Jump to content

Welcome, Guest!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Fernando

How to make invoice number go up by 2 each order

Recommended Posts

I believe you can create an override as override/classes/order/Order.php and change the increment value from 1 to 2

This code hasn't been verified but should be close to what you need.

Edit: I verified this on a test shop and it works.

<?php
/*******
* Override Created from Thirty Bees Order.php to increment invoice numbers by 2
* 
****** */

class Order extends OrderCore
{
     /**
     * @param int $orderInvoiceId
     * @param int $idShop
     *
     * @return bool
     * @throws PrestaShopException
     */
    public static function setLastInvoiceNumber($orderInvoiceId, $idShop)
    {
        if (!$orderInvoiceId) {
            return false;
        }

        $number = Configuration::get('PS_INVOICE_START_NUMBER', null, null, $idShop);
        // 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, $idShop);
        }

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

        if ($number) {
            $sql .= (int) $number;
        } else {
            // Find the next number (***line below was + 1 changed to + 2 to increment by 2****)
            $newNumberSql = 'SELECT (MAX(`number`) + 2) AS new_number
                FROM `'._DB_PREFIX_.'order_invoice`'.(Configuration::get('PS_INVOICE_RESET') ?
                ' WHERE DATE_FORMAT(`date_add`, "%Y") = '.(int) date('Y') : '');
            $newNumber = DB::getInstance()->getValue($newNumberSql);

            $sql .= (int) $newNumber;
        }

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

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

}

 

 

 

Edited by Rhapsody
Tested
Link to comment
Share on other sites

On 4/13/2020 at 3:23 PM, Rhapsody said:

I believe you can create an override as override/classes/order/Order.php and change the increment value from 1 to 2

This code hasn't been verified but should be close to what you need.

Edit: I verified this on a test shop and it works.

<?php
/*******
* Override Created from Thirty Bees Order.php to increment invoice numbers by 2
* 
****** */

class Order extends OrderCore
{
     /**
     * @param int $orderInvoiceId
     * @param int $idShop
     *
     * @return bool
     * @throws PrestaShopException
     */
    public static function setLastInvoiceNumber($orderInvoiceId, $idShop)
    {
        if (!$orderInvoiceId) {
            return false;
        }

        $number = Configuration::get('PS_INVOICE_START_NUMBER', null, null, $idShop);
        // 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, $idShop);
        }

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

        if ($number) {
            $sql .= (int) $number;
        } else {
            // Find the next number (***line below was + 1 changed to + 2 to increment by 2****)
            $newNumberSql = 'SELECT (MAX(`number`) + 2) AS new_number
                FROM `'._DB_PREFIX_.'order_invoice`'.(Configuration::get('PS_INVOICE_RESET') ?
                ' WHERE DATE_FORMAT(`date_add`, "%Y") = '.(int) date('Y') : '');
            $newNumber = DB::getInstance()->getValue($newNumberSql);

            $sql .= (int) $newNumber;
        }

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

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

}

 

 

 

So I create a file named order.php put your code into this file and copied the file in folder ...override/classes/order/

doesn´t work. any idea?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×
×
  • Create New...