From fe3aea4ab72fbe9024faecf874fb29d6f17a8a26 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Mon, 7 Oct 2013 11:57:43 +0200 Subject: [PATCH] tax types --- .../Thelia/Config/Resources/routing/admin.xml | 13 ++++ .../Thelia/Exception/TaxEngineException.php | 2 + .../Thelia/TaxEngine/TaxType/BaseTaxType.php | 3 +- .../TaxType/FeatureFixAmountTaxType.php | 72 +++++++++++++++++++ .../TaxType/FeatureSlicePercentTaxType.php | 2 +- .../TaxEngine/TaxType/FixAmountTaxType.php | 2 +- .../TaxEngine/TaxType/PricePercentTaxType.php | 2 +- install/insert.sql | 24 +++++-- templates/admin/default/taxes-rules.html | 14 ++-- 9 files changed, 120 insertions(+), 14 deletions(-) create mode 100755 core/lib/Thelia/TaxEngine/TaxType/FeatureFixAmountTaxType.php diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 2f85b57bc..8121a1ef4 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -777,6 +777,19 @@ + + + + Thelia\Controller\Admin\TaxRuleController::defaultAction + + + + Thelia\Controller\Admin\TaxRuleController::updateAction + \d+ + + + + diff --git a/core/lib/Thelia/Exception/TaxEngineException.php b/core/lib/Thelia/Exception/TaxEngineException.php index 86f8952b9..c36f7428c 100755 --- a/core/lib/Thelia/Exception/TaxEngineException.php +++ b/core/lib/Thelia/Exception/TaxEngineException.php @@ -43,6 +43,8 @@ class TaxEngineException extends \RuntimeException const BAD_AMOUNT_FORMAT = 601; + const FEATURE_BAD_EXPECTED_VALUE = 701; + public function __construct($message, $code = null, $previous = null) { if ($code === null) { diff --git a/core/lib/Thelia/TaxEngine/TaxType/BaseTaxType.php b/core/lib/Thelia/TaxEngine/TaxType/BaseTaxType.php index 149e3f1df..ef010a406 100755 --- a/core/lib/Thelia/TaxEngine/TaxType/BaseTaxType.php +++ b/core/lib/Thelia/TaxEngine/TaxType/BaseTaxType.php @@ -23,6 +23,7 @@ namespace Thelia\TaxEngine\TaxType; use Thelia\Exception\TaxEngineException; +use Thelia\Model\Product; use Thelia\Type\TypeInterface; /** @@ -38,7 +39,7 @@ abstract class BaseTaxType public abstract function pricePercentRetriever(); - public abstract function fixAmountRetriever(); + public abstract function fixAmountRetriever(Product $product); public abstract function getRequirementsList(); diff --git a/core/lib/Thelia/TaxEngine/TaxType/FeatureFixAmountTaxType.php b/core/lib/Thelia/TaxEngine/TaxType/FeatureFixAmountTaxType.php new file mode 100755 index 000000000..ea88dc494 --- /dev/null +++ b/core/lib/Thelia/TaxEngine/TaxType/FeatureFixAmountTaxType.php @@ -0,0 +1,72 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\TaxEngine\TaxType; + +use Thelia\Exception\TaxEngineException; +use Thelia\Model\FeatureProductQuery; +use Thelia\Model\Product; +use Thelia\Type\FloatType; + +/** + * + * @author Etienne Roudeix + * + */ +class FeatureFixAmountTaxType extends BaseTaxType +{ + public function calculate($untaxedPrice) + { + return $this->getRequirement("amount"); + } + + public function pricePercentRetriever() + { + return 0; + } + + public function fixAmountRetriever(Product $product) + { + $featureId = $this->getRequirement("featureId"); + + $query = FeatureProductQuery::create() + ->filterByProduct($product) + ->filterByFeatureId($featureId) + ->findOne(); + + $taxAmount = $query->getFreeTextValue(); + + $testInt = new FloatType(); + if(!$testInt->isValid($taxAmount)) { + throw new TaxEngineException('Feature value does not match FLOAT format', TaxEngineException::FEATURE_BAD_EXPECTED_VALUE); + } + + return $taxAmount; + } + + public function getRequirementsList() + { + return array( + 'featureId' => new ModelType('Feature'), + ); + } +} diff --git a/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php b/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php index 911439574..fc599c7b5 100755 --- a/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php +++ b/core/lib/Thelia/TaxEngine/TaxType/FeatureSlicePercentTaxType.php @@ -42,7 +42,7 @@ class featureSlicePercentTaxType extends BaseTaxType } - public function fixAmountRetriever() + public function fixAmountRetriever(\Thelia\Model\Product $product) { } diff --git a/core/lib/Thelia/TaxEngine/TaxType/FixAmountTaxType.php b/core/lib/Thelia/TaxEngine/TaxType/FixAmountTaxType.php index acd52bf8a..6f16560d8 100755 --- a/core/lib/Thelia/TaxEngine/TaxType/FixAmountTaxType.php +++ b/core/lib/Thelia/TaxEngine/TaxType/FixAmountTaxType.php @@ -41,7 +41,7 @@ class FixAmountTaxType extends BaseTaxType return 0; } - public function fixAmountRetriever() + public function fixAmountRetriever(\Thelia\Model\Product $product) { return $this->getRequirement("amount"); } diff --git a/core/lib/Thelia/TaxEngine/TaxType/PricePercentTaxType.php b/core/lib/Thelia/TaxEngine/TaxType/PricePercentTaxType.php index a8cd8c759..b3fbd59b0 100755 --- a/core/lib/Thelia/TaxEngine/TaxType/PricePercentTaxType.php +++ b/core/lib/Thelia/TaxEngine/TaxType/PricePercentTaxType.php @@ -41,7 +41,7 @@ class PricePercentTaxType extends BaseTaxType return ($this->getRequirement("percent") * 0.01); } - public function fixAmountRetriever() + public function fixAmountRetriever(\Thelia\Model\Product $product) { return 0; } diff --git a/install/insert.sql b/install/insert.sql index d91c511dc..c99f99920 100755 --- a/install/insert.sql +++ b/install/insert.sql @@ -1149,25 +1149,37 @@ INSERT INTO `country_i18n` (`id`, `locale`, `title`, `description`, `chapo`, `po INSERT INTO `tax` (`id`, `type`, `serialized_requirements`, `created_at`, `updated_at`) VALUES - (1, 'PricePercentTaxType', 'eyJwZXJjZW50IjoxOS42fQ==', NOW(), NOW()); + (1, 'PricePercentTaxType', 'eyJwZXJjZW50IjoxOS42fQ==', NOW(), NOW()), + (2, 'PricePercentTaxType', 'eyJwZXJjZW50Ijo1LjV9', NOW(), NOW()), + (3, 'FeatureFixAmountTaxType', 'eyJmZWF0dXJlIjowfQ==', NOW(), NOW()); INSERT INTO `tax_i18n` (`id`, `locale`, `title`) VALUES (1, 'fr_FR', 'TVA française à 19.6%'), - (1, 'en_US', 'French 19.6% VAT'); + (1, 'en_US', 'French 19.6% VAT'), + (2, 'fr_FR', 'TVA française à 5.5%'), + (2, 'en_US', 'French 5.5% VAT'), + (3, 'fr_FR', 'Ecotaxe UE'), + (3, 'en_US', 'EU ecotax'); INSERT INTO `tax_rule` (`id`, `is_default`, `created_at`, `updated_at`) VALUES - (1, 1, NOW(), NOW()); + (1, 1, NOW(), NOW()), + (2, 0, NOW(), NOW()); INSERT INTO `tax_rule_i18n` (`id`, `locale`, `title`) VALUES - (1, 'fr_FR', 'TVA française à 19.6%'), - (1, 'en_US', 'French 19.6% VAT'); + (1, 'fr_FR', 'TVA française à 19.6% avec ecotaxe'), + (1, 'en_US', 'French 19.6% VAT plus ecotax'), + (2, 'fr_FR', 'TVA française à 5.5% avec ecotaxe'), + (2, 'en_US', 'French 5.5% VAT plus ecotax'); INSERT INTO `tax_rule_country` (`tax_rule_id`, `country_id`, `tax_id`, `position`, `created_at`, `updated_at`) VALUES - (1, 64, 1, 1, NOW(), NOW()); + (1, 64, 3, 1, NOW(), NOW()), + (1, 64, 1, 2, NOW(), NOW()), + (2, 64, 3, 1, NOW(), NOW()), + (2, 64, 2, 2, NOW(), NOW()); INSERT INTO `order_status`(`id`, `code`, `created_at`, `updated_at`) VALUES (1, 'not_paid', NOW(), NOW()), diff --git a/templates/admin/default/taxes-rules.html b/templates/admin/default/taxes-rules.html index a0284d107..f1edc9bd9 100644 --- a/templates/admin/default/taxes-rules.html +++ b/templates/admin/default/taxes-rules.html @@ -40,21 +40,27 @@ + + {loop type="tax-rule" name="taxes-rules"} + - Eco taxe - Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequatur, aperiam, voluptatibus odio numquam adipisci! + {$TITLE} + {$DESCRIPTION}
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.taxes-rules.change"} {/loop} - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.taxes-rules.delete"} + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.taxes-rules.change"} {/loop}
- + + + {/loop} +