Skip to content

Commit

Permalink
Only show show lot from same src warehouse.
Browse files Browse the repository at this point in the history
When shipping from multiple warehouse, only allow lot from same src
warehouse. (expeditiondet_batch is on to many from expeditiondet).
  • Loading branch information
fappels committed Oct 30, 2017
1 parent a9ceb46 commit 08f931b
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 18 deletions.
23 changes: 17 additions & 6 deletions htdocs/expedition/card.php
Expand Up @@ -684,16 +684,21 @@
$batch="batchl".$detail_batch->fk_expeditiondet."_".$detail_batch->fk_origin_stock;
$qty = "qtyl".$detail_batch->fk_expeditiondet.'_'.$detail_batch->id;
$batch_id = GETPOST($batch,'int');
if (! empty($batch_id) && $batch_id != $detail_batch->fk_origin_stock)
$batch_qty = GETPOST($qty, 'int');
if (! empty($batch_id) && ($batch_id != $detail_batch->fk_origin_stock || $batch_qty != $detail_batch->dluo_qty))
{
if ($lotStock->fetch($batch_id) > 0)
if ($lotStock->fetch($batch_id) > 0 && $line->fetch($detail_batch->fk_expeditiondet) > 0)
{
$line->id = $detail_batch->fk_expeditiondet;
if ($lines[$i]->entrepot_id != 0)
{
// allow update line entrepot_id if not multi warehouse shipping
$line->entrepot_id = $lotStock->warehouseid;
}
$line->detail_batch->fk_origin_stock = $batch_id;
$line->detail_batch->batch = $lotStock->batch;
$line->detail_batch->id = $detail_batch->id;
$line->entrepot_id = $lotStock->warehouseid;
$line->qty = GETPOST($qty, 'int');
$line->detail_batch->entrepot_id = $lotStock->warehouseid;
$line->detail_batch->dluo_qty = $batch_qty;
if ($line->update($user) < 0) {
setEventMessages($line->error, $line->errors, 'errors');
$error++;
Expand Down Expand Up @@ -2157,13 +2162,19 @@
print '<td colspan="'.$editColspan.'"><table>';
if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0)
{
$line = new ExpeditionLigne($db);
foreach ($lines[$i]->detail_batch as $detail_batch)
{
print '<tr>';
// 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>';
// Batch number managment
print '<td>' . $formproduct->selectLotStock($detail_batch->fk_origin_stock, 'batchl'.$detail_batch->fk_expeditiondet.'_'.$detail_batch->fk_origin_stock, '', 1, 0, $lines[$i]->fk_product). '</td>';
if ($lines[$i]->entrepot_id == 0)
{
// only show lot numbers from src warehouse when shipping from multiple warehouses
$line->fetch($detail_batch->fk_expeditiondet);
}
print '<td>' . $formproduct->selectLotStock($detail_batch->fk_origin_stock, 'batchl'.$detail_batch->fk_expeditiondet.'_'.$detail_batch->fk_origin_stock, '', 1, 0, $lines[$i]->fk_product, $line->entrepot_id). '</td>';
print '</tr>';
}
}
Expand Down
76 changes: 64 additions & 12 deletions htdocs/expedition/class/expedition.class.php
Expand Up @@ -2278,6 +2278,40 @@ function __construct($db)
$this->db=$db;
}

/**
* Load line expedition
*
* @param int $rowid Id line order
* @return int <0 if KO, >0 if OK
*/
function fetch($rowid)
{
$sql = 'SELECT ed.rowid, ed.fk_expedition, ed.fk_entrepot, ed.fk_origin_line, ed.qty, ed.rang';
$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as ed';
$sql.= ' WHERE ed.rowid = '.$rowid;
$result = $this->db->query($sql);
if ($result)
{
$objp = $this->db->fetch_object($result);
$this->id = $objp->rowid;
$this->fk_expedition = $objp->fk_expedition;
$this->entrepot_id = $objp->fk_entrepot;
$this->fk_origin_line = $objp->fk_origin_line;
$this->qty = $objp->qty;
$this->rang = $objp->rang;

$this->db->free($result);

return 1;
}
else
{
$this->errors[] = $this->db->lasterror();
$this->error = $this->db->lasterror();
return -1;
}
}

/**
* Insert line into database
*
Expand Down Expand Up @@ -2451,14 +2485,7 @@ function update($user = null, $notrigger = 0)

dol_syslog(get_class($this)."::update id=$this->id, entrepot_id=$this->entrepot_id, product_id=$this->fk_product, qty=$this->qty");

// check parameters
if (! isset($this->id) || ! isset($this->entrepot_id))
{
dol_syslog(get_class($this).'::update missing line id and/or warehouse id', LOG_ERR);
$this->errors[]='ErrorMandatoryParametersNotProvided';
$error++;
return -1;
}


$this->db->begin();

Expand All @@ -2482,13 +2509,36 @@ function update($user = null, $notrigger = 0)
$batch = $this->detail_batch[0]->batch;
$batch_id = $this->detail_batch[0]->fk_origin_stock;
$expedition_batch_id = $this->detail_batch[0]->id;
if ($this->entrepot_id != $this->detail_batch[0]->entrepot_id)
{
dol_syslog(get_class($this).'::update only possible for batch of same warehouse', LOG_ERR);
$this->errors[]='ErrorBadParameters';
$error++;
}
$qty = price2num($this->detail_batch[0]->dluo_qty);
}
}
else
else if (! empty($this->detail_batch))
{
$batch = $this->detail_batch->batch;
$batch_id = $this->detail_batch->fk_origin_stock;
$expedition_batch_id = $this->detail_batch->id;
if ($this->entrepot_id != $this->detail_batch->entrepot_id)
{
dol_syslog(get_class($this).'::update only possible for batch of same warehouse', LOG_ERR);
$this->errors[]='ErrorBadParameters';
$error++;
}
$qty = price2num($this->detail_batch->dluo_qty);
}

// check parameters
if (! isset($this->id) || ! isset($this->entrepot_id))
{
dol_syslog(get_class($this).'::update missing line id and/or warehouse id', LOG_ERR);
$this->errors[]='ErrorMandatoryParametersNotProvided';
$error++;
return -1;
}

// update lot
Expand All @@ -2512,13 +2562,15 @@ function update($user = null, $notrigger = 0)
}
else
{
// caculate new total line qty
foreach ($lotArray as $lot)
{
if ($expedition_batch_id != $lot->id)
{
$remainingQty += $lot->dluo_qty;
}
}
$qty += $remainingQty;

//fetch lot details

Expand Down Expand Up @@ -2550,8 +2602,8 @@ function update($user = null, $notrigger = 0)
$shipmentLot->batch = $lot->batch;
$shipmentLot->eatby = $lot->eatby;
$shipmentLot->sellby = $lot->sellby;
$shipmentLot->entrepot_id = $this->entrepot_id;
$shipmentLot->dluo_qty = $qty;
$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)
{
Expand All @@ -2568,7 +2620,7 @@ function update($user = null, $notrigger = 0)
// update line
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
$sql.= " fk_entrepot = ".$this->entrepot_id;
$sql.= " , qty = ".($qty + $remainingQty);
$sql.= " , qty = ".$qty;
$sql.= " WHERE rowid = ".$this->id;

if (!$this->db->query($sql))
Expand Down

0 comments on commit 08f931b

Please sign in to comment.