- Accounting: Add new tab for product to define the number liable to an existing zone, update upgrader and installer
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9986 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -38,7 +38,8 @@
|
||||
<fieldset>
|
||||
<legend>{l s='Account number'}</legend>
|
||||
<div class="hint" style="display:block">
|
||||
{l s='Configure the account number by zone for:'} <b>{$shop['name']}</b>
|
||||
{l s='Configure the account number by zone for:'} <b>{$shop['name']}</b>.
|
||||
{l s='If a zone field is empty it will use the default number set.'}
|
||||
</div>
|
||||
<br />
|
||||
<form id="{$table}_form" method="POST" action="{$smarty.server.REQUEST_URI}">
|
||||
@@ -53,7 +54,7 @@
|
||||
</div>
|
||||
{/foreach}
|
||||
<div class="margin-form">
|
||||
<input type="submit" class="button" id="{$table}_form_submit_btn" name="UpdateNumbers" />
|
||||
<input type="submit" class="button" id="{$table}_form_submit_btn" name="UpdateNumbers" value="{l s='Save'}"/>
|
||||
</div>
|
||||
</form>
|
||||
<div class="separation"></div>
|
||||
|
||||
@@ -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 <contact@prestashop.com>
|
||||
* @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)}
|
||||
<div class="hint" style="display:block">{$error}</div>
|
||||
{else}
|
||||
<fieldset>
|
||||
<legend>{l s='Account number'}</legend>
|
||||
<div class="hint" style="display:block">
|
||||
{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 :'}
|
||||
</div>
|
||||
<br />
|
||||
{foreach from=$productAccountNumberList['zones'] key=id_zone item=currentZone}
|
||||
<label>{$currentZone['name']}</label>
|
||||
<div class="margin-form">
|
||||
<input type="text" name="zone_{$id_zone}" value="{$currentZone['account_number']}" />
|
||||
</div>
|
||||
{/foreach}
|
||||
<div class="margin-form">
|
||||
<input type="submit" class="button" name="submitAccountingDetails" />
|
||||
</div>
|
||||
</form>
|
||||
<div class="separation"></div>
|
||||
</fieldset>
|
||||
{/if}
|
||||
+51
-10
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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'];
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
function add_accounting_tab()
|
||||
{
|
||||
$id_parent = add_new_tab(
|
||||
'AdminAccounting',
|
||||
'en:Accounting|fr:Comptabilité|es:Accounting|de:Accounting|it:Accounting',
|
||||
0,
|
||||
true);
|
||||
|
||||
add_new_tab(
|
||||
'AdminAccountingManagement',
|
||||
'en:Account Number Management|fr:Gestion des numéros de comptes|es:Account Number Management|de:Account Number Management|it:Account Number Management',
|
||||
$id_parent);
|
||||
|
||||
add_new_tab(
|
||||
'AdminAccountingExport',
|
||||
'en:Export|fr:Export|es:Export|de:Export|it:Export',
|
||||
$id_parent);
|
||||
}
|
||||
@@ -2171,3 +2171,13 @@ CREATE TABLE `PREFIX_accounting_zone_shop` (
|
||||
PRIMARY KEY (`id_accounting_zone_shop`),
|
||||
UNIQUE KEY `id_zone` (`id_zone`,`id_shop`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `PREFIX_accounting_product_zone_shop` (
|
||||
`id_accounting_product_zone_shop` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id_product` int(11) NOT NULL,
|
||||
`id_shop` int(11) NOT NULL,
|
||||
`id_zone` int(11) NOT NULL,
|
||||
`account_number` varchar(64) NOT NULL,
|
||||
PRIMARY KEY (`id_accounting_product_zone_shop`),
|
||||
UNIQUE KEY `id_product` (`id_product`,`id_shop`,`id_zone`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
SET NAMES 'utf8';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `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;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `PREFIX_accounting_product_zone_shop` (
|
||||
`id_accounting_product_zone_shop` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id_product` int(11) NOT NULL,
|
||||
`id_shop` int(11) NOT NULL,
|
||||
`id_zone` int(11) NOT NULL,
|
||||
`account_number` varchar(64) NOT NULL,
|
||||
PRIMARY KEY (`id_accounting_product_zone_shop`),
|
||||
UNIQUE KEY `id_product` (`id_product`,`id_shop`,`id_zone`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
|
||||
/* PHP:add_accounting_tab(); */;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `PREFIX_module_access` (
|
||||
`id_profile` int(10) unsigned NOT NULL,
|
||||
`id_module` int(10) unsigned NOT NULL,
|
||||
|
||||
Reference in New Issue
Block a user