NEW prepare for additional warehouse statuses

Add additional warehouse statuses, so you can add extra filter
possibility. For example hide warehouses with damaged stock from
shipping. Feature is still hidden by conf ENTREPOT_EXTRA_STATUS
Still TODO: config all $formproduct->selectWarehouses
This commit is contained in:
fappels 2016-04-27 16:51:51 +02:00
parent 93fd994435
commit 65ea83fa06
4 changed files with 107 additions and 44 deletions

View File

@ -139,3 +139,7 @@ WarehouseMustBeSelectedAtFirstStepWhenProductBatchModuleOn=Source warehouse must
InventoryCodeShort=Inv./Mov. code
NoPendingReceptionOnSupplierOrder=No pending reception due to open supplier order
ThisSerialAlreadyExistWithDifferentDate=This lot/serial number (<strong>%s</strong>) already exists but with different eatby or sellby date (found <strong>%s</strong> but you enter <strong>%s</strong>).
OpenAll=Open for all actions
OpenInternal=Open for internal actions
OpenShipping=Open for shippings
OpenDispatch=Open for dispatch

View File

@ -1,5 +1,6 @@
<?php
/* Copyright (C) 2008-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2016 Francis Appels <francis.appels@yahoo.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -53,20 +54,20 @@ class FormProduct
*
* @param int $fk_product Add quantity of stock in label for product with id fk_product. Nothing if 0.
* @param string $batch Add quantity of batch stock in label for product with batch name batch, batch name precedes batch_id. Nothing if ''.
* @param int $fk_product_batch Add quantity of batch stock in label for product with batch id fk_product_batch. Nothing if 0.
* @param int $status additional filter on status other then 1
* @param boolean $sumStock sum total stock of a warehouse, default true
* @return int Nb of loaded lines, 0 if already loaded, <0 if KO
*/
function loadWarehouses($fk_product=0, $batch = '', $fk_product_batch=0, $sumStock = true)
function loadWarehouses($fk_product=0, $batch = '', $status=null, $sumStock = true)
{
global $conf, $langs;
if (empty($fk_product) && count($this->cache_warehouses)) return 0; // Cache already loaded and we do not want a list with information specific to a product
$sql = "SELECT e.rowid, e.label";
$sql = "SELECT e.rowid, e.label, e.description";
if (!empty($fk_product))
{
if (!empty($fk_product_batch) || !empty($batch))
if (!empty($batch))
{
$sql.= ", pb.qty as stock";
}
@ -87,13 +88,18 @@ class FormProduct
if (!empty($batch))
{
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_batch as pb on pb.fk_product_stock = ps.rowid AND pb.batch = '".$batch."'";
} else if (!empty($fk_product_batch))
{
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_batch as pb on pb.fk_product_stock = ps.rowid AND pb.rowid = '".$fk_product_batch."'";
}
}
}
$sql.= " WHERE e.entity IN (".getEntity('stock', 1).")";
$sql.= " AND e.statut = 1";
if (!empty($status))
{
$sql.= " AND e.statut IN (1, ".$status.")";
}
else
{
$sql.= " AND e.statut = 1";
}
if ($sumStock && empty($fk_product)) $sql.= " GROUP BY e.rowid, e.label, e.description";
$sql.= " ORDER BY e.label";
@ -127,7 +133,7 @@ class FormProduct
*
* @param int $selected Id of preselected warehouse ('' for no value, 'ifone'=select value if one value otherwise no value)
* @param string $htmlname Name of html select html
* @param string $filtertype For filter
* @param string $filtertype For filter, additional filter on status other then 1
* @param int $empty 1=Can be empty, 0 if not
* @param int $disabled 1=Select is disabled
* @param int $fk_product Add quantity of stock in label for product with id fk_product. Nothing if 0.
@ -142,11 +148,11 @@ class FormProduct
{
global $conf,$langs,$user;
dol_syslog(get_class($this)."::selectWarehouses $selected, $htmlname, $filtertype, $empty, $disabled, $fk_product",LOG_DEBUG);
dol_syslog(get_class($this)."::selectWarehouses $selected, $htmlname, $filtertype, $empty, $disabled, $fk_product, $empty_label, $showstock, $forcecombo, $morecss",LOG_DEBUG);
$out='';
$this->loadWarehouses($fk_product);
$this->loadWarehouses($fk_product, '', + $filtertype); // filter on numeric status
$nbofwarehouses=count($this->cache_warehouses);
if ($conf->use_javascript_ajax && ! $forcecombo)

View File

@ -3,6 +3,7 @@
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Simon Tosser <simon@kornog-computing.com>
* Copyright (C) 2005-2014 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2016 Francis Appels <francis.appels@yahoo.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -53,6 +54,7 @@ $result=restrictedArea($user,'stock');
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('warehousecard','globalcard'));
$object = new Entrepot($db);
/*
* Actions
@ -61,8 +63,6 @@ $hookmanager->initHooks(array('warehousecard','globalcard'));
// Ajout entrepot
if ($action == 'add' && $user->rights->stock->creer)
{
$object = new Entrepot($db);
$object->ref = GETPOST("ref");
$object->libelle = GETPOST("libelle");
$object->description = GETPOST("desc");
@ -107,7 +107,6 @@ if ($action == 'add' && $user->rights->stock->creer)
// Delete warehouse
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->stock->supprimer)
{
$object = new Entrepot($db);
$object->fetch($_REQUEST["id"]);
$result=$object->delete($user);
if ($result > 0)
@ -125,7 +124,6 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->stock->su
// Modification entrepot
if ($action == 'update' && $cancel <> $langs->trans("Cancel"))
{
$object = new Entrepot($db);
if ($object->fetch($id))
{
$object->libelle = GETPOST("libelle");
@ -215,11 +213,20 @@ if ($action == 'create')
print $form->select_country((!empty($object->country_id)?$object->country_id:$mysoc->country_code),'country_id');
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
print '</td></tr>';
// Status
print '<tr><td>'.$langs->trans("Status").'</td><td colspan="3">';
print '<select name="statut" class="flat">';
print '<option value="0">'.$langs->trans("WarehouseClosed").'</option>';
print '<option value="1" selected>'.$langs->trans("WarehouseOpened").'</option>';
foreach ($object->statuts as $key => $value)
{
if ($key == 1)
{
print '<option value="'.$key.'" selected>'.$langs->trans($value).'</option>';
}
else
{
print '<option value="'.$key.'">'.$langs->trans($value).'</option>';
}
}
print '</select>';
print '</td></tr>';
@ -558,8 +565,17 @@ else
print '<tr><td>'.$langs->trans("Status").'</td><td colspan="3">';
print '<select name="statut" class="flat">';
print '<option value="0" '.($object->statut == 0?'selected':'').'>'.$langs->trans("WarehouseClosed").'</option>';
print '<option value="1" '.($object->statut == 0?'':'selected').'>'.$langs->trans("WarehouseOpened").'</option>';
foreach ($object->statuts as $key => $value)
{
if ($key == $object->statut)
{
print '<option value="'.$key.'" selected>'.$langs->trans($value).'</option>';
}
else
{
print '<option value="'.$key.'">'.$langs->trans($value).'</option>';
}
}
print '</select>';
print '</td></tr>';

View File

@ -3,6 +3,7 @@
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2008 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2016 Francis Appels <francis.appels@yahoo.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -34,18 +35,45 @@ class Entrepot extends CommonObject
{
public $element='stock';
public $table_element='entrepot';
/**
* Warehouse closed, inactive
*/
const STATUS_CLOSED = 0;
/**
* Warehouse open and operations for customer shipping, supplier dispatch, internal stock transfers/corrections allowed.
*/
const STATUS_OPEN_ALL = 1;
/**
* Warehouse open and operations for stock transfers/corrections allowed (not for customer shipping and supplier dispatch).
*/
const STATUS_OPEN_INTERNAL = 2;
/**
* Warehouse open and operations for customer shipping and internal stock transfers/corrections allowed (not for supplier dispatch).
*/
const STATUS_OPEN_SHIPPING = 3;
/**
* Warehouse open and operations for supplier dispatch internal stock transfers/corrections allowed (not for customer shipping).
*/
const STATUS_OPEN_DISPATCH = 4;
var $libelle;
var $description;
//! Statut 1 pour ouvert, 0 pour ferme
var $statut;
var $lieu;
var $address;
//! Code Postal
var $zip;
var $town;
// List of short language codes for status
var $statuts = array();
/**
* Constructor
*
@ -53,11 +81,22 @@ class Entrepot extends CommonObject
*/
function __construct($db)
{
global $conf;
$this->db = $db;
// List of short language codes for status
$this->statuts[0] = 'Closed2';
$this->statuts[1] = 'Opened';
$this->statuts[self::STATUS_CLOSED] = 'Closed2';
if ($conf->global->ENTREPOT_EXTRA_STATUS)
{
$this->statuts[self::STATUS_OPEN_ALL] = 'OpenAll';
$this->statuts[self::STATUS_OPEN_INTERNAL] = 'OpenInternal';
$this->statuts[self::STATUS_OPEN_SHIPPING] = 'OpenShipping';
$this->statuts[self::STATUS_OPEN_DISPATCH] = 'OpenDispatch';
}
else
{
$this->statuts[self::STATUS_OPEN_ALL] = 'Opened';
}
}
/**
@ -455,42 +494,40 @@ class Entrepot extends CommonObject
function LibStatut($statut,$mode=0)
{
global $langs;
$langs->load('stocks');
$picto = 'statut5';
$label = $langs->trans($this->statuts[$statut]);
if ($mode == 0)
{
$prefix='';
if ($statut == 0) return $langs->trans($this->statuts[$statut]);
if ($statut == 1) return $langs->trans($this->statuts[$statut]);
return $label;
}
if ($mode == 1)
{
$prefix='Short';
if ($statut == 0) return $langs->trans($this->statuts[$statut]);
if ($statut == 1) return $langs->trans($this->statuts[$statut]);
return $label;
}
if ($mode == 2)
{
$prefix='Short';
if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut5').' '.$langs->trans($this->statuts[$statut]);
if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
if ($statut > 0) $picto = 'statut4';
return img_picto($label, $picto).' '.$label;
}
if ($mode == 3)
{
$prefix='Short';
if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut5');
if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut4');
if ($statut > 0) $picto = 'statut4';
return img_picto($label, $picto).' '.$label;
}
if ($mode == 4)
{
if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut5').' '.$langs->trans($this->statuts[$statut]);
if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
if ($statut > 0) $picto = 'statut4';
return img_picto($label, $picto).' '.$label;
}
if ($mode == 5)
{
$prefix='Short';
if ($statut == 0) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut5');
if ($statut == 1) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut4');
if ($statut > 0) $picto = 'statut4';
return $label.' '.img_picto($label, $picto);
}
}