From b728c133fb2067e17d595b0be89f364fae5bc2d3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 26 May 2008 21:27:50 +0000 Subject: [PATCH] Fix: Stock management debug --- htdocs/expedition/commande.php | 2 +- htdocs/expedition/expedition.class.php | 1072 ++++++++++++------------ htdocs/install/check.php | 1 + htdocs/langs/en_US/stocks.lang | 7 +- htdocs/langs/fr_FR/stocks.lang | 7 +- htdocs/product/reassort.php | 50 +- htdocs/product/stock/product.php | 542 ++++++------ 7 files changed, 848 insertions(+), 833 deletions(-) diff --git a/htdocs/expedition/commande.php b/htdocs/expedition/commande.php index bfd80ceacc3..41a561b4dc3 100644 --- a/htdocs/expedition/commande.php +++ b/htdocs/expedition/commande.php @@ -464,7 +464,7 @@ if ($_GET["id"] > 0) print ""; - + print '
'; show_list_sending_receive('commande',$commande->id); diff --git a/htdocs/expedition/expedition.class.php b/htdocs/expedition/expedition.class.php index 3385f168ec0..25aa8680763 100644 --- a/htdocs/expedition/expedition.class.php +++ b/htdocs/expedition/expedition.class.php @@ -20,21 +20,21 @@ */ /** - \file htdocs/expedition/expedition.class.php - \ingroup expedition - \brief Fichier de la classe de gestion des expeditions - \version $Id$ -*/ + \file htdocs/expedition/expedition.class.php + \ingroup expedition + \brief Fichier de la classe de gestion des expeditions + \version $Id$ + */ require_once(DOL_DOCUMENT_ROOT."/commonobject.class.php"); if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); -/** - \class Expedition - \brief Classe de gestion des expeditions -*/ +/** + \class Expedition + \brief Classe de gestion des expeditions + */ class Expedition extends CommonObject { var $db; @@ -52,506 +52,508 @@ class Expedition extends CommonObject /** - * Initialisation - * - */ + * Initialisation + * + */ function Expedition($DB) { global $langs; $this->db = $DB; $this->lignes = array(); - + $this->statuts[-1] = $langs->trans("Canceled"); $this->statuts[0] = $langs->trans("Draft"); $this->statuts[1] = $langs->trans("Validated"); - + $this->products = array(); } - /** - * \brief Créé expédition en base - * \param user Objet du user qui cré - * \return int <0 si erreur, id expédition créée si ok - */ + /** + * \brief Créé expédition en base + * \param user Objet du user qui cré + * \return int <0 si erreur, id expédition créée si ok + */ function create($user) - { - global $conf; - - require_once DOL_DOCUMENT_ROOT ."/product/stock/mouvementstock.class.php"; - $error = 0; - /* On positionne en mode brouillon l'expedition */ - $this->brouillon = 1; - - $this->user = $user; - - $this->db->begin(); - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."expedition (ref, date_creation, fk_user_author, date_expedition"; - $sql.= ", fk_soc"; - $sql.= ")"; - $sql.= " VALUES ('(PROV)', now(), $user->id, ".$this->db->idate($this->date_expedition); - $sql.= ", ".$this->socid; - $sql.= ")"; - - $resql=$this->db->query($sql); - if ($resql) - { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."expedition"); - - $sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id; - if ($this->db->query($sql)) - { - // Insertion des lignes - for ($i = 0 ; $i < sizeof($this->lignes) ; $i++) - { - if (! $this->create_line($this->lignes[$i]->entrepot_id, $this->lignes[$i]->origin_line_id, $this->lignes[$i]->qty) > 0) - { - $error++; - } - } - - if (! $error && $this->id && $this->origin_id) - { - if ($conf->commande->enabled) - { - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'co_exp (fk_expedition, fk_commande) VALUES ('.$this->id.','.$this->origin_id.')'; - if (!$this->db->query($sql)) - { - $error++; - } - - $sql = "UPDATE ".MAIN_DB_PREFIX."commande SET fk_statut = 2 WHERE rowid=".$this->origin_id; - if (! $this->db->query($sql)) - { - $error++; - } - } - else - { - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'pr_exp (fk_expedition, fk_propal) VALUES ('.$this->id.','.$this->origin_id.')'; - if (!$this->db->query($sql)) - { - $error++; - } - - //Todo: definir un statut - $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = 9 WHERE rowid=".$this->origin_id; - if (! $this->db->query($sql)) - { - $error++; - } - } - } - - if (! $error) - { - $this->db->commit(); - return $this->id; - } - else - { - $error++; - $this->error=$this->db->lasterror()." - sql=$sql"; - $this->db->rollback(); - return -3; - } - } - else - { - $error++; - $this->error=$this->db->lasterror()." - sql=$sql"; - $this->db->rollback(); - return -2; - } - } - else - { - $error++; - $this->error=$this->db->error()." - sql=$sql"; - $this->db->rollback(); - return -1; - } - } + { + global $conf; + + require_once DOL_DOCUMENT_ROOT ."/product/stock/mouvementstock.class.php"; + $error = 0; + /* On positionne en mode brouillon l'expedition */ + $this->brouillon = 1; - /** - * - * - */ - function create_line($entrepot_id, $origin_line_id, $qty) - { - $error = 0; + $this->user = $user; - $sql = "INSERT INTO ".MAIN_DB_PREFIX."expeditiondet (fk_expedition, fk_entrepot, fk_origin_line, qty)"; - $sql .= " VALUES (".$this->id.", ".($entrepot_id?$entrepot_id:'null').", ".$origin_line_id.", ".$qty.")"; - //print 'x'.$sql; - if (! $this->db->query($sql)) - { - $error++; - } + $this->db->begin(); - if (! $error) return 1; - else return -1; - } + $sql = "INSERT INTO ".MAIN_DB_PREFIX."expedition (ref, date_creation, fk_user_author, date_expedition"; + $sql.= ", fk_soc"; + $sql.= ")"; + $sql.= " VALUES ('(PROV)', now(), $user->id, ".$this->db->idate($this->date_expedition); + $sql.= ", ".$this->socid; + $sql.= ")"; - /** + $resql=$this->db->query($sql); + if ($resql) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."expedition"); + + $sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id; + if ($this->db->query($sql)) + { + // Insertion des lignes + for ($i = 0 ; $i < sizeof($this->lignes) ; $i++) + { + if (! $this->create_line($this->lignes[$i]->entrepot_id, $this->lignes[$i]->origin_line_id, $this->lignes[$i]->qty) > 0) + { + $error++; + } + } + + if (! $error && $this->id && $this->origin_id) + { + if ($conf->commande->enabled) + { + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'co_exp (fk_expedition, fk_commande) VALUES ('.$this->id.','.$this->origin_id.')'; + if (!$this->db->query($sql)) + { + $error++; + } + + $sql = "UPDATE ".MAIN_DB_PREFIX."commande SET fk_statut = 2 WHERE rowid=".$this->origin_id; + if (! $this->db->query($sql)) + { + $error++; + } + } + else + { + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'pr_exp (fk_expedition, fk_propal) VALUES ('.$this->id.','.$this->origin_id.')'; + if (!$this->db->query($sql)) + { + $error++; + } + + //Todo: definir un statut + $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = 9 WHERE rowid=".$this->origin_id; + if (! $this->db->query($sql)) + { + $error++; + } + } + } + + if (! $error) + { + $this->db->commit(); + return $this->id; + } + else + { + $error++; + $this->error=$this->db->lasterror()." - sql=$sql"; + $this->db->rollback(); + return -3; + } + } + else + { + $error++; + $this->error=$this->db->lasterror()." - sql=$sql"; + $this->db->rollback(); + return -2; + } + } + else + { + $error++; + $this->error=$this->db->error()." - sql=$sql"; + $this->db->rollback(); + return -1; + } + } + + /** + * + * + */ + function create_line($entrepot_id, $origin_line_id, $qty) + { + $error = 0; + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."expeditiondet (fk_expedition, fk_entrepot, fk_origin_line, qty)"; + $sql .= " VALUES (".$this->id.", ".($entrepot_id?$entrepot_id:'null').", ".$origin_line_id.", ".$qty.")"; + //print 'x'.$sql; + if (! $this->db->query($sql)) + { + $error++; + } + + if (! $error) return 1; + else return -1; + } + + /** * \brief Lit une expedition * \param id */ - function fetch ($id) - { - global $conf; - - $sql = "SELECT e.rowid, e.fk_soc as socid, e.date_creation, e.ref, e.fk_user_author, e.fk_statut"; - $sql.= ", ".$this->db->pdate("e.date_expedition")." as date_expedition, e.model_pdf, e.fk_adresse_livraison"; - if ($conf->commande->enabled) - { - $sql.=", ce.fk_commande as origin_id"; - } - else - { - $sql.=", pe.fk_propal as origin_id"; - } - if ($conf->livraison_bon->enabled) $sql.=", l.rowid as livraison_id"; - $sql.= " FROM ".MAIN_DB_PREFIX."expedition as e"; - if ($conf->commande->enabled) - { - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."co_exp as ce ON e.rowid = ce.fk_expedition"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON ce.fk_commande = c.rowid"; - } - else - { - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."pr_exp as pe ON e.rowid = pe.fk_expedition"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."propal as p ON pe.fk_propal = p.rowid"; - } - if ($conf->livraison_bon->enabled) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON e.rowid = l.fk_expedition"; - $sql.= " WHERE e.rowid = ".$id; + function fetch ($id) + { + global $conf; - $result = $this->db->query($sql) ; - - if ($result) - { - if ($this->db->num_rows($result)) - { - $obj = $this->db->fetch_object($result); - - $this->id = $obj->rowid; - $this->ref = $obj->ref; - $this->socid = $obj->socid; - $this->statut = $obj->fk_statut; - $this->origin_id = $obj->origin_id; - $this->livraison_id = $obj->livraison_id; - $this->user_author_id = $obj->fk_user_author; - $this->date = $obj->date_expedition; - $this->adresse_livraison_id = $obj->fk_adresse_livraison; - $this->modelpdf = $obj->model_pdf; - - if ($conf->commande->enabled) - { - $this->origin = "commande"; - } - else - { - $this->origin = "propal"; - } - - $this->db->free($result); - - if ($this->statut == 0) $this->brouillon = 1; - - $this->lignes = array(); - - $file = $conf->expedition->dir_output . "/" .get_exdir($expedition->id,2) . "/" . $this->id.".pdf"; - $this->pdf_filename = $file; - - /* - * Lignes - */ - $result=$this->fetch_lines(); - if ($result < 0) - { - return -3; - } - - return 1; - } - else - { - dolibarr_syslog('Expedition::Fetch Error rowid='.$rowid.' numrows=0 sql='.$sql); - $this->error='Delivery with id '.$rowid.' not found sql='.$sql; - return -2; - } - } - else - { - dolibarr_syslog('Expedition::Fetch Error rowid='.$rowid.' Erreur dans fetch de l\'expedition'); - $this->error=$this->db->error(); - return -1; - } - } + $sql = "SELECT e.rowid, e.fk_soc as socid, e.date_creation, e.ref, e.fk_user_author, e.fk_statut"; + $sql.= ", ".$this->db->pdate("e.date_expedition")." as date_expedition, e.model_pdf, e.fk_adresse_livraison"; + if ($conf->commande->enabled) + { + $sql.=", ce.fk_commande as origin_id"; + } + else + { + $sql.=", pe.fk_propal as origin_id"; + } + if ($conf->livraison_bon->enabled) $sql.=", l.rowid as livraison_id"; + $sql.= " FROM ".MAIN_DB_PREFIX."expedition as e"; + if ($conf->commande->enabled) + { + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."co_exp as ce ON e.rowid = ce.fk_expedition"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON ce.fk_commande = c.rowid"; + } + else + { + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."pr_exp as pe ON e.rowid = pe.fk_expedition"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."propal as p ON pe.fk_propal = p.rowid"; + } + if ($conf->livraison_bon->enabled) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON e.rowid = l.fk_expedition"; + $sql.= " WHERE e.rowid = ".$id; - /** - * \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"; - - dolibarr_syslog("expedition.class.php::valid"); + $result = $this->db->query($sql) ; - $this->db->begin(); - - $error = 0; - $provref = $this->ref; - - if ($user->rights->expedition->valider) - { - $this->ref = "EXP".$this->id; - - // Tester si non dejà au statut validé. Si oui, on arrete afin d'éviter - // de décrémenter 2 fois le stock. - $sql = "SELECT ref FROM ".MAIN_DB_PREFIX."expedition where ref='".$this->ref."' AND fk_statut <> '0'"; - $resql=$this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - if ($num > 0) - { - return 0; - } - } + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); - $sql = "UPDATE ".MAIN_DB_PREFIX."expedition"; - $sql.= " 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) ) - { - // Si module stock géré et que expedition faite depuis un entrepot - if ($conf->stock->enabled && $this->entrepot_id && $conf->global->STOCK_CALCULATE_ON_SHIPMENT == 1) - { - /* - * Enregistrement d'un mouvement de stock pour chaque produit de l'expedition - */ - dolibarr_syslog("expedition.class.php::valid enregistrement des mouvements"); + $this->id = $obj->rowid; + $this->ref = $obj->ref; + $this->socid = $obj->socid; + $this->statut = $obj->fk_statut; + $this->origin_id = $obj->origin_id; + $this->livraison_id = $obj->livraison_id; + $this->user_author_id = $obj->fk_user_author; + $this->date = $obj->date_expedition; + $this->adresse_livraison_id = $obj->fk_adresse_livraison; + $this->modelpdf = $obj->model_pdf; + + if ($conf->commande->enabled) + { + $this->origin = "commande"; + } + else + { + $this->origin = "propal"; + } + + $this->db->free($result); - $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"; - - $resql=$this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i=0; - while($i < $num) - { - dolibarr_syslog("expedition.class.php::valid movment $i"); + if ($this->statut == 0) $this->brouillon = 1; - $obj = $this->db->fetch_object($resql); + $this->lignes = array(); - $mouvS = new MouvementStock($this->db); - $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; - } + $file = $conf->expedition->dir_output . "/" .get_exdir($expedition->id,2) . "/" . $this->id.".pdf"; + $this->pdf_filename = $file; - $i++; - } - - } - else - { - $this->db->rollback(); - $this->error=$this->db->error()." - sql=$sql"; - dolibarr_syslog("expedition.class.php::valid ".$this->error); - return -2; - } - } - - // On efface le répertoire de pdf provisoire - $expeditionref = sanitize_string($provref); - if ($conf->expedition->dir_output) - { - $dir = $conf->expedition->dir_output . "/" . $expeditionref; - $file = $dir . "/" . $expeditionref . ".pdf"; - if (file_exists($file)) - { - if (!dol_delete_file($file)) - { - $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); - return 0; - } - } - if (file_exists($dir)) - { - if (!dol_delete_dir($dir)) - { - $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); - return 0; - } - } - } - - } - else - { - $this->db->rollback(); - $this->error=$this->db->error()." - sql=$sql"; - dolibarr_syslog("expedition.class.php::valid ".$this->error); - return -1; - } - } - else - { - $this->error="Non autorise"; - dolibarr_syslog("expedition.class.php::valid ".$this->error); - return -1; - } + /* + * Lignes + */ + $result=$this->fetch_lines(); + if ($result < 0) + { + return -3; + } - $this->db->commit(); - //dolibarr_syslog("expedition.class.php::valid commit"); - return 1; - } - - - /** - * \brief Crée un bon de livraison à partir de l'expédition - * \param user Utilisateur - * \return int <0 si ko, >=0 si ok - */ - function create_delivery($user) - { - global $conf; - - if ($conf->livraison_bon->enabled) - { - if ($this->statut == 1) - { - // Expédition validée - include_once(DOL_DOCUMENT_ROOT."/livraison/livraison.class.php"); - $livraison = new Livraison($this->db); - $result=$livraison->create_from_sending($user, $this->id); - if ($result > 0) - { - return $result; - } - else - { - $this->error=$livraison->error; - return $result; - } - } - else return 0; - } - else return 0; - } - - /** - * Ajoute une ligne - * - */ - function addline( $entrepot_id, $id, $qty ) - { - $num = sizeof($this->lignes); - $ligne = new ExpeditionLigne($this->db); - - $ligne->entrepot_id = $entrepot_id; - $ligne->origin_line_id = $id; - $ligne->qty = $qty; - - $this->lignes[$num] = $ligne; - } - - /** - * - * - */ - function delete_line($idligne) - { - if ($this->statut == 0) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet WHERE rowid = $idligne"; - - if ($this->db->query($sql) ) - { - $this->update_price(); - return 1; - } - else - { - return 0; - } - } + return 1; + } + else + { + dolibarr_syslog('Expedition::Fetch Error rowid='.$rowid.' numrows=0 sql='.$sql); + $this->error='Delivery with id '.$rowid.' not found sql='.$sql; + return -2; + } + } + else + { + dolibarr_syslog('Expedition::Fetch Error rowid='.$rowid.' Erreur dans fetch de l\'expedition'); + $this->error=$this->db->error(); + return -1; + } + } + + /** + * \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"; + + dolibarr_syslog("Expedition::valid"); + + $this->db->begin(); + + $error = 0; + $provref = $this->ref; + + if ($user->rights->expedition->valider) + { + $this->ref = "EXP".$this->id; + + // Tester si non dejà au statut validé. Si oui, on arrete afin d'éviter + // de décrémenter 2 fois le stock. + $sql = "SELECT ref FROM ".MAIN_DB_PREFIX."expedition where ref='".$this->ref."' AND fk_statut <> '0'"; + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + if ($num > 0) + { + dolibarr_syslog("Expedition::valid already validated", LOG_WARNING); + $this->db->rollback(); + return 0; + } + } + + $sql = "UPDATE ".MAIN_DB_PREFIX."expedition"; + $sql.= " SET ref='".$this->ref."', fk_statut = 1, date_valid = now(), fk_user_valid = ".$user->id; + $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; + + dolibarr_syslog("Expedition::valid update expedition sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + // If stock increment is done on sending (recommanded choice) + if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT) + { + /* + * Enregistrement d'un mouvement de stock pour chaque produit de l'expedition + */ + $sql = "SELECT cd.fk_product, ed.qty, ed.fk_entrepot"; + $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_origin_line"; + + dolibarr_syslog("Expedition::valid select details sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i=0; + while($i < $num) + { + dolibarr_syslog("Expedition::valid movment nb ".$i); + + $obj = $this->db->fetch_object($resql); + + $mouvS = new MouvementStock($this->db); + $result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty); + if ($result < 0) + { + $this->db->rollback(); + $this->error=$this->db->error()." - sql=$sql"; + dolibarr_syslog("Expedition::valid ".$this->error); + return -3; + } + + $i++; + } + + } + else + { + $this->db->rollback(); + $this->error=$this->db->error()." - sql=$sql"; + dolibarr_syslog("Expedition::valid ".$this->error); + return -2; + } + } + + // On efface le répertoire de pdf provisoire + $expeditionref = sanitize_string($provref); + if ($conf->expedition->dir_output) + { + $dir = $conf->expedition->dir_output . "/" . $expeditionref; + $file = $dir . "/" . $expeditionref . ".pdf"; + if (file_exists($file)) + { + if (!dol_delete_file($file)) + { + $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); + } + } + if (file_exists($dir)) + { + if (!dol_delete_dir($dir)) + { + $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); + } + } + } + + } + else + { + $this->db->rollback(); + $this->error=$this->db->error(); + dolibarr_syslog("Expedition::valid ".$this->error); + return -1; + } + } + else + { + $this->db->rollback(); + $this->error="Non autorise"; + dolibarr_syslog("Expedition::valid ".$this->error); + return -1; + } + + $this->db->commit(); + //dolibarr_syslog("expedition.class.php::valid commit"); + return 1; + } + + + /** + * \brief Crée un bon de livraison à partir de l'expédition + * \param user Utilisateur + * \return int <0 si ko, >=0 si ok + */ + function create_delivery($user) + { + global $conf; + + if ($conf->livraison_bon->enabled) + { + if ($this->statut == 1) + { + // Expédition validée + include_once(DOL_DOCUMENT_ROOT."/livraison/livraison.class.php"); + $livraison = new Livraison($this->db); + $result=$livraison->create_from_sending($user, $this->id); + if ($result > 0) + { + return $result; + } + else + { + $this->error=$livraison->error; + return $result; + } + } + else return 0; + } + else return 0; + } + + /** + * Ajoute une ligne + * + */ + function addline( $entrepot_id, $id, $qty ) + { + $num = sizeof($this->lignes); + $ligne = new ExpeditionLigne($this->db); + + $ligne->entrepot_id = $entrepot_id; + $ligne->origin_line_id = $id; + $ligne->qty = $qty; + + $this->lignes[$num] = $ligne; + } + + /** + * + * + */ + function delete_line($idligne) + { + if ($this->statut == 0) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet WHERE rowid = $idligne"; + + if ($this->db->query($sql) ) + { + $this->update_price(); + return 1; + } + else + { + return 0; + } + } + } + + /** + * Supprime la fiche + * + */ + function delete() + { + $this->db->begin(); + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet WHERE fk_expedition = ".$this->id; + if ( $this->db->query($sql) ) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."expedition WHERE rowid = ".$this->id; + if ( $this->db->query($sql) ) + { + $this->db->commit(); + + // On efface le répertoire de pdf provisoire + $expref = sanitize_string($this->ref); + if ($conf->expedition->dir_output) + { + $dir = $conf->expedition->dir_output . "/" . $expref ; + $file = $conf->expedition->dir_output . "/" . $expref . "/" . $expref . ".pdf"; + if (file_exists($file)) + { + if (!dol_delete_file($file)) + { + $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); + return 0; + } + } + if (file_exists($dir)) + { + if (!dol_delete_dir($dir)) + { + $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); + return 0; + } + } + } + return 1; + } + else + { + $this->db->rollback(); + return -2; + } + } + else + { + $this->db->rollback(); + return -1; + } } - - /** - * Supprime la fiche - * - */ - function delete() - { - $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet WHERE fk_expedition = ".$this->id; - if ( $this->db->query($sql) ) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."expedition WHERE rowid = ".$this->id; - if ( $this->db->query($sql) ) - { - $this->db->commit(); - - // On efface le répertoire de pdf provisoire - $expref = sanitize_string($this->ref); - if ($conf->expedition->dir_output) - { - $dir = $conf->expedition->dir_output . "/" . $expref ; - $file = $conf->expedition->dir_output . "/" . $expref . "/" . $expref . ".pdf"; - if (file_exists($file)) - { - if (!dol_delete_file($file)) - { - $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); - return 0; - } - } - if (file_exists($dir)) - { - if (!dol_delete_dir($dir)) - { - $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); - return 0; - } - } - } - return 1; - } - else - { - $this->db->rollback(); - return -2; - } - } - else - { - $this->db->rollback(); - return -1; - } - } - /* - * Lit le document associé - * - */ + * Lit le document associé + * + */ function fetch_object() { $object = $this->origin; @@ -560,11 +562,11 @@ class Expedition extends CommonObject $this->$object->fetch($this->origin_id); } - + function fetch_lines() { //Todo: récupérer les champs du document associé a part - + $sql = "SELECT cd.rowid, cd.fk_product, cd.description, cd.qty as qty_asked"; $sql.= ", ed.qty as qty_shipped, ed.fk_origin_line, ed.fk_entrepot"; $sql.= ", p.ref, p.label, p.weight, p.weight_units, p.volume, p.volume_units"; @@ -572,8 +574,8 @@ class Expedition extends CommonObject $sql.= ", ".MAIN_DB_PREFIX."expeditiondet as ed)"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON (p.rowid = cd.fk_product)"; $sql.= " WHERE ed.fk_expedition = ".$this->id; - $sql.= " AND ed.fk_origin_line = cd.rowid"; - + $sql.= " AND ed.fk_origin_line = cd.rowid"; + $resql = $this->db->query($sql); if ($resql) { @@ -583,9 +585,9 @@ class Expedition extends CommonObject { $ligne = new ExpeditionLigne($this->db); $obj = $this->db->fetch_object($resql); - + $ligne->origin_line_id = $obj->fk_origin_line; - $ligne->entrepot_id = $obj->fk_entrepot; + $ligne->entrepot_id = $obj->fk_entrepot; $ligne->fk_product = $obj->fk_product; $ligne->ref = $obj->ref; $ligne->libelle = $obj->label; @@ -596,7 +598,7 @@ class Expedition extends CommonObject $ligne->weight_units = $obj->weight_units; $ligne->volume = $obj->volume; $ligne->volume_units = $obj->volume_units; - + $this->lignes[$i] = $ligne; $i++; } @@ -606,51 +608,51 @@ class Expedition extends CommonObject else { $this->error=$this->db->error(); - dolibarr_syslog('Expedition::fetch_lines: Error '.$this->error); - return -3; - } + dolibarr_syslog('Expedition::fetch_lines: Error '.$this->error); + return -3; + } } - - /** - * \brief Retourne le libellé du statut d'une expedition - * \return string Libellé - */ - function getLibStatut($mode=0) - { - return $this->LibStatut($this->statut,$mode); - } - + + /** + * \brief Retourne le libellé du statut d'une expedition + * \return string Libellé + */ + function getLibStatut($mode=0) + { + return $this->LibStatut($this->statut,$mode); + } + /** * \brief Renvoi le libellé d'un statut donné * \param statut Id statut * \param mode 0=libellé long, 1=libellé court, 2=Picto + Libellé court, 3=Picto, 4=Picto + Libellé long, 5=Libellé court + Picto * \return string Libellé */ - function LibStatut($statut,$mode) - { + function LibStatut($statut,$mode) + { global $langs; - if ($mode==0) - { - if ($statut==0) return $this->statuts[$statut]; - if ($statut==1) return $this->statuts[$statut]; - } - if ($mode==1) - { - if ($statut==0) return $this->statuts[$statut]; - if ($statut==1) return $this->statuts[$statut]; - } - if ($mode == 4) - { - if ($statut==0) return img_picto($langs->trans('StatusSendingDraft'),'statut0').' '.$langs->trans('StatusSendingDraft'); - if ($statut==1) return img_picto($langs->trans('StatusSendingValidated'),'statut4').' '.$langs->trans('StatusSendingValidated'); + if ($mode==0) + { + if ($statut==0) return $this->statuts[$statut]; + if ($statut==1) return $this->statuts[$statut]; } - if ($mode == 5) - { - if ($statut==0) return $langs->trans('StatusSendingDraftShort').' '.img_picto($langs->trans('StatusSendingDraft'),'statut0'); - if ($statut==1) return $langs->trans('StatusSendingValidatedShort').' '.img_picto($langs->trans('StatusSendingValidated'),'statut4'); + if ($mode==1) + { + if ($statut==0) return $this->statuts[$statut]; + if ($statut==1) return $this->statuts[$statut]; } - } + if ($mode == 4) + { + if ($statut==0) return img_picto($langs->trans('StatusSendingDraft'),'statut0').' '.$langs->trans('StatusSendingDraft'); + if ($statut==1) return img_picto($langs->trans('StatusSendingValidated'),'statut4').' '.$langs->trans('StatusSendingValidated'); + } + if ($mode == 5) + { + if ($statut==0) return $langs->trans('StatusSendingDraftShort').' '.img_picto($langs->trans('StatusSendingDraft'),'statut0'); + if ($statut==1) return $langs->trans('StatusSendingValidatedShort').' '.img_picto($langs->trans('StatusSendingValidated'),'statut4'); + } + } /** * \brief Initialise la facture avec valeurs fictives aléatoire @@ -695,25 +697,25 @@ class Expedition extends CommonObject $order=new Commande($this->db); $order->initAsSpecimen(); - + // Initialise paramètres $this->id=0; $this->ref = 'SPECIMEN'; $this->specimen=1; $socid = rand(1, $num_socs); - $this->statut = 1; - if ($conf->livraison_bon->enabled) - { - $this->livraison_id = 0; - } - $this->date = time(); - $this->entrepot_id = 0; - $this->adresse_livraison_id = 0; + $this->statut = 1; + if ($conf->livraison_bon->enabled) + { + $this->livraison_id = 0; + } + $this->date = time(); + $this->entrepot_id = 0; + $this->adresse_livraison_id = 0; $this->socid = $socids[$socid]; $this->commande_id = 0; $this->commande = $order; - + $nbp = 5; $xnbp = 0; while ($xnbp < $nbp) @@ -727,33 +729,33 @@ class Expedition extends CommonObject $ligne->fk_product=$prodids[$prodid]; $xnbp++; } - } + } } /** - \class ExpeditionLigne - \brief Classe de gestion des lignes de bons d'expedition -*/ + \class ExpeditionLigne + \brief Classe de gestion des lignes de bons d'expedition + */ class ExpeditionLigne { var $db; - + // From llx_expeditiondet var $qty; var $qty_expedition; var $fk_product; - + // From llx_commandedet or llx_propaldet var $qty_asking; var $libelle; // Label produit var $product_desc; // Description produit var $ref; - + function ExpeditionLigne($DB) { - $this->db=$DB; + $this->db=$DB; } } diff --git a/htdocs/install/check.php b/htdocs/install/check.php index 2c15104384c..6c8866491e0 100644 --- a/htdocs/install/check.php +++ b/htdocs/install/check.php @@ -113,6 +113,7 @@ else // Check if GD installed if (! function_exists("imagecreate")) { + $langs->load("errors"); print 'Error '.$langs->trans("ErrorPHPDoesNotSupportGD")."
\n"; // $checksok=0; // If image ko, just warning. So check must still be 1 (otherwise no way to install) } diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index 1a2bc795fcf..ac49aa81818 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -38,9 +38,10 @@ EnhancedValueOfWarehouses=Warehouses value UserWarehouseAutoCreate=Create a stock automatically when creating a user QtyDispatched=Quantity dispatched OrderDispatch=Order dispatching -DeStockReStockOnBill=Decrease/increase stocks on invoices/credit notes -DeStockReStockOnValidateOrder=Decrease/increase stocks on orders notes -DeStockReStockOnShipment=Decrease/increase stocks on shipment +DeStockReStockOnBill=Decrease/increase real stocks on invoices/credit notes +DeStockReStockOnValidateOrder=Decrease/increase real stocks on orders notes +DeStockReStockOnShipment=Decrease/increase real stocks on shipment +StockDiffPhysicTeoric=Reason for difference stock physical and theorical 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 8204a3483d9..bfc4fcdee30 100644 --- a/htdocs/langs/fr_FR/stocks.lang +++ b/htdocs/langs/fr_FR/stocks.lang @@ -38,9 +38,10 @@ EnhancedValueOfWarehouses=Valorisation des stocks UserWarehouseAutoCreate=Créer un stock automatiquement à la création d'un utilisateur QtyDispatched=Quantité ventilée OrderDispatch=Ventilation commande -DeStockReStockOnBill=Décrémente/Incrémente les stocks sur les factures/avoirs -DeStockReStockOnValidateOrder=Décrémente/Incrémente les stocks sur les commandes -DeStockReStockOnShipment=Décrémente/Incrémente les stocks sur les expéditions +DeStockReStockOnBill=Décrémente/Incrémente les stocks réels sur les factures/avoirs +DeStockReStockOnValidateOrder=Décrémente/Incrémente les stocks réels sur les commandes +DeStockReStockOnShipment=Décrémente/Incrémente les stocks réels sur les expéditions +StockDiffPhysicTeoric=Raison écart stock physique-théorique StockLimitShort=Seuil StockLimit=Seuil alerte stock PhysicalStock=Stock physique diff --git a/htdocs/product/reassort.php b/htdocs/product/reassort.php index 8c51f1c0de7..c5614407cd9 100644 --- a/htdocs/product/reassort.php +++ b/htdocs/product/reassort.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2005-2006 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -16,15 +16,13 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ */ /** - \file htdocs/product/liste.php + \file htdocs/product/reassort.php \ingroup produit \brief Page liste des produits ou services - \version $Revision$ + \version $Id$ */ require("./pre.inc.php"); @@ -181,13 +179,18 @@ if ($resql) print "
"; } + print '
'; + print ''; + print ''; + print ''; + print ''; // Lignes des titres print ""; print_liste_field_titre($langs->trans("Ref"),"reassort.php", "p.ref","&envente=$envente".(isset($type)?"&type=$type":"")."&fourn_id=$fourn_id&snom=$snom&sref=$sref","","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Label"),"reassort.php", "p.label","&envente=$envente&".(isset($type)?"&type=$type":"")."&fourn_id=$fourn_id&snom=$snom&sref=$sref","","",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("TheoreticalStock"),"reassort.php", "stock_theorique","&envente=$envente&".(isset($type)?"&type=$type":"")."&fourn_id=$fourn_id&snom=$snom&sref=$sref","",'align="right"',$sortfield,$sortorder); + //print_liste_field_titre($langs->trans("TheoreticalStock"),"reassort.php", "stock_theorique","&envente=$envente&".(isset($type)?"&type=$type":"")."&fourn_id=$fourn_id&snom=$snom&sref=$sref","",'align="right"',$sortfield,$sortorder); if ($conf->service->enabled && $type == 1) print_liste_field_titre($langs->trans("Duration"),"reassort.php", "p.duration","&envente=$envente&".(isset($type)?"&type=$type":"")."&fourn_id=$fourn_id&snom=$snom&sref=$sref","",'align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("PhysicalStock"),"reassort.php", "stock_physique","&envente=$envente&".(isset($type)?"&type=$type":"")."&fourn_id=$fourn_id&snom=$snom&sref=$sref","",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("MininumStock"),"reassort.php", "p.seuil_stock_alerte","&envente=$envente&".(isset($type)?"&type=$type":"")."&fourn_id=$fourn_id&snom=$snom&sref=$sref","",'align="right"',$sortfield,$sortorder); @@ -195,10 +198,6 @@ if ($resql) print "\n"; // Lignes des champs de filtre - print ''; - print ''; - print ''; - print ''; print ''; print ''; } - print ''; print ''; print ''; - print ''; $product_static=new Product($db); @@ -245,21 +243,12 @@ if ($resql) $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); + //if ($objp->stock_theorique < $objp->seuil_stock_alerte) print ' '.img_warning($langs->trans("StockTooLow")); + print ''; print ''; if ($conf->service->enabled && $type == 1) @@ -271,7 +260,7 @@ if ($resql) else print $objp->duration; print ''; } - print ''; + //print ''; print ''; print ''; print ''; @@ -279,6 +268,9 @@ if ($resql) $i++; } + print "
'; print ''; @@ -212,7 +211,7 @@ if ($resql) print ' '; print ''; + print ''; print ' '; print ''; @@ -220,7 +219,6 @@ if ($resql) print ''; print '
'; - print "rowid\">"; - if ($objp->fk_product_type==1) - { - print img_object($langs->trans("ShowService"),"service"); - } - else - { - if ( $objp->stock_theorique > $objp->seuil_stock_alerte) { - print img_object($langs->trans("ShowProduct"),"product"); - } else { - print img_warning($langs->trans("StockTooLow")); - } - } - print ' '; - print ''.$objp->ref.''.$objp->label.''.$objp->stock_theorique.''.$objp->stock_theorique.''.$objp->stock_physique.''.$objp->seuil_stock_alerte.''.$product_static->LibStatut($objp->statut,5).'
"; + print ''; + if ($num > $conf->liste_limit) { if ($sref || $snom || $sall || $_POST["search"]) @@ -293,8 +285,6 @@ if ($resql) $db->free($resql); - print ""; - } else { diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php index 34258bbc426..3338e5bd1b8 100644 --- a/htdocs/product/stock/product.php +++ b/htdocs/product/stock/product.php @@ -21,11 +21,11 @@ */ /** - \file htdocs/product/stock/product.php - \ingroup product - \brief Page de la fiche stock d'un produit - \version $Id$ -*/ + \file htdocs/product/stock/product.php + \ingroup product + \brief Page de la fiche stock d'un produit + \version $Id$ + */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/product.lib.php"); @@ -44,50 +44,50 @@ if (! $user->rights->produit->lire || ! $product->type == 0 || ! $conf->stock->e /* -* Actions -*/ + * Actions + */ if ($_POST["action"] == "create_stock") { - $product = new Product($db); - $product->id = $_GET["id"]; - $product->create_stock($_POST["id_entrepot"], $_POST["nbpiece"]); + $product = new Product($db); + $product->id = $_GET["id"]; + $product->create_stock($_POST["id_entrepot"], $_POST["nbpiece"]); } if ($_POST["action"] == "correct_stock" && $_POST["cancel"] <> $langs->trans("Cancel")) { if (is_numeric($_POST["nbpiece"])) - { - $product = new Product($db); - $product->id = $_GET["id"]; - $product->correct_stock($user, - $_POST["id_entrepot"], - $_POST["nbpiece"], - $_POST["mouvement"]); - } + { + $product = new Product($db); + $product->id = $_GET["id"]; + $product->correct_stock($user, + $_POST["id_entrepot"], + $_POST["nbpiece"], + $_POST["mouvement"]); + } } if ($_POST["action"] == "transfert_stock" && $_POST["cancel"] <> $langs->trans("Cancel")) { - if ($_POST["id_entrepot_source"] <> $_POST["id_entrepot_destination"]) - { - if (is_numeric($_POST["nbpiece"])) + if ($_POST["id_entrepot_source"] <> $_POST["id_entrepot_destination"]) { - + if (is_numeric($_POST["nbpiece"])) + { + $product = new Product($db); $product->id = $_GET["id"]; - $product->correct_stock($user, - $_POST["id_entrepot_source"], - $_POST["nbpiece"], - 1); + $product->correct_stock($user, + $_POST["id_entrepot_source"], + $_POST["nbpiece"], + 1); - $product->correct_stock($user, - $_POST["id_entrepot_destination"], - $_POST["nbpiece"], - 0); + $product->correct_stock($user, + $_POST["id_entrepot_destination"], + $_POST["nbpiece"], + 0); + } } - } } /* @@ -96,251 +96,271 @@ if ($_POST["action"] == "transfert_stock" && $_POST["cancel"] <> $langs->trans(" */ if ($_GET["id"] || $_GET["ref"]) { - $product = new Product($db); - if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]); - if ($_GET["id"]) $result = $product->fetch($_GET["id"]); - - llxHeader("","",$langs->trans("CardProduct".$product->type)); + $product = new Product($db); + if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]); + if ($_GET["id"]) $result = $product->fetch($_GET["id"]); - if ($result > 0) - { - $head=product_prepare_head($product, $user); - $titre=$langs->trans("CardProduct".$product->type); - dolibarr_fiche_head($head, 'stock', $titre); - - $html = new Form($db); - - print($mesg); + llxHeader("","",$langs->trans("CardProduct".$product->type)); - print ''; + if ($result > 0) + { + $head=product_prepare_head($product, $user); + $titre=$langs->trans("CardProduct".$product->type); + dolibarr_fiche_head($head, 'stock', $titre); - // Reference - print ''; - print ''; - print ''; - - // Libellé - print ''; - print ''; + $html = new Form($db); - // Prix - print ''; + print($mesg); - // Statut - print ''; + print '
'.$langs->trans("Ref").''; - print $html->showrefnav($product,'ref','',1,'ref'); - print '
'.$langs->trans("Label").''.$product->libelle.'
'.$langs->trans("SellingPrice").''; - if ($product->price_base_type == 'TTC') - { - print price($product->price_ttc).' '.$langs->trans($product->price_base_type); - } - else - { - print price($product->price).' '.$langs->trans($product->price_base_type); - } - print '
'.$langs->trans("Status").''; - print $product->getLibStatut(2); - print '
'; - // Stock - print ''; - print ''; - print ''; - - // Stock - print ''; - if ($product->stock_reel < $product->seuil_stock_alerte) + // Reference + print ''; + print ''; + print ''; + + // Libellé + print ''; + print ''; + + // Prix + print ''; + print price($product->price_ttc).' '.$langs->trans($product->price_base_type); } else { - print "'; + print price($product->price).' '.$langs->trans($product->price_base_type); } - print ''; - - // Stock - print ''; - print "'; - print ''; - - // Nbre de commande clients en cours - if ($conf->commande->enabled) - { - $result=$product->load_stats_commande(0,'2'); - if ($result < 0) dolibarr_print_error($db,$product->error); - print ''; - print ''; - } - - // Nbre de commande fournisseurs en cours - if ($conf->fournisseur->enabled) - { - $result=$product->load_stats_commande_fournisseur(0,'3'); - if ($result < 0) dolibarr_print_error($db,$product->error); - print ''; - print ''; - } - - print "
'.$langs->trans("StockLimit").''.$product->seuil_stock_alerte.'
'.$langs->trans("PhysicalStock").'
'.$langs->trans("Ref").''; + print $html->showrefnav($product,'ref','',1,'ref'); + print '
'.$langs->trans("Label").''.$product->libelle.'
'.$langs->trans("SellingPrice").''; + if ($product->price_base_type == 'TTC') { - print ''.$product->stock_reel.' '.img_warning().'".$product->stock_reel.'
'.$langs->trans("VirtualStock").'".$langs->trans("FeatureNotYetAvailable").'
'.$langs->trans("CustomersOrdersRunning").''; - print $product->stats_commande['qty']; - $result=$product->load_stats_commande(0,'0,1'); - if ($result < 0) dolibarr_print_error($db,$product->error); - print ' ('.$langs->trans("DraftOrWaitingShipped").': '.$product->stats_commande['qty'].')'; - print '
'.$langs->trans("SuppliersOrdersRunning").''; - print $product->stats_commande_fournisseur['qty']; - $result=$product->load_stats_commande_fournisseur(0,'0,1,2'); - if ($result < 0) dolibarr_print_error($db,$product->error); - print ' ('.$langs->trans("DraftOrWaitingApproved").': '.$product->stats_commande_fournisseur['qty'].')'; - print '
"; + print ''; - } - print ''; + // Statut + print ''.$langs->trans("Status").''; + print $product->getLibStatut(2); + print ''; - /* - * Correction du stock - */ - if ($_GET["action"] == "correction") - { - print_titre($langs->trans("StockCorrection")); - print "
id\" method=\"post\">\n"; - print ''; - print ''; - print ''; - - // Entrepot - print ''; + print ''; + print ''; - $resql=$db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $obj = $db->fetch_object($resql); - print ''; - print ''; - print ''; - print ''; - print '
'.$langs->trans("Warehouse").'
'.$langs->trans("PhysicalStock").''.$product->stock_reel.'
'; - print ''.$langs->trans("NumberOfUnit").'
 '; - print '
'; - print '
'; + // Calculating a theorical value of stock if stock increment is done on order + if ($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) + { + $stock_commande_client=$stock_commande_fournisseur=0; + + if ($conf->commande->enabled) + { + $result=$product->load_stats_commande(0,'2'); + if ($result < 0) dolibarr_print_error($db,$product->error); + $stock_commande_client=$product->stats_commande['qty']; + } + if ($conf->fournisseur->enabled) + { + $result=$product->load_stats_commande_fournisseur(0,'3'); + if ($result < 0) dolibarr_print_error($db,$product->error); + $stock_commande_fournisseur=$product->stats_commande_fournisseur['qty']; + } + + $product->stock_theorique=$product->stock_reel-$stock_commande_client+$stock_commande_fournisseur; + + // Stock theorique + print ''.$langs->trans("VirtualStock").''; + print "".$product->stock_theorique; + if ($product->stock_theorique < $product->seuil_stock_alerte) + { + print ' '.img_warning($langs->trans("StockTooLow")); + } + print ''; + print ''; + + if ($product->stock_theorique != $product->stock_reel) + { + print ''.$langs->trans("StockDiffPhysicTeoric").''; + print ''; + $found=0; + + // Nbre de commande clients en cours + if ($conf->commande->enabled) + { + if ($found) print '
'; else $found=1; + print $langs->trans("CustomersOrdersRunning").': '.$stock_commande_client; + $result=$product->load_stats_commande(0,'0,1'); + if ($result < 0) dolibarr_print_error($db,$product->error); + print ' ('.$langs->trans("DraftOrWaitingShipped").': '.$product->stats_commande['qty'].')'; + } + + // Nbre de commande fournisseurs en cours + if ($conf->fournisseur->enabled) + { + if ($found) print '
'; else $found=1; + print $langs->trans("SuppliersOrdersRunning").': '.$stock_commande_fournisseur; + $result=$product->load_stats_commande_fournisseur(0,'0,1,2'); + if ($result < 0) dolibarr_print_error($db,$product->error); + print ' ('.$langs->trans("DraftOrWaitingApproved").': '.$product->stats_commande_fournisseur['qty'].')'; + } + print ''; + } + } + + // Stock + print ''.$langs->trans("StockLimit").''; + print ''.$product->seuil_stock_alerte.''; + print ''; - } - - /* - * Transfert de pièces - */ - if ($_GET["action"] == "transfert") - { - print_titre($langs->trans("Transfer")); - print "
id\" method=\"post\">\n"; - print ''; - print ''; - print '
'.$langs->trans("Source").'
"; - $sql = "SELECT e.rowid, e.label FROM ".MAIN_DB_PREFIX."entrepot as e"; - $sql .= " WHERE statut = 1"; - $sql .= " ORDER BY lower(e.label)"; + } + print ''; - $resql=$db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $obj = $db->fetch_object($resql); - print '
'; + print ''; + print ' '; + print ''; + print ''; + print ''; - } - - /* - * - */ - if ($_GET["action"] == "definir") - { - print_titre($langs->trans("SetStock")); - print "
id\" method=\"post\">\n"; - print ''; - print ''; - print ''; + + print ''; + print ''; + print ''; + print '
'.$langs->trans("Warehouse").''; + print ''; + print ''; - print ''; - print '
'.$langs->trans("Source").'Nb de pièce
 '; - print '
'; - print ''; - } + $sql = "SELECT e.rowid, e.label FROM ".MAIN_DB_PREFIX."entrepot as e"; + $sql .= " WHERE statut = 1"; + $sql .= " ORDER BY lower(e.label)"; + + $resql=$db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $obj = $db->fetch_object($resql); + print '
'.$langs->trans("Target").''.$langs->trans("NumberOfUnit").'
 '; + print '
'; + print ''; + + } + + /* + * + */ + if ($_GET["action"] == "definir") + { + print_titre($langs->trans("SetStock")); + print "
id\" method=\"post\">\n"; + print ''; + print ''; + print ''; + print ''; + print '
'.$langs->trans("Warehouse").'Nb de pièce
 '; + print '
'; + print '
'; + } } else { - dolibarr_print_error(); + dolibarr_print_error(); } /* ************************************************************************** */ -/* */ -/* Barre d'action */ -/* */ +/* */ +/* Barre d'action */ +/* */ /* ************************************************************************** */ print "
\n"; @@ -351,7 +371,7 @@ if ($_GET["action"] == '' ) { print ''.$langs->trans("StockMovement").''; } - + if ($user->rights->stock->creer) { print ''.$langs->trans("StockCorrection").''; @@ -378,21 +398,21 @@ $entrepotstatic=new Entrepot($db); $resql=$db->query($sql); if ($resql) { - $num = $db->num_rows($resql); - $i=0; $total=0; $var=false; - while ($i < $num) - { - $obj = $db->fetch_object($resql); - $entrepotstatic->id=$obj->rowid; - $entrepotstatic->libelle=$obj->label; - print ''; - print ''.$entrepotstatic->getNomUrl(1).''; - print ''.$obj->reel.''; - print ''; ; - $total = $total + $obj->reel; - $i++; - $var=!$var; - } + $num = $db->num_rows($resql); + $i=0; $total=0; $var=false; + while ($i < $num) + { + $obj = $db->fetch_object($resql); + $entrepotstatic->id=$obj->rowid; + $entrepotstatic->libelle=$obj->label; + print ''; + print ''.$entrepotstatic->getNomUrl(1).''; + print ''.$obj->reel.''; + print ''; ; + $total = $total + $obj->reel; + $i++; + $var=!$var; + } } print ''.$langs->trans("Total").':'.$total.""; print "";