mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 01:32:38 +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');
|
||||
}
|
||||
|
||||
$bestBeforeDate = date('Y-m-d');
|
||||
$bestBeforeDate = null;
|
||||
if (array_key_exists('best_before_date', $requestBody) && IsIsoDate($requestBody['best_before_date']))
|
||||
{
|
||||
$bestBeforeDate = $requestBody['best_before_date'];
|
||||
|
@ -166,6 +166,16 @@ class StockService extends BaseService
|
||||
|
||||
$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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user