Skip to content

Commit

Permalink
Work on MO
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Nov 12, 2019
1 parent 94d63a4 commit dc77a58
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 39 deletions.
2 changes: 1 addition & 1 deletion htdocs/bom/class/bom.class.php
Expand Up @@ -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,),
);
Expand Down
8 changes: 4 additions & 4 deletions htdocs/bom/tpl/objectline_create.tpl.php
Expand Up @@ -128,10 +128,10 @@
print '<td class="bordertop nobottom linecoldisablestockchange right"><input type="checkbox" name="disable_stock_change" id="disable_stock_change" class="flat right" value="1"'.(GETPOST("disable_stock_change", 'alpha')?' checked="checked"':'').'">';
print '</td>';

$coldisplay++;
print '<td class="bordertop nobottom nowrap linecollost right">';
print '<input type="text" size="1" name="efficiency" id="efficiency" class="flat right" value="'.(GETPOSTISSET("efficiency")?GETPOST("efficiency", 'alpha'):1).'">';
print '</td>';
//$coldisplay++;
//print '<td class="bordertop nobottom nowrap linecollost right">';
//print '<input type="text" size="1" name="efficiency" id="efficiency" class="flat right" value="'.(GETPOSTISSET("efficiency")?GETPOST("efficiency", 'alpha'):1).'">';
//print '</td>';


$coldisplay += $colspan;
Expand Down
6 changes: 3 additions & 3 deletions htdocs/bom/tpl/objectline_edit.tpl.php
Expand Up @@ -124,9 +124,9 @@
print '<td class="nobottom linecoldisablestockchange right"><input type="checkbox" name="disable_stock_change" id="disable_stock_change" class="flat right" value="1"'.(GETPOSTISSET('disablestockchange')?(GETPOST("disable_stock_change", 'int')?' checked="checked"':''):($line->disable_stock_change?' checked="checked"':'')).'">';
print '</td>';

$coldisplay++;
print '<td class="nobottom nowrap linecollost right">';
print '<input type="text" size="1" name="efficiency" id="efficiency" class="flat right" value="'.$line->efficiency.'"></td>';
//$coldisplay++;
//print '<td class="nobottom nowrap linecollost right">';
//print '<input type="text" size="1" name="efficiency" id="efficiency" class="flat right" value="'.$line->efficiency.'"></td>';

$coldisplay+=$colspan;
print '<td class="nobottom linecoledit center valignmiddle" colspan="'.$colspan.'">';
Expand Down
2 changes: 1 addition & 1 deletion htdocs/bom/tpl/objectline_title.tpl.php
Expand Up @@ -66,7 +66,7 @@
print '<td class="linecolqty right">'.$form->textwithpicto($langs->trans('DisableStockChange'), $langs->trans('DisableStockChangeHelp')).'</td>';

// Efficiency
print '<td class="linecollost right">'.$form->textwithpicto($langs->trans('ManufacturingEfficiency'), $langs->trans('ValueOfMeansLoss')).'</td>';
//print '<td class="linecollost right">'.$form->textwithpicto($langs->trans('ManufacturingEfficiency'), $langs->trans('XXX')).'</td>';

print '<td class="linecoledit"></td>'; // No width to allow autodim

Expand Down
10 changes: 5 additions & 5 deletions htdocs/bom/tpl/objectline_view.tpl.php
Expand Up @@ -97,12 +97,12 @@
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 '</td>';

print '<td class="linecolqty nowrap right">';
$coldisplay++;
echo $line->efficiency;
print '</td>';
//print '<td class="linecolqty nowrap right">';
//$coldisplay++;
//echo $line->efficiency;
//print '</td>';

if ($this->status == 0 && ($object_rights->write) && $action != 'selectlines' ) {
if ($this->status == 0 && ($object_rights->write) && $action != 'selectlines' ) {
print '<td class="linecoledit center">';
$coldisplay++;
if (($line->info_bits & 2) == 2 || ! empty($disableedit)) {
Expand Down
38 changes: 18 additions & 20 deletions htdocs/core/class/commonobject.class.php
Expand Up @@ -4018,7 +4018,7 @@ public function setIncoterms($id_incoterm, $location)
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))
Expand Down Expand Up @@ -4116,7 +4116,6 @@ public function printObjectLines($action, $seller, $buyer, $selected = 0, $dateS
}
}

$var = true;
$i = 0;

print "<tbody>\n";
Expand All @@ -4130,18 +4129,18 @@ public function printObjectLines($action, $seller, $buyer, $selected = 0, $dateS
{
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++;
Expand All @@ -4153,23 +4152,23 @@ public function printObjectLines($action, $seller, $buyer, $selected = 0, $dateS
* 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();
Expand Down Expand Up @@ -4319,7 +4318,6 @@ public function printOriginLinesList($restrictlist = '', $selectedLines = array(
print '<td class="right">'.$langs->trans('ReductionShort').'</td>';
print '<td class="center">'.$form->showCheckAddButtons('checkforselect', 1).'</td>';
print '</tr>';
$var = true;
$i = 0;

if (! empty($this->lines))
Expand All @@ -4330,14 +4328,14 @@ public function printOriginLinesList($restrictlist = '', $selectedLines = array(
{
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++;
Expand Down
4 changes: 3 additions & 1 deletion htdocs/core/tpl/originproductline.tpl.php
Expand Up @@ -43,7 +43,9 @@

$selected=1;
if (!empty($selectedLines) && !in_array($this->tpl['id'], $selectedLines)) $selected=0;
print '<td class="center"><input id="cb'.$this->tpl['id'].'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$this->tpl['id'].'"'.($selected?' checked="checked"':'').'></td>';
print '<td class="center">';
print '<input id="cb'.$this->tpl['id'].'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$this->tpl['id'].'"'.($selected?' checked="checked"':'').'>';
print '</td>';
print '</tr>'."\n";
?>
<!-- END PHP TEMPLATE originproductline.tpl.php -->
90 changes: 90 additions & 0 deletions htdocs/mrp/class/mo.class.php
Expand Up @@ -730,6 +730,96 @@ public function doScheduledJob()

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 '<tr class="liste_titre">';
print '<td>'.$langs->trans('Ref').'</td>';
print '<td class="right">'.$langs->trans('Qty').'</td>';
print '<td class="center">'.$langs->trans('QtyFrozen').'</td>';
print '<td class="center">'.$langs->trans('DisableStockChange').'</td>';
//print '<td class="right">'.$langs->trans('Efficiency').'</td>';
//print '<td class="center">'.$form->showCheckAddButtons('checkforselect', 1).'</td>';
print '<td class="center"></td>';
print '</tr>';
$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;
}
}

/**
Expand Down
33 changes: 29 additions & 4 deletions htdocs/mrp/mo_card.php
Expand Up @@ -47,8 +47,9 @@
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"));
Expand All @@ -65,6 +66,7 @@

// 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
Expand All @@ -87,6 +89,16 @@
// 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;
Expand Down Expand Up @@ -212,6 +224,9 @@ function init_myfunc()
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 = '<?php echo $_SERVER["PHP_SELF"] ?>?action=create&fk_bom='+jQuery('#fk_bom').val();
/*
$.getJSON('<?php echo DOL_URL_ROOT ?>/mrp/ajax/ajax_bom.php?action=getBoms&idbom='+jQuery('#fk_bom').val(), function(data) {
console.log(data);
if (typeof data.rowid != "undefined") {
Expand All @@ -234,7 +249,7 @@ function init_myfunc()
} else {
console.log("Failed to get BOM");
}
});
});*/
}
else {
/*
Expand All @@ -249,7 +264,7 @@ function init_myfunc()
}
});

jQuery('#fk_bom').trigger('change');
//jQuery('#fk_bom').trigger('change');
})
</script>
<?php
Expand All @@ -260,6 +275,16 @@ function init_myfunc()
print '<input type="'.($backtopage ? "submit" : "button").'" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'"'.($backtopage ? '' : ' onclick="javascript:history.go(-1)"').'>'; // Cancel for create does not post form if we don't know the backtopage
print '</div>';

print load_fiche_titre($langs->trans("ToConsume"));

print '<table class="noborder centpercent">';

$object->lines = $objectbom->lines;

$object->printOriginLinesList('', array());

print '</table>';

print '</form>';
}

Expand Down
44 changes: 44 additions & 0 deletions htdocs/mrp/tpl/originproductline.tpl.php
@@ -0,0 +1,44 @@
<?php
/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
/* Copyright (C) 2017 Charlie Benke <charlie@patas-monkey.com>
*
* 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 <https://www.gnu.org/licenses/>.
*/

// Protection to avoid direct call of template
if (empty($conf) || ! is_object($conf))
{
print "Error, template page can't be called as URL";
exit;
}

?>

<!-- BEGIN PHP TEMPLATE originproductline.tpl.php -->
<?php
print '<tr class="oddeven'.(empty($this->tpl['strike'])?'':' strikefordisabled').'">';
print '<td>'.$this->tpl['label'].'</td>';
print '<td class="right">'.$this->tpl['qty'].'</td>';
print '<td class="center">'.yn($this->tpl['qty_frozen']).'</td>';
print '<td class="center">'.yn($this->tpl['disable_stock_change']).'</td>';
//print '<td class="right">'.$this->tpl['efficiency'].'</td>';

$selected=1;
if (!empty($selectedLines) && !in_array($this->tpl['id'], $selectedLines)) $selected=0;
print '<td class="center">';
//print '<input id="cb'.$this->tpl['id'].'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$this->tpl['id'].'"'.($selected?' checked="checked"':'').'>';
print '</td>';
print '</tr>'."\n";
?>
<!-- END PHP TEMPLATE originproductline.tpl.php -->

0 comments on commit dc77a58

Please sign in to comment.