tax rule edition admin
This commit is contained in:
@@ -45,7 +45,9 @@
|
||||
<loop class="Thelia\Core\Template\Loop\Message" name="message"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Delivery" name="delivery"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Template" name="template"/> <!-- This is product templates ;-) -->
|
||||
<loop class="Thelia\Core\Template\Loop\Tax" name="tax"/>
|
||||
<loop class="Thelia\Core\Template\Loop\TaxRule" name="tax-rule"/>
|
||||
<loop class="Thelia\Core\Template\Loop\TaxRuleCountry" name="tax-rule-country"/>
|
||||
</loops>
|
||||
|
||||
<forms>
|
||||
|
||||
167
core/lib/Thelia/Core/Template/Loop/Tax.php
Normal file
167
core/lib/Thelia/Core/Template/Loop/Tax.php
Normal file
@@ -0,0 +1,167 @@
|
||||
<?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\Core\Template\Loop;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Core\Template\Element\BaseI18nLoop;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
|
||||
use Thelia\Model\Base\TaxRuleCountryQuery;
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type;
|
||||
use Thelia\Model\TaxQuery;
|
||||
|
||||
/**
|
||||
*
|
||||
* Tax loop
|
||||
*
|
||||
*
|
||||
* Class Tax
|
||||
* @package Thelia\Core\Template\Loop
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class Tax extends BaseI18nLoop
|
||||
{
|
||||
public $timestampable = true;
|
||||
|
||||
/**
|
||||
* @return ArgumentCollection
|
||||
*/
|
||||
protected function getArgDefinitions()
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntListTypeArgument('id'),
|
||||
Argument::createIntListTypeArgument('exclude'),
|
||||
Argument::createIntListTypeArgument('tax_rule'),
|
||||
Argument::createIntListTypeArgument('exclude_tax_rule'),
|
||||
Argument::createIntTypeArgument('country'),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
new Type\EnumListType(array('id', 'id_reverse', 'alpha', 'alpha_reverse'))
|
||||
),
|
||||
'alpha'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pagination
|
||||
*
|
||||
* @return \Thelia\Core\Template\Element\LoopResult
|
||||
*/
|
||||
public function exec(&$pagination)
|
||||
{
|
||||
$search = TaxQuery::create();
|
||||
|
||||
/* manage translations */
|
||||
$locale = $this->configureI18nProcessing($search, array('TITLE', 'DESCRIPTION'));
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
if (null !== $id) {
|
||||
$search->filterById($id, Criteria::IN);
|
||||
}
|
||||
|
||||
$exclude = $this->getExclude();
|
||||
|
||||
if (null !== $exclude) {
|
||||
$search->filterById($exclude, Criteria::NOT_IN);
|
||||
}
|
||||
|
||||
$country = $this->getCountry();
|
||||
|
||||
$taxRule = $this->getTax_rule();
|
||||
if(null !== $taxRule && null !== $country) {
|
||||
$search->filterByTaxRuleCountry(
|
||||
TaxRuleCountryQuery::create()
|
||||
->filterByCountryId($country, Criteria::EQUAL)
|
||||
->filterByTaxRuleId($taxRule, Criteria::IN)
|
||||
->find(),
|
||||
Criteria::IN
|
||||
);
|
||||
}
|
||||
|
||||
$excludeTaxRule = $this->getExclude_tax_rule();
|
||||
if(null !== $excludeTaxRule && null !== $country) {
|
||||
$excludedTaxes = TaxRuleCountryQuery::create()
|
||||
->filterByCountryId($country, Criteria::EQUAL)
|
||||
->filterByTaxRuleId($excludeTaxRule, Criteria::IN)
|
||||
->find();
|
||||
/*DOES NOT WORK
|
||||
* $search->filterByTaxRuleCountry(
|
||||
$excludedTaxes,
|
||||
Criteria::NOT_IN
|
||||
);*/
|
||||
foreach($excludedTaxes as $excludedTax) {
|
||||
$search->filterByTaxRuleCountry($excludedTax, Criteria::NOT_EQUAL);
|
||||
}
|
||||
}
|
||||
|
||||
$orders = $this->getOrder();
|
||||
|
||||
foreach ($orders as $order) {
|
||||
switch ($order) {
|
||||
case "id":
|
||||
$search->orderById(Criteria::ASC);
|
||||
break;
|
||||
case "id_reverse":
|
||||
$search->orderById(Criteria::DESC);
|
||||
break;
|
||||
case "alpha":
|
||||
$search->addAscendingOrderByColumn('i18n_TITLE');
|
||||
break;
|
||||
case "alpha_reverse":
|
||||
$search->addDescendingOrderByColumn('i18n_TITLE');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* perform search */
|
||||
$taxes = $this->search($search, $pagination);
|
||||
|
||||
$loopResult = new LoopResult($taxes);
|
||||
|
||||
foreach ($taxes as $tax) {
|
||||
|
||||
$loopResultRow = new LoopResultRow($loopResult, $tax, $this->versionable, $this->timestampable, $this->countable);
|
||||
|
||||
$loopResultRow
|
||||
->set("ID" , $tax->getId())
|
||||
->set("IS_TRANSLATED" , $tax->getVirtualColumn('IS_TRANSLATED'))
|
||||
->set("LOCALE" , $locale)
|
||||
->set("TITLE" , $tax->getVirtualColumn('i18n_TITLE'))
|
||||
->set("DESCRIPTION" , $tax->getVirtualColumn('i18n_DESCRIPTION'))
|
||||
;
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
return $loopResult;
|
||||
}
|
||||
}
|
||||
160
core/lib/Thelia/Core/Template/Loop/TaxRuleCountry.php
Normal file
160
core/lib/Thelia/Core/Template/Loop/TaxRuleCountry.php
Normal file
@@ -0,0 +1,160 @@
|
||||
<?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\Core\Template\Loop;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Propel\Runtime\ActiveQuery\Join;
|
||||
use Thelia\Core\Template\Element\BaseI18nLoop;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
|
||||
use Thelia\Model\Map\CountryTableMap;
|
||||
use Thelia\Model\Map\TaxRuleCountryTableMap;
|
||||
use Thelia\Model\Map\TaxTableMap;
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type;
|
||||
use Thelia\Model\TaxRuleCountryQuery;
|
||||
|
||||
/**
|
||||
*
|
||||
* TaxRuleCountry loop
|
||||
*
|
||||
*
|
||||
* Class TaxRuleCountry
|
||||
* @package Thelia\Core\Template\Loop
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class TaxRuleCountry extends BaseI18nLoop
|
||||
{
|
||||
public $timestampable = true;
|
||||
|
||||
/**
|
||||
* @return ArgumentCollection
|
||||
*/
|
||||
protected function getArgDefinitions()
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntTypeArgument('country'),
|
||||
Argument::createIntListTypeArgument('taxes'),
|
||||
Argument::createIntTypeArgument('tax_rule', null, true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pagination
|
||||
*
|
||||
* @return \Thelia\Core\Template\Element\LoopResult
|
||||
*/
|
||||
public function exec(&$pagination)
|
||||
{
|
||||
$search = TaxRuleCountryQuery::create();
|
||||
|
||||
$country = $this->getCountry();
|
||||
$taxes = $this->getTaxes();
|
||||
|
||||
if((null === $country && null === $taxes) || (null !== $country && null !== $taxes)) {
|
||||
throw new \InvalidArgumentException('You must provide either `country` or `taxes` parameter in tax-rule-country loop');
|
||||
}
|
||||
|
||||
if(null !== $country) {
|
||||
$search->filterByCountryId($country);
|
||||
|
||||
/* manage tax translation */
|
||||
$this->configureI18nProcessing(
|
||||
$search,
|
||||
array('TITLE', 'DESCRIPTION'),
|
||||
TaxTableMap::TABLE_NAME,
|
||||
'TAX_ID'
|
||||
);
|
||||
}
|
||||
|
||||
if(null !== $taxes) {
|
||||
$search->groupByCountryId();
|
||||
|
||||
$originalCountryJoin = new Join();
|
||||
$originalCountryJoin->addExplicitCondition(TaxRuleCountryTableMap::TABLE_NAME, 'TAX_RULE_ID', null, TaxRuleCountryTableMap::TABLE_NAME, 'TAX_RULE_ID', 'origin');
|
||||
$originalCountryJoin->addExplicitCondition(TaxRuleCountryTableMap::TABLE_NAME, 'TAX_ID', null, TaxRuleCountryTableMap::TABLE_NAME, 'TAX_ID', 'origin');
|
||||
$originalCountryJoin->addExplicitCondition(TaxRuleCountryTableMap::TABLE_NAME, 'POSITION', null, TaxRuleCountryTableMap::TABLE_NAME, 'POSITION', 'origin');
|
||||
$originalCountryJoin->addExplicitCondition(TaxRuleCountryTableMap::TABLE_NAME, 'COUNTRY_ID', null, TaxRuleCountryTableMap::TABLE_NAME, 'COUNTRY_ID', 'origin', Criteria::NOT_EQUAL);
|
||||
$originalCountryJoin->setJoinType(Criteria::LEFT_JOIN);
|
||||
|
||||
$search->addJoinObject($originalCountryJoin, 's_to_o');
|
||||
$search->where('`origin`.`COUNTRY_ID`' . Criteria::EQUAL . '?', 64, \PDO::PARAM_INT);
|
||||
|
||||
$search->having('COUNT(*)=?', count($taxes), \PDO::PARAM_INT);
|
||||
|
||||
/* manage tax translation */
|
||||
$this->configureI18nProcessing(
|
||||
$search,
|
||||
array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'),
|
||||
CountryTableMap::TABLE_NAME,
|
||||
'COUNTRY_ID'
|
||||
);
|
||||
}
|
||||
|
||||
$taxRule = $this->getTax_rule();
|
||||
$search->filterByTaxRuleId($taxRule);
|
||||
|
||||
$search->orderByPosition(Criteria::ASC);
|
||||
|
||||
/* perform search */
|
||||
$taxRuleCountries = $this->search($search, $pagination);
|
||||
|
||||
$loopResult = new LoopResult($taxRuleCountries);
|
||||
|
||||
foreach ($taxRuleCountries as $taxRuleCountry) {
|
||||
|
||||
$loopResultRow = new LoopResultRow($loopResult, $taxRuleCountry, $this->versionable, $this->timestampable, $this->countable);
|
||||
|
||||
if(null !== $country) {
|
||||
$loopResultRow
|
||||
->set("TAX_RULE" , $taxRuleCountry->getTaxRuleId())
|
||||
->set("COUNTRY" , $taxRuleCountry->getCountryId())
|
||||
->set("TAX" , $taxRuleCountry->getTaxId())
|
||||
->set("POSITION" , $taxRuleCountry->getPosition())
|
||||
->set("TAX_TITLE" , $taxRuleCountry->getVirtualColumn(TaxTableMap::TABLE_NAME . '_i18n_TITLE'))
|
||||
->set("TAX_DESCRIPTION" , $taxRuleCountry->getVirtualColumn(TaxTableMap::TABLE_NAME . '_i18n_DESCRIPTION'))
|
||||
;
|
||||
}
|
||||
|
||||
if(null !== $taxes) {
|
||||
$loopResultRow
|
||||
->set("TAX_RULE" , $taxRuleCountry->getTaxRuleId())
|
||||
->set("COUNTRY" , $taxRuleCountry->getCountryId())
|
||||
->set("COUNTRY_TITLE" , $taxRuleCountry->getVirtualColumn(CountryTableMap::TABLE_NAME . '_i18n_TITLE'))
|
||||
->set("COUNTRY_CHAPO" , $taxRuleCountry->getVirtualColumn(CountryTableMap::TABLE_NAME . '_i18n_CHAPO'))
|
||||
->set("COUNTRY_DESCRIPTION" , $taxRuleCountry->getVirtualColumn(CountryTableMap::TABLE_NAME . '_i18n_DESCRIPTION'))
|
||||
->set("COUNTRY_POSTSCRIPTUM" , $taxRuleCountry->getVirtualColumn(CountryTableMap::TABLE_NAME . '_i18n_POSTSCRIPTUM'))
|
||||
;
|
||||
}
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
return $loopResult;
|
||||
}
|
||||
}
|
||||
@@ -1172,8 +1172,8 @@ INSERT INTO `tax_rule_i18n` (`id`, `locale`, `title`)
|
||||
|
||||
INSERT INTO `tax_rule_country` (`tax_rule_id`, `country_id`, `tax_id`, `position`, `created_at`, `updated_at`)
|
||||
VALUES
|
||||
(1, 64, 1, 2, NOW(), NOW()),
|
||||
(2, 64, 2, 2, NOW(), NOW());
|
||||
(1, 64, 1, 1, NOW(), NOW()),
|
||||
(2, 64, 2, 1, NOW(), NOW());
|
||||
|
||||
INSERT INTO `order_status`(`id`, `code`, `created_at`, `updated_at`) VALUES
|
||||
(1, 'not_paid', NOW(), NOW()),
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
{block name="main-content"}
|
||||
|
||||
{assign oder_tab {$smarty.get.tab|default:"data"}}
|
||||
{assign asked_country {$smarty.get.country|default:{country ask="default" attr="isoalpha3"}}}
|
||||
{assign asked_country {$smarty.get.country|default:{country ask="default" attr="id"}}}
|
||||
|
||||
<div class="taxes-rules edit-taxes-rules">
|
||||
|
||||
@@ -107,16 +107,21 @@
|
||||
<label for="" class="label-control">{intl l="Choose a country"} :</label>
|
||||
<select id="country-selector" data-toggle="selectpicker">
|
||||
{loop type="country" name="country-list"}
|
||||
<option value="{$ID}" {if $ISOALPHA3 == $asked_country}selected="selected"{/if}>{$TITLE}</option>
|
||||
<option value="{$ID}" {if $ID == $asked_country}selected="selected"{/if}>{$TITLE}</option>
|
||||
{/loop}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<p><strong>{intl l="Countries that have the same tax rule"} :<strong></p>
|
||||
<p class="lead">
|
||||
<span class="label label-info">Italy</span>
|
||||
<span class="label label-info">England</span>
|
||||
<span class="label label-info">Japan</span>
|
||||
|
||||
{loop type="tax-rule-country" name="same-country-list" tax_rule=$ID taxes="1,2,3"}
|
||||
<span class="label label-info">{$COUNTRY_TITLE}</span>
|
||||
{/loop}
|
||||
|
||||
{elseloop rel="same-country-list"}
|
||||
<span class="label label-danger">{intl l="NONE"}</span>
|
||||
{/elseloop}
|
||||
</p>
|
||||
|
||||
<div class="row">
|
||||
@@ -124,16 +129,29 @@
|
||||
|
||||
<div id="panel" class="panel panel-default place">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Create a tax rule</h3>
|
||||
<h3 class="panel-title">{intl l="Manage the tax rule taxes appliance order"}</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
|
||||
{assign lastPosition 0}
|
||||
{loop type="tax-rule-country" name="existing-tax-list" tax_rule=$ID country=$asked_country}
|
||||
{if $POSITION != $lastPosition}
|
||||
{assign lastPosition $POSITION}
|
||||
{if $LOOP_COUNT > 1}
|
||||
</div>
|
||||
{/if}
|
||||
<div class="drop-group droppable add-to-group">
|
||||
<p class="drop-message">
|
||||
<span class="glyphicon glyphicon-plus"></span>
|
||||
<span class="message">{intl l="Add tax to this group"}</span>
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
<div class="drag" data-id="{$TAX}">{$TAX_TITLE} - {$POSITION}</div>
|
||||
|
||||
{if $LOOP_COUNT == $LOOP_TOTAL}
|
||||
</div>
|
||||
{/if}
|
||||
{/loop}
|
||||
|
||||
</div>
|
||||
<div class="panel-footer droppable create-group">
|
||||
@@ -151,14 +169,12 @@
|
||||
|
||||
<div id="panel-list" class="panel panel-default take">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">List of taxes</h3>
|
||||
<h3 class="panel-title">Available taxes</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="draggable">Cras justo odio</div>
|
||||
<div class="draggable">Dapibus ac facilisis in</div>
|
||||
<div class="draggable">Morbi leo risus</div>
|
||||
<div class="draggable">Porta ac consectetur ac</div>
|
||||
<div class="draggable">Vestibulum at eros</div>
|
||||
{loop type="tax" name="tax-list" exclude_tax_rule=$ID country=$asked_country}
|
||||
<div class="draggable" data-id="{$ID}">{$TITLE}</div>
|
||||
{/loop}
|
||||
</div>
|
||||
<div class="panel-footer droppable remove-from-group">
|
||||
<p class="drop-message">
|
||||
@@ -244,7 +260,7 @@
|
||||
|
||||
$('.drag', $this).each(function(j){
|
||||
taxesRules[index][j] = [];
|
||||
taxesRules[index][j] = $(this).text();
|
||||
taxesRules[index][j] = $(this).data('id'); // retrieve with data
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user