From 73e62c65aa834c3670a028808177cc7674e9cf40 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 4 Jan 2020 15:20:10 +0100 Subject: [PATCH] Fix phpcs --- htdocs/mrp/class/mo.class.php | 3 +- htdocs/mrp/mo_production.php | 65 ++++++++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 10 deletions(-) diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index e5ac29616a7..0f22e00de3c 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -1464,7 +1464,8 @@ class MoLine extends CommonObjectLine * @param string $role Get lines linked to current line with the selected role ('consumed', 'produced', ...) * @return array Array of lines */ - public function fetchLinesLinked($role) { + public function fetchLinesLinked($role) + { $array = array(); $sql = 'SELECT rowid, qty '; diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index 212a7040927..415e7cc7f99 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -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/mouvementstock.class.php'; dol_include_once('/mrp/class/mo.class.php'); dol_include_once('/mrp/lib/mrp_mo.lib.php'); @@ -152,6 +153,11 @@ if (empty($reshook)) } if ($action == 'confirm_consumeandproduceall') { + $stockmove = new MouvementStock($db); + + $labelmovement = GETPOST('inventorylabel', 'alphanohtml'); + $codemovement = GETPOST('inventorycode', 'alphanohtml'); + $db->begin(); // Process line to consume @@ -177,9 +183,24 @@ if (empty($reshook)) } if (! $error) { + // Record consumption + $moline = new MoLine($db); + $result = $moline->create($user); + if ($result <= 0) { + $error++; + setEventMessages($moline->error, $moline->errors, 'errors'); + } + } - + if (! $error) { + // Record stock movement + $id_product_batch = 0; + $result = $stockmove->livraison($user, $line->fk_product, GETPOST('idwarehouse-'.$line->id.'-'.$i), GETPOST('qty-'.$line->id.'-'.$i), 0, $labelmovement, dol_now(), '', '', GETPOST('batch-'.$line->id.'-'.$i), $id_product_batch, $codemovement); + if ($result <= 0) { + $error++; + setEventMessages($stockmove->error, $stockmove->errors, 'errors'); + } } $i++; @@ -210,9 +231,24 @@ if (empty($reshook)) } if (! $error) { + // Record production + $moline = new MoLine($db); + $result = $moline->create($user); + if ($result <= 0) { + $error++; + setEventMessages($moline->error, $moline->errors, 'errors'); + } + } - + if (! $error) { + // Record stock movement + $id_product_batch = 0; + $result = $stockmove->reception($user, $line->fk_product, GETPOST('idwarehouse-'.$line->id.'-'.$i), GETPOST('qty-'.$line->id.'-'.$i), 0, $labelmovement, dol_now(), '', '', GETPOST('batch-'.$line->id.'-'.$i), $id_product_batch, $codemovement); + if ($result <= 0) { + $error++; + setEventMessages($stockmove->error, $stockmove->errors, 'errors'); + } } $i++; @@ -222,7 +258,13 @@ if (empty($reshook)) if (! $error) { // Update status of MO - + $qtyremaintoconsume = 0; + $qtyremaintoproduce = 0; + if ($qtyremaintoconsume == 0 && $qtyremaintoproduce == 0) { + $object->setStatut($object::STATUS_INPROGRESS); + } else { + $object->setStatut($object::STATUS_PRODUCED); + } } if ($error) { @@ -455,12 +497,12 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } if ($action == 'consumeandproduceall') { - $defaultstockmovementlabel = $langs->trans("ProductionForRefAndDate", $object->ref, dol_print_date(dol_now(), 'standard')); - $defaultstockmovementcode = $object->ref.'_'.dol_print_date(dol_now(), 'dayhourlog'); + $defaultstockmovementlabel = GETPOST('inventorylabel', 'alphanohtml') ? GETPOST('inventorylabel', 'alphanohtml') : $langs->trans("ProductionForRefAndDate", $object->ref, dol_print_date(dol_now(), 'standard')); + $defaultstockmovementcode = GETPOST('inventorycode', 'alphanohtml') ? GETPOST('inventorycode', 'alphanohtml') : $object->ref.'_'.dol_print_date(dol_now(), 'dayhourlog'); print '
'; print ''.$langs->trans("ConfirmProductionDesc", $langs->transnoentitiesnoconv("Confirm")).'
'; - print $langs->trans("MovementLabel").':   '; + print $langs->trans("MovementLabel").':   '; print $langs->trans("InventoryCode").':

'; print ' '.$langs->trans("AutoCloseMO").'
'; print ''; @@ -495,7 +537,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''.$langs->trans("Product").''; print ''.$langs->trans("Qty").''; print ''.$langs->trans("QtyAlreadyConsumed").''; - print ''; + print ''; + if ($action == 'consumeandproduceall') print $langs->trans("Warehouse"); + print ''; if ($conf->productbatch->enabled) { print ''; if ($action == 'consumeandproduceall') print $langs->trans("Batch"); @@ -529,7 +573,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } print ''; print ''.$alreadyconsumed.''; - print ''; // Warehouse + print ''; + print ''; // Warehouse if ($conf->productbatch->enabled) { print ''; // Lot } @@ -604,7 +649,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''.$langs->trans("Product").''; print ''.$langs->trans("Qty").''; print ''.$langs->trans("QtyAlreadyProduced").''; - print ''; + print ''; + if ($action == 'consumeandproduceall') print $langs->trans("Warehouse"); + print ''; if ($conf->productbatch->enabled) { print ''; if ($action == 'consumeandproduceall') print $langs->trans("Batch");