Fix edit shipment line when line is a not predefined product

This commit is contained in:
Laurent Destailleur 2017-12-01 14:33:06 +01:00
parent 09e611aa21
commit e3671da37f
3 changed files with 100 additions and 61 deletions

View File

@ -653,7 +653,6 @@ if (empty($reshook))
else if ($action == 'updateline' && $user->rights->expedition->creer && GETPOST('save')) else if ($action == 'updateline' && $user->rights->expedition->creer && GETPOST('save'))
{ {
// Clean parameters // Clean parameters
$qty=0; $qty=0;
$entrepot_id = 0; $entrepot_id = 0;
$batch_id = 0; $batch_id = 0;
@ -662,9 +661,8 @@ if (empty($reshook))
$num_prod = count($lines); $num_prod = count($lines);
for ($i = 0 ; $i < $num_prod ; $i++) 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); $line = new ExpeditionLigne($db);
// Extrafields Lines // Extrafields Lines
$extrafieldsline = new ExtraFields($db); $extrafieldsline = new ExtraFields($db);
@ -795,6 +793,8 @@ if (empty($reshook))
} }
} }
else else
{
if ($lines[$i]->fk_product > 0)
{ {
// line without lot // line without lot
if ($lines[$i]->entrepot_id > 0) if ($lines[$i]->entrepot_id > 0)
@ -837,6 +837,19 @@ if (empty($reshook))
} }
} }
} }
else // Product no predefined
{
$qty = "qtyl".$line_id;
$line->id = $line_id;
$line->qty = GETPOST($qty, 'int');
$line->entrepot_id = 0;
if ($line->update($user) < 0) {
setEventMessages($line->error, $line->errors, 'errors');
$error++;
}
unset($_POST[$qty]);
}
}
} }
} }
@ -2010,9 +2023,8 @@ else if ($id || $ref)
print '<div class="clearboth"></div>'; print '<div class="clearboth"></div>';
/* // Lines of products
* Lines of products
*/
if ($action == 'editline') if ($action == 'editline')
{ {
print ' <form name="updateline" id="updateline" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;lineid=' . $line_id . '" method="POST"> print ' <form name="updateline" id="updateline" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;lineid=' . $line_id . '" method="POST">
@ -2027,11 +2039,14 @@ else if ($id || $ref)
print '<div class="div-table-responsive-no-min">'; print '<div class="div-table-responsive-no-min">';
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
// #
if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
{ {
print '<td width="5" align="center">&nbsp;</td>'; print '<td width="5" align="center">&nbsp;</td>';
} }
// Product/Service
print '<td>'.$langs->trans("Products").'</td>'; print '<td>'.$langs->trans("Products").'</td>';
// Qty
print '<td align="center">'.$langs->trans("QtyOrdered").'</td>'; print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
if ($origin && $origin_id > 0) 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(); $alreadysent = array();
if ($origin && $origin_id > 0) if ($origin && $origin_id > 0)
{ {
@ -2156,6 +2171,7 @@ else if ($id || $ref)
print '<!-- origin line id = '.$lines[$i]->origin_line_id.' -->'; // id of order line print '<!-- origin line id = '.$lines[$i]->origin_line_id.' -->'; // id of order line
print '<tr class="oddeven">'; print '<tr class="oddeven">';
// #
if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
{ {
print '<td align="center">'.($i+1).'</td>'; print '<td align="center">'.($i+1).'</td>';
@ -2195,7 +2211,7 @@ else if ($id || $ref)
else else
{ {
print "<td>"; print "<td>";
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'); else $text = img_object($langs->trans('Product'),'product');
if (! empty($lines[$i]->label)) { if (! empty($lines[$i]->label)) {
@ -2246,9 +2262,10 @@ else if ($id || $ref)
if ($action == 'editline' && $lines[$i]->id == $line_id) if ($action == 'editline' && $lines[$i]->id == $line_id)
{ {
// edit mode // edit mode
print '<td colspan="'.$editColspan.'"><table>'; print '<td colspan="'.$editColspan.'" align="center"><table class="nobordernopadding">';
if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0) if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0)
{ {
print '<!-- case edit 1 -->';
$line = new ExpeditionLigne($db); $line = new ExpeditionLigne($db);
foreach ($lines[$i]->detail_batch as $detail_batch) foreach ($lines[$i]->detail_batch as $detail_batch)
{ {
@ -2273,9 +2290,12 @@ else if ($id || $ref)
print '</tr>'; print '</tr>';
} }
else if (! empty($conf->stock->enabled)) else if (! empty($conf->stock->enabled))
{
if ($lines[$i]->fk_product > 0)
{ {
if ($lines[$i]->entrepot_id > 0) if ($lines[$i]->entrepot_id > 0)
{ {
print '<!-- case edit 2 -->';
print '<tr>'; print '<tr>';
// Qty to ship or shipped // Qty to ship or shipped
print '<td>' . '<input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty_shipped.'">' . '</td>'; print '<td>' . '<input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty_shipped.'">' . '</td>';
@ -2287,6 +2307,7 @@ else if ($id || $ref)
} }
else if (count($lines[$i]->details_entrepot) > 1) else if (count($lines[$i]->details_entrepot) > 1)
{ {
print '<!-- case edit 3 -->';
foreach ($lines[$i]->details_entrepot as $detail_entrepot) foreach ($lines[$i]->details_entrepot as $detail_entrepot)
{ {
print '<tr>'; print '<tr>';
@ -2299,6 +2320,24 @@ else if ($id || $ref)
print '</tr>'; print '</tr>';
} }
} }
else
{
print '<!-- case edit 4 -->';
print '<tr><td colspan="3">'.$langs->trans("NotEnoughStock").'</td></tr>';
}
}
else
{
print '<!-- case edit 5 -->';
print '<tr>';
// Qty to ship or shipped
print '<td>' . '<input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty_shipped.'">' . '</td>';
// Warehouse source
print '<td>' . '</td>';
// Batch number managment
print '<td>' . '</td>';
print '</tr>';
}
} }
print '</table></td>'; print '</table></td>';
} }

View File

@ -2619,7 +2619,7 @@ class ExpeditionLigne extends CommonObjectLine
{ {
// update line // update line
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; $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.= " , qty = ".$qty;
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;

View File

@ -774,7 +774,7 @@ if ($id > 0 || ! empty($ref))
$product->load_stock('warehouseopen'); $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 '<td align="center">'; print '<td align="center">';
print $product->stock_reel; print $product->stock_reel;