Jump to content

Edit History

Serhii

Serhii

On 8/29/2017 at 5:04 PM, phliippeduverger said:

Hello 

 

For the info (if it help someone)

I had to reset the invoice number in the middle of the year (from 2017-08-16)

 

I changed classes/order/Order.php

I updated  the getLastInvoiceNumber

 

(note that in my case, I have PS_INVOICE_RESET set to reset invoice number everyyear. 


  public static function getLastInvoiceNumber()
    {
        $sql = 'SELECT MAX(`number`) FROM `'._DB_PREFIX_.'order_invoice`';
        if (Configuration::get('PS_INVOICE_RESET')) {
            $sql .= ' WHERE DATE_FORMAT(`date_add`, "%Y") = '.(int)date('Y').'  AND `date_add` > "2017-08-16 21:00:00"';
        }


        return Db::getInstance()->getValue($sql);
    }

I was able with this change to change/reset it  in the backoffice.

Hi guys.
Finally the managed.
You can restart invoice numbers with this change in the code only if you make these changes:
Your code

    public static function setLastInvoiceNumber($order_invoice_id, $id_shop)
    {
        if (!$order_invoice_id) {
            return false;
        }

        $number = Configuration::get('PS_INVOICE_START_NUMBER', null, null, $id_shop);
        // If invoice start number has been set, you clean the value of this configuration
        if ($number) {
            Configuration::updateValue('PS_INVOICE_START_NUMBER', false, false, null, $id_shop);
        }

        $sql = 'UPDATE `'._DB_PREFIX_.'order_invoice` SET number =';

        if ($number) {
            $sql .= (int)$number;
        } else {
            // Find the next number
            $new_number_sql = 'SELECT (MAX(`number`) + 1) AS new_number
                FROM `'._DB_PREFIX_.'order_invoice`'.(Configuration::get('PS_INVOICE_RESET') ?
                ' WHERE DATE_FORMAT(`date_add`, "%Y") = '.(int)date('Y') : '');
            $new_number = DB::getInstance()->getValue($new_number_sql);
            
            $sql .= (int)$new_number;
        }

        $sql .= ' WHERE `id_order_invoice` = '.(int)$order_invoice_id;

        return Db::getInstance()->execute($sql);
    }

change this:  ' WHERE DATE_FORMAT(`date_add`, "%Y") = '.(int)date('Y') : '');  on ' WHERE DATE_FORMAT(`date_add`, "%Y") = '.(int)date('Y') : '').' AND `date_add` > "2019-02-05 11:06:00"';

my code

    public static function setLastInvoiceNumber($order_invoice_id, $id_shop)
    {
        if (!$order_invoice_id) {
            return false;
        }

        $number = Configuration::get('PS_INVOICE_START_NUMBER', null, null, $id_shop);
        // If invoice start number has been set, you clean the value of this configuration
        if ($number) {
            Configuration::updateValue('PS_INVOICE_START_NUMBER', false, false, null, $id_shop);
        }

        $sql = 'UPDATE `'._DB_PREFIX_.'order_invoice` SET number =';

        if ($number) {
            $sql .= (int)$number;
        } else {
            // Find the next number
            $new_number_sql = 'SELECT (MAX(`number`) + 1) AS new_number
                FROM `'._DB_PREFIX_.'order_invoice`'.(Configuration::get('PS_INVOICE_RESET') ?
                ' WHERE DATE_FORMAT(`date_add`, "%Y") = '.(int)date('Y') : '').' AND `date_add` > "2019-02-05 11:06:00"';
            $new_number = DB::getInstance()->getValue($new_number_sql);
            
            $sql .= (int)$new_number;
        }

        $sql .= ' WHERE `id_order_invoice` = '.(int)$order_invoice_id;

        return Db::getInstance()->execute($sql);
    }

after these changes I have reset the number invoice, tested on version 1.6.1.18

Serhii

Serhii

On 8/29/2017 at 5:04 PM, phliippeduverger said:

Hello 

 

For the info (if it help someone)

I had to reset the invoice number in the middle of the year (from 2017-08-16)

 

I changed classes/order/Order.php

I updated  the getLastInvoiceNumber

 

(note that in my case, I have PS_INVOICE_RESET set to reset invoice number everyyear. 


  public static function getLastInvoiceNumber()
    {
        $sql = 'SELECT MAX(`number`) FROM `'._DB_PREFIX_.'order_invoice`';
        if (Configuration::get('PS_INVOICE_RESET')) {
            $sql .= ' WHERE DATE_FORMAT(`date_add`, "%Y") = '.(int)date('Y').'  AND `date_add` > "2017-08-16 21:00:00"';
        }


        return Db::getInstance()->getValue($sql);
    }

I was able with this change to change/reset it  in the backoffice.

Hi guys.
Finally the managed.
You can restart invoice numbers with this change in the code only if you make these changes:
this part of code

    public static function setLastInvoiceNumber($order_invoice_id, $id_shop)
    {
        if (!$order_invoice_id) {
            return false;
        }

        $number = Configuration::get('PS_INVOICE_START_NUMBER', null, null, $id_shop);
        // If invoice start number has been set, you clean the value of this configuration
        if ($number) {
            Configuration::updateValue('PS_INVOICE_START_NUMBER', false, false, null, $id_shop);
        }

        $sql = 'UPDATE `'._DB_PREFIX_.'order_invoice` SET number =';

        if ($number) {
            $sql .= (int)$number;
        } else {
            // Find the next number
            $new_number_sql = 'SELECT (MAX(`number`) + 1) AS new_number
                FROM `'._DB_PREFIX_.'order_invoice`'.(Configuration::get('PS_INVOICE_RESET') ?
                ' WHERE DATE_FORMAT(`date_add`, "%Y") = '.(int)date('Y') : '');
            $new_number = DB::getInstance()->getValue($new_number_sql);
            
            $sql .= (int)$new_number;
        }

        $sql .= ' WHERE `id_order_invoice` = '.(int)$order_invoice_id;

        return Db::getInstance()->execute($sql);
    }

in it change ' WHERE DATE_FORMAT(`date_add`, "%Y") = '.(int)date('Y') : '');  on ' WHERE DATE_FORMAT(`date_add`, "%Y") = '.(int)date('Y') : '').' AND `date_add` > "2019-02-05 11:06:00"';

    public static function setLastInvoiceNumber($order_invoice_id, $id_shop)
    {
        if (!$order_invoice_id) {
            return false;
        }

        $number = Configuration::get('PS_INVOICE_START_NUMBER', null, null, $id_shop);
        // If invoice start number has been set, you clean the value of this configuration
        if ($number) {
            Configuration::updateValue('PS_INVOICE_START_NUMBER', false, false, null, $id_shop);
        }

        $sql = 'UPDATE `'._DB_PREFIX_.'order_invoice` SET number =';

        if ($number) {
            $sql .= (int)$number;
        } else {
            // Find the next number
            $new_number_sql = 'SELECT (MAX(`number`) + 1) AS new_number
                FROM `'._DB_PREFIX_.'order_invoice`'.(Configuration::get('PS_INVOICE_RESET') ?
                ' WHERE DATE_FORMAT(`date_add`, "%Y") = '.(int)date('Y') : '').' AND `date_add` > "2019-02-05 11:06:00"';
            $new_number = DB::getInstance()->getValue($new_number_sql);
            
            $sql .= (int)$new_number;
        }

        $sql .= ' WHERE `id_order_invoice` = '.(int)$order_invoice_id;

        return Db::getInstance()->execute($sql);
    }

after these changes I have reset the number invoice, tested on version 1.6.1.18

×
×
  • Create New...