From e36613f0f0373513a912f2c2cd3a1a478e0cd363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Thu, 30 May 2013 16:32:48 +0200 Subject: [PATCH 01/92] added the desired stock field to the create/edit product UI --- htdocs/langs/en_US/stocks.lang | 3 ++- htdocs/langs/fr_FR/stocks.lang | 1 + htdocs/product/class/product.class.php | 11 ++++++++--- htdocs/product/fiche.php | 14 +++++++++++++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index 71dfc2d8c68..831ed26d937 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -88,4 +88,5 @@ ThisWarehouseIsPersonalStock=This warehouse represents personal stock of %s %s SelectWarehouseForStockDecrease=Choose warehouse to use for stock decrease SelectWarehouseForStockIncrease=Choose warehouse to use for stock increase NoStockAction=No stock action -LastWaitingSupplierOrders=Orders waiting for receptions \ No newline at end of file +LastWaitingSupplierOrders=Orders waiting for receptions +DesiredStock=Desired stock diff --git a/htdocs/langs/fr_FR/stocks.lang b/htdocs/langs/fr_FR/stocks.lang index df80fe6f1a8..15029f07ec6 100644 --- a/htdocs/langs/fr_FR/stocks.lang +++ b/htdocs/langs/fr_FR/stocks.lang @@ -89,3 +89,4 @@ SelectWarehouseForStockDecrease=Sélectionner l'entrepôt à utiliser pour la d SelectWarehouseForStockIncrease=Sélectionner l'entrepôt à utiliser pour l'incrémentation du stock NoStockAction=Pas d'action sur l'entrepôt LastWaitingSupplierOrders=Commandes en attente de réception +DesiredStock=Stock désiré diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 7ff3d662ab3..998b58cc980 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -83,7 +83,8 @@ class Product extends CommonObject var $pmp; //! Stock alert var $seuil_stock_alerte; - + //! Ask for replenishment when $desiredstock < $stock_reel + public $desiredstock; //! Duree de validite du service var $duration_value; //! Unite de duree @@ -165,6 +166,7 @@ class Product extends CommonObject $this->nbphoto = 0; $this->stock_reel = 0; $this->seuil_stock_alerte = 0; + $this->desiredstock = 0; $this->canvas = ''; } @@ -489,6 +491,7 @@ class Product extends CommonObject $sql.= ",duration = '" . $this->duration_value . $this->duration_unit ."'"; $sql.= ",accountancy_code_buy = '" . $this->accountancy_code_buy."'"; $sql.= ",accountancy_code_sell= '" . $this->accountancy_code_sell."'"; + $sql.= ", desiredstock = " . ((isset($this->desiredstock) && $this->desiredstock != '') ? $this->desiredstock : "null"); $sql.= " WHERE rowid = " . $id; dol_syslog(get_class($this)."update sql=".$sql); @@ -1135,7 +1138,7 @@ class Product extends CommonObject $sql.= " tobuy, fk_product_type, duration, seuil_stock_alerte, canvas,"; $sql.= " weight, weight_units, length, length_units, surface, surface_units, volume, volume_units, barcode, fk_barcode_type, finished,"; $sql.= " accountancy_code_buy, accountancy_code_sell, stock, pmp,"; - $sql.= " datec, tms, import_key, entity"; + $sql.= " datec, tms, import_key, entity, desiredstock"; $sql.= " FROM ".MAIN_DB_PREFIX."product"; if ($id) $sql.= " WHERE rowid = '".$id."'"; else @@ -1199,6 +1202,7 @@ class Product extends CommonObject $this->accountancy_code_sell = $obj->accountancy_code_sell; $this->seuil_stock_alerte = $obj->seuil_stock_alerte; + $this->desiredstock = $obj->desiredstock; $this->stock_reel = $obj->stock; $this->pmp = $obj->pmp; @@ -2199,7 +2203,8 @@ class Product extends CommonObject 'stock'=>$this->stock_warehouse[1]->real, // Stock 'stock_alert'=>$this->seuil_stock_alerte, // Stock alert 'fullpath' => $compl_path.$label, // Label - 'type'=>$type // Nb of units that compose parent product + 'type'=>$type, // Nb of units that compose parent product + 'desiredstock' => $this->desiredstock ); // Recursive call if child is an array diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index aa262f9a6c2..5baf7d00e1e 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -187,6 +187,7 @@ if (empty($reshook)) $object->duration_value = GETPOST('duration_value'); $object->duration_unit = GETPOST('duration_unit'); $object->seuil_stock_alerte = GETPOST('seuil_stock_alerte')?GETPOST('seuil_stock_alerte'):0; + $object->desiredstock = GETPOST('desiredstock')?GETPOST('desiredstock'):0; $object->canvas = GETPOST('canvas'); $object->weight = GETPOST('weight'); $object->weight_units = GETPOST('weight_units'); @@ -256,6 +257,7 @@ if (empty($reshook)) $object->status = GETPOST('statut'); $object->status_buy = GETPOST('statut_buy'); $object->seuil_stock_alerte = GETPOST('seuil_stock_alerte'); + $object->desiredstock = GETPOST('desiredstock'); $object->duration_value = GETPOST('duration_value'); $object->duration_unit = GETPOST('duration_unit'); $object->canvas = GETPOST('canvas'); @@ -723,12 +725,17 @@ else print ''.$langs->trans("StockLimit").''; print ''; print ''; + // Stock desired level + print ''.$langs->trans("DesiredStock").''; + print ''; + print ''; } else { print ''; + print ''; } - + // Description (used in invoice, propal...) print ''.$langs->trans("Description").''; @@ -934,10 +941,15 @@ else print "".''.$langs->trans("StockLimit").''; print ''; print ''; + + print "".''.$langs->trans("DesiredStock").''; + print ''; + print ''; } else { print ''; + print ''; } if ($object->isservice()) From aae8a623689a079e2fe275b8af19e5f48f05f18e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Thu, 30 May 2013 16:58:23 +0200 Subject: [PATCH 02/92] added the desiredstock parameter in the SQL scripts --- htdocs/install/mysql/migration/3.4.0-3.5.0.sql | 2 ++ htdocs/install/mysql/tables/llx_product.sql | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/install/mysql/migration/3.4.0-3.5.0.sql b/htdocs/install/mysql/migration/3.4.0-3.5.0.sql index f13042bff2e..a25413f017b 100755 --- a/htdocs/install/mysql/migration/3.4.0-3.5.0.sql +++ b/htdocs/install/mysql/migration/3.4.0-3.5.0.sql @@ -31,6 +31,8 @@ create table llx_fichinter_extrafields ) ENGINE=innodb; ALTER TABLE llx_fichinter_extrafields ADD INDEX idx_ficheinter_extrafields (fk_object); +ALTER TABLE llx_product ADD COLUMN desiredstock integer DEFAULT 0; + create table llx_commandedet_extrafields ( diff --git a/htdocs/install/mysql/tables/llx_product.sql b/htdocs/install/mysql/tables/llx_product.sql index 5e851d910a7..f9c1dbb54cb 100644 --- a/htdocs/install/mysql/tables/llx_product.sql +++ b/htdocs/install/mysql/tables/llx_product.sql @@ -70,5 +70,6 @@ create table llx_product canvas varchar(32) DEFAULT NULL, finished tinyint DEFAULT NULL, hidden tinyint DEFAULT 0, -- Need permission see also hidden products - import_key varchar(14) -- Import key + import_key varchar(14), -- Import key + desiredstock integer DEFAULT 0 )ENGINE=innodb; From ea2d94451adb65b6f9ebee025276abe2a351ee93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Thu, 30 May 2013 17:53:41 +0200 Subject: [PATCH 03/92] added the desired stock field to the Stock UI --- htdocs/product/stock/product.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php index 6ac507b2070..72c32911796 100644 --- a/htdocs/product/stock/product.php +++ b/htdocs/product/stock/product.php @@ -43,6 +43,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 +68,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 +261,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(); From 4f399131468efcf0237aabedf87c2b52671bfccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Fri, 31 May 2013 11:05:50 +0200 Subject: [PATCH 04/92] display the desiredstock field in product/reassort.php --- htdocs/product/reassort.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/htdocs/product/reassort.php b/htdocs/product/reassort.php index f39a06f36c2..3aa7f8820f2 100644 --- a/htdocs/product/reassort.php +++ b/htdocs/product/reassort.php @@ -104,6 +104,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 +158,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 +244,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 +270,8 @@ if ($resql) print ' '; print ' '; print ' '; - print ' '; + print ' '; + print ' '; print ''; print ''; print ''; @@ -319,6 +323,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 +361,4 @@ else llxFooter(); $db->close(); -?> \ No newline at end of file +?> From 1c8ac0e9bb1275711ce3f8de2dc9f14378840181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Fri, 31 May 2013 11:13:16 +0200 Subject: [PATCH 05/92] display the desiredstock field in product/liste.php --- htdocs/product/liste.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/htdocs/product/liste.php b/htdocs/product/liste.php index 5c312886313..27c4123a0f8 100644 --- a/htdocs/product/liste.php +++ b/htdocs/product/liste.php @@ -130,6 +130,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 +196,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 +303,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 +354,10 @@ else print ''; print ' '; print ''; + //desiredstock + print ''; + print ' '; + print ''; } print ''; @@ -457,6 +464,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; From c1116b672faad69ce85b9a7694ce09449171b1fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 3 Jun 2013 15:18:33 +0200 Subject: [PATCH 06/92] wizard UI --- htdocs/langs/en_US/stocks.lang | 1 + htdocs/langs/fr_FR/stocks.lang | 1 + htdocs/product/replenish.php | 367 +++++++++++++++++++++++++++++++++ 3 files changed, 369 insertions(+) create mode 100644 htdocs/product/replenish.php diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index 831ed26d937..df33e4f49ee 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -90,3 +90,4 @@ SelectWarehouseForStockIncrease=Choose warehouse to use for stock increase NoStockAction=No stock action LastWaitingSupplierOrders=Orders waiting for receptions DesiredStock=Desired stock +StockToBuy=Stock to buy diff --git a/htdocs/langs/fr_FR/stocks.lang b/htdocs/langs/fr_FR/stocks.lang index 15029f07ec6..324823ab75e 100644 --- a/htdocs/langs/fr_FR/stocks.lang +++ b/htdocs/langs/fr_FR/stocks.lang @@ -90,3 +90,4 @@ SelectWarehouseForStockIncrease=Sélectionner l'entrepôt à utiliser pour l'inc NoStockAction=Pas d'action sur l'entrepôt LastWaitingSupplierOrders=Commandes en attente de réception DesiredStock=Stock désiré +StockToBuy=Stock à acheter diff --git a/htdocs/product/replenish.php b/htdocs/product/replenish.php new file mode 100644 index 00000000000..819f4f736d6 --- /dev/null +++ b/htdocs/product/replenish.php @@ -0,0 +1,367 @@ + + * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * + * 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/replenish.php + * \ingroup produit + * \brief Page to list stocks + */ + +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'; + +$langs->load("products"); +$langs->load("stocks"); + +// Security check +if ($user->societe_id) $socid=$user->societe_id; +$result=restrictedArea($user,'produit|service'); + + +$action=GETPOST('action','alpha'); +$sref=GETPOST("sref"); +$snom=GETPOST("snom"); +$sall=GETPOST("sall"); +$type=GETPOST("type","int"); +$sbarcode=GETPOST("sbarcode"); +$catid=GETPOST('catid','int'); +$tobuy = GETPOST("tobuy"); + +$sortfield = GETPOST("sortfield",'alpha'); +$sortorder = GETPOST("sortorder",'alpha'); +$page = GETPOST("page",'int'); +if (! $sortfield) $sortfield="stock_physique"; +if (! $sortorder) $sortorder="ASC"; +$limit = $conf->liste_limit; +$offset = $limit * $page ; + +// Load sale and categ filters +$search_sale = GETPOST("search_sale"); +$search_categ = GETPOST("search_categ"); + +// Get object canvas (By default, this is not defined, so standard usage of dolibarr) +//$object->getCanvas($id); +$canvas=GETPOST("canvas"); +$objcanvas=''; +if (! empty($canvas)) +{ + require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php'; + $objcanvas = new Canvas($db,$action); + $objcanvas->getCanvas('product','list',$canvas); +} + +if (! empty($_POST["button_removefilter_x"])) +{ + $sref=""; + $snom=""; + $sall=""; + $search_sale=""; + $search_categ=""; + $type=""; + $catid=''; +} + + + +/* + * Actions + */ + +// None + + +/* + * View + */ + +$htmlother=new FormOther($db); + +$title=$langs->trans("ProductsAndServices"); + +$sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,'; +$sql.= ' p.fk_product_type, p.tms as datem,'; +$sql.= ' 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'; +// 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"; +$sql .= ') LEFT JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price as pf on p.rowid = pf.fk_product'; +$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s on p.rowid = s.fk_product'; + +$sql.= " WHERE p.entity IN (".getEntity('product', 1).")"; +if ($search_categ) $sql.= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ +if ($sall) +{ + $sql.= " AND (p.ref LIKE '%".$db->escape($sall)."%' OR p.label LIKE '%".$db->escape($sall)."%' OR p.description LIKE '%".$db->escape($sall)."%' 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 ($sbarcode) $sql.= " AND p.barcode LIKE '%".$sbarcode."%'"; +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)."'"; +} +if($catid) +{ + $sql.= " AND cp.fk_categorie = ".$catid; +} + + $sql.= " AND p.rowid = pf.fk_product"; + +// Insert categ filter +if ($search_categ) +{ + $sql .= " AND cp.fk_categorie = ".$db->escape($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.tobuy, p.seuil_stock_alerte"; +$sql .= ", p.desiredstock"; +$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=''; + $helpurl='EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; + + if (isset($type)) + { + if ($type==1) { $texte = $langs->trans("Services"); } + else { $texte = $langs->trans("Products"); } + } else { + $texte = $langs->trans("ProductsAndServices"); + } + $texte.=' ('.$langs->trans("Stocks").')'; + + + llxHeader("",$title,$helpurl,$texte); + + if ($sref || $snom || $sall || GETPOST('search')) + { + print_barre_liste($texte, $page, "replenish.php", "&sref=".$sref."&snom=".$snom."&sall=".$sall, $sortfield, $sortorder,'',$num); + } + else + { + print_barre_liste($texte, $page, "replenish.php", "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":""), $sortfield, $sortorder,'',$num); + } + + if (! empty($catid)) + { + print "
"; + $c = new Categorie($db); + $c->fetch($catid); + $ways = $c->print_all_ways(' > ','product/replenish.php'); + print " > ".$ways[0]."
\n"; + print "

"; + } + + print '
'; + print ''; + print ''; + print ''; + print ''; + + print ''; + + // Filter on categories + $moreforfilter=''; + if (! empty($conf->categorie->enabled)) + { + $moreforfilter.=$langs->trans('Categories'). ': '; + $moreforfilter.=$htmlother->select_categories(0,$search_categ,'search_categ'); + $moreforfilter.='           '; + } + if ($moreforfilter) + { + print ''; + print ''; + } + + $param=(isset($type)?"&type=$type":"")."&fourn_id=$fourn_id&snom=$snom&sref=$sref"; + + // Lignes des titres + print ""; + print ""; + print_liste_field_titre($langs->trans("Ref"),"replenish.php", "p.ref",$param,"","",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Label"),"replenish.php", "p.label",$param,"","",$sortfield,$sortorder); + if (! empty($conf->service->enabled) && $type == 1) print_liste_field_titre($langs->trans("Duration"),"replenish.php", "p.duration",$param,"",'align="center"',$sortfield,$sortorder); + //print_liste_field_titre($langs->trans("MininumStock"),"replenish.php", "p.seuil_stock_alerte",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("DesiredStock"),"replenish.php", "p.desiredstock",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("PhysicalStock"),"replenish.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("StockToBuy"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Supplier"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); + // TODO Add info of running suppliers/customers orders + //print_liste_field_titre($langs->trans("TheoreticalStock"),"replenish.php", "stock_theorique",$param,"",'align="right"',$sortfield,$sortorder); + print ''; + print "\n"; + + // Lignes des champs de filtre + print ''; + print ''; + print ''; + print ''; + if (! empty($conf->service->enabled) && $type == 1) + { + print ''; + } + print ''; + print ''; + print ''; + print ''; + //print ''; + // print ''; + print ''; + print ''; + + $product_static=new Product($db); + + $var=True; + while ($i < min($num,$limit)) + { + $objp = $db->fetch_object($resql); + + // Multilangs + if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active + { + $sql = "SELECT label"; + $sql.= " FROM ".MAIN_DB_PREFIX."product_lang"; + $sql.= " WHERE fk_product=".$objp->rowid; + $sql.= " AND lang='". $langs->getDefaultLang() ."'"; + $sql.= " LIMIT 1"; + + $result = $db->query($sql); + if ($result) + { + $objtp = $db->fetch_object($result); + if (! empty($objtp->label)) $objp->label = $objtp->label; + } + } + + $var=!$var; + print ''; + print ''; + print ''; + print ''; + + if (! empty($conf->service->enabled) && $type == 1) + { + print ''; + } + //print ''; + //print ''; + print ''; + print ''; + //depending on conf, use either physical stock or + //theoretical stock to compute the stock to buy value + ($conf->global->use_theoretical_stock? $stock = $objp->stock_théorique : $stock = $objp->stock_physique); + $stocktobuy = $objp->desiredstock - $stock; + print ''; + $form = new Form($db); + print ''; + print ''; + print "\n"; + $i++; + } + print "
'; + print $moreforfilter; + print '
  
 '; + print ''; + print ''; + print ''; + print ''; + print ' '; + print '      '; + print ''; + print ''; + print '
'; + $product_static->ref=$objp->ref; + $product_static->id=$objp->rowid; + $product_static->type=$objp->fk_product_type; + print $product_static->getNomUrl(1,'',16); + //if ($objp->stock_theorique < $objp->seuil_stock_alerte) print ' '.img_warning($langs->trans("StockTooLow")); + print ''.$objp->label.''; + if (preg_match('/([0-9]+)y/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationYear"); + elseif (preg_match('/([0-9]+)m/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationMonth"); + elseif (preg_match('/([0-9]+)d/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationDay"); + else print $objp->duration; + print ''.$objp->stock_theorique.''.$objp->seuil_stock_alerte.''.$objp->desiredstock.''; + if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; + print $objp->stock_physique; + print ''.$stocktobuy.''.$form->select_product_fourn_price($product_static->id).' 
"; + print ''; + print ''; + print '
'; + print '
'; + + if ($num > $conf->liste_limit) + { + if ($sref || $snom || $sall || GETPOST('search')) + { + print_barre_liste('', $page, "replenish.php", "&sref=".$sref."&snom=".$snom."&sall=".$sall, $sortfield, $sortorder,'',$num, 0, ''); + } + else + { + print_barre_liste('', $page, "replenish.php", "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":""), $sortfield, $sortorder,'',$num, 0, ''); + } + } + + $db->free($resql); + +} +else +{ + dol_print_error($db); +} + + +llxFooter(); +$db->close(); +?> From 6927274d2ad636624fc2aadc144e82fb3b09375e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 3 Jun 2013 15:34:12 +0200 Subject: [PATCH 07/92] copyright --- htdocs/install/mysql/tables/llx_product.sql | 1 + htdocs/product/fiche.php | 1 + htdocs/product/liste.php | 1 + htdocs/product/reassort.php | 1 + htdocs/product/replenish.php | 11 +++++------ htdocs/product/stock/product.php | 1 + 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/htdocs/install/mysql/tables/llx_product.sql b/htdocs/install/mysql/tables/llx_product.sql index f9c1dbb54cb..763309273f3 100644 --- a/htdocs/install/mysql/tables/llx_product.sql +++ b/htdocs/install/mysql/tables/llx_product.sql @@ -3,6 +3,7 @@ -- Copyright (C) 2008-2010 Laurent Destailleur -- Copyright (C) 2005-2010 Regis Houssin -- Copyright (C) 2010 juanjo Menent +-- 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 diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index 5baf7d00e1e..f13f8018f9e 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -7,6 +7,7 @@ * Copyright (C) 2006 Auguria SARL * Copyright (C) 2010-2011 Juanjo Menent * Copyright (C) 2013 Marcos García + * 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 diff --git a/htdocs/product/liste.php b/htdocs/product/liste.php index 27c4123a0f8..9680a1346b2 100644 --- a/htdocs/product/liste.php +++ b/htdocs/product/liste.php @@ -6,6 +6,7 @@ * Copyright (C) 2013 Juanjo Menent * Copyright (C) 2013 Raphaël Doursenaud * Copyright (C) 2013 Jean Heimburger + * 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 diff --git a/htdocs/product/reassort.php b/htdocs/product/reassort.php index 3aa7f8820f2..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 diff --git a/htdocs/product/replenish.php b/htdocs/product/replenish.php index 819f4f736d6..1a296623994 100644 --- a/htdocs/product/replenish.php +++ b/htdocs/product/replenish.php @@ -1,11 +1,10 @@ - * 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 + * 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 + * 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, @@ -14,7 +13,7 @@ * 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 . + * along with this program. If not, see . */ /** diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php index 72c32911796..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 From 3e77575768f8f0a0e3ae6f5c68e25ac8f47a27f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 4 Jun 2013 12:27:09 +0200 Subject: [PATCH 08/92] order creation wizard --- htdocs/product/replenish.php | 196 +++++++++++++++++++++++++++++++++-- 1 file changed, 188 insertions(+), 8 deletions(-) diff --git a/htdocs/product/replenish.php b/htdocs/product/replenish.php index 1a296623994..ce9490cf4e5 100644 --- a/htdocs/product/replenish.php +++ b/htdocs/product/replenish.php @@ -27,6 +27,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.'/categories/class/categorie.class.php'; +require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; $langs->load("products"); $langs->load("stocks"); @@ -84,6 +85,56 @@ if (! empty($_POST["button_removefilter_x"])) /* * Actions */ + +if($action == 'order'){ + $linecount = GETPOST('linecount', 'int'); + $suppliers = array(); + for($i = 0; $i < $linecount; $i++) { + if(GETPOST($i, 'alpha') === 'on') { //one line + $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'; + $sql .= ' from '.MAIN_DB_PREFIX.'product_fournisseur_price'; + $sql .= ' where rowid = '.$supplierpriceid; + $resql = $db->query($sql); + if($resql) { + //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; + $line->total_tva = $line->total_ht * $line->tva_tx / 100; + $line->total_ttc = $line->total_ht + $line->total_tva; + $line->ref_fourn = $obj->ref_fourn; + $suppliers[$obj->fk_soc]['lines'][] = $line; + } + } + } + //At this point we 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]; + $order->source = 42; + $i++; + foreach($supplier['lines'] as $line){ + $order->lines[] = $line; + } + $id = $order->create($user); + if($id) { + //emulate what fourn/commande/liste.php does + } + } +} // None @@ -207,6 +258,8 @@ if ($resql) print ''; print ''; print ''; + print ''; + print ''; print ''; @@ -239,8 +292,6 @@ if ($resql) print_liste_field_titre($langs->trans("PhysicalStock"),"replenish.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("StockToBuy"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Supplier"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); - // TODO Add info of running suppliers/customers orders - //print_liste_field_titre($langs->trans("TheoreticalStock"),"replenish.php", "stock_theorique",$param,"",'align="right"',$sortfield,$sortorder); print ''; print "\n"; @@ -263,8 +314,6 @@ if ($resql) print ''; print ''; print ''; - //print ''; - // print ''; print ''; - print ''; + print ''; print ''; print ''; + print ''; if (! empty($conf->service->enabled) && $type == 1) { @@ -316,8 +366,6 @@ if ($resql) else print $objp->duration; print ''; } - //print ''; - //print ''; print ''; print ''; + print ''; $form = new Form($db); - print ''; + print ''; print ''; print "\n"; $i++; @@ -360,6 +409,137 @@ else dol_print_error($db); } +$commandestatic=new CommandeFournisseur($db); + +$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, cf.fk_user_author,"; +$sql.= " 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.= ")"; +$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON cf.fk_user_author = u.rowid"; +$sql.= " WHERE cf.fk_soc = s.rowid "; +$sql.= " AND cf.entity = ".$conf->entity; +$sql.= " AND cf.source = 42"; +$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 total_ttc = ".price2num($sttc); +} +if ($sall) +{ + $sql.= " AND (cf.ref LIKE '%".$db->escape($sall)."%' OR cf.note LIKE '%".$db->escape($sall)."%')"; +} +if ($socid) $sql.= " AND s.rowid = ".$socid; + +if (GETPOST('statut')) +{ + $sql .= " AND fk_statut =".GETPOST('statut'); +} + +$sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset); +$resql = $db->query($sql); +if ($resql) +{ + + $num = $db->num_rows($resql); + $i = 0; + + + print_barre_liste($title, $page, "replenishment.php", "", $sortfield, $sortorder, '', $num); + print ''; + print '
 
     '; print ''; print ''; @@ -297,7 +346,7 @@ if ($resql) $var=!$var; print '
'; $product_static->ref=$objp->ref; $product_static->id=$objp->rowid; @@ -306,6 +355,7 @@ if ($resql) //if ($objp->stock_theorique < $objp->seuil_stock_alerte) print ' '.img_warning($langs->trans("StockTooLow")); print ''.$objp->label.''.$objp->stock_theorique.''.$objp->seuil_stock_alerte.''.$objp->desiredstock.''; if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; @@ -328,8 +376,9 @@ if ($resql) ($conf->global->use_theoretical_stock? $stock = $objp->stock_théorique : $stock = $objp->stock_physique); $stocktobuy = $objp->desiredstock - $stock; print ''.$stocktobuy.''.$form->select_product_fourn_price($product_static->id).''.$form->select_product_fourn_price($product_static->id, "fourn".$i).' 
'; + print ''; + print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"cf.ref","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"],"u.login","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"total_ttc","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("OrderDate"),$_SERVER["PHP_SELF"],"dc","","",'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"cf.fk_statut","","",'align="right"',$sortfield,$sortorder); + print "\n"; + + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $var=true; + + $userstatic = new User($db); + + while ($i < min($num,$conf->liste_limit)) + { + $obj = $db->fetch_object($resql); + $var=!$var; + + print ""; + + // Ref + print ''."\n"; + + // Company + print ''."\n"; + + // Author + $userstatic->id=$obj->fk_user_author; + $userstatic->login=$obj->login; + print ""; + + // Amount + print '"; + + // Date + print "'; + + // Statut + print ''; + + print "\n"; + $i++; + } + print "
'; + print ''; + print '
'.img_object($langs->trans("ShowOrder"),"order").' '.$obj->ref.''.img_object($langs->trans("ShowCompany"),"company").' '; + print $obj->nom.'"; + if ($userstatic->id) print $userstatic->getLoginUrl(1); + else print " "; + print "'.price($obj->total_ttc).""; + if ($obj->dc) + { + print dol_print_date($db->jdate($obj->dc),"day"); + } + else + { + print "-"; + } + print ''.$commandestatic->LibStatut($obj->fk_statut, 5).'
\n"; + print "\n"; + + $db->free($resql); +} llxFooter(); $db->close(); From b8f5aef27f39b6cabc329d2ec3842a644eef5f39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 4 Jun 2013 16:26:19 +0200 Subject: [PATCH 09/92] some improvement to the wizard UI --- .../class/fournisseur.commande.class.php | 2 +- htdocs/langs/en_US/orders.lang | 3 +- htdocs/langs/en_US/stocks.lang | 2 + htdocs/langs/fr_FR/orders.lang | 1 + htdocs/langs/fr_FR/stocks.lang | 2 + htdocs/product/replenish.php | 58 +++++++++---------- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 35534ad823f..e00c80d92de 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -951,7 +951,7 @@ class CommandeFournisseur extends CommonOrder //$sql.= ", ".$this->db->idate($now); $sql.= ", ".$user->id; $sql.= ", 0"; - $sql.= ", 0"; + $sql.= ", ".($this->source? $this->source : 0); $sql.= ", '".$conf->global->COMMANDE_SUPPLIER_ADDON_PDF."'"; //$sql.= ", ".$this->mode_reglement_id; $sql.= ")"; diff --git a/htdocs/langs/en_US/orders.lang b/htdocs/langs/en_US/orders.lang index 393678ed4c4..7a4833ab54b 100644 --- a/htdocs/langs/en_US/orders.lang +++ b/htdocs/langs/en_US/orders.lang @@ -160,4 +160,5 @@ OrderByPhone=Phone CreateInvoiceForThisCustomer=Bill orders NoOrdersToInvoice=No orders billable CloseProcessedOrdersAutomatically=Classify "Processed" all selected orders. -MenuOrdersToBill2=Billables orders \ No newline at end of file +MenuOrdersToBill2=Billables orders +OrderCreation=Order creation diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index df33e4f49ee..140c0807be1 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -91,3 +91,5 @@ NoStockAction=No stock action LastWaitingSupplierOrders=Orders waiting for receptions DesiredStock=Desired stock StockToBuy=Stock to buy +Replenishment=Replenishment +ReplenishmentOrders=Replenishment orders diff --git a/htdocs/langs/fr_FR/orders.lang b/htdocs/langs/fr_FR/orders.lang index 1091b4c2844..f4ae2622c77 100644 --- a/htdocs/langs/fr_FR/orders.lang +++ b/htdocs/langs/fr_FR/orders.lang @@ -161,3 +161,4 @@ CreateInvoiceForThisCustomer=Facturer commandes NoOrdersToInvoice=Pas de commandes facturables CloseProcessedOrdersAutomatically=Classer automatiquement à "Traitées" les commandes sélectionnées. MenuOrdersToBill2=Commandes à facturer +OrderCreation=Date de création diff --git a/htdocs/langs/fr_FR/stocks.lang b/htdocs/langs/fr_FR/stocks.lang index 324823ab75e..c9f8621d14d 100644 --- a/htdocs/langs/fr_FR/stocks.lang +++ b/htdocs/langs/fr_FR/stocks.lang @@ -91,3 +91,5 @@ NoStockAction=Pas d'action sur l'entrepôt LastWaitingSupplierOrders=Commandes en attente de réception DesiredStock=Stock désiré StockToBuy=Stock à acheter +Replenishment=Réapprovisionnement +ReplenishmentOrders=Commandes de réapprovisionnement diff --git a/htdocs/product/replenish.php b/htdocs/product/replenish.php index ce9490cf4e5..bd8b1400d93 100644 --- a/htdocs/product/replenish.php +++ b/htdocs/product/replenish.php @@ -100,7 +100,7 @@ if($action == 'order'){ $sql .= ' from '.MAIN_DB_PREFIX.'product_fournisseur_price'; $sql .= ' where rowid = '.$supplierpriceid; $resql = $db->query($sql); - if($resql) { + if($resql && $db->num_rows($resql) > 0) { //might need some value checks $obj = $db->fetch_object($resql); $line = new CommandeFournisseurLigne($db); @@ -117,35 +117,33 @@ if($action == 'order'){ } } } - //At this point we know how many orders we need and what lines they have + //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]; + //little trick to know which orders have been generated this way $order->source = 42; - $i++; foreach($supplier['lines'] as $line){ $order->lines[] = $line; } $id = $order->create($user); - if($id) { - //emulate what fourn/commande/liste.php does + if($id < 0) { + //error stuff } + $i++; } } -// None - - /* * View */ $htmlother=new FormOther($db); -$title=$langs->trans("ProductsAndServices"); +$title=$langs->trans("Replenishment"); $sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,'; $sql.= ' p.fk_product_type, p.tms as datem,'; @@ -221,17 +219,7 @@ if ($resql) $helpurl=''; $helpurl='EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; - - if (isset($type)) - { - if ($type==1) { $texte = $langs->trans("Services"); } - else { $texte = $langs->trans("Products"); } - } else { - $texte = $langs->trans("ProductsAndServices"); - } - $texte.=' ('.$langs->trans("Stocks").')'; - - + $texte = $langs->trans('Replenishment'); llxHeader("",$title,$helpurl,$texte); if ($sref || $snom || $sall || GETPOST('search')) @@ -410,11 +398,17 @@ else } $commandestatic=new CommandeFournisseur($db); +$sref=GETPOST('search_ref'); +$snom=GETPOST('search_nom'); +$suser=GETPOST('search_user'); +$sttc=GETPOST('search_ttc'); +$sall=GETPOST('search_all'); -$sortorder = GETPOST('sortorder','alpha'); -$sortfield = GETPOST('sortfield','alpha'); -if($sortorder == '') $sortorder="DESC"; -if($sortfield == '') $sortfield="cf.date_creation"; +$page = GETPOST('page','int'); +/*$sortorder = GETPOST('sortorder','alpha'); +$sortfield = GETPOST('sortfield','alpha');*/ +$sortorder="DESC"; +$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, cf.fk_user_author,"; @@ -465,16 +459,16 @@ if ($resql) $i = 0; - print_barre_liste($title, $page, "replenishment.php", "", $sortfield, $sortorder, '', $num); - print '
'; + print_barre_liste($langs->trans('ReplenishmentOrders'), $page, "replenish.php", "", $sortfield, $sortorder, '', $num); + print ''; print ''; print ''; - print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"cf.ref","","",'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","",'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"],"u.login","","",'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"total_ttc","","",'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("OrderDate"),$_SERVER["PHP_SELF"],"dc","","",'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"cf.fk_statut","","",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("OrderCreation"),$_SERVER["PHP_SELF"],"","","",'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"","","",'align="right"',$sortfield,$sortorder); print "\n"; print ''; From 2566f9017d2805b6e3e5fd0110ab226db57ee506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 4 Jun 2013 16:28:29 +0200 Subject: [PATCH 10/92] trans --- htdocs/product/replenish.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/product/replenish.php b/htdocs/product/replenish.php index bd8b1400d93..d09079f818b 100644 --- a/htdocs/product/replenish.php +++ b/htdocs/product/replenish.php @@ -31,6 +31,7 @@ require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; $langs->load("products"); $langs->load("stocks"); +$langs->load("orders"); // Security check if ($user->societe_id) $socid=$user->societe_id; From 14ea02ecac7411519f79630b7b918820b726f599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 4 Jun 2013 16:33:23 +0200 Subject: [PATCH 11/92] copyright --- htdocs/fourn/class/fournisseur.commande.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index e00c80d92de..f7e3e73f15b 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -7,6 +7,7 @@ * Copyright (C) 2010-2013 Philippe Grand * Copyright (C) 2012 Marcos García * Copyright (C) 2013 Florian Henry + * 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 From da5bbd0a082d7a8dd69b5ebb10e183854dfda525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 4 Jun 2013 18:25:15 +0200 Subject: [PATCH 12/92] moved page + added link in the left menu --- htdocs/core/menus/standard/eldy.lib.php | 1 + htdocs/product/{ => stock}/replenish.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) rename htdocs/product/{ => stock}/replenish.php (99%) diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 869960854c9..1348ca5f451 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -1005,6 +1005,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu if (empty($leftmenu) || $leftmenu=="stock") $newmenu->add("/product/stock/liste.php", $langs->trans("List"), 1, $user->rights->stock->lire); if (empty($leftmenu) || $leftmenu=="stock") $newmenu->add("/product/stock/valo.php", $langs->trans("EnhancedValue"), 1, $user->rights->stock->lire); if (empty($leftmenu) || $leftmenu=="stock") $newmenu->add("/product/stock/mouvement.php", $langs->trans("Movements"), 1, $user->rights->stock->mouvement->lire); + if (empty($leftmenu) || $leftmenu=="stock") $newmenu->add("/product/stock/replenish.php", $langs->trans("Replenishment"), 1, $user->rights->stock->mouvement->lire); } // Expeditions diff --git a/htdocs/product/replenish.php b/htdocs/product/stock/replenish.php similarity index 99% rename from htdocs/product/replenish.php rename to htdocs/product/stock/replenish.php index d09079f818b..70679319158 100644 --- a/htdocs/product/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -22,7 +22,7 @@ * \brief Page to list stocks */ -require '../main.inc.php'; +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'; From 0e77b273dfd3f5f3a223b84c56ff32b59d2db077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 4 Jun 2013 18:27:28 +0200 Subject: [PATCH 13/92] copyright --- htdocs/core/menus/standard/eldy.lib.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 1348ca5f451..c37d105a2f7 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -2,6 +2,7 @@ /* Copyright (C) 2010-2013 Laurent Destailleur * Copyright (C) 2010 Regis Houssin * Copyright (C) 2012-2013 Juanjo Menent + * 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 From 66cb265d2bfd2366a53c62f71c8ec16fc5ad0dd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 5 Jun 2013 14:50:29 +0200 Subject: [PATCH 14/92] filter out lines where stock > desiredstock --- htdocs/product/stock/replenish.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 70679319158..3f05008a6c5 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -201,6 +201,7 @@ $sql.= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.pr $sql.= " 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)'; $sql.= $db->order($sortfield,$sortorder); $sql.= $db->plimit($limit + 1, $offset); $resql = $db->query($sql); From 9f4e641cd9e9422cf2644a7bfb10a74563560919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 5 Jun 2013 15:22:33 +0200 Subject: [PATCH 15/92] comments --- htdocs/product/stock/replenish.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 3f05008a6c5..8a33a4228c8 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -17,9 +17,9 @@ */ /** - * \file htdocs/product/replenish.php + * \file htdocs/product/stock/replenish.php * \ingroup produit - * \brief Page to list stocks + * \brief Page to list stocks to replenish */ require '../../main.inc.php'; @@ -86,7 +86,8 @@ if (! empty($_POST["button_removefilter_x"])) /* * Actions */ - + +//orders creation if($action == 'order'){ $linecount = GETPOST('linecount', 'int'); $suppliers = array(); @@ -277,7 +278,6 @@ if ($resql) print_liste_field_titre($langs->trans("Ref"),"replenish.php", "p.ref",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Label"),"replenish.php", "p.label",$param,"","",$sortfield,$sortorder); if (! empty($conf->service->enabled) && $type == 1) print_liste_field_titre($langs->trans("Duration"),"replenish.php", "p.duration",$param,"",'align="center"',$sortfield,$sortorder); - //print_liste_field_titre($langs->trans("MininumStock"),"replenish.php", "p.seuil_stock_alerte",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("DesiredStock"),"replenish.php", "p.desiredstock",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("PhysicalStock"),"replenish.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("StockToBuy"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); @@ -342,7 +342,6 @@ if ($resql) $product_static->id=$objp->rowid; $product_static->type=$objp->fk_product_type; print $product_static->getNomUrl(1,'',16); - //if ($objp->stock_theorique < $objp->seuil_stock_alerte) print ' '.img_warning($langs->trans("StockTooLow")); print ''; print ''; print ''; @@ -407,8 +406,7 @@ $sttc=GETPOST('search_ttc'); $sall=GETPOST('search_all'); $page = GETPOST('page','int'); -/*$sortorder = GETPOST('sortorder','alpha'); -$sortfield = GETPOST('sortfield','alpha');*/ + $sortorder="DESC"; $sortfield="cf.date_creation"; $offset = $conf->liste_limit * $page ; From d541611dd1a7fe5e41a4c75f281e812b460c9449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 5 Jun 2013 16:04:00 +0200 Subject: [PATCH 16/92] merge --- scripts/contracts/email_expire_services_to_customers.php | 2 +- scripts/contracts/email_expire_services_to_representatives.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 +?> From 9792e5ad0032cb2808e9d82fdd2827a43fde61d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Thu, 6 Jun 2013 11:31:12 +0200 Subject: [PATCH 17/92] merge --- scripts/user/sync_users_ldap2dolibarr.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 +?> From 80a9dbfb901a3783a49e83778949768350b11621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 10 Jun 2013 11:57:06 +0200 Subject: [PATCH 18/92] products now show up in the list even when they don't have a line in llx_product_stock --- htdocs/product/stock/replenish.php | 97 ++++++++++++++++-------------- 1 file changed, 53 insertions(+), 44 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 8a33a4228c8..804243dcd30 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -90,52 +90,60 @@ if (! empty($_POST["button_removefilter_x"])) //orders creation if($action == 'order'){ $linecount = GETPOST('linecount', 'int'); - $suppliers = array(); - for($i = 0; $i < $linecount; $i++) { - if(GETPOST($i, 'alpha') === 'on') { //one line - $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'; - $sql .= ' from '.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; - $line->total_tva = $line->total_ht * $line->tva_tx / 100; - $line->total_ttc = $line->total_ht + $line->total_tva; - $line->ref_fourn = $obj->ref_fourn; - $suppliers[$obj->fk_soc]['lines'][] = $line; + if($linecount > 0){ + $suppliers = array(); + for($i = 0; $i < $linecount; $i++) { + if(GETPOST($i, 'alpha') === 'on') { //one line + $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'; + $sql .= ' from '.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; + $line->total_tva = $line->total_ht * $line->tva_tx / 100; + $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); + } } } - } - //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]; - //little trick to know which orders have been generated this way - $order->source = 42; - foreach($supplier['lines'] as $line){ - $order->lines[] = $line; + $db->free($resql); + //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]; + //little 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) { + //error stuff + } + $i++; } - $id = $order->create($user); - if($id < 0) { - //error stuff - } - $i++; } } @@ -202,7 +210,7 @@ $sql.= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.pr $sql.= " 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)'; +$sql.= ' HAVING p.desiredstock > SUM(s.reel) or SUM(s.reel) is NULL'; $sql.= $db->order($sortfield,$sortorder); $sql.= $db->plimit($limit + 1, $offset); $resql = $db->query($sql); @@ -357,6 +365,7 @@ if ($resql) } print ''; print ''; From 737aa7819fdcc1c08c75c72368986b722f9b1312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 10 Jun 2013 12:37:50 +0200 Subject: [PATCH 19/92] show service lines only if the stock services option is enabled --- htdocs/product/stock/replenish.php | 101 +++++++++++++++-------------- 1 file changed, 51 insertions(+), 50 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 804243dcd30..a07120bc1a6 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -324,61 +324,62 @@ if ($resql) while ($i < min($num,$limit)) { $objp = $db->fetch_object($resql); - - // Multilangs - if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active - { - $sql = "SELECT label"; - $sql.= " FROM ".MAIN_DB_PREFIX."product_lang"; - $sql.= " WHERE fk_product=".$objp->rowid; - $sql.= " AND lang='". $langs->getDefaultLang() ."'"; - $sql.= " LIMIT 1"; - - $result = $db->query($sql); - if ($result) + if($conf->global->STOCK_SUPPORTS_SERVICES || $objp->fk_product_type == 0){ + // Multilangs + if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active { - $objtp = $db->fetch_object($result); - if (! empty($objtp->label)) $objp->label = $objtp->label; + $sql = "SELECT label"; + $sql.= " FROM ".MAIN_DB_PREFIX."product_lang"; + $sql.= " WHERE fk_product=".$objp->rowid; + $sql.= " AND lang='". $langs->getDefaultLang() ."'"; + $sql.= " LIMIT 1"; + + $result = $db->query($sql); + if ($result) + { + $objtp = $db->fetch_object($result); + if (! empty($objtp->label)) $objp->label = $objtp->label; + } } - } - $var=!$var; - print ''; - print ''; - print ''; - print ''; - print ''; - - if (! empty($conf->service->enabled) && $type == 1) - { - print ''; + print ''; + print ''; + print ''; + print ''; + + if (! empty($conf->service->enabled) && $type == 1) + { + print ''; + } + print ''; + print ''; + //depending on conf, use either physical stock or + //theoretical stock to compute the stock to buy value + ($conf->global->use_theoretical_stock? $stock = $objp->stock_théorique : $stock = $objp->stock_physique); + $stocktobuy = $objp->desiredstock - $stock; + print ''; + print ''; + $form = new Form($db); + print ''; + print ''; + print "\n"; } - print ''; - print ''; - //depending on conf, use either physical stock or - //theoretical stock to compute the stock to buy value - ($conf->global->use_theoretical_stock? $stock = $objp->stock_théorique : $stock = $objp->stock_physique); - $stocktobuy = $objp->desiredstock - $stock; - print ''; - print ''; - $form = new Form($db); - print ''; - print ''; - print "\n"; $i++; } print "
'.$objp->label.''.$objp->desiredstock.''; + if(!$objp->stock_physique) $objp->stock_physique = 0; if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; print $objp->stock_physique; print '
'; - $product_static->ref=$objp->ref; - $product_static->id=$objp->rowid; - $product_static->type=$objp->fk_product_type; - print $product_static->getNomUrl(1,'',16); - print ''.$objp->label.''; - if (preg_match('/([0-9]+)y/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationYear"); - elseif (preg_match('/([0-9]+)m/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationMonth"); - elseif (preg_match('/([0-9]+)d/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationDay"); - else print $objp->duration; + $var=!$var; + print '
'; + $product_static->ref=$objp->ref; + $product_static->id=$objp->rowid; + $product_static->type=$objp->fk_product_type; + print $product_static->getNomUrl(1,'',16); print ''.$objp->label.''; + if (preg_match('/([0-9]+)y/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationYear"); + elseif (preg_match('/([0-9]+)m/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationMonth"); + elseif (preg_match('/([0-9]+)d/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationDay"); + else print $objp->duration; + print ''.$objp->desiredstock.''; + if(!$objp->stock_physique) $objp->stock_physique = 0; + if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; + print $objp->stock_physique; + print ''.$stocktobuy.''.$form->select_product_fourn_price($product_static->id, "fourn".$i).' 
'.$objp->desiredstock.''; - if(!$objp->stock_physique) $objp->stock_physique = 0; - if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; - print $objp->stock_physique; - print ''.$stocktobuy.''.$form->select_product_fourn_price($product_static->id, "fourn".$i).' 
"; From 9b4601bcf2daae4345fa88300cd804e20165099f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 10 Jun 2013 15:42:58 +0200 Subject: [PATCH 20/92] added an option to use virtual stock instead of physical stock --- htdocs/admin/stock.php | 19 +++++++++++++++++++ htdocs/langs/en_US/stocks.lang | 2 +- htdocs/langs/fr_FR/stocks.lang | 2 +- htdocs/product/stock/replenish.php | 27 ++++++++++++++++++++++----- 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/htdocs/admin/stock.php b/htdocs/admin/stock.php index 3733973bb2a..cbd7e46fd05 100644 --- a/htdocs/admin/stock.php +++ b/htdocs/admin/stock.php @@ -73,6 +73,11 @@ if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_BILL' if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER','alpha'),'chaine',0,'',$conf->entity); } +if($action == 'USE_VIRTUAL_STOCK') { + $db->begin(); + $res = dolibarr_set_const($db, "USE_VIRTUAL_STOCK", GETPOST('USE_VIRTUAL_STOCK','alpha'),'chaine',0,'',$conf->entity); +} + if($action) { if (! $res > 0) $error++; @@ -89,6 +94,7 @@ if($action) } } + /* * View */ @@ -136,6 +142,19 @@ print '' print ''; print "\n"; print "\n"; + +print ""; +print ''.$langs->trans("UseVirtualStock").''; +print ''; +print "
"; +print ''; +print ""; +print $form->selectyesno("USE_VIRTUAL_STOCK",$conf->global->USE_VIRTUAL_STOCK,1); +print ''; +print '
'; +print "\n"; +print "\n"; + print '
'; print ''; print '
'; diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index 140c0807be1..d36fe6d9121 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -64,7 +64,6 @@ StockLimitShort=Limit StockLimit=Stock limit for alerts PhysicalStock=Physical stock RealStock=Real Stock -TheoreticalStock=Therocial stock VirtualStock=Virtual stock MininumStock=Minimum stock StockUp=Stock up @@ -93,3 +92,4 @@ DesiredStock=Desired stock StockToBuy=Stock to buy Replenishment=Replenishment ReplenishmentOrders=Replenishment orders +UseVirtualStock=Use virtual stock instead of physical stock diff --git a/htdocs/langs/fr_FR/stocks.lang b/htdocs/langs/fr_FR/stocks.lang index c9f8621d14d..e7859b0fd52 100644 --- a/htdocs/langs/fr_FR/stocks.lang +++ b/htdocs/langs/fr_FR/stocks.lang @@ -64,7 +64,6 @@ StockLimitShort=Seuil StockLimit=Seuil d'alerte de stock PhysicalStock=Stock physique RealStock=Stock réel -TheoreticalStock=Stock théorique VirtualStock=Stock théorique MininumStock=Stock minimum StockUp=Stock maximum @@ -93,3 +92,4 @@ DesiredStock=Stock désiré StockToBuy=Stock à acheter Replenishment=Réapprovisionnement ReplenishmentOrders=Commandes de réapprovisionnement +UseVirtualStock=Utiliser le stock théorique à la place du stock physique diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index a07120bc1a6..182de040300 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -287,7 +287,12 @@ if ($resql) print_liste_field_titre($langs->trans("Label"),"replenish.php", "p.label",$param,"","",$sortfield,$sortorder); if (! empty($conf->service->enabled) && $type == 1) print_liste_field_titre($langs->trans("Duration"),"replenish.php", "p.duration",$param,"",'align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("DesiredStock"),"replenish.php", "p.desiredstock",$param,"",'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("PhysicalStock"),"replenish.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder); + if($conf->global->USE_VIRTUAL_STOCK) { + print_liste_field_titre($langs->trans("VirtualStock"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); + } + else { + print_liste_field_titre($langs->trans("PhysicalStock"),"replenish.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder); + } print_liste_field_titre($langs->trans("StockToBuy"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Supplier"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); print ' '; @@ -366,12 +371,24 @@ if ($resql) print ''.$objp->desiredstock.''; print ''; if(!$objp->stock_physique) $objp->stock_physique = 0; - if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; - print $objp->stock_physique; + if($conf->global->USE_VIRTUAL_STOCK){ + $product_static->fetch($product_static->id); + $result=$product_static->load_stats_commande(0,'1,2'); + if ($result < 0) dol_print_error($db,$product_static->error); + $stock_commande_client = $product_static->stats_commande['qty']; + $result=$product_static->load_stats_commande_fournisseur(0,'3'); + if ($result < 0) dol_print_error($db,$product_static->error); + $stock_commande_fournisseur = $product_static->stats_commande_fournisseur['qty']; + $stock = $objp->stock_physique - $stock_commande_client + $stock_commande_fournisseur; + } + else{ + $stock = $objp->stock_physique; + } + if ($objp->seuil_stock_alerte && ($stock < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; + print $stock; print ''; //depending on conf, use either physical stock or - //theoretical stock to compute the stock to buy value - ($conf->global->use_theoretical_stock? $stock = $objp->stock_théorique : $stock = $objp->stock_physique); + //virtual stock to compute the stock to buy value $stocktobuy = $objp->desiredstock - $stock; print ''.$stocktobuy.''; print ''; From d262f044ce9e9d82249599ef3a33163897f9c503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 10 Jun 2013 16:04:34 +0200 Subject: [PATCH 21/92] fixed SQL error when trying to generate an order without selecting any product line --- htdocs/product/stock/replenish.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 182de040300..a483e5dfa74 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -123,9 +123,9 @@ if($action == 'order'){ dol_print_error($db); dol_syslog("replenish.php: ".$error, LOG_ERROR); } + $db->free($resql); } } - $db->free($resql); //we now know how many orders we need and what lines they have $i = 0; $orders = array(); From 47a07c1c29197e665a55ab97b6a977b600079177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 10 Jun 2013 16:07:41 +0200 Subject: [PATCH 22/92] fixed error when trying to create an order when a line has no associated supplier --- htdocs/product/stock/replenish.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index a483e5dfa74..e1d833d7765 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -93,7 +93,7 @@ if($action == 'order'){ if($linecount > 0){ $suppliers = array(); for($i = 0; $i < $linecount; $i++) { - if(GETPOST($i, 'alpha') === 'on') { //one line + if(GETPOST($i, 'alpha') === 'on' && GETPOST('fourn'.$i, 'int') > 0) { //one line $supplierpriceid = GETPOST('fourn'.$i, 'int'); //get all the parameters needed to create a line $qty = GETPOST('tobuy'.$i, 'int'); From 5f526fd84a232eb766d6cafcd41d306c14861346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 10 Jun 2013 17:20:49 +0200 Subject: [PATCH 23/92] separated replenishment configuration --- htdocs/admin/stock.php | 32 +++++++++++++++++++------------- htdocs/langs/en_US/stocks.lang | 1 + htdocs/langs/fr_FR/stocks.lang | 1 + 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/htdocs/admin/stock.php b/htdocs/admin/stock.php index cbd7e46fd05..54221551469 100644 --- a/htdocs/admin/stock.php +++ b/htdocs/admin/stock.php @@ -142,19 +142,6 @@ print '' print ''; print "\n"; print "\n"; - -print ""; -print ''.$langs->trans("UseVirtualStock").''; -print ''; -print "
"; -print ''; -print ""; -print $form->selectyesno("USE_VIRTUAL_STOCK",$conf->global->USE_VIRTUAL_STOCK,1); -print ''; -print '
'; -print "\n"; -print "\n"; - print '
'; print ''; print '
'; @@ -262,6 +249,25 @@ if (! empty($conf->fournisseur->enabled)) print ''; +print '
'; +print ''; +print ''; +print " \n"; +print " \n"; +print ''."\n"; +print ""; +print ''; +print '\n"; +print "\n"; +print '
".$langs->trans("RuleForStockReplenishment")." 
'.$langs->trans("UseVirtualStock").''; +print "
"; +print ''; +print ""; +print $form->selectyesno("USE_VIRTUAL_STOCK",$conf->global->USE_VIRTUAL_STOCK,1); +print ''; +print '
'; +print "
'; + dol_htmloutput_mesg($mesg); $db->close(); diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index d36fe6d9121..a178c416fb3 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -93,3 +93,4 @@ StockToBuy=Stock to buy Replenishment=Replenishment ReplenishmentOrders=Replenishment orders UseVirtualStock=Use virtual stock instead of physical stock +RuleForStockReplenishment=Rule for stocks replenishment diff --git a/htdocs/langs/fr_FR/stocks.lang b/htdocs/langs/fr_FR/stocks.lang index e7859b0fd52..b7cbf9344ae 100644 --- a/htdocs/langs/fr_FR/stocks.lang +++ b/htdocs/langs/fr_FR/stocks.lang @@ -93,3 +93,4 @@ StockToBuy=Stock à acheter Replenishment=Réapprovisionnement ReplenishmentOrders=Commandes de réapprovisionnement UseVirtualStock=Utiliser le stock théorique à la place du stock physique +RuleForStockReplenishment=Règle de gestion du réapprovisionnement des stocks From 8666725c624d7886ed634ff59211d70c667d7a4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 10 Jun 2013 18:10:06 +0200 Subject: [PATCH 24/92] Preselected supplier when there's only one --- htdocs/core/class/html.form.class.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 2b540f3aabd..6983865eac9 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1829,7 +1829,7 @@ class Form * @param string $htmlname Name of HTML field * @return void */ - function select_product_fourn_price($productid,$htmlname='productfournpriceid') + function select_product_fourn_price($productid,$htmlname='productfournpriceid', $showempty=0) { global $langs,$conf; @@ -1860,9 +1860,15 @@ class Form { $form.= ''; } + else if ($num == 1) { + $objp = $this->db->fetch_object($result); + $form = $objp->nom; + $form .= ''; + } else { - $form.= ''; + $form = ''; print ''; @@ -392,6 +419,9 @@ if ($resql) $stocktobuy = $objp->desiredstock - $stock; print ''.$stocktobuy.''; print ''; + print ''; + print ordered($product_static->id); + print ''; $form = new Form($db); print ''.$form->select_product_fourn_price($product_static->id, "fourn".$i).''; print ' '; From e068655e6e7e5156119ca62ca50e23593f588c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 11 Jun 2013 11:34:57 +0200 Subject: [PATCH 26/92] display the ordered quantity in the ordered column --- htdocs/product/stock/replenish.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index ace6ad548f4..946a6bb7305 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -39,17 +39,19 @@ $result=restrictedArea($user,'produit|service'); function ordered($product_id) { global $db; - $sql = 'SELECT DISTINCT cfd.fk_product from '; + $sql = 'SELECT DISTINCT cfd.fk_product, SUM(cfd.qty) from '; $sql .= MAIN_DB_PREFIX.'commande_fournisseurdet as cfd LEFT JOIN '; $sql .= MAIN_DB_PREFIX.'commande_fournisseur as cf ON '; $sql .= 'cfd.fk_commande = cf.rowid WHERE cf.source = 42 '; $sql .= 'AND cf.fk_statut < 5 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) { - return img_picto('','tick'); + $obj = $db->fetch_array($resql); + return $obj['SUM(cfd.qty)'].' '.img_picto('','tick'); } else { return img_picto('', 'stcomm-1'); From 2f6c979c32f2f50b3346de2b010e7ad6e0fbb5fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 11 Jun 2013 15:20:12 +0200 Subject: [PATCH 27/92] psr 0 --- htdocs/product/stock/replenish.php | 834 ++++++++++++++++++----------- 1 file changed, 520 insertions(+), 314 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 946a6bb7305..00c514a899f 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -40,10 +40,10 @@ $result=restrictedArea($user,'produit|service'); function ordered($product_id) { global $db; $sql = 'SELECT DISTINCT cfd.fk_product, SUM(cfd.qty) from '; - $sql .= MAIN_DB_PREFIX.'commande_fournisseurdet as cfd LEFT JOIN '; - $sql .= MAIN_DB_PREFIX.'commande_fournisseur as cf ON '; - $sql .= 'cfd.fk_commande = cf.rowid WHERE cf.source = 42 '; - $sql .= 'AND cf.fk_statut < 5 AND cfd.fk_product = '.$product_id; + $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 cf.source = 42 '; + $sql .= 'AND cf.fk_statut < 5 AND cfd.fk_product = ' . $product_id; $sql .= ' GROUP BY cfd.fk_product'; $resql = $db->query($sql); @@ -51,7 +51,7 @@ function ordered($product_id) { $exists = $db->num_rows($resql); if($exists) { $obj = $db->fetch_array($resql); - return $obj['SUM(cfd.qty)'].' '.img_picto('','tick'); + return $obj['SUM(cfd.qty)'] . ' ' . img_picto('','tick'); } else { return img_picto('', 'stcomm-1'); @@ -60,52 +60,50 @@ function ordered($product_id) { else { $error=$db->lasterror(); dol_print_error($db); - dol_syslog("replenish.php: ".$error, LOG_ERROR); + dol_syslog('replenish.php: ' . $error, LOG_ERROR); return $langs->trans('error'); } } -$action=GETPOST('action','alpha'); -$sref=GETPOST("sref"); -$snom=GETPOST("snom"); -$sall=GETPOST("sall"); -$type=GETPOST("type","int"); -$sbarcode=GETPOST("sbarcode"); -$catid=GETPOST('catid','int'); -$tobuy = GETPOST("tobuy"); +$action = GETPOST('action','alpha'); +$sref = GETPOST('sref'); +$snom = GETPOST('snom'); +$sall = GETPOST('sall'); +$type = GETPOST('type','int'); +$sbarcode = GETPOST('sbarcode'); +$catid = GETPOST('catid','int'); +$tobuy = GETPOST('tobuy'); -$sortfield = GETPOST("sortfield",'alpha'); -$sortorder = GETPOST("sortorder",'alpha'); -$page = GETPOST("page",'int'); -if (! $sortfield) $sortfield="stock_physique"; -if (! $sortorder) $sortorder="ASC"; +$sortfield = GETPOST('sortfield','alpha'); +$sortorder = GETPOST('sortorder','alpha'); +$page = GETPOST('page','int'); +if (! $sortfield) $sortfield = 'stock_physique'; +if (! $sortorder) $sortorder = 'ASC'; $limit = $conf->liste_limit; $offset = $limit * $page ; // Load sale and categ filters -$search_sale = GETPOST("search_sale"); -$search_categ = GETPOST("search_categ"); +$search_sale = GETPOST('search_sale'); +$search_categ = GETPOST('search_categ'); -// Get object canvas (By default, this is not defined, so standard usage of dolibarr) -//$object->getCanvas($id); -$canvas=GETPOST("canvas"); -$objcanvas=''; -if (! empty($canvas)) -{ - require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php'; +// Get object canvas +//(By default, this is not defined, so standard usage of dolibarr) +$canvas = GETPOST('canvas'); +$objcanvas = ''; +if (! empty($canvas)) { + require_once DOL_DOCUMENT_ROOT . '/core/class/canvas.class.php'; $objcanvas = new Canvas($db,$action); - $objcanvas->getCanvas('product','list',$canvas); + $objcanvas->getCanvas('product', 'list', $canvas); } -if (! empty($_POST["button_removefilter_x"])) -{ - $sref=""; - $snom=""; - $sall=""; - $search_sale=""; - $search_categ=""; - $type=""; - $catid=''; +if (! empty($_POST['button_removefilter_x'])) { + $sref = ''; + $snom = ''; + $sall = ''; + $search_sale = ''; + $search_categ = ''; + $type = ''; + $catid = ''; } @@ -115,20 +113,21 @@ if (! empty($_POST["button_removefilter_x"])) */ //orders creation -if($action == 'order'){ +if($action == 'order') { $linecount = GETPOST('linecount', 'int'); - if($linecount > 0){ + if($linecount > 0) { $suppliers = array(); for($i = 0; $i < $linecount; $i++) { - if(GETPOST($i, 'alpha') === 'on' && GETPOST('fourn'.$i, 'int') > 0) { //one line + if(GETPOST($i, 'alpha') === 'on' + && GETPOST('fourn' . $i, 'int') > 0) { //one line $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'; - $sql .= ' from '.MAIN_DB_PREFIX.'product_fournisseur_price'; - $sql .= ' where rowid = '.$supplierpriceid; + $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 @@ -140,7 +139,8 @@ if($action == 'order'){ $line->tva_tx = $obj->tva_tx; $line->subprice = $obj->unitprice; $line->total_ht = $obj->unitprice * $qty; - $line->total_tva = $line->total_ht * $line->tva_tx / 100; + $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; @@ -148,7 +148,7 @@ if($action == 'order'){ else { $error=$db->lasterror(); dol_print_error($db); - dol_syslog("replenish.php: ".$error, LOG_ERROR); + dol_syslog('replenish.php: '.$error, LOG_ERROR); } $db->free($resql); } @@ -157,12 +157,12 @@ if($action == 'order'){ $i = 0; $orders = array(); $suppliersid = array_keys($suppliers); - foreach($suppliers as $supplier){ + foreach($suppliers as $supplier) { $order = new CommandeFournisseur($db); $order->socid = $suppliersid[$i]; - //little trick to know which orders have been generated this way + //trick to know which orders have been generated this way $order->source = 42; - foreach($supplier['lines'] as $line){ + foreach($supplier['lines'] as $line) { $order->lines[] = $line; } $id = $order->create($user); @@ -180,163 +180,254 @@ if($action == 'order'){ $htmlother=new FormOther($db); -$title=$langs->trans("Replenishment"); +$title=$langs->trans('Replenishment'); -$sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,'; -$sql.= ' p.fk_product_type, p.tms as datem,'; -$sql.= ' p.duration, p.tobuy, p.seuil_stock_alerte,'; -$sql.= ' SUM(s.reel) as stock_physique'; +$sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, 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'; -// 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"; -$sql .= ') LEFT JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price as pf on p.rowid = pf.fk_product'; -$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s on p.rowid = s.fk_product'; +$sql .= ' FROM (' . MAIN_DB_PREFIX . 'product as p'; +// need this table joined to the select in order to filter by categ +if ($search_categ) { + $sql.= ", " . MAIN_DB_PREFIX . "categorie_product as cp"; +} +$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 ($search_categ) $sql.= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ -if ($sall) -{ - $sql.= " AND (p.ref LIKE '%".$db->escape($sall)."%' OR p.label LIKE '%".$db->escape($sall)."%' OR p.description LIKE '%".$db->escape($sall)."%' OR p.note LIKE '%".$db->escape($sall)."%')"; +$sql.= ' WHERE p.entity IN (' . getEntity("product", 1) . ')'; +if ($search_categ) { // Join for the needed table to filter by categ + $sql .= ' AND p.rowid = cp.fk_product'; +} +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'"; +if (dol_strlen($type)) { + if ($type == 1) { + $sql .= ' AND p.fk_product_type = 1'; } - else - { - $sql.= " AND p.fk_product_type <> '1'"; + else { + $sql .= ' AND p.fk_product_type != 1'; } } -if ($sref) $sql.= " AND p.ref LIKE '%".$sref."%'"; -if ($sbarcode) $sql.= " AND p.barcode LIKE '%".$sbarcode."%'"; -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)."'"; +if ($sref) { + $sql .= ' AND p.ref LIKE "%' . $sref . '%"'; } -if($catid) -{ - $sql.= " AND cp.fk_categorie = ".$catid; +if ($sbarcode) { + $sql .= ' AND p.barcode LIKE "%' . $sbarcode . '%"'; +} +if ($snom) { + $sql .= ' AND p.label LIKE "%' . $db->escape($snom) . '%"'; } - $sql.= " AND p.rowid = pf.fk_product"; +$sql .= ' AND p.tobuy = 1'; + +if (!empty($canvas)) { + $sql .= ' AND p.canvas = "' . $db->escape($canvas) . '"'; +} +if($catid) { + $sql .= ' AND cp.fk_categorie = ' . $catid; +} + + $sql .= ' AND p.rowid = pf.fk_product'; // Insert categ filter -if ($search_categ) -{ - $sql .= " AND cp.fk_categorie = ".$db->escape($search_categ); +if ($search_categ) { + $sql .= ' AND cp.fk_categorie = ' . $db->escape($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.tobuy, p.seuil_stock_alerte"; -$sql .= ", p.desiredstock"; -$sql.= ' HAVING p.desiredstock > SUM(s.reel) or SUM(s.reel) is NULL'; -$sql.= $db->order($sortfield,$sortorder); -$sql.= $db->plimit($limit + 1, $offset); +$sql .= ' GROUP BY p.rowid, p.ref, p.label, p.barcode, 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 .= $db->order($sortfield,$sortorder); +$sql .= $db->plimit($limit + 1, $offset); $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { $num = $db->num_rows($resql); - $i = 0; - - if ($num == 1 && ($sall or $snom or $sref)) - { + if ($num == 1 && ($sall or $snom or $sref)) { $objp = $db->fetch_object($resql); - header("Location: fiche.php?id=$objp->rowid"); + header('Location: ../fiche.php?id=' . $objp->rowid); exit; } - $helpurl=''; - $helpurl='EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; + $helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|'; + $helpurl .= 'ES:Módulo_Stocks'; $texte = $langs->trans('Replenishment'); - llxHeader("",$title,$helpurl,$texte); + llxHeader('', $title, $helpurl, $texte); - if ($sref || $snom || $sall || GETPOST('search')) - { - print_barre_liste($texte, $page, "replenish.php", "&sref=".$sref."&snom=".$snom."&sall=".$sall, $sortfield, $sortorder,'',$num); + if ($sref || $snom || $sall || GETPOST('search')) { + print_barre_liste($texte, + $page, + 'replenish.php', + '&sref=' . $sref . '&snom=' . $snom . '&sall=' . $sall, + $sortfield, + $sortorder, + '', + $num + ); } - else - { - print_barre_liste($texte, $page, "replenish.php", "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":""), $sortfield, $sortorder,'',$num); + else { + print_barre_liste($texte, + $page, + 'replenish.php', + '&sref=$sref&snom=$snom&fourn_id=$fourn_id' . (isset($type)?'&type=$type':''), + $sortfield, + $sortorder, + '', + $num); } - if (! empty($catid)) - { - print "
"; + if (!empty($catid)) { + print '
'; $c = new Categorie($db); $c->fetch($catid); - $ways = $c->print_all_ways(' > ','product/replenish.php'); - print " > ".$ways[0]."
\n"; - print "

"; + $ways = $c->print_all_ways(' > ', 'product/replenish.php'); + print ' > ' . $ways[0] . '
'; + print '

'; } print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; print ''; print ''; // Filter on categories - $moreforfilter=''; - if (! empty($conf->categorie->enabled)) - { - $moreforfilter.=$langs->trans('Categories'). ': '; - $moreforfilter.=$htmlother->select_categories(0,$search_categ,'search_categ'); - $moreforfilter.='           '; + $moreforfilter = ''; + if (!empty($conf->categorie->enabled)) { + $moreforfilter .= $langs->trans('Categories') . ': '; + $moreforfilter .= $htmlother->select_categories(0, + $search_categ, + 'search_categ' + ); + $moreforfilter .= '           '; } - if ($moreforfilter) - { + if ($moreforfilter) { print ''; print ''; } - $param=(isset($type)?"&type=$type":"")."&fourn_id=$fourn_id&snom=$snom&sref=$sref"; + $param = (isset($type)? '&type=$type' : ''); + $param .= '&fourn_id=$fourn_id&snom=$snom&sref=$sref'; // Lignes des titres - print ""; - print ""; - print_liste_field_titre($langs->trans("Ref"),"replenish.php", "p.ref",$param,"","",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Label"),"replenish.php", "p.label",$param,"","",$sortfield,$sortorder); - if (! empty($conf->service->enabled) && $type == 1) print_liste_field_titre($langs->trans("Duration"),"replenish.php", "p.duration",$param,"",'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("DesiredStock"),"replenish.php", "p.desiredstock",$param,"",'align="right"',$sortfield,$sortorder); + print ''; + print ''; + print_liste_field_titre($langs->trans('Ref'), + 'replenish.php', + 'p.ref', + $param, + '', + '', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('Label'), + 'replenish.php', + 'p.label', + $param, + '', + '', + $sortfield, + $sortorder + ); + if (!empty($conf->service->enabled) && $type == 1) { + print_liste_field_titre($langs->trans('Duration'), + 'replenish.php', + 'p.duration', + $param, + '', + 'align="center"', + $sortfield, + $sortorder + ); + } + print_liste_field_titre($langs->trans('DesiredStock'), + 'replenish.php', + 'p.desiredstock', + $param, + '', + 'align="right"', + $sortfield, + $sortorder + ); if($conf->global->USE_VIRTUAL_STOCK) { - print_liste_field_titre($langs->trans("VirtualStock"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('VirtualStock'), + 'replenish.php', + '', + $param, + '', + 'align="right"', + $sortfield, + $sortorder + ); } else { - print_liste_field_titre($langs->trans("PhysicalStock"),"replenish.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('PhysicalStock'), + 'replenish.php', + 'stock_physique', + $param, + '', + 'align="right"', + $sortfield, + $sortorder + ); } - print_liste_field_titre($langs->trans("StockToBuy"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Ordered"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Supplier"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('StockToBuy'), + 'replenish.php', + '', + $param, + '', + 'align="right"', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('Ordered'), + 'replenish.php', + '', + $param, + '', + 'align="right"', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('Supplier'), + 'replenish.php', + '', + $param, + '', + 'align="right"', + $sortfield, + $sortorder + ); print ''; - print "\n"; + print ''; // Lignes des champs de filtre print ''; print ''; print ''; print ''; - if (! empty($conf->service->enabled) && $type == 1) - { + if (!empty($conf->service->enabled) && $type == 1) { print ''; @@ -347,251 +438,366 @@ if ($resql) print ''; print ''; print ''; print ''; - $product_static=new Product($db); + $prod = new Product($db); - $var=True; - while ($i < min($num,$limit)) - { + $var = True; + while ($i < min($num, $limit)) { $objp = $db->fetch_object($resql); - if($conf->global->STOCK_SUPPORTS_SERVICES || $objp->fk_product_type == 0){ + if($conf->global->STOCK_SUPPORTS_SERVICES + || $objp->fk_product_type == 0) { // Multilangs - if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active - { - $sql = "SELECT label"; - $sql.= " FROM ".MAIN_DB_PREFIX."product_lang"; - $sql.= " WHERE fk_product=".$objp->rowid; - $sql.= " AND lang='". $langs->getDefaultLang() ."'"; - $sql.= " LIMIT 1"; + if(! empty($conf->global->MAIN_MULTILANGS)) { + $sql = 'SELECT label'; + $sql .= ' FROM ' . MAIN_DB_PREFIX . 'product_lang'; + $sql .= ' WHERE fk_product = ' . $objp->rowid; + $sql .= ' AND lang = "' . $langs->getDefaultLang() . '"'; + $sql .= ' LIMIT 1'; $result = $db->query($sql); - if ($result) - { + if($result) { $objtp = $db->fetch_object($result); - if (! empty($objtp->label)) $objp->label = $objtp->label; + if (!empty($objtp->label)) { + $objp->label = $objtp->label; + } } } - $var=!$var; - print ''; - print ''; + $var =! $var; + print ''; + print ''; print ''; - print ''; - print ''; + print ''; + print ''; - if (! empty($conf->service->enabled) && $type == 1) - { + if(!empty($conf->service->enabled) && $type == 1) { print ''; } - print ''; + print ''; print ''; //depending on conf, use either physical stock or //virtual stock to compute the stock to buy value $stocktobuy = $objp->desiredstock - $stock; print ''; - print ''; + print ''; print ''; $form = new Form($db); - print ''; + print ''; print ''; - print "\n"; + print ""; } $i++; } print "
'; print $moreforfilter; print '
 
  
 '; - print ''; + print ''; print ''; - print ''; + print ''; print ''; print ' '; print '  '; - print ''; - print ''; + print ''; + print ''; print '
'; - $product_static->ref=$objp->ref; - $product_static->id=$objp->rowid; - $product_static->type=$objp->fk_product_type; - print $product_static->getNomUrl(1,'',16); + $prod->ref = $objp->ref; + $prod->id = $objp->rowid; + $prod->type = $objp->fk_product_type; + print $prod->getNomUrl(1, '', 16); print ''.$objp->label.'' . $objp->label . ''; - if (preg_match('/([0-9]+)y/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationYear"); - elseif (preg_match('/([0-9]+)m/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationMonth"); - elseif (preg_match('/([0-9]+)d/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationDay"); - else print $objp->duration; + if(preg_match('/([0-9]+)y/i', $objp->duration, $regs)) { + print $regs[1] . ' ' . $langs->trans('DurationYear'); + } + else if(preg_match('/([0-9]+)m/i', $objp->duration, $regs)) { + print $regs[1] . ' ' . $langs->trans('DurationMonth'); + } + else if(preg_match('/([0-9]+)d/i', $objp->duration, $regs)) { + print $regs[1] . ' ' . $langs->trans('DurationDay'); + } + else { + print $objp->duration; + } print ''.$objp->desiredstock.'' . $objp->desiredstock . ''; - if(!$objp->stock_physique) $objp->stock_physique = 0; - if($conf->global->USE_VIRTUAL_STOCK){ - $product_static->fetch($product_static->id); - $result=$product_static->load_stats_commande(0,'1,2'); - if ($result < 0) dol_print_error($db,$product_static->error); - $stock_commande_client = $product_static->stats_commande['qty']; - $result=$product_static->load_stats_commande_fournisseur(0,'3'); - if ($result < 0) dol_print_error($db,$product_static->error); - $stock_commande_fournisseur = $product_static->stats_commande_fournisseur['qty']; + if(!$objp->stock_physique) { + $objp->stock_physique = 0; + } + if($conf->global->USE_VIRTUAL_STOCK) { + $prod->fetch($prod->id); + $result=$prod->load_stats_commande(0, '1,2'); + if ($result < 0) { + dol_print_error($db, $prod->error); + } + $stock_commande_client = $prod->stats_commande['qty']; + $result=$prod->load_stats_commande_fournisseur(0, '3'); + if ($result < 0) { + dol_print_error($db,$prod->error); + } + $stock_commande_fournisseur = $prod->stats_commande_fournisseur['qty']; $stock = $objp->stock_physique - $stock_commande_client + $stock_commande_fournisseur; } - else{ + else { $stock = $objp->stock_physique; } - if ($objp->seuil_stock_alerte && ($stock < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; + if ($objp->seuil_stock_alerte + && ($stock < $objp->seuil_stock_alerte)) { + $warn = $langs->trans('StockTooLow'); + print img_warning($warn) . ' '; + } print $stock; print ''.$stocktobuy.''; - print ordered($product_static->id); + print ordered($prod->id); print ''.$form->select_product_fourn_price($product_static->id, "fourn".$i).''; + print $form->select_product_fourn_price($prod->id, + "fourn".$i); + print ' 
"; print ''; - print ''; - print '
'; + print ''; + $valid = $langs->trans("Validate"); + print ''; + print ''; print '
'; - if ($num > $conf->liste_limit) - { - if ($sref || $snom || $sall || GETPOST('search')) - { - print_barre_liste('', $page, "replenish.php", "&sref=".$sref."&snom=".$snom."&sall=".$sall, $sortfield, $sortorder,'',$num, 0, ''); + if ($num > $conf->liste_limit) { + if ($sref || $snom || $sall || GETPOST('search')) { + print_barre_liste('', + $page, + 'replenish.php', + '&sref=' . $sref . '&snom=' . $snom . '&sall=' . $sall, + $sortfield, + $sortorder, + '', + $num, + 0, + '' + ); } - else - { - print_barre_liste('', $page, "replenish.php", "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":""), $sortfield, $sortorder,'',$num, 0, ''); + else { + print_barre_liste('', + $page, + 'replenish.php', + "&sref=$sref&snom=$snom&fourn_id=$fourn_id" . (isset($type)?"&type=$type":""), + $sortfield, + $sortorder, + '', + $num, + 0, + '' + ); } } $db->free($resql); } -else -{ +else { dol_print_error($db); } -$commandestatic=new CommandeFournisseur($db); -$sref=GETPOST('search_ref'); -$snom=GETPOST('search_nom'); -$suser=GETPOST('search_user'); -$sttc=GETPOST('search_ttc'); -$sall=GETPOST('search_all'); +$commandestatic = new CommandeFournisseur($db); +$sref = GETPOST('search_ref'); +$snom = GETPOST('search_nom'); +$suser = GETPOST('search_user'); +$sttc = GETPOST('search_ttc'); +$sall = GETPOST('search_all'); -$page = GETPOST('page','int'); +$page = GETPOST('page', 'int'); -$sortorder="DESC"; -$sortfield="cf.date_creation"; +$sortorder = 'DESC'; +$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, cf.fk_user_author,"; -$sql.= " 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.= ")"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON cf.fk_user_author = u.rowid"; -$sql.= " WHERE cf.fk_soc = s.rowid "; -$sql.= " AND cf.entity = ".$conf->entity; -$sql.= " AND cf.source = 42"; -$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)."%'"; +$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'; } -if ($snom) -{ - $sql.= " AND s.nom LIKE '%".$db->escape($snom)."%'"; +$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; +$sql .= ' AND cf.source = 42'; +$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 ($suser) -{ - $sql.= " AND u.login LIKE '%".$db->escape($suser)."%'"; +if ($sref) { + $sql .= ' AND cf.ref LIKE "%' . $db->escape($sref) . '%"'; } -if ($sttc) -{ - $sql .= " AND total_ttc = ".price2num($sttc); +if ($snom) { + $sql .= ' AND s.nom LIKE "%' . $db->escape($snom) . '%"'; } -if ($sall) -{ - $sql.= " AND (cf.ref LIKE '%".$db->escape($sall)."%' OR cf.note LIKE '%".$db->escape($sall)."%')"; +if ($suser) { + $sql .= ' AND u.login LIKE "%' . $db->escape($suser) . '%"'; +} +if ($sttc) { + $sql .= ' AND total_ttc = ' . price2num($sttc); +} +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 ($socid) $sql.= " AND s.rowid = ".$socid; if (GETPOST('statut')) { - $sql .= " AND fk_statut =".GETPOST('statut'); + $sql .= ' AND fk_statut = ' . GETPOST('statut'); } $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset); $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { - $num = $db->num_rows($resql); - $i = 0; + $num = $db->num_rows($resql); + $i = 0; - print_barre_liste($langs->trans('ReplenishmentOrders'), $page, "replenish.php", "", $sortfield, $sortorder, '', $num); - print '
'; - print ''; - print ''; - print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("OrderCreation"),$_SERVER["PHP_SELF"],"","","",'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"","","",'align="right"',$sortfield,$sortorder); - print "\n"; + print_barre_liste($langs->trans('ReplenishmentOrders'), + $page, + 'replenish.php', + '', + $sortfield, + $sortorder, + '', + $num + ); + print ''; + print '
'; + print ''; + print_liste_field_titre($langs->trans('Ref'), + $_SERVER['PHP_SELF'], + '', + '', + '', + '', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('Company'), + $_SERVER['PHP_SELF'], + '', + '', + '', + '', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('Author'), + $_SERVER['PHP_SELF'], + '', + '', + '', + '', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('AmountTTC'), + $_SERVER['PHP_SELF'], + '', + '', + '', + '', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('OrderCreation'), + $_SERVER['PHP_SELF'], + '', + '', + '', + 'align="center"', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('Status'), + $_SERVER['PHP_SELF'], + '', + '', + '', + 'align="right"', + $sortfield, + $sortorder + ); + print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + $var = true; + $userstatic = new User($db); - $var=true; + while($i < min($num,$conf->liste_limit)) { + $obj = $db->fetch_object($resql); + $var = !$var; - $userstatic = new User($db); + print ""; + // Ref + print ''.""; - while ($i < min($num,$conf->liste_limit)) - { - $obj = $db->fetch_object($resql); - $var=!$var; + // Company + print ''.""; - print ""; + // Author + $userstatic->id = $obj->fk_user_author; + $userstatic->login = $obj->login; + print ''; - // Ref - print ''."\n"; + // Amount + print ''; - // Company - print ''."\n"; + // Date + print ''; - // Author - $userstatic->id=$obj->fk_user_author; - $userstatic->login=$obj->login; - print ""; + // Statut + print ''; - // Amount - print '"; + print ''; + $i++; + } + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $src = DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/search.png'; + $value = dol_escape_htmltag($langs->trans('Search')); + print ''; + print '
'; - print ''; - print '
'; + $href = DOL_URL_ROOT . '/fourn/commande/fiche.php?id=' . $obj->rowid; + print ''; + print img_object($langs->trans('ShowOrder'), 'order') . ' ' . $obj->ref; + print ''; + $href = DOL_URL_ROOT . '/fourn/fiche.php?socid=' . $obj->socid; + print ''; + print img_object($langs->trans('ShowCompany'), 'company') . ' ' . $obj->nom; + print '
'; + if ($userstatic->id) { + print $userstatic->getLoginUrl(1); + } + else { + print ' '; + } + print ''.img_object($langs->trans("ShowOrder"),"order").' '.$obj->ref.''; + print price($obj->total_ttc); + print ''.img_object($langs->trans("ShowCompany"),"company").' '; - print $obj->nom.''; + if ($obj->dc) { + print dol_print_date($db->jdate($obj->dc), 'day'); + } + else { + print '-'; + } + print '"; - if ($userstatic->id) print $userstatic->getLoginUrl(1); - else print " "; - print "'; + print $commandestatic->LibStatut($obj->fk_statut, 5); + print ''.price($obj->total_ttc)."
'; + print '
'; - // Date - print ""; - if ($obj->dc) - { - print dol_print_date($db->jdate($obj->dc),"day"); - } - else - { - print "-"; - } - print ''; - - // Statut - print ''.$commandestatic->LibStatut($obj->fk_statut, 5).''; - - print "\n"; - $i++; - } - print "\n"; - print "\n"; - - $db->free($resql); + $db->free($resql); } llxFooter(); From 8517706ec244111df008775a892e09999ebcbc9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 11 Jun 2013 15:55:43 +0200 Subject: [PATCH 28/92] typo --- htdocs/product/stock/replenish.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 00c514a899f..43727a3a8a8 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -115,6 +115,7 @@ if (! empty($_POST['button_removefilter_x'])) { //orders creation if($action == 'order') { $linecount = GETPOST('linecount', 'int'); + unset($_POST['linecount']); if($linecount > 0) { $suppliers = array(); for($i = 0; $i < $linecount; $i++) { @@ -151,7 +152,9 @@ if($action == 'order') { 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; @@ -535,7 +538,7 @@ if ($resql) { $form = new Form($db); print ''; print $form->select_product_fourn_price($prod->id, - "fourn".$i); + 'fourn' . $i); print ''; print ' '; print ""; From e9ef91cdbc5dcc068876d4b53cbddd2f2c6798f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 11 Jun 2013 16:07:47 +0200 Subject: [PATCH 29/92] typo --- htdocs/product/stock/replenish.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 43727a3a8a8..7738f757d85 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -326,7 +326,7 @@ if ($resql) { } $param = (isset($type)? '&type=$type' : ''); - $param .= '&fourn_id=$fourn_id&snom=$snom&sref=$sref'; + $param .= '&fourn_id=' . $fourn_id . '&snom='. $snom . '&sref=' . $sref; // Lignes des titres print ''; From a637127599ebbf6e162ed7dbb50c8f14ec8c2c0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 11 Jun 2013 18:31:27 +0200 Subject: [PATCH 30/92] Split the page in two tabs, filters and pagination should work now --- htdocs/product/stock/replenish.php | 225 +------------------ htdocs/product/stock/replenishorders.php | 269 +++++++++++++++++++++++ 2 files changed, 278 insertions(+), 216 deletions(-) create mode 100644 htdocs/product/stock/replenishorders.php diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 7738f757d85..465ffd9d11a 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -266,7 +266,14 @@ if ($resql) { $helpurl .= 'ES:Módulo_Stocks'; $texte = $langs->trans('Replenishment'); llxHeader('', $title, $helpurl, $texte); - + $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', $title, 0, 'stock'); if ($sref || $snom || $sall || GETPOST('search')) { print_barre_liste($texte, $page, @@ -305,7 +312,7 @@ if ($resql) { print ''; print ''; print ''; - + //print ''; print ''; // Filter on categories @@ -589,220 +596,6 @@ else { dol_print_error($db); } -$commandestatic = new CommandeFournisseur($db); -$sref = GETPOST('search_ref'); -$snom = GETPOST('search_nom'); -$suser = GETPOST('search_user'); -$sttc = GETPOST('search_ttc'); -$sall = GETPOST('search_all'); - -$page = GETPOST('page', 'int'); - -$sortorder = 'DESC'; -$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; -$sql .= ' AND cf.source = 42'; -$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 total_ttc = ' . price2num($sttc); -} -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')) -{ - $sql .= ' AND fk_statut = ' . GETPOST('statut'); -} - -$sql .= " ORDER BY $sortfield $sortorder " . $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, - 'replenish.php', - '', - $sortfield, - $sortorder, - '', - $num - ); - print ''; - print '
'; - print ''; - print_liste_field_titre($langs->trans('Ref'), - $_SERVER['PHP_SELF'], - '', - '', - '', - '', - $sortfield, - $sortorder - ); - print_liste_field_titre($langs->trans('Company'), - $_SERVER['PHP_SELF'], - '', - '', - '', - '', - $sortfield, - $sortorder - ); - print_liste_field_titre($langs->trans('Author'), - $_SERVER['PHP_SELF'], - '', - '', - '', - '', - $sortfield, - $sortorder - ); - print_liste_field_titre($langs->trans('AmountTTC'), - $_SERVER['PHP_SELF'], - '', - '', - '', - '', - $sortfield, - $sortorder - ); - print_liste_field_titre($langs->trans('OrderCreation'), - $_SERVER['PHP_SELF'], - '', - '', - '', - 'align="center"', - $sortfield, - $sortorder - ); - print_liste_field_titre($langs->trans('Status'), - $_SERVER['PHP_SELF'], - '', - '', - '', - 'align="right"', - $sortfield, - $sortorder - ); - print ''; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - $var = true; - $userstatic = new User($db); - - while($i < min($num,$conf->liste_limit)) { - $obj = $db->fetch_object($resql); - $var = !$var; - - print ""; - // Ref - print ''.""; - - // Company - print ''.""; - - // Author - $userstatic->id = $obj->fk_user_author; - $userstatic->login = $obj->login; - print ''; - - // Amount - print ''; - - // Date - print ''; - - // Statut - print ''; - - print ''; - $i++; - } - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - $src = DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/search.png'; - $value = dol_escape_htmltag($langs->trans('Search')); - print ''; - print '
'; - $href = DOL_URL_ROOT . '/fourn/commande/fiche.php?id=' . $obj->rowid; - print ''; - print img_object($langs->trans('ShowOrder'), 'order') . ' ' . $obj->ref; - print ''; - $href = DOL_URL_ROOT . '/fourn/fiche.php?socid=' . $obj->socid; - print ''; - print img_object($langs->trans('ShowCompany'), 'company') . ' ' . $obj->nom; - print ''; - if ($userstatic->id) { - print $userstatic->getLoginUrl(1); - } - else { - print ' '; - } - print ''; - print price($obj->total_ttc); - print ''; - if ($obj->dc) { - print dol_print_date($db->jdate($obj->dc), 'day'); - } - else { - print '-'; - } - print ''; - print $commandestatic->LibStatut($obj->fk_statut, 5); - print '
'; - print ''; - - $db->free($resql); -} - llxFooter(); $db->close(); ?> diff --git a/htdocs/product/stock/replenishorders.php b/htdocs/product/stock/replenishorders.php new file mode 100644 index 00000000000..c06cf405ffa --- /dev/null +++ b/htdocs/product/stock/replenishorders.php @@ -0,0 +1,269 @@ + + * + * 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'; + +$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('Replenishment'); +$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, 'replenishorders', $langs->trans("Replenishment"), 0, 'stock'); +$commandestatic = new CommandeFournisseur($db); +$sref = GETPOST('search_ref'); +$snom = GETPOST('search_nom'); +$suser = GETPOST('search_user'); +$sttc = GETPOST('search_ttc'); +$sall = GETPOST('search_all'); + +$page = GETPOST('page', 'int'); + +$sortorder = GETPOST('sortorder'); +$sortfield = GETPOST('sortfield'); +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; +$sql .= ' AND cf.source = 42'; +$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 ($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')) +{ + $sql .= ' AND fk_statut = ' . GETPOST('statut'); +} + +$sql .= " ORDER BY $sortfield $sortorder " . $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 + ); + print '
'; + print ''; + print ''; + print_liste_field_titre($langs->trans('Ref'), + $_SERVER['PHP_SELF'], + 'cf.ref', + '', + '', + '', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('Company'), + $_SERVER['PHP_SELF'], + 's.nom', + '', + '', + '', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('Author'), + $_SERVER['PHP_SELF'], + 'u.login', + '', + '', + '', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('AmountTTC'), + $_SERVER['PHP_SELF'], + 'cf.total_ttc', + '', + '', + '', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('OrderCreation'), + $_SERVER['PHP_SELF'], + 'cf.date_creation', + '', + '', + 'align="center"', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('Status'), + $_SERVER['PHP_SELF'], + 'cf.fk_statut', + '', + '', + 'align="right"', + $sortfield, + $sortorder + ); + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $var = true; + $userstatic = new User($db); + + while($i < min($num,$conf->liste_limit)) { + $obj = $db->fetch_object($resql); + $var = !$var; + + print ""; + // Ref + print ''.""; + + // Company + print ''.""; + + // Author + $userstatic->id = $obj->fk_user_author; + $userstatic->login = $obj->login; + print ''; + + // Amount + print ''; + + // Date + print ''; + + // Statut + print ''; + + print ''; + $i++; + } + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $src = DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/search.png'; + $value = dol_escape_htmltag($langs->trans('Search')); + print ''; + print '
'; + $href = DOL_URL_ROOT . '/fourn/commande/fiche.php?id=' . $obj->rowid; + print ''; + print img_object($langs->trans('ShowOrder'), 'order') . ' ' . $obj->ref; + print ''; + $href = DOL_URL_ROOT . '/fourn/fiche.php?socid=' . $obj->socid; + print ''; + print img_object($langs->trans('ShowCompany'), 'company') . ' ' . $obj->nom; + print ''; + if ($userstatic->id) { + print $userstatic->getLoginUrl(1); + } + else { + print ' '; + } + print ''; + print price($obj->total_ttc); + print ''; + if ($obj->dc) { + print dol_print_date($db->jdate($obj->dc), 'day'); + } + else { + print '-'; + } + print ''; + print $commandestatic->LibStatut($obj->fk_statut, 5); + print '
'; + print '
'; + + $db->free($resql); +} + +llxFooter(); +$db->close(); +?> From 4c50b23b40b4ea50d64447cd3eb7edbba9169e16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 11 Jun 2013 18:47:19 +0200 Subject: [PATCH 31/92] message when succeeds/fails to create orders --- htdocs/langs/en_US/orders.lang | 2 ++ htdocs/langs/fr_FR/orders.lang | 2 ++ htdocs/product/stock/replenish.php | 6 +++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/orders.lang b/htdocs/langs/en_US/orders.lang index 648089a3268..65ce69d1cf4 100644 --- a/htdocs/langs/en_US/orders.lang +++ b/htdocs/langs/en_US/orders.lang @@ -163,3 +163,5 @@ CloseProcessedOrdersAutomatically=Classify "Processed" all selected orders. MenuOrdersToBill2=Billables orders OrderCreation=Order creation Ordered=Ordered +OrderCreated=Your orders have been created +OrderFail=An error happened during your orders creation diff --git a/htdocs/langs/fr_FR/orders.lang b/htdocs/langs/fr_FR/orders.lang index 187f948bd66..0bdb428c92f 100644 --- a/htdocs/langs/fr_FR/orders.lang +++ b/htdocs/langs/fr_FR/orders.lang @@ -163,3 +163,5 @@ CloseProcessedOrdersAutomatically=Classer automatiquement à "Traitées" les com MenuOrdersToBill2=Commandes à facturer OrderCreation=Date de création Ordered=Commandé +OrderCreated=Vos commandes ont été générées +OrderFail=Une erreur s'est produite pendant la création de vos commandes diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 465ffd9d11a..368b12141bf 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -171,16 +171,20 @@ if($action == 'order') { $id = $order->create($user); if($id < 0) { //error stuff + $fail++; + setEventMessage($langs->trans('OrderFail'), 'errors'); } $i++; } + if(!$fail) { + setEventMessage($langs->trans('OrderCreated'), 'mesgs'); + } } } /* * View */ - $htmlother=new FormOther($db); $title=$langs->trans('Replenishment'); From 2c82484d454964d94aac88f96ace830ebf97521d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 12 Jun 2013 11:55:28 +0200 Subject: [PATCH 32/92] reformat --- htdocs/product/stock/replenish.php | 40 +++++++++++++++------ htdocs/product/stock/replenishorders.php | 44 +++++++++++++++--------- 2 files changed, 57 insertions(+), 27 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 368b12141bf..2e0335a9bde 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -34,9 +34,12 @@ $langs->load("stocks"); $langs->load("orders"); // Security check -if ($user->societe_id) $socid=$user->societe_id; +if ($user->societe_id) { + $socid = $user->societe_id; +} $result=restrictedArea($user,'produit|service'); +//checks if a product has been ordered function ordered($product_id) { global $db; $sql = 'SELECT DISTINCT cfd.fk_product, SUM(cfd.qty) from '; @@ -58,7 +61,7 @@ function ordered($product_id) { } } else { - $error=$db->lasterror(); + $error = $db->lasterror(); dol_print_error($db); dol_syslog('replenish.php: ' . $error, LOG_ERROR); return $langs->trans('error'); @@ -77,8 +80,14 @@ $tobuy = GETPOST('tobuy'); $sortfield = GETPOST('sortfield','alpha'); $sortorder = GETPOST('sortorder','alpha'); $page = GETPOST('page','int'); -if (! $sortfield) $sortfield = 'stock_physique'; -if (! $sortorder) $sortorder = 'ASC'; + +if (!$sortfield) { + $sortfield = 'stock_physique'; +} + +if (!$sortorder) { + $sortorder = 'ASC'; +} $limit = $conf->liste_limit; $offset = $limit * $page ; @@ -279,10 +288,12 @@ if ($resql) { $head[1][2] = 'replenishorders'; dol_fiche_head($head, 'replenish', $title, 0, 'stock'); if ($sref || $snom || $sall || GETPOST('search')) { + $filters = '&sref=' . $sref . '&snom=' . $snom; + $filters .= '&sall=' . $sall; print_barre_liste($texte, $page, 'replenish.php', - '&sref=' . $sref . '&snom=' . $snom . '&sall=' . $sall, + $filters, $sortfield, $sortorder, '', @@ -290,10 +301,13 @@ if ($resql) { ); } else { + $filters = '&sref=' . $sref . '&snom=' . $snom; + $filters .= '&fourn_id=' . $fourn_id; + $filters .= (isset($type)?'&type=' . $type:''); print_barre_liste($texte, $page, 'replenish.php', - '&sref=$sref&snom=$snom&fourn_id=$fourn_id' . (isset($type)?'&type=$type':''), + $filters, $sortfield, $sortorder, '', @@ -336,8 +350,9 @@ if ($resql) { print ''; } - $param = (isset($type)? '&type=$type' : ''); - $param .= '&fourn_id=' . $fourn_id . '&snom='. $snom . '&sref=' . $sref; + $param = (isset($type)? '&type=' . $type : ''); + $param .= '&fourn_id=' . $fourn_id . '&snom='. $snom; + $param .= '&sref=' . $sref; // Lignes des titres print ''; @@ -566,10 +581,12 @@ if ($resql) { if ($num > $conf->liste_limit) { if ($sref || $snom || $sall || GETPOST('search')) { + $filters = '&sref=' . $sref . '&snom=' . $snom; + $filters .= '&sall=' . $sall; print_barre_liste('', $page, 'replenish.php', - '&sref=' . $sref . '&snom=' . $snom . '&sall=' . $sall, + $filters, $sortfield, $sortorder, '', @@ -579,10 +596,13 @@ if ($resql) { ); } else { + $filters = '&sref=' . $sref . '&snom=' . $snom; + $filters .= '&fourn_id=' . $fourn_id; + $filters .= (isset($type)? '&type=' . $type : ''); print_barre_liste('', $page, 'replenish.php', - "&sref=$sref&snom=$snom&fourn_id=$fourn_id" . (isset($type)?"&type=$type":""), + $filters, $sortfield, $sortorder, '', diff --git a/htdocs/product/stock/replenishorders.php b/htdocs/product/stock/replenishorders.php index c06cf405ffa..d7b506dca77 100644 --- a/htdocs/product/stock/replenishorders.php +++ b/htdocs/product/stock/replenishorders.php @@ -47,7 +47,10 @@ $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, 'replenishorders', $langs->trans("Replenishment"), 0, 'stock'); +dol_fiche_head($head, 'replenishorders', + $langs->trans("Replenishment"), + 0, + 'stock'); $commandestatic = new CommandeFournisseur($db); $sref = GETPOST('search_ref'); $snom = GETPOST('search_nom'); @@ -59,17 +62,27 @@ $page = GETPOST('page', 'int'); $sortorder = GETPOST('sortorder'); $sortfield = GETPOST('sortfield'); -if(!$sortorder) $sortorder = 'DESC'; -if(!$sortfield) $sortfield = 'cf.date_creation'; + +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 '; @@ -100,19 +113,18 @@ if ($socid) { $sql .= ' AND s.rowid = ' . $socid; } -if (GETPOST('statut')) -{ - $sql .= ' AND fk_statut = ' . GETPOST('statut'); +if (GETPOST('statut')) { + $sql .= ' AND fk_statut = ' . GETPOST('statut'); } -$sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset); +$sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder . ' '; +$sql .= $db->plimit($conf->liste_limit+1, $offset); $resql = $db->query($sql); -if ($resql) { +if ($resql) { $num = $db->num_rows($resql); $i = 0; - print_barre_liste($langs->trans('ReplenishmentOrders'), $page, 'replenishorders.php', @@ -197,7 +209,7 @@ if ($resql) { print ''; $src = DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/search.png'; $value = dol_escape_htmltag($langs->trans('Search')); - print ''; + print ''; print ''; print ''; @@ -214,32 +226,32 @@ if ($resql) { $href = DOL_URL_ROOT . '/fourn/commande/fiche.php?id=' . $obj->rowid; print ''; print img_object($langs->trans('ShowOrder'), 'order') . ' ' . $obj->ref; - print ''.""; + print ''; // Company print ''; $href = DOL_URL_ROOT . '/fourn/fiche.php?socid=' . $obj->socid; print ''; - print img_object($langs->trans('ShowCompany'), 'company') . ' ' . $obj->nom; - print ''.""; + print img_object($langs->trans('ShowCompany'), 'company') . ' '; + print $obj->nom . ''; // Author $userstatic->id = $obj->fk_user_author; $userstatic->login = $obj->login; print ''; + if ($userstatic->id) { print $userstatic->getLoginUrl(1); } else { print ' '; } + print ''; - // Amount print ''; print price($obj->total_ttc); print ''; - // Date print ''; if ($obj->dc) { @@ -249,12 +261,10 @@ if ($resql) { print '-'; } print ''; - // Statut print ''; print $commandestatic->LibStatut($obj->fk_statut, 5); print ''; - print ''; $i++; } From 810743cddc79d72f29408c7bd2749056cb5392fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 12 Jun 2013 11:58:55 +0200 Subject: [PATCH 33/92] fixed research calling replenish.php --- htdocs/product/stock/replenishorders.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/stock/replenishorders.php b/htdocs/product/stock/replenishorders.php index d7b506dca77..19223464a5d 100644 --- a/htdocs/product/stock/replenishorders.php +++ b/htdocs/product/stock/replenishorders.php @@ -134,7 +134,7 @@ if ($resql) { '', $num ); - print '
'; + print ''; print ''; print ''; print_liste_field_titre($langs->trans('Ref'), From 6e55d1c471e006cee75095d7b11019c3547dd7f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 12 Jun 2013 12:01:22 +0200 Subject: [PATCH 34/92] fixed success message showing up even when you don't create orders --- htdocs/product/stock/replenish.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 2e0335a9bde..058f7e2e1ff 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -185,7 +185,7 @@ if($action == 'order') { } $i++; } - if(!$fail) { + if(!$fail && $id) { setEventMessage($langs->trans('OrderCreated'), 'mesgs'); } } From 89ceafaef5a3b932b6b39694c9206ebe9d3e2fd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 12 Jun 2013 14:49:43 +0200 Subject: [PATCH 35/92] research by date --- htdocs/product/stock/replenishorders.php | 40 ++++++++++++++---------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/htdocs/product/stock/replenishorders.php b/htdocs/product/stock/replenishorders.php index 19223464a5d..fd2939d0bba 100644 --- a/htdocs/product/stock/replenishorders.php +++ b/htdocs/product/stock/replenishorders.php @@ -57,7 +57,7 @@ $snom = GETPOST('search_nom'); $suser = GETPOST('search_user'); $sttc = GETPOST('search_ttc'); $sall = GETPOST('search_all'); - +$sdate = GETPOST('search_date'); $page = GETPOST('page', 'int'); $sortorder = GETPOST('sortorder'); @@ -78,7 +78,7 @@ $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) { +if(!$user->rights->societe->client->voir && !$socid) { $sql.= ', ' . MAIN_DB_PREFIX . 'societe_commerciaux as sc'; } @@ -90,30 +90,35 @@ $sql .= ' AND cf.entity = ' . $conf->entity; $sql .= ' AND cf.source = 42'; $sql .= ' AND cf.fk_statut < 5'; -if (!$user->rights->societe->client->voir && !$socid) { +if(!$user->rights->societe->client->voir && !$socid) { $sql .= ' AND s.rowid = sc.fk_soc AND sc.fk_user = ' . $user->id; } -if ($sref) { +if($sref) { $sql .= ' AND cf.ref LIKE "%' . $db->escape($sref) . '%"'; } -if ($snom) { +if($snom) { $sql .= ' AND s.nom LIKE "%' . $db->escape($snom) . '%"'; } -if ($suser) { +if($suser) { $sql .= ' AND u.login LIKE "%' . $db->escape($suser) . '%"'; } -if ($sttc) { +if($sttc) { $sql .= ' AND cf.total_ttc = ' . price2num($sttc); } -if ($sall) { +if($sdate) { + $datearray = explode('/', $sdate); + $date = date('Y-m-d', mktime(0,0,0, $datearray[1], $datearray[0], $datearray[2])); + $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) { +if($socid) { $sql .= ' AND s.rowid = ' . $socid; } -if (GETPOST('statut')) { +if(GETPOST('statut')) { $sql .= ' AND fk_statut = ' . GETPOST('statut'); } @@ -121,7 +126,7 @@ $sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder . ' '; $sql .= $db->plimit($conf->liste_limit+1, $offset); $resql = $db->query($sql); -if ($resql) { +if($resql) { $num = $db->num_rows($resql); $i = 0; @@ -178,7 +183,7 @@ if ($resql) { 'cf.date_creation', '', '', - 'align="center"', + '', $sortfield, $sortorder ); @@ -206,7 +211,10 @@ if ($resql) { print ''; - print ''; + print ''; // Amount - print ''; // Date - print ''; print ''; print ""; From 2900227236e3bcbadfc1e593f2ca9af52d1a2e12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 12 Jun 2013 14:56:29 +0200 Subject: [PATCH 37/92] redirect user after orders creation --- htdocs/product/stock/replenish.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index a4d2d2b96d2..3a6cc211f3f 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -187,6 +187,8 @@ if($action == 'order') { } if(!$fail && $id) { setEventMessage($langs->trans('OrderCreated'), 'mesgs'); + header('Location: replenishorders.php'); + exit; } } } From 2a4ce81f449d5dc26af0738bee17c5a39216a2a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 12 Jun 2013 15:12:27 +0200 Subject: [PATCH 38/92] changed valid button label, position and look --- htdocs/langs/en_US/orders.lang | 1 + htdocs/langs/fr_FR/orders.lang | 1 + htdocs/product/stock/replenish.php | 5 +++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/htdocs/langs/en_US/orders.lang b/htdocs/langs/en_US/orders.lang index 65ce69d1cf4..9a75dc90d92 100644 --- a/htdocs/langs/en_US/orders.lang +++ b/htdocs/langs/en_US/orders.lang @@ -165,3 +165,4 @@ OrderCreation=Order creation Ordered=Ordered OrderCreated=Your orders have been created OrderFail=An error happened during your orders creation +CreateOrders=Create orders diff --git a/htdocs/langs/fr_FR/orders.lang b/htdocs/langs/fr_FR/orders.lang index 0bdb428c92f..021171ce6d1 100644 --- a/htdocs/langs/fr_FR/orders.lang +++ b/htdocs/langs/fr_FR/orders.lang @@ -165,3 +165,4 @@ OrderCreation=Date de création Ordered=Commandé OrderCreated=Vos commandes ont été générées OrderFail=Une erreur s'est produite pendant la création de vos commandes +CreateOrders=Créer commandes diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 3a6cc211f3f..75f0f66a1a4 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -574,10 +574,11 @@ if ($resql) { $i++; } print "
'; print ''; print ''; + print ''; + print ''; + print ''; $src = DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/search.png'; $value = dol_escape_htmltag($langs->trans('Search')); print ''; @@ -240,7 +248,7 @@ if ($resql) { $userstatic->login = $obj->login; print ''; - if ($userstatic->id) { + if($userstatic->id) { print $userstatic->getLoginUrl(1); } else { @@ -249,11 +257,11 @@ if ($resql) { print ''; + print ''; print price($obj->total_ttc); print ''; + print ''; if ($obj->dc) { print dol_print_date($db->jdate($obj->dc), 'day'); } From 9dfa5c4218fde5ca54efc84a218ac71b6b698333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 12 Jun 2013 14:50:32 +0200 Subject: [PATCH 36/92] selects --- htdocs/core/class/html.form.class.php | 8 +------- htdocs/product/stock/replenish.php | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 6983865eac9..d908e243dfa 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1860,15 +1860,9 @@ class Form { $form.= ''; } - else if ($num == 1) { - $objp = $this->db->fetch_object($result); - $form = $objp->nom; - $form .= ''; - } else { - $form = ''; print $form->select_product_fourn_price($prod->id, - 'fourn' . $i); + 'fourn' . $i, 1); print ' 
"; + print ''; print ''; print '
'; - $valid = $langs->trans("Validate"); - print ''; + $value = $langs->trans("CreateOrders"); + print ''; print '
'; print '
'; From 9ad3f55da25c3ef49166f4ba6b53718f61924484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 12 Jun 2013 15:15:05 +0200 Subject: [PATCH 39/92] changed "to buy" to "to order" --- htdocs/langs/en_US/stocks.lang | 2 +- htdocs/langs/fr_FR/stocks.lang | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index a178c416fb3..63d0724fb29 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -89,7 +89,7 @@ SelectWarehouseForStockIncrease=Choose warehouse to use for stock increase NoStockAction=No stock action LastWaitingSupplierOrders=Orders waiting for receptions DesiredStock=Desired stock -StockToBuy=Stock to buy +StockToBuy=Stock to order Replenishment=Replenishment ReplenishmentOrders=Replenishment orders UseVirtualStock=Use virtual stock instead of physical stock diff --git a/htdocs/langs/fr_FR/stocks.lang b/htdocs/langs/fr_FR/stocks.lang index b7cbf9344ae..d40278b6d45 100644 --- a/htdocs/langs/fr_FR/stocks.lang +++ b/htdocs/langs/fr_FR/stocks.lang @@ -89,7 +89,7 @@ SelectWarehouseForStockIncrease=Sélectionner l'entrepôt à utiliser pour l'inc NoStockAction=Pas d'action sur l'entrepôt LastWaitingSupplierOrders=Commandes en attente de réception DesiredStock=Stock désiré -StockToBuy=Stock à acheter +StockToBuy=Stock à commander Replenishment=Réapprovisionnement ReplenishmentOrders=Commandes de réapprovisionnement UseVirtualStock=Utiliser le stock théorique à la place du stock physique From dbdaa379c850fac5743db5f36289fa23b2ba6f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 12 Jun 2013 15:22:46 +0200 Subject: [PATCH 40/92] reformat --- htdocs/product/stock/replenishorders.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/htdocs/product/stock/replenishorders.php b/htdocs/product/stock/replenishorders.php index fd2939d0bba..854d6b94f9f 100644 --- a/htdocs/product/stock/replenishorders.php +++ b/htdocs/product/stock/replenishorders.php @@ -47,7 +47,8 @@ $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, 'replenishorders', +dol_fiche_head($head, + 'replenishorders', $langs->trans("Replenishment"), 0, 'stock'); @@ -72,6 +73,7 @@ if(!$sortfield) { } $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"; @@ -106,8 +108,10 @@ if($sttc) { $sql .= ' AND cf.total_ttc = ' . price2num($sttc); } if($sdate) { - $datearray = explode('/', $sdate); - $date = date('Y-m-d', mktime(0,0,0, $datearray[1], $datearray[0], $datearray[2])); + $elts = explode('/', $sdate); + $date = date('Y-m-d', + mktime(0, 0, 0, $elts[1], $elts[0], $elts[2]) + ); $sql .= ' AND cf.date_creation LIKE "' . $date . '%"'; } if($sall) { From f0243646df8b0f147b6f1bb5129da4e95a44a927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 12 Jun 2013 18:13:34 +0200 Subject: [PATCH 41/92] code cleanup --- htdocs/product/stock/replenish.php | 129 +++++------------------ htdocs/product/stock/replenishorders.php | 4 +- 2 files changed, 26 insertions(+), 107 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 75f0f66a1a4..4404780abae 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -26,7 +26,6 @@ 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'; $langs->load("products"); @@ -73,8 +72,6 @@ $sref = GETPOST('sref'); $snom = GETPOST('snom'); $sall = GETPOST('sall'); $type = GETPOST('type','int'); -$sbarcode = GETPOST('sbarcode'); -$catid = GETPOST('catid','int'); $tobuy = GETPOST('tobuy'); $sortfield = GETPOST('sortfield','alpha'); @@ -82,7 +79,7 @@ $sortorder = GETPOST('sortorder','alpha'); $page = GETPOST('page','int'); if (!$sortfield) { - $sortfield = 'stock_physique'; + $sortfield = 'p.ref'; } if (!$sortorder) { @@ -91,32 +88,6 @@ if (!$sortorder) { $limit = $conf->liste_limit; $offset = $limit * $page ; -// Load sale and categ filters -$search_sale = GETPOST('search_sale'); -$search_categ = GETPOST('search_categ'); - -// Get object canvas -//(By default, this is not defined, so standard usage of dolibarr) -$canvas = GETPOST('canvas'); -$objcanvas = ''; -if (! empty($canvas)) { - require_once DOL_DOCUMENT_ROOT . '/core/class/canvas.class.php'; - $objcanvas = new Canvas($db,$action); - $objcanvas->getCanvas('product', 'list', $canvas); -} - -if (! empty($_POST['button_removefilter_x'])) { - $sref = ''; - $snom = ''; - $sall = ''; - $search_sale = ''; - $search_categ = ''; - $type = ''; - $catid = ''; -} - - - /* * Actions */ @@ -179,7 +150,6 @@ if($action == 'order') { } $id = $order->create($user); if($id < 0) { - //error stuff $fail++; setEventMessage($langs->trans('OrderFail'), 'errors'); } @@ -196,29 +166,20 @@ if($action == 'order') { /* * View */ -$htmlother=new FormOther($db); +$title = $langs->trans('Replenishment'); -$title=$langs->trans('Replenishment'); - -$sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price'; +$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'; -// need this table joined to the select in order to filter by categ -if ($search_categ) { - $sql.= ", " . MAIN_DB_PREFIX . "categorie_product as cp"; -} -$sql .= ') LEFT JOIN ' . MAIN_DB_PREFIX . 'product_fournisseur_price as pf'; +$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 ($search_categ) { // Join for the needed table to filter by categ - $sql .= ' AND p.rowid = cp.fk_product'; -} + if ($sall) { $sql .= ' AND (p.ref LIKE "%'.$db->escape($sall).'%" '; $sql .= 'OR p.label LIKE "%'.$db->escape($sall).'%" '; @@ -237,9 +198,6 @@ if (dol_strlen($type)) { if ($sref) { $sql .= ' AND p.ref LIKE "%' . $sref . '%"'; } -if ($sbarcode) { - $sql .= ' AND p.barcode LIKE "%' . $sbarcode . '%"'; -} if ($snom) { $sql .= ' AND p.label LIKE "%' . $db->escape($snom) . '%"'; } @@ -249,17 +207,10 @@ $sql .= ' AND p.tobuy = 1'; if (!empty($canvas)) { $sql .= ' AND p.canvas = "' . $db->escape($canvas) . '"'; } -if($catid) { - $sql .= ' AND cp.fk_categorie = ' . $catid; -} $sql .= ' AND p.rowid = pf.fk_product'; -// Insert categ filter -if ($search_categ) { - $sql .= ' AND cp.fk_categorie = ' . $db->escape($search_categ); -} -$sql .= ' GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price'; +$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'; @@ -279,8 +230,7 @@ if ($resql) { $helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|'; $helpurl .= 'ES:Módulo_Stocks'; - $texte = $langs->trans('Replenishment'); - llxHeader('', $title, $helpurl, $texte); + llxHeader('', $title, $helpurl, $title); $head = array(); $head[0][0] = DOL_URL_ROOT.'/product/stock/replenish.php'; $head[0][1] = $title; @@ -316,15 +266,6 @@ if ($resql) { $num); } - if (!empty($catid)) { - print '
'; - $c = new Categorie($db); - $c->fetch($catid); - $ways = $c->print_all_ways(' > ', 'product/replenish.php'); - print ' > ' . $ways[0] . '
'; - print '

'; - } - print '
'; print ''; print ''; @@ -332,25 +273,8 @@ if ($resql) { print ''; print ''; print ''; - //print ''; - print ''; - // Filter on categories - $moreforfilter = ''; - if (!empty($conf->categorie->enabled)) { - $moreforfilter .= $langs->trans('Categories') . ': '; - $moreforfilter .= $htmlother->select_categories(0, - $search_categ, - 'search_categ' - ); - $moreforfilter .= '           '; - } - if ($moreforfilter) { - print ''; - print ''; - } + print '
'; - print $moreforfilter; - print '
'; $param = (isset($type)? '&type=' . $type : ''); $param .= '&fourn_id=' . $fourn_id . '&snom='. $snom; @@ -398,27 +322,20 @@ if ($resql) { $sortorder ); if($conf->global->USE_VIRTUAL_STOCK) { - print_liste_field_titre($langs->trans('VirtualStock'), - 'replenish.php', - '', - $param, - '', - 'align="right"', - $sortfield, - $sortorder - ); + $stocklabel = $langs->trans('VirtualStock'); } else { - print_liste_field_titre($langs->trans('PhysicalStock'), - 'replenish.php', - 'stock_physique', - $param, - '', - 'align="right"', - $sortfield, - $sortorder - ); + $stocklabel = $langs->trans('PhysicalStock'); } + print_liste_field_titre($stocklabel, + 'replenish.php', + 'stock_physique', + $param, + '', + 'align="right"', + $sortfield, + $sortorder + ); print_liste_field_titre($langs->trans('StockToBuy'), 'replenish.php', '', @@ -470,7 +387,6 @@ if ($resql) { print ''; print ''; print ''; @@ -532,6 +448,7 @@ if ($resql) { $objp->stock_physique = 0; } if($conf->global->USE_VIRTUAL_STOCK) { + //compute virtual stock $prod->fetch($prod->id); $result=$prod->load_stats_commande(0, '1,2'); if ($result < 0) { @@ -566,7 +483,9 @@ if ($resql) { $form = new Form($db); print ''; print ''; print ""; diff --git a/htdocs/product/stock/replenishorders.php b/htdocs/product/stock/replenishorders.php index 854d6b94f9f..1a87736ef9e 100644 --- a/htdocs/product/stock/replenishorders.php +++ b/htdocs/product/stock/replenishorders.php @@ -45,11 +45,11 @@ $head[0][0] = DOL_URL_ROOT.'/product/stock/replenish.php'; $head[0][1] = $langs->trans('Replenishment'); $head[0][2] = 'replenish'; $head[1][0] = DOL_URL_ROOT.'/product/stock/replenishorders.php'; -$head[1][1] = $langs->trans("ReplenishmentOrders"); +$head[1][1] = $texte; $head[1][2] = 'replenishorders'; dol_fiche_head($head, 'replenishorders', - $langs->trans("Replenishment"), + $langs->trans('Replenishment'), 0, 'stock'); $commandestatic = new CommandeFournisseur($db); From 2f5f96dc13748d99c903440441bb2513094f3967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Thu, 13 Jun 2013 17:40:18 +0200 Subject: [PATCH 42/92] PSR coding style --- htdocs/product/stock/replenish.php | 266 +++++++++++------------ htdocs/product/stock/replenishorders.php | 149 +++++++------ 2 files changed, 201 insertions(+), 214 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 4404780abae..105fe45c739 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -39,30 +39,31 @@ if ($user->societe_id) { $result=restrictedArea($user,'produit|service'); //checks if a product has been ordered -function ordered($product_id) { +function ordered($product_id) +{ global $db; $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 cf.source = 42 '; + $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 cf.source = 42 '; $sql .= 'AND cf.fk_statut < 5 AND cfd.fk_product = ' . $product_id; $sql .= ' GROUP BY cfd.fk_product'; - + $resql = $db->query($sql); - if($resql) { + if ($resql) { $exists = $db->num_rows($resql); - if($exists) { + if ($exists) { $obj = $db->fetch_array($resql); + return $obj['SUM(cfd.qty)'] . ' ' . img_picto('','tick'); - } - else { + } else { return img_picto('', 'stcomm-1'); } - } - else { + } else { $error = $db->lasterror(); dol_print_error($db); dol_syslog('replenish.php: ' . $error, LOG_ERROR); + return $langs->trans('error'); } } @@ -93,13 +94,13 @@ $offset = $limit * $page ; */ //orders creation -if($action == 'order') { +if ($action == 'order') { $linecount = GETPOST('linecount', 'int'); unset($_POST['linecount']); - if($linecount > 0) { + if ($linecount > 0) { $suppliers = array(); - for($i = 0; $i < $linecount; $i++) { - if(GETPOST($i, 'alpha') === 'on' + for ($i = 0; $i < $linecount; $i++) { + if(GETPOST($i, 'alpha') === 'on' && GETPOST('fourn' . $i, 'int') > 0) { //one line $supplierpriceid = GETPOST('fourn'.$i, 'int'); //get all the parameters needed to create a line @@ -110,7 +111,7 @@ if($action == 'order') { $sql .= MAIN_DB_PREFIX . 'product_fournisseur_price'; $sql .= ' WHERE rowid = ' . $supplierpriceid; $resql = $db->query($sql); - if($resql && $db->num_rows($resql) > 0) { + if ($resql && $db->num_rows($resql) > 0) { //might need some value checks $obj = $db->fetch_object($resql); $line = new CommandeFournisseurLigne($db); @@ -125,8 +126,7 @@ if($action == 'order') { $line->total_ttc = $line->total_ht + $line->total_tva; $line->ref_fourn = $obj->ref_fourn; $suppliers[$obj->fk_soc]['lines'][] = $line; - } - else { + } else { $error=$db->lasterror(); dol_print_error($db); dol_syslog('replenish.php: '.$error, LOG_ERROR); @@ -140,22 +140,22 @@ if($action == 'order') { $i = 0; $orders = array(); $suppliersid = array_keys($suppliers); - foreach($suppliers as $supplier) { + 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) { + foreach ($supplier['lines'] as $line) { $order->lines[] = $line; } $id = $order->create($user); - if($id < 0) { + if ($id < 0) { $fail++; setEventMessage($langs->trans('OrderFail'), 'errors'); } $i++; } - if(!$fail && $id) { + if (!$fail && $id) { setEventMessage($langs->trans('OrderCreated'), 'mesgs'); header('Location: replenishorders.php'); exit; @@ -190,8 +190,7 @@ if ($sall) { if (dol_strlen($type)) { if ($type == 1) { $sql .= ' AND p.fk_product_type = 1'; - } - else { + } else { $sql .= ' AND p.fk_product_type != 1'; } } @@ -242,27 +241,26 @@ if ($resql) { if ($sref || $snom || $sall || GETPOST('search')) { $filters = '&sref=' . $sref . '&snom=' . $snom; $filters .= '&sall=' . $sall; - print_barre_liste($texte, - $page, - 'replenish.php', - $filters, - $sortfield, + print_barre_liste($texte, + $page, + 'replenish.php', + $filters, + $sortfield, $sortorder, '', $num ); - } - else { + } 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, - '', + print_barre_liste($texte, + $page, + 'replenish.php', + $filters, + $sortfield, + $sortorder, + '', $num); } @@ -283,84 +281,83 @@ if ($resql) { // Lignes des titres print ''; print ''; - print_liste_field_titre($langs->trans('Ref'), - 'replenish.php', - 'p.ref', - $param, - '', - '', - $sortfield, + print_liste_field_titre($langs->trans('Ref'), + 'replenish.php', + 'p.ref', + $param, + '', + '', + $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('Label'), - 'replenish.php', - 'p.label', - $param, - '', - '', - $sortfield, + print_liste_field_titre($langs->trans('Label'), + 'replenish.php', + 'p.label', + $param, + '', + '', + $sortfield, $sortorder ); if (!empty($conf->service->enabled) && $type == 1) { - print_liste_field_titre($langs->trans('Duration'), - 'replenish.php', - 'p.duration', - $param, - '', - 'align="center"', - $sortfield, + print_liste_field_titre($langs->trans('Duration'), + 'replenish.php', + 'p.duration', + $param, + '', + 'align="center"', + $sortfield, $sortorder ); } - print_liste_field_titre($langs->trans('DesiredStock'), - 'replenish.php', - 'p.desiredstock', - $param, - '', - 'align="right"', - $sortfield, + print_liste_field_titre($langs->trans('DesiredStock'), + 'replenish.php', + 'p.desiredstock', + $param, + '', + 'align="right"', + $sortfield, $sortorder ); - if($conf->global->USE_VIRTUAL_STOCK) { + if ($conf->global->USE_VIRTUAL_STOCK) { $stocklabel = $langs->trans('VirtualStock'); - } - else { + } else { $stocklabel = $langs->trans('PhysicalStock'); } - print_liste_field_titre($stocklabel, - 'replenish.php', - 'stock_physique', - $param, - '', - 'align="right"', - $sortfield, + print_liste_field_titre($stocklabel, + 'replenish.php', + 'stock_physique', + $param, + '', + 'align="right"', + $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('StockToBuy'), - 'replenish.php', - '', - $param, - '', - 'align="right"', - $sortfield, + print_liste_field_titre($langs->trans('StockToBuy'), + 'replenish.php', + '', + $param, + '', + 'align="right"', + $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('Ordered'), - 'replenish.php', - '', - $param, - '', - 'align="right"', - $sortfield, + print_liste_field_titre($langs->trans('Ordered'), + 'replenish.php', + '', + $param, + '', + 'align="right"', + $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('Supplier'), - 'replenish.php', - '', - $param, - '', - 'align="right"', - $sortfield, + print_liste_field_titre($langs->trans('Supplier'), + 'replenish.php', + '', + $param, + '', + 'align="right"', + $sortfield, $sortorder ); print ''; @@ -395,10 +392,10 @@ if ($resql) { $var = True; while ($i < min($num, $limit)) { $objp = $db->fetch_object($resql); - if($conf->global->STOCK_SUPPORTS_SERVICES + if ($conf->global->STOCK_SUPPORTS_SERVICES || $objp->fk_product_type == 0) { // Multilangs - if(! empty($conf->global->MAIN_MULTILANGS)) { + if (! empty($conf->global->MAIN_MULTILANGS)) { $sql = 'SELECT label'; $sql .= ' FROM ' . MAIN_DB_PREFIX . 'product_lang'; $sql .= ' WHERE fk_product = ' . $objp->rowid; @@ -406,7 +403,7 @@ if ($resql) { $sql .= ' LIMIT 1'; $result = $db->query($sql); - if($result) { + if ($result) { $objtp = $db->fetch_object($result); if (!empty($objtp->label)) { $objp->label = $objtp->label; @@ -426,28 +423,25 @@ if ($resql) { print ''; print ''; - if(!empty($conf->service->enabled) && $type == 1) { + if (!empty($conf->service->enabled) && $type == 1) { print ''; } print ''; print ''; $form = new Form($db); print ''; @@ -505,31 +498,30 @@ if ($resql) { if ($sref || $snom || $sall || GETPOST('search')) { $filters = '&sref=' . $sref . '&snom=' . $snom; $filters .= '&sall=' . $sall; - print_barre_liste('', - $page, - 'replenish.php', - $filters, - $sortfield, - $sortorder, - '', - $num, - 0, + print_barre_liste('', + $page, + 'replenish.php', + $filters, + $sortfield, + $sortorder, + '', + $num, + 0, '' ); - } - else { + } 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, + print_barre_liste('', + $page, + 'replenish.php', + $filters, + $sortfield, + $sortorder, + '', + $num, + 0, '' ); } @@ -537,11 +529,9 @@ if ($resql) { $db->free($resql); -} -else { +} else { dol_print_error($db); } llxFooter(); $db->close(); -?> diff --git a/htdocs/product/stock/replenishorders.php b/htdocs/product/stock/replenishorders.php index 1a87736ef9e..d3fd138b01d 100644 --- a/htdocs/product/stock/replenishorders.php +++ b/htdocs/product/stock/replenishorders.php @@ -47,10 +47,10 @@ $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, +dol_fiche_head($head, + 'replenishorders', + $langs->trans('Replenishment'), + 0, 'stock'); $commandestatic = new CommandeFournisseur($db); $sref = GETPOST('search_ref'); @@ -64,11 +64,11 @@ $page = GETPOST('page', 'int'); $sortorder = GETPOST('sortorder'); $sortfield = GETPOST('sortfield'); -if(!$sortorder) { +if (!$sortorder) { $sortorder = 'DESC'; } -if(!$sortfield) { +if (!$sortfield) { $sortfield = 'cf.date_creation'; } @@ -80,7 +80,7 @@ $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) { +if (!$user->rights->societe->client->voir && !$socid) { $sql.= ', ' . MAIN_DB_PREFIX . 'societe_commerciaux as sc'; } @@ -92,37 +92,37 @@ $sql .= ' AND cf.entity = ' . $conf->entity; $sql .= ' AND cf.source = 42'; $sql .= ' AND cf.fk_statut < 5'; -if(!$user->rights->societe->client->voir && !$socid) { +if (!$user->rights->societe->client->voir && !$socid) { $sql .= ' AND s.rowid = sc.fk_soc AND sc.fk_user = ' . $user->id; } -if($sref) { +if ($sref) { $sql .= ' AND cf.ref LIKE "%' . $db->escape($sref) . '%"'; } -if($snom) { +if ($snom) { $sql .= ' AND s.nom LIKE "%' . $db->escape($snom) . '%"'; } -if($suser) { +if ($suser) { $sql .= ' AND u.login LIKE "%' . $db->escape($suser) . '%"'; } -if($sttc) { +if ($sttc) { $sql .= ' AND cf.total_ttc = ' . price2num($sttc); } -if($sdate) { +if ($sdate) { $elts = explode('/', $sdate); - $date = date('Y-m-d', + $date = date('Y-m-d', mktime(0, 0, 0, $elts[1], $elts[0], $elts[2]) ); $sql .= ' AND cf.date_creation LIKE "' . $date . '%"'; } -if($sall) { +if ($sall) { $sql .= ' AND (cf.ref LIKE "%' . $db->escape($sall) . '%" '; $sql .= 'OR cf.note LIKE "%' . $db->escape($sall) . '%")'; } -if($socid) { +if ($socid) { $sql .= ' AND s.rowid = ' . $socid; } -if(GETPOST('statut')) { +if (GETPOST('statut')) { $sql .= ' AND fk_statut = ' . GETPOST('statut'); } @@ -130,74 +130,74 @@ $sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder . ' '; $sql .= $db->plimit($conf->liste_limit+1, $offset); $resql = $db->query($sql); -if($resql) { +if ($resql) { $num = $db->num_rows($resql); $i = 0; - print_barre_liste($langs->trans('ReplenishmentOrders'), - $page, - 'replenishorders.php', - '', - $sortfield, - $sortorder, - '', + print_barre_liste($langs->trans('ReplenishmentOrders'), + $page, + 'replenishorders.php', + '', + $sortfield, + $sortorder, + '', $num ); print ''; print '
 '; print ''; - print ''; print '
'; print $form->select_product_fourn_price($prod->id, - 'fourn' . $i, 1); + 'fourn' . $i, + 1 + ); print ' 
  ' . $objp->label . ''; - if(preg_match('/([0-9]+)y/i', $objp->duration, $regs)) { + if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) { print $regs[1] . ' ' . $langs->trans('DurationYear'); - } - else if(preg_match('/([0-9]+)m/i', $objp->duration, $regs)) { + } elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) { print $regs[1] . ' ' . $langs->trans('DurationMonth'); - } - else if(preg_match('/([0-9]+)d/i', $objp->duration, $regs)) { + } elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) { print $regs[1] . ' ' . $langs->trans('DurationDay'); - } - else { + } else { print $objp->duration; } print '' . $objp->desiredstock . ''; - if(!$objp->stock_physique) { + if (!$objp->stock_physique) { $objp->stock_physique = 0; } - if($conf->global->USE_VIRTUAL_STOCK) { + if ($conf->global->USE_VIRTUAL_STOCK) { //compute virtual stock $prod->fetch($prod->id); $result=$prod->load_stats_commande(0, '1,2'); @@ -461,11 +455,10 @@ if ($resql) { } $stock_commande_fournisseur = $prod->stats_commande_fournisseur['qty']; $stock = $objp->stock_physique - $stock_commande_client + $stock_commande_fournisseur; - } - else { + } else { $stock = $objp->stock_physique; } - if ($objp->seuil_stock_alerte + if ($objp->seuil_stock_alerte && ($stock < $objp->seuil_stock_alerte)) { $warn = $langs->trans('StockTooLow'); print img_warning($warn) . ' '; @@ -482,8 +475,8 @@ if ($resql) { print ''; - print $form->select_product_fourn_price($prod->id, - 'fourn' . $i, + print $form->select_product_fourn_price($prod->id, + 'fourn' . $i, 1 ); print '
'; print ''; - print_liste_field_titre($langs->trans('Ref'), - $_SERVER['PHP_SELF'], - 'cf.ref', - '', - '', - '', - $sortfield, + print_liste_field_titre($langs->trans('Ref'), + $_SERVER['PHP_SELF'], + 'cf.ref', + '', + '', + '', + $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('Company'), - $_SERVER['PHP_SELF'], - 's.nom', - '', - '', - '', - $sortfield, + print_liste_field_titre($langs->trans('Company'), + $_SERVER['PHP_SELF'], + 's.nom', + '', + '', + '', + $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('Author'), - $_SERVER['PHP_SELF'], - 'u.login', - '', - '', - '', - $sortfield, + print_liste_field_titre($langs->trans('Author'), + $_SERVER['PHP_SELF'], + 'u.login', + '', + '', + '', + $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('AmountTTC'), - $_SERVER['PHP_SELF'], - 'cf.total_ttc', - '', - '', - '', - $sortfield, + print_liste_field_titre($langs->trans('AmountTTC'), + $_SERVER['PHP_SELF'], + 'cf.total_ttc', + '', + '', + '', + $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('OrderCreation'), - $_SERVER['PHP_SELF'], - 'cf.date_creation', - '', - '', - '', - $sortfield, + print_liste_field_titre($langs->trans('OrderCreation'), + $_SERVER['PHP_SELF'], + 'cf.date_creation', + '', + '', + '', + $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('Status'), - $_SERVER['PHP_SELF'], - 'cf.fk_statut', - '', - '', - 'align="right"', - $sortfield, + print_liste_field_titre($langs->trans('Status'), + $_SERVER['PHP_SELF'], + 'cf.fk_statut', + '', + '', + 'align="right"', + $sortfield, $sortorder ); print ''; @@ -228,7 +228,7 @@ if($resql) { $var = true; $userstatic = new User($db); - while($i < min($num,$conf->liste_limit)) { + while ($i < min($num,$conf->liste_limit)) { $obj = $db->fetch_object($resql); $var = !$var; @@ -251,14 +251,13 @@ if($resql) { $userstatic->id = $obj->fk_user_author; $userstatic->login = $obj->login; print ''; // Amount print ''; @@ -288,4 +286,3 @@ if($resql) { llxFooter(); $db->close(); -?> From e92858be36a33be944f96cef958239a2c5432578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 3 Jun 2013 15:18:33 +0200 Subject: [PATCH 43/92] wizard UI --- htdocs/product/replenish.php | 367 +++++++++++++++++++++++++++++++++++ 1 file changed, 367 insertions(+) create mode 100644 htdocs/product/replenish.php diff --git a/htdocs/product/replenish.php b/htdocs/product/replenish.php new file mode 100644 index 00000000000..819f4f736d6 --- /dev/null +++ b/htdocs/product/replenish.php @@ -0,0 +1,367 @@ + + * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * + * 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/replenish.php + * \ingroup produit + * \brief Page to list stocks + */ + +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'; + +$langs->load("products"); +$langs->load("stocks"); + +// Security check +if ($user->societe_id) $socid=$user->societe_id; +$result=restrictedArea($user,'produit|service'); + + +$action=GETPOST('action','alpha'); +$sref=GETPOST("sref"); +$snom=GETPOST("snom"); +$sall=GETPOST("sall"); +$type=GETPOST("type","int"); +$sbarcode=GETPOST("sbarcode"); +$catid=GETPOST('catid','int'); +$tobuy = GETPOST("tobuy"); + +$sortfield = GETPOST("sortfield",'alpha'); +$sortorder = GETPOST("sortorder",'alpha'); +$page = GETPOST("page",'int'); +if (! $sortfield) $sortfield="stock_physique"; +if (! $sortorder) $sortorder="ASC"; +$limit = $conf->liste_limit; +$offset = $limit * $page ; + +// Load sale and categ filters +$search_sale = GETPOST("search_sale"); +$search_categ = GETPOST("search_categ"); + +// Get object canvas (By default, this is not defined, so standard usage of dolibarr) +//$object->getCanvas($id); +$canvas=GETPOST("canvas"); +$objcanvas=''; +if (! empty($canvas)) +{ + require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php'; + $objcanvas = new Canvas($db,$action); + $objcanvas->getCanvas('product','list',$canvas); +} + +if (! empty($_POST["button_removefilter_x"])) +{ + $sref=""; + $snom=""; + $sall=""; + $search_sale=""; + $search_categ=""; + $type=""; + $catid=''; +} + + + +/* + * Actions + */ + +// None + + +/* + * View + */ + +$htmlother=new FormOther($db); + +$title=$langs->trans("ProductsAndServices"); + +$sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,'; +$sql.= ' p.fk_product_type, p.tms as datem,'; +$sql.= ' 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'; +// 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"; +$sql .= ') LEFT JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price as pf on p.rowid = pf.fk_product'; +$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s on p.rowid = s.fk_product'; + +$sql.= " WHERE p.entity IN (".getEntity('product', 1).")"; +if ($search_categ) $sql.= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ +if ($sall) +{ + $sql.= " AND (p.ref LIKE '%".$db->escape($sall)."%' OR p.label LIKE '%".$db->escape($sall)."%' OR p.description LIKE '%".$db->escape($sall)."%' 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 ($sbarcode) $sql.= " AND p.barcode LIKE '%".$sbarcode."%'"; +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)."'"; +} +if($catid) +{ + $sql.= " AND cp.fk_categorie = ".$catid; +} + + $sql.= " AND p.rowid = pf.fk_product"; + +// Insert categ filter +if ($search_categ) +{ + $sql .= " AND cp.fk_categorie = ".$db->escape($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.tobuy, p.seuil_stock_alerte"; +$sql .= ", p.desiredstock"; +$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=''; + $helpurl='EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; + + if (isset($type)) + { + if ($type==1) { $texte = $langs->trans("Services"); } + else { $texte = $langs->trans("Products"); } + } else { + $texte = $langs->trans("ProductsAndServices"); + } + $texte.=' ('.$langs->trans("Stocks").')'; + + + llxHeader("",$title,$helpurl,$texte); + + if ($sref || $snom || $sall || GETPOST('search')) + { + print_barre_liste($texte, $page, "replenish.php", "&sref=".$sref."&snom=".$snom."&sall=".$sall, $sortfield, $sortorder,'',$num); + } + else + { + print_barre_liste($texte, $page, "replenish.php", "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":""), $sortfield, $sortorder,'',$num); + } + + if (! empty($catid)) + { + print "
"; + $c = new Categorie($db); + $c->fetch($catid); + $ways = $c->print_all_ways(' > ','product/replenish.php'); + print " > ".$ways[0]."
\n"; + print "

"; + } + + print ''; + print ''; + print ''; + print ''; + print ''; + + print '
'; - - if($userstatic->id) { + + if ($userstatic->id) { print $userstatic->getLoginUrl(1); - } - else { + } else { print ' '; } - + print ''; @@ -268,8 +267,7 @@ if($resql) { print ''; if ($obj->dc) { print dol_print_date($db->jdate($obj->dc), 'day'); - } - else { + } else { print '-'; } print '
'; + + // Filter on categories + $moreforfilter=''; + if (! empty($conf->categorie->enabled)) + { + $moreforfilter.=$langs->trans('Categories'). ': '; + $moreforfilter.=$htmlother->select_categories(0,$search_categ,'search_categ'); + $moreforfilter.='           '; + } + if ($moreforfilter) + { + print ''; + print ''; + } + + $param=(isset($type)?"&type=$type":"")."&fourn_id=$fourn_id&snom=$snom&sref=$sref"; + + // Lignes des titres + print ""; + print ""; + print_liste_field_titre($langs->trans("Ref"),"replenish.php", "p.ref",$param,"","",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Label"),"replenish.php", "p.label",$param,"","",$sortfield,$sortorder); + if (! empty($conf->service->enabled) && $type == 1) print_liste_field_titre($langs->trans("Duration"),"replenish.php", "p.duration",$param,"",'align="center"',$sortfield,$sortorder); + //print_liste_field_titre($langs->trans("MininumStock"),"replenish.php", "p.seuil_stock_alerte",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("DesiredStock"),"replenish.php", "p.desiredstock",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("PhysicalStock"),"replenish.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("StockToBuy"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Supplier"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); + // TODO Add info of running suppliers/customers orders + //print_liste_field_titre($langs->trans("TheoreticalStock"),"replenish.php", "stock_theorique",$param,"",'align="right"',$sortfield,$sortorder); + print ''; + print "\n"; + + // Lignes des champs de filtre + print ''; + print ''; + print ''; + print ''; + if (! empty($conf->service->enabled) && $type == 1) + { + print ''; + } + print ''; + print ''; + print ''; + print ''; + //print ''; + // print ''; + print ''; + print ''; + + $product_static=new Product($db); + + $var=True; + while ($i < min($num,$limit)) + { + $objp = $db->fetch_object($resql); + + // Multilangs + if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active + { + $sql = "SELECT label"; + $sql.= " FROM ".MAIN_DB_PREFIX."product_lang"; + $sql.= " WHERE fk_product=".$objp->rowid; + $sql.= " AND lang='". $langs->getDefaultLang() ."'"; + $sql.= " LIMIT 1"; + + $result = $db->query($sql); + if ($result) + { + $objtp = $db->fetch_object($result); + if (! empty($objtp->label)) $objp->label = $objtp->label; + } + } + + $var=!$var; + print ''; + print ''; + print ''; + print ''; + + if (! empty($conf->service->enabled) && $type == 1) + { + print ''; + } + //print ''; + //print ''; + print ''; + print ''; + //depending on conf, use either physical stock or + //theoretical stock to compute the stock to buy value + ($conf->global->use_theoretical_stock? $stock = $objp->stock_théorique : $stock = $objp->stock_physique); + $stocktobuy = $objp->desiredstock - $stock; + print ''; + $form = new Form($db); + print ''; + print ''; + print "\n"; + $i++; + } + print "
'; + print $moreforfilter; + print '
  
 '; + print ''; + print ''; + print ''; + print ''; + print ' '; + print '      '; + print ''; + print ''; + print '
'; + $product_static->ref=$objp->ref; + $product_static->id=$objp->rowid; + $product_static->type=$objp->fk_product_type; + print $product_static->getNomUrl(1,'',16); + //if ($objp->stock_theorique < $objp->seuil_stock_alerte) print ' '.img_warning($langs->trans("StockTooLow")); + print ''.$objp->label.''; + if (preg_match('/([0-9]+)y/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationYear"); + elseif (preg_match('/([0-9]+)m/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationMonth"); + elseif (preg_match('/([0-9]+)d/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationDay"); + else print $objp->duration; + print ''.$objp->stock_theorique.''.$objp->seuil_stock_alerte.''.$objp->desiredstock.''; + if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; + print $objp->stock_physique; + print ''.$stocktobuy.''.$form->select_product_fourn_price($product_static->id).' 
"; + print ''; + print ''; + print '
'; + print '
'; + + if ($num > $conf->liste_limit) + { + if ($sref || $snom || $sall || GETPOST('search')) + { + print_barre_liste('', $page, "replenish.php", "&sref=".$sref."&snom=".$snom."&sall=".$sall, $sortfield, $sortorder,'',$num, 0, ''); + } + else + { + print_barre_liste('', $page, "replenish.php", "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":""), $sortfield, $sortorder,'',$num, 0, ''); + } + } + + $db->free($resql); + +} +else +{ + dol_print_error($db); +} + + +llxFooter(); +$db->close(); +?> From d3975bce7a8750c85c011660772a73a34f79306b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 3 Jun 2013 15:34:12 +0200 Subject: [PATCH 44/92] copyright --- htdocs/product/replenish.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/htdocs/product/replenish.php b/htdocs/product/replenish.php index 819f4f736d6..1a296623994 100644 --- a/htdocs/product/replenish.php +++ b/htdocs/product/replenish.php @@ -1,11 +1,10 @@ - * 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 + * 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 + * 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, @@ -14,7 +13,7 @@ * 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 . + * along with this program. If not, see . */ /** From 47a1ffd58c684057b78ed550afd958798a4b2be8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 4 Jun 2013 12:27:09 +0200 Subject: [PATCH 45/92] order creation wizard --- htdocs/product/replenish.php | 196 +++++++++++++++++++++++++++++++++-- 1 file changed, 188 insertions(+), 8 deletions(-) diff --git a/htdocs/product/replenish.php b/htdocs/product/replenish.php index 1a296623994..ce9490cf4e5 100644 --- a/htdocs/product/replenish.php +++ b/htdocs/product/replenish.php @@ -27,6 +27,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.'/categories/class/categorie.class.php'; +require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; $langs->load("products"); $langs->load("stocks"); @@ -84,6 +85,56 @@ if (! empty($_POST["button_removefilter_x"])) /* * Actions */ + +if($action == 'order'){ + $linecount = GETPOST('linecount', 'int'); + $suppliers = array(); + for($i = 0; $i < $linecount; $i++) { + if(GETPOST($i, 'alpha') === 'on') { //one line + $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'; + $sql .= ' from '.MAIN_DB_PREFIX.'product_fournisseur_price'; + $sql .= ' where rowid = '.$supplierpriceid; + $resql = $db->query($sql); + if($resql) { + //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; + $line->total_tva = $line->total_ht * $line->tva_tx / 100; + $line->total_ttc = $line->total_ht + $line->total_tva; + $line->ref_fourn = $obj->ref_fourn; + $suppliers[$obj->fk_soc]['lines'][] = $line; + } + } + } + //At this point we 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]; + $order->source = 42; + $i++; + foreach($supplier['lines'] as $line){ + $order->lines[] = $line; + } + $id = $order->create($user); + if($id) { + //emulate what fourn/commande/liste.php does + } + } +} // None @@ -207,6 +258,8 @@ if ($resql) print ''; print ''; print ''; + print ''; + print ''; print ''; @@ -239,8 +292,6 @@ if ($resql) print_liste_field_titre($langs->trans("PhysicalStock"),"replenish.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("StockToBuy"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Supplier"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); - // TODO Add info of running suppliers/customers orders - //print_liste_field_titre($langs->trans("TheoreticalStock"),"replenish.php", "stock_theorique",$param,"",'align="right"',$sortfield,$sortorder); print ''; print "\n"; @@ -263,8 +314,6 @@ if ($resql) print ''; print ''; print ''; - //print ''; - // print ''; print ''; - print ''; + print ''; print ''; print ''; + print ''; if (! empty($conf->service->enabled) && $type == 1) { @@ -316,8 +366,6 @@ if ($resql) else print $objp->duration; print ''; } - //print ''; - //print ''; print ''; print ''; + print ''; $form = new Form($db); - print ''; + print ''; print ''; print "\n"; $i++; @@ -360,6 +409,137 @@ else dol_print_error($db); } +$commandestatic=new CommandeFournisseur($db); + +$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, cf.fk_user_author,"; +$sql.= " 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.= ")"; +$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON cf.fk_user_author = u.rowid"; +$sql.= " WHERE cf.fk_soc = s.rowid "; +$sql.= " AND cf.entity = ".$conf->entity; +$sql.= " AND cf.source = 42"; +$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 total_ttc = ".price2num($sttc); +} +if ($sall) +{ + $sql.= " AND (cf.ref LIKE '%".$db->escape($sall)."%' OR cf.note LIKE '%".$db->escape($sall)."%')"; +} +if ($socid) $sql.= " AND s.rowid = ".$socid; + +if (GETPOST('statut')) +{ + $sql .= " AND fk_statut =".GETPOST('statut'); +} + +$sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset); +$resql = $db->query($sql); +if ($resql) +{ + + $num = $db->num_rows($resql); + $i = 0; + + + print_barre_liste($title, $page, "replenishment.php", "", $sortfield, $sortorder, '', $num); + print ''; + print '
 
     '; print ''; print ''; @@ -297,7 +346,7 @@ if ($resql) $var=!$var; print '
'; $product_static->ref=$objp->ref; $product_static->id=$objp->rowid; @@ -306,6 +355,7 @@ if ($resql) //if ($objp->stock_theorique < $objp->seuil_stock_alerte) print ' '.img_warning($langs->trans("StockTooLow")); print ''.$objp->label.''.$objp->stock_theorique.''.$objp->seuil_stock_alerte.''.$objp->desiredstock.''; if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; @@ -328,8 +376,9 @@ if ($resql) ($conf->global->use_theoretical_stock? $stock = $objp->stock_théorique : $stock = $objp->stock_physique); $stocktobuy = $objp->desiredstock - $stock; print ''.$stocktobuy.''.$form->select_product_fourn_price($product_static->id).''.$form->select_product_fourn_price($product_static->id, "fourn".$i).' 
'; + print ''; + print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"cf.ref","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"],"u.login","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"total_ttc","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("OrderDate"),$_SERVER["PHP_SELF"],"dc","","",'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"cf.fk_statut","","",'align="right"',$sortfield,$sortorder); + print "\n"; + + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $var=true; + + $userstatic = new User($db); + + while ($i < min($num,$conf->liste_limit)) + { + $obj = $db->fetch_object($resql); + $var=!$var; + + print ""; + + // Ref + print ''."\n"; + + // Company + print ''."\n"; + + // Author + $userstatic->id=$obj->fk_user_author; + $userstatic->login=$obj->login; + print ""; + + // Amount + print '"; + + // Date + print "'; + + // Statut + print ''; + + print "\n"; + $i++; + } + print "
'; + print ''; + print '
'.img_object($langs->trans("ShowOrder"),"order").' '.$obj->ref.''.img_object($langs->trans("ShowCompany"),"company").' '; + print $obj->nom.'"; + if ($userstatic->id) print $userstatic->getLoginUrl(1); + else print " "; + print "'.price($obj->total_ttc).""; + if ($obj->dc) + { + print dol_print_date($db->jdate($obj->dc),"day"); + } + else + { + print "-"; + } + print ''.$commandestatic->LibStatut($obj->fk_statut, 5).'
\n"; + print "\n"; + + $db->free($resql); +} llxFooter(); $db->close(); From 6f2bea124f61bf7592e6dbb5b0d199e11995abce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 4 Jun 2013 16:26:19 +0200 Subject: [PATCH 46/92] some improvement to the wizard UI --- htdocs/product/replenish.php | 58 ++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/htdocs/product/replenish.php b/htdocs/product/replenish.php index ce9490cf4e5..bd8b1400d93 100644 --- a/htdocs/product/replenish.php +++ b/htdocs/product/replenish.php @@ -100,7 +100,7 @@ if($action == 'order'){ $sql .= ' from '.MAIN_DB_PREFIX.'product_fournisseur_price'; $sql .= ' where rowid = '.$supplierpriceid; $resql = $db->query($sql); - if($resql) { + if($resql && $db->num_rows($resql) > 0) { //might need some value checks $obj = $db->fetch_object($resql); $line = new CommandeFournisseurLigne($db); @@ -117,35 +117,33 @@ if($action == 'order'){ } } } - //At this point we know how many orders we need and what lines they have + //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]; + //little trick to know which orders have been generated this way $order->source = 42; - $i++; foreach($supplier['lines'] as $line){ $order->lines[] = $line; } $id = $order->create($user); - if($id) { - //emulate what fourn/commande/liste.php does + if($id < 0) { + //error stuff } + $i++; } } -// None - - /* * View */ $htmlother=new FormOther($db); -$title=$langs->trans("ProductsAndServices"); +$title=$langs->trans("Replenishment"); $sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,'; $sql.= ' p.fk_product_type, p.tms as datem,'; @@ -221,17 +219,7 @@ if ($resql) $helpurl=''; $helpurl='EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; - - if (isset($type)) - { - if ($type==1) { $texte = $langs->trans("Services"); } - else { $texte = $langs->trans("Products"); } - } else { - $texte = $langs->trans("ProductsAndServices"); - } - $texte.=' ('.$langs->trans("Stocks").')'; - - + $texte = $langs->trans('Replenishment'); llxHeader("",$title,$helpurl,$texte); if ($sref || $snom || $sall || GETPOST('search')) @@ -410,11 +398,17 @@ else } $commandestatic=new CommandeFournisseur($db); +$sref=GETPOST('search_ref'); +$snom=GETPOST('search_nom'); +$suser=GETPOST('search_user'); +$sttc=GETPOST('search_ttc'); +$sall=GETPOST('search_all'); -$sortorder = GETPOST('sortorder','alpha'); -$sortfield = GETPOST('sortfield','alpha'); -if($sortorder == '') $sortorder="DESC"; -if($sortfield == '') $sortfield="cf.date_creation"; +$page = GETPOST('page','int'); +/*$sortorder = GETPOST('sortorder','alpha'); +$sortfield = GETPOST('sortfield','alpha');*/ +$sortorder="DESC"; +$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, cf.fk_user_author,"; @@ -465,16 +459,16 @@ if ($resql) $i = 0; - print_barre_liste($title, $page, "replenishment.php", "", $sortfield, $sortorder, '', $num); - print '
'; + print_barre_liste($langs->trans('ReplenishmentOrders'), $page, "replenish.php", "", $sortfield, $sortorder, '', $num); + print ''; print ''; print ''; - print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"cf.ref","","",'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","",'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"],"u.login","","",'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"total_ttc","","",'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("OrderDate"),$_SERVER["PHP_SELF"],"dc","","",'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"cf.fk_statut","","",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("OrderCreation"),$_SERVER["PHP_SELF"],"","","",'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"","","",'align="right"',$sortfield,$sortorder); print "\n"; print ''; From 194a5f071ea90b715ba83e1f889022fe96a33f7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 4 Jun 2013 16:28:29 +0200 Subject: [PATCH 47/92] trans --- htdocs/product/replenish.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/product/replenish.php b/htdocs/product/replenish.php index bd8b1400d93..d09079f818b 100644 --- a/htdocs/product/replenish.php +++ b/htdocs/product/replenish.php @@ -31,6 +31,7 @@ require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; $langs->load("products"); $langs->load("stocks"); +$langs->load("orders"); // Security check if ($user->societe_id) $socid=$user->societe_id; From 8d00838fa59065584ec88c0fccb7d2e0b558cc57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 4 Jun 2013 18:25:15 +0200 Subject: [PATCH 48/92] moved page + added link in the left menu --- htdocs/product/replenish.php | 541 ------------------- htdocs/product/stock/replenish.php | 826 +++++++++++++++-------------- 2 files changed, 415 insertions(+), 952 deletions(-) delete mode 100644 htdocs/product/replenish.php diff --git a/htdocs/product/replenish.php b/htdocs/product/replenish.php deleted file mode 100644 index d09079f818b..00000000000 --- a/htdocs/product/replenish.php +++ /dev/null @@ -1,541 +0,0 @@ - - * - * 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/replenish.php - * \ingroup produit - * \brief Page to list stocks - */ - -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'; - -$langs->load("products"); -$langs->load("stocks"); -$langs->load("orders"); - -// Security check -if ($user->societe_id) $socid=$user->societe_id; -$result=restrictedArea($user,'produit|service'); - - -$action=GETPOST('action','alpha'); -$sref=GETPOST("sref"); -$snom=GETPOST("snom"); -$sall=GETPOST("sall"); -$type=GETPOST("type","int"); -$sbarcode=GETPOST("sbarcode"); -$catid=GETPOST('catid','int'); -$tobuy = GETPOST("tobuy"); - -$sortfield = GETPOST("sortfield",'alpha'); -$sortorder = GETPOST("sortorder",'alpha'); -$page = GETPOST("page",'int'); -if (! $sortfield) $sortfield="stock_physique"; -if (! $sortorder) $sortorder="ASC"; -$limit = $conf->liste_limit; -$offset = $limit * $page ; - -// Load sale and categ filters -$search_sale = GETPOST("search_sale"); -$search_categ = GETPOST("search_categ"); - -// Get object canvas (By default, this is not defined, so standard usage of dolibarr) -//$object->getCanvas($id); -$canvas=GETPOST("canvas"); -$objcanvas=''; -if (! empty($canvas)) -{ - require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php'; - $objcanvas = new Canvas($db,$action); - $objcanvas->getCanvas('product','list',$canvas); -} - -if (! empty($_POST["button_removefilter_x"])) -{ - $sref=""; - $snom=""; - $sall=""; - $search_sale=""; - $search_categ=""; - $type=""; - $catid=''; -} - - - -/* - * Actions - */ - -if($action == 'order'){ - $linecount = GETPOST('linecount', 'int'); - $suppliers = array(); - for($i = 0; $i < $linecount; $i++) { - if(GETPOST($i, 'alpha') === 'on') { //one line - $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'; - $sql .= ' from '.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; - $line->total_tva = $line->total_ht * $line->tva_tx / 100; - $line->total_ttc = $line->total_ht + $line->total_tva; - $line->ref_fourn = $obj->ref_fourn; - $suppliers[$obj->fk_soc]['lines'][] = $line; - } - } - } - //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]; - //little 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) { - //error stuff - } - $i++; - } -} - -/* - * View - */ - -$htmlother=new FormOther($db); - -$title=$langs->trans("Replenishment"); - -$sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,'; -$sql.= ' p.fk_product_type, p.tms as datem,'; -$sql.= ' 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'; -// 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"; -$sql .= ') LEFT JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price as pf on p.rowid = pf.fk_product'; -$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s on p.rowid = s.fk_product'; - -$sql.= " WHERE p.entity IN (".getEntity('product', 1).")"; -if ($search_categ) $sql.= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ -if ($sall) -{ - $sql.= " AND (p.ref LIKE '%".$db->escape($sall)."%' OR p.label LIKE '%".$db->escape($sall)."%' OR p.description LIKE '%".$db->escape($sall)."%' 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 ($sbarcode) $sql.= " AND p.barcode LIKE '%".$sbarcode."%'"; -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)."'"; -} -if($catid) -{ - $sql.= " AND cp.fk_categorie = ".$catid; -} - - $sql.= " AND p.rowid = pf.fk_product"; - -// Insert categ filter -if ($search_categ) -{ - $sql .= " AND cp.fk_categorie = ".$db->escape($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.tobuy, p.seuil_stock_alerte"; -$sql .= ", p.desiredstock"; -$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=''; - $helpurl='EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; - $texte = $langs->trans('Replenishment'); - llxHeader("",$title,$helpurl,$texte); - - if ($sref || $snom || $sall || GETPOST('search')) - { - print_barre_liste($texte, $page, "replenish.php", "&sref=".$sref."&snom=".$snom."&sall=".$sall, $sortfield, $sortorder,'',$num); - } - else - { - print_barre_liste($texte, $page, "replenish.php", "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":""), $sortfield, $sortorder,'',$num); - } - - if (! empty($catid)) - { - print "
"; - $c = new Categorie($db); - $c->fetch($catid); - $ways = $c->print_all_ways(' > ','product/replenish.php'); - print " > ".$ways[0]."
\n"; - print "

"; - } - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - print '
'; - - // Filter on categories - $moreforfilter=''; - if (! empty($conf->categorie->enabled)) - { - $moreforfilter.=$langs->trans('Categories'). ': '; - $moreforfilter.=$htmlother->select_categories(0,$search_categ,'search_categ'); - $moreforfilter.='           '; - } - if ($moreforfilter) - { - print ''; - print ''; - } - - $param=(isset($type)?"&type=$type":"")."&fourn_id=$fourn_id&snom=$snom&sref=$sref"; - - // Lignes des titres - print ""; - print ""; - print_liste_field_titre($langs->trans("Ref"),"replenish.php", "p.ref",$param,"","",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Label"),"replenish.php", "p.label",$param,"","",$sortfield,$sortorder); - if (! empty($conf->service->enabled) && $type == 1) print_liste_field_titre($langs->trans("Duration"),"replenish.php", "p.duration",$param,"",'align="center"',$sortfield,$sortorder); - //print_liste_field_titre($langs->trans("MininumStock"),"replenish.php", "p.seuil_stock_alerte",$param,"",'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("DesiredStock"),"replenish.php", "p.desiredstock",$param,"",'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("PhysicalStock"),"replenish.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("StockToBuy"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Supplier"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); - print ''; - print "\n"; - - // Lignes des champs de filtre - print ''; - print ''; - print ''; - print ''; - if (! empty($conf->service->enabled) && $type == 1) - { - print ''; - } - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - $product_static=new Product($db); - - $var=True; - while ($i < min($num,$limit)) - { - $objp = $db->fetch_object($resql); - - // Multilangs - if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active - { - $sql = "SELECT label"; - $sql.= " FROM ".MAIN_DB_PREFIX."product_lang"; - $sql.= " WHERE fk_product=".$objp->rowid; - $sql.= " AND lang='". $langs->getDefaultLang() ."'"; - $sql.= " LIMIT 1"; - - $result = $db->query($sql); - if ($result) - { - $objtp = $db->fetch_object($result); - if (! empty($objtp->label)) $objp->label = $objtp->label; - } - } - - $var=!$var; - print ''; - print ''; - print ''; - print ''; - print ''; - - if (! empty($conf->service->enabled) && $type == 1) - { - print ''; - } - print ''; - print ''; - //depending on conf, use either physical stock or - //theoretical stock to compute the stock to buy value - ($conf->global->use_theoretical_stock? $stock = $objp->stock_théorique : $stock = $objp->stock_physique); - $stocktobuy = $objp->desiredstock - $stock; - print ''; - print ''; - $form = new Form($db); - print ''; - print ''; - print "\n"; - $i++; - } - print "
'; - print $moreforfilter; - print '
  
 '; - print ''; - print ''; - print ''; - print ''; - print ' '; - print '    '; - print ''; - print ''; - print '
'; - $product_static->ref=$objp->ref; - $product_static->id=$objp->rowid; - $product_static->type=$objp->fk_product_type; - print $product_static->getNomUrl(1,'',16); - //if ($objp->stock_theorique < $objp->seuil_stock_alerte) print ' '.img_warning($langs->trans("StockTooLow")); - print ''.$objp->label.''; - if (preg_match('/([0-9]+)y/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationYear"); - elseif (preg_match('/([0-9]+)m/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationMonth"); - elseif (preg_match('/([0-9]+)d/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationDay"); - else print $objp->duration; - print ''.$objp->desiredstock.''; - if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; - print $objp->stock_physique; - print ''.$stocktobuy.''.$form->select_product_fourn_price($product_static->id, "fourn".$i).' 
"; - print ''; - print ''; - print '
'; - print '
'; - - if ($num > $conf->liste_limit) - { - if ($sref || $snom || $sall || GETPOST('search')) - { - print_barre_liste('', $page, "replenish.php", "&sref=".$sref."&snom=".$snom."&sall=".$sall, $sortfield, $sortorder,'',$num, 0, ''); - } - else - { - print_barre_liste('', $page, "replenish.php", "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":""), $sortfield, $sortorder,'',$num, 0, ''); - } - } - - $db->free($resql); - -} -else -{ - dol_print_error($db); -} - -$commandestatic=new CommandeFournisseur($db); -$sref=GETPOST('search_ref'); -$snom=GETPOST('search_nom'); -$suser=GETPOST('search_user'); -$sttc=GETPOST('search_ttc'); -$sall=GETPOST('search_all'); - -$page = GETPOST('page','int'); -/*$sortorder = GETPOST('sortorder','alpha'); -$sortfield = GETPOST('sortfield','alpha');*/ -$sortorder="DESC"; -$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, cf.fk_user_author,"; -$sql.= " 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.= ")"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON cf.fk_user_author = u.rowid"; -$sql.= " WHERE cf.fk_soc = s.rowid "; -$sql.= " AND cf.entity = ".$conf->entity; -$sql.= " AND cf.source = 42"; -$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 total_ttc = ".price2num($sttc); -} -if ($sall) -{ - $sql.= " AND (cf.ref LIKE '%".$db->escape($sall)."%' OR cf.note LIKE '%".$db->escape($sall)."%')"; -} -if ($socid) $sql.= " AND s.rowid = ".$socid; - -if (GETPOST('statut')) -{ - $sql .= " AND fk_statut =".GETPOST('statut'); -} - -$sql .= " ORDER BY $sortfield $sortorder " . $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, "replenish.php", "", $sortfield, $sortorder, '', $num); - print '
'; - print ''; - print ''; - print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("OrderCreation"),$_SERVER["PHP_SELF"],"","","",'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"","","",'align="right"',$sortfield,$sortorder); - print "\n"; - - print ''; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - $var=true; - - $userstatic = new User($db); - - while ($i < min($num,$conf->liste_limit)) - { - $obj = $db->fetch_object($resql); - $var=!$var; - - print ""; - - // Ref - print ''."\n"; - - // Company - print ''."\n"; - - // Author - $userstatic->id=$obj->fk_user_author; - $userstatic->login=$obj->login; - print ""; - - // Amount - print '"; - - // Date - print "'; - - // Statut - print ''; - - print "\n"; - $i++; - } - print "
'; - print ''; - print '
'.img_object($langs->trans("ShowOrder"),"order").' '.$obj->ref.''.img_object($langs->trans("ShowCompany"),"company").' '; - print $obj->nom.'"; - if ($userstatic->id) print $userstatic->getLoginUrl(1); - else print " "; - print "'.price($obj->total_ttc).""; - if ($obj->dc) - { - print dol_print_date($db->jdate($obj->dc),"day"); - } - else - { - print "-"; - } - print ''.$commandestatic->LibStatut($obj->fk_statut, 5).'
\n"; - print "
\n"; - - $db->free($resql); -} - -llxFooter(); -$db->close(); -?> diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 105fe45c739..70679319158 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -17,15 +17,16 @@ */ /** - * \file htdocs/product/stock/replenish.php + * \file htdocs/product/replenish.php * \ingroup produit - * \brief Page to list stocks to replenish + * \brief Page to list stocks */ 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'; $langs->load("products"); @@ -33,346 +34,267 @@ $langs->load("stocks"); $langs->load("orders"); // Security check -if ($user->societe_id) { - $socid = $user->societe_id; -} +if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user,'produit|service'); -//checks if a product has been ordered -function ordered($product_id) -{ - global $db; - $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 cf.source = 42 '; - $sql .= 'AND cf.fk_statut < 5 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); +$action=GETPOST('action','alpha'); +$sref=GETPOST("sref"); +$snom=GETPOST("snom"); +$sall=GETPOST("sall"); +$type=GETPOST("type","int"); +$sbarcode=GETPOST("sbarcode"); +$catid=GETPOST('catid','int'); +$tobuy = GETPOST("tobuy"); - return $obj['SUM(cfd.qty)'] . ' ' . img_picto('','tick'); - } else { - return img_picto('', 'stcomm-1'); - } - } else { - $error = $db->lasterror(); - dol_print_error($db); - dol_syslog('replenish.php: ' . $error, LOG_ERROR); - - return $langs->trans('error'); - } -} - -$action = GETPOST('action','alpha'); -$sref = GETPOST('sref'); -$snom = GETPOST('snom'); -$sall = GETPOST('sall'); -$type = GETPOST('type','int'); -$tobuy = GETPOST('tobuy'); - -$sortfield = GETPOST('sortfield','alpha'); -$sortorder = GETPOST('sortorder','alpha'); -$page = GETPOST('page','int'); - -if (!$sortfield) { - $sortfield = 'p.ref'; -} - -if (!$sortorder) { - $sortorder = 'ASC'; -} +$sortfield = GETPOST("sortfield",'alpha'); +$sortorder = GETPOST("sortorder",'alpha'); +$page = GETPOST("page",'int'); +if (! $sortfield) $sortfield="stock_physique"; +if (! $sortorder) $sortorder="ASC"; $limit = $conf->liste_limit; $offset = $limit * $page ; +// Load sale and categ filters +$search_sale = GETPOST("search_sale"); +$search_categ = GETPOST("search_categ"); + +// Get object canvas (By default, this is not defined, so standard usage of dolibarr) +//$object->getCanvas($id); +$canvas=GETPOST("canvas"); +$objcanvas=''; +if (! empty($canvas)) +{ + require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php'; + $objcanvas = new Canvas($db,$action); + $objcanvas->getCanvas('product','list',$canvas); +} + +if (! empty($_POST["button_removefilter_x"])) +{ + $sref=""; + $snom=""; + $sall=""; + $search_sale=""; + $search_categ=""; + $type=""; + $catid=''; +} + + + /* * Actions */ - -//orders creation -if ($action == 'order') { + +if($action == 'order'){ $linecount = GETPOST('linecount', 'int'); - 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 - $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]); + $suppliers = array(); + for($i = 0; $i < $linecount; $i++) { + if(GETPOST($i, 'alpha') === 'on') { //one line + $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'; + $sql .= ' from '.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; + $line->total_tva = $line->total_ht * $line->tva_tx / 100; + $line->total_ttc = $line->total_ht + $line->total_tva; + $line->ref_fourn = $obj->ref_fourn; + $suppliers[$obj->fk_soc]['lines'][] = $line; } - 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++; + } + //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]; + //little trick to know which orders have been generated this way + $order->source = 42; + foreach($supplier['lines'] as $line){ + $order->lines[] = $line; } - if (!$fail && $id) { - setEventMessage($langs->trans('OrderCreated'), 'mesgs'); - header('Location: replenishorders.php'); - exit; + $id = $order->create($user); + if($id < 0) { + //error stuff } + $i++; } } /* * View */ -$title = $langs->trans('Replenishment'); -$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'; +$htmlother=new FormOther($db); + +$title=$langs->trans("Replenishment"); + +$sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,'; +$sql.= ' p.fk_product_type, p.tms as datem,'; +$sql.= ' 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) . ')'; +$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"; +$sql .= ') LEFT JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price as pf on p.rowid = pf.fk_product'; +$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s on p.rowid = s.fk_product'; -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).'%")'; +$sql.= " WHERE p.entity IN (".getEntity('product', 1).")"; +if ($search_categ) $sql.= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ +if ($sall) +{ + $sql.= " AND (p.ref LIKE '%".$db->escape($sall)."%' OR p.label LIKE '%".$db->escape($sall)."%' OR p.description LIKE '%".$db->escape($sall)."%' 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 (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 ($sref) $sql.= " AND p.ref LIKE '%".$sref."%'"; +if ($sbarcode) $sql.= " AND p.barcode LIKE '%".$sbarcode."%'"; +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)."'"; } -if ($snom) { - $sql .= ' AND p.label LIKE "%' . $db->escape($snom) . '%"'; +if($catid) +{ + $sql.= " AND cp.fk_categorie = ".$catid; } -$sql .= ' AND p.tobuy = 1'; + $sql.= " AND p.rowid = pf.fk_product"; -if (!empty($canvas)) { - $sql .= ' AND p.canvas = "' . $db->escape($canvas) . '"'; +// Insert categ filter +if ($search_categ) +{ + $sql .= " AND cp.fk_categorie = ".$db->escape($search_categ); } - - $sql .= ' AND p.rowid = pf.fk_product'; - -$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 .= $db->order($sortfield,$sortorder); -$sql .= $db->plimit($limit + 1, $offset); +$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.tobuy, p.seuil_stock_alerte"; +$sql .= ", p.desiredstock"; +$sql.= $db->order($sortfield,$sortorder); +$sql.= $db->plimit($limit + 1, $offset); $resql = $db->query($sql); -if ($resql) { +if ($resql) +{ $num = $db->num_rows($resql); + $i = 0; - if ($num == 1 && ($sall or $snom or $sref)) { + + if ($num == 1 && ($sall or $snom or $sref)) + { $objp = $db->fetch_object($resql); - header('Location: ../fiche.php?id=' . $objp->rowid); + 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', $title, 0, 'stock'); - if ($sref || $snom || $sall || GETPOST('search')) { - $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); + $helpurl=''; + $helpurl='EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; + $texte = $langs->trans('Replenishment'); + llxHeader("",$title,$helpurl,$texte); + + if ($sref || $snom || $sall || GETPOST('search')) + { + print_barre_liste($texte, $page, "replenish.php", "&sref=".$sref."&snom=".$snom."&sall=".$sall, $sortfield, $sortorder,'',$num); + } + else + { + print_barre_liste($texte, $page, "replenish.php", "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":""), $sortfield, $sortorder,'',$num); + } + + if (! empty($catid)) + { + print "
"; + $c = new Categorie($db); + $c->fetch($catid); + $ways = $c->print_all_ways(' > ','product/replenish.php'); + print " > ".$ways[0]."
\n"; + print "

"; } print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; print ''; print ''; - $param = (isset($type)? '&type=' . $type : ''); - $param .= '&fourn_id=' . $fourn_id . '&snom='. $snom; - $param .= '&sref=' . $sref; + // Filter on categories + $moreforfilter=''; + if (! empty($conf->categorie->enabled)) + { + $moreforfilter.=$langs->trans('Categories'). ': '; + $moreforfilter.=$htmlother->select_categories(0,$search_categ,'search_categ'); + $moreforfilter.='           '; + } + if ($moreforfilter) + { + print ''; + print ''; + } + + $param=(isset($type)?"&type=$type":"")."&fourn_id=$fourn_id&snom=$snom&sref=$sref"; // Lignes des titres - print ''; + print ""; + print ""; + print_liste_field_titre($langs->trans("Ref"),"replenish.php", "p.ref",$param,"","",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Label"),"replenish.php", "p.label",$param,"","",$sortfield,$sortorder); + if (! empty($conf->service->enabled) && $type == 1) print_liste_field_titre($langs->trans("Duration"),"replenish.php", "p.duration",$param,"",'align="center"',$sortfield,$sortorder); + //print_liste_field_titre($langs->trans("MininumStock"),"replenish.php", "p.seuil_stock_alerte",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("DesiredStock"),"replenish.php", "p.desiredstock",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("PhysicalStock"),"replenish.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("StockToBuy"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Supplier"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); print ''; - print_liste_field_titre($langs->trans('Ref'), - 'replenish.php', - 'p.ref', - $param, - '', - '', - $sortfield, - $sortorder - ); - print_liste_field_titre($langs->trans('Label'), - 'replenish.php', - 'p.label', - $param, - '', - '', - $sortfield, - $sortorder - ); - if (!empty($conf->service->enabled) && $type == 1) { - print_liste_field_titre($langs->trans('Duration'), - 'replenish.php', - 'p.duration', - $param, - '', - 'align="center"', - $sortfield, - $sortorder - ); - } - print_liste_field_titre($langs->trans('DesiredStock'), - 'replenish.php', - 'p.desiredstock', - $param, - '', - 'align="right"', - $sortfield, - $sortorder - ); - if ($conf->global->USE_VIRTUAL_STOCK) { - $stocklabel = $langs->trans('VirtualStock'); - } else { - $stocklabel = $langs->trans('PhysicalStock'); - } - print_liste_field_titre($stocklabel, - 'replenish.php', - 'stock_physique', - $param, - '', - 'align="right"', - $sortfield, - $sortorder - ); - print_liste_field_titre($langs->trans('StockToBuy'), - 'replenish.php', - '', - $param, - '', - 'align="right"', - $sortfield, - $sortorder - ); - print_liste_field_titre($langs->trans('Ordered'), - 'replenish.php', - '', - $param, - '', - 'align="right"', - $sortfield, - $sortorder - ); - print_liste_field_titre($langs->trans('Supplier'), - 'replenish.php', - '', - $param, - '', - 'align="right"', - $sortfield, - $sortorder - ); - print ''; - print ''; + print "\n"; // Lignes des champs de filtre print ''; print ''; print ''; print ''; - if (!empty($conf->service->enabled) && $type == 1) { + if (! empty($conf->service->enabled) && $type == 1) + { print ''; @@ -381,157 +303,239 @@ if ($resql) { print ''; print ''; print ''; - print ''; print ''; print ''; - $prod = new Product($db); + $product_static=new Product($db); - $var = True; - while ($i < min($num, $limit)) { + $var=True; + while ($i < min($num,$limit)) + { $objp = $db->fetch_object($resql); - if ($conf->global->STOCK_SUPPORTS_SERVICES - || $objp->fk_product_type == 0) { - // Multilangs - if (! empty($conf->global->MAIN_MULTILANGS)) { - $sql = 'SELECT label'; - $sql .= ' FROM ' . MAIN_DB_PREFIX . 'product_lang'; - $sql .= ' WHERE fk_product = ' . $objp->rowid; - $sql .= ' AND lang = "' . $langs->getDefaultLang() . '"'; - $sql .= ' LIMIT 1'; - $result = $db->query($sql); - if ($result) { - $objtp = $db->fetch_object($result); - if (!empty($objtp->label)) { - $objp->label = $objtp->label; - } - } - } + // Multilangs + if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active + { + $sql = "SELECT label"; + $sql.= " FROM ".MAIN_DB_PREFIX."product_lang"; + $sql.= " WHERE fk_product=".$objp->rowid; + $sql.= " AND lang='". $langs->getDefaultLang() ."'"; + $sql.= " LIMIT 1"; - $var =! $var; - print ''; - print ''; - print ''; - print ''; - print ''; - - if (!empty($conf->service->enabled) && $type == 1) { - print ''; + $result = $db->query($sql); + if ($result) + { + $objtp = $db->fetch_object($result); + if (! empty($objtp->label)) $objp->label = $objtp->label; } - print ''; - print ''; - //depending on conf, use either physical stock or - //virtual stock to compute the stock to buy value - $stocktobuy = $objp->desiredstock - $stock; - print ''; - print ''; - print ''; - $form = new Form($db); - print ''; - print ''; - print ""; } + + $var=!$var; + print ''; + print ''; + print ''; + print ''; + print ''; + + if (! empty($conf->service->enabled) && $type == 1) + { + print ''; + } + print ''; + print ''; + //depending on conf, use either physical stock or + //theoretical stock to compute the stock to buy value + ($conf->global->use_theoretical_stock? $stock = $objp->stock_théorique : $stock = $objp->stock_physique); + $stocktobuy = $objp->desiredstock - $stock; + print ''; + print ''; + $form = new Form($db); + print ''; + print ''; + print "\n"; $i++; } print "
'; + print $moreforfilter; + print '
   
 '; - print ''; + print ''; print ''; - print ''; + print ''; print ''; print ' '; print '    '; - print ''; + print ''; + print ''; print '
'; - $prod->ref = $objp->ref; - $prod->id = $objp->rowid; - $prod->type = $objp->fk_product_type; - print $prod->getNomUrl(1, '', 16); - print '' . $objp->label . ''; - if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) { - print $regs[1] . ' ' . $langs->trans('DurationYear'); - } elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) { - print $regs[1] . ' ' . $langs->trans('DurationMonth'); - } elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) { - print $regs[1] . ' ' . $langs->trans('DurationDay'); - } else { - print $objp->duration; - } - print '' . $objp->desiredstock . ''; - if (!$objp->stock_physique) { - $objp->stock_physique = 0; - } - if ($conf->global->USE_VIRTUAL_STOCK) { - //compute virtual stock - $prod->fetch($prod->id); - $result=$prod->load_stats_commande(0, '1,2'); - if ($result < 0) { - dol_print_error($db, $prod->error); - } - $stock_commande_client = $prod->stats_commande['qty']; - $result=$prod->load_stats_commande_fournisseur(0, '3'); - if ($result < 0) { - dol_print_error($db,$prod->error); - } - $stock_commande_fournisseur = $prod->stats_commande_fournisseur['qty']; - $stock = $objp->stock_physique - $stock_commande_client + $stock_commande_fournisseur; - } else { - $stock = $objp->stock_physique; - } - if ($objp->seuil_stock_alerte - && ($stock < $objp->seuil_stock_alerte)) { - $warn = $langs->trans('StockTooLow'); - print img_warning($warn) . ' '; - } - print $stock; - print ''.$stocktobuy.''; - print ordered($prod->id); - print ''; - print $form->select_product_fourn_price($prod->id, - 'fourn' . $i, - 1 - ); - print ' 
'; + $product_static->ref=$objp->ref; + $product_static->id=$objp->rowid; + $product_static->type=$objp->fk_product_type; + print $product_static->getNomUrl(1,'',16); + //if ($objp->stock_theorique < $objp->seuil_stock_alerte) print ' '.img_warning($langs->trans("StockTooLow")); + print ''.$objp->label.''; + if (preg_match('/([0-9]+)y/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationYear"); + elseif (preg_match('/([0-9]+)m/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationMonth"); + elseif (preg_match('/([0-9]+)d/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationDay"); + else print $objp->duration; + print ''.$objp->desiredstock.''; + if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; + print $objp->stock_physique; + print ''.$stocktobuy.''.$form->select_product_fourn_price($product_static->id, "fourn".$i).' 
"; - print ''; print ''; - print '
'; - $value = $langs->trans("CreateOrders"); - print ''; - print '
'; + print ''; + print ''; print '
'; - if ($num > $conf->liste_limit) { - if ($sref || $snom || $sall || GETPOST('search')) { - $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, - '' - ); + if ($num > $conf->liste_limit) + { + if ($sref || $snom || $sall || GETPOST('search')) + { + print_barre_liste('', $page, "replenish.php", "&sref=".$sref."&snom=".$snom."&sall=".$sall, $sortfield, $sortorder,'',$num, 0, ''); + } + else + { + print_barre_liste('', $page, "replenish.php", "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":""), $sortfield, $sortorder,'',$num, 0, ''); } } $db->free($resql); -} else { +} +else +{ dol_print_error($db); } +$commandestatic=new CommandeFournisseur($db); +$sref=GETPOST('search_ref'); +$snom=GETPOST('search_nom'); +$suser=GETPOST('search_user'); +$sttc=GETPOST('search_ttc'); +$sall=GETPOST('search_all'); + +$page = GETPOST('page','int'); +/*$sortorder = GETPOST('sortorder','alpha'); +$sortfield = GETPOST('sortfield','alpha');*/ +$sortorder="DESC"; +$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, cf.fk_user_author,"; +$sql.= " 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.= ")"; +$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON cf.fk_user_author = u.rowid"; +$sql.= " WHERE cf.fk_soc = s.rowid "; +$sql.= " AND cf.entity = ".$conf->entity; +$sql.= " AND cf.source = 42"; +$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 total_ttc = ".price2num($sttc); +} +if ($sall) +{ + $sql.= " AND (cf.ref LIKE '%".$db->escape($sall)."%' OR cf.note LIKE '%".$db->escape($sall)."%')"; +} +if ($socid) $sql.= " AND s.rowid = ".$socid; + +if (GETPOST('statut')) +{ + $sql .= " AND fk_statut =".GETPOST('statut'); +} + +$sql .= " ORDER BY $sortfield $sortorder " . $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, "replenish.php", "", $sortfield, $sortorder, '', $num); + print '
'; + print ''; + print ''; + print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("OrderCreation"),$_SERVER["PHP_SELF"],"","","",'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"","","",'align="right"',$sortfield,$sortorder); + print "\n"; + + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $var=true; + + $userstatic = new User($db); + + while ($i < min($num,$conf->liste_limit)) + { + $obj = $db->fetch_object($resql); + $var=!$var; + + print ""; + + // Ref + print ''."\n"; + + // Company + print ''."\n"; + + // Author + $userstatic->id=$obj->fk_user_author; + $userstatic->login=$obj->login; + print ""; + + // Amount + print '"; + + // Date + print "'; + + // Statut + print ''; + + print "\n"; + $i++; + } + print "
'; + print ''; + print '
'.img_object($langs->trans("ShowOrder"),"order").' '.$obj->ref.''.img_object($langs->trans("ShowCompany"),"company").' '; + print $obj->nom.'"; + if ($userstatic->id) print $userstatic->getLoginUrl(1); + else print " "; + print "'.price($obj->total_ttc).""; + if ($obj->dc) + { + print dol_print_date($db->jdate($obj->dc),"day"); + } + else + { + print "-"; + } + print ''.$commandestatic->LibStatut($obj->fk_statut, 5).'
\n"; + print "
\n"; + + $db->free($resql); +} + llxFooter(); $db->close(); +?> From e5a70ade85519494d8ec7b81bf876d19114e575b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 5 Jun 2013 14:50:29 +0200 Subject: [PATCH 49/92] filter out lines where stock > desiredstock --- htdocs/product/stock/replenish.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 70679319158..3f05008a6c5 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -201,6 +201,7 @@ $sql.= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.pr $sql.= " 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)'; $sql.= $db->order($sortfield,$sortorder); $sql.= $db->plimit($limit + 1, $offset); $resql = $db->query($sql); From d31064a8b1df0717ab53ad335e9c24d7fe949c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 5 Jun 2013 15:22:33 +0200 Subject: [PATCH 50/92] comments --- htdocs/product/stock/replenish.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 3f05008a6c5..8a33a4228c8 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -17,9 +17,9 @@ */ /** - * \file htdocs/product/replenish.php + * \file htdocs/product/stock/replenish.php * \ingroup produit - * \brief Page to list stocks + * \brief Page to list stocks to replenish */ require '../../main.inc.php'; @@ -86,7 +86,8 @@ if (! empty($_POST["button_removefilter_x"])) /* * Actions */ - + +//orders creation if($action == 'order'){ $linecount = GETPOST('linecount', 'int'); $suppliers = array(); @@ -277,7 +278,6 @@ if ($resql) print_liste_field_titre($langs->trans("Ref"),"replenish.php", "p.ref",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Label"),"replenish.php", "p.label",$param,"","",$sortfield,$sortorder); if (! empty($conf->service->enabled) && $type == 1) print_liste_field_titre($langs->trans("Duration"),"replenish.php", "p.duration",$param,"",'align="center"',$sortfield,$sortorder); - //print_liste_field_titre($langs->trans("MininumStock"),"replenish.php", "p.seuil_stock_alerte",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("DesiredStock"),"replenish.php", "p.desiredstock",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("PhysicalStock"),"replenish.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("StockToBuy"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); @@ -342,7 +342,6 @@ if ($resql) $product_static->id=$objp->rowid; $product_static->type=$objp->fk_product_type; print $product_static->getNomUrl(1,'',16); - //if ($objp->stock_theorique < $objp->seuil_stock_alerte) print ' '.img_warning($langs->trans("StockTooLow")); print ''; print ''.$objp->label.''; print ''; @@ -407,8 +406,7 @@ $sttc=GETPOST('search_ttc'); $sall=GETPOST('search_all'); $page = GETPOST('page','int'); -/*$sortorder = GETPOST('sortorder','alpha'); -$sortfield = GETPOST('sortfield','alpha');*/ + $sortorder="DESC"; $sortfield="cf.date_creation"; $offset = $conf->liste_limit * $page ; From f7a7e953a3fa80bbbb6f007d6929175e69d7a453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Thu, 6 Jun 2013 11:31:12 +0200 Subject: [PATCH 51/92] merge --- scripts/user/sync_groups_ldap2dolibarr.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 +?> From bdb2a005396c185556caf3565eeceec3c9ffc6ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 10 Jun 2013 11:57:06 +0200 Subject: [PATCH 52/92] products now show up in the list even when they don't have a line in llx_product_stock --- htdocs/product/stock/replenish.php | 97 ++++++++++++++++-------------- 1 file changed, 53 insertions(+), 44 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 8a33a4228c8..804243dcd30 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -90,52 +90,60 @@ if (! empty($_POST["button_removefilter_x"])) //orders creation if($action == 'order'){ $linecount = GETPOST('linecount', 'int'); - $suppliers = array(); - for($i = 0; $i < $linecount; $i++) { - if(GETPOST($i, 'alpha') === 'on') { //one line - $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'; - $sql .= ' from '.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; - $line->total_tva = $line->total_ht * $line->tva_tx / 100; - $line->total_ttc = $line->total_ht + $line->total_tva; - $line->ref_fourn = $obj->ref_fourn; - $suppliers[$obj->fk_soc]['lines'][] = $line; + if($linecount > 0){ + $suppliers = array(); + for($i = 0; $i < $linecount; $i++) { + if(GETPOST($i, 'alpha') === 'on') { //one line + $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'; + $sql .= ' from '.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; + $line->total_tva = $line->total_ht * $line->tva_tx / 100; + $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); + } } } - } - //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]; - //little trick to know which orders have been generated this way - $order->source = 42; - foreach($supplier['lines'] as $line){ - $order->lines[] = $line; + $db->free($resql); + //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]; + //little 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) { + //error stuff + } + $i++; } - $id = $order->create($user); - if($id < 0) { - //error stuff - } - $i++; } } @@ -202,7 +210,7 @@ $sql.= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.pr $sql.= " 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)'; +$sql.= ' HAVING p.desiredstock > SUM(s.reel) or SUM(s.reel) is NULL'; $sql.= $db->order($sortfield,$sortorder); $sql.= $db->plimit($limit + 1, $offset); $resql = $db->query($sql); @@ -357,6 +365,7 @@ if ($resql) } print ''.$objp->desiredstock.''; print ''; + if(!$objp->stock_physique) $objp->stock_physique = 0; if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; print $objp->stock_physique; print ''; From d4aa2a0f79dc8eb0d643ae083514bf501af2103f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 10 Jun 2013 12:37:50 +0200 Subject: [PATCH 53/92] show service lines only if the stock services option is enabled --- htdocs/product/stock/replenish.php | 101 +++++++++++++++-------------- 1 file changed, 51 insertions(+), 50 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 804243dcd30..a07120bc1a6 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -324,61 +324,62 @@ if ($resql) while ($i < min($num,$limit)) { $objp = $db->fetch_object($resql); - - // Multilangs - if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active - { - $sql = "SELECT label"; - $sql.= " FROM ".MAIN_DB_PREFIX."product_lang"; - $sql.= " WHERE fk_product=".$objp->rowid; - $sql.= " AND lang='". $langs->getDefaultLang() ."'"; - $sql.= " LIMIT 1"; - - $result = $db->query($sql); - if ($result) + if($conf->global->STOCK_SUPPORTS_SERVICES || $objp->fk_product_type == 0){ + // Multilangs + if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active { - $objtp = $db->fetch_object($result); - if (! empty($objtp->label)) $objp->label = $objtp->label; + $sql = "SELECT label"; + $sql.= " FROM ".MAIN_DB_PREFIX."product_lang"; + $sql.= " WHERE fk_product=".$objp->rowid; + $sql.= " AND lang='". $langs->getDefaultLang() ."'"; + $sql.= " LIMIT 1"; + + $result = $db->query($sql); + if ($result) + { + $objtp = $db->fetch_object($result); + if (! empty($objtp->label)) $objp->label = $objtp->label; + } } - } - $var=!$var; - print ''; - print ''; - print ''; - $product_static->ref=$objp->ref; - $product_static->id=$objp->rowid; - $product_static->type=$objp->fk_product_type; - print $product_static->getNomUrl(1,'',16); - print ''; - print ''.$objp->label.''; - print ''; - - if (! empty($conf->service->enabled) && $type == 1) - { - print ''; - if (preg_match('/([0-9]+)y/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationYear"); - elseif (preg_match('/([0-9]+)m/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationMonth"); - elseif (preg_match('/([0-9]+)d/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationDay"); - else print $objp->duration; + $var=!$var; + print ''; + print ''; + print ''; + $product_static->ref=$objp->ref; + $product_static->id=$objp->rowid; + $product_static->type=$objp->fk_product_type; + print $product_static->getNomUrl(1,'',16); print ''; + print ''.$objp->label.''; + print ''; + + if (! empty($conf->service->enabled) && $type == 1) + { + print ''; + if (preg_match('/([0-9]+)y/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationYear"); + elseif (preg_match('/([0-9]+)m/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationMonth"); + elseif (preg_match('/([0-9]+)d/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationDay"); + else print $objp->duration; + print ''; + } + print ''.$objp->desiredstock.''; + print ''; + if(!$objp->stock_physique) $objp->stock_physique = 0; + if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; + print $objp->stock_physique; + print ''; + //depending on conf, use either physical stock or + //theoretical stock to compute the stock to buy value + ($conf->global->use_theoretical_stock? $stock = $objp->stock_théorique : $stock = $objp->stock_physique); + $stocktobuy = $objp->desiredstock - $stock; + print ''.$stocktobuy.''; + print ''; + $form = new Form($db); + print ''.$form->select_product_fourn_price($product_static->id, "fourn".$i).''; + print ' '; + print "\n"; } - print ''.$objp->desiredstock.''; - print ''; - if(!$objp->stock_physique) $objp->stock_physique = 0; - if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; - print $objp->stock_physique; - print ''; - //depending on conf, use either physical stock or - //theoretical stock to compute the stock to buy value - ($conf->global->use_theoretical_stock? $stock = $objp->stock_théorique : $stock = $objp->stock_physique); - $stocktobuy = $objp->desiredstock - $stock; - print ''.$stocktobuy.''; - print ''; - $form = new Form($db); - print ''.$form->select_product_fourn_price($product_static->id, "fourn".$i).''; - print ' '; - print "\n"; $i++; } print ""; From 52cfecd0afa0569af8ea1d7a95890717082f8199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 10 Jun 2013 15:42:58 +0200 Subject: [PATCH 54/92] added an option to use virtual stock instead of physical stock --- htdocs/admin/stock.php | 13 +++++++++++++ htdocs/product/stock/replenish.php | 27 ++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/htdocs/admin/stock.php b/htdocs/admin/stock.php index 54221551469..860b01e9eb8 100644 --- a/htdocs/admin/stock.php +++ b/htdocs/admin/stock.php @@ -142,6 +142,19 @@ print '' print ''; print "\n"; print "\n"; + +print ""; +print ''.$langs->trans("UseVirtualStock").''; +print ''; +print "
"; +print ''; +print ""; +print $form->selectyesno("USE_VIRTUAL_STOCK",$conf->global->USE_VIRTUAL_STOCK,1); +print ''; +print '
'; +print "\n"; +print "\n"; + print '
'; print ''; print '
'; diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index a07120bc1a6..182de040300 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -287,7 +287,12 @@ if ($resql) print_liste_field_titre($langs->trans("Label"),"replenish.php", "p.label",$param,"","",$sortfield,$sortorder); if (! empty($conf->service->enabled) && $type == 1) print_liste_field_titre($langs->trans("Duration"),"replenish.php", "p.duration",$param,"",'align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("DesiredStock"),"replenish.php", "p.desiredstock",$param,"",'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("PhysicalStock"),"replenish.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder); + if($conf->global->USE_VIRTUAL_STOCK) { + print_liste_field_titre($langs->trans("VirtualStock"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); + } + else { + print_liste_field_titre($langs->trans("PhysicalStock"),"replenish.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder); + } print_liste_field_titre($langs->trans("StockToBuy"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Supplier"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); print ' '; @@ -366,12 +371,24 @@ if ($resql) print ''.$objp->desiredstock.''; print ''; if(!$objp->stock_physique) $objp->stock_physique = 0; - if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; - print $objp->stock_physique; + if($conf->global->USE_VIRTUAL_STOCK){ + $product_static->fetch($product_static->id); + $result=$product_static->load_stats_commande(0,'1,2'); + if ($result < 0) dol_print_error($db,$product_static->error); + $stock_commande_client = $product_static->stats_commande['qty']; + $result=$product_static->load_stats_commande_fournisseur(0,'3'); + if ($result < 0) dol_print_error($db,$product_static->error); + $stock_commande_fournisseur = $product_static->stats_commande_fournisseur['qty']; + $stock = $objp->stock_physique - $stock_commande_client + $stock_commande_fournisseur; + } + else{ + $stock = $objp->stock_physique; + } + if ($objp->seuil_stock_alerte && ($stock < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; + print $stock; print ''; //depending on conf, use either physical stock or - //theoretical stock to compute the stock to buy value - ($conf->global->use_theoretical_stock? $stock = $objp->stock_théorique : $stock = $objp->stock_physique); + //virtual stock to compute the stock to buy value $stocktobuy = $objp->desiredstock - $stock; print ''.$stocktobuy.''; print ''; From bcbe940ac003309fbc7efe2f6d8a2efc40c5cee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 10 Jun 2013 16:04:34 +0200 Subject: [PATCH 55/92] fixed SQL error when trying to generate an order without selecting any product line --- htdocs/product/stock/replenish.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 182de040300..a483e5dfa74 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -123,9 +123,9 @@ if($action == 'order'){ dol_print_error($db); dol_syslog("replenish.php: ".$error, LOG_ERROR); } + $db->free($resql); } } - $db->free($resql); //we now know how many orders we need and what lines they have $i = 0; $orders = array(); From c0c2f9af42f167ad739020fde9f3bfebd67f90da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 10 Jun 2013 16:07:41 +0200 Subject: [PATCH 56/92] fixed error when trying to create an order when a line has no associated supplier --- htdocs/product/stock/replenish.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index a483e5dfa74..e1d833d7765 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -93,7 +93,7 @@ if($action == 'order'){ if($linecount > 0){ $suppliers = array(); for($i = 0; $i < $linecount; $i++) { - if(GETPOST($i, 'alpha') === 'on') { //one line + if(GETPOST($i, 'alpha') === 'on' && GETPOST('fourn'.$i, 'int') > 0) { //one line $supplierpriceid = GETPOST('fourn'.$i, 'int'); //get all the parameters needed to create a line $qty = GETPOST('tobuy'.$i, 'int'); From 53265591fcfdf324b1ed352e1cd875a8883e3543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 10 Jun 2013 17:20:49 +0200 Subject: [PATCH 57/92] separated replenishment configuration --- htdocs/admin/stock.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/htdocs/admin/stock.php b/htdocs/admin/stock.php index 860b01e9eb8..54221551469 100644 --- a/htdocs/admin/stock.php +++ b/htdocs/admin/stock.php @@ -142,19 +142,6 @@ print '' print ''; print "\n"; print "\n"; - -print ""; -print ''.$langs->trans("UseVirtualStock").''; -print ''; -print "
"; -print ''; -print ""; -print $form->selectyesno("USE_VIRTUAL_STOCK",$conf->global->USE_VIRTUAL_STOCK,1); -print ''; -print '
'; -print "\n"; -print "\n"; - print '
'; print ''; print '
'; From bd9c4556e8cddb11fd0af587606f778ae6459e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 10 Jun 2013 18:10:06 +0200 Subject: [PATCH 58/92] Preselected supplier when there's only one --- htdocs/core/class/html.form.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index d908e243dfa..3dfc1e25d10 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1400,7 +1400,7 @@ class Form $objp->remise = $objp2->remise; $objp->price_by_qty_rowid = $objp2->rowid; - $this->constructProductListOption($objp, $opt, $optJson, 0, $selected); + $this->_construct_product_list_option($objp, $opt, $optJson, 0, $selected); $j++; @@ -1414,7 +1414,7 @@ class Form } else { - $this->constructProductListOption($objp, $opt, $optJson, $price_level, $selected); + $this->_construct_product_list_option($objp, $opt, $optJson, $price_level, $selected); // Add new entry // "key" value of json key array is used by jQuery automatically as selected value // "label" value of json key array is used by jQuery automatically as text for combo box From b261ef2aa2f8932f995d2970f5a0567932645786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 11 Jun 2013 11:10:31 +0200 Subject: [PATCH 59/92] ordered column --- htdocs/product/stock/replenish.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index e1d833d7765..ace6ad548f4 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -37,6 +37,31 @@ $langs->load("orders"); if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user,'produit|service'); +function ordered($product_id) { + global $db; + $sql = 'SELECT DISTINCT cfd.fk_product from '; + $sql .= MAIN_DB_PREFIX.'commande_fournisseurdet as cfd LEFT JOIN '; + $sql .= MAIN_DB_PREFIX.'commande_fournisseur as cf ON '; + $sql .= 'cfd.fk_commande = cf.rowid WHERE cf.source = 42 '; + $sql .= 'AND cf.fk_statut < 5 AND cfd.fk_product = '.$product_id; + + $resql = $db->query($sql); + if($resql) { + $exists = $db->num_rows($resql); + if($exists) { + return img_picto('','tick'); + } + else { + return img_picto('', 'stcomm-1'); + } + } + else { + $error=$db->lasterror(); + dol_print_error($db); + dol_syslog("replenish.php: ".$error, LOG_ERROR); + return $langs->trans('error'); + } +} $action=GETPOST('action','alpha'); $sref=GETPOST("sref"); @@ -294,6 +319,7 @@ if ($resql) print_liste_field_titre($langs->trans("PhysicalStock"),"replenish.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder); } print_liste_field_titre($langs->trans("StockToBuy"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Ordered"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Supplier"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); print ' '; print "\n"; @@ -317,6 +343,7 @@ if ($resql) print ' '; print ' '; print ' '; + print ' '; print ''; print ''; print ''; @@ -392,6 +419,9 @@ if ($resql) $stocktobuy = $objp->desiredstock - $stock; print ''.$stocktobuy.''; print ''; + print ''; + print ordered($product_static->id); + print ''; $form = new Form($db); print ''.$form->select_product_fourn_price($product_static->id, "fourn".$i).''; print ' '; From ef8d05676f8dc2afe6bc14cdfa9a31acea027356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 11 Jun 2013 11:34:57 +0200 Subject: [PATCH 60/92] display the ordered quantity in the ordered column --- htdocs/product/stock/replenish.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index ace6ad548f4..946a6bb7305 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -39,17 +39,19 @@ $result=restrictedArea($user,'produit|service'); function ordered($product_id) { global $db; - $sql = 'SELECT DISTINCT cfd.fk_product from '; + $sql = 'SELECT DISTINCT cfd.fk_product, SUM(cfd.qty) from '; $sql .= MAIN_DB_PREFIX.'commande_fournisseurdet as cfd LEFT JOIN '; $sql .= MAIN_DB_PREFIX.'commande_fournisseur as cf ON '; $sql .= 'cfd.fk_commande = cf.rowid WHERE cf.source = 42 '; $sql .= 'AND cf.fk_statut < 5 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) { - return img_picto('','tick'); + $obj = $db->fetch_array($resql); + return $obj['SUM(cfd.qty)'].' '.img_picto('','tick'); } else { return img_picto('', 'stcomm-1'); From c919826104694c6018e122ee165436ba2f78392f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 11 Jun 2013 15:20:12 +0200 Subject: [PATCH 61/92] psr 0 --- htdocs/product/stock/replenish.php | 834 ++++++++++++++++++----------- 1 file changed, 520 insertions(+), 314 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 946a6bb7305..00c514a899f 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -40,10 +40,10 @@ $result=restrictedArea($user,'produit|service'); function ordered($product_id) { global $db; $sql = 'SELECT DISTINCT cfd.fk_product, SUM(cfd.qty) from '; - $sql .= MAIN_DB_PREFIX.'commande_fournisseurdet as cfd LEFT JOIN '; - $sql .= MAIN_DB_PREFIX.'commande_fournisseur as cf ON '; - $sql .= 'cfd.fk_commande = cf.rowid WHERE cf.source = 42 '; - $sql .= 'AND cf.fk_statut < 5 AND cfd.fk_product = '.$product_id; + $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 cf.source = 42 '; + $sql .= 'AND cf.fk_statut < 5 AND cfd.fk_product = ' . $product_id; $sql .= ' GROUP BY cfd.fk_product'; $resql = $db->query($sql); @@ -51,7 +51,7 @@ function ordered($product_id) { $exists = $db->num_rows($resql); if($exists) { $obj = $db->fetch_array($resql); - return $obj['SUM(cfd.qty)'].' '.img_picto('','tick'); + return $obj['SUM(cfd.qty)'] . ' ' . img_picto('','tick'); } else { return img_picto('', 'stcomm-1'); @@ -60,52 +60,50 @@ function ordered($product_id) { else { $error=$db->lasterror(); dol_print_error($db); - dol_syslog("replenish.php: ".$error, LOG_ERROR); + dol_syslog('replenish.php: ' . $error, LOG_ERROR); return $langs->trans('error'); } } -$action=GETPOST('action','alpha'); -$sref=GETPOST("sref"); -$snom=GETPOST("snom"); -$sall=GETPOST("sall"); -$type=GETPOST("type","int"); -$sbarcode=GETPOST("sbarcode"); -$catid=GETPOST('catid','int'); -$tobuy = GETPOST("tobuy"); +$action = GETPOST('action','alpha'); +$sref = GETPOST('sref'); +$snom = GETPOST('snom'); +$sall = GETPOST('sall'); +$type = GETPOST('type','int'); +$sbarcode = GETPOST('sbarcode'); +$catid = GETPOST('catid','int'); +$tobuy = GETPOST('tobuy'); -$sortfield = GETPOST("sortfield",'alpha'); -$sortorder = GETPOST("sortorder",'alpha'); -$page = GETPOST("page",'int'); -if (! $sortfield) $sortfield="stock_physique"; -if (! $sortorder) $sortorder="ASC"; +$sortfield = GETPOST('sortfield','alpha'); +$sortorder = GETPOST('sortorder','alpha'); +$page = GETPOST('page','int'); +if (! $sortfield) $sortfield = 'stock_physique'; +if (! $sortorder) $sortorder = 'ASC'; $limit = $conf->liste_limit; $offset = $limit * $page ; // Load sale and categ filters -$search_sale = GETPOST("search_sale"); -$search_categ = GETPOST("search_categ"); +$search_sale = GETPOST('search_sale'); +$search_categ = GETPOST('search_categ'); -// Get object canvas (By default, this is not defined, so standard usage of dolibarr) -//$object->getCanvas($id); -$canvas=GETPOST("canvas"); -$objcanvas=''; -if (! empty($canvas)) -{ - require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php'; +// Get object canvas +//(By default, this is not defined, so standard usage of dolibarr) +$canvas = GETPOST('canvas'); +$objcanvas = ''; +if (! empty($canvas)) { + require_once DOL_DOCUMENT_ROOT . '/core/class/canvas.class.php'; $objcanvas = new Canvas($db,$action); - $objcanvas->getCanvas('product','list',$canvas); + $objcanvas->getCanvas('product', 'list', $canvas); } -if (! empty($_POST["button_removefilter_x"])) -{ - $sref=""; - $snom=""; - $sall=""; - $search_sale=""; - $search_categ=""; - $type=""; - $catid=''; +if (! empty($_POST['button_removefilter_x'])) { + $sref = ''; + $snom = ''; + $sall = ''; + $search_sale = ''; + $search_categ = ''; + $type = ''; + $catid = ''; } @@ -115,20 +113,21 @@ if (! empty($_POST["button_removefilter_x"])) */ //orders creation -if($action == 'order'){ +if($action == 'order') { $linecount = GETPOST('linecount', 'int'); - if($linecount > 0){ + if($linecount > 0) { $suppliers = array(); for($i = 0; $i < $linecount; $i++) { - if(GETPOST($i, 'alpha') === 'on' && GETPOST('fourn'.$i, 'int') > 0) { //one line + if(GETPOST($i, 'alpha') === 'on' + && GETPOST('fourn' . $i, 'int') > 0) { //one line $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'; - $sql .= ' from '.MAIN_DB_PREFIX.'product_fournisseur_price'; - $sql .= ' where rowid = '.$supplierpriceid; + $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 @@ -140,7 +139,8 @@ if($action == 'order'){ $line->tva_tx = $obj->tva_tx; $line->subprice = $obj->unitprice; $line->total_ht = $obj->unitprice * $qty; - $line->total_tva = $line->total_ht * $line->tva_tx / 100; + $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; @@ -148,7 +148,7 @@ if($action == 'order'){ else { $error=$db->lasterror(); dol_print_error($db); - dol_syslog("replenish.php: ".$error, LOG_ERROR); + dol_syslog('replenish.php: '.$error, LOG_ERROR); } $db->free($resql); } @@ -157,12 +157,12 @@ if($action == 'order'){ $i = 0; $orders = array(); $suppliersid = array_keys($suppliers); - foreach($suppliers as $supplier){ + foreach($suppliers as $supplier) { $order = new CommandeFournisseur($db); $order->socid = $suppliersid[$i]; - //little trick to know which orders have been generated this way + //trick to know which orders have been generated this way $order->source = 42; - foreach($supplier['lines'] as $line){ + foreach($supplier['lines'] as $line) { $order->lines[] = $line; } $id = $order->create($user); @@ -180,163 +180,254 @@ if($action == 'order'){ $htmlother=new FormOther($db); -$title=$langs->trans("Replenishment"); +$title=$langs->trans('Replenishment'); -$sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,'; -$sql.= ' p.fk_product_type, p.tms as datem,'; -$sql.= ' p.duration, p.tobuy, p.seuil_stock_alerte,'; -$sql.= ' SUM(s.reel) as stock_physique'; +$sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, 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'; -// 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"; -$sql .= ') LEFT JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price as pf on p.rowid = pf.fk_product'; -$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s on p.rowid = s.fk_product'; +$sql .= ' FROM (' . MAIN_DB_PREFIX . 'product as p'; +// need this table joined to the select in order to filter by categ +if ($search_categ) { + $sql.= ", " . MAIN_DB_PREFIX . "categorie_product as cp"; +} +$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 ($search_categ) $sql.= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ -if ($sall) -{ - $sql.= " AND (p.ref LIKE '%".$db->escape($sall)."%' OR p.label LIKE '%".$db->escape($sall)."%' OR p.description LIKE '%".$db->escape($sall)."%' OR p.note LIKE '%".$db->escape($sall)."%')"; +$sql.= ' WHERE p.entity IN (' . getEntity("product", 1) . ')'; +if ($search_categ) { // Join for the needed table to filter by categ + $sql .= ' AND p.rowid = cp.fk_product'; +} +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'"; +if (dol_strlen($type)) { + if ($type == 1) { + $sql .= ' AND p.fk_product_type = 1'; } - else - { - $sql.= " AND p.fk_product_type <> '1'"; + else { + $sql .= ' AND p.fk_product_type != 1'; } } -if ($sref) $sql.= " AND p.ref LIKE '%".$sref."%'"; -if ($sbarcode) $sql.= " AND p.barcode LIKE '%".$sbarcode."%'"; -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)."'"; +if ($sref) { + $sql .= ' AND p.ref LIKE "%' . $sref . '%"'; } -if($catid) -{ - $sql.= " AND cp.fk_categorie = ".$catid; +if ($sbarcode) { + $sql .= ' AND p.barcode LIKE "%' . $sbarcode . '%"'; +} +if ($snom) { + $sql .= ' AND p.label LIKE "%' . $db->escape($snom) . '%"'; } - $sql.= " AND p.rowid = pf.fk_product"; +$sql .= ' AND p.tobuy = 1'; + +if (!empty($canvas)) { + $sql .= ' AND p.canvas = "' . $db->escape($canvas) . '"'; +} +if($catid) { + $sql .= ' AND cp.fk_categorie = ' . $catid; +} + + $sql .= ' AND p.rowid = pf.fk_product'; // Insert categ filter -if ($search_categ) -{ - $sql .= " AND cp.fk_categorie = ".$db->escape($search_categ); +if ($search_categ) { + $sql .= ' AND cp.fk_categorie = ' . $db->escape($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.tobuy, p.seuil_stock_alerte"; -$sql .= ", p.desiredstock"; -$sql.= ' HAVING p.desiredstock > SUM(s.reel) or SUM(s.reel) is NULL'; -$sql.= $db->order($sortfield,$sortorder); -$sql.= $db->plimit($limit + 1, $offset); +$sql .= ' GROUP BY p.rowid, p.ref, p.label, p.barcode, 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 .= $db->order($sortfield,$sortorder); +$sql .= $db->plimit($limit + 1, $offset); $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { $num = $db->num_rows($resql); - $i = 0; - - if ($num == 1 && ($sall or $snom or $sref)) - { + if ($num == 1 && ($sall or $snom or $sref)) { $objp = $db->fetch_object($resql); - header("Location: fiche.php?id=$objp->rowid"); + header('Location: ../fiche.php?id=' . $objp->rowid); exit; } - $helpurl=''; - $helpurl='EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; + $helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|'; + $helpurl .= 'ES:Módulo_Stocks'; $texte = $langs->trans('Replenishment'); - llxHeader("",$title,$helpurl,$texte); + llxHeader('', $title, $helpurl, $texte); - if ($sref || $snom || $sall || GETPOST('search')) - { - print_barre_liste($texte, $page, "replenish.php", "&sref=".$sref."&snom=".$snom."&sall=".$sall, $sortfield, $sortorder,'',$num); + if ($sref || $snom || $sall || GETPOST('search')) { + print_barre_liste($texte, + $page, + 'replenish.php', + '&sref=' . $sref . '&snom=' . $snom . '&sall=' . $sall, + $sortfield, + $sortorder, + '', + $num + ); } - else - { - print_barre_liste($texte, $page, "replenish.php", "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":""), $sortfield, $sortorder,'',$num); + else { + print_barre_liste($texte, + $page, + 'replenish.php', + '&sref=$sref&snom=$snom&fourn_id=$fourn_id' . (isset($type)?'&type=$type':''), + $sortfield, + $sortorder, + '', + $num); } - if (! empty($catid)) - { - print "
"; + if (!empty($catid)) { + print '
'; $c = new Categorie($db); $c->fetch($catid); - $ways = $c->print_all_ways(' > ','product/replenish.php'); - print " > ".$ways[0]."
\n"; - print "

"; + $ways = $c->print_all_ways(' > ', 'product/replenish.php'); + print ' > ' . $ways[0] . '
'; + print '

'; } print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; print ''; print ''; // Filter on categories - $moreforfilter=''; - if (! empty($conf->categorie->enabled)) - { - $moreforfilter.=$langs->trans('Categories'). ': '; - $moreforfilter.=$htmlother->select_categories(0,$search_categ,'search_categ'); - $moreforfilter.='           '; + $moreforfilter = ''; + if (!empty($conf->categorie->enabled)) { + $moreforfilter .= $langs->trans('Categories') . ': '; + $moreforfilter .= $htmlother->select_categories(0, + $search_categ, + 'search_categ' + ); + $moreforfilter .= '           '; } - if ($moreforfilter) - { + if ($moreforfilter) { print ''; print ''; } - $param=(isset($type)?"&type=$type":"")."&fourn_id=$fourn_id&snom=$snom&sref=$sref"; + $param = (isset($type)? '&type=$type' : ''); + $param .= '&fourn_id=$fourn_id&snom=$snom&sref=$sref'; // Lignes des titres - print ""; - print ""; - print_liste_field_titre($langs->trans("Ref"),"replenish.php", "p.ref",$param,"","",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Label"),"replenish.php", "p.label",$param,"","",$sortfield,$sortorder); - if (! empty($conf->service->enabled) && $type == 1) print_liste_field_titre($langs->trans("Duration"),"replenish.php", "p.duration",$param,"",'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("DesiredStock"),"replenish.php", "p.desiredstock",$param,"",'align="right"',$sortfield,$sortorder); + print ''; + print ''; + print_liste_field_titre($langs->trans('Ref'), + 'replenish.php', + 'p.ref', + $param, + '', + '', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('Label'), + 'replenish.php', + 'p.label', + $param, + '', + '', + $sortfield, + $sortorder + ); + if (!empty($conf->service->enabled) && $type == 1) { + print_liste_field_titre($langs->trans('Duration'), + 'replenish.php', + 'p.duration', + $param, + '', + 'align="center"', + $sortfield, + $sortorder + ); + } + print_liste_field_titre($langs->trans('DesiredStock'), + 'replenish.php', + 'p.desiredstock', + $param, + '', + 'align="right"', + $sortfield, + $sortorder + ); if($conf->global->USE_VIRTUAL_STOCK) { - print_liste_field_titre($langs->trans("VirtualStock"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('VirtualStock'), + 'replenish.php', + '', + $param, + '', + 'align="right"', + $sortfield, + $sortorder + ); } else { - print_liste_field_titre($langs->trans("PhysicalStock"),"replenish.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('PhysicalStock'), + 'replenish.php', + 'stock_physique', + $param, + '', + 'align="right"', + $sortfield, + $sortorder + ); } - print_liste_field_titre($langs->trans("StockToBuy"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Ordered"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Supplier"),"replenish.php", "",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('StockToBuy'), + 'replenish.php', + '', + $param, + '', + 'align="right"', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('Ordered'), + 'replenish.php', + '', + $param, + '', + 'align="right"', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('Supplier'), + 'replenish.php', + '', + $param, + '', + 'align="right"', + $sortfield, + $sortorder + ); print ''; - print "\n"; + print ''; // Lignes des champs de filtre print ''; print ''; print ''; print ''; - if (! empty($conf->service->enabled) && $type == 1) - { + if (!empty($conf->service->enabled) && $type == 1) { print ''; @@ -347,251 +438,366 @@ if ($resql) print ''; print ''; print ''; print ''; - $product_static=new Product($db); + $prod = new Product($db); - $var=True; - while ($i < min($num,$limit)) - { + $var = True; + while ($i < min($num, $limit)) { $objp = $db->fetch_object($resql); - if($conf->global->STOCK_SUPPORTS_SERVICES || $objp->fk_product_type == 0){ + if($conf->global->STOCK_SUPPORTS_SERVICES + || $objp->fk_product_type == 0) { // Multilangs - if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active - { - $sql = "SELECT label"; - $sql.= " FROM ".MAIN_DB_PREFIX."product_lang"; - $sql.= " WHERE fk_product=".$objp->rowid; - $sql.= " AND lang='". $langs->getDefaultLang() ."'"; - $sql.= " LIMIT 1"; + if(! empty($conf->global->MAIN_MULTILANGS)) { + $sql = 'SELECT label'; + $sql .= ' FROM ' . MAIN_DB_PREFIX . 'product_lang'; + $sql .= ' WHERE fk_product = ' . $objp->rowid; + $sql .= ' AND lang = "' . $langs->getDefaultLang() . '"'; + $sql .= ' LIMIT 1'; $result = $db->query($sql); - if ($result) - { + if($result) { $objtp = $db->fetch_object($result); - if (! empty($objtp->label)) $objp->label = $objtp->label; + if (!empty($objtp->label)) { + $objp->label = $objtp->label; + } } } - $var=!$var; - print ''; - print ''; + $var =! $var; + print ''; + print ''; print ''; - print ''; - print ''; + print ''; + print ''; - if (! empty($conf->service->enabled) && $type == 1) - { + if(!empty($conf->service->enabled) && $type == 1) { print ''; } - print ''; + print ''; print ''; //depending on conf, use either physical stock or //virtual stock to compute the stock to buy value $stocktobuy = $objp->desiredstock - $stock; print ''; - print ''; + print ''; print ''; $form = new Form($db); - print ''; + print ''; print ''; - print "\n"; + print ""; } $i++; } print "
'; print $moreforfilter; print '
 
  
 '; - print ''; + print ''; print ''; - print ''; + print ''; print ''; print ' '; print '  '; - print ''; - print ''; + print ''; + print ''; print '
'; - $product_static->ref=$objp->ref; - $product_static->id=$objp->rowid; - $product_static->type=$objp->fk_product_type; - print $product_static->getNomUrl(1,'',16); + $prod->ref = $objp->ref; + $prod->id = $objp->rowid; + $prod->type = $objp->fk_product_type; + print $prod->getNomUrl(1, '', 16); print ''.$objp->label.'' . $objp->label . ''; - if (preg_match('/([0-9]+)y/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationYear"); - elseif (preg_match('/([0-9]+)m/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationMonth"); - elseif (preg_match('/([0-9]+)d/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationDay"); - else print $objp->duration; + if(preg_match('/([0-9]+)y/i', $objp->duration, $regs)) { + print $regs[1] . ' ' . $langs->trans('DurationYear'); + } + else if(preg_match('/([0-9]+)m/i', $objp->duration, $regs)) { + print $regs[1] . ' ' . $langs->trans('DurationMonth'); + } + else if(preg_match('/([0-9]+)d/i', $objp->duration, $regs)) { + print $regs[1] . ' ' . $langs->trans('DurationDay'); + } + else { + print $objp->duration; + } print ''.$objp->desiredstock.'' . $objp->desiredstock . ''; - if(!$objp->stock_physique) $objp->stock_physique = 0; - if($conf->global->USE_VIRTUAL_STOCK){ - $product_static->fetch($product_static->id); - $result=$product_static->load_stats_commande(0,'1,2'); - if ($result < 0) dol_print_error($db,$product_static->error); - $stock_commande_client = $product_static->stats_commande['qty']; - $result=$product_static->load_stats_commande_fournisseur(0,'3'); - if ($result < 0) dol_print_error($db,$product_static->error); - $stock_commande_fournisseur = $product_static->stats_commande_fournisseur['qty']; + if(!$objp->stock_physique) { + $objp->stock_physique = 0; + } + if($conf->global->USE_VIRTUAL_STOCK) { + $prod->fetch($prod->id); + $result=$prod->load_stats_commande(0, '1,2'); + if ($result < 0) { + dol_print_error($db, $prod->error); + } + $stock_commande_client = $prod->stats_commande['qty']; + $result=$prod->load_stats_commande_fournisseur(0, '3'); + if ($result < 0) { + dol_print_error($db,$prod->error); + } + $stock_commande_fournisseur = $prod->stats_commande_fournisseur['qty']; $stock = $objp->stock_physique - $stock_commande_client + $stock_commande_fournisseur; } - else{ + else { $stock = $objp->stock_physique; } - if ($objp->seuil_stock_alerte && ($stock < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; + if ($objp->seuil_stock_alerte + && ($stock < $objp->seuil_stock_alerte)) { + $warn = $langs->trans('StockTooLow'); + print img_warning($warn) . ' '; + } print $stock; print ''.$stocktobuy.''; - print ordered($product_static->id); + print ordered($prod->id); print ''.$form->select_product_fourn_price($product_static->id, "fourn".$i).''; + print $form->select_product_fourn_price($prod->id, + "fourn".$i); + print ' 
"; print ''; - print ''; - print '
'; + print ''; + $valid = $langs->trans("Validate"); + print ''; + print ''; print '
'; - if ($num > $conf->liste_limit) - { - if ($sref || $snom || $sall || GETPOST('search')) - { - print_barre_liste('', $page, "replenish.php", "&sref=".$sref."&snom=".$snom."&sall=".$sall, $sortfield, $sortorder,'',$num, 0, ''); + if ($num > $conf->liste_limit) { + if ($sref || $snom || $sall || GETPOST('search')) { + print_barre_liste('', + $page, + 'replenish.php', + '&sref=' . $sref . '&snom=' . $snom . '&sall=' . $sall, + $sortfield, + $sortorder, + '', + $num, + 0, + '' + ); } - else - { - print_barre_liste('', $page, "replenish.php", "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":""), $sortfield, $sortorder,'',$num, 0, ''); + else { + print_barre_liste('', + $page, + 'replenish.php', + "&sref=$sref&snom=$snom&fourn_id=$fourn_id" . (isset($type)?"&type=$type":""), + $sortfield, + $sortorder, + '', + $num, + 0, + '' + ); } } $db->free($resql); } -else -{ +else { dol_print_error($db); } -$commandestatic=new CommandeFournisseur($db); -$sref=GETPOST('search_ref'); -$snom=GETPOST('search_nom'); -$suser=GETPOST('search_user'); -$sttc=GETPOST('search_ttc'); -$sall=GETPOST('search_all'); +$commandestatic = new CommandeFournisseur($db); +$sref = GETPOST('search_ref'); +$snom = GETPOST('search_nom'); +$suser = GETPOST('search_user'); +$sttc = GETPOST('search_ttc'); +$sall = GETPOST('search_all'); -$page = GETPOST('page','int'); +$page = GETPOST('page', 'int'); -$sortorder="DESC"; -$sortfield="cf.date_creation"; +$sortorder = 'DESC'; +$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, cf.fk_user_author,"; -$sql.= " 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.= ")"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON cf.fk_user_author = u.rowid"; -$sql.= " WHERE cf.fk_soc = s.rowid "; -$sql.= " AND cf.entity = ".$conf->entity; -$sql.= " AND cf.source = 42"; -$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)."%'"; +$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'; } -if ($snom) -{ - $sql.= " AND s.nom LIKE '%".$db->escape($snom)."%'"; +$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; +$sql .= ' AND cf.source = 42'; +$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 ($suser) -{ - $sql.= " AND u.login LIKE '%".$db->escape($suser)."%'"; +if ($sref) { + $sql .= ' AND cf.ref LIKE "%' . $db->escape($sref) . '%"'; } -if ($sttc) -{ - $sql .= " AND total_ttc = ".price2num($sttc); +if ($snom) { + $sql .= ' AND s.nom LIKE "%' . $db->escape($snom) . '%"'; } -if ($sall) -{ - $sql.= " AND (cf.ref LIKE '%".$db->escape($sall)."%' OR cf.note LIKE '%".$db->escape($sall)."%')"; +if ($suser) { + $sql .= ' AND u.login LIKE "%' . $db->escape($suser) . '%"'; +} +if ($sttc) { + $sql .= ' AND total_ttc = ' . price2num($sttc); +} +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 ($socid) $sql.= " AND s.rowid = ".$socid; if (GETPOST('statut')) { - $sql .= " AND fk_statut =".GETPOST('statut'); + $sql .= ' AND fk_statut = ' . GETPOST('statut'); } $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset); $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { - $num = $db->num_rows($resql); - $i = 0; + $num = $db->num_rows($resql); + $i = 0; - print_barre_liste($langs->trans('ReplenishmentOrders'), $page, "replenish.php", "", $sortfield, $sortorder, '', $num); - print '
'; - print ''; - print ''; - print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"","","",'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("OrderCreation"),$_SERVER["PHP_SELF"],"","","",'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"","","",'align="right"',$sortfield,$sortorder); - print "\n"; + print_barre_liste($langs->trans('ReplenishmentOrders'), + $page, + 'replenish.php', + '', + $sortfield, + $sortorder, + '', + $num + ); + print ''; + print '
'; + print ''; + print_liste_field_titre($langs->trans('Ref'), + $_SERVER['PHP_SELF'], + '', + '', + '', + '', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('Company'), + $_SERVER['PHP_SELF'], + '', + '', + '', + '', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('Author'), + $_SERVER['PHP_SELF'], + '', + '', + '', + '', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('AmountTTC'), + $_SERVER['PHP_SELF'], + '', + '', + '', + '', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('OrderCreation'), + $_SERVER['PHP_SELF'], + '', + '', + '', + 'align="center"', + $sortfield, + $sortorder + ); + print_liste_field_titre($langs->trans('Status'), + $_SERVER['PHP_SELF'], + '', + '', + '', + 'align="right"', + $sortfield, + $sortorder + ); + print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + $var = true; + $userstatic = new User($db); - $var=true; + while($i < min($num,$conf->liste_limit)) { + $obj = $db->fetch_object($resql); + $var = !$var; - $userstatic = new User($db); + print ""; + // Ref + print ''.""; - while ($i < min($num,$conf->liste_limit)) - { - $obj = $db->fetch_object($resql); - $var=!$var; + // Company + print ''.""; - print ""; + // Author + $userstatic->id = $obj->fk_user_author; + $userstatic->login = $obj->login; + print ''; - // Ref - print ''."\n"; + // Amount + print ''; - // Company - print ''."\n"; + // Date + print ''; - // Author - $userstatic->id=$obj->fk_user_author; - $userstatic->login=$obj->login; - print ""; + // Statut + print ''; - // Amount - print '"; + print ''; + $i++; + } + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $src = DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/search.png'; + $value = dol_escape_htmltag($langs->trans('Search')); + print ''; + print '
'; - print ''; - print '
'; + $href = DOL_URL_ROOT . '/fourn/commande/fiche.php?id=' . $obj->rowid; + print ''; + print img_object($langs->trans('ShowOrder'), 'order') . ' ' . $obj->ref; + print ''; + $href = DOL_URL_ROOT . '/fourn/fiche.php?socid=' . $obj->socid; + print ''; + print img_object($langs->trans('ShowCompany'), 'company') . ' ' . $obj->nom; + print '
'; + if ($userstatic->id) { + print $userstatic->getLoginUrl(1); + } + else { + print ' '; + } + print ''.img_object($langs->trans("ShowOrder"),"order").' '.$obj->ref.''; + print price($obj->total_ttc); + print ''.img_object($langs->trans("ShowCompany"),"company").' '; - print $obj->nom.''; + if ($obj->dc) { + print dol_print_date($db->jdate($obj->dc), 'day'); + } + else { + print '-'; + } + print '"; - if ($userstatic->id) print $userstatic->getLoginUrl(1); - else print " "; - print "'; + print $commandestatic->LibStatut($obj->fk_statut, 5); + print ''.price($obj->total_ttc)."
'; + print '
'; - // Date - print ""; - if ($obj->dc) - { - print dol_print_date($db->jdate($obj->dc),"day"); - } - else - { - print "-"; - } - print ''; - - // Statut - print ''.$commandestatic->LibStatut($obj->fk_statut, 5).''; - - print "\n"; - $i++; - } - print "\n"; - print "\n"; - - $db->free($resql); + $db->free($resql); } llxFooter(); From 47177a2590af87984295865122a0ff4a07488eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 11 Jun 2013 15:55:43 +0200 Subject: [PATCH 62/92] typo --- htdocs/product/stock/replenish.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 00c514a899f..43727a3a8a8 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -115,6 +115,7 @@ if (! empty($_POST['button_removefilter_x'])) { //orders creation if($action == 'order') { $linecount = GETPOST('linecount', 'int'); + unset($_POST['linecount']); if($linecount > 0) { $suppliers = array(); for($i = 0; $i < $linecount; $i++) { @@ -151,7 +152,9 @@ if($action == 'order') { 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; @@ -535,7 +538,7 @@ if ($resql) { $form = new Form($db); print ''; print $form->select_product_fourn_price($prod->id, - "fourn".$i); + 'fourn' . $i); print ''; print ' '; print ""; From 407ffb8dd7891ffe4cc577f5660f25dcf928fcb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 11 Jun 2013 16:07:47 +0200 Subject: [PATCH 63/92] typo --- htdocs/product/stock/replenish.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 43727a3a8a8..7738f757d85 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -326,7 +326,7 @@ if ($resql) { } $param = (isset($type)? '&type=$type' : ''); - $param .= '&fourn_id=$fourn_id&snom=$snom&sref=$sref'; + $param .= '&fourn_id=' . $fourn_id . '&snom='. $snom . '&sref=' . $sref; // Lignes des titres print ''; From 3c04c6c35bd079f0d2b6dfb4cfbeda068fd220fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 11 Jun 2013 18:31:27 +0200 Subject: [PATCH 64/92] Split the page in two tabs, filters and pagination should work now --- htdocs/product/stock/replenish.php | 225 ++--------------------------- 1 file changed, 9 insertions(+), 216 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 7738f757d85..465ffd9d11a 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -266,7 +266,14 @@ if ($resql) { $helpurl .= 'ES:Módulo_Stocks'; $texte = $langs->trans('Replenishment'); llxHeader('', $title, $helpurl, $texte); - + $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', $title, 0, 'stock'); if ($sref || $snom || $sall || GETPOST('search')) { print_barre_liste($texte, $page, @@ -305,7 +312,7 @@ if ($resql) { print ''; print ''; print ''; - + //print ''; print ''; // Filter on categories @@ -589,220 +596,6 @@ else { dol_print_error($db); } -$commandestatic = new CommandeFournisseur($db); -$sref = GETPOST('search_ref'); -$snom = GETPOST('search_nom'); -$suser = GETPOST('search_user'); -$sttc = GETPOST('search_ttc'); -$sall = GETPOST('search_all'); - -$page = GETPOST('page', 'int'); - -$sortorder = 'DESC'; -$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; -$sql .= ' AND cf.source = 42'; -$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 total_ttc = ' . price2num($sttc); -} -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')) -{ - $sql .= ' AND fk_statut = ' . GETPOST('statut'); -} - -$sql .= " ORDER BY $sortfield $sortorder " . $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, - 'replenish.php', - '', - $sortfield, - $sortorder, - '', - $num - ); - print ''; - print '
'; - print ''; - print_liste_field_titre($langs->trans('Ref'), - $_SERVER['PHP_SELF'], - '', - '', - '', - '', - $sortfield, - $sortorder - ); - print_liste_field_titre($langs->trans('Company'), - $_SERVER['PHP_SELF'], - '', - '', - '', - '', - $sortfield, - $sortorder - ); - print_liste_field_titre($langs->trans('Author'), - $_SERVER['PHP_SELF'], - '', - '', - '', - '', - $sortfield, - $sortorder - ); - print_liste_field_titre($langs->trans('AmountTTC'), - $_SERVER['PHP_SELF'], - '', - '', - '', - '', - $sortfield, - $sortorder - ); - print_liste_field_titre($langs->trans('OrderCreation'), - $_SERVER['PHP_SELF'], - '', - '', - '', - 'align="center"', - $sortfield, - $sortorder - ); - print_liste_field_titre($langs->trans('Status'), - $_SERVER['PHP_SELF'], - '', - '', - '', - 'align="right"', - $sortfield, - $sortorder - ); - print ''; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - $var = true; - $userstatic = new User($db); - - while($i < min($num,$conf->liste_limit)) { - $obj = $db->fetch_object($resql); - $var = !$var; - - print ""; - // Ref - print ''.""; - - // Company - print ''.""; - - // Author - $userstatic->id = $obj->fk_user_author; - $userstatic->login = $obj->login; - print ''; - - // Amount - print ''; - - // Date - print ''; - - // Statut - print ''; - - print ''; - $i++; - } - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - $src = DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/search.png'; - $value = dol_escape_htmltag($langs->trans('Search')); - print ''; - print '
'; - $href = DOL_URL_ROOT . '/fourn/commande/fiche.php?id=' . $obj->rowid; - print ''; - print img_object($langs->trans('ShowOrder'), 'order') . ' ' . $obj->ref; - print ''; - $href = DOL_URL_ROOT . '/fourn/fiche.php?socid=' . $obj->socid; - print ''; - print img_object($langs->trans('ShowCompany'), 'company') . ' ' . $obj->nom; - print ''; - if ($userstatic->id) { - print $userstatic->getLoginUrl(1); - } - else { - print ' '; - } - print ''; - print price($obj->total_ttc); - print ''; - if ($obj->dc) { - print dol_print_date($db->jdate($obj->dc), 'day'); - } - else { - print '-'; - } - print ''; - print $commandestatic->LibStatut($obj->fk_statut, 5); - print '
'; - print ''; - - $db->free($resql); -} - llxFooter(); $db->close(); ?> From 3b6fa4a52b14cbda3550194842b9aeb09884e8a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 11 Jun 2013 18:47:19 +0200 Subject: [PATCH 65/92] message when succeeds/fails to create orders --- htdocs/product/stock/replenish.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 465ffd9d11a..368b12141bf 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -171,16 +171,20 @@ if($action == 'order') { $id = $order->create($user); if($id < 0) { //error stuff + $fail++; + setEventMessage($langs->trans('OrderFail'), 'errors'); } $i++; } + if(!$fail) { + setEventMessage($langs->trans('OrderCreated'), 'mesgs'); + } } } /* * View */ - $htmlother=new FormOther($db); $title=$langs->trans('Replenishment'); From 787125cf125cee968ef49797546157d896fc88a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 12 Jun 2013 11:55:28 +0200 Subject: [PATCH 66/92] reformat --- htdocs/product/stock/replenish.php | 40 ++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 368b12141bf..2e0335a9bde 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -34,9 +34,12 @@ $langs->load("stocks"); $langs->load("orders"); // Security check -if ($user->societe_id) $socid=$user->societe_id; +if ($user->societe_id) { + $socid = $user->societe_id; +} $result=restrictedArea($user,'produit|service'); +//checks if a product has been ordered function ordered($product_id) { global $db; $sql = 'SELECT DISTINCT cfd.fk_product, SUM(cfd.qty) from '; @@ -58,7 +61,7 @@ function ordered($product_id) { } } else { - $error=$db->lasterror(); + $error = $db->lasterror(); dol_print_error($db); dol_syslog('replenish.php: ' . $error, LOG_ERROR); return $langs->trans('error'); @@ -77,8 +80,14 @@ $tobuy = GETPOST('tobuy'); $sortfield = GETPOST('sortfield','alpha'); $sortorder = GETPOST('sortorder','alpha'); $page = GETPOST('page','int'); -if (! $sortfield) $sortfield = 'stock_physique'; -if (! $sortorder) $sortorder = 'ASC'; + +if (!$sortfield) { + $sortfield = 'stock_physique'; +} + +if (!$sortorder) { + $sortorder = 'ASC'; +} $limit = $conf->liste_limit; $offset = $limit * $page ; @@ -279,10 +288,12 @@ if ($resql) { $head[1][2] = 'replenishorders'; dol_fiche_head($head, 'replenish', $title, 0, 'stock'); if ($sref || $snom || $sall || GETPOST('search')) { + $filters = '&sref=' . $sref . '&snom=' . $snom; + $filters .= '&sall=' . $sall; print_barre_liste($texte, $page, 'replenish.php', - '&sref=' . $sref . '&snom=' . $snom . '&sall=' . $sall, + $filters, $sortfield, $sortorder, '', @@ -290,10 +301,13 @@ if ($resql) { ); } else { + $filters = '&sref=' . $sref . '&snom=' . $snom; + $filters .= '&fourn_id=' . $fourn_id; + $filters .= (isset($type)?'&type=' . $type:''); print_barre_liste($texte, $page, 'replenish.php', - '&sref=$sref&snom=$snom&fourn_id=$fourn_id' . (isset($type)?'&type=$type':''), + $filters, $sortfield, $sortorder, '', @@ -336,8 +350,9 @@ if ($resql) { print ''; } - $param = (isset($type)? '&type=$type' : ''); - $param .= '&fourn_id=' . $fourn_id . '&snom='. $snom . '&sref=' . $sref; + $param = (isset($type)? '&type=' . $type : ''); + $param .= '&fourn_id=' . $fourn_id . '&snom='. $snom; + $param .= '&sref=' . $sref; // Lignes des titres print ''; @@ -566,10 +581,12 @@ if ($resql) { if ($num > $conf->liste_limit) { if ($sref || $snom || $sall || GETPOST('search')) { + $filters = '&sref=' . $sref . '&snom=' . $snom; + $filters .= '&sall=' . $sall; print_barre_liste('', $page, 'replenish.php', - '&sref=' . $sref . '&snom=' . $snom . '&sall=' . $sall, + $filters, $sortfield, $sortorder, '', @@ -579,10 +596,13 @@ if ($resql) { ); } else { + $filters = '&sref=' . $sref . '&snom=' . $snom; + $filters .= '&fourn_id=' . $fourn_id; + $filters .= (isset($type)? '&type=' . $type : ''); print_barre_liste('', $page, 'replenish.php', - "&sref=$sref&snom=$snom&fourn_id=$fourn_id" . (isset($type)?"&type=$type":""), + $filters, $sortfield, $sortorder, '', From 72afadb84ec998f488d3a937a94a61db2897f9fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 12 Jun 2013 12:01:22 +0200 Subject: [PATCH 67/92] fixed success message showing up even when you don't create orders --- htdocs/product/stock/replenish.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 2e0335a9bde..058f7e2e1ff 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -185,7 +185,7 @@ if($action == 'order') { } $i++; } - if(!$fail) { + if(!$fail && $id) { setEventMessage($langs->trans('OrderCreated'), 'mesgs'); } } From 2c3053b9eeb99ff26d23062b02d3c7c074b0f01c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 12 Jun 2013 14:50:32 +0200 Subject: [PATCH 68/92] selects --- htdocs/product/stock/replenish.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 058f7e2e1ff..a4d2d2b96d2 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -564,7 +564,7 @@ if ($resql) { $form = new Form($db); print ''; print $form->select_product_fourn_price($prod->id, - 'fourn' . $i); + 'fourn' . $i, 1); print ''; print ' '; print ""; From 1a41511874ff94f2b302716548b9448026879f49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 12 Jun 2013 14:56:29 +0200 Subject: [PATCH 69/92] redirect user after orders creation --- htdocs/product/stock/replenish.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index a4d2d2b96d2..3a6cc211f3f 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -187,6 +187,8 @@ if($action == 'order') { } if(!$fail && $id) { setEventMessage($langs->trans('OrderCreated'), 'mesgs'); + header('Location: replenishorders.php'); + exit; } } } From d1550173cd8471a921d9e9477065835d7296cd99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 12 Jun 2013 15:12:27 +0200 Subject: [PATCH 70/92] changed valid button label, position and look --- htdocs/product/stock/replenish.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 3a6cc211f3f..75f0f66a1a4 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -574,10 +574,11 @@ if ($resql) { $i++; } print ""; + print ''; print ''; print '
'; - $valid = $langs->trans("Validate"); - print ''; + $value = $langs->trans("CreateOrders"); + print ''; print '
'; print ''; From fe8eb1be9277ed10f70306be33378d4df3332004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Wed, 12 Jun 2013 18:13:34 +0200 Subject: [PATCH 71/92] code cleanup --- htdocs/product/stock/replenish.php | 129 ++++++----------------------- 1 file changed, 24 insertions(+), 105 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 75f0f66a1a4..4404780abae 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -26,7 +26,6 @@ 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'; $langs->load("products"); @@ -73,8 +72,6 @@ $sref = GETPOST('sref'); $snom = GETPOST('snom'); $sall = GETPOST('sall'); $type = GETPOST('type','int'); -$sbarcode = GETPOST('sbarcode'); -$catid = GETPOST('catid','int'); $tobuy = GETPOST('tobuy'); $sortfield = GETPOST('sortfield','alpha'); @@ -82,7 +79,7 @@ $sortorder = GETPOST('sortorder','alpha'); $page = GETPOST('page','int'); if (!$sortfield) { - $sortfield = 'stock_physique'; + $sortfield = 'p.ref'; } if (!$sortorder) { @@ -91,32 +88,6 @@ if (!$sortorder) { $limit = $conf->liste_limit; $offset = $limit * $page ; -// Load sale and categ filters -$search_sale = GETPOST('search_sale'); -$search_categ = GETPOST('search_categ'); - -// Get object canvas -//(By default, this is not defined, so standard usage of dolibarr) -$canvas = GETPOST('canvas'); -$objcanvas = ''; -if (! empty($canvas)) { - require_once DOL_DOCUMENT_ROOT . '/core/class/canvas.class.php'; - $objcanvas = new Canvas($db,$action); - $objcanvas->getCanvas('product', 'list', $canvas); -} - -if (! empty($_POST['button_removefilter_x'])) { - $sref = ''; - $snom = ''; - $sall = ''; - $search_sale = ''; - $search_categ = ''; - $type = ''; - $catid = ''; -} - - - /* * Actions */ @@ -179,7 +150,6 @@ if($action == 'order') { } $id = $order->create($user); if($id < 0) { - //error stuff $fail++; setEventMessage($langs->trans('OrderFail'), 'errors'); } @@ -196,29 +166,20 @@ if($action == 'order') { /* * View */ -$htmlother=new FormOther($db); +$title = $langs->trans('Replenishment'); -$title=$langs->trans('Replenishment'); - -$sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price'; +$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'; -// need this table joined to the select in order to filter by categ -if ($search_categ) { - $sql.= ", " . MAIN_DB_PREFIX . "categorie_product as cp"; -} -$sql .= ') LEFT JOIN ' . MAIN_DB_PREFIX . 'product_fournisseur_price as pf'; +$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 ($search_categ) { // Join for the needed table to filter by categ - $sql .= ' AND p.rowid = cp.fk_product'; -} + if ($sall) { $sql .= ' AND (p.ref LIKE "%'.$db->escape($sall).'%" '; $sql .= 'OR p.label LIKE "%'.$db->escape($sall).'%" '; @@ -237,9 +198,6 @@ if (dol_strlen($type)) { if ($sref) { $sql .= ' AND p.ref LIKE "%' . $sref . '%"'; } -if ($sbarcode) { - $sql .= ' AND p.barcode LIKE "%' . $sbarcode . '%"'; -} if ($snom) { $sql .= ' AND p.label LIKE "%' . $db->escape($snom) . '%"'; } @@ -249,17 +207,10 @@ $sql .= ' AND p.tobuy = 1'; if (!empty($canvas)) { $sql .= ' AND p.canvas = "' . $db->escape($canvas) . '"'; } -if($catid) { - $sql .= ' AND cp.fk_categorie = ' . $catid; -} $sql .= ' AND p.rowid = pf.fk_product'; -// Insert categ filter -if ($search_categ) { - $sql .= ' AND cp.fk_categorie = ' . $db->escape($search_categ); -} -$sql .= ' GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price'; +$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'; @@ -279,8 +230,7 @@ if ($resql) { $helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|'; $helpurl .= 'ES:Módulo_Stocks'; - $texte = $langs->trans('Replenishment'); - llxHeader('', $title, $helpurl, $texte); + llxHeader('', $title, $helpurl, $title); $head = array(); $head[0][0] = DOL_URL_ROOT.'/product/stock/replenish.php'; $head[0][1] = $title; @@ -316,15 +266,6 @@ if ($resql) { $num); } - if (!empty($catid)) { - print '
'; - $c = new Categorie($db); - $c->fetch($catid); - $ways = $c->print_all_ways(' > ', 'product/replenish.php'); - print ' > ' . $ways[0] . '
'; - print '

'; - } - print '
'; print ''; print ''; @@ -332,25 +273,8 @@ if ($resql) { print ''; print ''; print ''; - //print ''; - print ''; - // Filter on categories - $moreforfilter = ''; - if (!empty($conf->categorie->enabled)) { - $moreforfilter .= $langs->trans('Categories') . ': '; - $moreforfilter .= $htmlother->select_categories(0, - $search_categ, - 'search_categ' - ); - $moreforfilter .= '           '; - } - if ($moreforfilter) { - print ''; - print ''; - } + print '
'; - print $moreforfilter; - print '
'; $param = (isset($type)? '&type=' . $type : ''); $param .= '&fourn_id=' . $fourn_id . '&snom='. $snom; @@ -398,27 +322,20 @@ if ($resql) { $sortorder ); if($conf->global->USE_VIRTUAL_STOCK) { - print_liste_field_titre($langs->trans('VirtualStock'), - 'replenish.php', - '', - $param, - '', - 'align="right"', - $sortfield, - $sortorder - ); + $stocklabel = $langs->trans('VirtualStock'); } else { - print_liste_field_titre($langs->trans('PhysicalStock'), - 'replenish.php', - 'stock_physique', - $param, - '', - 'align="right"', - $sortfield, - $sortorder - ); + $stocklabel = $langs->trans('PhysicalStock'); } + print_liste_field_titre($stocklabel, + 'replenish.php', + 'stock_physique', + $param, + '', + 'align="right"', + $sortfield, + $sortorder + ); print_liste_field_titre($langs->trans('StockToBuy'), 'replenish.php', '', @@ -470,7 +387,6 @@ if ($resql) { print ''; print ''; print ''; @@ -532,6 +448,7 @@ if ($resql) { $objp->stock_physique = 0; } if($conf->global->USE_VIRTUAL_STOCK) { + //compute virtual stock $prod->fetch($prod->id); $result=$prod->load_stats_commande(0, '1,2'); if ($result < 0) { @@ -566,7 +483,9 @@ if ($resql) { $form = new Form($db); print ''; print ''; print ""; From 7abf23c47167d698a25e11b0d4b1a8702bd3d878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Thu, 13 Jun 2013 17:40:18 +0200 Subject: [PATCH 72/92] PSR coding style --- htdocs/product/stock/replenish.php | 266 ++++++++++++++--------------- 1 file changed, 128 insertions(+), 138 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 4404780abae..105fe45c739 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -39,30 +39,31 @@ if ($user->societe_id) { $result=restrictedArea($user,'produit|service'); //checks if a product has been ordered -function ordered($product_id) { +function ordered($product_id) +{ global $db; $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 cf.source = 42 '; + $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 cf.source = 42 '; $sql .= 'AND cf.fk_statut < 5 AND cfd.fk_product = ' . $product_id; $sql .= ' GROUP BY cfd.fk_product'; - + $resql = $db->query($sql); - if($resql) { + if ($resql) { $exists = $db->num_rows($resql); - if($exists) { + if ($exists) { $obj = $db->fetch_array($resql); + return $obj['SUM(cfd.qty)'] . ' ' . img_picto('','tick'); - } - else { + } else { return img_picto('', 'stcomm-1'); } - } - else { + } else { $error = $db->lasterror(); dol_print_error($db); dol_syslog('replenish.php: ' . $error, LOG_ERROR); + return $langs->trans('error'); } } @@ -93,13 +94,13 @@ $offset = $limit * $page ; */ //orders creation -if($action == 'order') { +if ($action == 'order') { $linecount = GETPOST('linecount', 'int'); unset($_POST['linecount']); - if($linecount > 0) { + if ($linecount > 0) { $suppliers = array(); - for($i = 0; $i < $linecount; $i++) { - if(GETPOST($i, 'alpha') === 'on' + for ($i = 0; $i < $linecount; $i++) { + if(GETPOST($i, 'alpha') === 'on' && GETPOST('fourn' . $i, 'int') > 0) { //one line $supplierpriceid = GETPOST('fourn'.$i, 'int'); //get all the parameters needed to create a line @@ -110,7 +111,7 @@ if($action == 'order') { $sql .= MAIN_DB_PREFIX . 'product_fournisseur_price'; $sql .= ' WHERE rowid = ' . $supplierpriceid; $resql = $db->query($sql); - if($resql && $db->num_rows($resql) > 0) { + if ($resql && $db->num_rows($resql) > 0) { //might need some value checks $obj = $db->fetch_object($resql); $line = new CommandeFournisseurLigne($db); @@ -125,8 +126,7 @@ if($action == 'order') { $line->total_ttc = $line->total_ht + $line->total_tva; $line->ref_fourn = $obj->ref_fourn; $suppliers[$obj->fk_soc]['lines'][] = $line; - } - else { + } else { $error=$db->lasterror(); dol_print_error($db); dol_syslog('replenish.php: '.$error, LOG_ERROR); @@ -140,22 +140,22 @@ if($action == 'order') { $i = 0; $orders = array(); $suppliersid = array_keys($suppliers); - foreach($suppliers as $supplier) { + 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) { + foreach ($supplier['lines'] as $line) { $order->lines[] = $line; } $id = $order->create($user); - if($id < 0) { + if ($id < 0) { $fail++; setEventMessage($langs->trans('OrderFail'), 'errors'); } $i++; } - if(!$fail && $id) { + if (!$fail && $id) { setEventMessage($langs->trans('OrderCreated'), 'mesgs'); header('Location: replenishorders.php'); exit; @@ -190,8 +190,7 @@ if ($sall) { if (dol_strlen($type)) { if ($type == 1) { $sql .= ' AND p.fk_product_type = 1'; - } - else { + } else { $sql .= ' AND p.fk_product_type != 1'; } } @@ -242,27 +241,26 @@ if ($resql) { if ($sref || $snom || $sall || GETPOST('search')) { $filters = '&sref=' . $sref . '&snom=' . $snom; $filters .= '&sall=' . $sall; - print_barre_liste($texte, - $page, - 'replenish.php', - $filters, - $sortfield, + print_barre_liste($texte, + $page, + 'replenish.php', + $filters, + $sortfield, $sortorder, '', $num ); - } - else { + } 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, - '', + print_barre_liste($texte, + $page, + 'replenish.php', + $filters, + $sortfield, + $sortorder, + '', $num); } @@ -283,84 +281,83 @@ if ($resql) { // Lignes des titres print ''; print ''; - print_liste_field_titre($langs->trans('Ref'), - 'replenish.php', - 'p.ref', - $param, - '', - '', - $sortfield, + print_liste_field_titre($langs->trans('Ref'), + 'replenish.php', + 'p.ref', + $param, + '', + '', + $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('Label'), - 'replenish.php', - 'p.label', - $param, - '', - '', - $sortfield, + print_liste_field_titre($langs->trans('Label'), + 'replenish.php', + 'p.label', + $param, + '', + '', + $sortfield, $sortorder ); if (!empty($conf->service->enabled) && $type == 1) { - print_liste_field_titre($langs->trans('Duration'), - 'replenish.php', - 'p.duration', - $param, - '', - 'align="center"', - $sortfield, + print_liste_field_titre($langs->trans('Duration'), + 'replenish.php', + 'p.duration', + $param, + '', + 'align="center"', + $sortfield, $sortorder ); } - print_liste_field_titre($langs->trans('DesiredStock'), - 'replenish.php', - 'p.desiredstock', - $param, - '', - 'align="right"', - $sortfield, + print_liste_field_titre($langs->trans('DesiredStock'), + 'replenish.php', + 'p.desiredstock', + $param, + '', + 'align="right"', + $sortfield, $sortorder ); - if($conf->global->USE_VIRTUAL_STOCK) { + if ($conf->global->USE_VIRTUAL_STOCK) { $stocklabel = $langs->trans('VirtualStock'); - } - else { + } else { $stocklabel = $langs->trans('PhysicalStock'); } - print_liste_field_titre($stocklabel, - 'replenish.php', - 'stock_physique', - $param, - '', - 'align="right"', - $sortfield, + print_liste_field_titre($stocklabel, + 'replenish.php', + 'stock_physique', + $param, + '', + 'align="right"', + $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('StockToBuy'), - 'replenish.php', - '', - $param, - '', - 'align="right"', - $sortfield, + print_liste_field_titre($langs->trans('StockToBuy'), + 'replenish.php', + '', + $param, + '', + 'align="right"', + $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('Ordered'), - 'replenish.php', - '', - $param, - '', - 'align="right"', - $sortfield, + print_liste_field_titre($langs->trans('Ordered'), + 'replenish.php', + '', + $param, + '', + 'align="right"', + $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('Supplier'), - 'replenish.php', - '', - $param, - '', - 'align="right"', - $sortfield, + print_liste_field_titre($langs->trans('Supplier'), + 'replenish.php', + '', + $param, + '', + 'align="right"', + $sortfield, $sortorder ); print ''; @@ -395,10 +392,10 @@ if ($resql) { $var = True; while ($i < min($num, $limit)) { $objp = $db->fetch_object($resql); - if($conf->global->STOCK_SUPPORTS_SERVICES + if ($conf->global->STOCK_SUPPORTS_SERVICES || $objp->fk_product_type == 0) { // Multilangs - if(! empty($conf->global->MAIN_MULTILANGS)) { + if (! empty($conf->global->MAIN_MULTILANGS)) { $sql = 'SELECT label'; $sql .= ' FROM ' . MAIN_DB_PREFIX . 'product_lang'; $sql .= ' WHERE fk_product = ' . $objp->rowid; @@ -406,7 +403,7 @@ if ($resql) { $sql .= ' LIMIT 1'; $result = $db->query($sql); - if($result) { + if ($result) { $objtp = $db->fetch_object($result); if (!empty($objtp->label)) { $objp->label = $objtp->label; @@ -426,28 +423,25 @@ if ($resql) { print ''; print ''; - if(!empty($conf->service->enabled) && $type == 1) { + if (!empty($conf->service->enabled) && $type == 1) { print ''; } print ''; print ''; $form = new Form($db); print ''; @@ -505,31 +498,30 @@ if ($resql) { if ($sref || $snom || $sall || GETPOST('search')) { $filters = '&sref=' . $sref . '&snom=' . $snom; $filters .= '&sall=' . $sall; - print_barre_liste('', - $page, - 'replenish.php', - $filters, - $sortfield, - $sortorder, - '', - $num, - 0, + print_barre_liste('', + $page, + 'replenish.php', + $filters, + $sortfield, + $sortorder, + '', + $num, + 0, '' ); - } - else { + } 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, + print_barre_liste('', + $page, + 'replenish.php', + $filters, + $sortfield, + $sortorder, + '', + $num, + 0, '' ); } @@ -537,11 +529,9 @@ if ($resql) { $db->free($resql); -} -else { +} else { dol_print_error($db); } llxFooter(); $db->close(); -?> From 4b90157aa24cfa6818f18b196b5057b782027c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Fri, 14 Jun 2013 12:27:32 +0200 Subject: [PATCH 73/92] switch from print to echo --- htdocs/product/stock/replenish.php | 141 ++++++++++++----------- htdocs/product/stock/replenishorders.php | 107 +++++++++-------- 2 files changed, 124 insertions(+), 124 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 105fe45c739..728c5713261 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -264,23 +264,23 @@ if ($resql) { $num); } - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + echo '', + '', + '', + '', + '', + '', + '', - print '
 '; print ''; - print ''; print '
'; print $form->select_product_fourn_price($prod->id, - 'fourn' . $i, 1); + 'fourn' . $i, + 1 + ); print ' 
  ' . $objp->label . ''; - if(preg_match('/([0-9]+)y/i', $objp->duration, $regs)) { + if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) { print $regs[1] . ' ' . $langs->trans('DurationYear'); - } - else if(preg_match('/([0-9]+)m/i', $objp->duration, $regs)) { + } elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) { print $regs[1] . ' ' . $langs->trans('DurationMonth'); - } - else if(preg_match('/([0-9]+)d/i', $objp->duration, $regs)) { + } elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) { print $regs[1] . ' ' . $langs->trans('DurationDay'); - } - else { + } else { print $objp->duration; } print '' . $objp->desiredstock . ''; - if(!$objp->stock_physique) { + if (!$objp->stock_physique) { $objp->stock_physique = 0; } - if($conf->global->USE_VIRTUAL_STOCK) { + if ($conf->global->USE_VIRTUAL_STOCK) { //compute virtual stock $prod->fetch($prod->id); $result=$prod->load_stats_commande(0, '1,2'); @@ -461,11 +455,10 @@ if ($resql) { } $stock_commande_fournisseur = $prod->stats_commande_fournisseur['qty']; $stock = $objp->stock_physique - $stock_commande_client + $stock_commande_fournisseur; - } - else { + } else { $stock = $objp->stock_physique; } - if ($objp->seuil_stock_alerte + if ($objp->seuil_stock_alerte && ($stock < $objp->seuil_stock_alerte)) { $warn = $langs->trans('StockTooLow'); print img_warning($warn) . ' '; @@ -482,8 +475,8 @@ if ($resql) { print ''; - print $form->select_product_fourn_price($prod->id, - 'fourn' . $i, + print $form->select_product_fourn_price($prod->id, + 'fourn' . $i, 1 ); print '
'; + '
'; $param = (isset($type)? '&type=' . $type : ''); $param .= '&fourn_id=' . $fourn_id . '&snom='. $snom; $param .= '&sref=' . $sref; // Lignes des titres - print ''; - print ''; + echo '', + ''; print_liste_field_titre($langs->trans('Ref'), 'replenish.php', 'p.ref', @@ -360,32 +360,32 @@ if ($resql) { $sortfield, $sortorder ); - print ''; - print ''; + echo '', + '', // Lignes des champs de filtre - print ''; - print ''; - print ''; - print ''; + '', + '', + '', + ''; if (!empty($conf->service->enabled) && $type == 1) { - print ''; + echo ''; } - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + echo '', + '', + '', + '', + '', + '', + ''; $prod = new Product($db); @@ -410,34 +410,34 @@ if ($resql) { } } } - + $form = new Form($db); $var =! $var; - print ''; - print ''; - print ''; - print ''; - print ''; + echo '', + '', + '', + '', + ''; if (!empty($conf->service->enabled) && $type == 1) { - print ''; + echo ''; } - print ''; - print ''; //depending on conf, use either physical stock or //virtual stock to compute the stock to buy value $stocktobuy = $objp->desiredstock - $stock; - print ''; - print ''; - print ''; - $form = new Form($db); - print '', + '', + '', + '', + '', + ''; - print ''; - print ""; + ), + '', + '', + ''; } $i++; } - print "
 
  
 
 '; - print ''; - print ''; - print ''; - print '
 ', + '', + '', + '', + ''; - print ' '; - print '', + ' ', + '     '; - print ''; - print '
     ', + '', + '
'; $prod->ref = $objp->ref; $prod->id = $objp->rowid; $prod->type = $objp->fk_product_type; - print $prod->getNomUrl(1, '', 16); - print '' . $objp->label . '
', + $prod->getNomUrl(1, '', 16), + '' . $objp->label . ''; if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) { - print $regs[1] . ' ' . $langs->trans('DurationYear'); + $duration = $regs[1] . ' ' . $langs->trans('DurationYear'); } elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) { - print $regs[1] . ' ' . $langs->trans('DurationMonth'); + $duration = $regs[1] . ' ' . $langs->trans('DurationMonth'); } elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) { - print $regs[1] . ' ' . $langs->trans('DurationDay'); + $duration = $regs[1] . ' ' . $langs->trans('DurationDay'); } else { - print $objp->duration; + $duration = $objp->duration; } - print '', + $duration, + '' . $objp->desiredstock . ''; + if (!$objp->stock_physique) { $objp->stock_physique = 0; } @@ -461,38 +461,39 @@ if ($resql) { if ($objp->seuil_stock_alerte && ($stock < $objp->seuil_stock_alerte)) { $warn = $langs->trans('StockTooLow'); - print img_warning($warn) . ' '; + $stock = img_warning($warn) . ' ' . $stock; } - print $stock; - print ''.$stocktobuy.''; - print ordered($prod->id); - print ''; - print $form->select_product_fourn_price($prod->id, + echo '' . $objp->desiredstock . '', + $stock, + ''.$stocktobuy.'', + ordered($prod->id), + '', + $form->select_product_fourn_price($prod->id, 'fourn' . $i, 1 - ); - print ' 
 
"; - print ''; - print ''; - print '
'; $value = $langs->trans("CreateOrders"); - print ''; - print '
'; - print '
'; + echo '', + '', + '', + '
', + '', + '
', + ''; if ($num > $conf->liste_limit) { if ($sref || $snom || $sall || GETPOST('search')) { diff --git a/htdocs/product/stock/replenishorders.php b/htdocs/product/stock/replenishorders.php index d3fd138b01d..8fd3a110205 100644 --- a/htdocs/product/stock/replenishorders.php +++ b/htdocs/product/stock/replenishorders.php @@ -143,9 +143,9 @@ if ($resql) { '', $num ); - print '
'; - print ''; - print ''; + echo '', + '
', + ''; print_liste_field_titre($langs->trans('Ref'), $_SERVER['PHP_SELF'], 'cf.ref', @@ -200,30 +200,29 @@ if ($resql) { $sortfield, $sortorder ); - print ''; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print '', + '', + '', + '', + '', + '', + '', + ''; - print ''; + echo '', + '', + ''; $var = true; $userstatic = new User($db); @@ -232,54 +231,54 @@ if ($resql) { $obj = $db->fetch_object($resql); $var = !$var; - print ""; - // Ref - print ''; + echo '', + // Ref + ''; // Company - print ''; + echo ''; // Author $userstatic->id = $obj->fk_user_author; $userstatic->login = $obj->login; - print ''; + echo '', // Amount - print ''; + ''; // Date - print ''; + echo '', // Statut - print ''; - print ''; + '', + ''; $i++; } - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + echo '
', + '', + '', + '', + '', + '', + '', + '', + '', + '', + ''; $src = DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/search.png'; $value = dol_escape_htmltag($langs->trans('Search')); - print ''; - print '
'; $href = DOL_URL_ROOT . '/fourn/commande/fiche.php?id=' . $obj->rowid; - print ''; - print img_object($langs->trans('ShowOrder'), 'order') . ' ' . $obj->ref; - print '
', + '', + img_object($langs->trans('ShowOrder'), 'order') . ' ' . $obj->ref, + ''; $href = DOL_URL_ROOT . '/fourn/fiche.php?socid=' . $obj->socid; - print ''; - print img_object($langs->trans('ShowCompany'), 'company') . ' '; - print $obj->nom . '', + '', + img_object($langs->trans('ShowCompany'), 'company'), ' ', + $obj->nom . ''; - if ($userstatic->id) { - print $userstatic->getLoginUrl(1); + $txt = $userstatic->getLoginUrl(1); } else { - print ' '; + $txt = ' '; } - - print '', + $txt, + ''; - print price($obj->total_ttc); - print '', + price($obj->total_ttc), + ''; if ($obj->dc) { - print dol_print_date($db->jdate($obj->dc), 'day'); + $date = dol_print_date($db->jdate($obj->dc), 'day'); } else { - print '-'; + $date = '-'; } - print '', + $date, + ''; - print $commandestatic->LibStatut($obj->fk_statut, 5); - print '
', + $commandestatic->LibStatut($obj->fk_statut, 5), + '
'; - print '
'; + echo '', + ''; $db->free($resql); } From 5062eb80065e172c6d23662ac4e35d4181f24ec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Thu, 27 Jun 2013 15:54:04 +0200 Subject: [PATCH 74/92] check types on getpost + date research --- htdocs/product/stock/replenish.php | 12 ++++---- htdocs/product/stock/replenishorders.php | 39 +++++++++++++++--------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 728c5713261..0b0f1235a62 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -69,11 +69,11 @@ function ordered($product_id) } $action = GETPOST('action','alpha'); -$sref = GETPOST('sref'); -$snom = GETPOST('snom'); -$sall = GETPOST('sall'); +$sref = GETPOST('sref', 'alpha'); +$snom = GETPOST('snom', 'alpha'); +$sall = GETPOST('sall', 'alpha'); $type = GETPOST('type','int'); -$tobuy = GETPOST('tobuy'); +$tobuy = GETPOST('tobuy', 'int'); $sortfield = GETPOST('sortfield','alpha'); $sortorder = GETPOST('sortorder','alpha'); @@ -238,7 +238,7 @@ if ($resql) { $head[1][1] = $langs->trans("ReplenishmentOrders"); $head[1][2] = 'replenishorders'; dol_fiche_head($head, 'replenish', $title, 0, 'stock'); - if ($sref || $snom || $sall || GETPOST('search')) { + if ($sref || $snom || $sall || GETPOST('search', 'alpha')) { $filters = '&sref=' . $sref . '&snom=' . $snom; $filters .= '&sall=' . $sall; print_barre_liste($texte, @@ -496,7 +496,7 @@ if ($resql) { ''; if ($num > $conf->liste_limit) { - if ($sref || $snom || $sall || GETPOST('search')) { + if ($sref || $snom || $sall || GETPOST('search', 'alpha')) { $filters = '&sref=' . $sref . '&snom=' . $snom; $filters .= '&sall=' . $sall; print_barre_liste('', diff --git a/htdocs/product/stock/replenishorders.php b/htdocs/product/stock/replenishorders.php index 8fd3a110205..c4b8bf657a2 100644 --- a/htdocs/product/stock/replenishorders.php +++ b/htdocs/product/stock/replenishorders.php @@ -53,16 +53,16 @@ dol_fiche_head($head, 0, 'stock'); $commandestatic = new CommandeFournisseur($db); -$sref = GETPOST('search_ref'); -$snom = GETPOST('search_nom'); -$suser = GETPOST('search_user'); -$sttc = GETPOST('search_ttc'); -$sall = GETPOST('search_all'); -$sdate = GETPOST('search_date'); +$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'); -$sortorder = GETPOST('sortorder'); -$sortfield = GETPOST('sortfield'); +$sortorder = GETPOST('sortorder', 'alpha'); +$sortfield = GETPOST('sortfield', 'alpha'); if (!$sortorder) { $sortorder = 'DESC'; @@ -109,10 +109,21 @@ if ($sttc) { } if ($sdate) { $elts = explode('/', $sdate); - $date = date('Y-m-d', - mktime(0, 0, 0, $elts[1], $elts[0], $elts[2]) - ); - $sql .= ' AND cf.date_creation LIKE "' . $date . '%"'; + $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) . '%" '; @@ -122,8 +133,8 @@ if ($socid) { $sql .= ' AND s.rowid = ' . $socid; } -if (GETPOST('statut')) { - $sql .= ' AND fk_statut = ' . GETPOST('statut'); +if (GETPOST('statut', 'int')) { + $sql .= ' AND fk_statut = ' . GETPOST('statut', 'int'); } $sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder . ' '; From e3d5f086b6a3e6b190f42403a1ee0fc4243e6a29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Thu, 27 Jun 2013 15:54:29 +0200 Subject: [PATCH 75/92] background color --- htdocs/admin/stock.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/admin/stock.php b/htdocs/admin/stock.php index 54221551469..f7a45aff8d2 100644 --- a/htdocs/admin/stock.php +++ b/htdocs/admin/stock.php @@ -255,6 +255,7 @@ print ''; print " ".$langs->trans("RuleForStockReplenishment")."\n"; print "  \n"; print ''."\n"; +$var = !$var; print ""; print ''.$langs->trans("UseVirtualStock").''; print ''; From 357dc3e530af7c4958642ecab4f1711946de0169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Thu, 27 Jun 2013 18:31:18 +0200 Subject: [PATCH 76/92] datepicker --- htdocs/product/stock/replenishorders.php | 44 ++++++++++++++++-------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/htdocs/product/stock/replenishorders.php b/htdocs/product/stock/replenishorders.php index c4b8bf657a2..b79af87421c 100644 --- a/htdocs/product/stock/replenishorders.php +++ b/htdocs/product/stock/replenishorders.php @@ -108,21 +108,34 @@ if ($sttc) { $sql .= ' AND cf.total_ttc = ' . price2num($sttc); } if ($sdate) { - $elts = explode('/', $sdate); - $datearray = array(); - if($elts[2]) - { - $datearray[0] = $elts[2]; + 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); } - 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) { @@ -211,6 +224,7 @@ if ($resql) { $sortfield, $sortorder ); + $form = new Form($db); echo '', '', '', @@ -226,7 +240,7 @@ if ($resql) { '', '', '', - '', + $form->select_date('', 'search_date', 0, 0, 1, "", 1, 0, 1, 0, ''), '', ''; $src = DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/search.png'; From 435deae5e9d254d98a14471cad98bfe50ed3d5f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Fri, 28 Jun 2013 16:07:34 +0200 Subject: [PATCH 77/92] removed one-liner --- htdocs/fourn/class/fournisseur.commande.class.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index f7e3e73f15b..c0d1635a05f 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -922,6 +922,10 @@ class CommandeFournisseur extends CommonOrder $error=0; $now=dol_now(); + if(!$this->source) + { + $this->source = 0; + } /* On positionne en mode brouillon la commande */ $this->brouillon = 1; @@ -952,7 +956,7 @@ class CommandeFournisseur extends CommonOrder //$sql.= ", ".$this->db->idate($now); $sql.= ", ".$user->id; $sql.= ", 0"; - $sql.= ", ".($this->source? $this->source : 0); + $sql.= ", " . $this->source; $sql.= ", '".$conf->global->COMMANDE_SUPPLIER_ADDON_PDF."'"; //$sql.= ", ".$this->mode_reglement_id; $sql.= ")"; From a607cb677ddafdc7a955d6a25a72def44d5ddead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Mon, 1 Jul 2013 18:46:32 +0200 Subject: [PATCH 78/92] Bug fix: stock to buy now computes correctly when the stock too low picto is present --- htdocs/product/stock/replenish.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 0b0f1235a62..2c2bd754b04 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -458,10 +458,11 @@ if ($resql) { } else { $stock = $objp->stock_physique; } + $warning=''; if ($objp->seuil_stock_alerte && ($stock < $objp->seuil_stock_alerte)) { $warn = $langs->trans('StockTooLow'); - $stock = img_warning($warn) . ' ' . $stock; + $warning = img_warning($warn) . ' '; } //depending on conf, use either physical stock or //virtual stock to compute the stock to buy value @@ -470,7 +471,7 @@ if ($resql) { '', $stock, '', - ''.$stocktobuy.'', + '', $warning, $stocktobuy , '', '', '', ordered($prod->id), From 3df097695d1714827b2ab454de21bb79982e8343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Tue, 2 Jul 2013 18:32:50 +0200 Subject: [PATCH 79/92] removed useless variable --- htdocs/product/stock/replenish.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 2c2bd754b04..dcc628e784f 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -461,8 +461,7 @@ if ($resql) { $warning=''; if ($objp->seuil_stock_alerte && ($stock < $objp->seuil_stock_alerte)) { - $warn = $langs->trans('StockTooLow'); - $warning = img_warning($warn) . ' '; + $warning = img_warning($langs->trans('StockTooLow')) . ' '; } //depending on conf, use either physical stock or //virtual stock to compute the stock to buy value From c09b05a05f0fede8b034b734a75e7af7adf80583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Wed, 3 Jul 2013 12:12:32 +0200 Subject: [PATCH 80/92] Better wording --- htdocs/langs/en_US/stocks.lang | 2 +- htdocs/langs/fr_FR/stocks.lang | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index 63d0724fb29..bbc5a6fe261 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -89,7 +89,7 @@ SelectWarehouseForStockIncrease=Choose warehouse to use for stock increase NoStockAction=No stock action LastWaitingSupplierOrders=Orders waiting for receptions DesiredStock=Desired stock -StockToBuy=Stock to order +StockToBuy=To order Replenishment=Replenishment ReplenishmentOrders=Replenishment orders UseVirtualStock=Use virtual stock instead of physical stock diff --git a/htdocs/langs/fr_FR/stocks.lang b/htdocs/langs/fr_FR/stocks.lang index d40278b6d45..efdfa28a6da 100644 --- a/htdocs/langs/fr_FR/stocks.lang +++ b/htdocs/langs/fr_FR/stocks.lang @@ -89,7 +89,7 @@ SelectWarehouseForStockIncrease=Sélectionner l'entrepôt à utiliser pour l'inc NoStockAction=Pas d'action sur l'entrepôt LastWaitingSupplierOrders=Commandes en attente de réception DesiredStock=Stock désiré -StockToBuy=Stock à commander +StockToBuy=À commander Replenishment=Réapprovisionnement ReplenishmentOrders=Commandes de réapprovisionnement UseVirtualStock=Utiliser le stock théorique à la place du stock physique From 6bf95db95eeb2a6a347d5936e356f5d721682ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Thu, 4 Jul 2013 18:57:20 +0200 Subject: [PATCH 81/92] checkbox + improve order detection --- .../product/stock/lib/replenishment.lib.php | 106 ++++++++++++++++++ htdocs/product/stock/replenish.php | 98 ++++++++-------- htdocs/product/stock/replenishorders.php | 100 +++++++++-------- 3 files changed, 207 insertions(+), 97 deletions(-) create mode 100644 htdocs/product/stock/lib/replenishment.lib.php diff --git a/htdocs/product/stock/lib/replenishment.lib.php b/htdocs/product/stock/lib/replenishment.lib.php new file mode 100644 index 00000000000..0283c538d53 --- /dev/null +++ b/htdocs/product/stock/lib/replenishment.lib.php @@ -0,0 +1,106 @@ + + * + * 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 + */ + +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'); + } +} + +?> diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index dcc628e784f..621c1b08c92 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -27,6 +27,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 './lib/replenishment.lib.php'; $langs->load("products"); $langs->load("stocks"); @@ -39,34 +40,7 @@ if ($user->societe_id) { $result=restrictedArea($user,'produit|service'); //checks if a product has been ordered -function ordered($product_id) -{ - global $db; - $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 cf.source = 42 '; - $sql .= 'AND cf.fk_statut < 5 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 img_picto('', 'stcomm-1'); - } - } else { - $error = $db->lasterror(); - dol_print_error($db); - dol_syslog('replenish.php: ' . $error, LOG_ERROR); - - return $langs->trans('error'); - } -} $action = GETPOST('action','alpha'); $sref = GETPOST('sref', 'alpha'); @@ -94,6 +68,7 @@ $offset = $limit * $page ; */ //orders creation +//could go in the lib if ($action == 'order') { $linecount = GETPOST('linecount', 'int'); unset($_POST['linecount']); @@ -280,7 +255,7 @@ if ($resql) { // Lignes des titres echo '', - ' '; + ''; print_liste_field_titre($langs->trans('Ref'), 'replenish.php', 'p.ref', @@ -415,28 +390,7 @@ if ($resql) { $prod->ref = $objp->ref; $prod->id = $objp->rowid; $prod->type = $objp->fk_product_type; - echo '', - '', - '', - $prod->getNomUrl(1, '', 16), - '', - '' . $objp->label . '', - ''; - - if (!empty($conf->service->enabled) && $type == 1) { - if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) { - $duration = $regs[1] . ' ' . $langs->trans('DurationYear'); - } elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) { - $duration = $regs[1] . ' ' . $langs->trans('DurationMonth'); - } elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) { - $duration = $regs[1] . ' ' . $langs->trans('DurationDay'); - } else { - $duration = $objp->duration; - } - echo '', - $duration, - ''; - } + $ordered = ordered($prod->id); if (!$objp->stock_physique) { $objp->stock_physique = 0; @@ -466,6 +420,38 @@ if ($resql) { //depending on conf, use either physical stock or //virtual stock to compute the stock to buy value $stocktobuy = $objp->desiredstock - $stock; + + if($ordered) { + $picto = img_picto('','tick'); + if($ordered >= $stocktobuy) { + $disabled = 'disabled="disabled"'; + } + } else { + $picto = img_picto('', 'stcomm-1'); + } + echo '', + '', + '', + $prod->getNomUrl(1, '', 16), + '', + '' . $objp->label . '', + ''; + + if (!empty($conf->service->enabled) && $type == 1) { + if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) { + $duration = $regs[1] . ' ' . $langs->trans('DurationYear'); + } elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) { + $duration = $regs[1] . ' ' . $langs->trans('DurationMonth'); + } elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) { + $duration = $regs[1] . ' ' . $langs->trans('DurationDay'); + } else { + $duration = $objp->duration; + } + echo '', + $duration, + ''; + } + echo '' . $objp->desiredstock . '', '', $stock, @@ -473,7 +459,7 @@ if ($resql) { '', $warning, $stocktobuy , '', '', '', - ordered($prod->id), + $ordered, ' ', $picto, '', '', $form->select_product_fourn_price($prod->id, @@ -529,7 +515,15 @@ if ($resql) { } $db->free($resql); - +echo ' '; } else { dol_print_error($db); } diff --git a/htdocs/product/stock/replenishorders.php b/htdocs/product/stock/replenishorders.php index b79af87421c..d004ef47884 100644 --- a/htdocs/product/stock/replenishorders.php +++ b/htdocs/product/stock/replenishorders.php @@ -27,6 +27,7 @@ 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"); @@ -75,7 +76,7 @@ if (!$sortfield) { $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.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'; @@ -90,7 +91,14 @@ $sql .= 'ON cf.fk_user_author = u.rowid'; $sql .= ' WHERE cf.fk_soc = s.rowid '; $sql .= ' AND cf.entity = ' . $conf->entity; $sql .= ' AND cf.source = 42'; -$sql .= ' AND cf.fk_statut < 5'; + +if ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) { + $sql .= ' AND cf.fk_statut < 3'; +} else if ($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; @@ -149,11 +157,11 @@ if ($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; @@ -256,50 +264,52 @@ if ($resql) { $obj = $db->fetch_object($resql); $var = !$var; - $href = DOL_URL_ROOT . '/fourn/commande/fiche.php?id=' . $obj->rowid; - echo '', - // Ref - '', - '', - img_object($langs->trans('ShowOrder'), 'order') . ' ' . $obj->ref, - ''; + if(!dispatched($obj->rowid)) { + $href = DOL_URL_ROOT . '/fourn/commande/fiche.php?id=' . $obj->rowid; + echo '', + // Ref + '', + '', + img_object($langs->trans('ShowOrder'), 'order') . ' ' . $obj->ref, + ''; - // Company - $href = DOL_URL_ROOT . '/fourn/fiche.php?socid=' . $obj->socid; - echo '', - '', - img_object($langs->trans('ShowCompany'), 'company'), ' ', - $obj->nom . ''; + // Company + $href = DOL_URL_ROOT . '/fourn/fiche.php?socid=' . $obj->socid; + echo '', + '', + img_object($langs->trans('ShowCompany'), 'company'), ' ', + $obj->nom . ''; - // Author - $userstatic->id = $obj->fk_user_author; - $userstatic->login = $obj->login; - if ($userstatic->id) { - $txt = $userstatic->getLoginUrl(1); - } else { - $txt = ' '; + // Author + $userstatic->id = $obj->fk_user_author; + $userstatic->login = $obj->login; + if ($userstatic->id) { + $txt = $userstatic->getLoginUrl(1); + } else { + $txt = ' '; + } + echo '', + $txt, + '', + // Amount + '', + price($obj->total_ttc), + ''; + // Date + if ($obj->dc) { + $date = dol_print_date($db->jdate($obj->dc), 'day'); + } else { + $date = '-'; + } + echo '', + $date, + '', + // Statut + '', + $commandestatic->LibStatut($obj->fk_statut, 5), + '', + ''; } - echo '', - $txt, - '', - // Amount - '', - price($obj->total_ttc), - ''; - // Date - if ($obj->dc) { - $date = dol_print_date($db->jdate($obj->dc), 'day'); - } else { - $date = '-'; - } - echo '', - $date, - '', - // Statut - '', - $commandestatic->LibStatut($obj->fk_statut, 5), - '', - ''; $i++; } echo '', From 9ff183d4328f924270c8b2211fd84160e377a6a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Fri, 5 Jul 2013 11:17:53 +0200 Subject: [PATCH 82/92] debug checkbox + use textfields in the to order column --- htdocs/product/stock/replenish.php | 17 +++++++++-------- htdocs/product/stock/replenishorders.php | 1 - 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 621c1b08c92..65ef6f33415 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -308,7 +308,7 @@ if ($resql) { $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('StockToBuy'), + print_liste_field_titre($langs->trans('Ordered'), 'replenish.php', '', $param, @@ -317,7 +317,7 @@ if ($resql) { $sortfield, $sortorder ); - print_liste_field_titre($langs->trans('Ordered'), + print_liste_field_titre($langs->trans('StockToBuy'), 'replenish.php', '', $param, @@ -419,11 +419,11 @@ if ($resql) { } //depending on conf, use either physical stock or //virtual stock to compute the stock to buy value - $stocktobuy = $objp->desiredstock - $stock; - - if($ordered) { + $stocktobuy = max($objp->desiredstock - $stock - $ordered, 0); + $disabled = ''; + if($ordered > 0) { $picto = img_picto('','tick'); - if($ordered >= $stocktobuy) { + if($ordered + $stock >= $objp->desiredstock) { $disabled = 'disabled="disabled"'; } } else { @@ -456,11 +456,12 @@ if ($resql) { '', $stock, '', - '', $warning, $stocktobuy , '', - '', '', $ordered, ' ', $picto, '', + '', $warning, + '', + '', '', $form->select_product_fourn_price($prod->id, 'fourn' . $i, diff --git a/htdocs/product/stock/replenishorders.php b/htdocs/product/stock/replenishorders.php index d004ef47884..e22f472f21d 100644 --- a/htdocs/product/stock/replenishorders.php +++ b/htdocs/product/stock/replenishorders.php @@ -90,7 +90,6 @@ $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; -$sql .= ' AND cf.source = 42'; if ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) { $sql .= ' AND cf.fk_statut < 3'; From d4052f7b9c1e9fcec36247b05a2c148018e7f1ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Fri, 5 Jul 2013 12:10:45 +0200 Subject: [PATCH 83/92] warning message if you try to create orders without selecting any product --- htdocs/langs/en_US/stocks.lang | 1 + htdocs/langs/fr_FR/stocks.lang | 1 + htdocs/product/stock/replenish.php | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index bbc5a6fe261..5f6b45cff1e 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -94,3 +94,4 @@ Replenishment=Replenishment ReplenishmentOrders=Replenishment orders UseVirtualStock=Use virtual stock instead of physical stock RuleForStockReplenishment=Rule for stocks replenishment +SelectProduct=Select at least one product diff --git a/htdocs/langs/fr_FR/stocks.lang b/htdocs/langs/fr_FR/stocks.lang index efdfa28a6da..643bcc955fa 100644 --- a/htdocs/langs/fr_FR/stocks.lang +++ b/htdocs/langs/fr_FR/stocks.lang @@ -94,3 +94,4 @@ Replenishment=Réapprovisionnement ReplenishmentOrders=Commandes de réapprovisionnement UseVirtualStock=Utiliser le stock théorique à la place du stock physique RuleForStockReplenishment=Règle de gestion du réapprovisionnement des stocks +SelectProduct=Sélectionnez au moins un produit diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 65ef6f33415..cdb8e63077c 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -71,12 +71,14 @@ $offset = $limit * $page ; //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'); @@ -135,6 +137,9 @@ if ($action == 'order') { header('Location: replenishorders.php'); exit; } + } + if ($box == 0){ + setEventMessage($langs->trans('SelectProduct'), 'warnings'); } } From 5643a714ce1da7a017b91bcc3fca7bba288b3ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Salvador?= Date: Fri, 5 Jul 2013 12:14:41 +0200 Subject: [PATCH 84/92] changed tab name --- htdocs/product/stock/replenish.php | 4 ++-- htdocs/product/stock/replenishorders.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index cdb8e63077c..eda18d09f42 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -146,7 +146,7 @@ if ($action == 'order') { /* * View */ -$title = $langs->trans('Replenishment'); +$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'; @@ -217,7 +217,7 @@ if ($resql) { $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', $title, 0, 'stock'); + 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; diff --git a/htdocs/product/stock/replenishorders.php b/htdocs/product/stock/replenishorders.php index e22f472f21d..206f12029e8 100644 --- a/htdocs/product/stock/replenishorders.php +++ b/htdocs/product/stock/replenishorders.php @@ -43,7 +43,7 @@ $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('Replenishment'); +$head[0][1] = $langs->trans('Status'); $head[0][2] = 'replenish'; $head[1][0] = DOL_URL_ROOT.'/product/stock/replenishorders.php'; $head[1][1] = $texte; From 8d6591ac2f2c70ab566f42ba29e1fefb1ebf14a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Fri, 5 Jul 2013 16:42:59 +0200 Subject: [PATCH 85/92] Better comment --- htdocs/product/stock/replenish.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index eda18d09f42..7b351d336e4 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -68,7 +68,7 @@ $offset = $limit * $page ; */ //orders creation -//could go in the lib +//FIXME: could go in the lib if ($action == 'order') { $linecount = GETPOST('linecount', 'int'); $box = 0; @@ -159,7 +159,6 @@ $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).'%" '; @@ -363,7 +362,8 @@ if ($resql) { ' ', ' ', '', - '', + '', '', ''; From 18ec06a7f941e825ae2652be1a27234415921243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Fri, 5 Jul 2013 16:43:20 +0200 Subject: [PATCH 86/92] Allowed displaying products without buying price --- htdocs/product/stock/replenish.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 7b351d336e4..14285d753ef 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -185,9 +185,6 @@ $sql .= ' AND p.tobuy = 1'; if (!empty($canvas)) { $sql .= ' AND p.canvas = "' . $db->escape($canvas) . '"'; } - - $sql .= ' AND p.rowid = pf.fk_product'; - $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'; From 7d573bce1d69f33a01f84acf43256caab17e4498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Fri, 5 Jul 2013 16:45:27 +0200 Subject: [PATCH 87/92] PSR-0 coding style --- htdocs/product/stock/replenish.php | 16 ++++++++-------- htdocs/product/stock/replenishorders.php | 13 +++++-------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 14285d753ef..6530ed05f3b 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -41,7 +41,6 @@ $result=restrictedArea($user,'produit|service'); //checks if a product has been ordered - $action = GETPOST('action','alpha'); $sref = GETPOST('sref', 'alpha'); $snom = GETPOST('snom', 'alpha'); @@ -137,8 +136,8 @@ if ($action == 'order') { header('Location: replenishorders.php'); exit; } - } - if ($box == 0){ + } + if ($box == 0) { setEventMessage($langs->trans('SelectProduct'), 'warnings'); } } @@ -423,9 +422,9 @@ if ($resql) { //virtual stock to compute the stock to buy value $stocktobuy = max($objp->desiredstock - $stock - $ordered, 0); $disabled = ''; - if($ordered > 0) { + if ($ordered > 0) { $picto = img_picto('','tick'); - if($ordered + $stock >= $objp->desiredstock) { + if ($ordered + $stock >= $objp->desiredstock) { $disabled = 'disabled="disabled"'; } } else { @@ -519,10 +518,11 @@ if ($resql) { $db->free($resql); echo '