diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 5566ce4d90db7625d8660e73b0f663b96a0ec5e2..814c58b92f3bcb050716f3ba52a3f71b750bb51e 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -253,6 +253,7 @@ class Commande extends CommonOrder if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); + $mouvP->origin = &$this; // We decrement stock of product (and sub-products) $result=$mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("OrderValidatedInDolibarr",$num)); if ($result < 0) { $error++; } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index ec86fbcbaecdcc7c7169e0609065190f70270d63..07470503ec21911d4f0ff249d064336354337f8b 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1329,6 +1329,7 @@ class Facture extends CommonInvoice if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); + $mouvP->origin = &$this; // We decrease stock for product if ($this->type == self::TYPE_CREDIT_NOTE) $result=$mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceDeleteDolibarr",$this->ref)); else $result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, 0, $langs->trans("InvoiceDeleteDolibarr",$this->ref)); // we use 0 for price, to not change the weighted average value @@ -1794,6 +1795,7 @@ class Facture extends CommonInvoice if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); + $mouvP->origin = &$this; // We decrease stock for product if ($this->type == self::TYPE_CREDIT_NOTE) $result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceValidatedInDolibarr",$num)); else $result=$mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceValidatedInDolibarr",$num)); @@ -1916,6 +1918,7 @@ class Facture extends CommonInvoice if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); + $mouvP->origin = &$this; // We decrease stock for product if ($this->type == self::TYPE_CREDIT_NOTE) $result=$mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceBackToDraftInDolibarr",$this->ref)); else $result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, 0, $langs->trans("InvoiceBackToDraftInDolibarr",$this->ref)); // we use 0 for price, to not change the weighted average value diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 914ec8719511345d5fce9972a0cfa148623b6ef8..c7d3843dd0f2421abb6a7956a579f86a5667e748 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -580,6 +580,7 @@ class Expedition extends CommonObject //var_dump($this->lines[$i]); $mouvS = new MouvementStock($this->db); + $mouvS->origin = &$this; // 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, $langs->trans("ShipmentValidatedInDolibarr",$numref)); @@ -902,6 +903,7 @@ class Expedition extends CommonObject //var_dump($this->lines[$i]); $mouvS = new MouvementStock($this->db); + $mouvS->origin = &$this; // We decrement stock of product (and sub-products) // We use warehouse selected for each line $result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, $obj->subprice, $langs->trans("ShipmentDeletedInDolibarr",$this->ref)); diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index ed9cd323597ef123758b44e4d4cbf179e635ec8f..ecf163da81d6c3c1d38f3fdf3ecd37ad25386853 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -635,6 +635,7 @@ class CommandeFournisseur extends CommonOrder if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); + $mouvP->origin = &$this; // We decrement stock of product (and sub-products) $up_ht_disc=$this->lines[$i]->subprice; if (! empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) $up_ht_disc=price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100, 'MU'); @@ -1288,6 +1289,7 @@ class CommandeFournisseur extends CommonOrder if ($product > 0) { // $price should take into account discount (except if option STOCK_EXCLUDE_DISCOUNT_FOR_PMP is on) + $mouv->origin = &$this; $result=$mouv->reception($user, $product, $entrepot, $qty, $price, $comment); if ($result < 0) { diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index cefceac2047006f6d453f0bee7cd0c975bc44173..7e7cc14a92c056700d7796843a61cdc8fc8a5984 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -906,6 +906,7 @@ class FactureFournisseur extends CommonInvoice if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); + $mouvP->origin = &$this; // We increase stock for product $up_ht_disc=$this->lines[$i]->pu_ht; if (! empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) $up_ht_disc=price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100, 'MU'); diff --git a/htdocs/install/mysql/migration/3.5.0-3.6.0.sql b/htdocs/install/mysql/migration/3.5.0-3.6.0.sql index eef2d5eedce5033eb28c3a06f881ddcb38bd6e13..0fb148e0f40032116a12c92e4ccea51e4db16611 100644 --- a/htdocs/install/mysql/migration/3.5.0-3.6.0.sql +++ b/htdocs/install/mysql/migration/3.5.0-3.6.0.sql @@ -1060,4 +1060,8 @@ CREATE TABLE llx_payment_salary ( fk_bank integer, fk_user_creat integer, fk_user_modif integer -)ENGINE=innodb; \ No newline at end of file +)ENGINE=innodb; + +--New 1074 : Stock mouvement link to origin +ALTER TABLE llx_stock_mouvement ADD fk_origin INT NOT NULL ; +ALTER TABLE llx_stock_mouvement ADD origintype VARCHAR( 32 ) NOT NULL ; \ No newline at end of file diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index 143b9a8466cf1c8467c7312ade0eebff671a90a5..3c3980188055337eb4f5b2848ac96c4702a4de27 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -94,12 +94,23 @@ class MouvementStock if ($movestock && $entrepot_id > 0) // Change stock for current product, change for subproduct is done after { + if(!empty($this->origin)) { + $origintype = $this->origin->element; + $fk_origin = $this->origin->id; + } else { + $origintype = ''; + $fk_origin = 0; + } + $sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement"; - $sql.= " (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author, label, price)"; + $sql.= " (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author, label, price, fk_origin, origintype)"; $sql.= " VALUES ('".$this->db->idate($now)."', ".$fk_product.", ".$entrepot_id.", ".$qty.", ".$type.","; $sql.= " ".$user->id.","; $sql.= " '".$this->db->escape($label)."',"; - $sql.= " '".price2num($price)."')"; + $sql.= " '".price2num($price)."',"; + $sql.= " '".$fk_origin."',"; + $sql.= " '".$origintype."'"; + $sql.= ")"; dol_syslog(get_class($this)."::_create sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); @@ -469,5 +480,36 @@ class MouvementStock } + function get_origin($fk_origin, $origintype) { + switch ($origintype) { + case 'commande': + require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; + $origin = new Commande($this->db); + break; + case 'shipping': + require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; + $origin = new Expedition($this->db); + break; + case 'facture': + require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + $origin = new Facture($this->db); + break; + case 'order_supplier': + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; + $origin = new CommandeFournisseur($this->db); + break; + case 'invoice_supplier': + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; + $origin = new FactureFournisseur($this->db); + break; + + default: + return ''; + break; + } + + $origin->fetch($fk_origin); + return $origin->getNomUrl(1); + } } ?> diff --git a/htdocs/product/stock/mouvement.php b/htdocs/product/stock/mouvement.php index 5b7b56d6720e6a1307acaed3c057ab9af3a161e0..ee3f0b6563963bbdb2f82f1f2cb04072d07bd332 100644 --- a/htdocs/product/stock/mouvement.php +++ b/htdocs/product/stock/mouvement.php @@ -120,7 +120,7 @@ $formproduct=new FormProduct($db); $sql = "SELECT p.rowid, p.ref as product_ref, p.label as produit, p.fk_product_type as type,"; $sql.= " e.label as stock, e.rowid as entrepot_id,"; -$sql.= " m.rowid as mid, m.value, m.datem, m.fk_user_author, m.label,"; +$sql.= " m.rowid as mid, m.value, m.datem, m.fk_user_author, m.label, m.fk_origin, m.origintype,"; $sql.= " u.login"; $sql.= " FROM (".MAIN_DB_PREFIX."entrepot as e,"; $sql.= " ".MAIN_DB_PREFIX."product as p,"; @@ -418,6 +418,7 @@ if ($resql) //print_liste_field_titre($langs->trans("Id"),$_SERVER["PHP_SELF"], "m.rowid","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"], "m.datem","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("LabelMovement"),$_SERVER["PHP_SELF"], "m.label","",$param,"",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Source"),$_SERVER["PHP_SELF"], "m.label","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("ProductRef"),$_SERVER["PHP_SELF"], "p.ref","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("ProductLabel"),$_SERVER["PHP_SELF"], "p.ref","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Warehouse"),$_SERVER["PHP_SELF"], "","",$param,"",$sortfield,$sortorder); // We are on a specific warehouse card, no filter on other should be possible @@ -440,6 +441,10 @@ if ($resql) print '<td class="liste_titre" align="left">'; print '<input class="flat" type="text" size="10" name="search_movement" value="'.$search_movement.'">'; print '</td>'; + // Origin of movement + print '<td class="liste_titre" align="left">'; + print ' '; + print '</td>'; // Product Ref print '<td class="liste_titre" align="left">'; print '<input class="flat" type="text" size="6" name="search_product_ref" value="'.($idproduct?$product->ref:$search_product_ref).'">'; @@ -470,6 +475,11 @@ if ($resql) $objp = $db->fetch_object($resql); $arrayofuniqueproduct[$objp->rowid]=$objp->produit; + if(!empty($objp->fk_origin)) { + $origin = $movement->get_origin($objp->fk_origin, $objp->origintype); + } else { + $origin = ''; + } $var=!$var; print "<tr ".$bc[$var].">"; @@ -479,6 +489,8 @@ if ($resql) print '<td>'.dol_print_date($db->jdate($objp->datem),'dayhour').'</td>'; // Label of movement print '<td>'.$objp->label.'</td>'; + // Origin of movement + print '<td>'.$origin.'</td>'; // Product ref print '<td>'; $productstatic->id=$objp->rowid;