Merge pull request #1472 from atm-maxime/mko1074
Task 1074 : add link to source document on stock movement
This commit is contained in:
commit
271c2a8929
@ -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++; }
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -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');
|
||||
|
||||
@ -1060,4 +1060,8 @@ CREATE TABLE llx_payment_salary (
|
||||
fk_bank integer,
|
||||
fk_user_creat integer,
|
||||
fk_user_modif integer
|
||||
)ENGINE=innodb;
|
||||
)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 ;
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user