From efbf3c5d451fef403e96106f2bfd181d461b1c6f Mon Sep 17 00:00:00 2001 From: fBrignoli Date: Wed, 14 Sep 2011 09:06:20 +0000 Subject: [PATCH] [*] BO : Taxes are now historized [*] BO : Taxes are no longer stored in the order details row --- admin-dev/ajax.php | 7 +- admin-dev/tabs/AdminTaxRulesGroup.php | 146 +++++++++++------- classes/Carrier.php | 2 +- classes/Order.php | 25 +-- classes/OrderDetail.php | 109 +++++++++---- classes/PaymentModule.php | 25 +-- classes/tax/Tax.php | 120 ++++++++++---- classes/tax/TaxCalculator.php | 104 ++++++------- classes/tax/TaxRule.php | 42 +++-- classes/tax/TaxRulesTaxManager.php | 8 +- install-dev/php/update_order_detail_taxes.php | 45 ++++++ install-dev/sql/upgrade/1.5.0.1.sql | 16 +- install-dev/xml/doUpgrade.php | 2 + modules/vatnumber/VATNumberTaxManager.php | 5 +- 14 files changed, 439 insertions(+), 217 deletions(-) create mode 100644 install-dev/php/update_order_detail_taxes.php diff --git a/admin-dev/ajax.php b/admin-dev/ajax.php index a51f4a3b6..1f9c8815e 100644 --- a/admin-dev/ajax.php +++ b/admin-dev/ajax.php @@ -395,7 +395,10 @@ if (isset($_GET['ajaxStates']) AND isset($_GET['id_country'])) { $list = ''; if (Tools::getValue('no_empty') != true) - $list = ''."\n"; + { + $empty_value = (Tools::isSubmit('empty_value')) ? Tools::getValue('empty_value') : '----------'; + $list = ''."\n"; + } foreach ($states AS $state) $list .= ''."\n"; @@ -652,7 +655,7 @@ if (Tools::isSubmit('getAdminHomeElement')) { $content = explode('|', $content); if ($content[0] == 'OK' && Validate::isCleanHtml($content[2]) && Validate::isCleanHtml($content[1])) - { + { $result['partner_preactivation'] = $content[2]; $content[1] = explode('#%#', $content[1]); foreach ($content[1] as $partnerPopUp) diff --git a/admin-dev/tabs/AdminTaxRulesGroup.php b/admin-dev/tabs/AdminTaxRulesGroup.php index 33c874a47..7ff7c9232 100755 --- a/admin-dev/tabs/AdminTaxRulesGroup.php +++ b/admin-dev/tabs/AdminTaxRulesGroup.php @@ -25,10 +25,10 @@ * International Registered Trademark & Property of PrestaShop SA */ -class - AdminTaxRulesGroup extends AdminTab +class AdminTaxRulesGroup extends AdminTab { public $tax_rule; + public $selected_countries = array(); public $_errors_tax_rule; public function __construct() @@ -84,31 +84,45 @@ class { $zipcode = Tools::getValue('zipcode'); $id_rule = (int)Tools::getValue('id_tax_rule'); + + $this->selected_countries = Tools::getValue('country'); + $this->selected_states = Tools::getValue('states'); + + if (empty($this->selected_states) || sizeof($this->selected_states) == 0) + $this->selected_states = array(0); - $tr = new TaxRule(); - - // update or creation? - if (isset($id_rule)) - $tr->id = $id_rule; - - $tr->id_tax = (int)Tools::getValue('tax'); - $tr->id_tax_rules_group = (int)Tools::getValue('id_tax_rules_group'); - $tr->id_country = (int)Tools::getValue('country'); - $tr->id_state = (int)Tools::getValue('states'); - list($tr->zipcode_from, $tr->zipcode_to) = $tr->breakDownZipCode($zipcode); - $tr->behavior = (int)Tools::getValue('behavior'); - $tr->description = Tools::getValue('description'); - - $this->_errors_tax_rule = $this->validateTaxRule($tr); - - if (sizeof($this->_errors_tax_rule) == 0) + foreach ($this->selected_countries as $id_country) { - if (!$tr->save()) - die('error'); + foreach ($this->selected_states as $id_state) + { + $tr = new TaxRule(); + + // update or creation? + if (isset($id_rule)) + $tr->id = $id_rule; + + $tr->id_tax = (int)Tools::getValue('tax'); + $tr->id_tax_rules_group = (int)Tools::getValue('id_tax_rules_group'); + $tr->id_country = (int)$id_country; + $tr->id_state = (int)$id_state; + list($tr->zipcode_from, $tr->zipcode_to) = $tr->breakDownZipCode($zipcode); + $tr->behavior = (int)Tools::getValue('behavior'); + $tr->description = Tools::getValue('description'); + + $this->tax_rule = $tr; + $this->_errors_tax_rule = $this->validateTaxRule($tr); + if (sizeof($this->_errors_tax_rule) == 0) + { + if (!$tr->save()) + die(Tools::displayError('An error has occured: Can\'t save the current tax rule')); + } else + Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$tr->id_tax_rules_group.'&conf=4&update'.$this->table.'&token='.$this->token); + } } - - $this->tax_rule = $tr; - Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$tr->id_tax_rules_group.'&conf=4&update'.$this->table.'&token='.$this->token); + + if (sizeof($this->_errors_tax_rule) == 0) + Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$tr->id_tax_rules_group.'&conf=4&update'.$this->table.'&token='.$this->token); + } else parent::postProcess(); } @@ -127,28 +141,42 @@ class { global $cookie; + $all = $this->l('All'); $javascript = << function populateStates(id_country, id_state) { - $.ajax({ - url: "ajax.php", - cache: false, - data: "ajaxStates=1&id_country="+id_country+"&id_state="+id_state, - success: function(html){ - if (html == "false") - { - $("#state-label").hide(); - $("#state-select").hide(); - } - else - { - $("#state-label").show(); - $("#state-select").show(); - $("#states").html(html); - } - } - }); + if ($("#country option:selected").size() > 1) + { + $("#zipcode-label").hide(); + $("#zipcode").hide(); + + $("#state-select").hide(); + $("#state-label").hide(); + } else { + $.ajax({ + url: "ajax.php", + cache: false, + data: "ajaxStates=1&id_country="+id_country+"&id_state="+id_state+"&empty_value=$all", + success: function(html){ + if (html == "false") + { + $("#state-label").hide(); + $("#state-select").hide(); + } + else + { + $("#state-label").show(); + $("#state-select").show(); + $("#states").html(html); + } + } + }); + + $("#zipcode-label").show(); + $("#zipcode").show(); + + } } function loadTaxRule(id_tax_rule) @@ -302,12 +330,15 @@ EOT; { global $cookie, $currentIndex; - if (Validate::isLoadedObject($this->tax_rule)) + if (Validate::isLoadedObject($this->tax_rule)) die(Tools::displayError('Unable to load the tax rule!')); $country_select = Helper::selectInput(Country::getCountries((int)$cookie->id_lang), - array('id' => 'country', 'name' => 'country', 'onclick' => 'populateStates($(this).val(), \'\')'), - array('key' => 'id_country', 'value' => 'name')); + array('id' => 'country', 'name' => 'country[]', 'onclick' => 'populateStates($(this).val(), \'\')', 'multiple' => 'multiple'), + array('key' => 'id_country', + 'value' => 'name', + 'selected' => $this->selected_countries, + 'empty' => $this->l('All'))); $tax_select = Helper::selectInput(Tax::getTaxes((int)$cookie->id_lang), @@ -325,18 +356,23 @@ EOT; echo ' '.$this->l('Add a new tax rule').'