[-] BO : Delete accounting

This commit is contained in:
vSchoener
2012-05-10 09:30:04 +00:00
parent 4ccd85f553
commit a43d2f3b52
19 changed files with 7 additions and 1826 deletions

View File

@@ -1,57 +0,0 @@
{*
* 2007-2012 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-2012 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 $show_toolbar}
{include file="toolbar.tpl" toolbar_btn=$toolbar_btn toolbar_scroll=$toolbar_scroll title=$title}
<div class="leadin">{block name="leadin"}{/block}</div>
{/if}
{if !$has_shop_selected}
<div class="hint" style="display:block">{l s='Please select the shop you want to configure'}</div>
{else}
<form action="{$current}&token={$token}" id="{$table}_form" method="post" enctype="multipart/form-data">
{foreach from=$input_category_list item=category key=name_category}
<fieldset style="margin: 20px 0;">
<legend>{$category['title']}</legend>
{foreach from=$category['fields'] item=input key=input_name}
<div style="clear: both; padding-top:15px;" id="conf_id_{$input_name}" >
<label class="conf_title">{$input['title']}</label>
{if $input['type'] == 'text'}
<input type="text" name="{$input_name|htmlentities}" {if isset($input['id'])}id="{$input['id']|htmlentities}"{/if} value="{$input['value']|escape:'htmlall':'UTF-8'}" />
{/if}
<div class="margin-form">
{if isset($input['desc'])}<p class="preference_description">{$input['desc']}</p>{/if}
</div>
</div>
<div class="clear"></div>
{/foreach}
</fieldset>
{/foreach}
<div class="margin-form">
<input type="submit" class="button" id="{$table}_form_submit_btn" name="update_cfg" value="{l s='Save'}"/>
</div>
</form>
{/if}

View File

@@ -1,189 +0,0 @@
{*
* 2007-2012 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-2012 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
*}
<script type="text/javascript">
function validateInputDate(input, displayError)
{
{literal}
dateRegex = /^\d{4}-\d{1,2}-\d{1,2}$/
{/literal}
if (!input.val().match(dateRegex))
{
input.parent().find('span.input-error').fadeIn('fast');
return false;
}
input.parent().find('span.input-error').css('display','none');
return true;
}
function validateAccountingForm()
{
validation = true;
$('span.input-error').css('display', 'none');
$('.datepicker:visible').each(function() {
if (!(validateInputDate($(this), true)))
validation = false;
});
return validation;
}
$(document).ready(function() {
$('.datepicker').each(function() {
$(this).change(function() {
validateInputDate($(this), true);
});
$(this).datepicker({
prevText: '',
nextText: '',
dateFormat: 'yy-mm-dd'
});
});
$('.formAccountingExport form input[type="submit"]').each(function()
{
$(this).click(function() {
return validateAccountingForm();
});
});
});
</script>
<div id="export_menu">
<div class="toolbarBox">
<div class="pageTitle">
<h3>
<span id="current_obj" style="font-weight: normal;">
{l s='Accounting Export:'}
</span>
</h3>
</div>
</div>
</div>
{foreach from=$preventList key=name item=preventType}
{if !empty($preventType)}
<div class="{$name}">
<ul>
{foreach from=$preventType item=translationPrevent}
<li>{$translationPrevent}</li>
{/foreach}
{if $already_generated}
<li>
{l s='Generate it:'}
<a href="{$smarty.server.REQUEST_URI}&begin_date={$begin_date}&end_date={$end_date}&type={$export_type}&format={$file_format}&regenerate={$already_generated}&accounting_export=true">
{l s='Start export'}
</a>
<li>
{/if}
</ul>
</div>
{/if}
{/foreach}
<div id="account_list">
<form id="{$table}_form" method="POST" action="{$smarty.server.REQUEST_URI}">
<label for="beginDate">{l s='Begin at:'}</label>
<div class="margin-form">
<input class="datepicker" id="begin_date" type="text" name="begin_date" value="{$begin_date}" />
<span class="input-error">{l s='The date does not have the right format'}</span>
</div>
<label for="endDate">{l s='End at:'}</label>
<div class="margin-form">
<input class="datepicker" id="end_date" type="text" name="end_date" value="{$end_date}" />
<span class="input-error">{l s='The date does not have the right format'}</span>
</div>
<label for="format">{l s='File format:'}</label>
<div class="margin-form">
<select id="format" name="format">
<option value="">{l s='Choose a format'}</option>
<option value="csv" {if $file_format == 'csv'} selected="selected"{/if}>
{l s='Excel (CSV)'}
</option>
<option value="txt" {if $file_format == 'txt'} selected="selected"{/if}>
{l s='Text (TXT)'}
</option>
</select>
<span class="input-error">{l s='The date does not have the right format'}</span>
</div>
<label for="type">{l s='Export Type:'}</label>
<div class="margin-form">
<select id="type" name="type">
<option value="">{l s='Choose export type'}</option>
<option value="accounting_export" {if $export_type == 'accounting_export'} selected="selected"{/if}>
{l s='Accounting export'}
</option>
<option value="reconciliation_export" {if $export_type == 'reconciliation_export'} selected="selected"{/if}>
{l s='Reconciliation'}
</option>
</select>
<span class="input-error">{l s='The date does not have the right format'}</span>
</div>
<div class="margin-form">
<input type="submit" class="button" id="{$table}_form_submit_btn" name="accounting_export" value="{l s='Launch export'}"/>
</div>
</form>
</div>
<div id="account_list" style="margin-top:10px;">
<h3>{l s='History'}</h3>
{if $exported_list|count}
<table class="table" style="width:100%;">
<thead>
<th>{l s='Export type'}</th>
<th>{l s='Date start to'}</th>
<th>{l s='Date end to'}</th>
<th>{l s='File'}</th>
</thead>
<tbody>
{foreach from=$exported_list item=export_detail}
<tr>
<td>{$export_detail['title']}</td>
<td>{$export_detail['begin_to']}</td>
<td>{$export_detail['end_to']}</td>
<td>
<a href="{$smarty.server.REQUEST_URI}&download={$export_detail['file']}">
{l s='Download'}
<img src="../img/admin/{if $export_detail['file']|pathinfo:$smarty.const.PATHINFO_EXTENSION == 'csv'}excel_file.png{else}page_white_text.png{/if}" />
<a>
</td>
</tr>
{/foreach}
</tbody>
</table>
{else}
{l s='No exported data found'}
{/if}
</div>

View File

@@ -1,59 +0,0 @@
{*
* 2007-2012 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-2012 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 $show_toolbar}
{include file="toolbar.tpl" toolbar_btn=$toolbar_btn toolbar_scroll=$toolbar_scroll title=$title}
<div class="leadin">{block name="leadin"}{/block}</div>
{/if}
<div id="account_list">
{foreach from=$account_number_list item=detail key=name}
<h2>{$detail['title']}</h2>
{if $detail['list']|count}
<table class="table" style="width:100%;">
<thead>
{if $detail['list']|count}
{foreach from=$detail['fields'] item=col_name key=sql_name}
<th>{$col_name}</th>
{/foreach}
{/if}
</thead>
<tbody>
{foreach from=$detail['list'] item=row key=row_number}
<tr>
{foreach from=$row item=value key=value_num}
<td>{$value}</td>
{/foreach}
</tr>
{/foreach}
</tbody>
</table>
{else}
<p>{l s='No defined account number for this list'}</p>
{/if}
<div class="separation"></div>
{/foreach}
</div>

View File

@@ -1,52 +0,0 @@
{*
* 2007-2012 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-2012 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 isset($product->id)}
<input type="hidden" name="submitted_tabs[]" value="Accounting" />
<h4>{l s='Accounting'}</h4>
<div class="separation"></div>
{if !empty($error)}
<div class="hint" style="display:block">{$error}</div>
{else}
<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>
<h3>{l s='Account number'}</h3>
<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']|htmlentities}" />
</div>
{/foreach}
</form>
<div style="text-align:left; font-size:11px;">
<i>{l s='These fields are used for the accounting export'}</i>
</div>
<div class="separation"></div>
{/if}
{/if}

View File

@@ -2,7 +2,6 @@
'AbstractLogger' => 'override/classes/log/AbstractLogger.php',
'AbstractLoggerCore' => 'classes/log/AbstractLogger.php',
'Accounting' => 'override/classes/Accounting.php',
'AccountingCore' => 'classes/Accounting.php',
'Address' => 'override/classes/Address.php',
'AddressController' => 'override/controllers/front/AddressController.php',
'AddressControllerCore' => 'controllers/front/AddressController.php',
@@ -14,13 +13,9 @@
'AdminAccessController' => 'override/controllers/admin/AdminAccessController.php',
'AdminAccessControllerCore' => 'controllers/admin/AdminAccessController.php',
'AdminAccountingConfigurationController' => 'override/controllers/admin/AdminAccountingConfigurationController.php',
'AdminAccountingConfigurationControllerCore' => 'controllers/admin/AdminAccountingConfigurationController.php',
'AdminAccountingExportController' => 'override/controllers/admin/AdminAccountingExportController.php',
'AdminAccountingExportControllerCore' => 'controllers/admin/AdminAccountingExportController.php',
'AdminAccountingManagementController' => 'override/controllers/admin/AdminAccountingManagementController.php',
'AdminAccountingManagementControllerCore' => 'controllers/admin/AdminAccountingManagementController.php',
'AdminAccountingRegisteredNumberController' => 'override/controllers/admin/AdminAccountingRegisteredNumberController.php',
'AdminAccountingRegisteredNumberControllerCore' => 'controllers/admin/AdminAccountingRegisteredNumberController.php',
'AdminAddonsCatalogController' => 'override/controllers/admin/AdminAddonsCatalogController.php',
'AdminAddonsCatalogControllerCore' => 'controllers/admin/AdminAddonsCatalogController.php',
'AdminAddressesController' => 'override/controllers/admin/AdminAddressesController.php',

View File

@@ -1,211 +0,0 @@
<?php
/*
* 2007-2012 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-2012 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
{
const CONF_NAME = 'ACCOUNTING_CONFIGURATION';
/**
* Default Values
* All key modification have to be changed into the localization pack and xml
* This configuration is applied for a specific shop
*
* @var array
*/
public static $acc_conf = array(
'customer_prefix' => '',
'journal' => '',
'account_length' => '',
'account_submit_shipping_charge' => '',
'account_unsubmit_shipping_charge' => '',
'account_gift_wripping' => '',
'account_handling' => ''
);
public static $acc_conf_cached = false;
/**
* Set an account number to a zone (will be refactoring for a dynamic use depending of the Controller)
* @var array $asso_zone_shop_list 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($asso_zone_shop_list)
{
$query = '
REPLACE INTO`'._DB_PREFIX_.'accounting_zone_shop`
(id_zone, id_shop, account_number)
VALUES %s';
$values = '';
// Build the query for the update
foreach ($asso_zone_shop_list 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;
}
/**
* Add or update product accounting information for a product (will be refactoring for a dynamic use depending of the Controller)
* @param array $asso_product_zone_shop
* @return mixed bool|array
*/
public static function saveProductAccountingInformations($asso_product_zone_shop)
{
$query = '
REPLACE INTO`'._DB_PREFIX_.'accounting_product_zone_shop`
(id_zone, id_shop, id_product, account_number)
VALUES %s';
$values = '';
foreach ($asso_product_zone_shop 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_shop` = '.(int)$id_shop);
}
/**
* Get the Accounting Configuration
* If a key is defined, then it will try to get the value
*
* @static
* @param null $key
* @return array|bool
*/
public static function getConfiguration($key = null)
{
// Cache for call performance
if (!self::$acc_conf_cached)
{
// Merge default values with the configured values
if ($conf = unserialize(Configuration::get(Accounting::CONF_NAME)))
self::$acc_conf = array_merge(self::$acc_conf, $conf);
self::$acc_conf_cached = true;
}
// Return value key or the complete configuration depending of the $key definition
return (!$key) ? self::$acc_conf : ((isset(self::$acc_conf[$key]) ? self::$acc_conf[$key] : false));
}
/**
* Update Accounting configuration
*
* @static
* @param $acc_conf
*/
public static function updateConfiguration($acc_conf)
{
Configuration::updateValue(Accounting::CONF_NAME, serialize($acc_conf));
}
/**
* Get the list of export done
*
* @static
* @return array
*/
public static function getExportedList()
{
return Db::getInstance()->executeS('
SELECT * FROM `'._DB_PREFIX_.'accounting_export` ORDER BY `date` DESC');
}
/**
* Get the displayed customer account.
* Pad with / without prefix if the account is set
*
* @static
* @param $id_customer
* @param $default_value
* @return string
*/
public static function getDisplayedCustomerAccount($id_customer, $default_value = false)
{
$acc_num = Db::getInstance()->getValue('
SELECT account_number FROM `'._DB_PREFIX_.'customer`
WHERE id_customer = '.(int)$id_customer);
$display = $acc_num;
if (empty($acc_num) || $default_value)
{
$display = Accounting::getConfiguration('customer_prefix');
$max_len = Accounting::getConfiguration('account_length');
$len = Tools::strlen($display) + Tools::strlen((string)$id_customer);
// Pad the displayed string
while ($max_len > 0 && $max_len > $len)
{
$display .= '0';
--$max_len;
}
$display .= (string)$id_customer;
}
return $display;
}
}

View File

@@ -133,8 +133,6 @@ class CustomerCore extends ObjectModel
public $groupBox;
public $account_number = '';
protected $webserviceParameters = array(
'fields' => array(
'id_default_group' => array('xlink_resource' => 'groups'),
@@ -171,7 +169,6 @@ class CustomerCore extends ObjectModel
'optin' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'website' => array('type' => self::TYPE_STRING, 'validate' => 'isUrl'),
'company' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
'account_number' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'size' => 65000, 'copy_from_front' => false),
'siret' => array('type' => self::TYPE_STRING, 'validate' => 'isSiret'),
'ape' => array('type' => self::TYPE_STRING, 'validate' => 'isApe'),
'outstanding_allow_amount' => array('type' => self::TYPE_INT, 'validate' => 'isFloat', 'copy_post' => false),

View File

@@ -53,7 +53,6 @@ class LocalizationPackCore
$res &= $this->installConfiguration($xml);
$res &= $this->installModules($xml);
$res &= $this->updateDefaultGroupDisplayMethod($xml);
$res &= $this->installAccounting($xml);
if (!defined('_PS_MODE_DEV_') || !_PS_MODE_DEV_)
$res &= $this->_installLanguages($xml, $install_mode);
@@ -76,30 +75,6 @@ class LocalizationPackCore
return true;
}
/**
* Install the default value for accounting
*
* @param $xml
* @return true
*/
protected function installAccounting($xml)
{
if (isset($xml->accounting->conf))
{
$acc_conf = Accounting::getConfiguration();
foreach ($xml->accounting->conf as $conf)
{
$attributes = $conf->attributes();
if (isset($attributes['name']) &&
isset($attributes['value']) &&
isset($acc_conf[(string)$attributes['name']]))
$acc_conf[(string)$attributes['name']] = (string)$attributes['value'];
}
Accounting::updateConfiguration($acc_conf);
}
return true;
}
protected function _installStates($xml)
{
if (isset($xml->states->state))
@@ -176,7 +151,6 @@ class LocalizationPackCore
$tax = new Tax();
$tax->name[(int)Configuration::get('PS_LANG_DEFAULT')] = (string)$attributes['name'];
$tax->rate = (float)$attributes['rate'];
$tax->account_number = isset($attributes['account_number']) ? (string)$attributes['account_number'] : '';
$tax->active = 1;
if (!$tax->validateFields())

View File

@@ -40,9 +40,6 @@ class TaxCore extends ObjectModel
/** @var boolean true if the tax has been historized */
public $deleted = 0;
/** @var string Account Number */
public $account_number;
/**
* @see ObjectModel::$definition
*/
@@ -52,7 +49,6 @@ class TaxCore extends ObjectModel
'multilang' => true,
'fields' => array(
'rate' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'required' => true),
'account_number' => array('type' => self::TYPE_STRING),
'active' => array('type' => self::TYPE_BOOL),
'deleted' => array('type' => self::TYPE_BOOL),
@@ -260,18 +256,5 @@ class TaxCore extends ObjectModel
return $tax_calculator->getTotalRate();
}
/**
* Returns the Account number of a Tax
*
* @param integer $id_tax
* @return string Account Number
*/
public static function getAccountNumberByIdTax($id_tax)
{
return Db::getInstance()->getValue('
SELECT account_number FROM `'._DB_PREFIX_.'tax`
WHERE id_tax = '.(int)$id_tax);
}
}

View File

@@ -1,237 +0,0 @@
<?php
/*
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
ing*
* 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-2012 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 AdminAccountingConfigurationControllerCore extends AdminController
{
public $acc_conf = array();
public $fields_list_detail = array();
public function __construct()
{
parent::__construct();
$this->acc_conf = Accounting::getConfiguration();
$this->className = 'Accounting';
}
public function initToolbar()
{
$this->initToolbarTitle();
$this->toolbar_btn['save'] = array(
'href' => '#',
'desc' => $this->l('Save')
);
}
public function initAccountZoneShop()
{
$zones = Zone::getZones();
$id_shop = $this->context->shop->id;
$fields_option = array();
// Set default zone value to the shop and sort it
foreach ($zones as $zone)
$fields_option['zone_'.$zone['id_zone']] = array(
'title' => $zone['name'],
'type' => 'text',
'value' => '',
'size' => '15',
'id' => 'zone_'.$zone['id_zone'],
'name' => 'zone_'.$zone['id_zone'],
'auto_value' => false
);
ksort($fields_option);
$zone_shop_list = Accounting::getAccountNumberZoneShop($id_shop);
$this->fields_list_detail['zone'] = array(
'title' => $this->l('Account number by zone'),
'fields' => array(
'default_account_number' => array(
'title' => $this->l('Default number for this shop'),
'desc' => $this->l('If a zone field is empty it will use this default number'),
'type' => 'text',
'value' => Configuration::get('default_account_number', null, null, $id_shop),
'size' => '15',
'auto_value' => false
))
);
// Set Account number to the id_zone for the id_shop if exist
foreach ($zone_shop_list as $zone_shop)
$fields_option['zone_'.$zone_shop['id_zone']]['value'] = $zone_shop['account_number'];
$this->fields_list_detail['zone']['fields'] = array_merge($this->fields_list_detail['zone']['fields'], $fields_option);
}
public function initAccountingForm()
{
// Only text type available for this configuration, handle new missing type in the tpl file (as the options.tpl helper file)
$this->fields_list_detail = array(
'general' => array(
'title' => $this->l('Export'),
'fields' => array(
'customer_prefix' => array(
'title' => $this->l('Customer prefix:'),
'desc' => $this->l('Set your default customer prefix'),
'type' => 'text',
'value' => $this->acc_conf['customer_prefix'],
'size' => '15',
'auto_value' => false
),
'journal' => array(
'title' => $this->l('Journal:'),
'desc' => '',
'type' => 'text',
'value' => $this->acc_conf['journal'],
'size' => '15',
'auto_value' => false
),
'account_length' => array(
'title' => $this->l('Customer account length:'),
'desc' => $this->l('Set the length of the customer account number (the prefix will always be displayed with the customer id)'),
'type' => 'text',
'value' => $this->acc_conf['account_length'],
'size' => '15',
'auto_value' => false
)
)
),
'account_number_list' => array(
'title' => $this->l('Default account number Management'),
'fields' => array(
'account_submit_shipping_charge' => array(
'title' => $this->l('Submited shipping charge account:'),
'desc' => $this->l('Set the account for submited shipping charged'),
'type' => 'text',
'value' => $this->acc_conf['account_submit_shipping_charge'],
'size' => '15',
'auto_value' => false
),
'account_unsubmit_shipping_charge' => array(
'title' => $this->l('Unsubmited shipping charge account:'),
'desc' => $this->l('Set the account for unsubmited shipping charged'),
'type' => 'text',
'value' => $this->acc_conf['account_unsubmit_shipping_charge'],
'size' => '15',
'auto_value' => false
),
'account_gift_wripping' => array(
'title' => $this->l('Gift-wrapping account number:'),
'desc' => $this->l('Set the account number for the gift-wrapping'),
'type' => 'text',
'value' => $this->acc_conf['account_gift_wripping'],
'size' => '15',
'auto_value' => false
),
'account_handling' => array(
'title' => $this->l('Handling account number:'),
'desc' => $this->l('Set the account number for handling'),
'type' => 'text',
'value' => $this->acc_conf['account_handling'],
'size' => '15',
'auto_value' => false
)
),
'submit' => array('name' => 'update_cfg')
),
);
$this->initAccountZoneShop();
}
public function initContent()
{
$this->display = 'options';
$this->initToolbar();
$this->initAccountingForm();
$this->context->smarty->assign(array(
'title' => $this->l('Accounting Configuration'),
'acc_conf' => $this->acc_conf,
'input_category_list' => $this->fields_list_detail,
'table' => 'accounting',
'has_shop_selected' => (count(Shop::getContextListShopID()) == 1),
'toolbar_btn' => $this->toolbar_btn,
'show_toolbar' => $this->show_toolbar,
'toolbar_scroll' => $this->toolbar_scroll
));
parent::initContent();
}
public function postProcess()
{
if (Tools::isSubmit('update_cfg'))
{
foreach ($this->acc_conf as $name => $val)
$this->acc_conf[$name] = Tools::getValue($name);
Accounting::updateConfiguration($this->acc_conf);
$this->updateAccountNumber();
Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token.'&update=true');
}
else if (Tools::getValue('update'))
$this->confirmations[] = $this->l('Configuration updated');
}
/**
* Update the account number for each shop liable to their zones
*/
protected function updateAccountNumber()
{
$id_shop = $this->context->shop->id;
// 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))
$this->confirmations[] = $this->l('Account numbers have been updated');
else
$this->errors[] = $this->l('Account Numbers could not be updated or added in the database');
}
}
}

View File

@@ -1,536 +0,0 @@
<?php
/*
* 2007-2012 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-2012 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 $exportTypeList = array();
public $downloadDir = '';
public $downloadFile = '';
public $file = '';
public $already_generated = false;
public $exportSelected = '';
public $fd = null;
public $date = array(
'begin' => '',
'end' => ''
);
public $prevent = array(
'errors' => array(),
'warn' => array(),
'hints' => array());
public $exportedFilePath = '';
public $acc_conf = array();
public $file_format;
public function __construct()
{
$this->className = 'Accounting';
$this->content = '';
$this->downloadDir = _PS_ADMIN_DIR_.'/export/';
$this->exportSelected = 'accounting_export';
$this->initExportFieldList();
parent::__construct();
}
/**
* Init the available fields by export type with associated translation
*/
protected function initExportFieldList()
{
$this->exportTypeList = array(
'accounting_export' => array(
'name' => $this->l('Accounting Export'),
'type' => 'accounting_export',
'file' => 'accounting_export.csv',
'fields' => array(
'invoice_date' => $this->l('Invoice Date', 'AdminTab', false, false),
'journal' => $this->l('Journal', 'AdminTab', false, false),
'account' => $this->l('Account', 'AdminTab', false, false),
'invoice_number' => $this->l('Invoice Number', 'AdminTab', false, false),
'credit' => $this->l('Credit (TTC)', 'AdminTab', false, false),
'debit' => $this->l('Debit (TVA+HT)', 'AdminTab', false, false),
'transaction_id' => $this->l('Transaction Number', 'AdminTab', false, false),
'payment_type' => $this->l('Payment Type', 'AdminTab', false, false),
'currency_code' => $this->l('Currency Code', 'AdminTab', false, false),
'wording' => $this->l('Wording', 'AdminTab', false, false)
),
'type' => 0
),
'reconciliation_export' => array(
'name' => $this->l('Reconciliation Export'),
'type' => 'reconciliation_export',
'file' => 'accounting_reconciliation_export.csv',
'fields' => array(
'invoice_number' => $this->l('Invoice Number', 'AdminTab', false, false),
'wording' => $this->l('Wording', 'AdminTab', false, false),
'total_paid_real' => $this->l('Total TTC', 'AdminTab', false, false),
'invoice_date' => $this->l('Invoice Date', 'AdminTab', false, false),
'transaction_id' => $this->l('Transaction Number', 'AdminTab', false, false),
'account_client' => $this->l('Account client', 'AdminTab', false, false)
),
'type' => 1
)
);
}
/**
* AdminController::setMedia() override
* @see AdminController::setMedia()
*/
public function setMedia()
{
parent::setMedia();
$this->addJqueryUi('ui.datepicker');
}
protected function checkRights()
{
if (!is_writeable($this->downloadDir))
$this->errors[] = $this->l('The download folder doesn\'t have the sufficient right');
if (!($this->fd = fopen($this->downloadFile, 'w+')))
$this->errors[] = $this->l('The file can\'t be opened or created, please check the rights');
@chmod($this->downloadFile, 0777);
}
public function getExportedList()
{
$exported_list = Accounting::getExportedList();
foreach ($exported_list as &$export)
foreach ($this->exportTypeList as $export_type)
{
$export['title'] = $this->l('Undefined');
if (((int)$export_type['type']) == ((int)$export['type']))
{
$export['title'] = $export_type['name'];
break;
}
}
return $exported_list;
}
/**
* AdminController::init() override
* @see AdminController::init()
*/
public function initContent()
{
$this->context->smarty->assign(array(
'begin_date' => Tools::getValue('begin_date'),
'end_date' => Tools::getValue('end_date'),
'file_format' => $this->file_format,
'export_type' => $this->exportSelected,
'urlDownload' => Tools::getShopDomain().'/download/',
'preventList' => $this->prevent,
'export_type_list' => $this->exportTypeList,
'exported_list' => $this->getExportedList(),
'already_generated' => Configuration::get('REQUEST_URI').$this->already_generated,
));
parent::initContent();
}
public function saveRangeDate()
{
$keys = array('`begin_to`', '`end_to`', '`type`', '`file`');
$values = array(
'"'.pSQL($this->date['begin']).'"',
'"'.pSQL($this->date['end']).'"',
(int)$this->exportTypeList[$this->exportSelected]['type'],
'"'.pSQL($this->file).'"'
);
if (!($id_acc_export = Tools::getValue('regenerate')))
$query = '
INSERT INTO `'._DB_PREFIX_.'accounting_export`
('.implode(', ', $keys).')
VALUES('.implode(', ', $values).')';
else
$query = 'UPDATE `'._DB_PREFIX_.'accounting_export`
SET `date` = CURRENT_TIMESTAMP, `file` = "'.pSQL($this->file).'"
WHERE `id_accounting_export` = '.(int)$id_acc_export;
Db::getInstance()->execute($query);
}
/**
* AdminController::postProcess() override
* @see AdminController::postProcess()
*/
public function postProcess()
{
$succeed = false;
if (Tools::isSubmit('accounting_export'))
{
$this->acc_conf = Accounting::getConfiguration();
$this->date['begin'] = Tools::getValue('begin_date');
$this->date['end'] = Tools::getValue('end_date');
$this->exportSelected = Tools::getValue('type');
$this->file_format = Tools::getValue('format');
$this->file = $this->exportSelected.'-'.$this->date['begin'].
'to'.$this->date['end'].'.'.$this->file_format;
$this->downloadFile = $this->downloadDir.$this->file;
// Depends of the number of order and the range dates
// Switch to ajax if there is any problems with time
ini_set('max_execution_time', 0);
if (!in_array($this->file_format, array('csv', 'txt')))
$this->prevent['error'][] = $this->l('Please select file format');
else if (!empty($this->date['begin']) && !empty($this->date['end']) &&
(Tools::getValue('regenerate') || !$this->isAlreadyGenerated()))
{
switch ($this->exportSelected)
{
case 'reconciliation_export':
$succeed = $this->runReconciliationExport();
break;
case 'accounting_export':
$succeed = $this->runGlobalExport();
break;
default:
$this->prevent['error'][] = $this->l('Please select a export type');
}
if ($succeed)
$this->saveRangeDate();
}
else if (!$this->already_generated)
$this->prevent['error'][] = $this->l('Please select the date');
}
else if (($file = Tools::getValue('download')) && file_exists($this->downloadDir.$file))
$this->launchDownloadFile($file);
}
public function isAlreadyGenerated()
{
$query = '
SELECT ae.`type`, ae.`id_accounting_export`
FROM `'._DB_PREFIX_.'accounting_export` ae
WHERE ae.`begin_to` = "'.pSQL($this->date['begin']).'"
AND ae.`end_to` = "'.pSQL($this->date['end']).'"
AND ae.`type` = '.(int)$this->exportTypeList[$this->exportSelected]['type'];
if (($entry = Db::getInstance()->getRow($query)) !== false)
{
if ($this->exportTypeList[$this->exportSelected]['type'] == $entry['type'])
{
$this->prevent['warn'][] = $this->l('This export has already be proceed with this file format');
$this->already_generated = $entry['id_accounting_export'];
}
else
{
$this->prevent['warn'][] = $this->l('This export has already be proceed with a different file format');
$this->already_generated = true;
}
}
return (bool)$this->already_generated;
}
/**
* Write the exported content tout a file
* @var array $list Result of the SQL query
*/
protected function writeExportToFile($list)
{
$this->checkRights();
if (!count($this->errors) && $this->fd !== null)
{
$buffer = '';
foreach ($this->exportTypeList[$this->exportSelected]['fields'] as $key => $translation)
$buffer .= '"'.$translation.'";';
fwrite($this->fd, mb_convert_encoding(rtrim($buffer, ';')."\r\n", 'UTF-16LE'));
// Bufferize line by line and write it to the file
// Todo :: Allow to configure the size of the buffer before flushing it
foreach ($list as $row)
{
$buffer = '';
foreach ($row as $col => $val)
$buffer .= '"'.$val.'";';
fwrite($this->fd, mb_convert_encoding(rtrim($buffer, ';')."\r\n", 'UTF-16LE'));
}
$this->confirmations[] = $this->l('Export has been successfully completed');
return true;
}
return false;
}
/**
* Start the reconciliation export type
*/
protected function runReconciliationExport()
{
$query = '
SELECT
CONCAT(\''.Configuration::get('PS_INVOICE_PREFIX').'\', LPAD(oi.`number`, 6, "0")) AS invoice_number,
CASE
WHEN (a.`company` != "" AND a.`company` IS NOT NULL) THEN a.`company`
ELSE a.`lastname`
END AS wording,
o.`total_paid_real`,
oi.`date_add` as invoice_date,
pcc.`transaction_id`,
CONCAT(\''.pSQL($this->acc_conf['customer_prefix']).'\', LPAD(c.`id_customer`, 6, "0")) AS account_client
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'customer` c ON c.`id_customer` = o.`id_customer`
LEFT JOIN `'._DB_PREFIX_.'address` a ON a.`id_customer` = o.`id_customer`
LEFT JOIN `'._DB_PREFIX_.'order_payment` pcc ON pcc.`id_order` = o.`id_order`
LEFT JOIN `'._DB_PREFIX_.'order_invoice` oi ON oi.`id_order` = o.`id_order`
WHERE o.`valid` = 1
AND oi.`date_add`
BETWEEN \''.pSQL($this->date['begin']).'\'
AND \''.pSQL($this->date['end']).'\'';
$list = Db::getInstance()->executeS($query);
return $this->writeExportToFile($list);
}
/**
* Generate a line for the CSV for the global export
*
* @param $row
* @param $line_number
* @return array
*/
protected function createLine($row, $line_number)
{
$line = array();
// Default Values
$line[0] = $row['invoice_date'];
$line[1] = $this->acc_conf['journal'];
$line[2] = ''; // account number
$line[3] = $row['invoice_number'];
$line[4] = 0.00; // Credit TTC (Total for first csv line, 0 for others)
$line[5] = 0.00; // Debit HT (0 For the first line, used for tax too)
$line[6] = $row['transaction_id'];
$line[7] = $row['payment_type'];
$line[8] = $row['currency_code'];
$line[9] = $row['wording'];
// Override case depending of the whished line
switch ($line_number)
{
case 0:
$line[2] = $row['account_client'];
$line[4] = $row['total_price_tax_incl'];
break;
case 1:
$line[2] = !empty($row['account']) ? $row['account'] :
Configuration::get('default_account_number', null, null, $row['id_shop']);
// Force an empty string if Configuration send false
$line[2] = empty($line[2]) ? '' : $line[2];
$line[5] = $row['product_price_ht'];
break;
case 2:
$line[2] = $row['tax_accounting_account_number'];
$line[5] = $row['tax_total_amount'];
break;
}
return $line;
}
/**
* Build an proper list to be written into the export file
*
* @param $db_details
* @return array
*/
protected function buildGlobalExportlist($db_details)
{
// List use to write data in csv file
$list = array();
// Cache list to merge easily the content with the same accounting for different invoice number
$cache_list = array();
$num = 0;
foreach ($db_details as $row)
{
// Init the list for the current invoice number
if (!array_key_exists($row['invoice_number'], $cache_list))
$cache_list[$row['invoice_number']] = array();
// Need to Generate 3 lines for a product
for ($i = 0; $i < 3; ++$i)
// Create the two first line and check if a tax exist for the last one
if ($i < 2 || ($i == 2 && $row['id_tax'] !== null))
{
// Generate a product line
$line = $this->createLine($row, $i);
if ($i == 0)
$list[$num++] = $line;
else
{
// Check if the account number hadn't already be used for this invoice number
// $line[3] = invoice_number, $line[2] = account_number
if (!array_key_exists($line[2], $cache_list[$line[3]]))
$cache_list[$line[3]][$line[2]] = array();
// If this id_product doesn't exist for this invoice number, then we create it as a cache
if (!in_array($row['id_product'], $cache_list[$line[3]][$line[2]]))
{
$cache_list[$line[3]][$line[2]][$row['id_product']] = array(
'position' => $num,
'id_order' => $row['id_order'],
'id_product_attribute' => $row['id_product_attribute'],
'quantity' => 1,
'advanced_stock_management' => $row['advanced_stock_management']);
$list[$num++] = $line;
}
else
{
// Merge amount retrieving the position in the list of the invoice number
// Some information could change (quantity) for the Stock movement price calculation
$pos = $cache_list[$line[3]][$line[2]][$row['id_product']]['position'];
$cache_list[$line[3]][$line[2]][$row['id_product']]['quantity'] += 1;
if (!$i)
$list[$pos][4] += $line[4];
else
$list[$pos][5] += $line[5];
}
}
}
}
// If advanced stock management enable then we foreach the cache_list to know
// if a product use the system to store back the movement price.
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
foreach ($cache_list as $invoice_list)
foreach ($invoice_list as $product_list)
foreach ($product_list as $id_product => $product_detail)
if ($product_detail['advanced_stock_management'])
{
// Get stock product stock movement detail
$stock_mvt = StockMvt::getNegativeStockMvts(
$product_detail['id_order'],
$id_product,
$product_detail['id_product_attribute'],
$product_detail['quantity']);
// Store new price
$list[$product_detail['position']] = $stock_mvt['price_te'];
}
return $list;
}
/**
* Start the global export type
*
*/
protected function runGlobalExport()
{
$query = '
SELECT
od.`id_order`,
oi.`date_add` as invoice_date,
CASE
WHEN (acc_pzs.`account_number` != "" AND acc_pzs.`account_number` IS NOT NULL) THEN acc_pzs.`account_number`
WHEN (acc_zs.`account_number` != "" AND acc_zs.`account_number` IS NOT NULL) THEN acc_zs.`account_number`
ELSE ""
END AS account,
CONCAT(\''.Configuration::get('PS_INVOICE_PREFIX').'\', LPAD(oi.`number`, 6, "0")) AS invoice_number,
od.`total_price_tax_incl`,
od.`product_price` AS product_price_ht,
pcc.`transaction_id`,
o.`payment` AS payment_type,
currency.`iso_code` AS currency_code,
CONCAT(\''.pSQL($this->acc_conf['customer_prefix']).'\', LPAD(customer.`id_customer`, 6, "0")) AS account_client,
CASE
WHEN (customer.`account_number` != "" AND customer.`account_number` IS NOT NULL) THEN customer.`account_number`
WHEN (a.`company` != "" AND a.`company` IS NOT NULL) THEN a.`company`
ELSE a.`lastname`
END AS wording,
t.`account_number` AS tax_accounting_account_number,
t.`id_tax`,
o.`id_shop`,
odt.`total_amount` AS tax_total_amount,
od.`product_id` AS id_product,
od.`product_attribute_id` as id_product_attribute,
product_shop.`advanced_stock_management`
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'customer` customer ON customer.`id_customer` = o.`id_customer`
LEFT JOIN `'._DB_PREFIX_.'address` a ON a.`id_customer` = o.`id_customer`
LEFT JOIN `'._DB_PREFIX_.'order_payment` pcc ON pcc.`id_order` = o.`id_order`
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON od.`id_order` = o.`id_order`
LEFT JOIN `'._DB_PREFIX_.'currency` currency ON currency.`id_currency` = o.`id_currency`
LEFT JOIN `'._DB_PREFIX_.'order_detail_tax` odt ON odt.`id_order_detail` = od.`id_order_detail`
LEFT JOIN `'._DB_PREFIX_.'tax` t ON t.`id_tax` = odt.`id_tax`
LEFT JOIN `'._DB_PREFIX_.'country` country ON country.`id_country` = a.`id_country`
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = od.`product_id`
'.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN `'._DB_PREFIX_.'accounting_product_zone_shop` acc_pzs
ON (acc_pzs.`id_shop` = o.`id_shop`
AND acc_pzs.`id_zone` = country.`id_zone`
AND acc_pzs.`id_product` = od.`product_id`)
LEFT JOIN `'._DB_PREFIX_.'accounting_zone_shop` acc_zs
ON (acc_zs.`id_shop` = o.`id_shop`
AND acc_zs.`id_zone` = country.`id_zone`)
LEFT JOIN `'._DB_PREFIX_.'order_invoice` oi ON oi.id_order = o.id_order
WHERE o.`valid` = 1
AND oi.`date_add`
BETWEEN \''.pSQL($this->date['begin']).'\'
AND \''.pSQL($this->date['end']).'\'
ORDER BY o.`id_order` ASC';
$list = $this->buildGlobalExportlist(Db::getInstance()->executeS($query));
return $this->writeExportToFile($list);
}
/**
* Allow to download the last export file
* @var string File name
*/
protected function launchDownloadFile($fileName)
{
$path = $this->downloadDir.$fileName;
header('Content-length: '.filesize($path));
header('Content-Disposition: attachment; filename="'.$fileName.'"');
// Flush buffered data before reading the file
ob_clean();
flush();
@readfile($path);
exit();
}
}

View File

@@ -1,136 +0,0 @@
<?php
/*
* 2007-2012 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-2012 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->className = 'Accounting';
parent::__construct();
}
public function initContent()
{
$shop = array();
$error = '';
if (count(Shop::getContextListShopID()) > 1)
$error = $this->l('Please select the shop you want to configure');
else
{
$this->initToolbar();
$zones = Zone::getZones();
$id_shop = $this->context->shop->id;
// 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']);
$zone_shop_list = Accounting::getAccountNumberZoneShop($id_shop);
// Set Account number to the id_zone for the id_shop if exist
foreach ($zone_shop_list as $zone_shop)
$shop['zones'][$zone_shop['id_zone']]['account_number'] = $zone_shop['account_number'];
}
$this->context->smarty->assign(array(
'shop_details' => $shop,
'error' => $error,
'toolbar_btn' => $this->toolbar_btn,
'title' => $this->l('Accounting Management'),
'table' => 'accounting'
));
parent::initContent();
}
/**
* 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
*/
protected function updateAccountNumber()
{
$id_shop = $this->context->shop->id;
// 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))
$this->confirmations[] = $this->l('Account numbers have been updated');
else
$this->errors[] = $this->l('Account Numbers could not be updated or added in the database');
}
}
}

View File

@@ -1,193 +0,0 @@
<?php
/*
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
ing*
* 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-2012 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 AdminAccountingRegisteredNumberControllerCore extends AdminController
{
public $account_number_list = array();
public function __construct()
{
parent::__construct();
$this->className = 'Accounting';
$id_lang = $this->context->language->id;
// p. => main table, s. => join table
// Contains rules to build sql query, or method call to special traitment
$this->account_number_list = array(
// Product definition
'product' => array(
'table' => 'accounting_product_zone_shop',
'fields' => array(
'p.account_number' => $this->l('Account number'),
'COUNT(*) AS total' => $this->l('Number of products associated with this account')
),
'group_by' => 'account_number',
'condition' => 'p.account_number <> "" AND account_number IS NOT NULL',
'title' => $this->l('Product account numbers'),
'list' => array()),
// Taxes definition
'taxes' => array(
'table' => 'tax',
'fields' => array(
'account_number' => $this->l('Account number'),
'COUNT(*) AS total' => $this->l('Number of taxes associated with this account')
),
'group_by' => 'account_number',
'condition' => 'account_number <> "" AND account_number IS NOT NULL',
'title' => $this->l('Tax account numbers'),
'list' => array()),
// Gift wrapping definition
'gift_wrapping' => array(
'func_call' => 'getAccountingNumberConfiguration',
'key' => 'account_gift_wripping',
'fields' => array(
'account_number' => $this->l('Account number'),
'total' => $this->l('Number of gift-wrapping options associated with this account')
),
'title' => $this->l('Gift-wrapping account numbers'),
'list' => array()),
// Submited shipping charge definition
'submited_shipping_charge' => array(
'func_call' => 'getAccountingNumberConfiguration',
'key' => 'account_submit_shipping_charge',
'fields' => array(
'account_number' => $this->l('Account number'),
'total' => $this->l('Number of submited shipping charge associated to this account')
),
'title' => $this->l('Submited shipping charge account number list'),
'list' => array()),
// Unsubmited shipping charge definition
'unsubmited_shipping_charge' => array(
'func_call' => 'getAccountingNumberConfiguration',
'key' => 'account_unsubmit_shipping_charge',
'fields' => array(
'account_number' => $this->l('Account number'),
'total' => $this->l('Number of unsubmited shipping charge associated to this account')
),
'title' => $this->l('Unsubmited shipping charge account number list'),
'list' => array()),
// Customer definition
'customer' => array(
'table' => 'customer',
'fields' => array(
'account_number' => $this->l('Account number'),
'firstname' => $this->l('First name'),
'lastname' => $this->l('Last name')
),
'group_by' => 'account_number',
'condition' => 'account_number <> "" AND account_number IS NOT NULL',
'title' => $this->l('Customer account numbers'),
'list' => array()),
// Zone shop definition
'zone_shop' => array(
'table' => 'accounting_zone_shop',
'fields' => array(
'p.account_number' => $this->l('Account number'),
'COUNT(*) AS total' => $this->l('Number of zones associated with this account')
),
'group_by' => 'account_number',
'condition' => 'account_number <> "" AND account_number IS NOT NULL',
'title' => $this->l('Zone shop account numbers'),
'list' => array())
);
}
public function initToolbar()
{
$this->initToolbarTitle();
$this->toolbar_btn = array();
}
public function initContent()
{
$this->initToolbar();
$this->initAccountNumberList();
$this->context->smarty->assign(array(
'toolbar_btn' => $this->toolbar_btn,
'show_toolbar' => true,
'toolbar_scroll' => true,
'title' => $this->l('Accounting Plan'),
'account_number_list' => $this->account_number_list));
parent::initContent();
}
/**
* Return the value configuration requested.
*
* @TODO : Add the possibility to check in all shop
* @param string $key of the Accounting configuration
* @return array
*/
public function getAccountingNumberConfiguration($key)
{
if (($num = Accounting::getConfiguration($key)))
return array(array($num, '1'));
return array();
}
public function initAccountNumberList()
{
foreach ($this->account_number_list as $name => &$detail)
{
if (isset($detail['table']) && !empty($detail['table']))
{
$join = '';
if (isset($detail['left_join']))
{
$join = 'LEFT JOIN '._DB_PREFIX_.$detail['left_join']['table'].' s ON (';
foreach ($detail['left_join']['on'] as $on)
$join .= 'p.'.$on.' = s.'.$on.' AND ';
$join = rtrim($join, ' AND ').')';
}
$query = '
SELECT '.implode(', ', array_keys($detail['fields'])).'
FROM `'._DB_PREFIX_.$detail['table'].'` p '.$join.'
WHERE '.$detail['condition'];
if (isset($detail['group_by']))
$query .= ' GROUP BY '.$detail['group_by'];
$detail['list'] = Db::getInstance()->executeS($query);
}
else if (isset($detail['func_call']) &&
isset($detail['key']) &&
method_exists($this, $detail['func_call']))
$detail['list'] = $this->{$detail['func_call']}($detail['key']);
}
}
}

View File

@@ -272,15 +272,6 @@ class AdminCustomersControllerCore extends AdminController
'required' => ($obj->id ? false : true),
'desc' => ($obj->id ? $this->l('Leave blank if no change') : $this->l('5 characters min., only letters, numbers, or').' -_')
),
array(
'type' => 'text',
'label' => $this->l('Accounting number:'),
'name' => 'account_number',
'size' => 33,
'required' => false,
'desc' => sprintf($this->l('Used for the accounting export. If this field is empty, the accounting export will use the predefined number from your shop %s'),
$accounting_number ? '('.$accounting_number.')' : '')
),
array(
'type' => 'birthday',
'label' => $this->l('Birthday:'),

View File

@@ -2491,51 +2491,6 @@ class AdminProductsControllerCore extends AdminController
}
}
/**
* Init data for accounting
*/
public function initFormAccounting($obj)
{
$data = $this->createTemplate($this->tpl_form);
if ($obj->id)
{
$error = '';
$detail = array();
if (count(Shop::getContextListShopID()) > 1)
$error = $this->l('Please select the shop you want to configure');
else
{
$zones = Zone::getZones();
$id_shop = $this->context->shop->id;
// 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($obj->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'];
}
$data->assign(array(
'productAccountNumberList' => $detail,
'shopName' => $this->context->shop->name,
'error' => $error,
'product' => $obj
));
}
else
$this->displayWarning($this->l('You must save this product before managing accounting.'));
$this->tpl_form_vars['custom_form'] = $data->fetch();
}
public function initFormAssociations($obj)
{
$product = $obj;

View File

@@ -162,16 +162,6 @@ class AdminTaxesControllerCore extends AdminController
'label' => $this->l('Disabled')
)
)
),
array(
'type' => 'text',
'label' => $this->l('Account number:'),
'name' => 'account_number',
'size' => 33,
'maxlength' => 64,
'required' => false,
'hint' => $this->l('Invalid characters:').' <>;=#{}',
'desc' => $this->l('Used for the accounting export')
)
),
'submit' => array(

View File

@@ -542,7 +542,6 @@ CREATE TABLE `PREFIX_customer` (
`passwd` varchar(32) NOT NULL,
`last_passwd_gen` timestamp NOT NULL default CURRENT_TIMESTAMP,
`birthday` date default NULL,
`account_number` varchar(128) NULL,
`newsletter` tinyint(1) unsigned NOT NULL default '0',
`ip_registration_newsletter` varchar(15) default NULL,
`newsletter_date_add` datetime default NULL,
@@ -1748,8 +1747,7 @@ CREATE TABLE `PREFIX_tax` (
`id_tax` int(10) unsigned NOT NULL auto_increment,
`rate` DECIMAL(10, 3) NOT NULL,
`active` tinyint(1) unsigned NOT NULL default '1',
`deleted` tinyint(1) unsigned NOT NULL default '0',
`account_number` varchar(64) NOT NULL,
`deleted` tinyint(1) unsigned NOT NULL default '0',s
PRIMARY KEY (`id_tax`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
@@ -2328,35 +2326,6 @@ CREATE TABLE `PREFIX_product_supplier` (
UNIQUE KEY `id_product` (`id_product`,`id_product_attribute`,`id_supplier`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `PREFIX_accounting_export` (
`id_accounting_export` int(11) NOT NULL AUTO_INCREMENT,
`begin_to` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`end_to` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`type` int(11) NOT NULL,
`file` varchar(256) NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id_accounting_export`)
) 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;
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;
CREATE TABLE `PREFIX_order_carrier` (
`id_order_carrier` int(11) NOT NULL AUTO_INCREMENT,
`id_order` int(11) unsigned NOT NULL,

View File

@@ -255,12 +255,6 @@
<tab id="SQL_Manager" id_parent="Advanced_parameters" active="1">
<class_name>AdminRequestSql</class_name>
</tab>
<tab id="Accounting" id_parent="Advanced_parameters" active="1">
<class_name>AdminAccountingConfiguration</class_name>
</tab>
<tab id="Accounting_plan" id_parent="Advanced_parameters" active="1">
<class_name>AdminAccountingRegisteredNumber</class_name>
</tab>
<tab id="Logs" id_parent="Advanced_parameters" active="1">
<class_name>AdminLogs</class_name>
</tab>
@@ -294,9 +288,6 @@
<tab id="Referrers" id_parent="Stats" active="1">
<class_name>AdminReferrers</class_name>
</tab>
<tab id="Accounting_export" id_parent="Stats" active="1">
<class_name>AdminAccountingExport</class_name>
</tab>
<tab id="Warehouses" id_parent="Stock" active="1">
<class_name>AdminWarehouses</class_name>
</tab>

View File

@@ -2,5 +2,11 @@ SET NAMES 'utf8';
ALTER TABLE `PREFIX_state` CHANGE `iso_code` `iso_code` varchar(7) NOT NULL;
DROP TABLE `PREFIX_accounting_export`;
DROP TABLE `PREFIX_accounting_zone_shop`;
DROP TABLE `PREFIX_accounting_product_zone_shop`;
ALTER TABLE `PREFIX_tax` DROP `account_number`;
ALTER TABLE `PREFIX_customer` DROP `account_number`;
/* PHP:move_translations_module_file(); */;