// stock management : Bugs fix after rename and historization modifications

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10131 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
dSevere
2011-11-15 14:05:57 +00:00
parent b9ee33bdcb
commit ac8177b68c
5 changed files with 416 additions and 85 deletions
@@ -0,0 +1,215 @@
<?php
/*
* 2007-2011 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-2011 PrestaShop SA
* @version Release: $Revision: 7300 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminSuppliersControllerCore extends AdminController
{
public function __construct()
{
$this->table = 'supplier';
$this->className = 'Supplier';
$this->addRowAction('view');
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
$this->_select = 'COUNT(p.`id_product`) AS products';
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product` p ON (a.`id_supplier` = p.`id_supplier`)';
$this->_group = 'GROUP BY a.`id_supplier`';
$this->fieldImageSettings = array('name' => 'logo', 'dir' => 'su');
$this->fieldsDisplay = array(
'id_supplier' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'logo' => array('title' => $this->l('Logo'), 'width' => 150, 'align' => 'center', 'image' => 'su', 'orderby' => false, 'search' => false),
'name' => array('title' => $this->l('Name'), 'width' => 'auto'),
'products' => array('title' => $this->l('Number of products'), 'width' => 70, 'align' => 'right', 'filter_type' => 'int', 'tmpTableFilter' => true),
'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('Suppliers'),
'image' => '../img/admin/suppliers.gif'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Name:'),
'name' => 'name',
'size' => 40,
'required' => true,
'hint' => $this->l('Invalid characters:').' <>;=#{}',
),
array(
'type' => 'text',
'label' => $this->l('Description:'),
'name' => 'description',
'size' => 33,
'lang' => true,
'hint' => $this->l('Invalid characters:').' <>;=#{}',
'p' => $this->l('Will appear in supplier list')
),
array(
'type' => 'file',
'label' => $this->l('Logo:'),
'name' => 'logo',
'display_image' => true,
'p' => $this->l('Upload supplier logo from your computer')
),
array(
'type' => 'text',
'label' => $this->l('Meta title:'),
'name' => 'smeta_title',
'lang' => true,
'hint' => $this->l('Forbidden characters:').' <>;=#{}'
),
array(
'type' => 'text',
'label' => $this->l('Meta description:'),
'name' => 'meta_description',
'lang' => true,
'hint' => $this->l('Forbidden characters:').' <>;=#{}'
),
array(
'type' => 'text',
'label' => $this->l('Meta keywords:'),
'name' => 'meta_keywords',
'lang' => true,
'hint' => $this->l('Forbidden characters:').' <>;=#{}'
),
array(
'type' => 'radio',
'label' => $this->l('Enable:'),
'name' => 'active',
'required' => false,
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
)
)
),
'submit' => array(
'title' => $this->l(' Save '),
'class' => 'button'
)
);
if (Shop::isFeatureActive())
{
$this->fields_form['input'][] = array(
'type' => 'group_shop',
'label' => $this->l('Shop association:'),
'name' => 'checkBoxShopAsso',
'values' => Shop::getTree()
);
}
// Set logo image
$image = cacheImage(_PS_SUPP_IMG_DIR_.'/'.$this->object->id.'.jpg', $this->table.'_'.(int)$this->object->id.'.'.$this->imageType, 350, $this->imageType, true);
$this->fields_value = array(
'image' => $image ? $image : false,
'size' => $image ? filesize(_PS_SUPP_IMG_DIR_.'/'.$this->object->id.'.jpg') / 1000 : false
);
return parent::initForm();
}
public function initView()
{
$products = $this->object->getProductsLite($this->context->language->id);
$total_product = count($products);
for ($i = 0; $i < $total_product; $i++)
{
$products[$i] = new Product($products[$i]['id_product'], false, $this->context->language->id);
// Build attributes combinaisons
$combinaisons = $products[$i]->getAttributeCombinaisons($this->context->language->id);
foreach ($combinaisons as $k => $combinaison)
{
$comb_array[$combinaison['id_product_attribute']]['reference'] = $combinaison['reference'];
$comb_array[$combinaison['id_product_attribute']]['ean13'] = $combinaison['ean13'];
$comb_array[$combinaison['id_product_attribute']]['upc'] = $combinaison['upc'];
$comb_array[$combinaison['id_product_attribute']]['quantity'] = $combinaison['quantity'];
$comb_array[$combinaison['id_product_attribute']]['attributes'][] = array(
$combinaison['group_name'],
$combinaison['attribute_name'],
$combinaison['id_attribute']
);
}
if (isset($comb_array))
{
foreach ($comb_array as $key => $product_attribute)
{
$list = '';
foreach ($product_attribute['attributes'] as $attribute)
$list .= $attribute[0].' - '.$attribute[1].', ';
$comb_array[$key]['attributes'] = rtrim($list, ', ');
}
isset($comb_array) ? $products[$i]->combinaison = $comb_array : '';
unset($comb_array);
}
}
$this->context->smarty->assign(array(
'supplier' => $this->object,
'products' => $products,
'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'),
));
}
public function afterImageUpload()
{
/* Generate image with differents size */
if (($id_supplier = (int)(Tools::getValue('id_supplier'))) AND isset($_FILES) AND count($_FILES) AND file_exists(_PS_SUPP_IMG_DIR_.$id_supplier.'.jpg'))
{
$imagesTypes = ImageType::getImagesTypes('suppliers');
foreach ($imagesTypes AS $k => $imageType)
{
$file = _PS_SUPP_IMG_DIR_.$id_supplier.'.jpg';
imageResize($file, _PS_SUPP_IMG_DIR_.$id_supplier.'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height']));
}
}
}
}
@@ -523,10 +523,6 @@ class AdminSupplyOrdersControllerCore extends AdminController
'width' => 120,
'havingFilter' => true
),
/*'employee' => array(
'title' => $this->l('Employee'),
'havingFilter' => true
),*/
'supplier' => array(
'title' => $this->l('Supplier'),
'width' => 200,
@@ -780,15 +776,7 @@ class AdminSupplyOrdersControllerCore extends AdminController
// re-defines fieldsDisplay
$this->fieldsDisplay = array(
'id' => array(
'title' => $this->l('ID'),
'align' => 'center',
'width' => 20,
'orderby' => false,
'filter' => false,
'search' => false,
),
'p_reference' => array(
'reference' => array(
'title' => $this->l('Reference'),
'align' => 'center',
'width' => 30,
@@ -796,7 +784,7 @@ class AdminSupplyOrdersControllerCore extends AdminController
'filter' => false,
'search' => false,
),
'p_ean13' => array(
'ean13' => array(
'title' => $this->l('EAN13'),
'align' => 'center',
'width' => 30,
@@ -804,6 +792,14 @@ class AdminSupplyOrdersControllerCore extends AdminController
'filter' => false,
'search' => false,
),
'upc' => array(
'title' => $this->l('UPC'),
'align' => 'center',
'width' => 30,
'orderby' => false,
'filter' => false,
'search' => false,
),
'p_name' => array(
'title' => $this->l('Name'),
'align' => 'center',
@@ -860,41 +856,40 @@ class AdminSupplyOrdersControllerCore extends AdminController
// sets toolbar title with order reference
$this->toolbar_title = sprintf($this->l('Reception of products for supply order #%s'), $supply_order->reference);
// gets lang info
$this->lang = false;
$lang_id = (int)$this->context->language->id;
$lang_id = (int)$this->context->language->id; //employee lang
// gets values corresponding to fieldsDisplay
$this->_select = '
a.id_supply_order_detail as id,
a.quantity_received as quantity_received,
a.quantity_expected as quantity_expected,
IF (a.quantity_expected < a.quantity_received, 0, a.quantity_expected - a.quantity_received) as quantity_left,
IF (a.quantity_expected < a.quantity_received, 0, a.quantity_expected - a.quantity_received) as quantity_received_today,
IFNULL(CONCAT(pl.name, \' : \', GROUP_CONCAT(agl.name, \' - \', al.name SEPARATOR \', \')), pl.name) as p_name,
p.reference as p_reference,
p.ean13 as p_ean13';
a.id_supply_order_detail as id,
a.quantity_received as quantity_received,
a.quantity_expected as quantity_expected,
IF (a.quantity_expected < a.quantity_received, 0, a.quantity_expected - a.quantity_received) as quantity_left,
IF (a.quantity_expected < a.quantity_received, 0, a.quantity_expected - a.quantity_received) as quantity_received_today,
IFNULL(CONCAT(pl.name, \' : \', GROUP_CONCAT(agl.name, \' - \', al.name SEPARATOR \', \')), pl.name) as p_name';
$this->_join = '
INNER JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = a.id_product AND pl.id_lang = '.$lang_id.')
LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = a.id_product)
LEFT JOIN '._DB_PREFIX_.'product_attribute_combination pac ON (pac.id_product_attribute = a.id_product_attribute)
LEFT JOIN '._DB_PREFIX_.'attribute atr ON (atr.id_attribute = pac.id_attribute)
LEFT JOIN '._DB_PREFIX_.'attribute_lang al ON (al.id_attribute = atr.id_attribute AND al.id_lang = '.$lang_id.')
LEFT JOIN '._DB_PREFIX_.'attribute_group_lang agl ON (agl.id_attribute_group = atr.id_attribute_group AND agl.id_lang = '.$lang_id.')';
INNER JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = a.id_product AND pl.id_lang = '.$lang_id.')
LEFT JOIN '._DB_PREFIX_.'product_attribute_combination pac ON (pac.id_product_attribute = a.id_product_attribute)
LEFT JOIN '._DB_PREFIX_.'attribute atr ON (atr.id_attribute = pac.id_attribute)
LEFT JOIN '._DB_PREFIX_.'attribute_lang al ON (al.id_attribute = atr.id_attribute AND al.id_lang = '.$lang_id.')
LEFT JOIN '._DB_PREFIX_.'attribute_group_lang agl ON (agl.id_attribute_group = atr.id_attribute_group AND agl.id_lang = '.$lang_id.')';
$this->_where = 'AND a.`id_supply_order` = '.(int)$id_supply_order;
$this->_group = 'GROUP BY a.id_supply_order_detail';
// gets the list ordered by price desc, without limit
$this->getList($lang_id, 'quantity_expected', 'DESC', 0, false, false);
// defines action for POST
$action = '&id_supply_order='.$id_supply_order.'&submitUpdateReceipt';
$action = '&id_supply_order='.$id_supply_order;
// renders list
$helper = new HelperList();
$this->setHelperDisplay($helper);
$helper->override_folder = 'supply_orders_receipt_history/';
//$helper->shopLinkType = '';
$helper->currentIndex = self::$currentIndex.$action;
// display these global order informations
@@ -940,14 +935,12 @@ class AdminSupplyOrdersControllerCore extends AdminController
{
// load supply order
$id_supply_order = (int)Tools::getValue('id_supply_order', null);
$products_already_in_order = array();
if ($id_supply_order != null)
{
$supply_order = new SupplyOrder($id_supply_order);
$products_already_in_order = $supply_order->getEntries();
$currency = new Currency($supply_order->id_ref_currency);
if (Validate::isLoadedObject($supply_order))
{
// tests if the supplier or currency have changed in the supply order
@@ -962,6 +955,9 @@ class AdminSupplyOrdersControllerCore extends AdminController
}
else
{
$products_already_in_order = $supply_order->getEntries();
$currency = new Currency($supply_order->id_ref_currency);
// gets all product ids to manage
$product_ids_str = Tools::getValue('product_ids', null);
$product_ids = explode('|', $product_ids_str);
@@ -1147,8 +1143,11 @@ class AdminSupplyOrdersControllerCore extends AdminController
// if state is valid, change it in the order
if ($id_state == $state['id_supply_order_state'])
{
// special case of validate state - check if there are products in the order
if ($supply_order->isEditable() && !$supply_order->hasEntries())
$new_state = new SupplyOrderState($id_state);
// special case of validate state - check if there are products in the order and the required state is not an enclosed state
if ($supply_order->isEditable() && !$supply_order->hasEntries() && !$new_state->enclosed)
$this->_errors[] = Tools::displayError(
$this->l('It is not possible to change the state of this order because of no product are present in it')
);
@@ -1171,7 +1170,7 @@ class AdminSupplyOrdersControllerCore extends AdminController
}
}
if (Tools::isSubmit('submitUpdateReceipt') && Tools::isSubmit('id_supply_order'))
if (Tools::isSubmit('submitBulkUpdatesupply_order_detail') && Tools::isSubmit('id_supply_order'))
$this->postProcessUpdateReceipt();
parent::postProcess();
@@ -1184,6 +1183,7 @@ class AdminSupplyOrdersControllerCore extends AdminController
*/
protected function postProcessUpdateReceipt()
{
trace('test');
// gets all box selected
$rows = Tools::getValue('supply_order_detailBox');
if (!$rows)
@@ -1363,7 +1363,7 @@ class AdminSupplyOrdersControllerCore extends AdminController
unset($this->_select, $this->_join, $this->_where, $this->_orderBy, $this->_orderWay, $this->_group, $this->_filterHaving, $this->_filter);
$this->_select = '
a.`date_add` as history_date,
CONCAT(e.`lastname`, \' \', e.`firstname`) as history_employee,
CONCAT(a.`employee_lastname`, \' \', a.`employee_firstname`) as history_employee,
sosl.`name` as history_state_name,
sos.`color` as color';
@@ -1373,8 +1373,7 @@ class AdminSupplyOrdersControllerCore extends AdminController
(
a.`id_state` = sosl.`id_supply_order_state`
AND sosl.`id_lang` = '.(int)$lang_id.'
)
LEFT JOIN `'._DB_PREFIX_.'employee` e ON (e.`id_employee` = a.`id_employee`)';
)';
$this->_where = 'AND a.`id_supply_order` = '.(int)$id_supply_order;
$this->_orderBy = 'a.`date_add`';
@@ -1430,8 +1429,7 @@ class AdminSupplyOrdersControllerCore extends AdminController
// loads history of the given order
unset($this->_select, $this->_join, $this->_where, $this->_orderBy, $this->_orderWay, $this->_group, $this->_filterHaving, $this->_filter);
$this->_select = 'CONCAT(e.`lastname`, \' \', e.`firstname`) as employee';
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'employee` e ON (e.`id_employee` = a.`id_employee`)';
$this->_select = 'CONCAT(a.`employee_lastname`, \' \', a.`employee_firstname`) as employee';
$this->_where = 'AND a.`id_supply_order_detail` = '.(int)$id_supply_order_detail;
// gets list and forces no limit clause in the request
@@ -1469,45 +1467,30 @@ class AdminSupplyOrdersControllerCore extends AdminController
$this->lang = false;
$this->list_simple_header = true;
$this->list_no_link = true;
$lang_id = (int)$this->context->language->id;
// gets the id supplier to view
$id_supply_order = (int)Tools::getValue('id_supply_order');
// just in case..
unset($this->_select, $this->_join, $this->_where, $this->_orderBy, $this->_orderWay, $this->_group, $this->_filterHaving, $this->_filter);
// gets all information on the products ordered
$this->_select = '
IFNULL(CONCAT(pl.name, \' : \', GROUP_CONCAT(agl.name, \' - \', al.name SEPARATOR \', \')), pl.name) as p_name,
p.reference as p_reference,
p.ean13 as p_ean13';
$this->_join = '
INNER JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = a.id_product AND pl.id_lang = '.$lang_id.')
LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = a.id_product)
LEFT JOIN '._DB_PREFIX_.'product_attribute_combination pac ON (pac.id_product_attribute = a.id_product_attribute)
LEFT JOIN '._DB_PREFIX_.'attribute atr ON (atr.id_attribute = pac.id_attribute)
LEFT JOIN '._DB_PREFIX_.'attribute_lang al ON (al.id_attribute = atr.id_attribute AND al.id_lang = '.$lang_id.')
LEFT JOIN '._DB_PREFIX_.'attribute_group_lang agl ON (agl.id_attribute_group = atr.id_attribute_group AND agl.id_lang = '.$lang_id.')';
$this->_where = 'AND a.`id_supply_order` = '.(int)$id_supply_order;
$this->_group = 'GROUP BY a.id_product';
// gets global order information
$supply_order = new SupplyOrder((int)$id_supply_order);
if (Validate::isLoadedObject($supply_order))
{
$lang_id = (int)$supply_order->id_lang;
// just in case..
unset($this->_select, $this->_join, $this->_where, $this->_orderBy, $this->_orderWay, $this->_group, $this->_filterHaving, $this->_filter);
// gets all information on the products ordered
$this->_where = 'AND a.`id_supply_order` = '.(int)$id_supply_order;
$this->_group = 'GROUP BY a.id_product';
// gets the list ordered by price desc, without limit
$this->getList($lang_id, 'price_te', 'DESC', 0, false, false);
// gets the currency used in this order
$currency = new Currency($supply_order->id_currency);
// gets the employee in charge of the order
$employee = new Employee($supply_order->id_employee);
// gets the warehouse where products will be received
$warehouse = new Warehouse($supply_order->id_warehouse);
@@ -1516,7 +1499,7 @@ class AdminSupplyOrdersControllerCore extends AdminController
// re-defines fieldsDisplay
$this->fieldsDisplay = array(
'p_reference' => array(
'reference' => array(
'title' => $this->l('Reference'),
'align' => 'center',
'width' => 120,
@@ -1524,7 +1507,7 @@ class AdminSupplyOrdersControllerCore extends AdminController
'filter' => false,
'search' => false,
),
'p_ean13' => array(
'ean13' => array(
'title' => $this->l('EAN13'),
'align' => 'center',
'width' => 100,
@@ -1532,7 +1515,15 @@ class AdminSupplyOrdersControllerCore extends AdminController
'filter' => false,
'search' => false,
),
'p_name' => array(
'upc' => array(
'title' => $this->l('UPC'),
'align' => 'center',
'width' => 100,
'orderby' => false,
'filter' => false,
'search' => false,
),
'name' => array(
'title' => $this->l('Name'),
'orderby' => false,
'filter' => false,
@@ -1643,7 +1634,6 @@ class AdminSupplyOrdersControllerCore extends AdminController
// display these global order informations
$this->tpl_view_vars = array(
'supply_order_detail_content' => $content,
'supply_order_employee' => (Validate::isLoadedObject($employee) ? $employee->firstname.' '.$employee->lastname : ''),
'supply_order_warehouse' => (Validate::isLoadedObject($warehouse) ? $warehouse->name : ''),
'supply_order_reference' => $supply_order->reference,
'supply_order_creation_date' => Tools::displayDate($supply_order->date_add, $lang_id, true),