From 4756b6bc34eb3a87f803ee6787fdb806e0a4aeb8 Mon Sep 17 00:00:00 2001 From: bMancone Date: Fri, 4 Nov 2011 16:32:32 +0000 Subject: [PATCH] // AdminSupplierOrdersController : added action to update the products that are being received --- .../template/helper/list/list_content.tpl | 2 + .../supplier_orders/update_receipt.tpl | 35 ++++ .../admin/AdminSupplierOrdersController.php | 153 +++++++++++++++++- 3 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 admin-dev/themes/template/supplier_orders/update_receipt.tpl diff --git a/admin-dev/themes/template/helper/list/list_content.tpl b/admin-dev/themes/template/helper/list/list_content.tpl index 972823658..99dc41a71 100644 --- a/admin-dev/themes/template/helper/list/list_content.tpl +++ b/admin-dev/themes/template/helper/list/list_content.tpl @@ -82,6 +82,8 @@ {$tr.$key} {elseif isset($params.type) && $params.type == 'datetime'} {$tr.$key} + {elseif isset($params.type) && $params.type == 'editable'} + {elseif isset($params.callback)} {$tr.$key} {elseif isset($tr.$key) && $key == 'color'} diff --git a/admin-dev/themes/template/supplier_orders/update_receipt.tpl b/admin-dev/themes/template/supplier_orders/update_receipt.tpl new file mode 100644 index 000000000..c529ff0ce --- /dev/null +++ b/admin-dev/themes/template/supplier_orders/update_receipt.tpl @@ -0,0 +1,35 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision$ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} +
+

{l s='Supplier Order'} #{$supplier_order_reference}

+
+ +
+
+ {l s='Order'} #{$supplier_order_reference} + {$content} +
+
diff --git a/controllers/admin/AdminSupplierOrdersController.php b/controllers/admin/AdminSupplierOrdersController.php index fe8df5d4a..d1709ee2d 100644 --- a/controllers/admin/AdminSupplierOrdersController.php +++ b/controllers/admin/AdminSupplierOrdersController.php @@ -375,6 +375,8 @@ class AdminSupplierOrdersControllerCore extends AdminController $this->addRowActionSkipList('edit', $this->_list[$i]['id_supplier_order']); if ($this->_list[$i]['enclosed'] == 1) $this->addRowActionSkipList('changestate', $this->_list[$i]['id_supplier_order']); + if (1 != $this->_list[$i]['pending_receipt']) + $this->addRowActionSkipList('updatereceipt', $this->_list[$i]['id_supplier_order']); } } } @@ -425,6 +427,7 @@ class AdminSupplierOrdersControllerCore extends AdminController $this->addRowAction('changestate'); $this->addRowAction('details'); $this->addRowAction('view'); + $this->addRowAction('updatereceipt'); // test if a filter is applied for this list if (Tools::isSubmit('submitFilter'.$this->table) || $this->context->cookie->{'submitFilter'.$this->table} !== false) @@ -505,6 +508,7 @@ class AdminSupplierOrdersControllerCore extends AdminController st.editable, st.enclosed, st.receipt_state, + st.pending_receipt, st.color AS color, a.id_supplier_order as id_pdf'; @@ -652,6 +656,131 @@ class AdminSupplierOrdersControllerCore extends AdminController parent::initContent(); } + /** + * Inits the content of 'update_receipt' action + * Called in initContent() + * @see AdminSuppliersOrders::initContent() + */ + public function initUpdateReceiptContent() + { + // change the display type in order to add specific actions to + $this->display = 'update_receipt'; + // overrides parent::initContent(); + $this->initToolbar(); + + $id_supplier_order = (int)Tools::getValue('id_supplier_order', null); + + // if there is no order to fetch + if (null == $id_supplier_order) + return parent::initContent(); + + $supplier_order = new SupplierOrder($id_supplier_order); + // if it's not a valid order + if (!Validate::isLoadedObject($supplier_order)) + return parent::initContent(); + + // re-defines fieldsDisplay + $this->fieldsDisplay = array( + 'p_reference' => array( + 'title' => $this->l('Reference'), + 'align' => 'center', + 'width' => 100, + 'orderby' => false, + 'filter' => false, + 'search' => false, + ), + 'p_ean13' => array( + 'title' => $this->l('EAN13'), + 'align' => 'center', + 'width' => 75, + 'orderby' => false, + 'filter' => false, + 'search' => false, + ), + 'p_name' => array( + 'title' => $this->l('Name'), + 'width' => 350, + 'orderby' => false, + 'filter' => false, + 'search' => false, + ), + 'quantity_received' => array( + 'title' => $this->l('Quantity received'), + 'align' => 'center', + 'width' => 30, + 'type' => 'editable', + 'orderby' => false, + 'filter' => false, + 'search' => false, + ), + 'quantity_expected' => array( + 'title' => $this->l('Quantity expected'), + 'align' => 'center', + 'width' => 75, + 'orderby' => false, + 'filter' => false, + 'search' => false, + ) + ); + + // defines which table we are using + unset($this->_select, $this->_join, $this->_where, $this->_orderBy, $this->_orderWay, $this->_group, $this->_filterHaving, $this->_filter); + $this->table = 'supplier_order_detail'; + $this->identifier = 'id_supplier_order_detail'; + $this->className = 'SupplierOrderDetail'; + // theme pruposes + $this->colorOnBackground = false; + // gets lang info + $this->lang = false; + $lang_id = (int)$this->context->language->id; + + // gets values corresponding to fieldsDisplay + $this->_select = ' + a.id_supplier_order_detail as id, + SUM(sorh.quantity) as quantity_received, + a.quantity as quantity_expected, + 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 = ' + LEFT JOIN '._DB_PREFIX_.'supplier_order_receipt_history sorh ON (sorh.id_supplier_order_detail = a.id_supplier_order_detail) + 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_supplier_order` = '.(int)$id_supplier_order; + $this->_group = 'GROUP BY a.id_supplier_order_detail'; + + // gets the list ordered by price desc, without limit + $this->getList($lang_id, 'quantity', 'DESC', 0, false, false); + + // defines action for POST + $action = '&id_supplier_order='.$id_supplier_order.'&submitUpdateReceipt'; + // renders list + $helper = new HelperList(); + $helper->simple_header = true; + $helper->table = $this->table; + $helper->no_link = true; + $helper->shopLinkType = ''; + $helper->currentIndex = self::$currentIndex.$action; + $helper->token = $this->token; + $helper->identifier = $this->identifier; + + // display these global order informations + $this->displayInformation($this->l('This interface allows you to update the quantities of this on-going order.').'
'); + + // generates content + $content = $helper->generateList($this->_list, $this->fieldsDisplay); + + // assigns var + $this->context->smarty->assign(array( + 'content' => $content, + 'supplier_order_reference' => $supplier_order->reference + )); + } + /** * AdminController::initContent() override * @see AdminController::initContent() @@ -661,6 +790,8 @@ class AdminSupplierOrdersControllerCore extends AdminController // Manage the add stock form if (Tools::isSubmit('changestate')) $this->initChangeStateContent(); + else if (Tools::isSubmit('update_receipt') && Tools::isSubmit('id_supplier_order')) + $this->initUpdateReceiptContent(); else if (Tools::isSubmit('viewsupplier_order') && Tools::isSubmit('id_supplier_order')) { $this->display = 'view'; @@ -820,6 +951,27 @@ class AdminSupplierOrdersControllerCore extends AdminController * @param int $id the identifier to add to the link * @return string */ + public function displayUpdateReceiptLink($token = null, $id) + { + if (!array_key_exists('Receipt', self::$cache_lang)) + self::$cache_lang['Receipt'] = $this->l('Update on-going receptions'); + + $this->context->smarty->assign(array( + 'href' => self::$currentIndex. + '&'.$this->identifier.'='.$id. + '&update_receipt&token='.($token != null ? $token : $this->token), + 'action' => self::$cache_lang['Receipt'], + )); + + return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/helper/list/list_action_supplier_order_receipt.tpl'); + } + + /** + * Display receipt action link + * @param string $token the token to add to the link + * @param int $id the identifier to add to the link + * @return string + */ public function displayChangestateLink($token = null, $id) { if (!array_key_exists('State', self::$cache_lang)) @@ -1143,7 +1295,6 @@ class AdminSupplierOrdersControllerCore extends AdminController if (!Validate::isLoadedObject($supplier_order_state)) return; - if ($supplier_order_state->editable == false && $supplier_order_state->delivery_note == true) $content .= 'invoice'; else