diff --git a/admin-dev/themes/template/accounting_management/content.tpl b/admin-dev/themes/template/accounting_management/content.tpl index fc41b58df..fd44248b9 100644 --- a/admin-dev/themes/template/accounting_management/content.tpl +++ b/admin-dev/themes/template/accounting_management/content.tpl @@ -38,7 +38,8 @@
{l s='Account number'}
- {l s='Configure the account number by zone for:'} {$shop['name']} + {l s='Configure the account number by zone for:'} {$shop['name']}. + {l s='If a zone field is empty it will use the default number set.'}

@@ -53,7 +54,7 @@ {/foreach}
- +
diff --git a/admin-dev/themes/template/products/accounting.tpl b/admin-dev/themes/template/products/accounting.tpl new file mode 100644 index 000000000..60bdd7815 --- /dev/null +++ b/admin-dev/themes/template/products/accounting.tpl @@ -0,0 +1,48 @@ +{* +* 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} +
+ {l s='Account number'} +
+ {l s='Configure the account number of the product for each zone, if a field is empty, it will use the default one of the shop set in the Accounting Management tab :'} +
+
+ {foreach from=$productAccountNumberList['zones'] key=id_zone item=currentZone} + +
+ +
+ {/foreach} +
+ +
+ +
+
+{/if} \ No newline at end of file diff --git a/classes/Accounting.php b/classes/Accounting.php index a798fba85..31334e208 100644 --- a/classes/Accounting.php +++ b/classes/Accounting.php @@ -28,11 +28,11 @@ class AccountingCore { /** - * Set an account number to a zone + * Set an account number to a zone (will be refactoring for a dynamic use depending of the Controller) * @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) + public static function setAccountNumberByZoneShop($assoZoneShopList, $table) { $query = ' REPLACE INTO`'._DB_PREFIX_.'accounting_zone_shop` @@ -53,16 +53,57 @@ class AccountingCore } /** - * Get an account number by zone - * @var int $id_zone - * @return string + * Add or update product accounting information for a product (will be refactoring for a dynamic use depending of the Controller) + * @param int $id_product + * @param array $accountingInfos */ - public static function getAccountNumberByZone($id_zone, $id_shop) + public static function saveProductAccountingInformations($assoProductZoneShop) { - return Db::getInstance()->getValue(' - SELECT `accounting_account_number` + $query = ' + REPLACE INTO`'._DB_PREFIX_.'accounting_product_zone_shop` + (id_zone, id_shop, id_product, account_number) + VALUES %s'; + + $values = ''; + foreach($assoProductZoneShop as $asso) + if (array_key_exists('id_zone', $asso) && + array_key_exists('id_shop', $asso) && + array_key_exists('id_product', $asso) && + array_key_exists('num', $asso)) + $values .= '('.(int)$asso['id_zone'].','.(int)$asso['id_shop'].','.(int)$asso['id_product'].', \''.pSQL($asso['num']).'\'), '; + $query = sprintf($query, rtrim($values, ', ')); + + if (!empty($values)) + return Db::getInstance()->execute($query); + return false; + } + + /** + * Get product account number list by zone (will be refactoring for a dynamic use depending of the Controller) + * @var int $id_zone + * @var int $id_shop + * @return array + */ + public static function getProductAccountNumberZoneShop($id_product, $id_shop) + { + return Db::getInstance()->executeS(' + SELECT `account_number`, `id_zone` + FROM `'._DB_PREFIX_.'accounting_product_zone_shop` + WHERE `id_product` = '.(int)$id_product.' + AND `id_shop` = '.(int)$id_shop); + } + + /** + * Get shop account number list by zone (will be refactoring for a dynamic use depending of the Controller) + * @var int $id_zone + * @var int $id_shop + * @return array + */ + public static function getAccountNumberZoneShop($id_shop) + { + return Db::getInstance()->executeS(' + SELECT `id_shop`, `id_zone`, `account_number` FROM `'._DB_PREFIX_.'accounting_zone_shop` - WHERE `id_zone` = '.(int)$id_zone).' - AND id_shop` = '.(int)$id_shop; + WHERE `id_shop` = '.(int)$id_shop); } } \ No newline at end of file diff --git a/controllers/admin/AdminAccountingManagementController.php b/controllers/admin/AdminAccountingManagementController.php index e1930fc07..3219f1fa1 100644 --- a/controllers/admin/AdminAccountingManagementController.php +++ b/controllers/admin/AdminAccountingManagementController.php @@ -67,14 +67,9 @@ class AdminAccountingManagementControllerCore extends AdminController 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); + $zoneShopList = Accounting::getAccountNumberZoneShop($id_shop); - // Set Account number to the id_zone for an id_shop if exist + // Set Account number to the id_zone for the id_shop if exist foreach($zoneShopList as $zoneShop) $shop['zones'][$zoneShop['id_zone']]['account_number'] = $zoneShop['account_number']; } diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 6c824b0a1..c8b3f1694 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -35,7 +35,16 @@ class AdminProductsController extends AdminController private $_category; - protected $available_tabs = array('Informations', 'Images', 'Prices', 'Combinations', 'Features', 'Customization', 'Attachments', 'Quantities'); + protected $available_tabs = array( + 'Informations', + 'Images', + 'Prices', + 'Combinations', + 'Features', + 'Customization', + 'Attachments', + 'Quantities', + 'Accounting'); public function __construct() { @@ -908,6 +917,8 @@ class AdminProductsController extends AdminController else Tools::redirectAdmin(self::$currentIndex.'&'.$this->table.'Orderby=position&'.$this->table.'Orderway=asc&conf=5'.(($id_category = (!empty($_REQUEST['id_category'])?$_REQUEST['id_category']:'1')) ? ('&id_category='.$id_category) : '').'&token='.Tools::getAdminTokenLite('AdminProducts')); } + else if (Tools::isSubmit('submitAccountingDetails')) + $this->postProcessFormAccounting(); else parent::postProcess(true); } @@ -1791,12 +1802,13 @@ if (false) $i = 0; foreach($this->available_tabs as $product_tab) { + $endurl = '&id_product='.Tools::getValue('id_product').'&action='.$product_tab; $product_tabs[$product_tab] = array( 'id' => ++$i, 'selected' => (strtolower($product_tab) == strtolower($action)), // @todo $this->l() instead of product_tab 'name' => $product_tab, - 'href' => $this->context->link->getAdminLink('AdminProducts').'&id_product='.Tools::getValue('id_product').'&action='.$product_tab, + 'href' => $this->context->link->getAdminLink('AdminProducts').$endurl, ); } $smarty->assign('newproduct', 0); @@ -1903,6 +1915,71 @@ switch ($this->action) */ } } + + /** + * Post traitment for accounting + */ + public function postProcessFormAccounting() + { + if (Validate::isLoadedObject($product = new Product((int)(Tools::getValue('id_product'))))) + { + $id_shop = $this->context->shop->getID(); + + // If zone still exist, then update the database with the new value + if (count($zones = Zone::getZones())) + { + // Build tab with associated data + $tab = array(); + foreach($zones as $zone) + if (($num = Tools::getValue('zone_'.$zone['id_zone'])) !== NULL) + $tab[] = array( + 'id_zone' => $zone['id_zone'], + 'id_product' => $product->id, + 'id_shop' => $id_shop, + 'num' => $num); + + if (count($tab)) + Accounting::saveProductAccountingInformations($tab); + } + } + } + + /** + * Init data for accounting + */ + public function initFormAccounting($product, $t) + { + $error = ''; + $token = Tools::getValue('token') ? Tools::getValue('token') : $this->token; + + if (count($this->context->shop->getListOfID()) > 1) + $error = $this->l('Please select the shop you want to configure'); + else + { + $zones = Zone::getZones(); + $id_shop = $this->context->shop->getID(); + $detail = array(); + + // Set default zone value to the shop and sort it + foreach($zones as $zone) + { + $detail['zones'][$zone['id_zone']]['name'] = $zone['name']; + $detail['zones'][$zone['id_zone']]['account_number'] = ''; + } + $zoneAccountNumberList = Accounting::getProductAccountNumberZoneShop($product->id, $id_shop); + + // Set Account number to the id_zone for an id_shop if exist + foreach($zoneAccountNumberList as $zone) + $detail['zones'][$zone['id_zone']]['account_number'] = $zone['account_number']; + } + + $this->context->smarty->assign(array( + 'productAccountNumberList' => $detail, + 'shopName' => $this->context->shop->name, + 'error' => $error, + )); + $this->content = $this->context->smarty->fetch('products/accounting.tpl'); + } public function initFormPrices($obj, $languages, $defaultLanguage) { diff --git a/install-dev/php/add_accounting_tab.php b/install-dev/php/add_accounting_tab.php new file mode 100644 index 000000000..31ff6ef63 --- /dev/null +++ b/install-dev/php/add_accounting_tab.php @@ -0,0 +1,20 @@ +