';
+ $label.= '
' . $langs->trans('Ref') . ': ' . $this->ref;
+
+ $link = '
';
+ $linkend='';
+
+ if ($withpicto)
+ {
+ $result.=($link.img_object(($notooltip?'':$label), 'label', ($notooltip?'':'class="classfortooltip"')).$linkend);
+ if ($withpicto != 2) $result.=' ';
+ }
+ $result.= $link . $this->ref . $linkend;
+ return $result;
+ }
+
+ /**
+ * Retourne le libelle du status d'un user (actif, inactif)
+ *
+ * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
+ * @return string Label of status
+ */
+ function getLibStatut($mode=0)
+ {
+ return $this->LibStatut($this->status,$mode);
+ }
+
+ /**
+ * Renvoi le libelle d'un status donne
+ *
+ * @param int $status Id status
+ * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
+ * @return string Label of status
+ */
+ function LibStatut($status,$mode=0)
+ {
+ global $langs;
+
+ if ($mode == 0)
+ {
+ $prefix='';
+ if ($status == 1) return $langs->trans('Enabled');
+ if ($status == 0) return $langs->trans('Disabled');
+ }
+ if ($mode == 1)
+ {
+ if ($status == 1) return $langs->trans('Enabled');
+ if ($status == 0) return $langs->trans('Disabled');
+ }
+ if ($mode == 2)
+ {
+ if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
+ if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
+ }
+ if ($mode == 3)
+ {
+ if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4');
+ if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5');
+ }
+ if ($mode == 4)
+ {
+ if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
+ if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
+ }
+ if ($mode == 5)
+ {
+ if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
+ if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
+ }
+ }
+
+
+ /**
+ * Initialise object with example values
+ * Id must be 0 if object instance is a specimen
+ *
+ * @return void
+ */
+ public function initAsSpecimen()
+ {
+ $this->id = 0;
+
+ $this->tms = '';
+ $this->fk_product = '';
+ $this->fk_entrepot = '';
+ $this->seuil_stock_alerte = '';
+ $this->desiredstock = '';
+ $this->import_key = '';
+
+
+ }
+
+}
diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php
index 5a600707bc7..4482e249410 100644
--- a/htdocs/product/stock/product.php
+++ b/htdocs/product/stock/product.php
@@ -35,6 +35,7 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
+require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productstockentrepot.class.php';
if (! empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
$langs->load("products");
@@ -100,6 +101,60 @@ $parameters=array('id'=>$id, 'ref'=>$ref, 'objcanvas'=>$objcanvas);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
+if($action == 'addlimitstockwarehouse') {
+
+ $seuil_stock_alerte = GETPOST('seuil_stock_alerte');
+ $desiredstock = GETPOST('desiredstock');
+
+ $maj_ok = true;
+ if($seuil_stock_alerte == '') {
+ setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("StockLimit")), null, 'errors');
+ $maj_ok = false;
+ }
+ if($desiredstock == '') {
+ setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DesiredStock")), null, 'errors');
+ $maj_ok = false;
+ }
+
+ if($maj_ok) {
+
+ $pse = new ProductStockEntrepot($db);
+ if($pse->fetch('', GETPOST('id'), GETPOST('fk_entrepot')) > 0) {
+
+ // Update
+ $pse->seuil_stock_alerte = $seuil_stock_alerte;
+ $pse->desiredstock = $desiredstock;
+ if($pse->update($user) > 0) setEventMessage($langs->trans('ProductStockWarehouseUpdated'));
+
+ } else {
+
+ // Create
+ $pse->fk_entrepot = GETPOST('fk_entrepot');
+ $pse->fk_product = GETPOST('id');
+ $pse->seuil_stock_alerte = GETPOST('seuil_stock_alerte');
+ $pse->desiredstock = GETPOST('desiredstock');
+ if($pse->create($user) > 0) setEventMessage($langs->trans('ProductStockWarehouseCreated'));
+
+ }
+
+ }
+
+ header("Location: ".$_SERVER["PHP_SELF"]."?id=".GETPOST('id'));
+ exit;
+
+}
+
+if($action == 'delete_productstockwarehouse')
+{
+
+ $pse = new ProductStockEntrepot($db);
+ $pse->fetch(GETPOST('fk_productstockwarehouse'));
+ if($pse->delete($user) > 0) setEventMessage($langs->trans('ProductStockWarehouseDeleted'));
+
+ $action = '';
+
+}
+
// Set stock limit
if ($action == 'setseuil_stock_alerte')
{
@@ -864,6 +919,49 @@ print '';
print "";
print "";
+if(!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE)) {
+
+ print '
';
+ print_titre($langs->trans('AddNewProductStockWarehouse'));
+ //print '
';
+
+ print '
';
+
+}
llxFooter();
diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php
index ebd9f63f127..ca71f36b8a6 100644
--- a/htdocs/product/stock/replenish.php
+++ b/htdocs/product/stock/replenish.php
@@ -29,6 +29,7 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
+require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
require_once './lib/replenishment.lib.php';
$langs->load("products");
@@ -53,6 +54,7 @@ $salert = GETPOST('salert', 'alpha');
$mode = GETPOST('mode','alpha');
$fourn_id = GETPOST('fourn_id','int');
+$fk_entrepot = GETPOST('fk_entrepot','int');
$texte = '';
$sortfield = GETPOST('sortfield','alpha');
@@ -250,17 +252,26 @@ if ($action == 'order' && isset($_POST['valid']))
*/
$form = new Form($db);
+$formproduct = new FormProduct($db);
$title = $langs->trans('Status');
$sql = 'SELECT p.rowid, p.ref, p.label, p.description, p.price,';
$sql.= ' p.price_ttc, p.price_base_type,p.fk_product_type,';
$sql.= ' p.tms as datem, p.duration, p.tobuy,';
-$sql.= ' p.desiredstock, p.seuil_stock_alerte as alertstock,';
+if(!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
+ $sql.= ' '.$db->ifsql("pse.desiredstock IS NULL", "p.desiredstock", "pse.desiredstock").' as desiredstock,';
+ $sql.= ' '.$db->ifsql("pse.seuil_stock_alerte IS NULL", "p.seuil_stock_alerte", "pse.seuil_stock_alerte").' as alertstock,';
+} else {
+ $sql.= ' p.desiredstock, p.seuil_stock_alerte as alertstock,';
+}
$sql.= ' SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").') as stock_physique';
$sql.= ' FROM ' . MAIN_DB_PREFIX . 'product as p';
$sql.= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_stock as s';
$sql.= ' ON p.rowid = s.fk_product';
+if(!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
+ $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock_entrepot pse ON (p.rowid = pse.fk_product AND pse.fk_entrepot = '.$fk_entrepot.')';
+}
$sql.= ' WHERE p.entity IN (' . getEntity("product", 1) . ')';
if ($sall) {
$sql .= ' AND (p.ref LIKE "%'.$db->escape($sall).'%" ';
@@ -295,7 +306,11 @@ if (!empty($canvas)) $sql .= ' AND p.canvas = "' . $db->escape($canvas) . '"';
$sql.= ' GROUP BY p.rowid, p.ref, p.label, p.description, p.price';
$sql.= ', p.price_ttc, p.price_base_type,p.fk_product_type, p.tms';
$sql.= ', p.duration, p.tobuy';
-$sql.= ', p.desiredstock, p.seuil_stock_alerte';
+if(!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE) && $fk_entrepot > 0) {
+ $sql.= ', desiredstock, alertstock';
+} else {
+ $sql.= ', p.desiredstock, p.seuil_stock_alerte';
+}
$sql.= ', s.fk_product';
if ($usevirtualstock)
@@ -331,24 +346,24 @@ if ($usevirtualstock)
$sqlReceptionFourn.= " AND fd.fk_product = p.rowid";
$sqlReceptionFourn.= " AND cf.fk_statut IN (3,4))";
- $sql.= ' HAVING ((('.$db->ifsql("p.desiredstock IS NULL", "0", "p.desiredstock").' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
+ $sql.= ' HAVING ((('.$db->ifsql("desiredstock IS NULL", "0", "desiredstock").' > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
$sql.= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.')))';
- $sql.= ' OR (p.seuil_stock_alerte >= 0 AND (p.seuil_stock_alerte > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
+ $sql.= ' OR (alertstock >= 0 AND (alertstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
$sql.= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.'))))';
if ($salert == 'on') // Option to see when stock is lower than alert
{
- $sql.= ' AND (p.seuil_stock_alerte > 0 AND (p.seuil_stock_alerte > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
+ $sql.= ' AND (alertstock > 0 AND (alertstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
$sql.= ' - ('.$sqlCommandesCli.' - '.$sqlExpeditionsCli.') + ('.$sqlCommandesFourn.' - '.$sqlReceptionFourn.')))';
$alertchecked = 'checked';
}
} else {
- $sql.= ' HAVING ((p.desiredstock > 0 AND (p.desiredstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')))';
- $sql.= ' OR (p.seuil_stock_alerte > 0 AND (p.seuil_stock_alerte > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").'))))';
+ $sql.= ' HAVING ((desiredstock > 0 AND (desiredstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')))';
+ $sql.= ' OR (alertstock > 0 AND (alertstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").'))))';
if ($salert == 'on') // Option to see when stock is lower than alert
{
- $sql.= ' AND (p.seuil_stock_alerte > 0 AND (p.seuil_stock_alerte > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')))';
+ $sql.= ' AND (alertstock > 0 AND (alertstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')))';
$alertchecked = 'checked';
}
}
@@ -384,16 +399,6 @@ $head[1][2] = 'replenishorders';
print load_fiche_titre($langs->trans('Replenishment'), '', 'title_generic.png');
-
-print '
';
+
if ($sref || $snom || $sall || $salert || GETPOST('search', 'alpha')) {
$filters = '&sref=' . $sref . '&snom=' . $snom;
$filters .= '&sall=' . $sall;
$filters .= '&salert=' . $salert;
$filters .= '&mode=' . $mode;
+ $filters .= '&fk_entrepot=' . $fk_entrepot;
print_barre_liste(
$texte,
$page,
@@ -432,6 +448,7 @@ if ($sref || $snom || $sall || $salert || GETPOST('search', 'alpha')) {
$filters .= (isset($type)?'&type=' . $type:'');
$filters .= '&=' . $salert;
$filters .= '&mode=' . $mode;
+ $filters .= '&fk_entrepot=' . $fk_entrepot;
print_barre_liste(
$texte,
$page,
@@ -450,11 +467,21 @@ $param = (isset($type)? '&type=' . $type : '');
$param .= '&fourn_id=' . $fourn_id . '&snom='. $snom . '&salert=' . $salert;
$param .= '&sref=' . $sref;
$param .= '&mode=' . $mode;
+$param .= '&fk_entrepot=' . $fk_entrepot;
$stocklabel = $langs->trans('Stock');
if ($usevirtualstock == 1) $stocklabel = $langs->trans('VirtualStock');
if ($usevirtualstock == 0) $stocklabel = $langs->trans('PhysicalStock');
+print '