mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 01:32:38 +00:00
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:
parent
10bd5ce900
commit
a7f3f64d89
@ -286,23 +286,7 @@ if (Grocy.Components.ProductPicker !== undefined)
|
|||||||
$("#tare-weight-handling-info").addClass("d-none");
|
$("#tare-weight-handling-info").addClass("d-none");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING)
|
PrefillBestBeforeDate(productDetails.product, productDetails.location);
|
||||||
{
|
|
||||||
if (productDetails.product.default_best_before_days.toString() !== '0')
|
|
||||||
{
|
|
||||||
if (productDetails.product.default_best_before_days == -1)
|
|
||||||
{
|
|
||||||
if (!$("#datetimepicker-shortcut").is(":checked"))
|
|
||||||
{
|
|
||||||
$("#datetimepicker-shortcut").click();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Grocy.Components.DateTimePicker.SetValue(moment().add(productDetails.product.default_best_before_days, 'days').format('YYYY-MM-DD'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_LABEL_PRINTER)
|
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_LABEL_PRINTER)
|
||||||
{
|
{
|
||||||
@ -396,6 +380,53 @@ if (Grocy.Components.ProductPicker !== undefined)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function PrefillBestBeforeDate(product, location)
|
||||||
|
{
|
||||||
|
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING)
|
||||||
|
{
|
||||||
|
var dueDays;
|
||||||
|
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRODUCT_FREEZING && BoolVal(location.is_freezer))
|
||||||
|
{
|
||||||
|
dueDays = product.default_best_before_days_after_freezing;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dueDays = product.default_best_before_days;
|
||||||
|
}
|
||||||
|
|
||||||
|
dueDays = parseFloat(dueDays);
|
||||||
|
if (dueDays != 0)
|
||||||
|
{
|
||||||
|
if (dueDays == -1)
|
||||||
|
{
|
||||||
|
if (!$("#datetimepicker-shortcut").is(":checked"))
|
||||||
|
{
|
||||||
|
$("#datetimepicker-shortcut").click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Grocy.Components.DateTimePicker.SetValue(moment().add(dueDays, 'days').format('YYYY-MM-DD'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Grocy.Components.LocationPicker.GetPicker().on('change', function(e)
|
||||||
|
{
|
||||||
|
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRODUCT_FREEZING)
|
||||||
|
{
|
||||||
|
Grocy.Api.Get('objects/locations/' + Grocy.Components.LocationPicker.GetValue(),
|
||||||
|
function(location)
|
||||||
|
{
|
||||||
|
PrefillBestBeforeDate(CurrentProductDetails.product, location);
|
||||||
|
},
|
||||||
|
function(xhr)
|
||||||
|
{ }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$('#display_amount').val(parseFloat(Grocy.UserSettings.stock_default_purchase_amount));
|
$('#display_amount').val(parseFloat(Grocy.UserSettings.stock_default_purchase_amount));
|
||||||
RefreshLocaleNumberInput();
|
RefreshLocaleNumberInput();
|
||||||
$(".input-group-productamountpicker").trigger("change");
|
$(".input-group-productamountpicker").trigger("change");
|
||||||
|
@ -144,7 +144,27 @@ 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 && 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');
|
$bestBeforeDate = date('2999-12-31');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user