Debug MRP

This commit is contained in:
Laurent Destailleur 2020-01-08 19:04:00 +01:00
parent 0802df78b5
commit d0739af8b4
7 changed files with 119 additions and 50 deletions

View File

@ -554,6 +554,7 @@ ALTER TABLE llx_mrp_production MODIFY COLUMN qty real NOT NULL DEFAULT 1;
ALTER TABLE llx_mrp_production ADD COLUMN qty_frozen smallint DEFAULT 0;
ALTER TABLE llx_mrp_production ADD COLUMN disable_stock_change smallint DEFAULT 0;
ALTER TABLE llx_mrp_production ADD CONSTRAINT fk_mrp_production_mo FOREIGN KEY (fk_mo) REFERENCES llx_mrp_mo (rowid);
ALTER TABLE llx_mrp_production ADD CONSTRAINT fk_mrp_production_product FOREIGN KEY (fk_product) REFERENCES llx_product (rowid);
ALTER TABLE llx_mrp_production ADD CONSTRAINT fk_mrp_production_stock_movement FOREIGN KEY (fk_stock_movement) REFERENCES llx_stock_mouvement (rowid);

View File

@ -469,7 +469,10 @@ update llx_facturedet set product_type = 1 where product_type = 0 AND fk_product
update llx_facture_fourn_det set product_type = 0 where product_type = 1 AND fk_product > 0 AND fk_product IN (SELECT rowid FROM llx_product WHERE fk_product_type = 0);
update llx_facture_fourn_det set product_type = 1 where product_type = 0 AND fk_product > 0 AND fk_product IN (SELECT rowid FROM llx_product WHERE fk_product_type = 1);
DELETE FROM llx_mrp_production where qty = 0;
UPDATE llx_accounting_bookkeeping set date_creation = tms where date_creation IS NULL;

View File

@ -496,6 +496,7 @@ class Mo extends CommonObject
if ($obj) {
$resarray[] = array(
'rowid'=> $obj->rowid,
'date'=> $this->db->jdate($obj->date_creation),
'qty' => $obj->qty,
'role' => $obj->role,
'fk_product' => $obj->fk_product,

View File

@ -43,6 +43,12 @@ function moPrepareHead($object)
$head[$h][0] = DOL_URL_ROOT.'/mrp/mo_production.php?id='.$object->id;
$head[$h][1] = $langs->trans("Production");
$arrayproduced = $object->fetchLinesLinked('produced', 0);
$nbProduced = 0;
foreach($arrayproduced as $lineproduced) {
$nbProduced += $lineproduced['qty'];
}
$head[$h][1].= '<span class="badge marginleftonlyshort">'.$nbProduced.' / '.$object->qty.'</span>';
$head[$h][2] = 'production';
$h++;

View File

@ -49,6 +49,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
dol_include_once('/mrp/class/mo.class.php');
dol_include_once('/mrp/lib/mrp_mo.lib.php');
@ -66,6 +67,8 @@ $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'moc
$backtopage = GETPOST('backtopage', 'alpha');
//$lineid = GETPOST('lineid', 'int');
$collapse = GETPOST('collapse', 'aZ09comma');
// Initialize technical objects
$object = new Mo($db);
$extrafields = new ExtraFields($db);
@ -371,6 +374,7 @@ $form = new Form($db);
$formfile = new FormFile($db);
$formproject = new FormProjets($db);
$formproduct = new FormProduct($db);
$tmpwarehouse = new Entrepot($db);
llxHeader('', $langs->trans('Mo'), '');
@ -587,6 +591,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
/*
* Lines
*/
$collapse = 1;
if (!empty($object->table_element_line))
{
@ -601,26 +606,36 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print load_fiche_titre($langs->trans('Consumption'), '', '');
print '<div class="div-table-responsive-no-min">';
print '<table id="tablelines" class="noborder noshadow" width="100%">';
print '<table id="tablelines" class="noborder noshadow nobottom centpercent">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Product").'</td>';
print '<td>'.$langs->trans("Qty").'</td>';
print '<td>'.$langs->trans("QtyAlreadyConsumed").'</td>';
print '<td class="right">'.$langs->trans("Qty").'</td>';
print '<td class="right">'.$langs->trans("QtyAlreadyConsumed").'</td>';
print '<td>';
if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) print $langs->trans("Warehouse");
if ($collapse || in_array($action, array('consumeorproduce', 'consumeandproduceall'))) print $langs->trans("Warehouse");
print '</td>';
if ($conf->productbatch->enabled) {
print '<td>';
if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) print $langs->trans("Batch");
if ($collapse || in_array($action, array('consumeorproduce', 'consumeandproduceall'))) print $langs->trans("Batch");
print '</td>';
}
print '</tr>';
if (!empty($object->lines))
{
foreach($object->lines as $line) {
$nblinetoconsume = 0;
foreach($object->lines as $line) {
if ($line->role == 'toconsume') {
$nblinetoconsume++;
}
}
$nblinetoconsumecursor = 0;
foreach($object->lines as $line) {
if ($line->role == 'toconsume') {
$nblinetoconsumecursor++;
$tmpproduct = new Product($db);
$tmpproduct->fetch($line->fk_product);
@ -632,31 +647,37 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '<tr>';
print '<td>'.$tmpproduct->getNomUrl(1).'</td>';
print '<td>';
print '<td class="right">';
$help = '';
if ($line->qty_frozen) $help.=($help ? '<br>' : '').'<strong>'.$langs->trans("QuantityFrozen").'</strong>: '.yn(1).' ('.$langs->trans("QuantityConsumedInvariable").')';
if ($line->disable_stock_change) $help.=($help ? '<br>' : '').'<strong>'.$langs->trans("DisableStockChange").'</strong>: '.yn(1).' ('.(($tmpproduct->type == Product::TYPE_SERVICE && empty($conf->global->STOCK_SUPPORTS_SERVICES)) ? $langs->trans("NoStockChangeOnServices") : $langs->trans("DisableStockChangeHelp")).')';
if ($help) {
print $form->textwithpicto($line->qty, $help);
print $form->textwithpicto($line->qty, $help, -1);
} else {
print $line->qty;
}
print '</td>';
print '<td>'.$alreadyconsumed.'</td>';
print '<td>'; // Warehouse
print '<td class="right">';
if ($alreadyconsumed) {
print '<script>';
print 'jQuery(document).ready(function() {
print '<script>';
print 'jQuery(document).ready(function() {
jQuery("#expandtoproduce'.$line->id.'").click(function() {
console.log("Expand mrp_production line '.$line->id.'");
jQuery(".expanddetail'.$line->id.'").toggle();
jQuery(".expanddetail'.$line->id.'").toggle();';
if ($nblinetoconsume == $nblinetoconsumecursor) {
print 'if (jQuery("#tablelines").hasClass("nobottom")) { jQuery("#tablelines").removeClass("nobottom"); } else { jQuery("#tablelines").addClass("nobottom"); }';
}
print '
});
});';
print '</script>';
if (empty($conf->use_javascript_ajax)) print '<a href="'.$_SERVER["PHP_SELF"].'?collapse='.$collapse.','.$line->id.'">';
print img_picto($langs->trans("ShowDetails"), "chevron-down", 'id="expandtoproduce'.$line->id.'"');
if (empty($conf->use_javascript_ajax)) print '</a>';
print '</script>';
if (empty($conf->use_javascript_ajax)) print '<a href="'.$_SERVER["PHP_SELF"].'?collapse='.$collapse.','.$line->id.'">';
print img_picto($langs->trans("ShowDetails"), "chevron-down", 'id="expandtoproduce'.$line->id.'"');
if (empty($conf->use_javascript_ajax)) print '</a>';
}
print ' '.$alreadyconsumed;
print '</td>';
print '<td>'; // Warehouse
print '</td>';
if ($conf->productbatch->enabled) {
print '<td></td>'; // Lot
@ -664,7 +685,22 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '</tr>';
// Show detailed of already consumed with js code to collapse
//$arrayoflines = $object->fetchLinesLinked('consumed', $line->id);
foreach($arrayoflines as $line2) {
print '<tr class="expanddetail'.$line->id.' hideobject opacitylow">';
print '<td>';
print dol_print_date($line2['date'], 'dayhour');
print '</td>';
print '<td></td>';
print '<td class="right">'.$line2['qty'].'</td>';
print '<td>';
if ($line2['fk_warehouse'] > 0) {
$tmpwarehouse->fetch($line2['fk_warehouse']);
print $tmpwarehouse->getNomUrl();
}
print '</td>';
print '<td>'.$line2['batch'].'</td>';
print '</tr>';
}
if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
$i = 1;
@ -672,7 +708,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '<td>'.$langs->trans("ToConsume").'</td>';
$preselected = (GETPOSTISSET('qty-'.$line->id.'-'.$i) ? GETPOST('qty-'.$line->id.'-'.$i) : max(0, $line->qty - $alreadyconsumed));
if ($action == 'consumeorproduce' && ! GETPOSTISSET('qty-'.$line->id.'-'.$i)) $preselected = 0;
print '<td><input type="text" class="width50" name="qty-'.$line->id.'-'.$i.'" value="'.$preselected.'"></td>';
print '<td class="right"><input type="text" class="width50" name="qty-'.$line->id.'-'.$i.'" value="'.$preselected.'"></td>';
print '<td></td>';
print '<td>';
if ($tmpproduct->type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
@ -700,24 +736,6 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
}
}
/*if (!empty($object->lines))
{
$object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1, '/mrp/tpl');
}
// Form to add new line
if ($object->status == 0 && $permissiontoadd && $action != 'selectlines')
{
if ($action != 'editline')
{
// Add products/services form
$object->formAddObjectLine(1, $mysoc, $soc, '/mrp/tpl');
$parameters = array();
$reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
}
}*/
print '</table>';
print '</div>';
@ -728,26 +746,36 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print load_fiche_titre($langs->trans('Production'), '', '');
print '<div class="div-table-responsive-no-min">';
print '<table id="tablelines" class="noborder noshadow" width="100%">';
print '<table id="tablelinestoproduce" class="noborder noshadow nobottom centpercent">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Product").'</td>';
print '<td>'.$langs->trans("Qty").'</td>';
print '<td>'.$langs->trans("QtyAlreadyProduced").'</td>';
print '<td class="right">'.$langs->trans("Qty").'</td>';
print '<td class="right">'.$langs->trans("QtyAlreadyProduced").'</td>';
print '<td>';
if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) print $langs->trans("Warehouse");
if ($collapse || in_array($action, array('consumeorproduce', 'consumeandproduceall'))) print $langs->trans("Warehouse");
print '</td>';
if ($conf->productbatch->enabled) {
print '<td>';
if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) print $langs->trans("Batch");
if ($collapse || in_array($action, array('consumeorproduce', 'consumeandproduceall'))) print $langs->trans("Batch");
print '</td>';
}
print '</tr>';
if (!empty($object->lines))
{
$nblinetoproduce = 0;
foreach($object->lines as $line) {
if ($line->role == 'toproduce') {
$nblinetoproduce++;
}
}
$nblinetoproducecursor = 0;
foreach($object->lines as $line) {
if ($line->role == 'toproduce') {
$nblinetoproducecursor++;
$tmpproduct = new Product($db);
$tmpproduct->fetch($line->fk_product);
@ -759,34 +787,58 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '<tr>';
print '<td>'.$tmpproduct->getNomUrl(1).'</td>';
print '<td>'.$line->qty.'</td>';
print '<td>'.$alreadyproduced.'</td>';
print '<td>'; // Warehouse
print '<td class="right">'.$line->qty.'</td>';
print '<td class="right">';
if ($alreadyproduced) {
print '<script>';
print 'jQuery(document).ready(function() {
jQuery("#expand'.$line->id.'").click(function() {
jQuery("#expandtoproduce'.$line->id.'").click(function() {
console.log("Expand mrp_production line '.$line->id.'");
jQuery(".expanddetail'.$line->id.'").toggle();
jQuery(".expanddetailtoproduce'.$line->id.'").toggle();';
if ($nblinetoproduce == $nblinetoproducecursor) {
print 'if (jQuery("#tablelinestoproduce").hasClass("nobottom")) { jQuery("#tablelinestoproduce").removeClass("nobottom"); } else { jQuery("#tablelinestoproduce").addClass("nobottom"); }';
}
print '
});
});';
print '</script>';
if (empty($conf->use_javascript_ajax)) print '<a href="'.$_SERVER["PHP_SELF"].'?collapse='.$collapse.','.$line->id.'">';
print img_picto($langs->trans("ShowDetails"), "chevron-down", 'id="expand'.$line->id.'"');
print img_picto($langs->trans("ShowDetails"), "chevron-down", 'id="expandtoproduce'.$line->id.'"');
if (empty($conf->use_javascript_ajax)) print '</a>';
}
print ' '.$alreadyproduced;
print '</td>';
print '<td>'; // Warehouse
print '</td>';
if ($conf->productbatch->enabled) {
print '<td></td>'; // Lot
}
print '</tr>';
// Show detailed of already consumed with js code to collapse
foreach($arrayoflines as $line2) {
print '<tr class="expanddetailtoproduce'.$line->id.' hideobject opacitylow">';
print '<td>';
print dol_print_date($line2['date'], 'dayhour');
print '</td>';
print '<td></td>';
print '<td class="right">'.$line2['qty'].'</td>';
print '<td>';
if ($line2['fk_warehouse'] > 0) {
$tmpwarehouse->fetch($line2['fk_warehouse']);
print $tmpwarehouse->getNomUrl();
}
print '</td>';
print '<td>'.$line2['batch'].'</td>';
print '</tr>';
}
if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
print '<tr>';
print '<td>'.$langs->trans("ToProduce").'</td>';
$preselected = (GETPOSTISSET('qtytoproduce-'.$line->id.'-'.$i) ? GETPOST('qtytoproduce-'.$line->id.'-'.$i) : max(0, $line->qty - $alreadyproduced));
if ($action == 'consumeorproduce' && ! GETPOSTISSET('qtytoproduce-'.$line->id.'-'.$i)) $preselected = 0;
print '<td><input type="text" class="width50" name="qtytoproduce-'.$line->id.'-'.$i.'" value="'.$preselected.'"></td>';
print '<td class="right"><input type="text" class="width50" name="qtytoproduce-'.$line->id.'-'.$i.'" value="'.$preselected.'"></td>';
print '<td></td>';
print '<td>';
if ($tmpproduct->type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {

View File

@ -244,6 +244,9 @@ select.flat, form.flat select {
.opacitymediumbycolor {
color: rgba(0, 0, 0, 0.4);
}
.opacitylow {
opacity: 0.6;
}
.opacityhigh {
opacity: 0.2;
}

View File

@ -462,6 +462,9 @@ select.flat, form.flat select {
.opacitymediumbycolor {
color: rgba(0, 0, 0, 0.4);
}
.opacitylow {
opacity: 0.6;
}
.opacityhigh {
opacity: 0.2;
}