[*] BO : Taxes are now historized
[*] BO : Taxes are no longer stored in the order details row
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
function update_order_detail_taxes()
|
||||
{
|
||||
$order_detail_taxes = Db::getInstance()->ExecuteS('
|
||||
SELECT `id_order_detail`, `tax_name`, `tax_rate` FROM `'._DB_PREFIX_.'order_detail`
|
||||
');
|
||||
|
||||
foreach ($order_detail_taxes as $order_detail_tax)
|
||||
{
|
||||
if ($order_detail_tax['tax_rate'] == '0.000')
|
||||
continue;
|
||||
|
||||
$alternative_tax_name = 'Tax '.$order_detail_tax['tax_rate'];
|
||||
$create_tax = true;
|
||||
|
||||
if ($id_tax = (int)Tax::getTaxIdByName($order_detail_tax['tax_name'], false) || $id_tax = (int)Tax::getTaxIdByName($alternative_tax_name, false))
|
||||
{
|
||||
$tax = new Tax($id_tax);
|
||||
if (Validate::isLoadedObject($tax))
|
||||
if ((string)$tax->rate == (string)$order_detail_tax['tax_rate'])
|
||||
$create_tax = false;
|
||||
else
|
||||
echo (string)$tax->rate.'!='.(string)$order_detail_tax['tax_rate'];
|
||||
}
|
||||
|
||||
if ($create_tax)
|
||||
{
|
||||
$tax = new Tax();
|
||||
$tax->rate = (float)$order_detail_tax['tax_rate'];
|
||||
$tax->name[Configuration::get('PS_LANG_DEFAULT')] = (isset($order_detail_tax['tax_name']) ? $order_detail_tax['tax_name'] : $alternative_tax_name);
|
||||
$tax->deleted = true;
|
||||
$tax->active = false;
|
||||
$tax->save();
|
||||
|
||||
$id_tax = $tax->id;
|
||||
}
|
||||
|
||||
Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'order_detail_tax` (`id_order_detail`, `id_tax`)
|
||||
VALUES ('.(int)$order_detail_tax['id_order_detail'].','.$id_tax.')
|
||||
');
|
||||
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ ALTER TABLE `PREFIX_employee`
|
||||
ADD `id_last_order` tinyint(1) unsigned NOT NULL default '0',
|
||||
ADD `id_last_message` tinyint(1) unsigned NOT NULL default '0',
|
||||
ADD `id_last_customer` tinyint(1) unsigned NOT NULL default '0';
|
||||
|
||||
|
||||
INSERT INTO `PREFIX_configuration` (`name`, `value`, `date_add`, `date_upd`) VALUES
|
||||
('PS_SHOW_NEW_ORDERS', '1', NOW(), NOW()),
|
||||
('PS_SHOW_NEW_CUSTOMERS', '1', NOW(), NOW()),
|
||||
@@ -78,3 +78,17 @@ ALTER TABLE `PREFIX_product_attribute` ADD `available_date` DATETIME NOT NULL;
|
||||
|
||||
/* Index was only used by deprecated function Image::positionImage() */
|
||||
ALTER TABLE `PREFIX_image` DROP INDEX `product_position`;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `PREFIX_order_detail_tax` (
|
||||
`id_order_detail` INT NOT NULL ,
|
||||
`id_tax` INT NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE `PREFIX_tax` ADD `deleted` INT NOT NULL AFTER `active`;
|
||||
|
||||
/* PHP:update_order_detail_taxes(); */;
|
||||
|
||||
ALTER TABLE `PREFIX_order_detail`
|
||||
DROP `tax_name`,
|
||||
DROP `tax_rate`;
|
||||
|
||||
|
||||
@@ -135,6 +135,8 @@ require_once(_PS_INSTALLER_PHP_UPGRADE_DIR_.'add_order_state.php');
|
||||
|
||||
require_once(_PS_INSTALLER_PHP_UPGRADE_DIR_.'remove_tab.php');
|
||||
|
||||
require_once(_PS_INSTALLER_PHP_UPGRADE_DIR_.'update_order_detail_taxes.php');
|
||||
|
||||
//old version detection
|
||||
global $oldversion, $logger;
|
||||
$oldversion = false;
|
||||
|
||||
Reference in New Issue
Block a user