tax types

This commit is contained in:
Etienne Roudeix
2013-10-07 11:57:43 +02:00
parent 0efb01220c
commit fe3aea4ab7
9 changed files with 120 additions and 14 deletions

View File

@@ -777,6 +777,19 @@
<!-- end Modules rule management -->
<!-- taxe rules management -->
<route id="admin.configuration.taxes-rules.default" path="/admin/configuration/taxes_rules">
<default key="_controller">Thelia\Controller\Admin\TaxRuleController::defaultAction</default>
</route>
<route id="admin.configuration.taxes-rules.update" path="/admin/configuration/taxes_rules/update/{tax_rule_id}" methods="get">
<default key="_controller">Thelia\Controller\Admin\TaxRuleController::updateAction</default>
<requirement key="tax_rule_id">\d+</requirement>
</route>
<!-- end tax rules management -->
<!-- The default route, to display a template -->

View File

@@ -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) {

View File

@@ -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();

View File

@@ -0,0 +1,72 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\TaxEngine\TaxType;
use Thelia\Exception\TaxEngineException;
use Thelia\Model\FeatureProductQuery;
use Thelia\Model\Product;
use Thelia\Type\FloatType;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
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'),
);
}
}

View File

@@ -42,7 +42,7 @@ class featureSlicePercentTaxType extends BaseTaxType
}
public function fixAmountRetriever()
public function fixAmountRetriever(\Thelia\Model\Product $product)
{
}

View File

@@ -41,7 +41,7 @@ class FixAmountTaxType extends BaseTaxType
return 0;
}
public function fixAmountRetriever()
public function fixAmountRetriever(\Thelia\Model\Product $product)
{
return $this->getRequirement("amount");
}

View File

@@ -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;
}

View File

@@ -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()),

View File

@@ -40,21 +40,27 @@
</tr>
</thead>
<tbody>
{loop type="tax-rule" name="taxes-rules"}
<tr>
<td>Eco taxe</td>
<td>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequatur, aperiam, voluptatibus odio numquam adipisci!</td>
<td>{$TITLE}</td>
<td>{$DESCRIPTION}</td>
<td>
<div class="btn-group">
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.taxes-rules.change"}
<a class="btn btn-default btn-xs" title="{intl l='Change this tax rule'}" href="{url path="/admin/configuration/taxes_rules/update/{$ID}"}"><span class="glyphicon glyphicon-edit"></span></a>
{/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"}
<a class="btn btn-default btn-xs" title="{intl l='Delete this tax rule'}" href="#tax_rule_delete_dialog" data-id="{$ID}" data-toggle="modal"><span class="glyphicon glyphicon-trash"></span></a>
{/loop}
</div>
</td>
</tr>
</tr>
{/loop}
</tbody>
</table>
</div>