Fix move the code into mouvementstock class
This commit is contained in:
parent
c62a69ccc8
commit
67392fbac5
@ -240,7 +240,7 @@ class MouvementStock extends CommonObject
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO Check qty is ok for stock move.
|
||||
if (! empty($conf->productbatch->enabled) && $product->hasbatch() && ! $skip_batch)
|
||||
{
|
||||
@ -250,6 +250,17 @@ class MouvementStock extends CommonObject
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (empty($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER) && in_array($type, array(1, 2)))
|
||||
{
|
||||
if (empty($product->stock_warehouse[$entrepot_id]->real) || $product->stock_warehouse[$entrepot_id]->real < abs($qty))
|
||||
{
|
||||
$this->error = $langs->trans('qtyToTranferIsNotEnough');
|
||||
$this->errors[] = $langs->trans('qtyToTranferIsNotEnough');
|
||||
$this->db->rollback();
|
||||
return -8;
|
||||
}
|
||||
}
|
||||
|
||||
// Define if we must make the stock change (If product type is a service or if stock is used also for services)
|
||||
$movestock=0;
|
||||
|
||||
@ -231,117 +231,98 @@ if ($action == "transfert_stock" && ! $cancel)
|
||||
$pricesrc=0;
|
||||
if (isset($object->pmp)) $pricesrc=$object->pmp;
|
||||
$pricedest=$pricesrc;
|
||||
|
||||
$do_tranfer = true;
|
||||
if (empty($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER))
|
||||
{
|
||||
$fk_warehouse_source = GETPOST("id_entrepot");
|
||||
$nb_unit = GETPOST("nbpiece",'int');
|
||||
|
||||
if (empty($object->stock_warehouse[$fk_warehouse_source]->real) || $object->stock_warehouse[$fk_warehouse_source]->real < $nb_unit)
|
||||
{
|
||||
$do_tranfer = false;
|
||||
$result1 = $result2 = -1;
|
||||
$action='';
|
||||
$object->error = $langs->trans('qtyToTranferIsNotEnough');
|
||||
}
|
||||
}
|
||||
|
||||
if ($do_tranfer)
|
||||
if ($object->hasbatch())
|
||||
{
|
||||
$pdluo = new Productbatch($db);
|
||||
|
||||
if ($object->hasbatch())
|
||||
if ($pdluoid > 0)
|
||||
{
|
||||
$pdluo = new Productbatch($db);
|
||||
|
||||
if ($pdluoid > 0)
|
||||
$result=$pdluo->fetch($pdluoid);
|
||||
if ($result)
|
||||
{
|
||||
$result=$pdluo->fetch($pdluoid);
|
||||
if ($result)
|
||||
{
|
||||
$srcwarehouseid=$pdluo->warehouseid;
|
||||
$batch=$pdluo->batch;
|
||||
$eatby=$pdluo->eatby;
|
||||
$sellby=$pdluo->sellby;
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessages($pdluo->error, $pdluo->errors, 'errors');
|
||||
$error++;
|
||||
}
|
||||
$srcwarehouseid=$pdluo->warehouseid;
|
||||
$batch=$pdluo->batch;
|
||||
$eatby=$pdluo->eatby;
|
||||
$sellby=$pdluo->sellby;
|
||||
}
|
||||
else
|
||||
{
|
||||
$srcwarehouseid=GETPOST('id_entrepot','int');
|
||||
$batch=GETPOST('batch_number');
|
||||
$eatby=$d_eatby;
|
||||
$sellby=$d_sellby;
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
// Remove stock
|
||||
$result1=$object->correct_stock_batch(
|
||||
$user,
|
||||
$srcwarehouseid,
|
||||
GETPOST("nbpiece",'int'),
|
||||
1,
|
||||
GETPOST("label",'san_alpha'),
|
||||
$pricesrc,
|
||||
$eatby,$sellby,$batch,
|
||||
GETPOST('inventorycode')
|
||||
);
|
||||
if ($result1 < 0) $error++;
|
||||
}
|
||||
if (! $error)
|
||||
{
|
||||
// Add stock
|
||||
$result2=$object->correct_stock_batch(
|
||||
$user,
|
||||
GETPOST("id_entrepot_destination",'int'),
|
||||
GETPOST("nbpiece",'int'),
|
||||
0,
|
||||
GETPOST("label",'san_alpha'),
|
||||
$pricedest,
|
||||
$eatby,$sellby,$batch,
|
||||
GETPOST('inventorycode')
|
||||
);
|
||||
if ($result2 < 0) $error++;
|
||||
setEventMessages($pdluo->error, $pdluo->errors, 'errors');
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! $error)
|
||||
{
|
||||
// Remove stock
|
||||
$result1=$object->correct_stock(
|
||||
$user,
|
||||
GETPOST("id_entrepot"),
|
||||
GETPOST("nbpiece"),
|
||||
1,
|
||||
GETPOST("label"),
|
||||
$pricesrc,
|
||||
GETPOST('inventorycode')
|
||||
);
|
||||
if ($result1 < 0) $error++;
|
||||
}
|
||||
if (! $error)
|
||||
{
|
||||
// Add stock
|
||||
$result2=$object->correct_stock(
|
||||
$user,
|
||||
GETPOST("id_entrepot_destination"),
|
||||
GETPOST("nbpiece"),
|
||||
0,
|
||||
GETPOST("label"),
|
||||
$pricedest,
|
||||
GETPOST('inventorycode')
|
||||
);
|
||||
if ($result2 < 0) $error++;
|
||||
}
|
||||
$srcwarehouseid=GETPOST('id_entrepot','int');
|
||||
$batch=GETPOST('batch_number');
|
||||
$eatby=$d_eatby;
|
||||
$sellby=$d_sellby;
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
// Remove stock
|
||||
$result1=$object->correct_stock_batch(
|
||||
$user,
|
||||
$srcwarehouseid,
|
||||
GETPOST("nbpiece",'int'),
|
||||
1,
|
||||
GETPOST("label",'san_alpha'),
|
||||
$pricesrc,
|
||||
$eatby,$sellby,$batch,
|
||||
GETPOST('inventorycode')
|
||||
);
|
||||
if ($result1 < 0) $error++;
|
||||
}
|
||||
if (! $error)
|
||||
{
|
||||
// Add stock
|
||||
$result2=$object->correct_stock_batch(
|
||||
$user,
|
||||
GETPOST("id_entrepot_destination",'int'),
|
||||
GETPOST("nbpiece",'int'),
|
||||
0,
|
||||
GETPOST("label",'san_alpha'),
|
||||
$pricedest,
|
||||
$eatby,$sellby,$batch,
|
||||
GETPOST('inventorycode')
|
||||
);
|
||||
if ($result2 < 0) $error++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! $error)
|
||||
{
|
||||
// Remove stock
|
||||
$result1=$object->correct_stock(
|
||||
$user,
|
||||
GETPOST("id_entrepot"),
|
||||
GETPOST("nbpiece"),
|
||||
1,
|
||||
GETPOST("label"),
|
||||
$pricesrc,
|
||||
GETPOST('inventorycode')
|
||||
);
|
||||
if ($result1 < 0) $error++;
|
||||
}
|
||||
if (! $error)
|
||||
{
|
||||
// Add stock
|
||||
$result2=$object->correct_stock(
|
||||
$user,
|
||||
GETPOST("id_entrepot_destination"),
|
||||
GETPOST("nbpiece"),
|
||||
0,
|
||||
GETPOST("label"),
|
||||
$pricedest,
|
||||
GETPOST('inventorycode')
|
||||
);
|
||||
if ($result2 < 0) $error++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (! $error && $result1 >= 0 && $result2 >= 0)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user