mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
Use default best before date when adding product through API
This commit is contained in:
parent
1a23eaabf1
commit
1e33975a96
@ -67,7 +67,7 @@ class StockApiController extends BaseApiController
|
|||||||
throw new \Exception('An amount is required');
|
throw new \Exception('An amount is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
$bestBeforeDate = date('Y-m-d');
|
$bestBeforeDate = null;
|
||||||
if (array_key_exists('best_before_date', $requestBody) && IsIsoDate($requestBody['best_before_date']))
|
if (array_key_exists('best_before_date', $requestBody) && IsIsoDate($requestBody['best_before_date']))
|
||||||
{
|
{
|
||||||
$bestBeforeDate = $requestBody['best_before_date'];
|
$bestBeforeDate = $requestBody['best_before_date'];
|
||||||
|
@ -167,6 +167,16 @@ class StockService extends BaseService
|
|||||||
$amount = $amount - $productDetails->stock_amount - $productDetails->product->tare_weight;
|
$amount = $amount - $productDetails->stock_amount - $productDetails->product->tare_weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Sets the default best before date, if none is supplied
|
||||||
|
if ($bestBeforeDate == null)
|
||||||
|
{
|
||||||
|
if ($productDetails->product->default_best_before_days == -1) {
|
||||||
|
$bestBeforeDate = date('2999-12-31');
|
||||||
|
} else {
|
||||||
|
$bestBeforeDate = date('Y-m-d', strtotime(date('Y-m-d') . ' + '.$productDetails->product->default_best_before_days.' days'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($transactionType === self::TRANSACTION_TYPE_PURCHASE || $transactionType === self::TRANSACTION_TYPE_INVENTORY_CORRECTION)
|
if ($transactionType === self::TRANSACTION_TYPE_PURCHASE || $transactionType === self::TRANSACTION_TYPE_INVENTORY_CORRECTION)
|
||||||
{
|
{
|
||||||
$stockId = uniqid();
|
$stockId = uniqid();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user