[*] BO #PSFV-94 : Added AdminTaxRulesGroupController
This commit is contained in:
@@ -970,3 +970,15 @@ if (Tools::isSubmit('getParentCategoriesId') AND $id_category = Tools::getValue(
|
||||
die(Tools::jsonEncode($output));
|
||||
}
|
||||
|
||||
/* Update attribute */
|
||||
if (Tools::isSubmit('ajaxUpdateTaxRule'))
|
||||
{
|
||||
$id_tax_rule = Tools::getValue('id_tax_rule');
|
||||
$tax_rules = new TaxRule((int)$id_tax_rule);
|
||||
$output = array();
|
||||
foreach($tax_rules as $key => $result)
|
||||
$output[$key] = $result;
|
||||
die(Tools::jsonEncode($output));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,8 @@
|
||||
{rdelim});
|
||||
</script>
|
||||
<script type="text/javascript" src="../js/form.js"></script>
|
||||
{block name="script"}
|
||||
{/block}
|
||||
{/if}
|
||||
|
||||
{if isset($toolbar) && $toolbar}
|
||||
@@ -70,7 +72,7 @@
|
||||
{if isset($fields.title)}<h2>{$fields.title}</h2>{/if}
|
||||
<form class="defaultForm" action="{$current}&{$submit_action}=1&token={$token}" method="post" enctype="multipart/form-data">
|
||||
{if $form_id}
|
||||
<input type="hidden" name="id_{$table}" value="{$form_id}" />
|
||||
<input type="hidden" name="id_{$table}" id="id_{$table}" value="{$form_id}" />
|
||||
{/if}
|
||||
<fieldset>
|
||||
{foreach $fields as $key => $field}
|
||||
@@ -131,7 +133,11 @@
|
||||
{$input.required = false}
|
||||
{$input.p = null}
|
||||
{else}
|
||||
<select name="{$input.name}" id="{$input.name}" {if isset($input.multiple)}multiple="multiple" {/if}{if isset($input.onchange)}onchange="{$input.onchange}"{/if}>
|
||||
<select name="{$input.name}"
|
||||
id="{if isset($input.id)}{$input.id}{else}{$input.name}{/if}"
|
||||
{if isset($input.multiple)}multiple="multiple" {/if}
|
||||
{if isset($input.size)}size="{$input.size}"{/if}
|
||||
{if isset($input.onchange)}onchange="{$input.onchange}"{/if}>
|
||||
{if isset($input.options.default)}
|
||||
<option value="{$input.options.default.value}">{$input.options.default.label}</option>
|
||||
{/if}
|
||||
@@ -156,7 +162,6 @@
|
||||
<option value="{$option[$input.options.id]}"
|
||||
{if isset($input.multiple)}
|
||||
{foreach $fields_value[$input.name] as $field_value}
|
||||
{$field_value}
|
||||
{if $field_value == $option[$input.options.id]}selected="selected"{/if}
|
||||
{/foreach}
|
||||
{else}
|
||||
@@ -281,7 +286,10 @@
|
||||
{/foreach}
|
||||
{elseif $key == 'submit'}
|
||||
<div class="margin-form">
|
||||
<input type="submit" value="{$field.title}" name="{$submit_action}" {if isset($field.class)}class="{$field.class}"{/if} />
|
||||
<input type="submit"
|
||||
value="{$field.title}"
|
||||
name="{$submit_action}{if isset($field.stay) && $field.stay}AndStay{/if}"
|
||||
{if isset($field.class)}class="{$field.class}"{/if} />
|
||||
</div>
|
||||
{/if}
|
||||
{/foreach}
|
||||
|
||||
@@ -37,7 +37,18 @@
|
||||
</table>
|
||||
<input type="hidden" name="token" value="{$token}" />
|
||||
</form>
|
||||
|
||||
{*
|
||||
if (isset($this->_includeTab) AND sizeof($this->_includeTab))
|
||||
echo '<br /><br />';
|
||||
*}
|
||||
*}
|
||||
|
||||
{if !$no_back}
|
||||
<br />
|
||||
{if $back}
|
||||
<a href="{$back}"><img src="../img/admin/arrow2.gif" />{l s='Back'}</a>
|
||||
{else}
|
||||
<a href="{$current}&token={$token}"><img src="../img/admin/arrow2.gif" />{l s='Back to list'}</a>
|
||||
{/if}
|
||||
<br />
|
||||
{/if}
|
||||
@@ -0,0 +1,26 @@
|
||||
{*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 9197 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
<a onclick="loadTaxRule('{$id}'); return false;" href="#"><img src="../img/admin/edit.gif" alt="{$action}" title="{$action}" /></a>
|
||||
@@ -0,0 +1,126 @@
|
||||
{*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 9608 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
<tbody>
|
||||
{foreach $list AS $index => $tr}
|
||||
<tr
|
||||
{if $is_dnd_identifier}id="tr_{$id_category}_{$tr.$identifier}_{$tr.position['position']}"{/if}
|
||||
{if $index is odd}class="alt_row"{/if}
|
||||
{if isset($tr.color) && $color_on_bg}style="background-color: {$tr.color}"{/if}
|
||||
>
|
||||
<td class="center">
|
||||
{if $bulk_actions}
|
||||
{assign var=bulkActionPossible value=true}
|
||||
{foreach $list_skip_actions as $key => $value}
|
||||
{if in_array($tr.$identifier, $value) == true}
|
||||
{assign var=bulkActionPossible value=false}
|
||||
{/if}
|
||||
{/foreach}
|
||||
{if $bulkActionPossible == true}
|
||||
<input type="checkbox" name="{$table}Box[]" value="{$tr.$identifier}" class="noborder" />
|
||||
{/if}
|
||||
{/if}
|
||||
</td>
|
||||
{foreach $fields_display AS $key => $params}
|
||||
<td
|
||||
{if isset($params.position)}
|
||||
id="td_{if $id_category}{$id_category}{else}0{/if}_{$tr.$identifier}"
|
||||
{/if}
|
||||
class="{if !$no_link}pointer{/if}
|
||||
{if isset($params.position) && $order_by == 'position'} dragHandle{/if}
|
||||
{if isset($params.align)} {$params.align}{/if}"
|
||||
|
||||
{if (!isset($params.position) && !$no_link)}
|
||||
onclick="document.location = '{$current_index}&{$identifier}={$tr.$identifier}{if $view}&view{else}&update{/if}{$table}&token={$token}'">{if isset($params.prefix)}{$params.prefix}{/if}
|
||||
{else}
|
||||
>
|
||||
{/if}
|
||||
{if isset($params.active)}
|
||||
{$tr.$key}
|
||||
{elseif isset($params.activeVisu)}
|
||||
<img src="../img/admin/{if $tr.$key}enabled.gif{else}disabled.gif{/if}"
|
||||
alt="{if $tr.$key}{l s='Enabled'}{else}{l s='Disabled'}{/if}" title="{if $tr.$key}{l s='Enabled'}{else}{l s='Disabled'}{/if}" />
|
||||
{elseif isset($params.position)}
|
||||
{if $order_by == 'position' && $order_way != 'DESC'}
|
||||
<a href="{$tr.$key.position_url_down}" {if !($tr.$key.position != $positions[count($positions) - 1])}style="display: none;"{/if}>
|
||||
<img src="../img/admin/{if $order_way == 'ASC'}down{else}up{/if}.gif" alt="{l s='Down'}" title="{l s='Down'}" />
|
||||
</a>
|
||||
|
||||
<a href="{$tr.$key.position_url_up}" {if !($tr.$key.position != $positions.0)}style="display: none;"{/if}>
|
||||
<img src="../img/admin/{if $order_way == 'ASC'}up{else}down{/if}.gif" alt="{l s='Up'}" title="{l s='Up'}" />
|
||||
</a>
|
||||
{else}
|
||||
{$tr.$key.position + 1}
|
||||
{/if}
|
||||
{elseif isset($params.image)}
|
||||
{$tr.$key}
|
||||
{elseif (isset($params.icon))}
|
||||
<img src="../img/admin/{$tr[$key]}" alt="{$tr[$key]}" title="{$tr[$key]}" />
|
||||
{elseif isset($params.price)}
|
||||
{$tr.$key}
|
||||
{elseif isset($params.float)}
|
||||
{$tr.$key}
|
||||
{elseif isset($params.type) && $params.type == 'date'}
|
||||
{$tr.$key}
|
||||
{elseif isset($params.type) && $params.type == 'datetime'}
|
||||
{$tr.$key}
|
||||
{elseif isset($params.callback)}
|
||||
{$tr.$key}
|
||||
{elseif isset($tr.$key)}
|
||||
{if $key == 'behavior'}
|
||||
{if $tr.$key == 0}
|
||||
{l s='This tax only'}
|
||||
{elseif $tr.$key == 1}
|
||||
{l s='Compute with others'}
|
||||
{elseif $tr.$key == 2}
|
||||
{l s='One after another'}
|
||||
{/if}
|
||||
{elseif $key == 'rate'}
|
||||
{$tr.$key|string_format:"%.2f"}%
|
||||
{else}
|
||||
{$tr.$key|escape:'htmlall':'UTF-8'}
|
||||
{/if}
|
||||
{else}
|
||||
--
|
||||
{/if}
|
||||
{if isset($params.suffix)}{$params.suffix}{/if}
|
||||
</td>
|
||||
{/foreach}
|
||||
|
||||
{if $shop_link_type}
|
||||
<td class="center" {if $name != $tr.shop_name}title="{$tr.shop_name}"{/if}>{if isset($tr.shop_short_name)}{$tr.shop_short_name}{else}{$tr.shop_name}{/if}</td>
|
||||
{/if}
|
||||
{if $has_actions}
|
||||
<td class="center" style="white-space: nowrap;">
|
||||
{foreach $actions AS $action}
|
||||
{if isset($tr.$action)}
|
||||
{$tr.$action}
|
||||
{/if}
|
||||
{/foreach}
|
||||
</td>
|
||||
{/if}
|
||||
</tr>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
@@ -0,0 +1,159 @@
|
||||
{*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 8971 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
{extends file="../helper/form/form.tpl"}
|
||||
|
||||
{block name="label"}
|
||||
{if $input.type == 'select' && $input.name == 'country[]'}
|
||||
<div id="add_new_tax_rule" style="display:none">
|
||||
<label>{$input.label} </label>
|
||||
{else}
|
||||
{if isset($input.label)}
|
||||
<label
|
||||
{if $input.name == 'states[]'}
|
||||
id="state-label" style="display: none;"
|
||||
{elseif $input.name == 'zipcode'}
|
||||
id="zipcode-label"
|
||||
{/if}
|
||||
>{$input.label} </label>
|
||||
{/if}
|
||||
{/if}
|
||||
{/block}
|
||||
|
||||
{block name="start_field_block"}
|
||||
<div class="margin-form"
|
||||
{if $input.name == 'states[]'}
|
||||
id="state-select" style="display: none;"
|
||||
{/if}
|
||||
>
|
||||
{/block}
|
||||
|
||||
{block name="end_field_block"}
|
||||
{if $input.type == 'submit'}
|
||||
</div>
|
||||
</div>
|
||||
{else}
|
||||
</div>
|
||||
{/if}
|
||||
{/block}
|
||||
|
||||
{block name="script"}
|
||||
<script type="text/javascript">
|
||||
|
||||
$(document).ready(function() {
|
||||
$('#country').click(function() {
|
||||
populateStates($(this).val(), '');
|
||||
});
|
||||
|
||||
$('.toolbar_btn').click(function() {
|
||||
initForm();
|
||||
$('#add_new_tax_rule').slideToggle();
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
function populateStates(id_country, id_state)
|
||||
{
|
||||
if ($("#country option:selected").size() > 1)
|
||||
{
|
||||
$("#zipcode-label").hide();
|
||||
$("#zipcode").hide();
|
||||
|
||||
$("#state-select").hide();
|
||||
$("#state-label").hide();
|
||||
} else {
|
||||
$.ajax({
|
||||
url: "ajax.php",
|
||||
cache: false,
|
||||
data: "ajaxStates=1&id_country="+id_country+"&id_state="+id_state+"&empty_value={l s='All'}",
|
||||
success: function(html){
|
||||
if (html == "false")
|
||||
{
|
||||
$("#state-label").hide();
|
||||
$("#state-select").hide();
|
||||
$("#states").html('');
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#state-label").show();
|
||||
$("#state-select").show();
|
||||
$("#states").html(html);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$("#zipcode-label").show();
|
||||
$("#zipcode").show();
|
||||
}
|
||||
}
|
||||
|
||||
function loadTaxRule(id_tax_rule)
|
||||
{
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'ajax.php',
|
||||
async: true,
|
||||
dataType: 'json',
|
||||
data: 'ajaxStates=1&ajaxUpdateTaxRule=1&id_tax_rule='+id_tax_rule,
|
||||
success: function(data){
|
||||
$('#add_new_tax_rule').show();
|
||||
$('#id_tax_rule').val(data.id);
|
||||
$('#country').val(data.id_country);
|
||||
$('#state').val(data.id_state);
|
||||
|
||||
zipcode = 0;
|
||||
if (data.zipcode_from != 0)
|
||||
{
|
||||
zipcode = data.zipcode_from;
|
||||
|
||||
if (data.zipcode_to != 0)
|
||||
zipcode = zipcode +"-"+data.zipcode_to
|
||||
}
|
||||
|
||||
$('#zipcode').val(zipcode);
|
||||
$('#behavior').val(data.behavior);
|
||||
$('#id_tax').val(data.id_tax);
|
||||
$('#description').val(data.description);
|
||||
|
||||
populateStates(data.id_country, data.id_state);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function initForm()
|
||||
{
|
||||
$('#id_tax_rule').val('');
|
||||
$('#country').val(0);
|
||||
$('#state').val(0);
|
||||
$('#zipcode').val(0);
|
||||
$('#behavior').val(0);
|
||||
$('#tax').val(0);
|
||||
$('#description').val('');
|
||||
|
||||
populateStates(0,0);
|
||||
}
|
||||
|
||||
</script>
|
||||
{/block}
|
||||
@@ -1198,16 +1198,19 @@ class AdminControllerCore extends Controller
|
||||
$helper->shopLink = $this->shopLink;
|
||||
$helper->shopLinkType = $this->shopLinkType;
|
||||
$helper->identifier = $this->identifier;
|
||||
$helper->tpl_folder = $this->tpl_folder;
|
||||
$helper->token = $this->token;
|
||||
$helper->specificConfirmDelete = $this->specificConfirmDelete;
|
||||
$helper->imageType = $this->imageType;
|
||||
$helper->no_add = isset($this->no_add) ? $this->no_add : false;
|
||||
$helper->simple_header = isset($this->simple_header) ? $this->simple_header : false;
|
||||
$helper->no_link = $this->list_no_link;
|
||||
$helper->colorOnBackground = $this->colorOnBackground;
|
||||
$helper->no_back = isset($this->no_back) ? $this->no_back : true;
|
||||
|
||||
// For each action, try to add the corresponding skip elements list
|
||||
$helper->list_skip_actions = $this->list_skip_actions;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1234,6 +1237,7 @@ class AdminControllerCore extends Controller
|
||||
$helper->allow_employee_form_lang = $this->allow_employee_form_lang;
|
||||
$helper->fields_value = $this->getFieldsValue($this->object);
|
||||
$helper->toolbar_btn = $this->toolbar_btn;
|
||||
$helper->no_back = isset($this->no_back) ? $this->no_back : false;
|
||||
if ($this->tabAccess['view'])
|
||||
{
|
||||
if (Tools::getValue('back'))
|
||||
|
||||
+19
-2
@@ -55,6 +55,9 @@ class HelperListCore extends Helper
|
||||
|
||||
protected $deleted = 0;
|
||||
|
||||
/** @var string Folder of controller */
|
||||
public $tpl_folder;
|
||||
|
||||
/** @var array $cache_lang use to cache texts in current language */
|
||||
public static $cache_lang = array();
|
||||
|
||||
@@ -109,6 +112,12 @@ class HelperListCore extends Helper
|
||||
/** @var boolean ask for simple header : no filters, no paginations and no sorting */
|
||||
public $simple_header = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* Usage : Set the value to false if you want to simply display the back button
|
||||
*/
|
||||
public $no_back = true;
|
||||
|
||||
/**
|
||||
* Return an html list given the data to fill it up
|
||||
*
|
||||
@@ -388,10 +397,16 @@ class HelperListCore extends Helper
|
||||
$this->context->smarty->assign(array(
|
||||
'href' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&update'.$this->table.'&token='.($token != null ? $token : $this->token),
|
||||
'action' => self::$cache_lang['Edit'],
|
||||
'id' => (int)$id
|
||||
));
|
||||
|
||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/helper/list/list_action_edit.tpl');
|
||||
if (file_exists($this->context->smarty->template_dir[0].'/'.$this->tpl_folder.'list_action_edit.tpl'))
|
||||
$tpl = $this->context->smarty->template_dir[0].'/'.$this->tpl_folder.'list_action_edit.tpl';
|
||||
else
|
||||
$tpl = $this->context->smarty->template_dir[0].'/helper/list/list_action_edit.tpl';
|
||||
|
||||
return $this->context->smarty->fetch($tpl);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -540,7 +555,9 @@ class HelperListCore extends Helper
|
||||
'table_dnd' => isset($table_dnd) ? $table_dnd : null,
|
||||
'name' => isset($name) ? $name : null,
|
||||
'name_id' => isset($name_id) ? $name_id : null,
|
||||
'toolbar' => $this->toolbar
|
||||
'toolbar' => $this->toolbar,
|
||||
'back' => Tools::getValue('back'),
|
||||
'no_back' => $this->no_back
|
||||
));
|
||||
|
||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/'.$this->header_tpl);
|
||||
|
||||
+10
-10
@@ -51,17 +51,17 @@ class TaxRuleCore extends ObjectModel
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
$this->validateFields();
|
||||
$fields['id_tax_rules_group'] = (int)$this->id_tax_rules_group;
|
||||
$fields['id_country'] = (int)$this->id_country;
|
||||
$fields['id_state'] = (int)$this->id_state;
|
||||
$fields['zipcode_from'] = (int)$this->zipcode_from;
|
||||
$fields['zipcode_to'] = (int)$this->zipcode_to;
|
||||
$fields['behavior'] = (int)$this->behavior;
|
||||
$fields['id_tax'] = (int)$this->id_tax;
|
||||
$fields['description'] = $this->description;
|
||||
$this->validateFields();
|
||||
$fields['id_tax_rules_group'] = (int)$this->id_tax_rules_group;
|
||||
$fields['id_country'] = (int)$this->id_country;
|
||||
$fields['id_state'] = (int)$this->id_state;
|
||||
$fields['zipcode_from'] = (int)$this->zipcode_from;
|
||||
$fields['zipcode_to'] = (int)$this->zipcode_to;
|
||||
$fields['behavior'] = (int)$this->behavior;
|
||||
$fields['id_tax'] = (int)$this->id_tax;
|
||||
$fields['description'] = $this->description;
|
||||
|
||||
return $fields;
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public static function deleteByGroupId($id_group)
|
||||
|
||||
@@ -31,14 +31,14 @@ class TaxRulesGroupCore extends ObjectModel
|
||||
public $name;
|
||||
|
||||
/** @var bool active state */
|
||||
public $active;
|
||||
public $active;
|
||||
|
||||
protected $fieldsRequired = array('name');
|
||||
protected $fieldsSize = array('name' => 64);
|
||||
protected $fieldsValidate = array('name' => 'isGenericName');
|
||||
protected $fieldsRequired = array('name');
|
||||
protected $fieldsSize = array('name' => 64);
|
||||
protected $fieldsValidate = array('name' => 'isGenericName');
|
||||
|
||||
protected $table = 'tax_rules_group';
|
||||
protected $identifier = 'id_tax_rules_group';
|
||||
protected $table = 'tax_rules_group';
|
||||
protected $identifier = 'id_tax_rules_group';
|
||||
|
||||
protected static $_taxes = array();
|
||||
|
||||
@@ -46,7 +46,7 @@ class TaxRulesGroupCore extends ObjectModel
|
||||
{
|
||||
$this->validateFields();
|
||||
$fields['name'] = ($this->name);
|
||||
$fields['active'] = (int)($this->active);
|
||||
$fields['active'] = (int)$this->active;
|
||||
return $fields;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ class TaxRulesGroupCore extends ObjectModel
|
||||
);
|
||||
|
||||
$res = array();
|
||||
foreach ($rows AS $row)
|
||||
foreach ($rows as $row)
|
||||
$res[$row['id_tax_rules_group']] = $row['rate'];
|
||||
|
||||
return $res;
|
||||
@@ -113,7 +113,7 @@ class TaxRulesGroupCore extends ObjectModel
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
$rate = 0;
|
||||
foreach (TaxRulesGroup::getTaxes($id_tax_rules_group, $id_country, $id_state, $zipcode) AS $tax)
|
||||
foreach (TaxRulesGroup::getTaxes($id_tax_rules_group, $id_country, $id_state, $zipcode) as $tax)
|
||||
$rate += (float)$tax->rate;
|
||||
|
||||
return $rate;
|
||||
|
||||
@@ -0,0 +1,428 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 8971 $
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class AdminTaxRulesGroupControllerCore extends AdminController
|
||||
{
|
||||
public $tax_rule;
|
||||
public $selected_countries = array();
|
||||
public $selected_states = array();
|
||||
public $_errors_tax_rule;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->table = 'tax_rules_group';
|
||||
$this->className = 'TaxRulesGroup';
|
||||
$this->lang = false;
|
||||
|
||||
$this->context = Context::getContext();
|
||||
|
||||
$this->fieldsDisplay = array(
|
||||
'id_tax_rules_group' => array(
|
||||
'title' => $this->l('ID'),
|
||||
'width' => 25
|
||||
),
|
||||
'name' => array(
|
||||
'title' => $this->l('Name'),
|
||||
'width' => 140
|
||||
),
|
||||
'active' => array(
|
||||
'title' => $this->l('Enabled'),
|
||||
'width' => 25,
|
||||
'active' => 'status',
|
||||
'type' => 'bool',
|
||||
'orderby' => false
|
||||
)
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function initList()
|
||||
{
|
||||
$this->addRowAction('edit');
|
||||
$this->addRowAction('delete');
|
||||
|
||||
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
|
||||
|
||||
return parent::initList();
|
||||
}
|
||||
|
||||
public function initRulesList($id_group)
|
||||
{
|
||||
$this->table = 'tax_rule';
|
||||
$this->identifier = 'id_tax_rule';
|
||||
$this->lang = false;
|
||||
$this->simple_header = true;
|
||||
$this->toolbar_btn = null;
|
||||
$this->no_back = false;
|
||||
$this->list_no_link = true;
|
||||
|
||||
$this->fieldsDisplay = array(
|
||||
'id_tax_rule' => array(
|
||||
'title' => $this->l('ID'),
|
||||
'width' => 25
|
||||
),
|
||||
'country_name' => array(
|
||||
'title' => $this->l('Country'),
|
||||
'width' => 140
|
||||
),
|
||||
'state_name' => array(
|
||||
'title' => $this->l('State'),
|
||||
'width' => 140
|
||||
),
|
||||
'zipcode' => array(
|
||||
'title' => $this->l('ZipCodes'),
|
||||
'width' => 25,
|
||||
),
|
||||
'behavior' => array(
|
||||
'title' => $this->l('Behavior'),
|
||||
'width' => 25,
|
||||
),
|
||||
'rate' => array(
|
||||
'title' => $this->l('Tax'),
|
||||
'width' => 25,
|
||||
),
|
||||
'description' => array(
|
||||
'title' => $this->l('Description'),
|
||||
'width' => 25,
|
||||
)
|
||||
);
|
||||
|
||||
$this->addRowAction('edit');
|
||||
$this->addRowAction('delete');
|
||||
|
||||
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
|
||||
|
||||
$this->_select = '
|
||||
c.`name` AS country_name,
|
||||
s.`name` AS state_name,
|
||||
CONCAT_WS(" - ", a.`zipcode_from`, a.`zipcode_to`) AS zipcode,
|
||||
t.rate';
|
||||
|
||||
$this->_join = '
|
||||
LEFT JOIN `'._DB_PREFIX_.'country_lang` c
|
||||
ON (a.`id_country` = c.`id_country` AND id_lang = '.(int)$this->context->language->id.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'state` s
|
||||
ON (a.`id_state` = s.`id_state`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` t
|
||||
ON (a.`id_tax` = t.`id_tax`)';
|
||||
$this->_where = 'AND `id_tax_rules_group` = '.(int)$id_group;
|
||||
|
||||
return parent::initList();
|
||||
}
|
||||
|
||||
public function initForm()
|
||||
{
|
||||
$this->fields_form = array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Tax Rules'),
|
||||
'image' => '../img/admin/dollar.gif'
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Name:'),
|
||||
'name' => 'name',
|
||||
'size' => 33,
|
||||
'required' => true,
|
||||
'hint' => $this->l('Invalid characters:').' <>;=#{}'
|
||||
),
|
||||
array(
|
||||
'type' => 'radio',
|
||||
'label' => $this->l('Enable:'),
|
||||
'name' => 'active',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'active_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'active_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save and stay'),
|
||||
'class' => 'button',
|
||||
'stay' => true
|
||||
)
|
||||
);
|
||||
|
||||
if (!($obj = $this->loadObject(true)))
|
||||
return;
|
||||
if (!isset($obj->id))
|
||||
{
|
||||
$this->no_back = false;
|
||||
$content = parent::initForm();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->no_back = true;
|
||||
$this->toolbar_btn['new'] = array(
|
||||
'href' => '#',
|
||||
'desc' => $this->l('Add new tax rule')
|
||||
);
|
||||
$content = parent::initForm();
|
||||
$content .= $this->initRuleForm();
|
||||
|
||||
// We change the variable $ tpl_folder to avoid the overhead calling the file in list_action_edit.tpl in intList ();
|
||||
$this->tpl_folder = 'tax_rules/';
|
||||
|
||||
$content .= $this->initRulesList((int)$obj->id);
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function initRuleForm()
|
||||
{
|
||||
$this->fields_form = array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('New tax rule'),
|
||||
'image' => '../img/admin/dollar.gif'
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Country:'),
|
||||
'name' => 'country[]',
|
||||
'id' => 'country',
|
||||
'multiple' => true,
|
||||
'size' => 15,
|
||||
'options' => array(
|
||||
'query' => Country::getCountries((int)$this->context->language->id),
|
||||
'id' => 'id_country',
|
||||
'name' => 'name',
|
||||
'default' => array(
|
||||
'value' => 0,
|
||||
'label' => $this->l('All')
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('State:'),
|
||||
'name' => 'states[]',
|
||||
'id' => 'states',
|
||||
'multiple' => true,
|
||||
'size' => 5,
|
||||
'options' => array(
|
||||
'query' => array(),
|
||||
'id' => 'id_state',
|
||||
'name' => 'name',
|
||||
'default' => array(
|
||||
'value' => 0,
|
||||
'label' => $this->l('All')
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'action'
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'id_tax_rules_group'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('ZipCode range:'),
|
||||
'name' => 'zipcode',
|
||||
'required' => false,
|
||||
'hint' => $this->l('You can define a range (eg: 75000-75015) or a simple zipcode')
|
||||
),
|
||||
array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Behavior:'),
|
||||
'name' => 'behavior',
|
||||
'required' => false,
|
||||
'options' => array(
|
||||
'query' => array(
|
||||
array(
|
||||
'id' => 0,
|
||||
'name' => $this->l('This tax only')
|
||||
),
|
||||
array(
|
||||
'id' => 1,
|
||||
'name' => $this->l('Combine')
|
||||
),
|
||||
array(
|
||||
'id' => 2,
|
||||
'name' => $this->l('One After Another')
|
||||
)
|
||||
),
|
||||
'id' => 'id',
|
||||
'name' => 'name'
|
||||
),
|
||||
'hint' => array(
|
||||
$this->l('Define the behavior if an address matches multiple rules:'),
|
||||
'<b>'.$this->l('This Tax Only:').'</b> '.$this->l('Will apply only this tax'),
|
||||
'<b>'.$this->l('Combine:').'</b> '.$this->l('Combine taxes (eg: 10% + 5% => 15%)'),
|
||||
'<b>'.$this->l('One After Another:').'</b> '.$this->l('Apply taxes one after another (eg: 100€ + 10% => 110€ + 5% => 115.5€)')
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Tax:'),
|
||||
'name' => 'id_tax',
|
||||
'required' => false,
|
||||
'options' => array(
|
||||
'query' => Tax::getTaxes((int)$this->context->language->id),
|
||||
'id' => 'id_tax',
|
||||
'name' => 'name',
|
||||
'default' => array(
|
||||
'value' => 'name',
|
||||
'label' => $this->l('No Tax')
|
||||
)
|
||||
),
|
||||
'p' => $this->l('(Total tax:').'9%)'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Description:'),
|
||||
'name' => 'description',
|
||||
'size' => 40,
|
||||
)
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save and stay'),
|
||||
'class' => 'button',
|
||||
'stay' => true
|
||||
)
|
||||
);
|
||||
|
||||
if (!($obj = $this->loadObject(true)))
|
||||
return;
|
||||
|
||||
$this->fields_value = array(
|
||||
'action' => 'create_rule',
|
||||
'id_tax_rules_group' => $obj->id,
|
||||
'id_tax_rule' => ''
|
||||
);
|
||||
|
||||
$this->getlanguages();
|
||||
$helper = new HelperForm();
|
||||
|
||||
// Check if form template has been overriden
|
||||
if (file_exists($this->context->smarty->template_dir[0].'/'.$this->tpl_folder.'form_new.tpl'))
|
||||
$helper->tpl = $this->tpl_folder.'form_new.tpl';
|
||||
|
||||
$helper->currentIndex = self::$currentIndex;
|
||||
$helper->token = $this->token;
|
||||
$helper->table = 'tax_rule';
|
||||
$helper->identifier = 'id_tax_rule';
|
||||
$helper->id = $obj->id;
|
||||
$helper->languages = $this->_languages;
|
||||
$helper->default_form_language = $this->default_form_language;
|
||||
$helper->allow_employee_form_lang = $this->allow_employee_form_lang;
|
||||
$helper->fields_value = $this->getFieldsValue($this->object);
|
||||
$helper->toolbar_btn = null;
|
||||
$helper->submit_action = 'create_rule';
|
||||
$helper->no_back = true;
|
||||
|
||||
return $helper->generateForm($this->fields_form);
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (Tools::isSubmit('deletetax_rule'))
|
||||
{
|
||||
$id_rule = (int)Tools::getValue('id_tax_rule');
|
||||
$tax_rule = new TaxRule($id_rule);
|
||||
|
||||
if (Validate::isLoadedObject($tax_rule))
|
||||
{
|
||||
$tax_rule->delete();
|
||||
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$tax_rule->id_tax_rules_group.'&conf=4&update'.$this->table.'&token='.$this->token);
|
||||
}
|
||||
}
|
||||
else if (Tools::getValue('action') == 'create_rule')
|
||||
{
|
||||
$zipcode = Tools::getValue('zipcode');
|
||||
$id_rule = (int)Tools::getValue('id_tax_rule');
|
||||
|
||||
$this->selected_countries = Tools::getValue('country');
|
||||
$this->selected_states = Tools::getValue('states');
|
||||
|
||||
if (empty($this->selected_states) || count($this->selected_states) == 0)
|
||||
$this->selected_states = array(0);
|
||||
|
||||
foreach ($this->selected_countries as $id_country)
|
||||
{
|
||||
foreach ($this->selected_states as $id_state)
|
||||
{
|
||||
$tr = new TaxRule();
|
||||
|
||||
// update or creation?
|
||||
if (isset($id_rule))
|
||||
$tr->id = $id_rule;
|
||||
|
||||
$tr->id_tax = (int)Tools::getValue('id_tax');
|
||||
$tr->id_tax_rules_group = (int)Tools::getValue('id_tax_rules_group');
|
||||
$tr->id_country = (int)$id_country;
|
||||
$tr->id_state = (int)$id_state;
|
||||
list($tr->zipcode_from, $tr->zipcode_to) = $tr->breakDownZipCode($zipcode);
|
||||
$tr->behavior = (int)Tools::getValue('behavior');
|
||||
$tr->description = Tools::getValue('description');
|
||||
$this->tax_rule = $tr;
|
||||
$_POST['id_state'] = $tr->id_state;
|
||||
$this->_errors_tax_rule = $this->validateTaxRule($tr);
|
||||
if (count($this->_errors_tax_rule) == 0)
|
||||
{
|
||||
|
||||
if (!$tr->save())
|
||||
$this->_errors[] = Tools::displayError('An error has occured: Can\'t save the current tax rule');
|
||||
} else
|
||||
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$tr->id_tax_rules_group.'&conf=4&update'.$this->table.'&token='.$this->token);
|
||||
}
|
||||
}
|
||||
|
||||
if (count($this->_errors_tax_rule) == 0)
|
||||
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$tr->id_tax_rules_group.'&conf=4&update'.$this->table.'&token='.$this->token);
|
||||
|
||||
} else
|
||||
parent::postProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the tax rule could be added in the database
|
||||
* @param TaxRule $tr
|
||||
*/
|
||||
protected function validateTaxRule(TaxRule $tr)
|
||||
{
|
||||
// TODO: check if the rule already exists
|
||||
return $tr->validateController();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user