From e3671da37f6ad49324b5b2fdab8f0d21eedf11ba Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 1 Dec 2017 14:33:06 +0100 Subject: [PATCH] Fix edit shipment line when line is a not predefined product --- htdocs/expedition/card.php | 147 ++++++++++++------- htdocs/expedition/class/expedition.class.php | 12 +- htdocs/expedition/shipment.php | 2 +- 3 files changed, 100 insertions(+), 61 deletions(-) diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index e8a716c10f0..04d895fd015 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -653,7 +653,6 @@ if (empty($reshook)) else if ($action == 'updateline' && $user->rights->expedition->creer && GETPOST('save')) { // Clean parameters - $qty=0; $entrepot_id = 0; $batch_id = 0; @@ -662,9 +661,8 @@ if (empty($reshook)) $num_prod = count($lines); for ($i = 0 ; $i < $num_prod ; $i++) { - if ($lines[$i]->id == $line_id) + if ($lines[$i]->id == $line_id) // we have found line to update { - // line to update $line = new ExpeditionLigne($db); // Extrafields Lines $extrafieldsline = new ExtraFields($db); @@ -796,46 +794,61 @@ if (empty($reshook)) } else { - // line without lot - if ($lines[$i]->entrepot_id > 0) + if ($lines[$i]->fk_product > 0) + { + // line without lot + if ($lines[$i]->entrepot_id > 0) + { + // single warehouse shipment line + $stockLocation="entl".$line_id; + $qty = "qtyl".$line_id; + $line->id = $line_id; + $line->entrepot_id = GETPOST($stockLocation,'int'); + $line->qty = GETPOST($qty, 'int'); + if ($line->update($user) < 0) { + setEventMessages($line->error, $line->errors, 'errors'); + $error++; + } + unset($_POST[$stockLocation]); + unset($_POST[$qty]); + } + else if (count($lines[$i]->details_entrepot) > 1) + { + // multi warehouse shipment lines + foreach ($lines[$i]->details_entrepot as $detail_entrepot) + { + if (! $error) { + $stockLocation="entl".$detail_entrepot->line_id; + $qty = "qtyl".$detail_entrepot->line_id; + $warehouse = GETPOST($stockLocation,'int'); + if (!empty ($warehouse)) + { + $line->id = $detail_entrepot->line_id; + $line->entrepot_id = $warehouse; + $line->qty = GETPOST($qty, 'int'); + if ($line->update($user) < 0) { + setEventMessages($line->error, $line->errors, 'errors'); + $error++; + } + } + unset($_POST[$stockLocation]); + unset($_POST[$qty]); + } + } + } + } + else // Product no predefined { - // single warehouse shipment line - $stockLocation="entl".$line_id; $qty = "qtyl".$line_id; $line->id = $line_id; - $line->entrepot_id = GETPOST($stockLocation,'int'); $line->qty = GETPOST($qty, 'int'); + $line->entrepot_id = 0; if ($line->update($user) < 0) { setEventMessages($line->error, $line->errors, 'errors'); $error++; } - unset($_POST[$stockLocation]); unset($_POST[$qty]); } - else if (count($lines[$i]->details_entrepot) > 1) - { - // multi warehouse shipment lines - foreach ($lines[$i]->details_entrepot as $detail_entrepot) - { - if (! $error) { - $stockLocation="entl".$detail_entrepot->line_id; - $qty = "qtyl".$detail_entrepot->line_id; - $warehouse = GETPOST($stockLocation,'int'); - if (!empty ($warehouse)) - { - $line->id = $detail_entrepot->line_id; - $line->entrepot_id = $warehouse; - $line->qty = GETPOST($qty, 'int'); - if ($line->update($user) < 0) { - setEventMessages($line->error, $line->errors, 'errors'); - $error++; - } - } - unset($_POST[$stockLocation]); - unset($_POST[$qty]); - } - } - } } } } @@ -2010,9 +2023,8 @@ else if ($id || $ref) print '
'; - /* - * Lines of products - */ + // Lines of products + if ($action == 'editline') { print '
@@ -2027,11 +2039,14 @@ else if ($id || $ref) print '
'; print ''; print ''; + // # if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { print ''; } + // Product/Service print ''; + // Qty print ''; if ($origin && $origin_id > 0) { @@ -2107,7 +2122,7 @@ else if ($id || $ref) } } - // Get list of products already sent for same source object + // Get list of products already sent for same source object into $alreadysent $alreadysent = array(); if ($origin && $origin_id > 0) { @@ -2156,6 +2171,7 @@ else if ($id || $ref) print ''; // id of order line print ''; + // # if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { print ''; @@ -2195,7 +2211,7 @@ else if ($id || $ref) else { print "
 '.$langs->trans("Products").''.$langs->trans("QtyOrdered").'
'.($i+1).'"; - if ($lines[$i]->fk_product_type==1) $text = img_object($langs->trans('Service'),'service'); + if ($lines[$i]->product_type == Product::TYPE_SERVICE) $text = img_object($langs->trans('Service'),'service'); else $text = img_object($langs->trans('Product'),'product'); if (! empty($lines[$i]->label)) { @@ -2246,9 +2262,10 @@ else if ($id || $ref) if ($action == 'editline' && $lines[$i]->id == $line_id) { // edit mode - print ''; + print ''; diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 4807564e65f..342b7a3aa1f 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -2544,8 +2544,8 @@ class ExpeditionLigne extends CommonObjectLine if (! empty($batch) && $conf->productbatch->enabled) { - dol_syslog(get_class($this)."::update expedition batch id=$expedition_batch_id, batch_id=$batch_id, batch=$batch"); - + dol_syslog(get_class($this)."::update expedition batch id=$expedition_batch_id, batch_id=$batch_id, batch=$batch"); + if (empty($batch_id) || empty($this->fk_product)) { dol_syslog(get_class($this).'::update missing fk_origin_stock (batch_id) and/or fk_product', LOG_ERR); $this->errors[]='ErrorMandatoryParametersNotProvided'; @@ -2594,10 +2594,10 @@ class ExpeditionLigne extends CommonObjectLine $error++; } } - if (! $error && $this->detail_batch->dluo_qty > 0) + if (! $error && $this->detail_batch->dluo_qty > 0) { // create lot expedition line - if (isset($lot->id)) + if (isset($lot->id)) { $shipmentLot = new ExpeditionLineBatch($this->db); $shipmentLot->batch = $lot->batch; @@ -2606,7 +2606,7 @@ class ExpeditionLigne extends CommonObjectLine $shipmentLot->entrepot_id = $this->detail_batch->entrepot_id; $shipmentLot->dluo_qty = $this->detail_batch->dluo_qty; $shipmentLot->fk_origin_stock = $batch_id; - if ($shipmentLot->create($this->id) < 0) + if ($shipmentLot->create($this->id) < 0) { $this->errors[]=$shipmentLot->errors; $error++; @@ -2619,7 +2619,7 @@ class ExpeditionLigne extends CommonObjectLine { // update line $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; - $sql.= " fk_entrepot = ".$this->entrepot_id; + $sql.= " fk_entrepot = ".($this->entrepot_id > 0 ? $this->entrepot_id : 'null'); $sql.= " , qty = ".$qty; $sql.= " WHERE rowid = ".$this->id; diff --git a/htdocs/expedition/shipment.php b/htdocs/expedition/shipment.php index 3d3d8a0de6c..a358d349531 100644 --- a/htdocs/expedition/shipment.php +++ b/htdocs/expedition/shipment.php @@ -774,7 +774,7 @@ if ($id > 0 || ! empty($ref)) $product->load_stock('warehouseopen'); } - if ($objp->fk_product > 0 && $type == 0 && ! empty($conf->stock->enabled)) + if ($objp->fk_product > 0 && ($type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES)) && ! empty($conf->stock->enabled)) { print '
'; if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0) { + print ''; $line = new ExpeditionLigne($db); foreach ($lines[$i]->detail_batch as $detail_batch) { @@ -2274,30 +2291,52 @@ else if ($id || $ref) } else if (! empty($conf->stock->enabled)) { - if ($lines[$i]->entrepot_id > 0) + if ($lines[$i]->fk_product > 0) { - print ''; - // Qty to ship or shipped - print ''; - // Warehouse source - print ''; - // Batch number managment - print ''; - print ''; - } - else if (count($lines[$i]->details_entrepot) > 1) - { - foreach ($lines[$i]->details_entrepot as $detail_entrepot) + if ($lines[$i]->entrepot_id > 0) { + print ''; print ''; // Qty to ship or shipped - print ''; + print ''; // Warehouse source - print ''; + print ''; // Batch number managment print ''; print ''; } + else if (count($lines[$i]->details_entrepot) > 1) + { + print ''; + foreach ($lines[$i]->details_entrepot as $detail_entrepot) + { + print ''; + // Qty to ship or shipped + print ''; + // Warehouse source + print ''; + // Batch number managment + print ''; + print ''; + } + } + else + { + print ''; + print ''; + } + } + else + { + print ''; + print ''; + // Qty to ship or shipped + print ''; + // Warehouse source + print ''; + // Batch number managment + print ''; + print ''; } } print '
' . '' . '' . $formproduct->selectWarehouses($lines[$i]->entrepot_id, 'entl'.$line_id, '', 1, 0, $lines[$i]->fk_product, '', 1). ' - ' . $langs->trans("NA") . '
' . '' . '' . '' . '' . $formproduct->selectWarehouses($detail_entrepot->entrepot_id, 'entl'.$detail_entrepot->line_id, '', 1, 0, $lines[$i]->fk_product, '', 1) . '' . $formproduct->selectWarehouses($lines[$i]->entrepot_id, 'entl'.$line_id, '', 1, 0, $lines[$i]->fk_product, '', 1). ' - ' . $langs->trans("NA") . '
' . '' . '' . $formproduct->selectWarehouses($detail_entrepot->entrepot_id, 'entl'.$detail_entrepot->line_id, '', 1, 0, $lines[$i]->fk_product, '', 1) . ' - ' . $langs->trans("NA") . '
'.$langs->trans("NotEnoughStock").'
' . '' . '' . '' . '
'; print $product->stock_reel;