From 18f22d38a4a96e355347eb61ed4e531959059e2b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 21 Sep 2005 23:43:07 +0000 Subject: [PATCH] =?UTF-8?q?Fixed:=20bug=20#14432=20overview:=20Bug=20=E0?= =?UTF-8?q?=20la=20cr=E9ation=20d'une=20exp=E9dition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/expedition/commande.php | 44 +++-- htdocs/expedition/expedition.class.php | 74 ++++++-- htdocs/expedition/fiche.php | 174 ++++++++++-------- htdocs/langs/en_US/sendings.lang | 3 +- htdocs/langs/fr_FR/sendings.lang | 3 +- htdocs/product.class.php | 17 +- htdocs/product/stock/fiche.php | 18 +- htdocs/product/stock/mouvement.php | 3 +- htdocs/product/stock/mouvementstock.class.php | 98 +++++----- 9 files changed, 262 insertions(+), 172 deletions(-) diff --git a/htdocs/expedition/commande.php b/htdocs/expedition/commande.php index 697dcbfe16e..5d55d35402f 100644 --- a/htdocs/expedition/commande.php +++ b/htdocs/expedition/commande.php @@ -189,7 +189,7 @@ if ($_GET["id"] > 0) if ($resql) { $num = $db->num_rows($resql); - $i = 0; $total = 0; + $i = 0; print ''; print ''.$langs->trans("Description").''; @@ -371,49 +371,63 @@ if ($_GET["id"] > 0) } /* - * Déjà livr + * Déjà livré */ - $sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande, ed.qty as qty_livre, e.ref, e.rowid as expedition_id"; - $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e"; - $sql .= " WHERE cd.fk_commande = ".$commande->id." AND cd.rowid = ed.fk_commande_ligne AND ed.fk_expedition = e.rowid"; - $sql .= " ORDER BY e.rowid DESC, cd.fk_product"; + $sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande"; + $sql .= " , ed.qty as qty_livre, e.ref, ed.fk_expedition as expedition_id"; + $sql .= ",".$db->pdate("e.date_expedition")." as date_expedition"; + $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; + $sql .= " , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e"; + $sql .= " WHERE cd.fk_commande = $commande->id"; + $sql .= " AND cd.rowid = ed.fk_commande_ligne"; + $sql .= " AND ed.fk_expedition = e.rowid"; + $sql .= " ORDER BY cd.fk_product"; + $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); - $i = 0; $total = 0; + $i = 0; if ($num) { - print '
'; + print '
'; print ''; print ''; print ''; - print ''; - + print ''; + print ''; print "\n"; $var=True; while ($i < $num) { - $objp = $db->fetch_object($resql); + $var=!$var; + $objp = $db->fetch_object($resql); print ""; if ($objp->fk_product > 0) { - print ''; + $product = new Product($db); + $product->fetch($objp->fk_product); + + print ''; } else { - print "\n"; + print "\n"; } print ''; - print ''; + print ''; + print ''; $i++; } print '
'.$langs->trans("Description").'Quan. livréeExpédition'.$langs->trans("Sending").''.$langs->trans("Date").'
'; - print ''.stripslashes(nl2br($objp->description)).''; + print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.$product->libelle; + if ($objp->description) print nl2br($objp->description); + print '".stripslashes(nl2br($objp->description))."".stripslashes(nl2br($objp->description))."'.$objp->qty_livre.''.$objp->ref.''.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.''.dolibarr_print_date($objp->date_expedition).'
'; } + $db->free($resql); } else { dolibarr_print_error($db); diff --git a/htdocs/expedition/expedition.class.php b/htdocs/expedition/expedition.class.php index 2342cca9703..ae65bbc973b 100644 --- a/htdocs/expedition/expedition.class.php +++ b/htdocs/expedition/expedition.class.php @@ -28,7 +28,8 @@ */ -/** \class Expedition +/** + \class Expedition \brief Classe de gestion des expeditions */ class Expedition @@ -37,6 +38,7 @@ class Expedition var $id ; var $brouillon; var $entrepot_id; + /** * Initialisation * @@ -222,58 +224,98 @@ class Expedition } /** - * \brief Valide l'expedition + * \brief Valide l'expedition, et met a jour le stock si stock géré * \param user Objet de l'utilisateur qui valide * \return int */ function valid($user) { + global $conf; + require_once DOL_DOCUMENT_ROOT ."/product/stock/mouvementstock.class.php"; - $result = 0; + dolibarr_syslog("expedition.class.php::valid"); + + $this->db->begin(); + + $error = 0; + if ($user->rights->expedition->valider) { $this->ref = "EXP".$this->id; + // \todo Tester si non dejà au statut validé. Si oui, on arrete afin d'éviter + // de décrémenter 2 fois le stock. + $sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET ref='".$this->ref."', fk_statut = 1, date_valid=now(), fk_user_valid=$user->id"; $sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;"; if ($this->db->query($sql) ) { - $result = 1; - // Si module stock géré et que expedition faite depuis un entrepot if ($conf->stock->enabled && $this->entrepot_id) { /* * Enregistrement d'un mouvement de stock pour chaque produit de l'expedition */ + + dolibarr_syslog("expedition.class.php::valid enregistrement des mouvements"); + + $sql = "SELECT cd.fk_product, ed.qty "; + $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."expeditiondet as ed"; + $sql.= " WHERE ed.fk_expedition = $this->id AND cd.rowid = ed.fk_commande_ligne"; - $sql = "SELECT cd.fk_product, ed.qty "; - $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd , ".MAIN_DB_PREFIX."expeditiondet as ed"; - $sql .= " WHERE ed.fk_expedition = $this->id AND cd.rowid = ed.fk_commande_ligne "; - - if ($this->db->query($sql)) + $resql=$this->db->query($sql); + if ($resql) { - $num = $this->db->num_rows(); + $num = $this->db->num_rows($resql); $i=0; while($i < $num) { + dolibarr_syslog("expedition.class.php::valid movment $i"); + + $obj = $this->db->fetch_object($resql); + $mouvS = new MouvementStock($this->db); - $obj = $this->db->fetch_object(); - $mouvS->livraison($user, $obj->fk_product, $this->entrepot_id, $obj->qty, 0); + $result=$mouvS->livraison($user, $obj->fk_product, $this->entrepot_id, $obj->qty); + if ($result < 0) + { + $this->db->rollback(); + $this->error=$this->db->error()." - sql=$sql"; + dolibarr_syslog("expedition.class.php::valid ".$this->error); + return -3; + } $i++; } + + } + else + { + $this->db->rollback(); + $this->error=$this->db->error()." - sql=$sql"; + dolibarr_syslog("expedition.class.php::valid ".$this->error); + return -2; } } } else { - $result = -1; - $this->error=$this->db->error()." - sql=".$sql; + $this->db->rollback(); + $this->error=$this->db->error()." - sql=$sql"; + dolibarr_syslog("expedition.class.php::valid ".$this->error); + return -1; } } - return $result ; + else + { + $this->error="Non autorise"; + dolibarr_syslog("expedition.class.php::valid ".$this->error); + return -1; + } + + $this->db->commit(); + //dolibarr_syslog("expedition.class.php::valid commit"); + return 1; } diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index a6c56283537..f68f39690ee 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -55,6 +55,9 @@ if ($user->societe_id > 0) if ($_POST["action"] == 'add') { + $db->begin(); + + // Creation de l'objet expedition $expedition = new Expedition($db); $expedition->date_expedition = time(); @@ -62,12 +65,11 @@ if ($_POST["action"] == 'add') $expedition->commande_id = $_POST["commande_id"]; $expedition->entrepot_id = $_POST["entrepot_id"]; + // On boucle sur chaque ligne de commande pour compléter objet expedition + // avec qté à livrer $commande = new Commande($db); $commande->fetch($expedition->commande_id); $commande->fetch_lignes(); - - $db->begin(); - for ($i = 0 ; $i < sizeof($commande->lignes) ; $i++) { $qty = "qtyl".$i; @@ -177,13 +179,13 @@ if ($_GET["action"] == 'create') print "".$langs->trans("Date").""; print "".strftime("%A %d %B %Y",$commande->date)."\n"; - print ''.$langs->trans("Order").': ' . $commande->ref; + print ''.$langs->trans("Order").''.img_object($langs->trans("ShowOrder"),'order').' '.$commande->ref.''; print "\n"; print ''.$langs->trans("Warehouse").''; print ''; $ents = $entrepot->list_array(); - print $ents[$_GET["entrepot_id"]]; + print ''.img_object($langs->trans("ShowWarehouse"),'stock').' '.$ents[$_GET["entrepot_id"]].''; print ''; print "".$langs->trans("Author")."$author->fullname\n"; @@ -232,7 +234,9 @@ if ($_GET["action"] == 'create') $product->fetch($ligne->product_id); print ''; - print ''.nl2br($ligne->description).''; + print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.$product->libelle; + if ($ligne->description) print nl2br($ligne->description); + print ''; } else { @@ -247,36 +251,40 @@ if ($_GET["action"] == 'create') $quantite_livree = $commande->livraisons[$ligne->product_id]; print $quantite_livree;; print ''; - /* - * - */ - print ''; - print ''; - + $quantite_commandee = $ligne->qty; $quantite_a_livrer = $quantite_commandee - $quantite_livree; - if ($conf->stock->enabled) - { - $stock = $product->stock_entrepot[$_POST["entrepot_id"]]; + if ($conf->stock->enabled) + { + $stock = $product->stock_entrepot[$_GET["entrepot_id"]]; + $stock+=0; // Convertit en numérique + + // Quantité à livrer + print ''; + print ''; + print ''; + print ''; + + // Stock + if ($stock < $quantite_a_livrer) + { + print ''.$stock.''; + } + else + { + print ''.$stock.''; + } + } + else + { + // Quantité à livrer + print ''; + print ''; + print ''; + print ''; + } - print ''; - print ''; - - if ($stock < $quantite_a_livrer) - { - print ''.$stock.''; - } - else - { - print ''.$stock.''; - } - } - else - { - print ''; - print ''; - } print "\n"; $i++; @@ -425,8 +433,13 @@ else print ""; if ($objp->fk_product > 0) { - print ''; - print ''.stripslashes(nl2br($objp->description)).''; + $product = new Product($db); + $product->fetch($objp->fk_product); + + print ''; + print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.$product->libelle; + if ($objp->description) print nl2br($objp->description); + print ''; } else { @@ -495,10 +508,9 @@ else /* * Déjà livré - * */ $sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande"; - $sql .= " , ed.qty as qty_livre, e.ref"; + $sql .= " , ed.qty as qty_livre, e.ref, ed.fk_expedition as expedition_id"; $sql .= ",".$db->pdate("e.date_expedition")." as date_expedition"; $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; $sql .= " , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e"; @@ -509,47 +521,57 @@ else $sql .= " ORDER BY cd.fk_product"; $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - - if ($num) - { - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - - print "\n"; - - $var=True; - while ($i < $num) - { - $objp = $db->fetch_object($resql); - print ""; - if ($objp->fk_product > 0) - { - print ''; - } - else - { - print "\n"; - } - print ''; - print ''; - print ''; - $i++; - } - - print '
'.$langs->trans("Description").'Quan. livréeExpédition'.$langs->trans("Date").'
'; - print ''.stripslashes(nl2br($objp->description)).'".stripslashes(nl2br($objp->description))."'.$objp->qty_livre.''.$objp->ref.''.dolibarr_print_date($objp->date_expedition).'
'; + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + + if ($num) + { + print '
'; + + print_titre($langs->trans("OtherSendingsForSameOrder")); + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + $var=True; + while ($i < $num) + { + $var=!$var; + $objp = $db->fetch_object($resql); + print ""; + if ($objp->fk_product > 0) + { + $product = new Product($db); + $product->fetch($objp->fk_product); + + print ''; + } + else + { + print "\n"; + } + print ''; + print ''; + print ''; + $i++; + } + + print '
'.$langs->trans("Description").'Quan. livrée'.$langs->trans("Sending").''.$langs->trans("Date").'
'; + print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.$product->libelle; + if ($objp->description) print nl2br($objp->description); + print '".stripslashes(nl2br($objp->description))."'.$objp->qty_livre.''.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.''.dolibarr_print_date($objp->date_expedition).'
'; + } + $db->free($resql); + } + else { + dolibarr_print_error($db); } - $db->free($resql); - } - /* * Documents générés diff --git a/htdocs/langs/en_US/sendings.lang b/htdocs/langs/en_US/sendings.lang index 5403139d571..acf1600db48 100644 --- a/htdocs/langs/en_US/sendings.lang +++ b/htdocs/langs/en_US/sendings.lang @@ -15,4 +15,5 @@ CreateASending=Create a sending CreateSending=Create sending QtyOrdered=Qty ordered QtyShipped=Qty shipped -KeepToShip=Keep to ship \ No newline at end of file +KeepToShip=Keep to ship +OtherSendingsForSameOrder=Other sendings already shipped \ No newline at end of file diff --git a/htdocs/langs/fr_FR/sendings.lang b/htdocs/langs/fr_FR/sendings.lang index ea6f812b918..bdd783ffca6 100644 --- a/htdocs/langs/fr_FR/sendings.lang +++ b/htdocs/langs/fr_FR/sendings.lang @@ -15,4 +15,5 @@ CreateASending=Cr CreateSending=Créer expedition QtyOrdered=Qté commandée QtyShipped=Qté expédiée -KeepToShip=Reste à expédier \ No newline at end of file +KeepToShip=Reste à expédier +OtherSendingsForSameOrder=Autres expéditions déjà envoyés \ No newline at end of file diff --git a/htdocs/product.class.php b/htdocs/product.class.php index ee673e7df38..cd016dc284f 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -447,17 +447,17 @@ class Product $this->db->free(); $sql = "SELECT reel, fk_entrepot"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_stock WHERE fk_product = $id"; + $sql .= " FROM ".MAIN_DB_PREFIX."product_stock WHERE fk_product = ".$id; $result = $this->db->query($sql) ; - if ( $result ) + if ($result) { - $num = $this->db->num_rows(); + $num = $this->db->num_rows($result); $i=0; if ($num > 0) { while ($i < $num ) { - $row = $this->db->fetch_row($i); + $row = $this->db->fetch_row($result); $this->stock_entrepot[$row[1]] = $row[0]; $this->stock_reel = $this->stock_reel + $row[0]; @@ -470,9 +470,14 @@ class Product { $this->no_stock = 1; } - $this->db->free(); + $this->db->free($result); + return 1; + } + else + { + $this->error=$this->db->error(); + return -2; } - return 1; } else { diff --git a/htdocs/product/stock/fiche.php b/htdocs/product/stock/fiche.php index 589abe720bc..7c55aff8b04 100644 --- a/htdocs/product/stock/fiche.php +++ b/htdocs/product/stock/fiche.php @@ -134,19 +134,19 @@ if ($_GET["action"] == 'create') } print ''; - print ''; - print ''; + print '"; - print ''; + print ''; print ''; - print ''; - print ''; + print ''; + print ''; print '
'.$langs->trans("Ref").'
'.$langs->trans("Description").''; + print '
'.$langs->trans("Ref").'
'.$langs->trans("Description").''; print '
'.$langs->trans("LocationSummary").'
'.$langs->trans("LocationSummary").'
'.$langs->trans('Address').'
'.$langs->trans('Zip').''.$langs->trans('Town').'
'.$langs->trans('Zip').''.$langs->trans('Town').'
'.$langs->trans('Country').''; $form->select_pays($entrepot->pays_id,$entrepot->pays_code); @@ -198,17 +198,17 @@ else dolibarr_fiche_head($head, $hselected, $langs->trans("Warehouse").': '.$entrepot->libelle); print ''; - print ''; + print ''; print ''; - print ''; + print ''; print ''; - print ''; - print ''; + print ''; + print ''; print '
'.$langs->trans("Ref").''.$entrepot->libelle.'
'.$langs->trans("Ref").''.$entrepot->libelle.'
'.$langs->trans("Description").''.nl2br($entrepot->description).'
'.$langs->trans("LocationSummary").''.$entrepot->lieu.'
'.$langs->trans("LocationSummary").''.$entrepot->lieu.'
'.$langs->trans('Address').''; print $entrepot->address; print '
'.$langs->trans('Zip').''.$entrepot->cp.''.$langs->trans('Town').''.$entrepot->ville.'
'.$langs->trans('Zip').''.$entrepot->cp.''.$langs->trans('Town').''.$entrepot->ville.'
'.$langs->trans('Country').''; $entrepot->pays; diff --git a/htdocs/product/stock/mouvement.php b/htdocs/product/stock/mouvement.php index 835a3e54831..1711dda7f3a 100644 --- a/htdocs/product/stock/mouvement.php +++ b/htdocs/product/stock/mouvement.php @@ -18,7 +18,6 @@ * * $Id$ * $Source$ - * */ /** @@ -104,5 +103,5 @@ else $db->close(); -llxFooter("Dernière modification $Date$ révision $Revision$"); +llxFooter('$Date$ - $Revision$'); ?> diff --git a/htdocs/product/stock/mouvementstock.class.php b/htdocs/product/stock/mouvementstock.class.php index 36271dabb30..8f2882264a9 100644 --- a/htdocs/product/stock/mouvementstock.class.php +++ b/htdocs/product/stock/mouvementstock.class.php @@ -1,5 +1,6 @@ + * Copyright (C) 2005 Laurent Destailleur * * 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 @@ -17,10 +18,10 @@ * * $Id$ * $Source$ - * */ -/** \file htdocs/product/stock/mouvementstock.class.php +/** + \file htdocs/product/stock/mouvementstock.class.php \ingroup stock \brief Fichier de la classe de gestion des mouvements de stocks \version $Revision$ @@ -34,59 +35,64 @@ class MouvementStock { - function MouvementStock($DB) + function MouvementStock($DB) { - $this->db = $DB; + $this->db = $DB; } - /* - * - * - */ - function _create($user, $product_id, $entrepot_id, $qty, $type, $transaction=1) + /** + * \brief Crée un mouvement en base + * \return int <0 si ko, >0 si ok + */ + function _create($user, $product_id, $entrepot_id, $qty, $type) { + dolibarr_syslog("mouvementstock.class.php::create $user, $product_id, $entrepot_id, $qty, $type"); + + $this->db->begin(); - if ($this->db->begin($transaction) ) - { - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author)"; - $sql .= " VALUES (now(), $product_id, $entrepot_id, $qty, $type, $user->id)"; - - if ($this->db->query($sql)) - { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author)"; + $sql .= " VALUES (now(), $product_id, $entrepot_id, $qty, $type, $user->id)"; - $sql = "UPDATE ".MAIN_DB_PREFIX."product_stock SET reel = reel + $qty WHERE fk_entrepot = $entrepot_id AND fk_product = $product_id"; + if ($this->db->query($sql)) + { - if ($this->db->query($sql)) - { - return 1; - } - else - { - print $this->db->error() . "
$sql
"; - return 0; - } - } - else - { - print $this->db->error() . "
$sql
"; - return 0; - } - } - else - { - return 0; - } - } - /* - * - * - */ - function livraison($user, $product_id, $entrepot_id, $qty, $transaction=1) - { + $sql = "UPDATE ".MAIN_DB_PREFIX."product_stock SET reel = reel + $qty"; + $sql.= " WHERE fk_entrepot = $entrepot_id AND fk_product = $product_id"; - return $this->_create($user, $product_id, $entrepot_id, (0 - $qty), 2, $transaction); + if ($this->db->query($sql)) + { + $this->db->commit(); + //dolibarr_syslog("mouvementstock.class.php::create update ok"); + return 1; + } + else + { + $this->db->rollback(); + $this->error=$this->db->error() . " - $sql"; + dolibarr_syslog("mouvementstock.class.php::create echec update ".$this->error); + return -2; + } + } + else + { + $this->db->rollback(); + $this->error=$this->db->error() . " - $sql"; + dolibarr_syslog("mouvementstock.class.php::create echec insert ".$this->error); + return -1; + } } + + /* + * + * + */ + function livraison($user, $product_id, $entrepot_id, $qty) + { + + return $this->_create($user, $product_id, $entrepot_id, (0 - $qty), 2); + + } + } ?>