Skip to content
Snippets Groups Projects
Commit ce3a60b2 authored by Cédric Gross's avatar Cédric Gross
Browse files

Allow warehouse transfer for batched product

parent f7dd4a13
No related branches found
No related tags found
No related merge requests found
...@@ -42,6 +42,7 @@ class Productbatch extends CommonObject ...@@ -42,6 +42,7 @@ class Productbatch extends CommonObject
var $batch=''; var $batch='';
var $qty; var $qty;
var $import_key; var $import_key;
public $warehouseid;
...@@ -155,10 +156,11 @@ class Productbatch extends CommonObject ...@@ -155,10 +156,11 @@ class Productbatch extends CommonObject
$sql.= " t.eatby,"; $sql.= " t.eatby,";
$sql.= " t.batch,"; $sql.= " t.batch,";
$sql.= " t.qty,"; $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.= " 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; $sql.= " WHERE t.rowid = ".$id;
dol_syslog(get_class($this)."::fetch", LOG_DEBUG); dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
...@@ -177,6 +179,7 @@ class Productbatch extends CommonObject ...@@ -177,6 +179,7 @@ class Productbatch extends CommonObject
$this->batch = $obj->batch; $this->batch = $obj->batch;
$this->qty = $obj->qty; $this->qty = $obj->qty;
$this->import_key = $obj->import_key; $this->import_key = $obj->import_key;
$this->warehouseid= $obj->fk_entrepot;
} }
$this->db->free($resql); $this->db->free($resql);
......
...@@ -170,13 +170,13 @@ if ($action == "correct_stock" && ! $cancel) ...@@ -170,13 +170,13 @@ if ($action == "correct_stock" && ! $cancel)
// Transfer stock from a warehouse to another warehouse // Transfer stock from a warehouse to another warehouse
if ($action == "transfert_stock" && ! $cancel) 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'); setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Warehouse")), 'errors');
$error++; $error++;
$action='transfert'; $action='transfert';
} }
if (! GETPOST("nbpiece")) if (! GETPOST("nbpiece",'int'))
{ {
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("NumberOfUnit")), 'errors'); setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("NumberOfUnit")), 'errors');
$error++; $error++;
...@@ -185,9 +185,9 @@ if ($action == "transfert_stock" && ! $cancel) ...@@ -185,9 +185,9 @@ if ($action == "transfert_stock" && ! $cancel)
if (! $error) 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); $product = new Product($db);
$result=$product->fetch($id); $result=$product->fetch($id);
...@@ -201,8 +201,39 @@ if ($action == "transfert_stock" && ! $cancel) ...@@ -201,8 +201,39 @@ if ($action == "transfert_stock" && ! $cancel)
if (isset($product->stock_warehouse[GETPOST("id_entrepot_source")]->pmp)) $pricesrc=$product->stock_warehouse[GETPOST("id_entrepot_source")]->pmp; if (isset($product->stock_warehouse[GETPOST("id_entrepot_source")]->pmp)) $pricesrc=$product->stock_warehouse[GETPOST("id_entrepot_source")]->pmp;
$pricedest=$pricesrc; $pricedest=$pricesrc;
//print 'price src='.$pricesrc.', price dest='.$pricedest;exit; $pdluoid=GETPOST('pdluoid','int');
if ($pdluoid>0)
{
$pdluo = new Productbatch($db);
$result=$pdluo->fetch($pdluoid);
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 // Remove stock
$result1=$product->correct_stock( $result1=$product->correct_stock(
$user, $user,
...@@ -222,7 +253,7 @@ if ($action == "transfert_stock" && ! $cancel) ...@@ -222,7 +253,7 @@ if ($action == "transfert_stock" && ! $cancel)
GETPOST("label"), GETPOST("label"),
$pricedest $pricedest
); );
}
if ($result1 >= 0 && $result2 >= 0) if ($result1 >= 0 && $result2 >= 0)
{ {
$db->commit(); $db->commit();
...@@ -239,6 +270,7 @@ if ($action == "transfert_stock" && ! $cancel) ...@@ -239,6 +270,7 @@ if ($action == "transfert_stock" && ! $cancel)
} }
} }
// Update batch information
if ($action == 'updateline' && GETPOST('save') == $langs->trans('Save')) if ($action == 'updateline' && GETPOST('save') == $langs->trans('Save'))
{ {
...@@ -540,15 +572,43 @@ if ($id > 0 || $ref) ...@@ -540,15 +572,43 @@ if ($id > 0 || $ref)
*/ */
if ($action == "transfert") 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_titre($langs->trans("StockTransfer"));
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$product->id.'" method="post">'."\n"; 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="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="transfert_stock">'; 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 '<table class="border" width="100%">';
print '<tr>'; print '<tr>';
print '<td width="20%" class="fieldrequired">'.$langs->trans("WarehouseSource").'</td><td width="20%">'; print '<td width="20%" class="fieldrequired">'.$langs->trans("WarehouseSource").'</td><td width="20%">';
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 $formproduct->selectWarehouses(($_GET["dwid"]?$_GET["dwid"]:GETPOST('id_entrepot_source')),'id_entrepot_source','',1);
}
print '</td>'; print '</td>';
print '<td width="20%" class="fieldrequired">'.$langs->trans("WarehouseTarget").'</td><td width="20%">'; print '<td width="20%" class="fieldrequired">'.$langs->trans("WarehouseTarget").'</td><td width="20%">';
print $formproduct->selectWarehouses(GETPOST('id_entrepot_destination'),'id_entrepot_destination','',1); print $formproduct->selectWarehouses(GETPOST('id_entrepot_destination'),'id_entrepot_destination','',1);
...@@ -630,7 +690,7 @@ if (empty($action) && $product->id) ...@@ -630,7 +690,7 @@ if (empty($action) && $product->id)
/* /*
* Contenu des stocks * Stock detail
*/ */
print '<br><table class="noborder" width="100%">'; print '<br><table class="noborder" width="100%">';
print '<tr class="liste_titre"><td width="40%" colspan="4">'.$langs->trans("Warehouse").'</td>'; print '<tr class="liste_titre"><td width="40%" colspan="4">'.$langs->trans("Warehouse").'</td>';
...@@ -720,6 +780,7 @@ if ($resql) ...@@ -720,6 +780,7 @@ if ($resql)
else else
{ {
print "\n".'<tr><td align="right">'; print "\n".'<tr><td align="right">';
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$product->id.'&amp;action=transfert&amp;pdluoid='.$pdluo->id.'">'.$langs->trans("StockMovement").'</a>';
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&amp;action=editline&amp;lineid='.$pdluo->id.'#'.$pdluo->id.'">'; print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&amp;action=editline&amp;lineid='.$pdluo->id.'#'.$pdluo->id.'">';
print img_edit().'</a></td>'; print img_edit().'</a></td>';
print '<td align="right">'.$pdluo->batch.'</td>'; print '<td align="right">'.$pdluo->batch.'</td>';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment