Skip to content

Commit

Permalink
Task 1074 : add link to source document on stock movement
Browse files Browse the repository at this point in the history
  • Loading branch information
atm-maxime committed Mar 15, 2014
1 parent 85f33a6 commit 6734248
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 4 deletions.
1 change: 1 addition & 0 deletions htdocs/commande/class/commande.class.php
Expand Up @@ -253,6 +253,7 @@ function valid($user, $idwarehouse=0)
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++; }
Expand Down
3 changes: 3 additions & 0 deletions htdocs/compta/facture/class/facture.class.php
Expand Up @@ -1329,6 +1329,7 @@ function delete($rowid=0, $notrigger=0, $idwarehouse=-1)
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
Expand Down Expand Up @@ -1794,6 +1795,7 @@ function validate($user, $force_number='', $idwarehouse=0)
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));
Expand Down Expand Up @@ -1916,6 +1918,7 @@ function set_draft($user,$idwarehouse=-1)
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
Expand Down
2 changes: 2 additions & 0 deletions htdocs/expedition/class/expedition.class.php
Expand Up @@ -580,6 +580,7 @@ function valid($user)

//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));
Expand Down Expand Up @@ -902,6 +903,7 @@ function delete()

//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));
Expand Down
2 changes: 2 additions & 0 deletions htdocs/fourn/class/fournisseur.commande.class.php
Expand Up @@ -635,6 +635,7 @@ function approve($user, $idwarehouse=0)
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');
Expand Down Expand Up @@ -1288,6 +1289,7 @@ function DispatchProduct($user, $product, $qty, $entrepot, $price=0, $comment=''
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)
{
Expand Down
1 change: 1 addition & 0 deletions htdocs/fourn/class/fournisseur.facture.class.php
Expand Up @@ -906,6 +906,7 @@ function validate($user, $force_number='', $idwarehouse=0)
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');
Expand Down
6 changes: 5 additions & 1 deletion htdocs/install/mysql/migration/3.5.0-3.6.0.sql
Expand Up @@ -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 ;
46 changes: 44 additions & 2 deletions htdocs/product/stock/class/mouvementstock.class.php
Expand Up @@ -94,12 +94,23 @@ function _create($user, $fk_product, $entrepot_id, $qty, $type, $price=0, $label

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);
Expand Down Expand Up @@ -469,5 +480,36 @@ function _create_batch($dluo, $qty ) {

}

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);
}
}
?>
14 changes: 13 additions & 1 deletion htdocs/product/stock/mouvement.php
Expand Up @@ -120,7 +120,7 @@

$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,";
Expand Down Expand Up @@ -418,6 +418,7 @@
//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
Expand All @@ -440,6 +441,10 @@
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 '&nbsp; ';
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).'">';
Expand Down Expand Up @@ -470,6 +475,11 @@
$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].">";
Expand All @@ -479,6 +489,8 @@
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;
Expand Down

0 comments on commit 6734248

Please sign in to comment.