コード例 #1
0
 public function hasUniqueTaxRuleForCountry($id_country, $id_state, $id_tax_rule = false)
 {
     $rules = TaxRule::getTaxRulesByGroupId((int) Context::getContext()->language->id, (int) $this->id);
     foreach ($rules as $rule) {
         if ($rule['id_country'] == $id_country && $id_state == $rule['id_state'] && !$rule['behavior'] && (int) $id_tax_rule != $rule['id_tax_rule']) {
             return true;
         }
     }
     return false;
 }
コード例 #2
0
    public function displayForm($isMainTab = true)
    {
        global $cookie, $currentIndex;
        parent::displayForm();
        if (!($obj = $this->loadObject(true))) {
            return;
        }
        $tax_rules = isset($obj->id) ? $tax_rules = TaxRule::getTaxRulesByGroupId($obj->id) : array();
        $param_product = Tools::getValue('id_product') ? '&id_product=' . Tools::getValue('id_product') : '';
        echo '<form action="' . $currentIndex . '&submitAdd' . $this->table . '=1&token=' . $this->token . $param_product . '" method="post">
				' . ($obj->id ? '<input type="hidden" name="id_' . $this->table . '" value="' . $obj->id . '" />' : '') . '
				<fieldset><legend><img src="../img/admin/dollar.gif" />' . $this->l('Tax Rules') . '</legend>
				<input type="hidden" name="tabs" id="tabs" value="0" />
				';
        echo '<label>' . $this->l('Name') . '</label>
				<div class="margin-form">
					<input size="33" type="text" name="name" value="' . Tools::htmlentitiesUTF8($this->getFieldValue($obj, 'name')) . '" /><sup> *</sup>
					<span class="hint" name="help_box">' . $this->l('Invalid characters:') . ' <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
			<p class="clear"></p>
			</div>';
        echo '
			<label>' . $this->l('Enable:') . ' </label>
			<div class="margin-form">
				<input type="radio" name="active" id="active_on" value="1" ' . ($this->getFieldValue($obj, 'active') ? 'checked="checked" ' : '') . '/>
				<label class="t" for="active_on"> <img src="../img/admin/enabled.gif" alt="' . $this->l('Enabled') . '" title="' . $this->l('Enabled') . '" /></label>
				<input type="radio" name="active" id="active_off" value="0" ' . (!$this->getFieldValue($obj, 'active') ? 'checked="checked" ' : '') . '/>
				<label class="t" for="active_off"> <img src="../img/admin/disabled.gif" alt="' . $this->l('Disabled') . '" title="' . $this->l('Disabled') . '" /></label>
			</div>
			<div class="margin-form">
				<input type="submit" value="' . $this->l('   Save   ') . '" name="submitAdd' . $this->table . '" class="button" />&nbsp;
				<input type="submit" value="' . $this->l('Save and stay') . '" name="submitAdd' . $this->table . 'AndStay" class="button" />
			</div>';
        echo '<br />';
        echo '<div class="tab-panet-tax" id="tab-pane-1">
			<script type="text/javascript">
			var pos_select = ' . (($tab = Tools::getValue('tabs')) ? $tab : '0') . ';
			function loadTab(id)
			{}

			function applyTax(id_zone)
			{
				   cur_tax = $("#zone_"+id_zone).val();
					$(".tax_"+id_zone).val(cur_tax);
					return false;
			}

			function disableStateTaxRate(id_country, id_state)
			{
				if ($("#behavior_state_"+id_state).val() == ' . PS_PRODUCT_TAX . ')
					$("#tax_"+id_country+"_"+id_state).attr("disabled", true);
				else
					$("#tax_"+id_country+"_"+id_state).attr("disabled", false);
			}

			function disableCountyTaxRate(id_country, id_state, id_county)
			{

				if ($("#behavior_county_"+id_county).val() == ' . County::USE_STATE_TAX . ')
					$("#tax_"+id_country+"_"+id_state+"_"+id_county).attr("disabled", true);
				else
				{

					$("#tax_"+id_country+"_"+id_state+"_"+id_county).attr("disabled", false);
				}
			}

			$(\'document\').ready(function (){
				$(\'.states\').hide();
				$(\'.counties\').hide();

				$(\'.open_state\').click(function (){
					if ($(\'.\'+$(this).attr(\'id\')).is(\':hidden\'))
					{
						$(\'.\'+$(this).attr(\'id\')).show();
						$(\'#\'+$(this).attr(\'id\')+\'_button\').attr("src","../img/admin/less.png");
					}
					else
					{
						$(\'.\'+$(this).attr(\'id\')).hide();
						$(\'.county_\'+$(this).attr(\'id\')).hide();
						$(\'.county_\'+$(this).attr(\'id\')+\'_button\').attr("src","../img/admin/more.png");
						$(\'#\'+$(this).attr(\'id\')+\'_button\').attr("src","../img/admin/more.png");
					}
				});

				$(\'.open_county\').click(function (){
					if ($(\'.\'+$(this).attr(\'id\')).is(\':hidden\'))
					{
						$(\'.\'+$(this).attr(\'id\')).show();
						$(\'#\'+$(this).attr(\'id\')+\'_button\').attr("src","../img/admin/less.png");
					}
					else
					{
						$(\'.\'+$(this).attr(\'id\')).hide();
						$(\'#\'+$(this).attr(\'id\')+\'_button\').attr("src","../img/admin/more.png");
					}
				});
			});
			</script>
			<script src="../js/tabpane.js" type="text/javascript"></script>
			<script type="text/javascript">
				var tabPane1 = new WebFXTabPane( document.getElementById( "tab-pane-1" ) );
			</script>
			<link type="text/css" rel="stylesheet" href="../css/tabpane.css" />' . $this->renderZones($tax_rules, (int) $cookie->id_lang);
        echo '
				<div class="margin-form" style="margin-top: 10px">
					<input type="submit" value="' . $this->l('   Save   ') . '" name="submitAdd' . $this->table . '" class="button" />&nbsp;&nbsp;
					<input type="submit" value="' . $this->l('Save and stay') . '" name="submitAdd' . $this->table . 'AndStay" class="button" />
				</div>
			</fieldset>
		</form>';
    }
コード例 #3
0
 private function generateEuropeTaxRule()
 {
     $euro_vat_array = self::$europe_vat_array;
     $euro_tax_rule_grp_id = TaxRulesGroup::getIdByName((string) $this->european_vat_name);
     if (!$euro_tax_rule_grp_id) {
         // Create it
         $trg = new TaxRulesGroup();
         $trg->name = (string) $this->european_vat_name;
         $trg->active = 1;
         if (!$trg->save()) {
             $this->_errors[] = Tools::displayError('Tax rule cannot be saved.');
             return false;
         }
         $euro_tax_rule_grp_id = (int) $trg->id;
     }
     $tax_rules_euro_group = TaxRule::getTaxRulesByGroupId((int) Context::getContext()->language->id, (int) $euro_tax_rule_grp_id);
     $euro_group_taxes_rules = array();
     foreach ($tax_rules_euro_group as $tax_rule) {
         $euro_group_taxes_rules[] = $tax_rule;
     }
     foreach ($euro_vat_array as $euro_vat_name => $euro_vat_details) {
         $posted_euro_vat = 'euro_vat_' . (string) $euro_vat_details['iso_country'];
         $posted_available_vat = 'available_vat_' . (string) $euro_vat_details['iso_country'];
         $country_id = Country::getByIso((string) $euro_vat_details['iso_country']);
         if (Tools::isSubmit($posted_euro_vat)) {
             if (!Tools::isSubmit($posted_available_vat)) {
                 $id_tax_found = Tax::getTaxIdByName((string) $euro_vat_name);
                 if ($id_tax_found !== false) {
                     $tax = new Tax((int) $id_tax_found);
                 } else {
                     $tax = new Tax();
                 }
                 $tax->name[(int) Configuration::get('PS_LANG_DEFAULT')] = (string) $euro_vat_name;
                 $tax->rate = (double) $euro_vat_details['rate'];
                 $tax->active = 1;
                 if ($tax->validateFields(false, true) !== true || $tax->validateFieldsLang(false, true) !== true) {
                     $this->_errors[] = Tools::displayError('Invalid tax properties.');
                     continue;
                 }
                 if (!$tax->save()) {
                     $this->_errors[] = Tools::displayError('An error occurred while saving the tax: ');
                     continue;
                 }
                 $id_tax_rule = $this->getTaxRuleIdFromUnique($euro_tax_rule_grp_id, $country_id, $id_tax_found);
                 if ($id_tax_rule !== false) {
                     $tr = new TaxRule((int) $id_tax_rule);
                 } else {
                     $tr = new TaxRule();
                 }
                 $tr->id_tax_rules_group = (int) $euro_tax_rule_grp_id;
                 $tr->id_country = (int) $country_id;
                 $tr->id_state = 0;
                 $tr->id_county = 0;
                 $tr->zipcode_from = 0;
                 $tr->zipcode_to = 0;
                 $tr->behavior = 0;
                 $tr->description = '';
                 $tr->id_tax = (int) $tax->id;
                 $tr->save();
             } else {
                 $assoc_id_tax = (int) Tools::getValue($posted_available_vat);
                 $id_tax_rule = $this->getTaxRuleIdFromUnique($euro_tax_rule_grp_id, $country_id, $assoc_id_tax);
                 if ($id_tax_rule !== false) {
                     $tr = new TaxRule((int) $id_tax_rule);
                 } else {
                     $tr = new TaxRule();
                 }
                 $tr->id_tax_rules_group = (int) $euro_tax_rule_grp_id;
                 $tr->id_country = (int) $country_id;
                 $tr->id_state = 0;
                 $tr->id_county = 0;
                 $tr->zipcode_from = 0;
                 $tr->zipcode_to = 0;
                 $tr->behavior = 0;
                 $tr->description = '';
                 $tr->id_tax = (int) $assoc_id_tax;
                 $tr->save();
             }
         } else {
             $this->_errors[] = Tools::displayError('Invalid parameters received');
         }
     }
 }
コード例 #4
0
 /**
  * @param $module
  * @return mixed
  */
 protected static function getTaxRules($module)
 {
     $taxRules = array();
     $taxRuleGroups = TaxRulesGroup::getTaxRulesGroups(true);
     foreach ($taxRuleGroups as $taxRuleGroup) {
         /** @var TaxCore $taxItem */
         $taxItem = ShopgateSettings::getTaxItemByTaxRuleGroupId($taxRuleGroup['id_tax_rules_group']);
         $rule = array('id' => $taxRuleGroup['id_tax_rules_group'], 'name' => $taxRuleGroup['name'], 'priority' => 0);
         $rule['product_tax_classes'] = array(array('id' => $taxItem->id, 'key' => is_array($taxItem->name) ? reset($taxItem->name) : ''));
         $rule['customer_tax_classes'] = array(array('key' => 'default', 'is_default' => true));
         $rule['tax_rates'] = array();
         if (version_compare(_PS_VERSION_, '1.5.0.1', '<')) {
             $taxRulesPrestashop = TaxRule::getTaxRulesByGroupId($taxRuleGroup['id_tax_rules_group']);
         } else {
             $taxRulesPrestashop = TaxRule::getTaxRulesByGroupId($module->context->language->id, $taxRuleGroup['id_tax_rules_group']);
         }
         foreach ($taxRulesPrestashop as $idCountry => $taxRuleItem) {
             if (version_compare(_PS_VERSION_, '1.5.0.1', '>=')) {
                 $taxRuleItem = new TaxRule($taxRuleItem['id_tax_rule']);
                 $idTax = $taxRuleItem->id_tax;
                 $idCountry = $taxRuleItem->id_country;
                 $idState = $taxRuleItem->id_state;
             } else {
                 $idTax = self::getTaxIdFromTaxRule($taxRuleItem);
                 $idState = key($taxRuleItem);
             }
             /** @var TaxCore $taxItem */
             $taxItem = new Tax($idTax, $module->context->language->id);
             $country = Country::getIsoById($idCountry);
             $stateModel = new State($idState);
             $state = $stateModel->iso_code;
             $resultTaxRate = array();
             $resultTaxRate['key'] = self::getTaxRateKey($taxItem, $country, $state);
             //Fix for 1.4.x.x the taxes were exported multiple
             if (self::arrayValueExists('key', $resultTaxRate['key'], $rule['tax_rates'])) {
                 continue;
             }
             $rule['tax_rates'][] = $resultTaxRate;
         }
         if ($taxItem->active && Configuration::get('PS_TAX') == 1) {
             $taxRules[] = $rule;
         }
     }
     return $taxRules;
 }