• Hello,

    On your webwsite it says
    ‘Automatically increment the invoice’s custom ID by one: WP-Invoice creates a random automatic ID for the first invoice you create. You also have the option to set a custom ID for the invoice (to match your offline book-keeping or for any other reason).’

    How do I set the invoice number ID?

    Having random IDs breaks UK law if Vat registered. Invoices have to be sequential.

    Gary.

    https://wordpress.org/plugins/wp-invoice/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Anton Korotkoff

    (@anton-korotkoff)

    Hello,

    first go to the settings http://joxi.ru/kNZwU_3JTJBVU1nD3so and enable the option.

    Second, remove all your existing invoices with custom IDs if you have such.

    Third, when creating first invoice open advanced settings http://joxi.ru/itdwUxjKTJCgRls0GxY That way you started invoice counting from 1.

    Next invoice will be created with ID of 2.

    Let me know if you have other questions.

    Thanks.

    Thread Starter gazzamit

    (@gazzamit)

    I had since done that, but when I create a new invoice ‘from another’ it does not increment. (I tried creating with an entirely new invoice and the increment worked fine so you prob just need to add the increment code to ‘invoice from another’ tool).

    Plugin Contributor Anton Korotkoff

    (@anton-korotkoff)

    Thanks. We’ll look into it.

    Thread Starter gazzamit

    (@gazzamit)

    Hi, I just tested your plugin again and this bug has not been fixed. Custom ID’s do not increment if a new invoice is created from an existing template.

    Thread Starter gazzamit

    (@gazzamit)

    Hi, I had a quick look myself at the code and invoice_page_wpi_page_manage_invoice.php does not increment the custom_invoice_id if a new invoice is created from an existing invoice.

    I altered the code as below to solve the problem so that copying from an existing invoice also increments custom_invoice_id. Hopefully this will help the developer to address the bug:

    wpi_ui.php

    static function page_manage_invoice_preprocess( $screen_id ) {
        global $wpi_settings, $this_invoice, $wpdb, $template_used; //add $template_used
    
    // a few lines lower down...
    
     // New Invoice
        if ( isset( $_REQUEST[ 'wpi' ][ 'new_invoice' ] ) && empty( $invoice_id_exists ) ) {
          $this_invoice = new WPI_Invoice();
          $this_invoice->create_new_invoice( "invoice_id={$_REQUEST[ 'wpi' ][ 'new_invoice' ]['invoice_id']}" );
    		$template_used = 0;  //add $template_used = 0 
    
     	// If we are copying from a template
          if ( !empty( $_REQUEST[ 'wpi' ][ 'new_invoice' ][ 'template_copy' ] ) ) {
            $this_invoice->load_template( "id={$_REQUEST[ 'wpi' ][ 'new_invoice' ]['template_copy']}" );
    		$template_used = 1;  //add $template_used = 1

    invoice_page_wpi_page_manage_invoice.php

    if ((empty($custom_invoice_id) && $wpi_settings['increment_invoice_id'] == 'true') || $template_used = 1) {  //add || $template_used = 1

    Plugin Contributor Anton Korotkoff

    (@anton-korotkoff)

    Please use github pull requests for fixes like this.

    We will look into it then. Thanks.

    Thread Starter gazzamit

    (@gazzamit)

    OK, I have never done anything like that before but will try.

    Thread Starter gazzamit

    (@gazzamit)

    Having studied code a little further there is a simple fix to make custom invoice IDs increment when copying from existing invoice.

    In meta file /wp-invoice/core/ui/metabox/invoice_page_wpi_page_manage_invoice.php

    Original code (~line 198):
    if ((empty($custom_invoice_id) && $wpi_settings['increment_invoice_id'] == 'true'))

    New Code:
    if (((empty($custom_invoice_id) || empty($this_invoice['ID'])) && $wpi_settings['increment_invoice_id'] == 'true'))

    Addition of: || empty($this_invoice['ID']

    The idea is that this simply tests for the existence of an ID which is unset after a template is loaded by the last line of the load_template function from wpi_invoice.php:
    unset($this->data['ID']);

    _______
    PS: Error in my original code from above:
    code
    I accidentally typo
    || $template_used = 1)
    instead of
    || $template_used == 1)
    in invoice_page_wpi_page_manage_invoice.php (meta file)

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Custom Invoice number’ is closed to new replies.