mirror of
https://github.com/grocy/grocy.git
synced 2026-04-09 14:06:16 +02:00
StockService: Set the product's bestBeforeDate to the freezer date if it is being purchased to a freezer
This commit is contained in:
parent
8105dea17f
commit
9578f1696b
|
|
@ -288,9 +288,19 @@ if (Grocy.Components.ProductPicker !== undefined)
|
||||||
|
|
||||||
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING)
|
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING)
|
||||||
{
|
{
|
||||||
if (productDetails.product.default_best_before_days.toString() !== '0')
|
var best_before;
|
||||||
|
if (productDetails.location.is_freezer.toString() == "1")
|
||||||
{
|
{
|
||||||
if (productDetails.product.default_best_before_days == -1)
|
best_before = productDetails.product.default_best_before_days_after_freezing;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
best_before = productDetails.product.default_best_before_days;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (best_before.toString() !== '0')
|
||||||
|
{
|
||||||
|
if (best_before == -1)
|
||||||
{
|
{
|
||||||
if (!$("#datetimepicker-shortcut").is(":checked"))
|
if (!$("#datetimepicker-shortcut").is(":checked"))
|
||||||
{
|
{
|
||||||
|
|
@ -299,7 +309,7 @@ if (Grocy.Components.ProductPicker !== undefined)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Grocy.Components.DateTimePicker.SetValue(moment().add(productDetails.product.default_best_before_days, 'days').format('YYYY-MM-DD'));
|
Grocy.Components.DateTimePicker.SetValue(moment().add(best_before, 'days').format('YYYY-MM-DD'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,24 @@ class StockService extends BaseService
|
||||||
//Set the default due date, if none is supplied
|
//Set the default due date, if none is supplied
|
||||||
if ($bestBeforeDate == null)
|
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 && $productDetails->product->default_best_before_days_after_freezing >= -1)
|
||||||
|
{
|
||||||
|
if ($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');
|
$bestBeforeDate = date('2999-12-31');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user