diff --git a/admin-dev/themes/template/accounting/content.tpl b/admin-dev/themes/template/accounting/content.tpl new file mode 100644 index 000000000..1ce757188 --- /dev/null +++ b/admin-dev/themes/template/accounting/content.tpl @@ -0,0 +1,27 @@ +{* +* 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 +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 9856 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{$content} \ No newline at end of file diff --git a/admin-dev/themes/template/accounting_management/content.tpl b/admin-dev/themes/template/accounting_management/content.tpl new file mode 100644 index 000000000..fc41b58df --- /dev/null +++ b/admin-dev/themes/template/accounting_management/content.tpl @@ -0,0 +1,61 @@ +{* +* 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 +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 9856 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{if !empty($error)} +
{$error}
+{else} +
+ {include file="toolbar.tpl" toolbar_btn=$toolbar_btn} +
+

+ {$title|default:' '} +

+
+
+
+ {l s='Account number'} +
+ {l s='Configure the account number by zone for:'} {$shop['name']} +
+
+
+ +
+ +
+ {foreach from=$shop['zones'] key=id_zone item=currentZone} + +
+ +
+ {/foreach} +
+ +
+
+
+
+{/if} \ No newline at end of file diff --git a/classes/Accounting.php b/classes/Accounting.php new file mode 100644 index 000000000..a798fba85 --- /dev/null +++ b/classes/Accounting.php @@ -0,0 +1,68 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 6844 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +class AccountingCore +{ + /** + * Set an account number to a zone + * @var array $assoZoneShopList correspond to an associated list of id_zone - id_shop - num + * @return bool To know if any modification in the database succeed + */ + public static function setAccountNumberByZoneShop($assoZoneShopList) + { + $query = ' + REPLACE INTO`'._DB_PREFIX_.'accounting_zone_shop` + (id_zone, id_shop, account_number) + VALUES %s'; + + $values = ''; + foreach($assoZoneShopList as $asso) + if (array_key_exists('id_zone', $asso) && + array_key_exists('id_shop', $asso) && + array_key_exists('num', $asso)) + $values .= '('.(int)$asso['id_zone'].','.(int)$asso['id_shop'].', \''.pSQL($asso['num']).'\'), '; + $query = sprintf($query, rtrim($values, ', ')); + + if (!empty($values)) + return Db::getInstance()->execute($query); + return false; + } + + /** + * Get an account number by zone + * @var int $id_zone + * @return string + */ + public static function getAccountNumberByZone($id_zone, $id_shop) + { + return Db::getInstance()->getValue(' + SELECT `accounting_account_number` + FROM `'._DB_PREFIX_.'accounting_zone_shop` + WHERE `id_zone` = '.(int)$id_zone).' + AND id_shop` = '.(int)$id_shop; + } +} \ No newline at end of file diff --git a/classes/AdminController.php b/classes/AdminController.php index 1accb0dc2..97c9db315 100644 --- a/classes/AdminController.php +++ b/classes/AdminController.php @@ -60,7 +60,7 @@ class AdminControllerCore extends Controller public $id = -1; /** @var array noTabLink array of admintab names witch have no content */ - public $noTabLink = array('AdminCatalog', 'AdminTools', 'AdminStock'); + public $noTabLink = array('AdminCatalog', 'AdminTools', 'AdminStock', 'AdminAccounting'); /** @var string Security token */ public $token; @@ -360,8 +360,8 @@ class AdminControllerCore extends Controller $token = Tools::getValue('token') ? Tools::getValue('token') : $this->token; // Sub included tab postProcessing - $this->includeSubTab('postProcess', array('status', 'submitAdd1', 'submitDel', 'delete', 'submitFilter', 'submitReset')); - + $this->includeSubTab('postProcess', array('status', 'submitAdd1', 'submitDel', 'delete', 'submitFilter', 'submitReset')); + if (!empty($this->action) && method_exists($this, 'process'.ucfirst(Tools::toCamelCase($this->action)))) $this->{'process'.Tools::toCamelCase($this->action)}($token); else if (method_exists($this, $this->action)) diff --git a/classes/shop/GroupShop.php b/classes/shop/GroupShop.php index d5781d27c..630b8b5de 100644 --- a/classes/shop/GroupShop.php +++ b/classes/shop/GroupShop.php @@ -53,7 +53,7 @@ class GroupShopCore extends ObjectModel 'group' => array('type' => 'group_shop'), 'manufacturer' => array('type' => 'group_shop'), 'supplier' => array('type' => 'group_shop'), - 'zone' => array('type' => 'group_shop'), + 'zone' => array('type' => 'shop'), 'tax_rules_group' => array('type' => 'group_shop'), ); diff --git a/classes/shop/Shop.php b/classes/shop/Shop.php index 8cd4e2ce6..a575db629 100644 --- a/classes/shop/Shop.php +++ b/classes/shop/Shop.php @@ -83,6 +83,7 @@ class ShopCore extends ObjectModel 'referrer' => array('type' => 'shop'), 'scene' => array('type' => 'shop'), 'store' => array('type' => 'shop'), + 'zone_shop' => array('type' => 'shop'), 'webservice_account' => array('type' => 'shop'), ); diff --git a/controllers/admin/AdminAccountingExportController.php b/controllers/admin/AdminAccountingExportController.php new file mode 100644 index 000000000..8052f7e00 --- /dev/null +++ b/controllers/admin/AdminAccountingExportController.php @@ -0,0 +1,48 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 9841 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +class AdminAccountingExportControllerCore extends AdminController +{ + public function __construct() + { + $this->context = Context::getContext(); + parent::__construct(); + } + + /** + * AdminController::init() override + * @see AdminController::init() + */ + public function init() + { + + } + + public function initContent() + { + } +} \ No newline at end of file diff --git a/controllers/admin/AdminAccountingManagementController.php b/controllers/admin/AdminAccountingManagementController.php new file mode 100644 index 000000000..1e8002194 --- /dev/null +++ b/controllers/admin/AdminAccountingManagementController.php @@ -0,0 +1,148 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 9841 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +class AdminAccountingManagementControllerCore extends AdminController +{ + public function __construct() + { + $this->context = Context::getContext(); + parent::__construct(); + } + + /** + * AdminController::init() override + * @see AdminController::init() + */ + public function init() + { + $shop = array(); + $error = ''; + + parent::init(); + + if (count($this->context->shop->getListOfID()) > 1) + $error = $this->l('Please select the shop you want to configure'); + else + { + $this->initToolbar(); + + $zones = Zone::getZones(); + $id_shop = $this->context->shop->getID(); + + // Set default zone value to the shop and sort it + foreach($zones as $zone) + { + $shop['zones'][$zone['id_zone']]['name'] = $zone['name']; + $shop['zones'][$zone['id_zone']]['account_number'] = ''; + $shop['name'] = $this->context->shop->name; + } + + $shop['default_account_number'] = Configuration::get('default_account_number', + NULL, NULL, $id_shop); + ksort($shop['zones']); + + $query = ' + SELECT `id_shop`, `id_zone`, `account_number` + FROM `'._DB_PREFIX_.'accounting_zone_shop` + WHERE `id_shop` = '.(int)$id_shop; + + $zoneShopList = Db::getInstance()->executeS($query); + + // Set Account number to the id_zone for an id_shop if exist + foreach($zoneShopList as $zoneShop) + $shop['zones'][$zoneShop['id_zone']]['account_number'] = $zoneShop['account_number']; + } + + $this->context->smarty->assign(array( + 'shop' => $shop, + 'error' => $error, + 'toolbar_btn' => $this->toolbar_btn, + 'title' => $this->l('Accounting Management'), + 'table' => 'accounting' + )); + } + + /** + * AdminController::init() override + * @see AdminController::postProcess() + */ + public function postProcess() + { + if (Tools::isSubmit('UpdateNumbers')) + $this->updateAccountNumber(); + } + + /** + * assign default action in toolbar_btn smarty var, if they are not set. + * uses override to specifically add, modify or remove items + * + */ + public function initToolbar() + { + $this->initToolbarTitle(); + $this->toolbar_btn['save'] = array( + 'href' => '#', + 'desc' => $this->l('Save') + ); + } + + /** + * Update the account number for each shop liable to their zones + */ + private function updateAccountNumber() + { + $id_shop = $this->context->shop->getID(); + + // Update the current default shop account number + Configuration::updateValue( + 'default_account_number', + Tools::getValue('default_account_number'), + false, NULL, + $id_shop); + + // If zone still exist, then update the database with the new value + if (count($zones = Zone::getZones())) + { + $tab = array(); + foreach($zones as $zone) + if (($num = Tools::getValue('zone_'.$zone['id_zone'])) !== NULL) + $tab[] = array( + 'id_zone' => $zone['id_zone'], + 'id_shop' => $id_shop, + 'num' => $num); + + // Save to the database the account + if (count($tab)) + { + Accounting::setAccountNumberByZoneShop($tab); + $token = Tools::getValue('token') ? Tools::getValue('token') : $this->token; + Tools::redirectAdmin(self::$currentIndex.'&token='.$token); + } + } + } + +} \ No newline at end of file diff --git a/controllers/admin/AdminTabsController.php b/controllers/admin/AdminTabsController.php index 312c03de9..2c0e45a21 100644 --- a/controllers/admin/AdminTabsController.php +++ b/controllers/admin/AdminTabsController.php @@ -94,7 +94,8 @@ class AdminTabsControllerCore extends AdminController 'input' => array( array( 'type' => 'hidden', - 'name' => 'position' + 'name' => 'position', + 'required' => false ), array( 'type' => 'text', @@ -221,7 +222,7 @@ class AdminTabsControllerCore extends AdminController return; } /* PrestaShop demo mode*/ - + if (($id_tab = (int)Tools::getValue('id_tab')) && ($direction = Tools::getValue('move')) && Validate::isLoadedObject($tab = new Tab($id_tab))) { if ($tab->move($direction)) @@ -240,7 +241,11 @@ class AdminTabsControllerCore extends AdminController Tools::redirectAdmin(self::$currentIndex.'&conf=5&token='.Tools::getAdminTokenLite('AdminTabs')); } else + { + // Temporary add the position depend of the selection of the parent category + $_POST['position'] = Tab::getNbTabs(Tools::getValue('id_parent')); parent::postProcess(); + } } public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false) diff --git a/controllers/admin/AdminZonesController.php b/controllers/admin/AdminZonesController.php index e6cbf5747..4d40020b2 100644 --- a/controllers/admin/AdminZonesController.php +++ b/controllers/admin/AdminZonesController.php @@ -27,6 +27,8 @@ class AdminZonesControllerCore extends AdminController { + public $asso_type = 'shop'; + public function __construct() { $this->table = 'zone'; @@ -42,7 +44,12 @@ class AdminZonesControllerCore extends AdminController 'name' => array('title' => $this->l('Zone'), 'width' => 'auto'), 'active' => array('title' => $this->l('Enabled'), 'width' => '70', 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false) ); - + + parent::__construct(); + } + + public function initForm() + { $this->fields_form = array( 'legend' => array( 'title' => $this->l('Zones'), @@ -80,17 +87,17 @@ class AdminZonesControllerCore extends AdminController ), array( 'type' => 'asso_shop', - 'label' => 'Shop groups:', + 'label' => 'Shop :', 'name' => '' ) ), - 'asso_shop' => 'group', + 'asso_shop' => $this->asso_type, 'submit' => array( 'title' => $this->l(' Save '), 'class' => 'button' ) ); - parent::__construct(); + return parent::initForm(); } } diff --git a/install-dev/sql/db.sql b/install-dev/sql/db.sql index fe4a0d9a0..2503b20bf 100644 --- a/install-dev/sql/db.sql +++ b/install-dev/sql/db.sql @@ -2163,3 +2163,11 @@ CREATE TABLE `PREFIX_supplier_rates` ( PRIMARY KEY (`id_product`, `id_product_attribute`, `id_supplier`, `quantity_min`, `quantity_max`) ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; +CREATE TABLE `PREFIX_accounting_zone_shop` ( + `id_accounting_zone_shop` int(11) NOT NULL AUTO_INCREMENT, + `id_zone` int(11) NOT NULL, + `id_shop` int(11) NOT NULL, + `account_number` varchar(64) NOT NULL, + PRIMARY KEY (`id_accounting_zone_shop`), + UNIQUE KEY `id_zone` (`id_zone`,`id_shop`) +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; diff --git a/install-dev/sql/db_settings_lite.sql b/install-dev/sql/db_settings_lite.sql index fd4ab7a30..2aec14c45 100644 --- a/install-dev/sql/db_settings_lite.sql +++ b/install-dev/sql/db_settings_lite.sql @@ -950,7 +950,10 @@ INSERT INTO `PREFIX_tab` (`id_tab`, `class_name`, `id_parent`, `position`) VALUE (98, 'AdminStockInstantState', 95, 4), (99, 'AdminStockCover', 95, 5), (100, 'AdminSupplierOrders', 95, 6), -(101, 'AdminAttributeGenerator', -1, 0); +(101, 'AdminAttributeGenerator', -1, 0), +(102, 'AdminAccounting', 0, 16), +(103, 'AdminAccountingManagement', 102, 1), +(104, 'AdminAccountingExport', 102, 2); INSERT INTO `PREFIX_access` (`id_profile`, `id_tab`, `view`, `add`, `edit`, `delete`) (SELECT 1, id_tab, 1, 1, 1, 1 FROM `PREFIX_tab`); @@ -976,7 +979,10 @@ INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES (1, 98, 'Stock instant state'), (1, 99, 'Stock cover'), (1, 100, 'Supplier orders'), -(1, 101, 'Combinations generator'); +(1, 101, 'Combinations generator'), +(1, 102, 'Accounting'), +(1, 103, 'Account Number Management'), +(1, 104, 'Export'); INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES (2, 1, 'Catalogue'),(2, 2, 'Clients'),(2, 3, 'Commandes'),(2, 4, 'Paiement'),(2, 5, 'Transport'), @@ -1000,7 +1006,10 @@ INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES (2, 98, 'Etat instantané du stock'), (2, 99, 'Couverture de stock'), (2, 100, 'Commandes fournisseurs'), -(2, 101, 'Générateur de combinaisons'); +(2, 101, 'Générateur de combinaisons'), +(2, 102, 'Comptabilité'), +(2, 103, 'Gestion des numéros de comptes'), +(2, 104, 'Export'); INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES (3, 1, 'Catálogo'),(3, 2, 'Clientes'),(3, 3, 'Pedidos'),(3, 4, 'Pago'),(3, 5, 'Transporte'), @@ -1023,7 +1032,10 @@ INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES (3, 98, 'Stock instant state'), (3, 99, 'Stock cover'), (3, 100, 'Supplier orders'), -(3, 101, 'Combinations generator'); +(3, 101, 'Combinations generator'), +(3, 102, 'Accounting'), +(3, 103, 'Account Number Management'), +(3, 104, 'Export'); INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES (4, 1, 'Katalog'),(4, 2, 'Kunden'),(4, 3, 'Bestellungen'),(4, 4, 'Zahlung'), @@ -1047,7 +1059,10 @@ INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES (4, 98, 'Stock instant state'), (4, 99, 'Stock cover'), (4, 100, 'Supplier orders'), -(4, 101, 'Combinations generator'); +(4, 101, 'Combinations generator'), +(4, 102, 'Accounting'), +(4, 103, 'Account Number Management'), +(4, 104, 'Export'); INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES (5, 1, 'Catalogo'),(5, 2, 'Clienti'),(5, 3, 'Ordini'),(5, 4, 'Pagamento'), @@ -1071,7 +1086,10 @@ INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES (5, 98, 'Stock instant state'), (5, 99, 'Stock cover'), (5, 100, 'Supplier orders'), -(5, 101, 'Combinations generator'); +(5, 101, 'Combinations generator'), +(5, 102, 'Accounting'), +(5, 103, 'Account Number Management'), +(5, 104, 'Export'); INSERT IGNORE INTO `PREFIX_tab_lang` (`id_tab`, `id_lang`, `name`) (SELECT `id_tab`, id_lang, (SELECT tl.`name`