FIX qty not visible for a lot when making shipment on a dedicated stock

This commit is contained in:
Laurent Destailleur
2018-10-11 11:56:52 +02:00
parent 40f89d138f
commit ced4038443
6 changed files with 51 additions and 50 deletions

View File

@@ -86,7 +86,7 @@ NEW: Add a tab to specify accountant/auditor of the company
NEW: Add Date delivery and Availability on Propals List NEW: Add Date delivery and Availability on Propals List
NEW: Add date in goods reception supplier order table NEW: Add date in goods reception supplier order table
NEW: Add delivery_time_days of suppliers in export profile NEW: Add delivery_time_days of suppliers in export profile
NEW: Add Docments'tab to expedition module NEW: Add Documents'tab to expedition module
NEW: Use dol_print_phone in thirdparty list page to format phone NEW: Use dol_print_phone in thirdparty list page to format phone
NEW: Add entry for the GDPR contact NEW: Add entry for the GDPR contact
NEW: Add extrafield type "html" NEW: Add extrafield type "html"

View File

@@ -1376,7 +1376,7 @@ function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issuppl
if ($detail->eatby) $dte[]=$outputlangs->transnoentitiesnoconv('printEatby',dol_print_date($detail->eatby, $format, false, $outputlangs)); if ($detail->eatby) $dte[]=$outputlangs->transnoentitiesnoconv('printEatby',dol_print_date($detail->eatby, $format, false, $outputlangs));
if ($detail->sellby) $dte[]=$outputlangs->transnoentitiesnoconv('printSellby',dol_print_date($detail->sellby, $format, false, $outputlangs)); if ($detail->sellby) $dte[]=$outputlangs->transnoentitiesnoconv('printSellby',dol_print_date($detail->sellby, $format, false, $outputlangs));
if ($detail->batch) $dte[]=$outputlangs->transnoentitiesnoconv('printBatch',$detail->batch); if ($detail->batch) $dte[]=$outputlangs->transnoentitiesnoconv('printBatch',$detail->batch);
$dte[]=$outputlangs->transnoentitiesnoconv('printQty',$detail->dluo_qty); $dte[]=$outputlangs->transnoentitiesnoconv('printQty',$detail->qty);
$libelleproduitservice.= "__N__ ".implode(" - ", $dte); $libelleproduitservice.= "__N__ ".implode(" - ", $dte);
} }
} }

View File

@@ -364,7 +364,7 @@ function show_list_sending_receive($origin,$origin_id,$filter='')
$detail.= $langs->trans("Batch").': '.$dbatch->batch; $detail.= $langs->trans("Batch").': '.$dbatch->batch;
$detail.= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby,"day"); $detail.= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby,"day");
$detail.= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby,"day"); $detail.= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby,"day");
$detail.= ' - '.$langs->trans("Qty").': '.$dbatch->dluo_qty; $detail.= ' - '.$langs->trans("Qty").': '.$dbatch->qty;
$detail.= '<br>'; $detail.= '<br>';
} }
print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"),$detail); print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"),$detail);

View File

@@ -649,7 +649,7 @@ if (empty($reshook))
$qty = "qtyl".$detail_batch->fk_expeditiondet.'_'.$detail_batch->id; $qty = "qtyl".$detail_batch->fk_expeditiondet.'_'.$detail_batch->id;
$batch_id = GETPOST($batch,'int'); $batch_id = GETPOST($batch,'int');
$batch_qty = GETPOST($qty, 'int'); $batch_qty = GETPOST($qty, 'int');
if (! empty($batch_id) && ($batch_id != $detail_batch->fk_origin_stock || $batch_qty != $detail_batch->dluo_qty)) if (! empty($batch_id) && ($batch_id != $detail_batch->fk_origin_stock || $batch_qty != $detail_batch->qty))
{ {
if ($lotStock->fetch($batch_id) > 0 && $line->fetch($detail_batch->fk_expeditiondet) > 0) // $line is ExpeditionLine if ($lotStock->fetch($batch_id) > 0 && $line->fetch($detail_batch->fk_expeditiondet) > 0) // $line is ExpeditionLine
{ {
@@ -666,7 +666,7 @@ if (empty($reshook))
$line->detail_batch->batch = $lotStock->batch; $line->detail_batch->batch = $lotStock->batch;
$line->detail_batch->id = $detail_batch->id; $line->detail_batch->id = $detail_batch->id;
$line->detail_batch->entrepot_id = $lotStock->warehouseid; $line->detail_batch->entrepot_id = $lotStock->warehouseid;
$line->detail_batch->dluo_qty = $batch_qty; $line->detail_batch->qty = $batch_qty;
if ($line->update($user) < 0) { if ($line->update($user) < 0) {
setEventMessages($line->error, $line->errors, 'errors'); setEventMessages($line->error, $line->errors, 'errors');
$error++; $error++;
@@ -720,7 +720,7 @@ if (empty($reshook))
$line->detail_batch->fk_origin_stock = $batch_id; $line->detail_batch->fk_origin_stock = $batch_id;
$line->detail_batch->batch = $lotStock->batch; $line->detail_batch->batch = $lotStock->batch;
$line->detail_batch->entrepot_id = $lotStock->warehouseid; $line->detail_batch->entrepot_id = $lotStock->warehouseid;
$line->detail_batch->dluo_qty = $batch_qty; $line->detail_batch->qty = $batch_qty;
if ($line->update($user) < 0) { if ($line->update($user) < 0) {
setEventMessages($line->error, $line->errors, 'errors'); setEventMessages($line->error, $line->errors, 'errors');
$error++; $error++;
@@ -741,7 +741,7 @@ if (empty($reshook))
$line->detail_batch[0]->fk_origin_stock = $batch_id; $line->detail_batch[0]->fk_origin_stock = $batch_id;
$line->detail_batch[0]->batch = $lotStock->batch; $line->detail_batch[0]->batch = $lotStock->batch;
$line->detail_batch[0]->entrepot_id = $lotStock->warehouseid; $line->detail_batch[0]->entrepot_id = $lotStock->warehouseid;
$line->detail_batch[0]->dluo_qty = $batch_qty; $line->detail_batch[0]->qty = $batch_qty;
if ($object->create_line_batch($line, $line->array_options) < 0) if ($object->create_line_batch($line, $line->array_options) < 0)
{ {
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
@@ -1306,6 +1306,7 @@ if ($action == 'create')
{ {
// Product need lot // Product need lot
print '<td></td><td></td></tr>'; // end line and start a new one for lot/serial print '<td></td><td></td></tr>'; // end line and start a new one for lot/serial
print '<!-- Case product need lot -->';
$staticwarehouse=new Entrepot($db); $staticwarehouse=new Entrepot($db);
if ($warehouse_id > 0) $staticwarehouse->fetch($warehouse_id); if ($warehouse_id > 0) $staticwarehouse->fetch($warehouse_id);
@@ -1323,7 +1324,7 @@ if ($action == 'create')
print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">'; print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
if (is_object($product->stock_warehouse[$warehouse_id]) && count($product->stock_warehouse[$warehouse_id]->detail_batch)) if (is_object($product->stock_warehouse[$warehouse_id]) && count($product->stock_warehouse[$warehouse_id]->detail_batch))
{ {
foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch) foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch) // $dbatch is instance of Productbatch
{ {
//var_dump($dbatch); //var_dump($dbatch);
$batchStock = + $dbatch->qty; // To get a numeric $batchStock = + $dbatch->qty; // To get a numeric
@@ -1344,7 +1345,7 @@ if ($action == 'create')
$detail.= $langs->trans("Batch").': '.$dbatch->batch; $detail.= $langs->trans("Batch").': '.$dbatch->batch;
$detail.= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby,"day"); $detail.= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby,"day");
$detail.= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby,"day"); $detail.= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby,"day");
$detail.= ' - '.$langs->trans("Qty").': '.$dbatch->dluo_qty; $detail.= ' - '.$langs->trans("Qty").': '.$dbatch->qty;
$detail.= '<br>'; $detail.= '<br>';
print $detail; print $detail;
@@ -2242,7 +2243,7 @@ else if ($id || $ref)
{ {
print '<tr>'; print '<tr>';
// Qty to ship or shipped // Qty to ship or shipped
print '<td>' . '<input name="qtyl'.$detail_batch->fk_expeditiondet.'_'.$detail_batch->id.'" id="qtyl'.$line_id.'_'.$detail_batch->id.'" type="text" size="4" value="'.$detail_batch->dluo_qty.'">' . '</td>'; print '<td>' . '<input name="qtyl'.$detail_batch->fk_expeditiondet.'_'.$detail_batch->id.'" id="qtyl'.$line_id.'_'.$detail_batch->id.'" type="text" size="4" value="'.$detail_batch->qty.'">' . '</td>';
// Batch number managment // Batch number managment
if ($lines[$i]->entrepot_id == 0) if ($lines[$i]->entrepot_id == 0)
{ {
@@ -2354,12 +2355,12 @@ else if ($id || $ref)
if ($lines[$i]->product_tobatch) if ($lines[$i]->product_tobatch)
{ {
$detail = ''; $detail = '';
foreach ($lines[$i]->detail_batch as $dbatch) foreach ($lines[$i]->detail_batch as $dbatch) // $dbatch is instance of ExpeditionLineBatch
{ {
$detail.= $langs->trans("Batch").': '.$dbatch->batch; $detail.= $langs->trans("Batch").': '.$dbatch->batch;
$detail.= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby,"day"); $detail.= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby,"day");
$detail.= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby,"day"); $detail.= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby,"day");
$detail.= ' - '.$langs->trans("Qty").': '.$dbatch->dluo_qty; $detail.= ' - '.$langs->trans("Qty").': '.$dbatch->qty;
$detail.= '<br>'; $detail.= '<br>';
} }
print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"),$detail); print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"),$detail);

View File

@@ -415,7 +415,7 @@ class Expedition extends CommonObject
{ {
if ($detbatch->entrepot_id) if ($detbatch->entrepot_id)
{ {
$stockLocationQty[$detbatch->entrepot_id] += $detbatch->dluo_qty; $stockLocationQty[$detbatch->entrepot_id] += $detbatch->qty;
} }
} }
// create shipment lines // create shipment lines
@@ -931,7 +931,7 @@ class Expedition extends CommonObject
$this->error=$linebatch->error; $this->error=$linebatch->error;
return -1; return -1;
} }
$linebatch->dluo_qty=$value['q']; $linebatch->qty=$value['q'];
$tab[]=$linebatch; $tab[]=$linebatch;
if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT) if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT)
@@ -940,7 +940,7 @@ class Expedition extends CommonObject
$prod_batch = new Productbatch($this->db); $prod_batch = new Productbatch($this->db);
$prod_batch->fetch($value['id_batch']); $prod_batch->fetch($value['id_batch']);
if ($prod_batch->qty < $linebatch->dluo_qty) if ($prod_batch->qty < $linebatch->qty)
{ {
$langs->load("errors"); $langs->load("errors");
$this->errors[]=$langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $prod_batch->fk_product); $this->errors[]=$langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $prod_batch->fk_product);
@@ -1164,7 +1164,7 @@ class Expedition extends CommonObject
// We use warehouse selected for each line // We use warehouse selected for each line
foreach($lotArray as $lot) foreach($lotArray as $lot)
{ {
$result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->dluo_qty, 0, $langs->trans("ShipmentDeletedInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch); // Price is set to 0, because we don't want to see WAP changed $result=$mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->trans("ShipmentDeletedInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch); // Price is set to 0, because we don't want to see WAP changed
if ($result < 0) if ($result < 0)
{ {
$error++;$this->errors=$this->errors + $mouvS->errors; $error++;$this->errors=$this->errors + $mouvS->errors;
@@ -2572,7 +2572,7 @@ class ExpeditionLigne extends CommonObjectLine
$this->errors[]='ErrorBadParameters'; $this->errors[]='ErrorBadParameters';
$error++; $error++;
} }
$qty = price2num($this->detail_batch[0]->dluo_qty); $qty = price2num($this->detail_batch[0]->qty);
} }
} }
else if (! empty($this->detail_batch)) else if (! empty($this->detail_batch))
@@ -2586,7 +2586,7 @@ class ExpeditionLigne extends CommonObjectLine
$this->errors[]='ErrorBadParameters'; $this->errors[]='ErrorBadParameters';
$error++; $error++;
} }
$qty = price2num($this->detail_batch->dluo_qty); $qty = price2num($this->detail_batch->qty);
} }
// check parameters // check parameters
@@ -2624,7 +2624,7 @@ class ExpeditionLigne extends CommonObjectLine
{ {
if ($expedition_batch_id != $lot->id) if ($expedition_batch_id != $lot->id)
{ {
$remainingQty += $lot->dluo_qty; $remainingQty += $lot->qty;
} }
} }
$qty += $remainingQty; $qty += $remainingQty;
@@ -2652,7 +2652,7 @@ class ExpeditionLigne extends CommonObjectLine
$error++; $error++;
} }
} }
if (! $error && $this->detail_batch->dluo_qty > 0) if (! $error && $this->detail_batch->qty > 0)
{ {
// create lot expedition line // create lot expedition line
if (isset($lot->id)) if (isset($lot->id))
@@ -2662,7 +2662,7 @@ class ExpeditionLigne extends CommonObjectLine
$shipmentLot->eatby = $lot->eatby; $shipmentLot->eatby = $lot->eatby;
$shipmentLot->sellby = $lot->sellby; $shipmentLot->sellby = $lot->sellby;
$shipmentLot->entrepot_id = $this->detail_batch->entrepot_id; $shipmentLot->entrepot_id = $this->detail_batch->entrepot_id;
$shipmentLot->dluo_qty = $this->detail_batch->dluo_qty; $shipmentLot->qty = $this->detail_batch->qty;
$shipmentLot->fk_origin_stock = $batch_id; $shipmentLot->fk_origin_stock = $batch_id;
if ($shipmentLot->create($this->id) < 0) if ($shipmentLot->create($this->id) < 0)
{ {

View File

@@ -34,7 +34,7 @@ class ExpeditionLineBatch extends CommonObject
var $sellby; var $sellby;
var $eatby; var $eatby;
var $batch; var $batch;
var $dluo_qty; var $qty;
var $entrepot_id; var $entrepot_id;
var $fk_origin_stock; var $fk_origin_stock;
var $fk_expeditiondet; var $fk_expeditiondet;
@@ -58,41 +58,41 @@ class ExpeditionLineBatch extends CommonObject
*/ */
function fetchFromStock($id_stockdluo) function fetchFromStock($id_stockdluo)
{ {
$sql = "SELECT"; $sql = "SELECT";
$sql.= " pb.batch,"; $sql.= " pb.batch,";
$sql.= " pl.sellby,"; $sql.= " pl.sellby,";
$sql.= " pl.eatby,"; $sql.= " pl.eatby,";
$sql.= " ps.fk_entrepot"; $sql.= " ps.fk_entrepot";
$sql.= " FROM ".MAIN_DB_PREFIX."product_batch as pb"; $sql.= " FROM ".MAIN_DB_PREFIX."product_batch as pb";
$sql.= " JOIN ".MAIN_DB_PREFIX."product_stock as ps on pb.fk_product_stock=ps.rowid"; $sql.= " JOIN ".MAIN_DB_PREFIX."product_stock as ps on pb.fk_product_stock=ps.rowid";
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."product_lot as pl on pl.batch = pb.batch AND pl.fk_product = ps.fk_product"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."product_lot as pl on pl.batch = pb.batch AND pl.fk_product = ps.fk_product";
$sql.= " WHERE pb.rowid = ".(int) $id_stockdluo; $sql.= " WHERE pb.rowid = ".(int) $id_stockdluo;
dol_syslog(get_class($this)."::fetch", LOG_DEBUG); dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
if ($this->db->num_rows($resql)) if ($this->db->num_rows($resql))
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$this->sellby = $this->db->jdate($obj->sellby); $this->sellby = $this->db->jdate($obj->sellby);
$this->eatby = $this->db->jdate($obj->eatby); $this->eatby = $this->db->jdate($obj->eatby);
$this->batch = $obj->batch; $this->batch = $obj->batch;
$this->entrepot_id= $obj->fk_entrepot; $this->entrepot_id= $obj->fk_entrepot;
$this->fk_origin_stock=(int) $id_stockdluo; $this->fk_origin_stock=(int) $id_stockdluo;
} }
$this->db->free($resql); $this->db->free($resql);
return 1; return 1;
} }
else else
{ {
$this->error="Error ".$this->db->lasterror(); $this->error="Error ".$this->db->lasterror();
return -1; return -1;
} }
} }
/** /**
* Create an expeditiondet_batch DB record link to an expedtiondet record * Create an expeditiondet_batch DB record link to an expedtiondet record
@@ -118,7 +118,7 @@ class ExpeditionLineBatch extends CommonObject
$sql.= " ".(! isset($this->sellby) || dol_strlen($this->sellby)==0?'NULL':("'".$this->db->idate($this->sellby))."'").","; $sql.= " ".(! isset($this->sellby) || dol_strlen($this->sellby)==0?'NULL':("'".$this->db->idate($this->sellby))."'").",";
$sql.= " ".(! isset($this->eatby) || dol_strlen($this->eatby)==0?'NULL':("'".$this->db->idate($this->eatby))."'").","; $sql.= " ".(! isset($this->eatby) || dol_strlen($this->eatby)==0?'NULL':("'".$this->db->idate($this->eatby))."'").",";
$sql.= " ".(! isset($this->batch)?'NULL':("'".$this->db->escape($this->batch)."'")).","; $sql.= " ".(! isset($this->batch)?'NULL':("'".$this->db->escape($this->batch)."'")).",";
$sql.= " ".(! isset($this->dluo_qty)?'NULL':$this->dluo_qty).","; $sql.= " ".(! isset($this->qty)?'NULL':$this->qty).",";
$sql.= " ".(! isset($this->fk_origin_stock)?'NULL':$this->fk_origin_stock); $sql.= " ".(! isset($this->fk_origin_stock)?'NULL':$this->fk_origin_stock);
$sql.= ")"; $sql.= ")";
@@ -218,7 +218,7 @@ class ExpeditionLineBatch extends CommonObject
$tmp->id = $obj->rowid; $tmp->id = $obj->rowid;
$tmp->fk_origin_stock = $obj->fk_origin_stock; $tmp->fk_origin_stock = $obj->fk_origin_stock;
$tmp->fk_expeditiondet = $obj->fk_expeditiondet; $tmp->fk_expeditiondet = $obj->fk_expeditiondet;
$tmp->dluo_qty = $obj->qty; $tmp->qty = $obj->qty;
$ret[]=$tmp; $ret[]=$tmp;
$i++; $i++;