diff --git a/ChangeLog b/ChangeLog index 179ee126a70..c85550ee6b4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,8 @@ For users: saved clicks again). - New: Add graph using Jquery Flot. - New: Usage of Jquery Notify to show result or error messages on action. +- New: If a service contains subproducts, subrpoducts are decrease when service + is decrease. - New: Add status for third parties to disable a third party. - New: Can send interventions cards by email. - New: Add option MAIN_FIRST_TO_UPPER to force upper case of first diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 7c4db6b17c9..e69ee5dec0a 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -238,11 +238,12 @@ class Commande extends CommonObject if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) { require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); + $langs->load("agenda"); // Loop on each line for ($i = 0 ; $i < sizeof($this->lines) ; $i++) { - if ($this->lines[$i]->fk_product > 0 && $this->lines[$i]->product_type == 0) + if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); // We decrement stock of product (and sub-products) @@ -345,10 +346,11 @@ class Commande extends CommonObject if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) { require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); + $langs->load("agenda"); for ($i = 0 ; $i < sizeof($this->lines) ; $i++) { - if ($this->lines[$i]->fk_product > 0 && $this->lines[$i]->product_type == 0) + if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); // We increment stock of product (and sub-products) @@ -506,8 +508,9 @@ class Commande extends CommonObject if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) { require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); + $langs->load("agenda"); - if ($this->lines[$i]->fk_product > 0 && $this->lines[$i]->product_type == 0) + if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); // We increment stock of product (and sub-products) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 863b7ad7d8e..4c2c26a2603 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1542,13 +1542,13 @@ class Facture extends CommonObject if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_BILL) { require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); + $langs->load("agenda"); // Loop on each line for ($i = 0 ; $i < sizeof($this->lines) ; $i++) { - if ($this->lines[$i]->fk_product > 0 && $this->lines[$i]->product_type == 0) + if ($this->lines[$i]->fk_product > 0) { - $langs->load("agenda"); $mouvP = new MouvementStock($this->db); // We decrease stock for product $entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot @@ -1653,12 +1653,12 @@ class Facture extends CommonObject if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_BILL) { require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); + $langs->load("agenda"); for ($i = 0 ; $i < sizeof($this->lines) ; $i++) { - if ($this->lines[$i]->fk_product && $this->lines[$i]->product_type == 0) + if ($this->lines[$i]->fk_product > 0) { - $langs->load("agenda"); $mouvP = new MouvementStock($this->db); // We decrease stock for product $entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 7e5a9091107..c42e752081b 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -382,9 +382,9 @@ class Expedition extends CommonObject } /** - * \brief Validate object and update stock if option enabled - * \param user Objet de l'utilisateur qui valide - * \return int + * Validate object and update stock if option enabled + * @param user Object user that validate + * @return int */ function valid($user) { @@ -451,6 +451,7 @@ class Expedition extends CommonObject if (! $error && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT) { require_once DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"; + $langs->load("agenda"); // Loop on each product line to add a stock movement // TODO possibilite d'expedier a partir d'une propale ou autre origine @@ -471,15 +472,12 @@ class Expedition extends CommonObject dol_syslog("Expedition::valid movement index ".$i); $obj = $this->db->fetch_object($resql); - if ($this->lines[$i]->fk_product > 0 && $this->lines[$i]->product_type == 0) - { - //var_dump($this->lines[$i]); - $mouvS = new MouvementStock($this->db); - // We decrement stock of product (and sub-products) - // We use warehouse selected for each line - $result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, $obj->subprice); - if ($result < 0) { $error++; break; } - } + //var_dump($this->lines[$i]); + $mouvS = new MouvementStock($this->db); + // We decrement stock of product (and sub-products) + // We use warehouse selected for each line + $result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, $obj->subprice); + if ($result < 0) { $error++; break; } $i++; } diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 762d17b5c7f..8253308a104 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -412,17 +412,17 @@ class CommandeFournisseur extends Commande if ($this->db->query($sql)) { // If stock is incremented on validate order, we must redecrement it - if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 0) + if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) { require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); for ($i = 0 ; $i < sizeof($this->lines) ; $i++) { - if ($this->lines[$i]->fk_product > 0 && $this->lines[$i]->product_type == 0) + if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); // We increment stock of product (and sub-products) - $entrepot_id = "1"; //Todo: ajouter possibilite de choisir l'entrepot + $entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot $result=$mouvP->reception($user, $this->lines[$i]->fk_product, $entrepot_id, $this->lines[$i]->qty, $this->lines[$i]->subprice); if ($result < 0) { $error++; } } @@ -633,11 +633,11 @@ class CommandeFournisseur extends Commande for ($i = 0 ; $i < sizeof($this->lines) ; $i++) { // Product with reference - if (!empty($this->lines[$i]->fk_product)) + if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); // We decrement stock of product (and sub-products) - $entrepot_id = "1"; //Todo: ajouter possibilite de choisir l'entrepot + $entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot $result=$mouvP->reception($user, $this->lines[$i]->fk_product, $entrepot_id, $this->lines[$i]->qty, $this->lines[$i]->subprice); if ($result < 0) { $error++; } } @@ -1058,9 +1058,8 @@ class CommandeFournisseur extends Commande /** * Add a product into a stock warehouse. - * * @param $user User object making change - * @param $product Product object to dispatch + * @param $product Id of product to dispatch * @param $qty Qty to dispatch * @param $entrepot Id of warehouse to add product * @param $price Price for PMP value calculation @@ -1098,16 +1097,19 @@ class CommandeFournisseur extends Commande $error++; } - // Si module stock gere et que expedition faite depuis un entrepot + // Si module stock gere et que incrementation faite depuis un dispatching en stock 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, $comment); - if ($result < 0) + if ($product > 0) { - $this->error=$mouv->error; - dol_syslog("CommandeFournisseur::DispatchProduct ".$this->error, LOG_ERR); - $error++; + $result=$mouv->reception($user, $product, $entrepot, $qty, $price, $comment); + if ($result < 0) + { + $this->error=$mouv->error; + dol_syslog("CommandeFournisseur::DispatchProduct ".$this->error, LOG_ERR); + $error++; + } } $i++; } @@ -1369,7 +1371,7 @@ class CommandeFournisseur extends Commande return $result ; } - /** + /** * Cree la commande depuis une propale existante * @param user Utilisateur qui cree * @param propale_id id de la propale qui sert de modele diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 2ac91f49eb7..3a703e21adb 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -790,12 +790,12 @@ class FactureFournisseur extends Facture if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) { require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); + $langs->load("agenda"); for ($i = 0 ; $i < sizeof($this->lines) ; $i++) { - if ($this->lines[$i]->fk_product && $this->lines[$i]->product_type == 0) + if ($this->lines[$i]->fk_product > 0) { - $langs->load("agenda"); $mouvP = new MouvementStock($this->db); // We increase stock for product $entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot @@ -865,12 +865,12 @@ class FactureFournisseur extends Facture if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) { require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); + $langs->load("agenda"); for ($i = 0 ; $i < sizeof($this->lines) ; $i++) { - if ($this->lines[$i]->fk_product && $this->lines[$i]->product_type == 0) + if ($this->lines[$i]->fk_product > 0) { - $langs->load("agenda"); $mouvP = new MouvementStock($this->db); // We increase stock for product $entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index 9e7c72052c8..e04b7019bf2 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005 Eric Seigne * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2010 Juanjo Menent @@ -312,7 +312,7 @@ if ($id > 0 || ! empty($ref)) print 'trans("DispatchSupplierOrder",$commande->ref); // print ' / '.$commande->ref_supplier; // Not yet available - print '" class="flat">'; + print '" class="flat">

'; print '
db->query($sql); if ($resql) { - // Si module stock gere et que expedition faite depuis un entrepot - if ($conf->stock->enabled && $this->entrepot_id && $conf->global->STOCK_CALCULATE_ON_RECEIVING == 1) - { - - //Enregistrement d'un mouvement de stock pour chaque produit de l'expedition - - dol_syslog("livraison.class.php::valid enregistrement des mouvements"); - - $sql = "SELECT cd.fk_product, cd.subprice, ld.qty "; - $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; - $sql.= ", ".MAIN_DB_PREFIX."livraisondet as ld"; - $sql.= " WHERE ld.fk_livraison = ".$this->id; - $sql.= " AND cd.rowid = ld.fk_commande_ligne"; - - $resql=$this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i=0; - while($i < $num) - { - dol_syslog("livraison.class.php::valid movement $i"); - - $obj = $this->db->fetch_object($resql); - - $mouvS = new MouvementStock($this->db); - $entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot - $result=$mouvS->livraison($user, $obj->fk_product, $entrepot_id, $obj->qty, $obj->subprice); - if ($result < 0) { $error++; break; } - $i++; - } - - } - else - { - $this->db->rollback(); - $this->error=$this->db->error()." - sql=$sql"; - dol_syslog("livraison.class.php::valid ".$this->error, LOG_ERR); - return -2; - - } - } - // On efface le repertoire de pdf provisoire $livraisonref = dol_sanitizeFileName($this->ref); if ($conf->expedition->dir_output) diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index 2329dacba85..b93a44aa97d 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -32,24 +32,27 @@ */ class MouvementStock { - + /** + * Constructor + * @param DB Database handler + */ function MouvementStock($DB) { $this->db = $DB; } /** - * \brief Add a movement of stock (in one direction only) - * \param user User object - * \param fk_product Id of product - * \param entrepot_id Id of warehouse - * \param qty Qty of movement (can be <0 or >0) - * \param type Direction of movement: + * Add a movement of stock (in one direction only) + * @param user User object + * @param fk_product Id of product + * @param entrepot_id Id of warehouse + * @param qty Qty of movement (can be <0 or >0) + * @param type Direction of movement: * 0=input (stock increase after stock transfert), 1=output (stock decrease after stock transfer), * 2=output (stock decrease), 3=input (stock increase) - * \param price Unit price HT of product - * \param label Label of stock movement - * \return int <0 if KO, >0 if OK + * @param price Unit price HT of product + * @param label Label of stock movement + * @return int <0 if KO, >0 if OK */ function _create($user, $fk_product, $entrepot_id, $qty, $type, $price=0, $label='') { @@ -70,7 +73,10 @@ class MouvementStock return -1; } - if (1 == 1) // Always change stock for current product, change for subproduct is done after + $movestock=0; + if ($product->type != 1 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES)) $movestock=1; + + if ($movestock) // Change stock for current product, change for subproduct is done after { $sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement"; $sql.= " (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author, label, price)"; @@ -195,19 +201,20 @@ class MouvementStock } } - // Add movement for sub products + // Add movement for sub products (recursive call) if (! $error && $conf->global->PRODUIT_SOUSPRODUITS) { $error = $this->_createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, 0, $label); // pmp is not change for subproduct } - // composition module (this is a non official external module) + // Composition module (this is an external module) + /* Removed. This code must be provided by module on trigger STOCK_MOVEMENT if (! $error && $qty < 0 && $conf->global->MAIN_MODULE_COMPOSITION) { $error = $this->_createProductComposition($user, $fk_product, $entrepot_id, $qty, $type, 0, $label); // pmp is not change for subproduct - } + }*/ - if (! $error) + if ($movestock && ! $error) { // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); @@ -285,6 +292,7 @@ class MouvementStock * @param label Label of stock movement * @return int <0 if KO, 0 if OK */ + /* This function is specific to a module. Should be inside the trigger of module instead of core code. function _createProductComposition($user, $fk_product, $entrepot_id, $qty, $type, $price=0, $label='') { dol_syslog("MouvementStock::_createProductComposition $user->id, $fk_product, $entrepot_id, $qty, $type, $price, $label"); @@ -316,7 +324,7 @@ class MouvementStock } return 0; - } + }*/ /** @@ -333,7 +341,7 @@ class MouvementStock /** * Increase stock for product and subproducts * @param label Label of stock movement - * @return int <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK */ function reception($user, $fk_product, $entrepot_id, $qty, $price=0, $label='') {