diff --git a/htdocs/install/mysql/migration/10.0.0-11.0.0.sql b/htdocs/install/mysql/migration/10.0.0-11.0.0.sql index 63a71d59f44..4f70af3b566 100644 --- a/htdocs/install/mysql/migration/10.0.0-11.0.0.sql +++ b/htdocs/install/mysql/migration/10.0.0-11.0.0.sql @@ -74,3 +74,5 @@ ALTER TABLE llx_payment_salary_extrafields ADD INDEX idx_payment_salary_extrafie ALTER TABLE llx_c_price_expression MODIFY COLUMN expression varchar(255) NOT NULL; UPDATE llx_bank_url set url = REPLACE( url, 'compta/salaries/', 'salaries/'); + +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 fdeab913268..29f263bc520 100644 --- a/htdocs/install/mysql/tables/llx_stock_mouvement.sql +++ b/htdocs/install/mysql/tables/llx_stock_mouvement.sql @@ -36,5 +36,6 @@ create table llx_stock_mouvement fk_project integer, 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 c6db985f515..1ddf58cde2b 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -344,17 +344,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").", "; @@ -366,7 +380,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); @@ -569,7 +584,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/movement_list.php b/htdocs/product/stock/movement_list.php index efcbc534c08..f62b732cf7e 100644 --- a/htdocs/product/stock/movement_list.php +++ b/htdocs/product/stock/movement_list.php @@ -112,6 +112,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) ); @@ -423,6 +424,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 @@ -854,7 +856,14 @@ if ($resql) if (! empty($arrayfields['m.price']['checked'])) { // Price - print ''; + print ''; + print '  '; + print ''; + } + if (! empty($arrayfields['m.fk_projet']['checked'])) + { + // fk_projet + print ''; print '  '; print ''; } @@ -933,6 +942,9 @@ if ($resql) if (! empty($arrayfields['m.price']['checked'])) { print_liste_field_titre($arrayfields['m.price']['label'], $_SERVER["PHP_SELF"], "m.price", "", $param, '', $sortfield, $sortorder, 'right '); } + if (! empty($arrayfields['m.fk_projet']['checked'])) { + print_liste_field_titre($arrayfields['m.fk_projet']['label'], $_SERVER["PHP_SELF"], "m.fk_projet", "", $param, 'align="right"', $sortfield, $sortorder); + } // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; @@ -1100,6 +1112,13 @@ if ($resql) if ($objp->price != 0) print price($objp->price); print ''; } + if (! empty($arrayfields['m.fk_projet']['checked'])) + { + // fk_projet + print ''; + if ($objp->fk_projet != 0) print $movement->get_origin($objp->fk_projet, 'project'); + print ''; + } // Action column print ''; if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined