Use default best before date when adding product through API

This commit is contained in:
Marc Ole Bulling 2019-08-04 20:58:11 +02:00
parent 1a23eaabf1
commit 1e33975a96
2 changed files with 11 additions and 1 deletions

View File

@ -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'];

View File

@ -166,6 +166,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)
{ {