function setVATType($VATID) { $this->VATType = eZVatType::fetch($VATID); if (!$this->VATType) { eZDebug::writeDebug("VAT type with id '{$VATID}' is unavailable", __METHOD__); $this->VATType = eZVatType::create(); } }
/** * Return VAT type object. */ function vatTypeObject() { return eZVatType::fetch($this->attribute('vat_type')); }
/** * Choose the best matching VAT type for given product category and country. * * We calculate priority for each VAT type and then choose * the VAT type having the highest priority * (or first of those having the highest priority). * * VAT type priority is calculated from county match and category match as following: * * CountryMatch = 0 * CategoryMatch = 1 * * if ( there is exact match on country ) * CountryMatch = 2 * elseif ( there is weak match on country ) * CountryMatch = 1 * * if ( there is exact match on product category ) * CategoryMatch = 2 * elseif ( there is weak match on product category ) * CategoryMatch = 1 * * if ( there is match on both country and category ) * VatTypePriority = CountryMatch * 2 + CategoryMatch - 2 * else * VatTypePriority = 0 * * \private * \static */ function chooseVatType( $productCategory, $country ) { $vatRules = eZVatRule::fetchList(); $catID = $productCategory->attribute( 'id' ); $vatPriorities = array(); foreach ( $vatRules as $rule ) { $ruleCountry = $rule->attribute( 'country_code' ); $ruleCatIDs = $rule->attribute( 'product_categories_ids' ); $ruleVatID = $rule->attribute( 'vat_type' ); $categoryMatch = 0; $countryMatch = 0; if ( $ruleCountry == '*' ) $countryMatch = 1; elseif ( $ruleCountry == $country ) $countryMatch = 2; if ( !$ruleCatIDs ) $categoryMatch = 1; elseif ( in_array( $catID, $ruleCatIDs ) ) $categoryMatch = 2; if ( $countryMatch && $categoryMatch ) $vatPriority = $countryMatch * 2 + $categoryMatch - 2; else $vatPriority = 0; if ( !isset( $vatPriorities[$vatPriority] ) ) $vatPriorities[$vatPriority] = $ruleVatID; } krsort( $vatPriorities, SORT_NUMERIC ); $bestPriority = 0; if ( $vatPriorities ) { $tmpKeys = array_keys( $vatPriorities ); $bestPriority = array_shift( $tmpKeys ); } if ( $bestPriority == 0 ) { eZDebug::writeError( "Cannot find a suitable VAT type " . "for country '" . $country . "'" . " and category '" . $productCategory->attribute( 'name' ). "'." ); return new eZVatType( array( "id" => 0, "name" => ezpI18n::tr( 'kernel/shop', 'None' ), "percentage" => 0.0 ) ); } $bestVatTypeID = array_shift( $vatPriorities ); $bestVatType = eZVatType::fetch( $bestVatTypeID ); eZDebug::writeDebug( sprintf( "Best matching VAT for '%s'/'%s' is '%s' (%d%%)", $country, $productCategory->attribute( 'name' ), $bestVatType->attribute( 'name' ), $bestVatType->attribute( 'percentage' ) ) ); return $bestVatType; }
function setVATType($VATID) { $this->VATType = eZVatType::fetch($VATID); if (!$this->VATType) { eZDebug::writeDebug("VAT type with id '{$VATID}' is unavailable", 'eZSimplePrice::setVATType'); $this->VATType = eZVatType::create(); } }
/** * Determine dependent VAT rules and products for the given VAT types. * * \private */ function findDependencies( $vatTypeIDList, &$deps, &$haveDeps, &$canRemove ) { // Find dependencies (products and/or VAT rules). $deps = array(); $haveDeps = false; $canRemove = true; foreach ( $vatTypeIDList as $vatID ) { $vatType = eZVatType::fetch( $vatID ); $vatName = $vatType->attribute( 'name' ); // Find dependent VAT rules. $nRules = eZVatRule::fetchCountByVatType( $vatID ); // Find dependent products. $nProducts = eZVatType::fetchDependentProductsCount( $vatID ); // Find product classes having this VAT type set as default. $nClasses = eZVatType::fetchDependentClassesCount( $vatID ); if ( $nClasses ) $canRemove = false; $deps[$vatID] = array( 'name' => $vatName, 'affected_rules_count' => $nRules, 'affected_products_count' => $nProducts, 'affected_classes_count' => $nClasses ); if ( !$haveDeps && ( $nRules > 0 || $nProducts > 0 ) ) $haveDeps = true; } }