From 38d91e99dd53083ec4266da2cdc3e5c18cc33ae2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 28 May 2010 20:41:41 +0000 Subject: [PATCH] New: Add a new mode for automatic stock increase: Can be increased on supplier order dispatching of products. --- htdocs/admin/stock.php | 22 +++- htdocs/core/class/html.form.class.php | 21 ++-- .../class/fournisseur.commande.class.php | 49 ++++---- htdocs/fourn/commande/dispatch.php | 107 +++++++----------- htdocs/fourn/commande/fiche.php | 8 +- htdocs/langs/en_US/stocks.lang | 2 + htdocs/langs/fr_FR/stocks.lang | 2 + htdocs/lib/fourn.lib.php | 2 +- 8 files changed, 101 insertions(+), 112 deletions(-) diff --git a/htdocs/admin/stock.php b/htdocs/admin/stock.php index 3102f427fdc..f3a354d9065 100644 --- a/htdocs/admin/stock.php +++ b/htdocs/admin/stock.php @@ -1,6 +1,6 @@ - * Copyright (C) 2008 Laurent Destailleur + * Copyright (C) 2008-2010 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -80,17 +80,20 @@ if ($_POST["action"] == 'STOCK_CALCULATE_ON_BILL' dol_print_error("Error in some requests", LOG_ERR); } } -// Mode of stock decrease +// Mode of stock increase if ($_POST["action"] == 'STOCK_CALCULATE_ON_SUPPLIER_BILL' -|| $_POST["action"] == 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') +|| $_POST["action"] == 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER' +|| $_POST["action"] == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') { $count=0; $db->begin(); $count+=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_BILL", '','chaine',0,'',$conf->entity); $count+=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", '','chaine',0,'',$conf->entity); + $count+=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", '','chaine',0,'',$conf->entity); if ($_POST["action"] == 'STOCK_CALCULATE_ON_SUPPLIER_BILL') $count+=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_BILL", $_POST["STOCK_CALCULATE_ON_SUPPLIER_BILL"],'chaine',0,'',$conf->entity); if ($_POST["action"] == 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') $count+=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", $_POST["STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER"],'chaine',0,'',$conf->entity); - if ($count == 3) + if ($_POST["action"] == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') $count+=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", $_POST["STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER"],'chaine',0,'',$conf->entity); + if ($count == 4) { $db->commit(); Header("Location: stock.php"); @@ -243,6 +246,17 @@ if ($conf->commande->enabled) print $html->selectyesno("STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER",$conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER,1); print ''; print "\n\n\n"; + + $var=!$var; + print ""; + print ''.$langs->trans("ReStockOnDispatchOrder").''; + print ''; + print "
"; + print ''; + print ""; + print $html->selectyesno("STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER",$conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER,1); + print ''; + print "
\n\n\n"; } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 479ad0e65a8..35f3198b5ff 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1513,7 +1513,7 @@ class Form print ''; if ($user->admin && ! $noadmininfo) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); } - + /** * \brief Selection HT ou TTC * \param selected Id pre-selectionne @@ -1532,9 +1532,9 @@ class Form function load_PriceBaseType($selected='',$htmlname='price_base_type') { global $langs; - + $return=''; - + $return.= ''; - + return $return; } @@ -2206,7 +2206,7 @@ class Form return 1; } } - + /** * \brief Output an HTML select vat rate * \param name Nom champ html @@ -2244,7 +2244,7 @@ class Form function load_tva($name='tauxtva', $selectedrate='', $societe_vendeuse='', $societe_acheteuse='', $taux_produit='', $info_bits=0) { global $langs,$conf,$mysoc; - + $return=''; $txtva=array(); @@ -2357,7 +2357,7 @@ class Form } $return.= ''; } - + return $return; } @@ -2703,9 +2703,10 @@ class Form * \param option Valeur de l'option en fonction du type choisi * \param translate Traduire la valeur * \param maxlen Length maximum for labels + * \param disabled Html select box is disabled * \return string HTML select string */ - function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $optionType=0, $option='', $translate=0, $maxlen=0) + function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $optionType=0, $option='', $translate=0, $maxlen=0, $disabled=0) { global $langs; @@ -2714,11 +2715,11 @@ class Form // \TODO Simplify optionType and option (only one should be necessary) if ($optionType == 1 && $option != '') { - $out.=''; } else { - $out.=''; } if ($show_empty) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index d033b43ce88..2c4e6bbfe85 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -505,7 +505,7 @@ class CommandeFournisseur extends Commande $this->log($user, 2, time()); // Statut 2 // If stock is incremented on validate order, we must increment it - if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER == 1) + if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) { require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); @@ -918,36 +918,22 @@ class CommandeFournisseur extends Commande /** - * \brief Dispatch un element de la commande dans un stock + * Add a product into a stock warehouse. + * + * @param unknown_type $user + * @param unknown_type $product + * @param unknown_type $qty + * @param unknown_type $entrepot Id of warehouse to add product + * @param unknown_type $price + * @return unknown */ - function DispatchProducts($user, $products, $qtys, $entrepots) - { - global $conf; - require_once DOL_DOCUMENT_ROOT ."/product/stock/class/mouvementstock.class.php"; - - $this->db->begin(); - - if ( is_array($products) ) - { - - } - else - { - $res = $this->DispatchProduct($user, $product, $qty, $entrepot); - } - - $this->db->rollback(); - - return $res; - } - function DispatchProduct($user, $product, $qty, $entrepot, $price=0) { global $conf; $error = 0; require_once DOL_DOCUMENT_ROOT ."/product/stock/class/mouvementstock.class.php"; - dol_syslog("CommandeFournisseur::DispatchProduct"); + $now=dol_now(); if ( ($this->statut == 3 || $this->statut == 4 || $this->statut == 5) && $qty > 0) { @@ -955,23 +941,26 @@ class CommandeFournisseur extends Commande $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur_dispatch "; $sql.= " (fk_commande,fk_product, qty, fk_entrepot, fk_user, datec) VALUES "; - $sql.= " ('".$this->id."','".$product."','".$qty."','".$entrepot."','".$user->id."',".$this->db->idate(mktime()).")"; + $sql.= " ('".$this->id."','".$product."','".$qty."',".($entrepot>0?"'".$entrepot."'":"null").",'".$user->id."','".$this->db->idate($now)."')"; + dol_syslog("CommandeFournisseur::DispatchProduct sql=".$sql); $resql = $this->db->query($sql); if (! $resql) { - $error = -1; + $this->error=$this->db->lasterror(); + $error++; } + // Si module stock gere et que expedition faite depuis un entrepot - if (!$error && $conf->stock->enabled && $entrepot) + if (!$error && $entrepot > 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) { $mouv = new MouvementStock($this->db); $result=$mouv->reception($user, $product, $entrepot, $qty, $price); if ($result < 0) { - $this->error=$this->db->error()." - sql=$sql"; - dol_syslog("CommandeFournisseur::DispatchProduct".$this->error, LOG_ERR); - $error = -2; + $this->error=$mouv->error; + dol_syslog("CommandeFournisseur::DispatchProduct ".$this->error, LOG_ERR); + $error++; } $i++; } diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index d4d4fec0f8a..b9ecf8ecc71 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -1,7 +1,7 @@ - * Copyright (C) 2004-2009 Laurent Destailleur - * Copyright (C) 2005 Eric Seigne + * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2005 Eric Seigne * Copyright (C) 2005-2009 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -20,7 +20,7 @@ */ /** - * \file htdocs/fourn/commande/fiche.php + * \file htdocs/fourn/commande/dispatch.php * \ingroup commande * \brief Fiche de ventilation des commandes fournisseurs * \version $Id$ @@ -64,16 +64,23 @@ if ($_POST["action"] == 'dispatch' && $user->rights->fournisseur->commande->rece { if ( preg_match('/^product_([0-9]+)$/i', $key, $reg) ) { - $prod = "product_".$reg[1]; - $qty = "qty_".$reg[1]; - $ent = "entrepot_".$reg[1]; - $pu = "pu_".$reg[1]; - $result = $commande->DispatchProduct($user, $_POST[$prod], $_POST[$qty], $_POST[$ent], $_POST[$pu]); + $prod = "product_".$reg[1]; + $qty = "qty_".$reg[1]; + $ent = "entrepot_".$reg[1]; + $pu = "pu_".$reg[1]; + $result = $commande->DispatchProduct($user, $_POST[$prod], $_POST[$qty], $_POST[$ent], $_POST[$pu]); } } - Header("Location: dispatch.php?id=".$_GET["id"]); - exit; + if ($result > 0) + { + Header("Location: dispatch.php?id=".$_GET["id"]); + exit; + } + else + { + $mesg=$commande->error; + } } @@ -86,7 +93,7 @@ llxHeader('',$langs->trans("OrderCard"),"CommandeFournisseur"); $html = new Form($db); -$now=gmmktime(); +$now=dol_now(); $id = $_GET['id']; $ref= $_GET['ref']; @@ -160,6 +167,10 @@ if ($id > 0 || ! empty($ref)) if ($mesg) print $mesg; else print '
'; + + $disabled=1; + if ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) $disabled=0; + /* * Lignes de commandes */ @@ -200,6 +211,9 @@ if ($id > 0 || ! empty($ref)) $num = $db->num_rows($resql); $i = 0; + $remaintodispatch=$objp->qty - $products_dispatched[$objp->fk_product]; + if ($remaintodispatch < 0) $remaintodispatch=0; + if ($num) { print ''; @@ -207,8 +221,8 @@ if ($id > 0 || ! empty($ref)) print ''.$langs->trans("QtyOrdered").''; print ''.$langs->trans("QtyDispatched").''; - print ''.$langs->trans("Warehouse").''; print ''.$langs->trans("QtyDelivered").''; + print ''.$langs->trans("Warehouse").''; print "\n"; } @@ -234,20 +248,22 @@ if ($id > 0 || ! empty($ref)) print ''.$objp->qty.''; print ''.$products_dispatched[$objp->fk_product].''; - print ''; + // Dispatch + print ''; + // Warehouse + print ''; if (sizeof($user->entrepots) === 1) { $uentrepot = array(); $uentrepot[$user->entrepots[0]['id']] = $user->entrepots[0]['label']; - $html->select_array("entrepot_".$i, $uentrepot); + print $html->selectarray("entrepot_".$i, $uentrepot, '', $disabled, 0, 0, 0, '', 0, 0, $disabled); } else { - $html->select_array("entrepot_".$i, $entrepot->list_array()); + print $html->selectarray("entrepot_".$i, $entrepot->list_array(), '', $disabled, 0, 0, 0, '', 0, 0, $disabled); } print "\n"; - print ''; print "\n"; } $i++; @@ -261,22 +277,24 @@ if ($id > 0 || ! empty($ref)) print "\n"; print "
\n"; - print '
'; + + print '
'; + + print ''; } print "
\n"; + + // List of already dispatching print ''; - - $sql = "SELECT p.ref,cfd.fk_product, cfd.qty"; - $sql.= ", cfd.rowid"; - $sql.= ", p.label, e.label as entrepot"; - $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as cfd"; - $sql.= " , ".MAIN_DB_PREFIX."product as p "; - $sql.= " , ".MAIN_DB_PREFIX."entrepot as e "; + $sql = "SELECT p.ref, p.label, e.label as entrepot,"; + $sql.= " cfd.fk_product, cfd.qty, cfd.rowid"; + $sql.= " FROM ".MAIN_DB_PREFIX."product as p,"; + $sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as cfd"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e ON cfd.fk_entrepot = e.rowid"; $sql.= " WHERE cfd.fk_commande = ".$commande->id; $sql.= " AND cfd.fk_product = p.rowid"; - $sql.= " AND cfd.fk_entrepot = e.rowid"; $sql.= " ORDER BY cfd.rowid ASC"; $resql = $db->query($sql); @@ -305,7 +323,7 @@ if ($id > 0 || ! empty($ref)) print "\n"; print ''; - print ''; + print ''; print "\n"; $i++; @@ -328,45 +346,8 @@ if ($id > 0 || ! empty($ref)) { print '
'; - if ($commande->statut == 0 && $num > 0) - { - if ($user->rights->fournisseur->commande->valider) - { - print ''.$langs->trans("Valid").''; - } - } - - if ($commande->statut == 1) - { - if ($user->rights->fournisseur->commande->approuver) - { - print ''.$langs->trans("ApproveOrder").''; - - print ''.$langs->trans("RefuseOrder").''; - } - } - - if ($commande->statut == 2) - { - if ($user->rights->fournisseur->commande->commander) - { - print ''.$langs->trans("CancelOrder").''; - } - } - - if ($commande->statut == 0) - { - if ($user->rights->fournisseur->commande->creer) - { - print ''.$langs->trans("Delete").''; - } - } print "
"; } - /* - * - * - */ } else { diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index e7c54204c79..68f39458445 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -1314,8 +1314,8 @@ if ($id > 0 || ! empty($ref)) $formorder->select_methodes_commande($_POST["methodecommande"],"methodecommande",1); print ''; - print ''; - print ''; + print ''; + print ''; print '
'.$objp->qty.''.stripslashes($objp->entrepot).''.$objp->entrepot.'
'.$langs->trans("Comment").'
'.$langs->trans("Comment").'
'; print ''; } @@ -1346,8 +1346,8 @@ if ($id > 0 || ! empty($ref)) print $html->select_array("type",$liv); print ''; - print ''.$langs->trans("Comment").''; - print ''; + print ''.$langs->trans("Comment").''; + print ''; print "\n"; print "\n"; } diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index a9d61ac4687..255018f3135 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -48,7 +48,9 @@ DeStockOnValidateOrder=Decrease real stocks on orders notes validation (warning, DeStockOnShipment=Decrease real stocks on shipment validation (recommended) ReStockOnBill=Increase real stocks on invoices/credit notes validation (warning, in this version, it's only in warehouse number 1 that stock is modified) ReStockOnValidateOrder=Increase real stocks on orders notes validation (warning, in this version, it's only in warehouse number 1 that stock is modified) +ReStockOnDispatchOrder=Increase real stocks on manual dispatching into warehouses, after order receiving StockDiffPhysicTeoric=Reason for difference stock physical and theoretical +DispatchVerb=Dispatch StockLimitShort=Limit StockLimit=Stock limit for alerts PhysicalStock=Physical stock diff --git a/htdocs/langs/fr_FR/stocks.lang b/htdocs/langs/fr_FR/stocks.lang index 7977481c7e7..5ee9d1c572c 100644 --- a/htdocs/langs/fr_FR/stocks.lang +++ b/htdocs/langs/fr_FR/stocks.lang @@ -48,7 +48,9 @@ DeStockOnValidateOrder=Décrémente les stocks physiques sur validation des comm DeStockOnShipment=Décrémente les stocks physiques sur validation des expéditions (recommandé) ReStockOnBill=Incrémente les stocks physiques sur validation des factures/avoirs (attention, dans cette version, c'est toujours dans le premier entrepôt que se fait l'ajustement) ReStockOnValidateOrder=Incrémente les stocks physiques sur validation des commandes (attention, dans cette version, c'est toujours dans le premier entrepôt que se fait l'ajustement) +ReStockOnDispatchOrder=Incrémente les stocks physiques sur ventilation manuelle de la réception des commandes dans les entrepots StockDiffPhysicTeoric=Raison écart stock physique-théorique +DispatchVerb=Ventiler StockLimitShort=Seuil StockLimit=Seuil alerte stock PhysicalStock=Stock physique diff --git a/htdocs/lib/fourn.lib.php b/htdocs/lib/fourn.lib.php index dbdc25cc3e5..2892c33f4a3 100644 --- a/htdocs/lib/fourn.lib.php +++ b/htdocs/lib/fourn.lib.php @@ -91,7 +91,7 @@ function ordersupplier_prepare_head($commande) $head[$h][2] = 'card'; $h++; - if ($conf->stock->enabled) + if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) { $langs->load("stocks"); $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/dispatch.php?id='.$commande->id;