diff --git a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql index 380c64c28fc..7a6f837fd7f 100644 --- a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql +++ b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql @@ -562,3 +562,5 @@ ALTER TABLE llx_advtargetemailing DROP COLUMN fk_mailing; DROP TABLE llx_ticket_logs; ALTER TABLE llx_actioncomm MODIFY COLUMN code varchar(50); + +ALTER TABLE llx_stock_mouvement ADD COLUMN fk_projet INTEGER NOT NULL DEFAULT 0 AFTER model_pdf; diff --git a/htdocs/install/mysql/tables/llx_stock_mouvement.sql b/htdocs/install/mysql/tables/llx_stock_mouvement.sql index 1e78e7a9820..88d7aed98a7 100644 --- a/htdocs/install/mysql/tables/llx_stock_mouvement.sql +++ b/htdocs/install/mysql/tables/llx_stock_mouvement.sql @@ -35,5 +35,6 @@ create table llx_stock_mouvement inventorycode varchar(128), -- Code used to group different movement line into one operation (may be an inventory, a mass picking) fk_origin integer, origintype varchar(32), - model_pdf varchar(255) + model_pdf varchar(255), + fk_projet integer NOT NULL DEFAULT 0 )ENGINE=innodb; diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index 825034b87cb..268b2127d68 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -322,17 +322,31 @@ class MouvementStock extends CommonObject if ($movestock && $entrepot_id > 0) // Change stock for current product, change for subproduct is done after { + $fk_project = 0; if(!empty($this->origin)) { // This is set by caller for tracking reason $origintype = $this->origin->element; $fk_origin = $this->origin->id; + if($origintype == 'project') $fk_project = $fk_origin; + else + { + $res = $this->origin->fetch($fk_origin); + if ($res > 0) + { + if (!empty($this->origin->fk_project)) + { + $fk_project = $this->origin->fk_project; + } + } + } } else { $origintype = ''; $fk_origin = 0; + $fk_project = 0; } $sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement("; $sql.= " datem, fk_product, batch, eatby, sellby,"; - $sql.= " fk_entrepot, value, type_mouvement, fk_user_author, label, inventorycode, price, fk_origin, origintype"; + $sql.= " fk_entrepot, value, type_mouvement, fk_user_author, label, inventorycode, price, fk_origin, origintype, fk_projet"; $sql.= ")"; $sql.= " VALUES ('".$this->db->idate($now)."', ".$this->product_id.", "; $sql.= " ".($batch?"'".$batch."'":"null").", "; @@ -344,7 +358,8 @@ class MouvementStock extends CommonObject $sql.= " ".($inventorycode?"'".$this->db->escape($inventorycode)."'":"null").","; $sql.= " '".price2num($price)."',"; $sql.= " '".$fk_origin."',"; - $sql.= " '".$origintype."'"; + $sql.= " '".$origintype."',"; + $sql.= " ". $fk_project; $sql.= ")"; dol_syslog(get_class($this)."::_create insert record into stock_mouvement", LOG_DEBUG); @@ -548,7 +563,8 @@ class MouvementStock extends CommonObject $sql .= " t.inventorycode,"; $sql .= " t.batch,"; $sql .= " t.eatby,"; - $sql .= " t.sellby"; + $sql .= " t.sellby,"; + $sql .= " t.fk_projet"; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; $sql.= ' WHERE 1 = 1'; //if (null !== $ref) { diff --git a/htdocs/product/stock/mouvement.php b/htdocs/product/stock/mouvement.php index 331d39efccb..ca09469ca2d 100644 --- a/htdocs/product/stock/mouvement.php +++ b/htdocs/product/stock/mouvement.php @@ -109,6 +109,7 @@ $arrayfields=array( 'origin'=>array('label'=>$langs->trans("Origin"), 'checked'=>1), 'm.value'=>array('label'=>$langs->trans("Qty"), 'checked'=>1), 'm.price'=>array('label'=>$langs->trans("UnitPurchaseValue"), 'checked'=>0), + 'm.fk_projet'=>array('label'=>$langs->trans('Project'), 'checked'=>0) //'m.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), //'m.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500) ); @@ -442,6 +443,7 @@ $sql.= " e.ref as stock, e.rowid as entrepot_id, e.lieu,"; $sql.= " m.rowid as mid, m.value as qty, m.datem, m.fk_user_author, m.label, m.inventorycode, m.fk_origin, m.origintype,"; $sql.= " m.batch, m.price,"; $sql.= " m.type_mouvement,"; +$sql.= " m.fk_projet,"; $sql.= " pl.rowid as lotid, pl.eatby, pl.sellby,"; $sql.= " u.login, u.photo, u.lastname, u.firstname"; // Add fields from extrafields @@ -874,6 +876,13 @@ if ($resql) print ' '; print ''; } + if (! empty($arrayfields['m.fk_projet']['checked'])) + { + // Price + print '