Allow warehouse transfer for batched product

This commit is contained in:
KreizIT 2015-01-06 13:23:51 +01:00
parent f7dd4a1357
commit ce3a60b2a3
2 changed files with 91 additions and 27 deletions

View File

@ -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
$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
$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);

View File

@ -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)
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,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; 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');
// Remove stock if ($pdluoid>0)
$result1=$product->correct_stock( {
$user, $pdluo = new Productbatch($db);
GETPOST("id_entrepot_source"), $result=$pdluo->fetch($pdluoid);
GETPOST("nbpiece"),
1,
GETPOST("label"),
$pricesrc
);
// Add stock if ($result>0 && $pdluo->id)
$result2=$product->correct_stock( {
$user, // Remove stock
GETPOST("id_entrepot_destination"), $result1=$product->correct_stock_batch(
GETPOST("nbpiece"), $user,
0, $pdluo->warehouseid,
GETPOST("label"), GETPOST("nbpiece",'int'),
$pricedest 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) if ($result1 >= 0 && $result2 >= 0)
{ {
$db->commit(); $db->commit();
@ -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)
*/ */
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%">';
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>';
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)
/* /*
* 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)
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>';