// AdminSupplyOrdersController: it now possible to create supply order templates, and use them to create actual supply orders
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10745 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
{*
|
||||
* 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$
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
<a href="{$href}">
|
||||
<img src="../img/admin/copy_files.gif" alt="{$action}" title="{$action}" /></a>
|
||||
@@ -28,7 +28,7 @@
|
||||
{block name="override_tpl"}
|
||||
<div style="margin-top: 20px;">
|
||||
<fieldset>
|
||||
<legend>{l s='General informations'}</legend>
|
||||
<legend>{if isset($is_template)} {l s='Template'} {/if}{l s='General informations'}</legend>
|
||||
<table style="width: 400px;" classe="table">
|
||||
<tr>
|
||||
<td>{l s='Creation date:'}</td>
|
||||
@@ -64,14 +64,14 @@
|
||||
|
||||
<div style="margin-top: 20px;">
|
||||
<fieldset>
|
||||
<legend>{l s='Products'}</legend>
|
||||
<legend>{if isset($is_template)} {l s='Template'} {/if}{l s='Products'}</legend>
|
||||
{$supply_order_detail_content}
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 20px;">
|
||||
<fieldset>
|
||||
<legend>{l s='Summary'}</legend>
|
||||
<legend>{if isset($is_template)} {l s='Template'} {/if}{l s='Summary'}</legend>
|
||||
<table style="width: 400px;" classe="table">
|
||||
<tr>
|
||||
<th>{l s='Designation'}</th>
|
||||
|
||||
@@ -199,7 +199,7 @@ class SupplyOrderCore extends ObjectModel
|
||||
|
||||
$res = parent::update($null_values);
|
||||
|
||||
if ($res)
|
||||
if ($res && !$this->is_template)
|
||||
$this->addHistory();
|
||||
|
||||
return $res;
|
||||
@@ -214,7 +214,7 @@ class SupplyOrderCore extends ObjectModel
|
||||
|
||||
$res = parent::add($autodate, $null_values);
|
||||
|
||||
if ($res)
|
||||
if ($res && !$this->is_template)
|
||||
$this->addHistory();
|
||||
|
||||
return $res;
|
||||
|
||||
@@ -159,6 +159,9 @@ class AdminSupplyOrdersControllerCore extends AdminController
|
||||
if (Tools::isSubmit('updatesupply_order') || Tools::isSubmit('submitUpdatesupply_order'))
|
||||
$this->toolbar_title = $this->l('Stock : Manage supply order');
|
||||
|
||||
if (Tools::isSubmit('mod') && Tools::getValue('mod') === 'template' || $this->object->is_template)
|
||||
$this->toolbar_title .= ' '.$this->l('template');
|
||||
|
||||
$this->addJqueryUI('ui.datepicker');
|
||||
|
||||
//get warehouses list
|
||||
@@ -268,6 +271,16 @@ class AdminSupplyOrdersControllerCore extends AdminController
|
||||
)
|
||||
);
|
||||
|
||||
if (Tools::isSubmit('mod') && Tools::getValue('mod') === 'template' ||
|
||||
$this->object->is_template)
|
||||
{
|
||||
|
||||
$this->fields_form['input'][] = array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'is_template'
|
||||
);
|
||||
}
|
||||
|
||||
//specific discount display
|
||||
$this->object->discount_rate = Tools::ps_round($this->object->discount_rate, 4);
|
||||
|
||||
@@ -336,7 +349,36 @@ class AdminSupplyOrdersControllerCore extends AdminController
|
||||
LEFT JOIN `'._DB_PREFIX_.'supplier` s ON a.id_supplier = s.id_supplier
|
||||
LEFT JOIN `'._DB_PREFIX_.'warehouse` w ON (w.id_warehouse = a.id_warehouse)';
|
||||
|
||||
return parent::initList();
|
||||
$this->_where = ' AND a.is_template = 0';
|
||||
$first_list = parent::initList();
|
||||
|
||||
// second list : templates
|
||||
$second_list = null;
|
||||
|
||||
// unsets actions
|
||||
$this->actions = array();
|
||||
// adds actions
|
||||
$this->addRowAction('delete');
|
||||
$this->addRowAction('view');
|
||||
$this->addRowAction('edit');
|
||||
$this->addRowAction('createsupplyorder');
|
||||
// unsets some fields
|
||||
unset($this->fieldsDisplay['state'], $this->fieldsDisplay['date_upd'], $this->fieldsDisplay['id_pdf'], $this->fieldsDisplay['date_delivery_expected']);
|
||||
// adds filter, to gets only templates
|
||||
unset($this->_where);
|
||||
$this->_where = ' AND a.is_template = 1';
|
||||
|
||||
// re-defines toolbar & buttons
|
||||
$this->toolbar_title = $this->l('Stock : Supply orders templates');
|
||||
$this->initToolbar();
|
||||
$this->toolbar_btn['new'] = array(
|
||||
'href' => self::$currentIndex.'&add'.$this->table.'&mod=template&token='.$this->token,
|
||||
'desc' => $this->l('Add new template')
|
||||
);
|
||||
// inits list
|
||||
$second_list = parent::initList();
|
||||
|
||||
return $first_list.$second_list;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -941,9 +983,14 @@ class AdminSupplyOrdersControllerCore extends AdminController
|
||||
}
|
||||
}
|
||||
|
||||
// updates receipt
|
||||
if (Tools::isSubmit('submitBulkUpdatesupply_order_detail') && Tools::isSubmit('id_supply_order'))
|
||||
$this->postProcessUpdateReceipt();
|
||||
|
||||
// use template to create a supply order
|
||||
if (Tools::isSubmit('create_supply_order') && Tools::isSubmit('id_supply_order'))
|
||||
$this->postProcessCopyFromTemplate();
|
||||
|
||||
parent::postProcess();
|
||||
|
||||
// if the threshold is defined and we are saving the order
|
||||
@@ -1027,9 +1074,9 @@ class AdminSupplyOrdersControllerCore extends AdminController
|
||||
|
||||
// then, converts the newly calculated price from the default currency to the needed currency
|
||||
$price = Tools::ps_round(Tools::convertPrice($price_converted_to_default_currency,
|
||||
$warehouse->id_currency,
|
||||
true),
|
||||
6);
|
||||
$warehouse->id_currency,
|
||||
true),
|
||||
6);
|
||||
}
|
||||
|
||||
$manager = StockManagerFactory::getManager();
|
||||
@@ -1104,6 +1151,27 @@ class AdminSupplyOrdersControllerCore extends AdminController
|
||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/helper/list/list_action_supply_order_change_state.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display state 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 displayCreateSupplyOrderLink($token = null, $id)
|
||||
{
|
||||
if (!array_key_exists('CreateSupplyOrder', self::$cache_lang))
|
||||
self::$cache_lang['CreateSupplyOrder'] = $this->l('Use this template to create a supply order');
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'href' => self::$currentIndex.
|
||||
'&'.$this->identifier.'='.$id.
|
||||
'&create_supply_order&token='.($token != null ? $token : $this->token),
|
||||
'action' => self::$cache_lang['CreateSupplyOrder'],
|
||||
));
|
||||
|
||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/helper/list/list_action_supply_order_create_from_template.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* method call when ajax request is made with the details row action
|
||||
* @see AdminController::postProcess()
|
||||
@@ -1300,8 +1368,6 @@ class AdminSupplyOrdersControllerCore extends AdminController
|
||||
*/
|
||||
public function initView()
|
||||
{
|
||||
$this->displayInformation($this->l('This interface allows you to display detailed informations on your order.').'<br />');
|
||||
|
||||
$this->show_toolbar = true;
|
||||
$this->toolbar_fix = false;
|
||||
$this->table = 'supply_order_detail';
|
||||
@@ -1320,6 +1386,11 @@ class AdminSupplyOrdersControllerCore extends AdminController
|
||||
|
||||
if (Validate::isLoadedObject($supply_order))
|
||||
{
|
||||
if (!$supply_order->is_template)
|
||||
$this->displayInformation($this->l('This interface allows you to display detailed informations on your order.').'<br />');
|
||||
else
|
||||
$this->displayInformation($this->l('This interface allows you to display detailed informations on your template of order.').'<br />');
|
||||
|
||||
$lang_id = (int)$supply_order->id_lang;
|
||||
|
||||
// just in case..
|
||||
@@ -1338,8 +1409,10 @@ class AdminSupplyOrdersControllerCore extends AdminController
|
||||
$warehouse = new Warehouse($supply_order->id_warehouse);
|
||||
|
||||
// sets toolbar title with order reference
|
||||
$this->toolbar_title = sprintf($this->l('Details on supply order #%s'), $supply_order->reference);
|
||||
|
||||
if (!$supply_order->is_template)
|
||||
$this->toolbar_title = sprintf($this->l('Details on supply order #%s'), $supply_order->reference);
|
||||
else
|
||||
$this->toolbar_title = sprintf($this->l('Details on supply order template #%s'), $supply_order->reference);
|
||||
// re-defines fieldsDisplay
|
||||
$this->fieldsDisplay = array(
|
||||
'supplier_reference' => array(
|
||||
@@ -1479,6 +1552,7 @@ class AdminSupplyOrdersControllerCore extends AdminController
|
||||
// renders list
|
||||
$helper = new HelperList();
|
||||
$this->setHelperDisplay($helper);
|
||||
$helper->actions = array();
|
||||
$helper->show_toolbar = false;
|
||||
|
||||
$content = $helper->generateList($this->_list, $this->fieldsDisplay);
|
||||
@@ -1499,6 +1573,7 @@ class AdminSupplyOrdersControllerCore extends AdminController
|
||||
'supply_order_total_tax' => Tools::displayPrice($supply_order->total_tax, $currency),
|
||||
'supply_order_total_ti' => Tools::displayPrice($supply_order->total_ti, $currency),
|
||||
'supply_order_currency' => $currency,
|
||||
'is_template' => $supply_order->is_template,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1568,7 +1643,6 @@ class AdminSupplyOrdersControllerCore extends AdminController
|
||||
'href' => '#',
|
||||
'desc' => $this->l('Save and stay')
|
||||
);
|
||||
|
||||
default:
|
||||
parent::initToolbar();
|
||||
}
|
||||
@@ -1666,4 +1740,50 @@ class AdminSupplyOrdersControllerCore extends AdminController
|
||||
$supply_order_detail->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides AdminController::beforeAdd()
|
||||
* @see AdminController::beforeAdd()
|
||||
* @param ObjectModel $object
|
||||
*/
|
||||
public function beforeAdd($object)
|
||||
{
|
||||
if (Tools::isSubmit('is_template'));
|
||||
$object->is_template = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for AdminSupplyOrdersController::postProcess()
|
||||
* @see AdminSupplyOrdersController::postProcess()
|
||||
*/
|
||||
protected function postProcessCopyFromTemplate()
|
||||
{
|
||||
// gets SupplyOrder and checks if it is valid
|
||||
$id_supply_order = (int)Tools::getValue('id_supply_order');
|
||||
$supply_order = new SupplyOrder($id_supply_order);
|
||||
if (!Validate::isLoadedObject($supply_order))
|
||||
$this->_errors[] = Tools::displayError($this->l('Could not copy this template.'));
|
||||
|
||||
// gets SupplyOrderDetail
|
||||
$entries = $supply_order->getEntriesCollection($supply_order->id_lang);
|
||||
|
||||
// updates SupplyOrder so that it is not a template anymore
|
||||
$supply_order->is_template = 0;
|
||||
$supply_order->id = (int)0;
|
||||
$supply_order->save();
|
||||
|
||||
// copies SupplyOrderDetail
|
||||
foreach ($entries as $entry)
|
||||
{
|
||||
$entry->id_supply_order = $supply_order->id;
|
||||
$entry->id = (int)0;
|
||||
$entry->save();
|
||||
}
|
||||
|
||||
// redirect when done
|
||||
$token = Tools::getValue('token') ? Tools::getValue('token') : $this->token;
|
||||
$redirect = self::$currentIndex.'&token='.$token;
|
||||
$this->redirect_after = $redirect.'&conf=19';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user