This commit is contained in:
phf 2016-06-04 18:23:22 +02:00
parent 1552e7f41f
commit 3cbbdf5e20
4 changed files with 94 additions and 49 deletions

View File

@ -49,6 +49,10 @@ if($action)
{ {
$res = dolibarr_set_const($db, "STOCK_USERSTOCK_AUTOCREATE", GETPOST('STOCK_USERSTOCK_AUTOCREATE','alpha'),'chaine',0,'',$conf->entity); $res = dolibarr_set_const($db, "STOCK_USERSTOCK_AUTOCREATE", GETPOST('STOCK_USERSTOCK_AUTOCREATE','alpha'),'chaine',0,'',$conf->entity);
} }
if ($action == 'STOCK_ALLOW_NEGATIVE_TRANSFER')
{
$res = dolibarr_set_const($db, "STOCK_ALLOW_NEGATIVE_TRANSFER", GETPOST('STOCK_ALLOW_NEGATIVE_TRANSFER','alpha'),'chaine',0,'',$conf->entity);
}
// Mode of stock decrease // Mode of stock decrease
if ($action == 'STOCK_CALCULATE_ON_BILL' if ($action == 'STOCK_CALCULATE_ON_BILL'
|| $action == 'STOCK_CALCULATE_ON_VALIDATE_ORDER' || $action == 'STOCK_CALCULATE_ON_VALIDATE_ORDER'
@ -367,6 +371,22 @@ print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">'
print '</form>'; print '</form>';
print "</td>\n"; print "</td>\n";
print "</tr>\n"; print "</tr>\n";
$var=!$var;
print "<tr ".$bc[$var].">";
print '<td width="60%">'.$langs->trans("WarehouseAllowNegativeTransfer").'</td>';
print '<td width="160" align="right">';
print "<form method=\"post\" action=\"stock.php\">";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print "<input type=\"hidden\" name=\"action\" value=\"STOCK_ALLOW_NEGATIVE_TRANSFER\">";
print $form->selectyesno("STOCK_ALLOW_NEGATIVE_TRANSFER",$conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER,1);
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
print '</form>';
print "</td>\n";
print "</tr>\n";
print '<br>'; print '<br>';
print '</table>'; print '</table>';
print '<br>'; print '<br>';

View File

@ -70,7 +70,9 @@ class modStock extends DolibarrModules
$this->langfiles = array("stocks"); $this->langfiles = array("stocks");
// Constants // Constants
$this->const = array(); $this->const = array(
0=>array('STOCK_ALLOW_NEGATIVE_TRANSFER','chaine','1','',1)
);
// Boxes // Boxes
$this->boxes = array(); $this->boxes = array();

View File

@ -123,3 +123,5 @@ StockMustBeEnoughForInvoice=Stock level must be enough to add product/service in
StockMustBeEnoughForOrder=Stock level must be enough to add product/service into order StockMustBeEnoughForOrder=Stock level must be enough to add product/service into order
StockMustBeEnoughForShipment= Stock level must be enough to add product/service into shipment StockMustBeEnoughForShipment= Stock level must be enough to add product/service into shipment
WarehouseMustBeSelectedAtFirstStepWhenProductBatchModuleOn=Source warehouse must be defined here when batch module is on. It will be used to list wich lot/serial is available for product that required lot/serial data for movement. If you want to send products from different warehouses, just make the shipment into several steps. WarehouseMustBeSelectedAtFirstStepWhenProductBatchModuleOn=Source warehouse must be defined here when batch module is on. It will be used to list wich lot/serial is available for product that required lot/serial data for movement. If you want to send products from different warehouses, just make the shipment into several steps.
WarehouseAllowNegativeTransfer=Allow transfer even without stock
qtyToTranferIsNotEnough=You don't have enough stock from your source warehouse

View File

@ -204,59 +204,80 @@ if ($action == "transfert_stock" && ! $cancel)
//print 'price src='.$pricesrc.', price dest='.$pricedest;exit; //print 'price src='.$pricesrc.', price dest='.$pricedest;exit;
$pdluoid=GETPOST('pdluoid','int'); $do_tranfer = true;
if ($pdluoid>0) if (empty($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER))
{ {
$pdluo = new Productbatch($db); $fk_warehouse_source = GETPOST("id_entrepot_source");
$result=$pdluo->fetch($pdluoid); $nb_unit = GETPOST("nbpiece",'int');
if ($result>0 && $pdluo->id) if (empty($product->stock_warehouse[$fk_warehouse_source]->real) || $product->stock_warehouse[$fk_warehouse_source]->real < $nb_unit)
{ {
// Remove stock $do_tranfer = false;
$result1=$product->correct_stock_batch( $result1 = $result2 = -1;
$user, $action='';
$pdluo->warehouseid, $product->error = $langs->trans('qtyToTranferIsNotEnough');
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
if ($do_tranfer)
{ {
// Remove stock $pdluoid=GETPOST('pdluoid','int');
$result1=$product->correct_stock(
$user,
GETPOST("id_entrepot_source"),
GETPOST("nbpiece"),
1,
GETPOST("label"),
$pricesrc
);
// Add stock if ($pdluoid>0)
$result2=$product->correct_stock( {
$user, $pdluo = new Productbatch($db);
GETPOST("id_entrepot_destination"), $result=$pdluo->fetch($pdluoid);
GETPOST("nbpiece"),
0, if ($result>0 && $pdluo->id)
GETPOST("label"), {
$pricedest // 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) if ($result1 >= 0 && $result2 >= 0)
{ {
$db->commit(); $db->commit();