From 1083d5ca8b62d4c6d1054f295cca6c8b7e638e95 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 28 May 2010 21:52:51 +0000 Subject: [PATCH] Serious debug of supplier order process --- .../class/fournisseur.commande.class.php | 65 ++++++++++++-- .../fourn/class/fournisseur.facture.class.php | 5 +- htdocs/fourn/commande/dispatch.php | 90 ++++++++++++------- htdocs/fourn/commande/fiche.php | 36 +++++++- htdocs/langs/en_US/stocks.lang | 4 +- htdocs/langs/fr_FR/stocks.lang | 2 + 6 files changed, 155 insertions(+), 47 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 2c4e6bbfe85..7f86c91ed6a 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -49,6 +49,10 @@ class CommandeFournisseur extends Commande var $ref; var $brouillon; + var $statut; // 0=Draft -> 1=Validated -> 2=Approved -> 3=Process runing -> 4=Received partially -> 5=Received totally + // -> 7=Canceled/Never received -> 3=Process + // -> 6=Canceled -> 2=Approved + // -> 9=Refused -> 1=Validated /** \brief Constructeur @@ -67,6 +71,7 @@ class CommandeFournisseur extends Commande $this->statuts[4] = 'StatusOrderReceivedPartially'; $this->statuts[5] = 'StatusOrderReceivedAll'; $this->statuts[6] = 'StatusOrderCanceled'; + $this->statuts[7] = 'StatusOrderCanceled'; $this->statuts[9] = 'StatusOrderRefused'; } @@ -373,7 +378,7 @@ class CommandeFournisseur extends Commande if ($statut==3) return img_picto($langs->trans($this->statuts[$statut]),'statut3'); if ($statut==4) return img_picto($langs->trans($this->statuts[$statut]),'statut3'); if ($statut==5) return img_picto($langs->trans($this->statuts[$statut]),'statut6'); - if ($statut==6) return img_picto($langs->trans($this->statuts[$statut]),'statut5'); + if ($statut==6 || $statut==7) return img_picto($langs->trans($this->statuts[$statut]),'statut5'); if ($statut==9) return img_picto($langs->trans($this->statuts[$statut]),'statut5'); } if ($mode == 4) @@ -384,7 +389,7 @@ class CommandeFournisseur extends Commande if ($statut==3) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]); if ($statut==4) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]); if ($statut==5) return img_picto($langs->trans($this->statuts[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]); - if ($statut==6) return img_picto($langs->trans($this->statuts[$statut]),'statut5').' '.$langs->trans($this->statuts[$statut]); + if ($statut==6 || $statut==7) return img_picto($langs->trans($this->statuts[$statut]),'statut5').' '.$langs->trans($this->statuts[$statut]); if ($statut==9) return img_picto($langs->trans($this->statuts[$statut]),'statut5').' '.$langs->trans($this->statuts[$statut]); } if ($mode == 5) @@ -395,7 +400,7 @@ class CommandeFournisseur extends Commande if ($statut==3) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut3'); if ($statut==4) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut3'); if ($statut==5) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut6'); - if ($statut==6) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut5'); + if ($statut==6 || $statut==7) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut5'); if ($statut==9) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut5'); } } @@ -981,6 +986,7 @@ class CommandeFournisseur extends Commande return -2; } } + /** * Supprime une ligne de la commande * @@ -1106,21 +1112,21 @@ class CommandeFournisseur extends Commande dol_syslog("CommandeFournisseur::Livraison"); - if ($user->rights->fournisseur->commande->receptionner && $date < gmmktime()) + if ($user->rights->fournisseur->commande->receptionner) { - if ($type == 'tot') $statut = 5; if ($type == 'par') $statut = 4; - if ($type == 'nev') $statut = 6; - if ($type == 'can') $statut = 6; + if ($type == 'tot') $statut = 5; + if ($type == 'nev') $statut = 7; + if ($type == 'can') $statut = 7; - if ($statut == 4 or $statut == 5 or $statut == 6) + if ($statut == 4 or $statut == 5 or $statut == 7) { $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur"; $sql.= " SET fk_statut = ".$statut; $sql.= " WHERE rowid = ".$this->id; - $sql.= " AND fk_statut IN (3,4)"; + $sql.= " AND fk_statut IN (3,4)"; // Process running or Partially received dol_syslog("CommandeFournisseur::Livraison sql=".$sql); $resql=$this->db->query($sql); @@ -1264,6 +1270,47 @@ class CommandeFournisseur extends Commande } + /** + * \brief Tag order with a particular status + * \param user Object user that change status + * \return int <0 if KO, >0 if OK + */ + function setStatus($user,$status) + { + global $conf,$langs; + $error=0; + + $this->db->begin(); + + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur'; + $sql.= ' SET fk_statut='.$status; + $sql.= ' WHERE rowid = '.$this->id; + + dol_syslog("CommandeFournisseur::setStatus sql=".$sql); + $resql = $this->db->query($sql); + if ($resql) + { + + } + else + { + $error++; + $this->error=$this->db->lasterror(); + dol_syslog("CommandeFournisseur::setStatus ".$this->error); + } + + if (! $error) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } + } + /** * \brief Update line * \param rowid Id de la ligne de facture diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 2d13e1ec99e..dd1893972f4 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -522,7 +522,6 @@ class FactureFournisseur extends Facture $this->db->begin(); - dol_syslog("FactureFournisseur::set_unpaid rowid=".$this->id, LOG_DEBUG); $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture_fourn'; $sql.= ' SET paye=0, fk_statut=1, close_code=null, close_note=null'; $sql.= ' WHERE rowid = '.$this->id; @@ -543,8 +542,8 @@ class FactureFournisseur extends Facture else { $error++; - $this->error=$this->db->error(); - dol_print_error($this->db); + $this->error=$this->db->lasterror(); + dol_syslog("FactureFournisseur::set_unpaid ".$this->error); } if (! $error) diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index b9ecf8ecc71..2c8269d679c 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -174,6 +174,11 @@ if ($id > 0 || ! empty($ref)) /* * Lignes de commandes */ + if ($commande->statut <= 2 || $commande->statut >= 6) + { + print $langs->trans("OrderStatusNotReadyToDispatch"); + } + if ($commande->statut == 3 || $commande->statut == 4 || $commande->statut == 5) { print '
'; @@ -211,9 +216,6 @@ 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 ''; @@ -227,14 +229,26 @@ if ($id > 0 || ! empty($ref)) } $entrepot = new Entrepot($db); + $nbfreeproduct=0; + $nbproduct=0; $var=true; while ($i < $num) { $objp = $db->fetch_object($resql); + // On n'affiche pas les produits personnalises - if ($objp->fk_product) + if (! $objp->fk_product > 0) { + $nbfreeproduct++; + } + else + { + $nbproduct++; + + $remaintodispatch=($objp->qty - $products_dispatched[$objp->fk_product]); + if ($remaintodispatch < 0) $remaintodispatch=0; + $var=!$var; print ""; print ''; @@ -278,16 +292,19 @@ if ($id > 0 || ! empty($ref)) print "\n"; print "
\n"; - print '
'; + if ($nbproduct) + { + print '
'; + } + if (! $nbproduct && $nbfreeproduct) + { + print $langs->trans("NoPredefinedProductToDispatch"); + } print '
'; } - print "
\n"; - // List of already dispatching - print ''; - $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,"; @@ -303,50 +320,57 @@ if ($id > 0 || ! empty($ref)) $num = $db->num_rows($resql); $i = 0; - if ($num) + if ($num > 0) { + print "
\n"; + + print '
'; + print ''; print ''; print ''; print ''; print "\n"; + + $var=false; + + while ($i < $num) + { + $objp = $db->fetch_object($resql); + print ""; + print '\n"; + + print ''; + print ''; + print "\n"; + + $i++; + $var=!$var; + } + $db->free($resql); + + print "
'.$langs->trans("Description").''.$langs->trans("QtyDispatched").''.$langs->trans("Warehouse").'
'; + print ''.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.''; + print ' - '.$objp->label; + print "'.$objp->qty.''.$objp->entrepot.'
\n"; } - $var=false; - - while ($i < $num) - { - $objp = $db->fetch_object($resql); - print ""; - print ''; - print ''.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.''; - print ' - '.$objp->label; - print "\n"; - - print ''.$objp->qty.''; - print ''.$objp->entrepot.''; - print "\n"; - - $i++; - $var=!$var; - } - $db->free($resql); } else { dol_print_error($db); } - print "\n"; - print ''; + dol_fiche_end(); + /** * Boutons actions */ if ($user->societe_id == 0 && $commande->statut < 3 && ($_GET["action"] <> 'valid' || $_GET['action'] == 'builddoc')) { - print '
'; + //print '
'; - print "
"; + //print "
"; } } else diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index 68f39458445..e1f2d7104b8 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -81,6 +81,30 @@ if ($_REQUEST['action'] == 'setremisepercent' && $user->rights->fournisseur->com $id=$_REQUEST['id']; } +if ($_GET['action'] == 'reopen' && $user->rights->fournisseur->commande->approuver) +{ + $order = new CommandeFournisseur($db); + $result = $order->fetch($_REQUEST['id']); + if ($order->statut == 5 || $order->statut == 6 || $order->statut == 7 || $order->statut == 9) + { + if ($order->statut == 5) $newstatus=4; // Received->Received partially + if ($order->statut == 6) $newstatus=2; // Canceled->Approved + if ($order->statut == 7) $newstatus=3; // Canceled->Process running + if ($order->statut == 9) $newstatus=1; // Refused->Validated + + $result = $order->setStatus($user,$newstatus); + if ($result > 0) + { + Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$_REQUEST['id']); + exit; + } + else + { + $mesg='
'.$order->error.'
'; + } + } +} + /* * Ajout d'une ligne produit dans la commande */ @@ -341,6 +365,7 @@ if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes' && } } +// Receive if ($_POST["action"] == 'livraison' && $user->rights->fournisseur->commande->receptionner) { $commande = new CommandeFournisseur($db); @@ -1267,6 +1292,15 @@ if ($id > 0 || ! empty($ref)) } } + // Reopen + if ($commande->statut == 5 || $commande->statut == 6 || $commande->statut == 7 || $commande->statut == 9) + { + if ($user->rights->fournisseur->commande->commander) + { + print ''.$langs->trans("ReOpen").''; + } + } + if ($user->rights->fournisseur->commande->supprimer) { print ''.$langs->trans("Delete").''; @@ -1294,7 +1328,7 @@ if ($id > 0 || ! empty($ref)) print ''; - if ( $user->rights->fournisseur->commande->commander && ($commande->statut == 2 || $commande->statut == 6)) + if ( $user->rights->fournisseur->commande->commander && $commande->statut == 2) { /** * Commander (action=commande) diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index 255018f3135..66f47861bdf 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -49,7 +49,9 @@ 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 +OrderStatusNotReadyToDispatch=Order has not yet or no more a status that allows dispatching of products in stock warehouses. +StockDiffPhysicTeoric=Reason for difference stock physical and theoretical +NoPredefinedProductToDispatch=No predefined products for this object. So no dispatching in stock is required. DispatchVerb=Dispatch StockLimitShort=Limit StockLimit=Stock limit for alerts diff --git a/htdocs/langs/fr_FR/stocks.lang b/htdocs/langs/fr_FR/stocks.lang index 5ee9d1c572c..5640f8d8034 100644 --- a/htdocs/langs/fr_FR/stocks.lang +++ b/htdocs/langs/fr_FR/stocks.lang @@ -49,7 +49,9 @@ DeStockOnShipment=Décrémente les stocks physiques sur validation des expéditi 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 +OrderStatusNotReadyToDispatch=La commande n'a pas encore ou n'a plus un status permettant une ventilation en stock. StockDiffPhysicTeoric=Raison écart stock physique-théorique +NoPredefinedProductToDispatch=Pas de produits prédéfinis dans cet object. Aucune ventilation en stock n'est donc à faire. DispatchVerb=Ventiler StockLimitShort=Seuil StockLimit=Seuil alerte stock