StockService: Set the product's bestBeforeDate to the freezer date if it is being purchased to a freezer (#1672)

* StockService: Set the product's bestBeforeDate to the freezer date if it is being purchased to a freezer

* Formatting / feature flag checks / proper data type comparision

* Prefill due date also on location change

Co-authored-by: Bernd Bestel <bernd@berrnd.de>
This commit is contained in:
Graham Christensen
2021-11-13 11:41:04 -05:00
committed by GitHub
parent 10bd5ce900
commit a7f3f64d89
2 changed files with 69 additions and 18 deletions

View File

@@ -144,7 +144,27 @@ class StockService extends BaseService
//Set the default due date, if none is supplied
if ($bestBeforeDate == null)
{
if (intval($productDetails->product->default_best_before_days) == -1)
if ($locationId !== null && !$this->LocationExists($locationId))
{
throw new \Exception('Location does not exist');
}
else
{
$location = $this->getDatabase()->locations()->where('id', $locationId)->fetch();
}
if (GROCY_FEATURE_FLAG_STOCK_PRODUCT_FREEZING && $locationId !== null && intval($location->is_freezer) === 1 && intval($productDetails->product->default_best_before_days_after_freezing) >= -1)
{
if (intval($productDetails->product->default_best_before_days_after_freezing) == -1)
{
$bestBeforeDate = date('2999-12-31');
}
else
{
$bestBeforeDate = date('Y-m-d', strtotime('+' . $productDetails->product->default_best_before_days_after_freezing . ' days'));
}
}
elseif (intval($productDetails->product->default_best_before_days) == -1)
{
$bestBeforeDate = date('2999-12-31');
}