mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-13 11:15:21 +01:00
Allow warehouse transfer for batched product
This commit is contained in:
@@ -42,6 +42,7 @@ class Productbatch extends CommonObject
|
||||
var $batch='';
|
||||
var $qty;
|
||||
var $import_key;
|
||||
public $warehouseid;
|
||||
|
||||
|
||||
|
||||
@@ -155,10 +156,11 @@ class Productbatch extends CommonObject
|
||||
$sql.= " t.eatby,";
|
||||
$sql.= " t.batch,";
|
||||
$sql.= " t.qty,";
|
||||
$sql.= " t.import_key";
|
||||
|
||||
$sql.= " t.import_key,";
|
||||
$sql.= " w.fk_entrepot";
|
||||
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.self::$_table_element." as t";
|
||||
$sql.= " INNER JOIN ".MAIN_DB_PREFIX."product_stock w on t.fk_product_stock=w.rowid";
|
||||
$sql.= " WHERE t.rowid = ".$id;
|
||||
|
||||
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
|
||||
@@ -177,6 +179,7 @@ class Productbatch extends CommonObject
|
||||
$this->batch = $obj->batch;
|
||||
$this->qty = $obj->qty;
|
||||
$this->import_key = $obj->import_key;
|
||||
$this->warehouseid= $obj->fk_entrepot;
|
||||
}
|
||||
$this->db->free($resql);
|
||||
|
||||
|
||||
@@ -170,13 +170,13 @@ if ($action == "correct_stock" && ! $cancel)
|
||||
// Transfer stock from a warehouse to another warehouse
|
||||
if ($action == "transfert_stock" && ! $cancel)
|
||||
{
|
||||
if (! (GETPOST("id_entrepot_source") > 0) || ! (GETPOST("id_entrepot_destination") > 0))
|
||||
if (! (GETPOST("id_entrepot_source",'int') > 0) || ! (GETPOST("id_entrepot_destination",'int') > 0))
|
||||
{
|
||||
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Warehouse")), 'errors');
|
||||
$error++;
|
||||
$action='transfert';
|
||||
}
|
||||
if (! GETPOST("nbpiece"))
|
||||
if (! GETPOST("nbpiece",'int'))
|
||||
{
|
||||
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("NumberOfUnit")), 'errors');
|
||||
$error++;
|
||||
@@ -185,9 +185,9 @@ if ($action == "transfert_stock" && ! $cancel)
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
if (GETPOST("id_entrepot_source") <> GETPOST("id_entrepot_destination"))
|
||||
if (GETPOST("id_entrepot_source",'int') <> GETPOST("id_entrepot_destination",'int'))
|
||||
{
|
||||
if (is_numeric(GETPOST("nbpiece")) && $id)
|
||||
if (GETPOST("nbpiece",'int') && $id)
|
||||
{
|
||||
$product = new Product($db);
|
||||
$result=$product->fetch($id);
|
||||
@@ -201,28 +201,59 @@ if ($action == "transfert_stock" && ! $cancel)
|
||||
if (isset($product->stock_warehouse[GETPOST("id_entrepot_source")]->pmp)) $pricesrc=$product->stock_warehouse[GETPOST("id_entrepot_source")]->pmp;
|
||||
$pricedest=$pricesrc;
|
||||
|
||||
//print 'price src='.$pricesrc.', price dest='.$pricedest;exit;
|
||||
$pdluoid=GETPOST('pdluoid','int');
|
||||
|
||||
// Remove stock
|
||||
$result1=$product->correct_stock(
|
||||
$user,
|
||||
GETPOST("id_entrepot_source"),
|
||||
GETPOST("nbpiece"),
|
||||
1,
|
||||
GETPOST("label"),
|
||||
$pricesrc
|
||||
);
|
||||
if ($pdluoid>0)
|
||||
{
|
||||
$pdluo = new Productbatch($db);
|
||||
$result=$pdluo->fetch($pdluoid);
|
||||
|
||||
// Add stock
|
||||
$result2=$product->correct_stock(
|
||||
$user,
|
||||
GETPOST("id_entrepot_destination"),
|
||||
GETPOST("nbpiece"),
|
||||
0,
|
||||
GETPOST("label"),
|
||||
$pricedest
|
||||
);
|
||||
if ($result>0 && $pdluo->id)
|
||||
{
|
||||
// Remove stock
|
||||
$result1=$product->correct_stock_batch(
|
||||
$user,
|
||||
$pdluo->warehouseid,
|
||||
GETPOST("nbpiece",'int'),
|
||||
1,
|
||||
GETPOST("label",'san_alpha'),
|
||||
$pricesrc,
|
||||
$pdluo->eatby,$pdluo->sellby,$pdluo->batch
|
||||
);
|
||||
// Add stock
|
||||
$result2=$product->correct_stock_batch(
|
||||
$user,
|
||||
GETPOST("id_entrepot_destination",'int'),
|
||||
GETPOST("nbpiece",'int'),
|
||||
0,
|
||||
GETPOST("label",'san_alpha'),
|
||||
$pricedest,
|
||||
$pdluo->eatby,$pdluo->sellby,$pdluo->batch
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remove stock
|
||||
$result1=$product->correct_stock(
|
||||
$user,
|
||||
GETPOST("id_entrepot_source"),
|
||||
GETPOST("nbpiece"),
|
||||
1,
|
||||
GETPOST("label"),
|
||||
$pricesrc
|
||||
);
|
||||
|
||||
// Add stock
|
||||
$result2=$product->correct_stock(
|
||||
$user,
|
||||
GETPOST("id_entrepot_destination"),
|
||||
GETPOST("nbpiece"),
|
||||
0,
|
||||
GETPOST("label"),
|
||||
$pricedest
|
||||
);
|
||||
}
|
||||
if ($result1 >= 0 && $result2 >= 0)
|
||||
{
|
||||
$db->commit();
|
||||
@@ -239,6 +270,7 @@ if ($action == "transfert_stock" && ! $cancel)
|
||||
}
|
||||
}
|
||||
|
||||
// Update batch information
|
||||
if ($action == 'updateline' && GETPOST('save') == $langs->trans('Save'))
|
||||
{
|
||||
|
||||
@@ -540,15 +572,43 @@ if ($id > 0 || $ref)
|
||||
*/
|
||||
if ($action == "transfert")
|
||||
{
|
||||
$pdluoid=GETPOST('pdluoid','int');
|
||||
|
||||
if ($pdluoid > 0)
|
||||
{
|
||||
$pdluo = new Productbatch($db);
|
||||
$result=$pdluo->fetch($pdluoid);
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$pdluoid=$pdluo->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
}
|
||||
|
||||
print_titre($langs->trans("StockTransfer"));
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$product->id.'" method="post">'."\n";
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="transfert_stock">';
|
||||
if ($pdluoid)
|
||||
{
|
||||
print '<input type="hidden" name="pdluoid" value="'.$pdluoid.'">';
|
||||
}
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
print '<tr>';
|
||||
print '<td width="20%" class="fieldrequired">'.$langs->trans("WarehouseSource").'</td><td width="20%">';
|
||||
print $formproduct->selectWarehouses(($_GET["dwid"]?$_GET["dwid"]:GETPOST('id_entrepot_source')),'id_entrepot_source','',1);
|
||||
if ($pdluoid)
|
||||
{
|
||||
print $formproduct->selectWarehouses($pdluo->warehouseid,'id_entrepot_source','',1,1);
|
||||
}
|
||||
else
|
||||
{
|
||||
print $formproduct->selectWarehouses(($_GET["dwid"]?$_GET["dwid"]:GETPOST('id_entrepot_source')),'id_entrepot_source','',1);
|
||||
}
|
||||
print '</td>';
|
||||
print '<td width="20%" class="fieldrequired">'.$langs->trans("WarehouseTarget").'</td><td width="20%">';
|
||||
print $formproduct->selectWarehouses(GETPOST('id_entrepot_destination'),'id_entrepot_destination','',1);
|
||||
@@ -630,7 +690,7 @@ if (empty($action) && $product->id)
|
||||
|
||||
|
||||
/*
|
||||
* Contenu des stocks
|
||||
* Stock detail
|
||||
*/
|
||||
print '<br><table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre"><td width="40%" colspan="4">'.$langs->trans("Warehouse").'</td>';
|
||||
@@ -720,6 +780,7 @@ if ($resql)
|
||||
else
|
||||
{
|
||||
print "\n".'<tr><td align="right">';
|
||||
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$product->id.'&action=transfert&pdluoid='.$pdluo->id.'">'.$langs->trans("StockMovement").'</a>';
|
||||
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=editline&lineid='.$pdluo->id.'#'.$pdluo->id.'">';
|
||||
print img_edit().'</a></td>';
|
||||
print '<td align="right">'.$pdluo->batch.'</td>';
|
||||
|
||||
Reference in New Issue
Block a user