*
* 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
@@ -130,6 +131,7 @@ else
$sql.= ' p.fk_product_type, p.tms as datem,';
$sql.= ' p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte,';
$sql.= ' MIN(pfp.unitprice) as minsellprice';
+ $sql .= ', p.desiredstock';
$sql.= ' FROM '.MAIN_DB_PREFIX.'product as p';
if (! empty($search_categ) || ! empty($catid)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; // We'll need this table joined to the select in order to filter by categ
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
@@ -195,6 +197,7 @@ else
$sql.= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,";
$sql.= " p.fk_product_type, p.tms,";
$sql.= " p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte";
+ $sql .= ', p.desiredstock';
//if (GETPOST("toolowstock")) $sql.= " HAVING SUM(s.reel) < p.seuil_stock_alerte"; // Not used yet
$sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($limit + 1, $offset);
@@ -301,6 +304,7 @@ else
if (! empty($conf->service->enabled) && $type != 0) print_liste_field_titre($langs->trans("Duration"), $_SERVER["PHP_SELF"], "p.duration",$param,"",'align="center"',$sortfield,$sortorder);
if (empty($conf->global->PRODUIT_MULTIPRICES)) print_liste_field_titre($langs->trans("SellingPrice"), $_SERVER["PHP_SELF"], "p.price",$param,"",'align="right"',$sortfield,$sortorder);
print ''.$langs->trans("BuyingPriceMinShort").' ';
+ if (! empty($conf->stock->enabled) && $user->rights->stock->lire && $type != 1) print ''.$langs->trans("DesiredStock").' ';
if (! empty($conf->stock->enabled) && $user->rights->stock->lire && $type != 1) print ''.$langs->trans("PhysicalStock").' ';
print_liste_field_titre($langs->trans("Sell"), $_SERVER["PHP_SELF"], "p.tosell",$param,"",'align="right"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Buy"), $_SERVER["PHP_SELF"], "p.tobuy",$param,"",'align="right"',$sortfield,$sortorder);
@@ -351,6 +355,10 @@ else
print '';
print ' ';
print ' ';
+ //desiredstock
+ print '';
+ print ' ';
+ print ' ';
}
print '';
@@ -457,6 +465,9 @@ else
{
$product_static->id = $objp->rowid;
$product_static->load_stock();
+ print ' ';
+ print $objp->desiredstock;
+ print ' ';
print '';
if ($product_static->stock_reel < $objp->seuil_stock_alerte) print img_warning($langs->trans("StockTooLow")).' ';
print $product_static->stock_reel;
diff --git a/htdocs/product/reassort.php b/htdocs/product/reassort.php
index f39a06f36c2..00793b2ff8a 100644
--- a/htdocs/product/reassort.php
+++ b/htdocs/product/reassort.php
@@ -2,6 +2,7 @@
/* Copyright (C) 2001-2006 Rodolphe Quiedeville
* Copyright (C) 2004-2011 Laurent Destailleur
* Copyright (C) 2005-2012 Regis Houssin
+ * Copyright (C) 2013 Cédric Salvador
*
* 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
@@ -104,6 +105,7 @@ $sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price
$sql.= ' p.fk_product_type, p.tms as datem,';
$sql.= ' p.duration, p.tosell as statut, p.tobuy, p.seuil_stock_alerte,';
$sql.= ' SUM(s.reel) as stock_physique';
+$sql .= ', p.desiredstock';
$sql.= ' FROM ('.MAIN_DB_PREFIX.'product as p';
// We'll need this table joined to the select in order to filter by categ
if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_product as cp";
@@ -157,6 +159,7 @@ if ($search_categ)
$sql.= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,";
$sql.= " p.fk_product_type, p.tms,";
$sql.= " p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte";
+$sql .= ", p.desiredstock";
if ($toolowstock) $sql.= " HAVING SUM(s.reel) < p.seuil_stock_alerte"; // Not used yet
$sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($limit + 1, $offset);
@@ -242,6 +245,7 @@ if ($resql)
print_liste_field_titre($langs->trans("Label"),"reassort.php", "p.label",$param,"","",$sortfield,$sortorder);
if (! empty($conf->service->enabled) && $type == 1) print_liste_field_titre($langs->trans("Duration"),"reassort.php", "p.duration",$param,"",'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("MininumStock"),"reassort.php", "p.seuil_stock_alerte",$param,"",'align="right"',$sortfield,$sortorder);
+ print_liste_field_titre($langs->trans("DesiredStock"),"reassort.php", "p.desiredstock",$param,"",'align="right"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("PhysicalStock"),"reassort.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder);
// TODO Add info of running suppliers/customers orders
//print_liste_field_titre($langs->trans("TheoreticalStock"),"reassort.php", "stock_theorique",$param,"",'align="right"',$sortfield,$sortorder);
@@ -267,7 +271,8 @@ if ($resql)
print ' ';
print ' ';
print ' ';
- print ' ';
+ print ' ';
+ print ' ';
print '';
print ' ';
print ' ';
@@ -319,6 +324,7 @@ if ($resql)
}
//print ' '.$objp->stock_theorique.' ';
print ''.$objp->seuil_stock_alerte.' ';
+ print ''.$objp->desiredstock.' ';
print '';
if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' ';
print $objp->stock_physique;
@@ -356,4 +362,4 @@ else
llxFooter();
$db->close();
-?>
\ No newline at end of file
+?>
diff --git a/htdocs/product/stock/img/no.png b/htdocs/product/stock/img/no.png
new file mode 100644
index 00000000000..8aa4a46ba76
Binary files /dev/null and b/htdocs/product/stock/img/no.png differ
diff --git a/htdocs/product/stock/img/yes.png b/htdocs/product/stock/img/yes.png
new file mode 100644
index 00000000000..8e07437a95f
Binary files /dev/null and b/htdocs/product/stock/img/yes.png differ
diff --git a/htdocs/product/stock/lib/replenishment.lib.php b/htdocs/product/stock/lib/replenishment.lib.php
new file mode 100644
index 00000000000..470ca7fc2e1
--- /dev/null
+++ b/htdocs/product/stock/lib/replenishment.lib.php
@@ -0,0 +1,123 @@
+
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+/**
+ * \file htdocs/product/stock/replenishment.lib.php
+ * \ingroup produit
+ * \brief Contains functions used in replenish.php and replenishorders.php
+ */
+require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php';
+
+function dispatched($order_id)
+{
+ global $db;
+ $sql = 'SELECT fk_product, SUM(qty) from llx_commande_fournisseur_dispatch';
+ $sql .= ' WHERE fk_commande = ' . $order_id . ' GROUP BY fk_product';
+ $sql .= ' ORDER by fk_product';
+ $resql = $db->query($sql);
+ $dispatched = array();
+ $ordered = array();
+ if($resql && $db->num_rows($resql)) {
+ while($res = $db->fetch_object($resql))
+ $dispatched[] = $res;
+ }
+ $sql = 'SELECT fk_product, SUM(qty) from llx_commande_fournisseurdet';
+ $sql .= ' WHERE fk_commande = ' . $order_id . ' GROUP BY fk_product';
+ $sql .= ' ORDER by fk_product';
+ $resql = $db->query($sql);
+ if($resql && $db->num_rows($resql)) {
+ while($res = $db->fetch_object($resql))
+ $ordered[] = $res;
+ }
+ return $dispatched == $ordered;
+}
+
+function dispatchedOrders()
+{
+ global $db;
+ $sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . 'commande_fournisseur';
+ $resql = $db->query($sql);
+ $res = array();
+ if ($resql && $db->num_rows($resql) > 0) {
+ while ($obj = $db->fetch_object($resql)) {
+ if (dispatched($obj->rowid)) {
+ $res[] = $obj->rowid;
+ }
+ }
+ }
+ if ($res) {
+ $res = '(' . implode(',', $res) . ')';
+ } else {
+ //hack to make sure ordered SQL request won't syntax error
+ $res = '(0)';
+ }
+ return $res;
+}
+
+function ordered($product_id)
+{
+ global $db, $langs, $conf;
+ $sql = 'SELECT DISTINCT cfd.fk_product, SUM(cfd.qty) FROM';
+ $sql .= ' ' . MAIN_DB_PREFIX . 'commande_fournisseurdet as cfd ';
+ $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'commande_fournisseur as cf';
+ $sql .= ' ON cfd.fk_commande = cf.rowid WHERE';
+ if ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) {
+ $sql .= ' cf.fk_statut < 3';
+ } else if ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) {
+ $sql .= ' cf.fk_statut < 6 AND cf.rowid NOT IN ' . dispatchedOrders();
+ } else {
+ $sql .= ' cf.fk_statut < 5';
+ }
+ $sql .= ' AND cfd.fk_product = ' . $product_id;
+ $sql .= ' GROUP BY cfd.fk_product';
+
+ $resql = $db->query($sql);
+ if ($resql) {
+ $exists = $db->num_rows($resql);
+ if ($exists) {
+ $obj = $db->fetch_array($resql);
+ return $obj['SUM(cfd.qty)']; //. ' ' . img_picto('','tick');
+ } else {
+ return null;//img_picto('', 'stcomm-1');
+ }
+ } else {
+ $error = $db->lasterror();
+ dol_print_error($db);
+ dol_syslog('replenish.php: ' . $error, LOG_ERROR);
+
+ return $langs->trans('error');
+ }
+}
+
+function getProducts($order_id)
+{
+ global $db;
+ $order = new CommandeFournisseur($db);
+ $f = $order->fetch($order_id);
+ $products = array();
+ if($f) {
+ foreach($order->lines as $line) {
+ if (!in_array($line->fk_product, $products)) {
+ $products[] = $line->fk_product;
+ }
+ }
+ }
+ return $products;
+}
+
+?>
diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php
index 6ac507b2070..bca6660e10a 100644
--- a/htdocs/product/stock/product.php
+++ b/htdocs/product/stock/product.php
@@ -4,6 +4,7 @@
* Copyright (C) 2004 Eric Seigne
* Copyright (C) 2005 Simon TOSSER
* Copyright (C) 2005-2009 Regis Houssin
+ * Copyright (C) 2013 Cédric Salvador
*
* 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
@@ -43,6 +44,7 @@ $cancel=GETPOST('cancel');
$id = GETPOST('id')?GETPOST('id'):GETPOST('ref');
$ref = GETPOST('ref');
$stocklimit = GETPOST('stocklimit');
+$desiredstock = GETPOST('desiredstock');
$cancel = GETPOST('cancel');
$fieldid = isset($_GET["ref"])?'ref':'rowid';
if ($user->societe_id) $socid=$user->societe_id;
@@ -67,6 +69,19 @@ if ($action == 'setstocklimit')
$action='';
}
+// Set desired stock
+if ($action == 'setdesiredstock')
+{
+ $product = new Product($db);
+ $result=$product->fetch($id);
+ $product->desiredstock=$desiredstock;
+ $result=$product->update($product->id,$user,1,0,1);
+ if ($result < 0)
+ setEventMessage($product->error, 'errors');
+ $action='';
+}
+
+
// Correct stock
if ($action == "correct_stock" && ! $cancel)
{
@@ -247,6 +262,11 @@ if ($id > 0 || $ref)
print ''.$form->editfieldkey("StockLimit",'stocklimit',$product->seuil_stock_alerte,$product,$user->rights->produit->creer).' ';
print $form->editfieldval("StockLimit",'stocklimit',$product->seuil_stock_alerte,$product,$user->rights->produit->creer);
print ' ';
+
+ // Desired stock
+ print ''.$form->editfieldkey("DesiredStock",'desiredstock',$product->desiredstock,$product,$user->rights->produit->creer).' ';
+ print $form->editfieldval("DesiredStock",'desiredstock',$product->desiredstock,$product,$user->rights->produit->creer);
+ print ' ';
// Real stock
$product->load_stock();
diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php
new file mode 100644
index 00000000000..dfa764b615c
--- /dev/null
+++ b/htdocs/product/stock/replenish.php
@@ -0,0 +1,541 @@
+
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+/**
+ * \file htdocs/product/stock/replenish.php
+ * \ingroup produit
+ * \brief Page to list stocks to replenish
+ */
+
+require '../../main.inc.php';
+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 './lib/replenishment.lib.php';
+
+$langs->load("products");
+$langs->load("stocks");
+$langs->load("orders");
+
+// Security check
+if ($user->societe_id) {
+ $socid = $user->societe_id;
+}
+$result=restrictedArea($user,'produit|service');
+
+//checks if a product has been ordered
+
+$action = GETPOST('action','alpha');
+$sref = GETPOST('sref', 'alpha');
+$snom = GETPOST('snom', 'alpha');
+$sall = GETPOST('sall', 'alpha');
+$type = GETPOST('type','int');
+$tobuy = GETPOST('tobuy', 'int');
+
+$sortfield = GETPOST('sortfield','alpha');
+$sortorder = GETPOST('sortorder','alpha');
+$page = GETPOST('page','int');
+
+if (!$sortfield) {
+ $sortfield = 'p.ref';
+}
+
+if (!$sortorder) {
+ $sortorder = 'ASC';
+}
+$limit = $conf->liste_limit;
+$offset = $limit * $page ;
+
+/*
+ * Actions
+ */
+
+//orders creation
+//FIXME: could go in the lib
+if ($action == 'order') {
+ $linecount = GETPOST('linecount', 'int');
+ $box = 0;
+ unset($_POST['linecount']);
+ if ($linecount > 0) {
+ $suppliers = array();
+ for ($i = 0; $i < $linecount; $i++) {
+ if(GETPOST($i, 'alpha') === 'on'
+ && GETPOST('fourn' . $i, 'int') > 0) { //one line
+ $box = $i;
+ $supplierpriceid = GETPOST('fourn'.$i, 'int');
+ //get all the parameters needed to create a line
+ $qty = GETPOST('tobuy'.$i, 'int');
+ $desc = GETPOST('desc'.$i, 'alpha');
+ $sql = 'SELECT fk_product, fk_soc, ref_fourn';
+ $sql .= ', tva_tx, unitprice FROM ';
+ $sql .= MAIN_DB_PREFIX . 'product_fournisseur_price';
+ $sql .= ' WHERE rowid = ' . $supplierpriceid;
+ $resql = $db->query($sql);
+ if ($resql && $db->num_rows($resql) > 0) {
+ //might need some value checks
+ $obj = $db->fetch_object($resql);
+ $line = new CommandeFournisseurLigne($db);
+ $line->qty = $qty;
+ $line->desc = $desc;
+ $line->fk_product = $obj->fk_product;
+ $line->tva_tx = $obj->tva_tx;
+ $line->subprice = $obj->unitprice;
+ $line->total_ht = $obj->unitprice * $qty;
+ $tva = $line->tva_tx / 100;
+ $line->total_tva = $line->total_ht * $tva;
+ $line->total_ttc = $line->total_ht + $line->total_tva;
+ $line->ref_fourn = $obj->ref_fourn;
+ $suppliers[$obj->fk_soc]['lines'][] = $line;
+ } else {
+ $error=$db->lasterror();
+ dol_print_error($db);
+ dol_syslog('replenish.php: '.$error, LOG_ERROR);
+ }
+ $db->free($resql);
+ unset($_POST['fourn' . $i]);
+ }
+ unset($_POST[$i]);
+ }
+ //we now know how many orders we need and what lines they have
+ $i = 0;
+ $orders = array();
+ $suppliersid = array_keys($suppliers);
+ foreach ($suppliers as $supplier) {
+ $order = new CommandeFournisseur($db);
+ $order->socid = $suppliersid[$i];
+ //trick to know which orders have been generated this way
+ $order->source = 42;
+ foreach ($supplier['lines'] as $line) {
+ $order->lines[] = $line;
+ }
+ $id = $order->create($user);
+ if ($id < 0) {
+ $fail++;
+ setEventMessage($langs->trans('OrderFail'), 'errors');
+ }
+ $i++;
+ }
+ if (!$fail && $id) {
+ setEventMessage($langs->trans('OrderCreated'), 'mesgs');
+ header('Location: replenishorders.php');
+ exit;
+ }
+ }
+ if ($box == 0) {
+ setEventMessage($langs->trans('SelectProduct'), 'warnings');
+ }
+}
+
+/*
+ * View
+ */
+$title = $langs->trans('Status');
+
+$sql = 'SELECT p.rowid, p.ref, p.label, p.price';
+$sql .= ', p.price_ttc, p.price_base_type,p.fk_product_type';
+$sql .= ', p.tms as datem, p.duration, p.tobuy, p.seuil_stock_alerte,';
+$sql .= ' SUM(s.reel) as stock_physique';
+$sql .= ', p.desiredstock';
+$sql .= ' FROM ' . MAIN_DB_PREFIX . 'product as p';
+$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_fournisseur_price as pf';
+$sql .= ' ON p.rowid = pf.fk_product';
+$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_stock as s';
+$sql .= ' ON p.rowid = s.fk_product';
+$sql.= ' WHERE p.entity IN (' . getEntity("product", 1) . ')';
+if ($sall) {
+ $sql .= ' AND (p.ref LIKE "%'.$db->escape($sall).'%" ';
+ $sql .= 'OR p.label LIKE "%'.$db->escape($sall).'%" ';
+ $sql .= 'OR p.description LIKE "%'.$db->escape($sall).'%" ';
+ $sql .= 'OR p.note LIKE "%'.$db->escape($sall).'%")';
+}
+// if the type is not 1, we show all products (type = 0,2,3)
+if (dol_strlen($type)) {
+ if ($type == 1) {
+ $sql .= ' AND p.fk_product_type = 1';
+ } else {
+ $sql .= ' AND p.fk_product_type != 1';
+ }
+}
+if ($sref) {
+ $sql .= ' AND p.ref LIKE "%' . $sref . '%"';
+}
+if ($snom) {
+ $sql .= ' AND p.label LIKE "%' . $db->escape($snom) . '%"';
+}
+
+$sql .= ' AND p.tobuy = 1';
+
+if (!empty($canvas)) {
+ $sql .= ' AND p.canvas = "' . $db->escape($canvas) . '"';
+}
+$sql .= ' GROUP BY p.rowid, p.ref, p.label, p.price';
+$sql .= ', p.price_ttc, p.price_base_type,p.fk_product_type, p.tms';
+$sql .= ', p.duration, p.tobuy, p.seuil_stock_alerte';
+$sql .= ', p.desiredstock';
+$sql .= ' HAVING (p.desiredstock > SUM(s.reel) or SUM(s.reel) is NULL)';
+$sql .= ' AND p.desiredstock > 0';
+$sql .= $db->order($sortfield,$sortorder);
+$sql .= $db->plimit($limit + 1, $offset);
+$resql = $db->query($sql);
+
+if ($resql) {
+ $num = $db->num_rows($resql);
+ $i = 0;
+ if ($num == 1 && ($sall or $snom or $sref)) {
+ $objp = $db->fetch_object($resql);
+ header('Location: ../fiche.php?id=' . $objp->rowid);
+ exit;
+ }
+
+ $helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|';
+ $helpurl .= 'ES:Módulo_Stocks';
+ llxHeader('', $title, $helpurl, $title);
+ $head = array();
+ $head[0][0] = DOL_URL_ROOT.'/product/stock/replenish.php';
+ $head[0][1] = $title;
+ $head[0][2] = 'replenish';
+ $head[1][0] = DOL_URL_ROOT.'/product/stock/replenishorders.php';
+ $head[1][1] = $langs->trans("ReplenishmentOrders");
+ $head[1][2] = 'replenishorders';
+ dol_fiche_head($head, 'replenish', $langs->trans('Replenishment'), 0, 'stock');
+ if ($sref || $snom || $sall || GETPOST('search', 'alpha')) {
+ $filters = '&sref=' . $sref . '&snom=' . $snom;
+ $filters .= '&sall=' . $sall;
+ print_barre_liste($texte,
+ $page,
+ 'replenish.php',
+ $filters,
+ $sortfield,
+ $sortorder,
+ '',
+ $num
+ );
+ } else {
+ $filters = '&sref=' . $sref . '&snom=' . $snom;
+ $filters .= '&fourn_id=' . $fourn_id;
+ $filters .= (isset($type)?'&type=' . $type:'');
+ print_barre_liste($texte,
+ $page,
+ 'replenish.php',
+ $filters,
+ $sortfield,
+ $sortorder,
+ '',
+ $num);
+ }
+
+ echo '';
+
+ if ($num > $conf->liste_limit) {
+ if ($sref || $snom || $sall || GETPOST('search', 'alpha')) {
+ $filters = '&sref=' . $sref . '&snom=' . $snom;
+ $filters .= '&sall=' . $sall;
+ print_barre_liste('',
+ $page,
+ 'replenish.php',
+ $filters,
+ $sortfield,
+ $sortorder,
+ '',
+ $num,
+ 0,
+ ''
+ );
+ } else {
+ $filters = '&sref=' . $sref . '&snom=' . $snom;
+ $filters .= '&fourn_id=' . $fourn_id;
+ $filters .= (isset($type)? '&type=' . $type : '');
+ print_barre_liste('',
+ $page,
+ 'replenish.php',
+ $filters,
+ $sortfield,
+ $sortorder,
+ '',
+ $num,
+ 0,
+ ''
+ );
+ }
+ }
+
+ $db->free($resql);
+echo ' ';
+} else {
+ dol_print_error($db);
+}
+
+llxFooter();
+$db->close();
diff --git a/htdocs/product/stock/replenishorders.php b/htdocs/product/stock/replenishorders.php
new file mode 100644
index 00000000000..ed76755cfc0
--- /dev/null
+++ b/htdocs/product/stock/replenishorders.php
@@ -0,0 +1,318 @@
+
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+/**
+ * \file htdocs/product/stock/replenishorders.php
+ * \ingroup produit
+ * \brief Page to list replenishment orders
+ */
+require '../../main.inc.php';
+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.'/categories/class/categorie.class.php';
+require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
+require_once './lib/replenishment.lib.php';
+
+$langs->load("products");
+$langs->load("stocks");
+$langs->load("orders");
+
+// Security check
+if ($user->societe_id) $socid=$user->societe_id;
+$result=restrictedArea($user,'produit|service');
+
+$helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|';
+$helpurl .= 'ES:Módulo_Stocks';
+$texte = $langs->trans('ReplenishmentOrders');
+llxHeader('', $texte, $helpurl, $texte);
+$head = array();
+$head[0][0] = DOL_URL_ROOT.'/product/stock/replenish.php';
+$head[0][1] = $langs->trans('Status');
+$head[0][2] = 'replenish';
+$head[1][0] = DOL_URL_ROOT.'/product/stock/replenishorders.php';
+$head[1][1] = $texte;
+$head[1][2] = 'replenishorders';
+dol_fiche_head($head,
+ 'replenishorders',
+ $langs->trans('Replenishment'),
+ 0,
+ 'stock');
+$commandestatic = new CommandeFournisseur($db);
+$sref = GETPOST('search_ref', 'alpha');
+$snom = GETPOST('search_nom', 'alpha');
+$suser = GETPOST('search_user', 'alpha');
+$sttc = GETPOST('search_ttc', 'int');
+$sall = GETPOST('search_all', 'alpha');
+$sdate = GETPOST('search_date', 'alpha');
+$page = GETPOST('page', 'int');
+$sproduct = GETPOST('sproduct', 'int');
+$sortorder = GETPOST('sortorder', 'alpha');
+$sortfield = GETPOST('sortfield', 'alpha');
+
+if (!$sortorder) {
+ $sortorder = 'DESC';
+}
+
+if (!$sortfield) {
+ $sortfield = 'cf.date_creation';
+}
+
+$offset = $conf->liste_limit * $page ;
+
+$sql = 'SELECT s.rowid as socid, s.nom, cf.date_creation as dc,';
+$sql .= ' cf.rowid, cf.ref, cf.fk_statut, cf.total_ttc';
+$sql .= ", cf.fk_user_author, u.login";
+$sql .= ' FROM (' . MAIN_DB_PREFIX . 'societe as s,';
+$sql .= ' ' . MAIN_DB_PREFIX . 'commande_fournisseur as cf';
+
+if (!$user->rights->societe->client->voir && !$socid) {
+ $sql.= ', ' . MAIN_DB_PREFIX . 'societe_commerciaux as sc';
+
+}
+
+$sql .= ') LEFT JOIN ' . MAIN_DB_PREFIX . 'user as u ';
+$sql .= 'ON cf.fk_user_author = u.rowid';
+$sql .= ' WHERE cf.fk_soc = s.rowid ';
+$sql .= ' AND cf.entity = ' . $conf->entity;
+
+if ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) {
+ $sql .= ' AND cf.fk_statut < 3';
+} elseif ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) {
+ $sql .= ' AND cf.fk_statut < 6';
+} else {
+ $sql .= ' AND cf.fk_statut < 5';
+}
+
+if (!$user->rights->societe->client->voir && !$socid) {
+ $sql .= ' AND s.rowid = sc.fk_soc AND sc.fk_user = ' . $user->id;
+}
+if ($sref) {
+ $sql .= ' AND cf.ref LIKE "%' . $db->escape($sref) . '%"';
+}
+if ($snom) {
+ $sql .= ' AND s.nom LIKE "%' . $db->escape($snom) . '%"';
+}
+if ($suser) {
+ $sql .= ' AND u.login LIKE "%' . $db->escape($suser) . '%"';
+}
+if ($sttc) {
+ $sql .= ' AND cf.total_ttc = ' . price2num($sttc);
+}
+if ($sdate) {
+ if(GETPOST('search_datemonth', 'int') && GETPOST('search_dateday', 'int')
+ && GETPOST('search_dateyear', 'int')) {
+ $date = date('Y-m-d',
+ dol_mktime(0,
+ 0,
+ 0,
+ GETPOST('search_datemonth', 'int'),
+ GETPOST('search_dateday', 'int'),
+ GETPOST('search_dateyear', 'int')
+ )
+ );
+ } else {
+ $elts = explode('/', $sdate);
+ $datearray = array();
+ if ($elts[2]) {
+ $datearray[0] = $elts[2];
+ }
+ if ($elts[1]) {
+ $datearray[1] = $elts[1];
+ }
+ if ($elts[0]) {
+ $datearray[2] = $elts[0];
+ }
+ $date = implode('-', $datearray);
+ }
+ $sql .= ' AND cf.date_creation LIKE "%' . $date . '%"';
+}
+if ($sall) {
+ $sql .= ' AND (cf.ref LIKE "%' . $db->escape($sall) . '%" ';
+ $sql .= 'OR cf.note LIKE "%' . $db->escape($sall) . '%")';
+}
+if ($socid) {
+ $sql .= ' AND s.rowid = ' . $socid;
+}
+
+if (GETPOST('statut', 'int')) {
+ $sql .= ' AND fk_statut = ' . GETPOST('statut', 'int');
+}
+$sql .= ' GROUP BY cf.rowid, cf.ref, cf.date_creation, cf.fk_statut';
+$sql .= ', cf.total_ttc, cf.fk_user_author, u.login, s.rowid, s.nom';
+$sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder . ' ';
+$sql .= $db->plimit($conf->liste_limit+1, $offset);
+$resql = $db->query($sql);
+if ($resql) {
+ $num = $db->num_rows($resql);
+ $i = 0;
+
+ print_barre_liste($langs->trans('ReplenishmentOrders'),
+ $page,
+ 'replenishorders.php',
+ '',
+ $sortfield,
+ $sortorder,
+ '',
+ $num
+ );
+ echo '';
+
+ $db->free($resql);
+}
+
+llxFooter();
+$db->close();
diff --git a/scripts/contracts/email_expire_services_to_customers.php b/scripts/contracts/email_expire_services_to_customers.php
index 9753599115c..611d614393a 100755
--- a/scripts/contracts/email_expire_services_to_customers.php
+++ b/scripts/contracts/email_expire_services_to_customers.php
@@ -281,4 +281,4 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldcustomer,$dura
}
}
-?>
\ No newline at end of file
+?>
diff --git a/scripts/contracts/email_expire_services_to_representatives.php b/scripts/contracts/email_expire_services_to_representatives.php
index a41a59de3cf..7fded53a9f7 100755
--- a/scripts/contracts/email_expire_services_to_representatives.php
+++ b/scripts/contracts/email_expire_services_to_representatives.php
@@ -279,4 +279,4 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldsalerepresenta
}
}
-?>
\ No newline at end of file
+?>
diff --git a/scripts/user/sync_groups_ldap2dolibarr.php b/scripts/user/sync_groups_ldap2dolibarr.php
index 485f0dbf72a..e7bf8773a25 100755
--- a/scripts/user/sync_groups_ldap2dolibarr.php
+++ b/scripts/user/sync_groups_ldap2dolibarr.php
@@ -256,4 +256,4 @@ function dolValidElement($element)
return (trim($element) != '');
}
-?>
\ No newline at end of file
+?>
diff --git a/scripts/user/sync_users_ldap2dolibarr.php b/scripts/user/sync_users_ldap2dolibarr.php
index 8e831e26e84..60cb1118c37 100755
--- a/scripts/user/sync_users_ldap2dolibarr.php
+++ b/scripts/user/sync_users_ldap2dolibarr.php
@@ -311,4 +311,4 @@ function dolValidElement($element)
return (trim($element) != '');
}
-?>
\ No newline at end of file
+?>