diff --git a/classes/Tax.php b/classes/Tax.php index 41730e33..28c52bde 100755 --- a/classes/Tax.php +++ b/classes/Tax.php @@ -281,26 +281,26 @@ class TaxCore extends ObjectModel */ public static function getProductTaxRate($id_product, $id_address = NULL) { - $id_country = (int)Country::getDefaultCountryId(); - $id_state = 0; - $id_county = 0; - $rate = 0; - if (!empty($id_address)) - { - $address_infos = Address::getCountryAndState($id_address); - if ($address_infos['id_country']) - { - $id_country = (int)($address_infos['id_country']); - $id_state = (int)$address_infos['id_state']; - $id_county = (int)County::getIdCountyByZipCode($address_infos['id_state'], $address_infos['postcode']); + $id_country = (int)Country::getDefaultCountryId(); + $id_state = 0; + $id_county = 0; + $rate = 0; + if (!empty($id_address)) { + $address_infos = Address::getCountryAndState($id_address); + if ($address_infos['id_country']) { + $id_country = (int)($address_infos['id_country']); + $id_state = (int)$address_infos['id_state']; + $id_county = (int)County::getIdCountyByZipCode($address_infos['id_state'], $address_infos['postcode']); } - if (!empty($address_infos['vat_number']) AND $address_infos['id_country'] != Configuration::get('VATNUMBER_COUNTRY') AND Configuration::get('VATNUMBER_MANAGEMENT')) - return 0; + if (!empty($address_infos['vat_number']) AND $address_infos['id_country'] != Configuration::get('VATNUMBER_COUNTRY') AND Configuration::get('VATNUMBER_MANAGEMENT')) { + return 0; + } } - if ($rate = Tax::getProductTaxRateViaRules((int)$id_product, (int)$id_country, (int)$id_state, (int)$id_county)) - return $rate; + if ($rate = Tax::getProductTaxRateViaRules((int)$id_product, (int)$id_country, (int)$id_state, (int)$id_county)) { + return $rate; + } return $rate; } diff --git a/modules/bulkupdate/AdminBulkUpdate.php b/modules/bulkupdate/AdminBulkUpdate.php index 54d62c9e..09e7e5fe 100644 --- a/modules/bulkupdate/AdminBulkUpdate.php +++ b/modules/bulkupdate/AdminBulkUpdate.php @@ -548,31 +548,35 @@ class AdminBulkUpdate extends AdminTab { $prices = array(); if (Tools::getValue('price_process') == 2) { - while($line = fgetcsv($f, 0, ';')) { - if(empty($line[0])) { + while ($line = fgetcsv($f, 0, ';')) { + if (empty($line[0])) { continue; } $products[] = (int) $line[0]; } - } elseif(Tools::getValue('price_process') == 3 || Tools::getValue('price_process') == 4) { - while($line = fgetcsv($f, 0, ';')) { - if(empty($line[0])) { + } + // Prix d'achat HT || Prix public TTC + elseif (Tools::getValue('price_process') == 3 || Tools::getValue('price_process') == 4) { + while ($line = fgetcsv($f, 0, ';')) { + if (empty($line[0])) { continue; } $prices[] = array( - (int) $line[0], - $line[1] + (int) $line[0], + $line[1] ); } - } else { - while($line = fgetcsv($f, 0, ';')) { - if(empty($line[0])) { + } + // Reduction + else { + while ($line = fgetcsv($f, 0, ';')) { + if (empty($line[0])) { continue; } - if(!isset($line[1])) { + if (!isset($line[1])) { continue; } @@ -587,6 +591,7 @@ class AdminBulkUpdate extends AdminTab { fclose($f); + // Reduction || ... if (Tools::getValue('price_process') == 1 || Tools::getValue('price_process') == 2) { Db::getInstance()->ExecuteS(' DELETE FROM `'._DB_PREFIX_.'specific_price` @@ -594,9 +599,10 @@ class AdminBulkUpdate extends AdminTab { '); } + // Reduction if (Tools::getValue('price_process') == 1) { - foreach($prices as $price) { - if((int) $price[0] != 0) { + foreach ($prices as $price) { + if ((int) $price[0] != 0) { Db::getInstance()->ExecuteS(' INSERT INTO `'._DB_PREFIX_.'specific_price` VALUES ( DEFAULT, @@ -618,51 +624,64 @@ class AdminBulkUpdate extends AdminTab { } } } + + // Prix d'achat HT if (Tools::getValue('price_process') == 3) { - foreach($prices as $price) { - if((int) $price[0] != 0){ + foreach ($prices as $price) { + if ((int) $price[0] != 0){ $price[1] = str_replace(',', '.', $price[1]); $price_ht = floatval($price[1]); Db::getInstance()->ExecuteS(' UPDATE `'._DB_PREFIX_.'product` SET wholesale_price = '. (float)$price_ht .' WHERE id_product ='. (int)$price[0]); - }else{ + } else { $output .= '
ID produit à 0, ligne non traitée : '.serialize($price).'
'; } } } + + // Prix public TTC if (Tools::getValue('price_process') == 4) { - foreach($prices as $price) { - if((int) $price[0] != 0){ + foreach ($prices as $price) { + if ((int) $price[0] != 0){ $price[1] = str_replace(',', '.', $price[1]); - $price_ht = floatval($price[1] / 1.20); + // Find Tax for this id product + // product.id_tax_rules_group => tax_rules_group => tax_rule => tax.rate + $tax = new Tax(); + $taxValue = $tax->getProductTaxRate((int)$price[0]); + if ($taxValue == 0) { + $taxValue = 20; + } + + $price_ht = floatval($price[1] / (1 + $taxValue / 100) ); Db::getInstance()->ExecuteS(' UPDATE `'._DB_PREFIX_.'product` SET price = '. (float)$price_ht .' WHERE id_product ='. (int)$price[0]); - }else{ + } else { $output .= 'ID produit à 0, ligne non traitée : '.serialize($price).'
'; } } } $output .= ''.$this->l('Products updated').'
'; - } elseif (Tools::isSubmit('submitUploadProductDescriptions')) { + } + elseif (Tools::isSubmit('submitUploadProductDescriptions')) { $id_lang = Tools::getValue('description_process'); $f = fopen($_FILES['csvfile']['tmp_name'], 'r'); fgetcsv($f, 0, ';'); $products = array(); - while($line = fgetcsv($f, 0, ';')) { - if($line[0] == '' || $line[1] == '') { + while ($line = fgetcsv($f, 0, ';')) { + if ($line[0] == '' || $line[1] == '') { continue; } $products[] = $line; } - foreach($products as $line) { + foreach ($products as $line) { $result = Db::getInstance()->ExecuteS(' UPDATE `'._DB_PREFIX_.'product_lang` SET `description` = "'. pSQL($line[1],true) .'" @@ -676,14 +695,15 @@ class AdminBulkUpdate extends AdminTab { fclose($f); $output .= ''.$this->l('Products updated').'
'; - } elseif (Tools::isSubmit('submitUploadCombinations')) { + } + elseif (Tools::isSubmit('submitUploadCombinations')) { $f = fopen($_FILES['csvfile']['tmp_name'], 'r'); fgetcsv($f, 0, ';'); $products = array(); - while($line = fgetcsv($f, 0, ';')) { - if(empty($line[0])) { + while ($line = fgetcsv($f, 0, ';')) { + if (empty($line[0])) { continue; }