// stock: add warehouse tab and update stock mvt tab

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9332 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
dSevere
2011-10-13 16:18:09 +00:00
parent e16af90d6a
commit bc565999d1
3 changed files with 403 additions and 152 deletions
+1 -1
View File
@@ -3680,7 +3680,7 @@ class AdminProducts extends AdminTab
$productDesignation = array(); $productDesignation = array();
foreach ($attributes as $attribute) foreach ($attributes as $attribute)
{ {
$physicalQuantity[$attribute['id_product_attribute']] = (int)rand(0, 100);//StockManagerFactory::getManager()->getProductPhysicalQuantities((int)$obj->id, $attribute['id_product_attribute']); $physicalQuantity[$attribute['id_product_attribute']] = (int)StockManagerFactory::getManager()->getProductPhysicalQuantities((int)$obj->id, $attribute['id_product_attribute']);
$totalQuantity += $physicalQuantity[$attribute['id_product_attribute']]; $totalQuantity += $physicalQuantity[$attribute['id_product_attribute']];
// @TODO // @TODO
+30 -24
View File
@@ -34,23 +34,24 @@ class AdminStockMvt extends AdminTab
$this->className = 'StockMvt'; $this->className = 'StockMvt';
$this->edit = false; $this->edit = false;
$this->delete = false; $this->delete = false;
$this->view = true; $this->view = false;
$this->fieldsDisplay = array( $this->fieldsDisplay = array(
'id_stock_mvt' => array('title' => $this->l('ID'), 'width' => 40), 'id_stock_mvt' => array('title' => $this->l('ID'), 'width' => 40),
'product_name' => array('title' => $this->l('Product Name'), 'width' => 250, 'havingFilter' => true), 'product_name' => array('title' => $this->l('Product Name'), 'width' => 200, 'havingFilter' => true),
'quantity' => array('title' => $this->l('Quantity'), 'width' => 40), 'physical_quantity' => array('title' => $this->l('Quantity'), 'width' => 40),
'reason' => array('title' => $this->l('Reason'), 'width' => 250), 'reason' => array('title' => $this->l('Reason'), 'width' => 200),
'id_order' => array('title' => $this->l('ID Order'), 'width' => 40), 'id_order' => array('title' => $this->l('ID Order'), 'width' => 40),
'employee' => array('title' => $this->l('Employee'), 'width' => 100, 'havingFilter' => true), 'employee' => array('title' => $this->l('Employee'), 'width' => 100, 'havingFilter' => true),
'warehouse' => array('title' => $this->l('Warehouse'), 'width' => 100, 'havingFilter' => true),
); );
$this->_select = 'CONCAT(pl.name, \' \', GROUP_CONCAT(IFNULL(al.name, \'\'), \'\')) product_name, CONCAT(e.lastname, \' \', e.firstname) AS employee, mrl.name AS reason, CONCAT(w.reference, " - ", w.name) AS warehouse';
$this->_select = 'CONCAT(pl.name, \' \', GROUP_CONCAT(IFNULL(al.name, \'\'), \'\')) product_name, CONCAT(e.lastname, \' \', e.firstname) employee, mrl.name reason'; $this->_join = 'INNER JOIN '._DB_PREFIX_.'stock stock ON a.id_stock = stock.id_stock
$this->_join = 'INNER JOIN '._DB_PREFIX_.'stock stock ON a.id_stock = stock.id_stock '.$this->context->shop->sqlRestriction(Shop::SHARE_STOCK, 'stock').'
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (stock.id_product = pl.id_product AND pl.id_lang = '.(int)$this->context->language->id.$this->context->shop->sqlLang('pl').') LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (stock.id_product = pl.id_product AND pl.id_lang = '.(int)$this->context->language->id.$this->context->shop->sqlLang('pl').')
LEFT JOIN `'._DB_PREFIX_.'stock_mvt_reason_lang` mrl ON (a.id_stock_mvt_reason = mrl.id_stock_mvt_reason AND mrl.id_lang = '.(int)$this->context->language->id.') LEFT JOIN `'._DB_PREFIX_.'stock_mvt_reason_lang` mrl ON (a.id_stock_mvt_reason = mrl.id_stock_mvt_reason AND mrl.id_lang = '.(int)$this->context->language->id.')
LEFT JOIN `'._DB_PREFIX_.'employee` e ON (e.id_employee = a.id_employee) LEFT JOIN `'._DB_PREFIX_.'employee` e ON (e.id_employee = a.id_employee)
LEFT JOIN `'._DB_PREFIX_.'warehouse` w ON (w.id_warehouse = stock.id_warehouse)
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON (pac.id_product_attribute = stock.id_product_attribute) LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON (pac.id_product_attribute = stock.id_product_attribute)
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (al.id_attribute = pac.id_attribute AND al.id_lang = '.(int)$this->context->language->id.')'; LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (al.id_attribute = pac.id_attribute AND al.id_lang = '.(int)$this->context->language->id.')';
$this->_group = 'GROUP BY a.id_stock_mvt'; $this->_group = 'GROUP BY a.id_stock_mvt';
@@ -59,8 +60,8 @@ class AdminStockMvt extends AdminTab
public function postProcess() public function postProcess()
{ {
if (Tools::isSubmit('rebuildStock')) /*if (Tools::isSubmit('rebuildStock'))
StockMvt::addMissingMvt($this->context->employee->id, false); StockMvt::addMissingMvt($this->context->employee->id, false);*/
return parent::postProcess(); return parent::postProcess();
} }
@@ -90,14 +91,14 @@ class AdminStockMvt extends AdminTab
<option value="-1">'.$this->l('Decrease stock').'</option> <option value="-1">'.$this->l('Decrease stock').'</option>
</select> </select>
</div> </div>
<div class="clear space">&nbsp;</div>'; <div class="clear space">&nbsp;</div>
echo '<div class="margin-form"> <div class="margin-form">
<input type="submit" value="'.$this->l(' Save ').'" name="submitAdd'.$this->table.'" class="button" /> <input type="submit" value="'.$this->l(' Save ').'" name="submitAdd'.$this->table.'" class="button" />
</div> </div>
</fieldset> </fieldset>
</form>'; </form>';
} }
/*
public function viewstock_mvt() public function viewstock_mvt()
{ {
$stockMvt = new StockMvt((int)Tools::getValue('id_stock_mvt')); $stockMvt = new StockMvt((int)Tools::getValue('id_stock_mvt'));
@@ -131,20 +132,19 @@ class AdminStockMvt extends AdminTab
} }
echo '</table>'; echo '</table>';
} }
*/
public function display() public function display()
{ {
$old_post = false; $old_post = false;
if (!isset($_GET['addstock_mvt_reason']) OR (Tools::isSubmit('submitAddstock_mvt_reason') AND Tools::getValue('id_stock_mvt_reason'))) if (!isset($_GET['addstock_mvt_reason']) || (Tools::isSubmit('submitAddstock_mvt_reason') && Tools::getValue('id_stock_mvt_reason')))
{ {
if (isset($_POST)) if (isset($_POST))
{
$old_post = $_POST; $old_post = $_POST;
}
echo '<h2>'.$this->l('Stock movement history').'</h2>'; echo '<h2>'.$this->l('Stock movement history').'</h2>';
parent::display(); parent::display();
if (!isset($_GET['view'.$this->table])) /*if (!isset($_GET['view'.$this->table]))
echo ' echo '
<fieldset> <fieldset>
<form method="post" action="'.self::$currentIndex.'&token='.$this->token.'&rebuildMvt=1"> <form method="post" action="'.self::$currentIndex.'&token='.$this->token.'&rebuildMvt=1">
@@ -153,7 +153,7 @@ class AdminStockMvt extends AdminTab
<input class="button" type="submit" name="rebuildStock" value="'.$this->l('Submit').'" /> <input class="button" type="submit" name="rebuildStock" value="'.$this->l('Submit').'" />
</div> </div>
</form> </form>
</fieldset><br />'; </fieldset><br />';*/
} }
if (isset($_GET['view'.$this->table])) if (isset($_GET['view'.$this->table]))
return; return;
@@ -176,17 +176,25 @@ class AdminStockMvt extends AdminTab
'sign' => array('title' => $this->l('Sign'), 'width' => 15, 'align' => 'center', 'type' => 'select', 'icon' => array(-1 => 'arrow_down.png', 1 => 'arrow_up.png'), 'orderby' => false), 'sign' => array('title' => $this->l('Sign'), 'width' => 15, 'align' => 'center', 'type' => 'select', 'icon' => array(-1 => 'arrow_down.png', 1 => 'arrow_up.png'), 'orderby' => false),
'name' => array('title' => $this->l('Name'), 'width' => 500)); 'name' => array('title' => $this->l('Name'), 'width' => 500));
$reasons = StockMvtReason::getStockMvtReasons($this->context->language->id); $reasons_inc = StockMvtReason::getStockMvtReasons($this->context->language->id, 1);
$reasons_dec = StockMvtReason::getStockMvtReasons($this->context->language->id, -1);
$this->optionsList = array( $this->optionsList = array(
'general' => array( 'general' => array(
'title' => $this->l('Options'), 'title' => $this->l('Options'),
'fields' => array( 'fields' => array(
'PS_STOCK_MVT_REASON_DEFAULT' => array( 'PS_STOCK_MVT_INC_REASON_DEFAULT' => array(
'title' => $this->l('Default Stock Movement reason:'), 'title' => $this->l('Default Stock Movement reason for increment stock:'),
'cast' => 'intval', 'cast' => 'intval',
'type' => 'select', 'type' => 'select',
'list' => $reasons, 'list' => $reasons_inc,
'identifier' => 'id_stock_mvt_reason'
),
'PS_STOCK_MVT_DEC_REASON_DEFAULT' => array(
'title' => $this->l('Default Stock Movement reason for decrement stock:'),
'cast' => 'intval',
'type' => 'select',
'list' => $reasons_dec,
'identifier' => 'id_stock_mvt_reason' 'identifier' => 'id_stock_mvt_reason'
), ),
), ),
@@ -199,5 +207,3 @@ class AdminStockMvt extends AdminTab
return parent::display(); return parent::display();
} }
} }
+245
View File
@@ -0,0 +1,245 @@
<?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: 7307 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5.0
*/
class AdminWarehouses extends AdminTab
{
public function __construct()
{
$this->context = Context::getContext();
$this->table = 'warehouse';
$this->className = 'Warehouse';
$this->edit = true;
$this->delete = false;
$this->view = false;
$this->fieldsDisplay = array(
'reference' => array('title' => $this->l('Reference'), 'width' => 40),
'name' => array('title' => $this->l('Name'), 'width' => 300, 'havingFilter' => true),
'management_type' => array('title' => $this->l('Managment type'), 'width' => 40),
'employee' => array('title' => $this->l('Manager'), 'width' => 150, 'havingFilter' => true),
'location' => array('title' => $this->l('Location'), 'width' => 150),
'contact' => array('title' => $this->l('Phone Number'), 'width' => 50),
);
$this->_select = 'reference, name, management_type,
CONCAT(e.lastname, \' \', e.firstname) AS employee,
ad.phone AS contact,
CONCAT(ad.city, \' \', c.iso_code) location';
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'employee` e ON (e.id_employee = a.id_employee)
LEFT JOIN `'._DB_PREFIX_.'address` ad ON (ad.id_address = a.id_address)
LEFT JOIN `'._DB_PREFIX_.'country` c ON (c.id_country = ad.id_country)';
// Get countries list for warehouse localisation
$countries = Country::getCountries($this->context->language->id);
foreach ($countries as $country)
$this->countries_array[$country['id_country']] = $country['name'];
// Get employee list for warehouse manager
$query = new DbQuery();
$query->select('id_employee, CONCAT(lastname," ",firstname) as name');
$query->from('employee');
$query->where('active = 1');
$employees = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
foreach ($employees as $employee)
$this->employees_array[$employee['id_employee']] = $employee['name'];
parent::__construct();
}
public function postProcess()
{
// update/create address if not exists
if (isset($_POST['submitAdd'.$this->table]))
{
if (isset($_POST['id_address']) && $_POST['id_address'] > 0)
//update address
$address = new Address((int)$_POST['id_address']);
else
//create address
$address = new Address();
$address->alias = $_POST['name'];
$address->lastname = $_POST['name'];
$address->firstname = $_POST['name'];
$address->address1 = $_POST['address1'];
$address->address2 = $_POST['address2'];
$address->postcode = $_POST['postcode'];
$address->phone = $_POST['phone'];
$address->id_country = $_POST['id_country'];
$address->city = $_POST['city'];
if (isset($_POST['id_address']) && $_POST['id_address'] > 0)
{
//update address
$address->update();
}
else {
$address->save();
$_POST['id_address'] = $address->id;
}
}
return parent::postProcess();
}
public function displayForm($is_main_tab = true)
{
parent::displayForm();
if (!($obj = $this->loadObject(true)))
return;
if ($obj->id_address > 0)
$address = new Address($obj->id_address);
echo '<form action="'.self::$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'&addwarehouse" method="post">
'.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
<input type="hidden" name="id_address" value="'.(isset($obj->id_address) ? $obj->id_address : 0).'" />
<fieldset><legend><img src="../img/admin/tab.gif" />'.$this->l('Warehouse').'</legend>
<label>'.$this->l('Reference:').'</label>
<div class="margin-form">
<input size="20" type="text" name="reference" value="'.htmlentities($this->getFieldValue($obj, 'reference'), ENT_COMPAT, 'UTF-8').'" /><sup> *</sup>
</div>
<label>'.$this->l('Name:').'</label>
<div class="margin-form">
<input size="50" type="text" name="name" value="'.htmlentities($this->getFieldValue($obj, 'name'), ENT_COMPAT, 'UTF-8').'" /><sup> *</sup>
</div>
<label>'.$this->l('Phone Number').'</label>
<div class="margin-form">
<input type="text" size="33" name="phone" value="'.htmlentities(isset($address) ? $address->phone : '', ENT_COMPAT, 'UTF-8').'" /> <sup>*</sup>
</div>
<label>'.$this->l('Address').'</label>
<div class="margin-form">
<input type="text" size="33" name="address1" value="'.htmlentities(isset($address) ? $address->address1 : '', ENT_COMPAT, 'UTF-8').'" /> <sup>*</sup>
</div>
<label>'.$this->l('Address').' (2)</label>
<div class="margin-form">
<input type="text" size="33" name="address2" value="'.htmlentities(isset($address) ? $address->address2 : '', ENT_COMPAT, 'UTF-8').'" />
</div>
<label>'.$this->l('Postcode/ Zip Code').'</label>
<div class="margin-form">
<input type="text" size="33" name="postcode" value="'.htmlentities(isset($address) ? $address->postcode : '', ENT_COMPAT, 'UTF-8').'" />
</div>
<label>'.$this->l('City').'</label>
<div class="margin-form">
<input type="text" size="33" name="city" value="'.htmlentities(isset($address) ? $address->city : '', ENT_COMPAT, 'UTF-8').'" style="text-transform: uppercase;" /> <sup>*</sup>
</div>
<label>'.$this->l('Country').'</label>
<div class="margin-form">
<select name="id_country" id="id_country" />';
$selected_country = $this->getFieldValue($obj, 'id_country');
foreach ($this->countries_array as $id_country => $name)
echo '<option value="'.$id_country.'"'.((!$selected_country && Configuration::get('PS_COUNTRY_DEFAULT') == $id_country) ? ' selected="selected"' : ($selectedCountry == $id_country ? ' selected="selected"' : '')).'>'.$name.'</option>';
echo '</select> <sup>*</sup>
</div>
<div id="contains_states" '.(!Country::containsStates((int)$selected_country) ? 'style="display:none;"' : '').'>
<label>'.$this->l('State').'</label>
<div class="margin-form">
<select name="id_state" id="id_state">
</select>
<sup>*</sup>
</div>
</div>';
$id_country_ajax = (int)$this->getFieldValue($obj, 'id_country');
echo '
<script type="text/javascript">
$(document).ready(function(){
ajaxStates ();
$(\'#id_country\').change(function() {
ajaxStates ();
});
function ajaxStates ()
{
$.ajax({
url: "ajax.php",
cache: false,
data: "ajaxStates=1&id_country="+$(\'#id_country\').val()+"&id_state="+$(\'#id_state\').val(),
success: function(html)
{
if (html == \'false\')
{
$("#contains_states").fadeOut();
$(\'#id_state option[value=0]\').attr("selected", "selected");
}
else
{
$("#id_state").html(html);
$("#contains_states").fadeIn();
$(\'#id_state option[value='.(isset($address) ? $address->id_state : 0).']\').attr("selected", "selected");
}
}
});
};
});
</script>
<label>'.$this->l('Manager').'</label>
<div class="margin-form">
<select name="id_employee" id="id_employee" />';
$selected_employee = $this->getFieldValue($obj, 'id_employee');
$selected_management_type = $this->getFieldValue($obj, 'management_type');
foreach ($this->employees_array as $id_employee => $name)
echo '<option value="'.$id_employee.'"'.(($selected_employee == $id_employee) ? ' selected="selected"' : '').'>'.$name.'</option>';
echo '</select> <sup>*</sup>
</div>
<label>'.$this->l('Management type').'</label>
<div class="margin-form">
<select name="management_type" id="management_type">
<option value="FIFO"'.(($selected_management_type == 'FIFO') ? ' selected="selected"' : '').'>'.$this->l('First In, First Out').'</option>
<option value="LIFO"'.(($selected_management_type == 'LIFO') ? ' selected="selected"' : '').'>'.$this->l('Last In, First Out').'</option>
<option value="WA"'.(($selected_management_type == 'WA') ? ' selected="selected"' : '').'>'.$this->l('Weight Average').'</option>
</select>
<sup>*</sup>
</div>
<div class="clear"></div><br />
<div class="margin-form">
<input type="submit" value="'.$this->l(' Save ').'" name="submitAdd'.$this->table.'" class="button" />
</div>
</fieldset>
</form>';
}
}