* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7541 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class AdminTaxes extends AdminTab { public function __construct() { global $cookie; $this->table = 'tax'; $this->className = 'Tax'; $this->lang = true; $this->edit = true; $this->delete = true; $this->fieldsDisplay = array( 'id_tax' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'name' => array('title' => $this->l('Name'), 'width' => 140), 'rate' => array('title' => $this->l('Rate'), 'align' => 'center', 'suffix' => '%', 'width' => 50), 'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false)); $ecotax_desc = ''; if (Configuration::get('PS_USE_ECOTAX')) $ecotax_desc = $this->l('If you disable the ecotax, the ecotax for all your products will be set to 0'); $this->optionTitle = $this->l('Tax options'); $this->_fieldsOptions = array( 'PS_TAX' => array('title' => $this->l('Enable tax:'), 'desc' => $this->l('Select whether or not to include tax on purchases'), 'cast' => 'intval', 'type' => 'bool'), 'PS_TAX_DISPLAY' => array('title' => $this->l('Display tax in cart:'), 'desc' => $this->l('Select whether or not to display tax on a distinct line in the cart'), 'cast' => 'intval', 'type' => 'bool'), 'PS_TAX_ADDRESS_TYPE' => array('title' => $this->l('Base on:'), 'cast' => 'pSQL', 'type' => 'select', 'list' => array(array('name' => $this->l('Invoice Address'), 'id' => 'id_address_invoice'), array('name' => $this->l('Delivery Address'), 'id' => 'id_address_delivery')), 'identifier' => 'id'), 'PS_USE_ECOTAX' => array('title' => $this->l('Use ecotax'), 'desc' => $ecotax_desc, 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), ); if (Configuration::get('PS_USE_ECOTAX')) $this->_fieldsOptions['PS_ECOTAX_TAX_RULES_GROUP_ID'] = array('title' => $this->l('Ecotax:'), 'desc' => $this->l('The tax to apply on the ecotax (e.g., French ecotax: 19.6%).'), 'cast' => 'intval', 'type' => 'select', 'identifier' => 'id_tax', 'identifier' => 'id_tax_rules_group', 'list' => TaxRulesGroup::getTaxRulesGroupsForOptions()); parent::__construct(); } public function displayForm($isMainTab = true) { global $currentIndex, $cookie; parent::displayForm(); if (!($obj = $this->loadObject(true))) return; $zones = Zone::getZones(true); $states = State::getStates((int)$cookie->id_lang); echo '
'.($obj->id ? '' : '').'
'.$this->l('Taxes').'
'; foreach ($this->_languages as $language) echo '
* '.$this->l('Invalid characters:').' <>;=#{} 
'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'name', 'name'); echo '

'.$this->l('Tax name to display in cart and on invoice, e.g., VAT').'

*

'.$this->l('Format: XX.XX or XX.XXX (e.g., 19.60 or 13.925)').'

getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/> getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/>
* '.$this->l('Required field').'
'; } public function postProcess() { global $currentIndex; if (Tools::getValue('submitAdd'.$this->table)) { /* Checking fields validity */ $this->validateRules(); if (!sizeof($this->_errors)) { $id = (int)(Tools::getValue('id_'.$this->table)); /* Object update */ if (isset($id) AND !empty($id)) { if ($this->tabAccess['edit'] === '1') { $object = new $this->className($id); if (Validate::isLoadedObject($object)) { $this->copyFromPost($object, $this->table); $result = $object->update(false, false); if (!$result) $this->_errors[] = Tools::displayError('An error occurred while updating object.').' '.$this->table.''; elseif ($this->postImage($object->id)) { Tools::redirectAdmin($currentIndex.'&id_'.$this->table.'='.$object->id.'&conf=4'.'&token='.$this->token); } } else $this->_errors[] = Tools::displayError('An error occurred while updating object.').' '.$this->table.' '.Tools::displayError('(cannot load object)'); } else $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } /* Object creation */ else { if ($this->tabAccess['add'] === '1') { $object = new $this->className(); $this->copyFromPost($object, $this->table); if (!$object->add()) $this->_errors[] = Tools::displayError('An error occurred while creating object.').' '.$this->table.''; elseif (($_POST['id_'.$this->table] = $object->id /* voluntary */) AND $this->postImage($object->id) AND $this->_redirect) { Tools::redirectAdmin($currentIndex.'&id_'.$this->table.'='.$object->id.'&conf=3'.'&token='.$this->token); } } else $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } } } else parent::postProcess(); } protected function _displayDeleteLink($token = NULL, $id) { global $currentIndex; $_cacheLang['Delete'] = $this->l('Delete', __CLASS__, TRUE, FALSE); $_cacheLang['DeleteItem'] = $this->l('Delete item #', __CLASS__, TRUE, FALSE).$id.' ?)'; if (TaxRule::isTaxInUse($id)) $_cacheLang['DeleteItem'] = $this->l('This tax is currently in use in a tax rule. Are you sure?'); echo ' '.$_cacheLang['Delete'].''; } protected function _displayEnableLink($token, $id, $value, $active, $id_category = NULL, $id_product = NULL) { global $currentIndex; $confirm = ($value AND TaxRule::isTaxInUse($id)) ? 'onclick="return confirm(\''. $this->l('This tax is currently in use in a tax rule. If you continue this tax will be removed from the tax rule, are you sure?').'\')"' : ''; echo ' '.($value ? $this->l('Enabled') : $this->l('Disabled')).''; } public function updateOptionPsUseEcotax($value) { $old_value = (int)Configuration::get('PS_USE_ECOTAX'); if ($old_value != $value) { // Reset ecotax if ($value == 0) Product::resetEcoTax(); Configuration::updateValue('PS_USE_ECOTAX', (int)$value); } } }