tax edition

This commit is contained in:
Etienne Roudeix
2013-10-07 17:18:38 +02:00
parent b84e863033
commit 942638281a
11 changed files with 419 additions and 88 deletions

View File

@@ -111,6 +111,8 @@
<form name="thelia.admin.featureav.creation" class="Thelia\Form\FeatureAvCreationForm"/>
<form name="thelia.admin.taxrule.modification" class="Thelia\Form\TaxRuleModificationForm"/>
<form name="thelia.admin.template.creation" class="Thelia\Form\TemplateCreationForm"/>
<form name="thelia.admin.template.modification" class="Thelia\Form\TemplateModificationForm"/>

View File

@@ -779,11 +779,11 @@
<!-- taxe rules management -->
<route id="admin.configuration.taxes-rules.default" path="/admin/configuration/taxes_rules">
<route id="admin.configuration.taxes-rules.list" 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">
<route id="admin.configuration.taxes-rules.update" path="/admin/configuration/taxes_rules/update/{tax_rule_id}/{country_isoalpha3}" methods="get">
<default key="_controller">Thelia\Controller\Admin\TaxRuleController::updateAction</default>
<requirement key="tax_rule_id">\d+</requirement>
</route>

View File

@@ -23,23 +23,154 @@
namespace Thelia\Controller\Admin;
/**
* Class TaxRuleController
* @package Thelia\Controller\Admin
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class TaxRuleController extends BaseAdminController
use Thelia\Core\Event\Tax\TaxRuleEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\TaxRuleCreationForm;
use Thelia\Form\TaxRuleModificationForm;
use Thelia\Model\CountryQuery;
use Thelia\Model\TaxRuleQuery;
class TaxRuleController extends AbstractCrudController
{
public function defaultAction()
public function __construct()
{
if (null !== $response = $this->checkAuth("admin.taxes-rules.view")) return $response;
return $this->render("taxes-rules", array("display_taxes_rules" => 20));
parent::__construct(
'taxrule',
'manual',
'order',
'admin.configuration.taxrule.view',
'admin.configuration.taxrule.create',
'admin.configuration.taxrule.update',
'admin.configuration.taxrule.delete',
TheliaEvents::TAX_RULE_CREATE,
TheliaEvents::TAX_RULE_UPDATE,
TheliaEvents::TAX_RULE_DELETE
);
}
public function updateAction($tax_rule_id){
return $this->render("tax-rule-edit", array(
"tax_rule_id" => $tax_rule_id
));
protected function getCreationForm()
{
return new TaxRuleCreationForm($this->getRequest());
}
protected function getUpdateForm()
{
return new TaxRuleModificationForm($this->getRequest());
}
protected function getCreationEvent($formData)
{
$event = new TaxRuleEvent();
/* @todo fill event */
return $event;
}
protected function getUpdateEvent($formData)
{
$event = new TaxRuleEvent();
/* @todo fill event */
return $event;
}
protected function getDeleteEvent()
{
$event = new TaxRuleEvent();
/* @todo fill event */
return $event;
}
protected function eventContainsObject($event)
{
return $event->hasTaxRule();
}
protected function hydrateObjectForm($object)
{
$data = array(
'id' => $object->getId(),
'locale' => $object->getLocale(),
'title' => $object->getTitle(),
'description' => $object->getDescription(),
);
// Setup the object form
return new TaxRuleModificationForm($this->getRequest(), "form", $data);
}
protected function getObjectFromEvent($event)
{
return $event->hasTaxRule() ? $event->getTaxRule() : null;
}
protected function getExistingObject()
{
return TaxRuleQuery::create()
->joinWithI18n($this->getCurrentEditionLocale())
->findOneById($this->getRequest()->get('tax_rule_id'));
}
protected function getObjectLabel($object)
{
return $object->getTitle();
}
protected function getObjectId($object)
{
return $object->getId();
}
protected function getViewArguments()
{
return array(
'tax_rule_id' => $this->getRequest()->get('tax_rule_id'),
'country_isoalpha3' => $this->getRequest()->get('country_isoalpha3'),
);
}
protected function renderListTemplate($currentOrder)
{
// We always return to the feature edition form
return $this->render(
'taxes-rules',
array()
);
}
protected function renderEditionTemplate()
{
/* check the country exists */
$country = CountryQuery::create()->findOneByIsoalpha3($this->getRequest()->get('country_isoalpha3'));
if(null === $country) {
$this->redirectToListTemplate();
}
// We always return to the feature edition form
return $this->render('tax-rule-edit', $this->getViewArguments());
}
protected function redirectToEditionTemplate()
{
// We always return to the feature edition form
$this->redirectToRoute(
"admin.configuration.taxes-rules.update",
$this->getViewArguments()
);
}
protected function redirectToListTemplate()
{
$this->redirectToRoute(
"admin.configuration.taxes-rules.list",
array()
);
}
}

View File

@@ -0,0 +1,53 @@
<?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\Event\Tax;
use Thelia\Core\Event\ActionEvent;
use Thelia\Model\TaxRule;
class TaxRuleEvent extends ActionEvent
{
protected $taxRule = null;
public function __construct(TaxRule $taxRule = null)
{
$this->taxRule = $taxRule;
}
public function hasTaxRule()
{
return ! is_null($this->taxRule);
}
public function getTaxRule()
{
return $this->taxRule;
}
public function setTaxRule(TaxRule $taxRule)
{
$this->taxRule = $taxRule;
return $this;
}
}

View File

@@ -503,6 +503,13 @@ final class TheliaEvents
const CHANGE_DEFAULT_CURRENCY = 'action.changeDefaultCurrency';
// -- Tax Rules management ---------------------------------------------
const TAX_RULE_CREATE = "action.createTaxRule";
const TAX_RULE_UPDATE = "action.updateTaxRule";
const TAX_RULE_DELETE = "action.deleteTaxRule";
const TAX_RULE_SET_DEFAULT = "action.setDefaultTaxRule";
// -- Product templates management -----------------------------------------
const TEMPLATE_CREATE = "action.createTemplate";

View File

@@ -113,6 +113,7 @@ class Country extends BaseI18nLoop
->set("CHAPO", $country->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $country->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM", $country->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("IS_DEFAULT", $country->getByDefault() === 1 ? "1" : "0")
->set("ISOCODE", $country->getIsocode())
->set("ISOALPHA2", $country->getIsoalpha2())
->set("ISOALPHA3", $country->getIsoalpha3());

View File

@@ -163,16 +163,16 @@ class DataAccessFunctions extends AbstractSmartyPlugin
public function countryDataAccess($params, $smarty)
{
if (array_key_exists('defaultCountry', self::$dataAccessCache)) {
$defaultCountry = self::$dataAccessCache['defaultCountry'];
} else {
$defaultCountry = CountryQuery::create()->findOneByByDefault(1);
self::$dataAccessCache['defaultCountry'] = $defaultCountry;
}
switch ($params["attr"]) {
switch ($params["ask"]) {
case "default":
return $defaultCountry->getId();
/*if (array_key_exists('defaultCountry', self::$dataAccessCache)) {
$defaultCountry = self::$dataAccessCache['defaultCountry'];
} else {
$defaultCountry = CountryQuery::create()->findOneByByDefault(1);
self::$dataAccessCache['defaultCountry'] = $defaultCountry;
}*/
$defaultCountry = CountryQuery::create()->filterByByDefault(1)->limit(1);
return $this->dataAccessWithI18n("defaultCountry", $params, $defaultCountry);
}
}

View File

@@ -0,0 +1,60 @@
<?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\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
class TaxRuleCreationForm extends BaseForm
{
protected function buildForm()
{
$this->formBuilder
->add("title" , "text" , array(
"constraints" => array(
new NotBlank()
),
"label" => Translator::getInstance()->trans("Title *"),
"label_attr" => array(
"for" => "title"
))
)
->add("locale" , "text" , array(
"constraints" => array(
new NotBlank()
))
)
->add("feature_id", "hidden", array(
"constraints" => array(
new NotBlank()
))
)
;
}
public function getName()
{
return "thelia_tax_rule_creation";
}
}

View File

@@ -0,0 +1,52 @@
<?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\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\GreaterThan;
class TaxRuleModificationForm extends FeatureCreationForm
{
use StandardDescriptionFieldsTrait;
protected function buildForm()
{
$this->formBuilder
->add("id", "hidden", array(
"constraints" => array(
new GreaterThan(
array('value' => 0)
)
)
))
;
// Add standard description fields
$this->addStandardDescFields();
}
public function getName()
{
return "thelia_tax_rule_modification";
}
}

View File

@@ -5,6 +5,9 @@
{block name="check-permissions"}admin.configuration.taxes-rules.edit{/block}
{block name="main-content"}
{assign oder_tab {$smarty.get.tab|default:"data"}}
<div class="taxes-rules edit-taxes-rules">
<div id="wrapper" class="container">
@@ -13,86 +16,106 @@
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
<li><a href="{url path='/admin/configuration'}">{intl l="Configuration"}</a></li>
<li><a href="{url path='/admin/configuration/taxes_rules'}">{intl l="Taxes rules"}</a></li>
<li>{intl l='Editing tax rule "%name"' name="{$TITLE}"}</li>
<li>{intl l='Editing tax rule'}</li>
</ul>
{loop type="tax-rule" name="tax-rule" id=$tax_rule_id}
<div class="row">
<div class="col-md-12 general-block-decorator clearfix">
<div class="title title-without-tabs">
{intl l="Edit tax rule $TITLE"}
</div>
<ul class="nav nav-tabs clearfix">
<li {if $oder_tab == 'data'}class="active"{/if}><a href="#data" data-tab-name="cart" data-toggle="tab"><span class="glyphicon glyphicon-shopping-cart"></span> {intl l="Description"}</a></li>
<li {if $oder_tab == 'taxes'}class="active"{/if}><a href="#taxes" data-tab-name="bill" data-toggle="tab"><span class="glyphicon glyphicon-list-alt"></span> {intl l="Taxes"}</a></li>
</ul>
<form action="" method="post">
<div class="tab-content">
<div class="tab-pane fade {if $oder_tab == 'data'}active in{/if}" id="data">
TODO
{form name="thelia.admin.taxrule.modification"}
<form method="POST" action="{url path="/admin/configuration/taxes_rules/update/$tax_rule_id/$country_isoalpha3"}" {form_enctype form=$form} >
</form>
{/form}
<div class="form-group">
<label for="" class="label-control">{intl l="Choose a country"} :</label>
<div class="input-group">
<select name="" id="" data-toggle="selectpicker">
<option value="">France</option>
<option value="">Spanish</option>
</select>
<span class="input-group-btn">
<button type="submit" class="btn btn-default btn-primary"><span class="glyphicon glyphicon-check"></span></button>
</span>
</div>
</div>
</form>
<div class="tab-pane fade {if $oder_tab == 'taxes'}active in{/if}" id="taxes">
<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>
</p>
<div class="col-md-12 title title-without-tabs">
{intl l="Manage taxes"}
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<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 == $country_isoalpha3}selected="selected"{/if}>{$TITLE}</option>
{/loop}
</select>
</div>
<div id="panel" class="panel panel-default place">
<div class="panel-heading">
<h3 class="panel-title">Create a tax rule</h3>
</div>
<div class="panel-body">
<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>
</p>
<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>
<div class="row">
<div class="col-md-6">
<div id="panel" class="panel panel-default place">
<div class="panel-heading">
<h3 class="panel-title">Create a tax rule</h3>
</div>
<div class="panel-body">
<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>
</div>
</div>
<div class="panel-footer droppable create-group">
<p class="drop-message">
<span class="glyphicon glyphicon-plus"></span>
<span class="message">{intl l="Drop tax here to create a tax group"}</span>
</p>
</div>
</div>
</div>
<div class="panel-footer droppable create-group">
<p class="drop-message">
<span class="glyphicon glyphicon-plus"></span>
<span class="message">{intl l="Drop tax here to create a tax group"}</span>
</p>
</div>
</div>
<a href="#confirmation_dialog" data-toggle="modal" id="apply-taxes-rules" class="btn btn-default btn-primary btn-block"><span class="glyphicon glyphicon-check"></span> {intl l="Apply"}</a>
<a href="#confirmation_dialog" data-toggle="modal" id="apply-taxes-rules" class="btn btn-default btn-primary btn-block"><span class="glyphicon glyphicon-check"></span> {intl l="Apply"}</a>
</div>
<div class="col-md-6">
<div id="panel-list" class="panel panel-default take">
<div class="panel-heading">
<h3 class="panel-title">List of 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>
</div>
<div class="panel-footer droppable remove-from-group">
<p class="drop-message">
<span class="glyphicon glyphicon-minus"></span>
<span class="message">{intl l="Drop tax here to delete from group"}</span>
</p>
<div class="col-md-6">
<div id="panel-list" class="panel panel-default take">
<div class="panel-heading">
<h3 class="panel-title">List of 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>
</div>
<div class="panel-footer droppable remove-from-group">
<p class="drop-message">
<span class="glyphicon glyphicon-minus"></span>
<span class="message">{intl l="Drop tax here to delete from group"}</span>
</p>
</div>
</div>
</div>
</div>
@@ -102,6 +125,8 @@
</div>
</div>
{/loop}
</div>
{* Confirmation dialog *}

View File

@@ -49,7 +49,7 @@
<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>
<a class="btn btn-default btn-xs" title="{intl l='Change this tax rule'}" href="{url path="/admin/configuration/taxes_rules/update/$ID/{country ask="default" attr="isoalpha3"}"}"><span class="glyphicon glyphicon-edit"></span></a>
{/loop}
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.taxes-rules.change"}