Skip to content

Commit

Permalink
Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into d…
Browse files Browse the repository at this point in the history
…evelop
  • Loading branch information
eldy committed Feb 5, 2015
2 parents a6e4fdd + 556c27f commit 7d64d3d
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 52 deletions.
8 changes: 4 additions & 4 deletions htdocs/fourn/class/fournisseur.product.class.php 100644 → 100755
Expand Up @@ -623,10 +623,10 @@ function setSupplierPriceExpression($expression_id)
*/
function getSocNomUrl($withpicto=0,$option='supplier')
{
$cust = new Fournisseur($this->db);
$cust->fetch($this->fourn_id);
$thirdparty = new Fournisseur($this->db);
$thirdparty->fetch($this->fourn_id);

return $cust->getNomUrl($withpicto,$option);
return $thirdparty->getNomUrl($withpicto,$option);
}

/**
Expand All @@ -640,7 +640,7 @@ function display_price_product_fournisseur($showunitprice=1,$showsuptitle=1)
{
global $langs;
$langs->load("suppliers");
$out=($showunitprice?price($this->fourn_unitprice).' '.$langs->trans("HT").'   (':'').($showsuptitle?$langs->trans("Supplier").': ':'').$this->getSocNomUrl(1).' / '.$langs->trans("SupplierRef").': '.$this->fourn_ref.($showunitprice?')':'');
$out=($showunitprice?price($this->fourn_unitprice).' '.$langs->trans("HT").'   (':'').($showsuptitle?$langs->trans("Supplier").': ':'').$this->getSocNomUrl(1, 'supplier').' / '.$langs->trans("SupplierRef").': '.$this->fourn_ref.($showunitprice?')':'');
return $out;
}

Expand Down
8 changes: 8 additions & 0 deletions htdocs/install/mysql/migration/3.7.0-3.8.0.sql
Expand Up @@ -76,6 +76,14 @@ create table llx_bank_account_extrafields
import_key varchar(14) -- import key
) ENGINE=innodb;


ALTER TABLE llx_stock_mouvement MODIFY COLUMN label varchar(255);
ALTER TABLE llx_stock_mouvement ADD COLUMN inventorycode varchar(128);

ALTER TABLE llx_product_association ADD COLUMN incdec integer DEFAULT 1;



ALTER TABLE llx_bank_account_extrafields ADD INDEX idx_bank_account_extrafields (fk_object);


Expand Down
3 changes: 2 additions & 1 deletion htdocs/install/mysql/tables/llx_product_association.sql
Expand Up @@ -22,6 +22,7 @@ create table llx_product_association
rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_product_pere integer NOT NULL DEFAULT 0, -- id du produit maitre
fk_product_fils integer NOT NULL DEFAULT 0, -- id du sous-produit
qty double NULL
qty double NULL,
incdec integer DEFAULT 1 -- when set to 1 changing stock of product will change stock of linked product too
)ENGINE=innodb;

3 changes: 2 additions & 1 deletion htdocs/install/mysql/tables/llx_stock_mouvement.sql
Expand Up @@ -28,7 +28,8 @@ create table llx_stock_mouvement
price float(13,4) DEFAULT 0,
type_mouvement smallint,
fk_user_author integer,
label varchar(128),
label varchar(255),
inventorycode varchar(128),
fk_origin integer,
origintype varchar(32)
)ENGINE=innodb;
4 changes: 3 additions & 1 deletion htdocs/langs/en_US/stocks.lang
Expand Up @@ -122,4 +122,6 @@ RuleForStockAvailability=Rules on stock requirements
StockMustBeEnoughForInvoice=Stock level must be enough to add product/service into invoice
StockMustBeEnoughForOrder=Stock level must be enough to add product/service into order
StockMustBeEnoughForShipment= Stock level must be enough to add product/service into shipment

MovementLabel=Label of movement
InventoryCode=Inventory code
IsInPackage=Contained into package
11 changes: 6 additions & 5 deletions htdocs/product/class/product.class.php 100644 → 100755
Expand Up @@ -1697,7 +1697,6 @@ function fetch($id='', $ref='', $ref_ext='', $ignore_expression = 0)

// We should not load stock at each fetch. If someone need stock, he must call load_stock after fetch.
//$res=$this->load_stock();

// instead we just init the stock_warehouse array
$this->stock_warehouse = array();

Expand Down Expand Up @@ -3027,9 +3026,10 @@ function getLibFinished()
* @param int $movement 0 = add, 1 = remove
* @param string $label Label of stock movement
* @param double $price Price to use for stock eval
* @param string $inventorycode Inventory code
* @return int <0 if KO, >0 if OK
*/
function correct_stock($user, $id_entrepot, $nbpiece, $movement, $label='', $price=0)
function correct_stock($user, $id_entrepot, $nbpiece, $movement, $label='', $price=0, $inventorycode='')
{
if ($id_entrepot)
{
Expand All @@ -3041,7 +3041,7 @@ function correct_stock($user, $id_entrepot, $nbpiece, $movement, $label='', $pri
$op[1] = "-".trim($nbpiece);

$movementstock=new MouvementStock($this->db);
$result=$movementstock->_create($user,$this->id,$id_entrepot,$op[$movement],$movement,$price,$label);
$result=$movementstock->_create($user,$this->id,$id_entrepot,$op[$movement],$movement,$price,$label,$inventorycode);

if ($result >= 0)
{
Expand Down Expand Up @@ -3643,9 +3643,10 @@ function hasbatch()
* @param date $dlc eat-by date
* @param date $dluo sell-by date
* @param string $lot Lot number
* @param string $inventorycode Inventory code
* @return int <0 if KO, >0 if OK
*/
function correct_stock_batch($user, $id_entrepot, $nbpiece, $movement, $label='', $price=0, $dlc='', $dluo='',$lot='')
function correct_stock_batch($user, $id_entrepot, $nbpiece, $movement, $label='', $price=0, $dlc='', $dluo='',$lot='', $inventorycode='')
{
if ($id_entrepot)
{
Expand All @@ -3657,7 +3658,7 @@ function correct_stock_batch($user, $id_entrepot, $nbpiece, $movement, $label=''
$op[1] = "-".trim($nbpiece);

$movementstock=new MouvementStock($this->db);
$result=$movementstock->_create($user,$this->id,$id_entrepot,$op[$movement],$movement,$price,$label,'',$dlc,$dluo,$lot);
$result=$movementstock->_create($user,$this->id,$id_entrepot,$op[$movement],$movement,$price,$label,$inventorycode,'',$dlc,$dluo,$lot);

if ($result >= 0)
{
Expand Down
3 changes: 2 additions & 1 deletion htdocs/product/composition/card.php
Expand Up @@ -34,6 +34,7 @@

$langs->load("bills");
$langs->load("products");
$langs->load("stocks");

$id=GETPOST('id','int');
$ref=GETPOST('ref','alpha');
Expand Down Expand Up @@ -456,7 +457,7 @@
print '<tr class="liste_titre">';
print '<th class="liste_titre">'.$langs->trans("Ref").'</td>';
print '<th class="liste_titre">'.$langs->trans("Label").'</td>';
print '<th class="liste_titre" align="center">'.$langs->trans("AddDel").'</td>';
print '<th class="liste_titre" align="center">'.$langs->trans("IsInPackage").'</td>';
print '<th class="liste_titre" align="right">'.$langs->trans("Qty").'</td>';
print '</tr>';
if ($resql)
Expand Down
62 changes: 37 additions & 25 deletions htdocs/product/stock/class/mouvementstock.class.php
Expand Up @@ -55,28 +55,35 @@ function __construct($db)
* 2=output (stock decrease), 3=input (stock increase)
* @param int $price Unit price HT of product, used to calculate average weighted price (PMP in french). If 0, average weighted price is not changed.
* @param string $label Label of stock movement
* @param string $inventorycode Inventory code
* @param string $datem Force date of movement
* @param date $eatby eat-by date
* @param date $sellby sell-by date
* @param string $batch batch number
* @param boolean $skip_sellby If set to true, stock mouvement is done without impacting batch record
* @return int <0 if KO, 0 if fk_product is null, >0 if OK
*/
function _create($user, $fk_product, $entrepot_id, $qty, $type, $price=0, $label='', $datem='',$eatby='',$sellby='',$batch='',$skip_sellby=false)
function _create($user, $fk_product, $entrepot_id, $qty, $type, $price=0, $label='', $inventorycode='', $datem='',$eatby='',$sellby='',$batch='',$skip_sellby=false)
{
global $conf, $langs;

require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
$error = 0;
dol_syslog(get_class($this)."::_create start userid=$user->id, fk_product=$fk_product, warehouse=$entrepot_id, qty=$qty, type=$type, price=$price label=$label");
dol_syslog(get_class($this)."::_create start userid=$user->id, fk_product=$fk_product, warehouse=$entrepot_id, qty=$qty, type=$type, price=$price, label=$label, inventorycode=$inventorycode");

// Clean parameters
if (empty($price)) $price=0;
$now=(! empty($datem) ? $datem : dol_now());

// Check parameters
if (empty($fk_product)) return 0;

$now=(! empty($datem) ? $datem : dol_now());

// Set properties of movement
$this->product_id = $fk_product;
$this->entrepot_id = $entrepot_id;
$this->qty = $qty;
$this->type = $type;

$this->db->begin();

$product = new Product($this->db);
Expand All @@ -94,19 +101,22 @@ 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)) {
if(!empty($this->origin)) { // This is set by caller for tracking reason
$origintype = $this->origin->element;
$fk_origin = $this->origin->id;
} else {
$origintype = '';
$fk_origin = 0;
}

$mvid = 0;

$sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement";
$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.= " (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author, label, inventorycode, price, fk_origin, origintype)";
$sql.= " VALUES ('".$this->db->idate($now)."', ".$this->product_id.", ".$this->entrepot_id.", ".$this->qty.", ".$this->type.",";
$sql.= " ".$user->id.",";
$sql.= " '".$this->db->escape($label)."',";
$sql.= " '".$this->db->escape($inventorycode)."',";
$sql.= " '".price2num($price)."',";
$sql.= " '".$fk_origin."',";
$sql.= " '".$origintype."'";
Expand All @@ -117,6 +127,7 @@ function _create($user, $fk_product, $entrepot_id, $qty, $type, $price=0, $label
if ($resql)
{
$mvid = $this->db->last_insert_id(MAIN_DB_PREFIX."stock_mouvement");
$this->id = $mvid;
}
else
{
Expand Down Expand Up @@ -159,10 +170,11 @@ function _create($user, $fk_product, $entrepot_id, $qty, $type, $price=0, $label
}

// Calculate new PMP.
$newpmp=0;
$newpmpwarehouse=0;
/*
if (! $error)
{
$newpmp=0;
$newpmpwarehouse=0;
// Note: PMP is calculated on stock input only (type of movement = 0 or 3). If type == 0 or 3, qty should be > 0.
// Note: Price should always be >0 or 0. PMP should be always >0 (calculated on input)
if (($type == 0 || $type == 3) && $price > 0)
Expand Down Expand Up @@ -190,9 +202,9 @@ function _create($user, $fk_product, $entrepot_id, $qty, $type, $price=0, $label
if ($oldpmpwarehouse > 0) $newpmpwarehouse=price2num((($oldqtywarehousetouse * $oldpmpwarehouse) + ($qty * $price)) / ($oldqtywarehousetouse + $qty), 'MU');
else $newpmpwarehouse=$price;
/*print "oldqtytouse=".$oldqtytouse." oldpmp=".$oldpmp." oldqtywarehousetouse=".$oldqtywarehousetouse." oldpmpwarehouse=".$oldpmpwarehouse." ";
print "qty=".$qty." newpmp=".$newpmp." newpmpwarehouse=".$newpmpwarehouse;
exit;*/
//print "oldqtytouse=".$oldqtytouse." oldpmp=".$oldpmp." oldqtywarehousetouse=".$oldqtywarehousetouse." oldpmpwarehouse=".$oldpmpwarehouse." ";
//print "qty=".$qty." newpmp=".$newpmp." newpmpwarehouse=".$newpmpwarehouse;
//exit;
}
else if ($type == 1 || $type == 2)
{
Expand All @@ -204,7 +216,8 @@ function _create($user, $fk_product, $entrepot_id, $qty, $type, $price=0, $label
$newpmpwarehouse = $oldpmpwarehouse;
}
}

*/

// Update denormalized value of stock in product_stock and product
if (! $error)
{
Expand Down Expand Up @@ -262,21 +275,15 @@ function _create($user, $fk_product, $entrepot_id, $qty, $type, $price=0, $label
// Add movement for sub products (recursive call)
if (! $error && ! empty($conf->global->PRODUIT_SOUSPRODUITS))
{
$error = $this->_createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, 0, $label); // we use 0 as price, because pmp is not changed for subproduct
$error = $this->_createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, 0, $label, $inventorycode); // we use 0 as price, because pmp is not changed for subproduct
}

if ($movestock && ! $error)
{
$this->product_id = $fk_product;
$this->entrepot_id = $entrepot_id;
$this->qty = $qty;

// Call trigger
$result=$this->call_trigger('STOCK_MOVEMENT',$user);
if ($result < 0) $error++;
// End call triggers

//FIXME: Restore previous value of product_id, entrepot_id, qty if trigger fail
}

if (! $error)
Expand All @@ -303,9 +310,10 @@ function _create($user, $fk_product, $entrepot_id, $qty, $type, $price=0, $label
* @param int $type Type
* @param int $price Price
* @param string $label Label of movement
* @param string $inventorycode Inventory code
* @return int <0 if KO, 0 if OK
*/
function _createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price=0, $label='')
function _createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price=0, $label='', $inventorycode='')
{
$error = 0;
$pids = array();
Expand All @@ -314,7 +322,9 @@ function _createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price=
$sql = "SELECT fk_product_pere, fk_product_fils, qty";
$sql.= " FROM ".MAIN_DB_PREFIX."product_association";
$sql.= " WHERE fk_product_pere = ".$idProduct;

// TODO Select only subproduct with incdec tag
//$sql.= " AND incdec = 1";

dol_syslog(get_class($this)."::_createSubProduct", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
Expand All @@ -336,7 +346,9 @@ function _createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price=
// Create movement for each subproduct
foreach($pids as $key => $value)
{
$this->_create($user, $pids[$key], $entrepot_id, ($qty * $pqtys[$key]), $type, 0, $label);
$tmpmove = dol_clone($this);
$tmpmove->_create($user, $pids[$key], $entrepot_id, ($qty * $pqtys[$key]), $type, 0, $label, $inventorycode); // This will also call _createSubProduct making this recursive
unset($tmpmove);
}

return $error;
Expand All @@ -357,7 +369,7 @@ function _createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price=
*/
function livraison($user, $fk_product, $entrepot_id, $qty, $price=0, $label='', $datem='')
{
return $this->_create($user, $fk_product, $entrepot_id, (0 - $qty), 2, $price, $label, $datem,'','','',true);
return $this->_create($user, $fk_product, $entrepot_id, (0 - $qty), 2, $price, $label, '', $datem,'','','',true);
}

/**
Expand Down Expand Up @@ -389,7 +401,7 @@ function livraison_batch($id_stock_dluo, $qty)
*/
function reception($user, $fk_product, $entrepot_id, $qty, $price=0, $label='', $eatby='', $sellby='', $batch='')
{
return $this->_create($user, $fk_product, $entrepot_id, $qty, 3, $price, $label, '', $eatby, $sellby, $batch);
return $this->_create($user, $fk_product, $entrepot_id, $qty, 3, $price, $label, '', '', $eatby, $sellby, $batch);
}


Expand Down
19 changes: 16 additions & 3 deletions htdocs/product/stock/mouvement.php
Expand Up @@ -50,6 +50,7 @@
$search_product_ref = trim(GETPOST("search_product_ref"));
$search_product = trim(GETPOST("search_product"));
$search_warehouse = trim(GETPOST("search_warehouse"));
$search_inventorycode = trim(GETPOST("search_inventorycode"));
$search_user = trim(GETPOST("search_user"));
$page = GETPOST("page",'int');
$sortfield = GETPOST("sortfield",'alpha');
Expand Down Expand Up @@ -120,7 +121,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, e.lieu,";
$sql.= " m.rowid as mid, m.value, m.datem, m.fk_user_author, m.label, m.fk_origin, m.origintype,";
$sql.= " m.rowid as mid, m.value, m.datem, m.fk_user_author, m.label, m.inventorycode, 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 @@ -149,6 +150,10 @@
{
$sql.= " AND m.label LIKE '%".$db->escape($search_movement)."%'";
}
if (! empty($search_inventorycode))
{
$sql.= " AND m.inventorycode LIKE '%".$db->escape($search_inventorycode)."%'";
}
if (! empty($search_product_ref))
{
$sql.= " AND p.ref LIKE '%".$db->escape($search_product_ref)."%'";
Expand Down Expand Up @@ -410,6 +415,7 @@
$param='';
if ($id) $param.='&id='.$id;
if ($search_movement) $param.='&search_movement='.urlencode($search_movement);
if ($search_inventorycode) $param.='&search_inventorycode='.urlencode($search_inventorycode);
if ($search_product_ref) $param.='&search_product_ref='.urlencode($search_product_ref);
if ($search_product) $param.='&search_product='.urlencode($search_product);
if ($search_warehouse) $param.='&search_warehouse='.urlencode($search_warehouse);
Expand All @@ -425,7 +431,8 @@
//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("InventoryCode"),$_SERVER["PHP_SELF"], "m.inventorycode","",$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 @@ -448,6 +455,10 @@
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" size="10" name="search_movement" value="'.$search_movement.'">';
print '</td>';
// Inventory code
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" size="4" name="search_inventorycode" value="'.$search_inventorycode.'">';
print '</td>';
// Origin of movement
print '<td class="liste_titre" align="left">';
print '&nbsp; ';
Expand Down Expand Up @@ -495,7 +506,9 @@
print '<td>'.dol_print_date($db->jdate($objp->datem),'dayhour').'</td>';
// Label of movement
print '<td>'.$objp->label.'</td>';
// Origin of movement
// Inventory code
print '<td>'.$objp->inventorycode.'</td>';
// Origin of movement
print '<td>'.$origin.'</td>';
// Product ref
print '<td>';
Expand Down

0 comments on commit 7d64d3d

Please sign in to comment.