tax rule edition

This commit is contained in:
Etienne Roudeix
2013-10-14 14:58:08 +02:00
parent 669be89896
commit 0ae9c562e4
2 changed files with 105 additions and 51 deletions

View File

@@ -32,6 +32,7 @@ use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Model\CountryQuery;
use Thelia\Model\Map\CountryTableMap;
use Thelia\Model\Map\TaxRuleCountryTableMap;
use Thelia\Model\Map\TaxTableMap;
@@ -58,8 +59,14 @@ class TaxRuleCountry extends BaseI18nLoop
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntTypeArgument('country'),
Argument::createIntListTypeArgument('taxes'),
Argument::createIntTypeArgument('country', null, true),
new Argument(
'ask',
new TypeCollection(
new Type\EnumType(array('taxes', 'countries'))
),
'taxes'
),
Argument::createIntTypeArgument('tax_rule', null, true)
);
}
@@ -73,40 +80,54 @@ class TaxRuleCountry extends BaseI18nLoop
{
$search = TaxRuleCountryQuery::create();
$ask = $this->getAsk();
$country = $this->getCountry();
$taxes = $this->getTaxes();
$taxRule = $this->getTax_rule();
if((null === $country && null === $taxes)) {
throw new \InvalidArgumentException('You must provide either `country` or `taxes` parameter in tax-rule-country loop');
}
if($ask === 'countries') {
$taxCountForOriginCountry = TaxRuleCountryQuery::create()->filterByCountryId($country)->count();
if((null === $country && null !== $taxes)) {
throw new \InvalidArgumentException('You must provide `country` parameter with `taxes` parameter in tax-rule-country loop');
}
if($taxCountForOriginCountry > 0) {
$search->groupByCountryId();
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);
$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 . '?', $country, \PDO::PARAM_INT);
$search->addJoinObject($originalCountryJoin, 's_to_o');
$search->where('`origin`.`COUNTRY_ID`' . Criteria::EQUAL . '?', $country, \PDO::PARAM_INT);
$search->having('COUNT(*)=?', $taxCountForOriginCountry, \PDO::PARAM_INT);
$search->having('COUNT(*)=?', count($taxes), \PDO::PARAM_INT);
$search->filterByTaxRuleId($taxRule);
/* manage tax translation */
$this->configureI18nProcessing(
$search,
array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'),
CountryTableMap::TABLE_NAME,
'COUNTRY_ID'
);
} elseif(null !== $country) {
/* manage tax translation */
$this->configureI18nProcessing(
$search,
array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'),
CountryTableMap::TABLE_NAME,
'COUNTRY_ID'
);
$search->addAscendingOrderByColumn('`' . CountryTableMap::TABLE_NAME . '_i18n_TITLE`');
} else {
$search = CountryQuery::create()
->joinTaxRuleCountry('trc', Criteria::LEFT_JOIN);
/* manage tax translation */
$this->configureI18nProcessing(
$search
);
$search->where('ISNULL(`trc`.`COUNTRY_ID`)');
$search->addAscendingOrderByColumn('i18n_TITLE');
}
} elseif($ask === 'taxes') {
$search->filterByCountryId($country);
/* manage tax translation */
@@ -116,13 +137,11 @@ class TaxRuleCountry extends BaseI18nLoop
TaxTableMap::TABLE_NAME,
'TAX_ID'
);
$search->filterByTaxRuleId($taxRule);
$search->orderByPosition(Criteria::ASC);
}
$taxRule = $this->getTax_rule();
$search->filterByTaxRuleId($taxRule);
$search->orderByPosition(Criteria::ASC);
/* perform search */
$taxRuleCountries = $this->search($search, $pagination);
@@ -132,16 +151,23 @@ class TaxRuleCountry extends BaseI18nLoop
$loopResultRow = new LoopResultRow($loopResult, $taxRuleCountry, $this->versionable, $this->timestampable, $this->countable);
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'))
;
}elseif(null !== $country) {
if($ask === 'countries') {
if($taxCountForOriginCountry > 0) {
$loopResultRow
->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'));
} else {
$loopResultRow
->set("COUNTRY" , $taxRuleCountry->getId())
->set("COUNTRY_TITLE" , $taxRuleCountry->getVirtualColumn('i18n_TITLE'))
->set("COUNTRY_CHAPO" , $taxRuleCountry->getVirtualColumn('i18n_CHAPO'))
->set("COUNTRY_DESCRIPTION" , $taxRuleCountry->getVirtualColumn('i18n_DESCRIPTION'))
->set("COUNTRY_POSTSCRIPTUM" , $taxRuleCountry->getVirtualColumn('i18n_POSTSCRIPTUM'));
}
} elseif($ask === 'taxes') {
$loopResultRow
->set("TAX_RULE" , $taxRuleCountry->getTaxRuleId())
->set("COUNTRY" , $taxRuleCountry->getCountryId())

View File

@@ -116,11 +116,11 @@
</div>
<p><strong>{intl l="Countries that have the same tax rule"} :<strong></p>
<p class="lead">
<p class="lead js-collapse" id="same_countries" data-collapse-height="86">
{$matchedCountries.first=$asked_country}
{loop type="tax-rule-country" name="same-country-list" tax_rule=$ID taxes="1,2,3" country=$asked_country}
{loop type="tax-rule-country" name="same-country-list" tax_rule=$ID ask="countries" country=$asked_country}
{$matchedCountries[]=$COUNTRY}
<span class="label label-info">{$COUNTRY_TITLE}</span>
{/loop}
@@ -129,6 +129,7 @@
<span class="label label-danger">{intl l="NONE"}</span>
{/elseloop}
</p>
<button data-collapse-block="same_countries" type="button" class="btn btn-info btn-sm btn-block js-collapse-btn" style="margin-bottom: 15px">See all countries</button>
<div class="row">
<div class="col-md-6">
@@ -234,11 +235,16 @@
<p>{intl l="Tax rule taxes will be update for the following countries :"}</p>
<div class="form-group">
<select name="{$name}" data-toggle="selectpicker" multiple>
{loop type="country" name="country-list"}
<option value='{$ID}' {if (!$value AND in_array($ID, $matchedCountries)) OR ($value AND in_array($ID, $value))}selected="selected"{/if}>{$TITLE}</option>
{/loop}
</select>
<div class="input-group">
<select id="countries-select" class="" name="{$name}" data-toggle="selectpicker" multiple>
{loop type="country" name="country-list"}
<option value='{$ID}' {if (!$value AND in_array($ID, $matchedCountries)) OR ($value AND in_array($ID, $value))}selected="selected"{/if}>{$TITLE}</option>
{/loop}
</select>
<span class="input-group-btn">
<button class="btn btn-primary js-uncheck-all" data-uncheck-select="countries-select">{intl l="uncheck all"}</button>
</span>
</div>
</div>
{/form_field}
@@ -283,6 +289,29 @@
$('#tax_list_update_dialog').modal();
{/if}
$('.js-collapse').each(function(k, v) {
var h = $(v).data('collapse-height');
if( $(v).height() > h ) {
$(v).css('overflow', 'hidden').css('height', h + 'px');
} else {
$('[data-collapse-block=' + $(v).attr('id') + ']').hide();
}
});
$('.js-collapse-btn').click(function(e) {
e.preventDefault();
var block = $(this).data('collapseBlock');
$('#' + block).css('overflow', 'initial').css('height', 'initial');
$(this).unbind().remove();
});
$('.js-uncheck-all').click(function(e) {
e.preventDefault();
var selectId = $(this).data('uncheckSelect');
$('#' + selectId).selectpicker('deselectAll');
});
{literal}
$('#country-selector').change(function(e) {
$('#country-selector-form').submit();
@@ -308,7 +337,6 @@
});
});
console.log(taxesRules);
$('#tax_list').val(JSON.stringify(taxesRules));
});