From dc77a58a7327a185d0b4fc6da7e40f7ba84b0322 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 12 Nov 2019 01:48:12 +0100 Subject: [PATCH] Work on MO --- htdocs/bom/class/bom.class.php | 2 +- htdocs/bom/tpl/objectline_create.tpl.php | 8 +- htdocs/bom/tpl/objectline_edit.tpl.php | 6 +- htdocs/bom/tpl/objectline_title.tpl.php | 2 +- htdocs/bom/tpl/objectline_view.tpl.php | 10 +-- htdocs/core/class/commonobject.class.php | 38 +++++----- htdocs/core/tpl/originproductline.tpl.php | 4 +- htdocs/mrp/class/mo.class.php | 90 +++++++++++++++++++++++ htdocs/mrp/mo_card.php | 33 ++++++++- htdocs/mrp/tpl/originproductline.tpl.php | 44 +++++++++++ 10 files changed, 198 insertions(+), 39 deletions(-) create mode 100644 htdocs/mrp/tpl/originproductline.tpl.php diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index 4dce2533bdc..524fd5c0f93 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -1051,7 +1051,7 @@ class BOMLine extends CommonObject 'qty' => array('type'=>'double(24,8)', 'label'=>'Quantity', 'enabled'=>1, 'visible'=>1, 'position'=>100, 'notnull'=>1, 'isameasure'=>'1',), 'qty_frozen' => array('type'=>'smallint', 'label'=>'QuantityFrozen', 'enabled'=>1, 'visible'=>1, 'default'=>0, 'position'=>105, 'css'=>'maxwidth50imp', 'help'=>'QuantityConsumedInvariable'), 'disable_stock_change' => array('type'=>'smallint', 'label'=>'DisableStockChange', 'enabled'=>1, 'visible'=>1, 'default'=>0, 'position'=>108, 'css'=>'maxwidth50imp', 'help'=>'DisableStockChangeHelp'), - 'efficiency' => array('type'=>'double(8,4)', 'label'=>'ManufacturingEfficiency', 'enabled'=>1, 'visible'=>1, 'default'=>1, 'position'=>110, 'notnull'=>1, 'css'=>'maxwidth50imp', 'help'=>'ValueOfMeansLoss'), + //'efficiency' => array('type'=>'double(8,4)', 'label'=>'ManufacturingEfficiency', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'position'=>110, 'notnull'=>1, 'css'=>'maxwidth50imp', 'help'=>'ValueOfEfficiencyConsumedMeans'), 'position' => array('type'=>'integer', 'label'=>'Rank', 'enabled'=>1, 'visible'=>0, 'default'=>0, 'position'=>200, 'notnull'=>1,), 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000, 'notnull'=>-1,), ); diff --git a/htdocs/bom/tpl/objectline_create.tpl.php b/htdocs/bom/tpl/objectline_create.tpl.php index d3aaabbad80..e05c1865ab3 100644 --- a/htdocs/bom/tpl/objectline_create.tpl.php +++ b/htdocs/bom/tpl/objectline_create.tpl.php @@ -128,10 +128,10 @@ $coldisplay++; print ''; print ''; -$coldisplay++; -print ''; -print ''; -print ''; +//$coldisplay++; +//print ''; +//print ''; +//print ''; $coldisplay += $colspan; diff --git a/htdocs/bom/tpl/objectline_edit.tpl.php b/htdocs/bom/tpl/objectline_edit.tpl.php index c7fc4f73cd7..1695f643964 100644 --- a/htdocs/bom/tpl/objectline_edit.tpl.php +++ b/htdocs/bom/tpl/objectline_edit.tpl.php @@ -124,9 +124,9 @@ $coldisplay++; print 'disable_stock_change?' checked="checked"':'')).'">'; print ''; -$coldisplay++; -print ''; -print ''; +//$coldisplay++; +//print ''; +//print ''; $coldisplay+=$colspan; print ''; diff --git a/htdocs/bom/tpl/objectline_title.tpl.php b/htdocs/bom/tpl/objectline_title.tpl.php index 138a0b9aa58..706f71af7ec 100644 --- a/htdocs/bom/tpl/objectline_title.tpl.php +++ b/htdocs/bom/tpl/objectline_title.tpl.php @@ -66,7 +66,7 @@ print ''.$form->textwithpicto($langs->trans('QtyFro print ''.$form->textwithpicto($langs->trans('DisableStockChange'), $langs->trans('DisableStockChangeHelp')).''; // Efficiency -print ''.$form->textwithpicto($langs->trans('ManufacturingEfficiency'), $langs->trans('ValueOfMeansLoss')).''; +//print ''.$form->textwithpicto($langs->trans('ManufacturingEfficiency'), $langs->trans('XXX')).''; print ''; // No width to allow autodim diff --git a/htdocs/bom/tpl/objectline_view.tpl.php b/htdocs/bom/tpl/objectline_view.tpl.php index 330f8ef8a33..6f79f7640df 100644 --- a/htdocs/bom/tpl/objectline_view.tpl.php +++ b/htdocs/bom/tpl/objectline_view.tpl.php @@ -97,12 +97,12 @@ $coldisplay++; echo $line->disable_stock_change ? yn($line->disable_stock_change) : ''; // Yes, it is a quantity, not a price, but we just want the formating role of function price print ''; -print ''; -$coldisplay++; -echo $line->efficiency; -print ''; +//print ''; +//$coldisplay++; +//echo $line->efficiency; +//print ''; -if ($this->status == 0 && ($object_rights->write) && $action != 'selectlines' ) { +if ($this->status == 0 && ($object_rights->write) && $action != 'selectlines' ) { print ''; $coldisplay++; if (($line->info_bits & 2) == 2 || ! empty($disableedit)) { diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 127e12f919e..140d41c9a62 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4018,7 +4018,7 @@ abstract class CommonObject public function formAddObjectLine($dateSelector, $seller, $buyer, $defaulttpldir = '/core/tpl') { global $conf,$user,$langs,$object,$hookmanager,$extrafields; - global $form,$bcnd,$var; + global $form; // Line extrafield if (! is_object($extrafields)) @@ -4116,7 +4116,6 @@ abstract class CommonObject } } - $var = true; $i = 0; print "\n"; @@ -4130,18 +4129,18 @@ abstract class CommonObject { if (empty($line->fk_parent_line)) { - $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'table_element_line'=>$line->table_element); + $parameters = array('line'=>$line, 'num'=>$num, 'i'=>$i, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer, 'selected'=>$selected, 'table_element_line'=>$line->table_element); $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks } else { - $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'table_element_line'=>$line->table_element, 'fk_parent_line'=>$line->fk_parent_line); + $parameters = array('line'=>$line, 'num'=>$num, 'i'=>$i, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer, 'selected'=>$selected, 'table_element_line'=>$line->table_element, 'fk_parent_line'=>$line->fk_parent_line); $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks } } if (empty($reshook)) { - $this->printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafields, $defaulttpldir); + $this->printObjectLine($action, $line, '', $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafields, $defaulttpldir); } $i++; @@ -4153,23 +4152,23 @@ abstract class CommonObject * Return HTML content of a detail line * TODO Move this into an output class file (htmlline.class.php) * - * @param string $action GET/POST action - * @param CommonObjectLine $line Selected object line to output - * @param string $var Is it a an odd line (true) - * @param int $num Number of line (0) - * @param int $i I - * @param int $dateSelector 1=Show also date range input fields - * @param string $seller Object of seller third party - * @param string $buyer Object of buyer third party - * @param int $selected Object line selected - * @param Extrafields $extrafields Object of extrafields - * @param string $defaulttpldir Directory where to find the template + * @param string $action GET/POST action + * @param CommonObjectLine $line Selected object line to output + * @param string $var Is it a an odd line (true) + * @param int $num Number of line (0) + * @param int $i I + * @param int $dateSelector 1=Show also date range input fields + * @param string $seller Object of seller third party + * @param string $buyer Object of buyer third party + * @param int $selected Object line selected + * @param Extrafields $extrafields Object of extrafields + * @param string $defaulttpldir Directory where to find the template * @return void */ public function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafields = null, $defaulttpldir = '/core/tpl') { global $conf,$langs,$user,$object,$hookmanager; - global $form,$bc,$bcdd; + global $form; global $object_rights, $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this ! $object_rights = $this->getRights(); @@ -4319,7 +4318,6 @@ abstract class CommonObject print ''.$langs->trans('ReductionShort').''; print ''.$form->showCheckAddButtons('checkforselect', 1).''; print ''; - $var = true; $i = 0; if (! empty($this->lines)) @@ -4330,14 +4328,14 @@ abstract class CommonObject { if (empty($line->fk_parent_line)) { - $parameters=array('line'=>$line,'var'=>$var,'i'=>$i); + $parameters=array('line'=>$line, 'i'=>$i); $action=''; $hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks } } else { - $this->printOriginLine($line, $var, $restrictlist, '/core/tpl', $selectedLines); + $this->printOriginLine($line, '', $restrictlist, '/core/tpl', $selectedLines); } $i++; diff --git a/htdocs/core/tpl/originproductline.tpl.php b/htdocs/core/tpl/originproductline.tpl.php index 2fd33c25cc5..bfc1456e005 100644 --- a/htdocs/core/tpl/originproductline.tpl.php +++ b/htdocs/core/tpl/originproductline.tpl.php @@ -43,7 +43,9 @@ print ''.$this->tpl['remise_percent'].''; $selected=1; if (!empty($selectedLines) && !in_array($this->tpl['id'], $selectedLines)) $selected=0; -print ''; +print ''; +print ''; +print ''; print ''."\n"; ?> diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index 96cb662fe0b..c4f0b6d4e83 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -730,6 +730,96 @@ class Mo extends CommonObject return $error; } + + /** + * Return HTML table table of source object lines + * TODO Move this and previous function into output html class file (htmlline.class.php). + * If lines are into a template, title must also be into a template + * But for the moment we don't know if it's possible, so we keep the method available on overloaded objects. + * + * @param string $restrictlist ''=All lines, 'services'=Restrict to services only + * @param array $selectedLines Array of lines id for selected lines + * @return void + */ + public function printOriginLinesList($restrictlist = '', $selectedLines = array()) + { + global $langs, $hookmanager, $conf, $form; + + print ''; + print ''.$langs->trans('Ref').''; + print ''.$langs->trans('Qty').''; + print ''.$langs->trans('QtyFrozen').''; + print ''.$langs->trans('DisableStockChange').''; + //print ''.$langs->trans('Efficiency').''; + //print ''.$form->showCheckAddButtons('checkforselect', 1).''; + print ''; + print ''; + $i = 0; + + if (! empty($this->lines)) + { + foreach ($this->lines as $line) + { + if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) + { + if (empty($line->fk_parent_line)) + { + $parameters=array('line'=>$line, 'i'=>$i); + $action=''; + $hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + } + } + else + { + $this->printOriginLine($line, '', $restrictlist, '/core/tpl', $selectedLines); + } + + $i++; + } + } + } + + + /** + * Return HTML with a line of table array of source object lines + * TODO Move this and previous function into output html class file (htmlline.class.php). + * If lines are into a template, title must also be into a template + * But for the moment we don't know if it's possible as we keep a method available on overloaded objects. + * + * @param CommonObjectLine $line Line + * @param string $var Var + * @param string $restrictlist ''=All lines, 'services'=Restrict to services only (strike line if not) + * @param string $defaulttpldir Directory where to find the template + * @param array $selectedLines Array of lines id for selected lines + * @return void + */ + public function printOriginLine($line, $var, $restrictlist = '', $defaulttpldir = '/core/tpl', $selectedLines = array()) + { + global $langs, $conf; + + $this->tpl['id'] = $line->id; + + $this->tpl['label']=''; + if (! empty($line->fk_product)) + { + $productstatic = new Product($this->db); + $productstatic->fetch($line->fk_product); + $this->tpl['label'].= $productstatic->getNomUrl(1); + //$this->tpl['label'].= ' - '.$productstatic->label; + } + else + { + + } + + $this->tpl['qty'] = $line->qty; + $this->tpl['qty_frozen'] = $line->qty_frozen; + $this->tpl['disable_stock_change'] = $line->disable_stock_change; + //$this->tpl['efficiency'] = $line->efficiency; + + $tpl = DOL_DOCUMENT_ROOT.'/mrp/tpl/originproductline.tpl.php'; + $res = include $tpl; + } } /** diff --git a/htdocs/mrp/mo_card.php b/htdocs/mrp/mo_card.php index 7294d5cb04d..1408162b111 100644 --- a/htdocs/mrp/mo_card.php +++ b/htdocs/mrp/mo_card.php @@ -47,8 +47,9 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; -dol_include_once('/mrp/class/mo.class.php'); -dol_include_once('/mrp/lib/mrp_mo.lib.php'); +require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php'; +require_once DOL_DOCUMENT_ROOT.'/mrp/lib/mrp_mo.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php'; // Load translation files required by the page $langs->loadLangs(array("mrp", "other")); @@ -65,6 +66,7 @@ $backtopage = GETPOST('backtopage', 'alpha'); // Initialize technical objects $object = new Mo($db); +$objectbom = new BOM($db); $extrafields = new ExtraFields($db); $diroutputmassaction = $conf->mrp->dir_output.'/temp/massgeneration/'.$user->id; $hookmanager->initHooks(array('mocard', 'globalcard')); // Note that conf->hooks_modules contains array @@ -87,6 +89,16 @@ if (empty($action) && empty($id) && empty($ref)) $action = 'view'; // Load object include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once. +if (GETPOST('fk_bom', 'int')) +{ + $objectbom->fetch(GETPOST('fk_bom', 'int')); + + $_POST['fk_product'] = $objectbom->fk_product; + $_POST['qty'] = $objectbom->qty; + $_POST['fk_warehouse'] = $objectbom->fk_warehouse; + $_POST['note_private'] = $objectbom->note_private; +} + // Security check - Protection if external user //if ($user->socid > 0) access_forbidden(); //if ($user->socid > 0) $socid = $user->socid; @@ -212,6 +224,9 @@ if ($action == 'create') console.log('We change value of BOM with BOM of id '+jQuery('#fk_bom').val()); if (jQuery('#fk_bom').val() > 0) { + // Redirect to page with fk_bom set + window.location.href = '?action=create&fk_bom='+jQuery('#fk_bom').val(); + /* $.getJSON('/mrp/ajax/ajax_bom.php?action=getBoms&idbom='+jQuery('#fk_bom').val(), function(data) { console.log(data); if (typeof data.rowid != "undefined") { @@ -234,7 +249,7 @@ if ($action == 'create') } else { console.log("Failed to get BOM"); } - }); + });*/ } else { /* @@ -249,7 +264,7 @@ if ($action == 'create') } }); - jQuery('#fk_bom').trigger('change'); + //jQuery('#fk_bom').trigger('change'); }) trans("Cancel")).'"'.($backtopage ? '' : ' onclick="javascript:history.go(-1)"').'>'; // Cancel for create does not post form if we don't know the backtopage print ''; + print load_fiche_titre($langs->trans("ToConsume")); + + print ''; + + $object->lines = $objectbom->lines; + + $object->printOriginLinesList('', array()); + + print '
'; + print ''; } diff --git a/htdocs/mrp/tpl/originproductline.tpl.php b/htdocs/mrp/tpl/originproductline.tpl.php new file mode 100644 index 00000000000..67032eea7fe --- /dev/null +++ b/htdocs/mrp/tpl/originproductline.tpl.php @@ -0,0 +1,44 @@ + +/* Copyright (C) 2017 Charlie Benke + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// Protection to avoid direct call of template +if (empty($conf) || ! is_object($conf)) +{ + print "Error, template page can't be called as URL"; + exit; +} + +?> + + +tpl['strike'])?'':' strikefordisabled').'">'; +print ''.$this->tpl['label'].''; +print ''.$this->tpl['qty'].''; +print ''.yn($this->tpl['qty_frozen']).''; +print ''.yn($this->tpl['disable_stock_change']).''; +//print ''.$this->tpl['efficiency'].''; + +$selected=1; +if (!empty($selectedLines) && !in_array($this->tpl['id'], $selectedLines)) $selected=0; +print ''; +//print ''; +print ''; +print ''."\n"; +?> +