Example #1
0
    public function setDeliveryNumber($order_invoice_id, $id_shop)
    {
        if (!$order_invoice_id) {
            return false;
        }
        $id_shop = shop::getTotalShops() > 1 ? $id_shop : null;
        $number = Configuration::get('PS_DELIVERY_NUMBER', null, null, $id_shop);
        // If delivery slip start number has been set, you clean the value of this configuration
        if ($number) {
            Configuration::updateValue('PS_DELIVERY_NUMBER', false, false, null, $id_shop);
        }
        $sql = 'UPDATE `' . _DB_PREFIX_ . 'order_invoice` SET delivery_number =';
        if ($number) {
            $sql .= (int) $number;
        } else {
            $sql .= '(SELECT new_number FROM (SELECT (MAX(`delivery_number`) + 1) AS new_number
			FROM `' . _DB_PREFIX_ . 'order_invoice`) AS result)';
        }
        $sql .= ' WHERE `id_order_invoice` = ' . (int) $order_invoice_id;
        return Db::getInstance()->execute($sql);
    }