diff --git a/htdocs/core/class/html.formprojet.class.php b/htdocs/core/class/html.formprojet.class.php
index 97e9895686f..a0e37026ff8 100644
--- a/htdocs/core/class/html.formprojet.class.php
+++ b/htdocs/core/class/html.formprojet.class.php
@@ -464,7 +464,7 @@ class FormProjets
if ($table_element == 'projet_task') return ''; // Special cas of element we never link to a project (already always done)
$linkedtothirdparty=false;
- if (! in_array($table_element, array('don','expensereport_det','expensereport','loan'))) $linkedtothirdparty=true;
+ if (! in_array($table_element, array('don','expensereport_det','expensereport','loan','stock_mouvement'))) $linkedtothirdparty=true;
$sqlfilter='';
$projectkey="fk_projet";
@@ -503,6 +503,10 @@ class FormProjets
case "fichinter":
$sql = "SELECT t.rowid, t.ref";
break;
+ case 'stock_mouvement':
+ $sql = 'SELECT t.rowid, t.label as ref';
+ $projectkey='fk_origin';
+ break;
default:
$sql = "SELECT t.rowid, t.ref";
break;
@@ -516,7 +520,7 @@ class FormProjets
if (is_numeric($socid)) $sql.= " AND t.fk_soc=".$socid;
else $sql.= " AND t.fk_soc IN (".$socid.")";
}
- if (! in_array($table_element, array('expensereport_det'))) $sql.= ' AND t.entity IN ('.getEntity('project',1).')';
+ if (! in_array($table_element, array('expensereport_det','stock_mouvement'))) $sql.= ' AND t.entity IN ('.getEntity('project',1).')';
if ($linkedtothirdparty) $sql.=" AND s.rowid = t.fk_soc";
if ($sqlfilter) $sql.= " AND ".$sqlfilter;
$sql.= " ORDER BY ref DESC";
diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang
index f7a77db4821..cfced089c3a 100644
--- a/htdocs/langs/en_US/stocks.lang
+++ b/htdocs/langs/en_US/stocks.lang
@@ -22,6 +22,8 @@ Movements=Movements
ErrorWarehouseRefRequired=Warehouse reference name is required
ListOfWarehouses=List of warehouses
ListOfStockMovements=List of stock movements
+StockMovementForId=Movement ID %d
+ListMouvementStockProject=List of stock movements associated to project
StocksArea=Warehouses area
Location=Location
LocationSummary=Short name location
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index 32ffbeead05..51fca3d8487 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -3520,20 +3520,23 @@ class Product extends CommonObject
* @param string $label Label of stock movement
* @param double $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 $inventorycode Inventory code
+ * @param string $origin_element Origin element type
+ * @param int $origin_id Origin id of element
* @return int <0 if KO, >0 if OK
*/
- function correct_stock($user, $id_entrepot, $nbpiece, $movement, $label='', $price=0, $inventorycode='')
+ function correct_stock($user, $id_entrepot, $nbpiece, $movement, $label='', $price=0, $inventorycode='', $origin_element='', $origin_id=null)
{
if ($id_entrepot)
{
$this->db->begin();
require_once DOL_DOCUMENT_ROOT .'/product/stock/class/mouvementstock.class.php';
-
+
$op[0] = "+".trim($nbpiece);
$op[1] = "-".trim($nbpiece);
$movementstock=new MouvementStock($this->db);
+ $movementstock->setOrigin($origin_element, $origin_id);
$result=$movementstock->_create($user,$this->id,$id_entrepot,$op[$movement],$movement,$price,$label,$inventorycode);
if ($result >= 0)
@@ -3565,9 +3568,11 @@ class Product extends CommonObject
* @param date $dluo sell-by date
* @param string $lot Lot number
* @param string $inventorycode Inventory code
+ * @param string $origin_element Origin element type
+ * @param int $origin_id Origin id of element
* @return int <0 if KO, >0 if OK
*/
- function correct_stock_batch($user, $id_entrepot, $nbpiece, $movement, $label='', $price=0, $dlc='', $dluo='',$lot='', $inventorycode='')
+ function correct_stock_batch($user, $id_entrepot, $nbpiece, $movement, $label='', $price=0, $dlc='', $dluo='',$lot='', $inventorycode='', $origin_element='', $origin_id=null)
{
if ($id_entrepot)
{
@@ -3579,6 +3584,7 @@ class Product extends CommonObject
$op[1] = "-".trim($nbpiece);
$movementstock=new MouvementStock($this->db);
+ $movementstock->setOrigin($origin_element, $origin_id);
$result=$movementstock->_create($user,$this->id,$id_entrepot,$op[$movement],$movement,$price,$label,$inventorycode,'',$dlc,$dluo,$lot);
if ($result >= 0)
diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php
index dee344b6a5b..e6631d4b716 100644
--- a/htdocs/product/stock/class/mouvementstock.class.php
+++ b/htdocs/product/stock/class/mouvementstock.class.php
@@ -893,6 +893,33 @@ class MouvementStock extends CommonObject
return '';
}
+
+ /**
+ * Set attribute origin to object
+ *
+ * @param string $origin_element type of element
+ * @param int $origin_id id of element
+ *
+ * @return void
+ */
+ function setOrigin($origin_element, $origin_id)
+ {
+ if (!empty($origin_element) && $origin_id > 0)
+ {
+ $origin='';
+ if ($origin_element == 'project')
+ {
+ if (!class_exists('Project')) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
+ $origin = new Project($this->db);
+ }
+
+ if (!empty($origin))
+ {
+ $this->origin = $origin;
+ $this->origin->id = $origin_id;
+ }
+ }
+ }
/**
@@ -911,4 +938,89 @@ class MouvementStock extends CommonObject
// There is no specific properties. All data into insert are provided as method parameter.
}
+
+ /**
+ * Return a link (with optionaly the picto)
+ * Use this->id,this->lastname, this->firstname
+ *
+ * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
+ * @param string $option On what the link point to
+ * @param integer $notooltip 1=Disable tooltip
+ * @param int $maxlen Max length of visible user name
+ * @param string $morecss Add more css on link
+ * @return string String with URL
+ */
+ function getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='')
+ {
+ global $langs, $conf, $db;
+
+ $result = '';
+ $companylink = '';
+
+ $label = '' . $langs->trans("Movement") . ' '.$this->id.'';
+ $label.= '