Add purchased date to inventory (#1102)

* Add purchased date to inventory

* Clarify stock settings label

Co-authored-by: Bernd Bestel <bernd@berrnd.de>
This commit is contained in:
kriddles 2020-10-29 11:04:34 -05:00 committed by GitHub
parent fb17c57dd3
commit 9bbcdafab9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 7 deletions

View File

@ -427,6 +427,13 @@ class StockApiController extends BaseApiController
$bestBeforeDate = $requestBody['best_before_date'];
}
$purchasedDate = null;
if (array_key_exists('purchased_date', $requestBody) && IsIsoDate($requestBody['purchased_date']))
{
$bestBeforeDate = $requestBody['purchased_date'];
}
$locationId = null;
if (array_key_exists('location_id', $requestBody) && is_numeric($requestBody['location_id']))
@ -448,7 +455,7 @@ class StockApiController extends BaseApiController
$shoppingLocationId = $requestBody['shopping_location_id'];
}
$bookingId = $this->getStockService()->InventoryProduct($args['productId'], $requestBody['new_amount'], $bestBeforeDate, $locationId, $price, $shoppingLocationId);
$bookingId = $this->getStockService()->InventoryProduct($args['productId'], $requestBody['new_amount'], $bestBeforeDate, $locationId, $price, $shoppingLocationId, $purchasedDate);
return $this->ApiResponse($response, $this->getDatabase()->stock_log($bookingId));
}
catch (\Exception $ex)

View File

@ -1922,7 +1922,7 @@ msgstr ""
msgid "%s total value"
msgstr ""
msgid "Show purchased date on purchase form (otherwise the purchased date defaults to today)"
msgid "Show purchased date on purchase and inventory page (otherwise the purchased date defaults to today)"
msgstr ""
msgid "Common"

View File

@ -25,6 +25,10 @@
{
jsonData.location_id = Grocy.Components.LocationPicker.GetValue();
}
if (Grocy.UserSettings.show_purchased_date_on_purchase)
{
jsonData.purchased_date = Grocy.Components.DateTimePicker2.GetValue();
}
jsonData.price = price;

View File

@ -677,7 +677,7 @@ class StockService extends BaseService
return $this->getDatabase()->stock()->where('id', $entryId)->fetch();
}
public function InventoryProduct(int $productId, float $newAmount, $bestBeforeDate, $locationId = null, $price = null, $shoppingLocationId = null)
public function InventoryProduct(int $productId, float $newAmount, $bestBeforeDate, $locationId = null, $price = null, $shoppingLocationId = null, $purchasedDate)
{
if (!$this->ProductExists($productId))
{
@ -720,7 +720,7 @@ class StockService extends BaseService
$bookingAmount = $newAmount;
}
return $this->AddProduct($productId, $bookingAmount, $bestBeforeDate, self::TRANSACTION_TYPE_INVENTORY_CORRECTION, date('Y-m-d'), $price, null, $locationId, $shoppingLocationId);
return $this->AddProduct($productId, $bookingAmount, $bestBeforeDate, self::TRANSACTION_TYPE_INVENTORY_CORRECTION, $purchasedDate, $price, null, $locationId, $shoppingLocationId);
}
elseif ($newAmount < $productDetails->stock_amount + $containerWeight)
{

View File

@ -20,7 +20,7 @@
@include('components.numberpicker', array(
'id' => 'new_amount',
'label' => 'New amount',
'label' => 'New stock amount',
'hintId' => 'new_amount_qu_unit',
'min' => 0,
'decimals' => $userSettings['stock_decimal_places_amounts'],
@ -33,6 +33,23 @@
class="text-small text-info font-italic d-none">' . $__t('Tare weight handling enabled - please weigh the whole container, the amount to be posted will be automatically calculcated') . '</div>'
))
@if(boolval($userSettings['show_purchased_date_on_purchase']))
@include('components.datetimepicker2', array(
'id' => 'purchased_date',
'label' => 'Purchased date',
'format' => 'YYYY-MM-DD',
'hint' => 'This will apply to added products',
'initWithNow' => true,
'limitEndToNow' => false,
'limitStartToNow' => false,
'invalidFeedback' => $__t('A purchased date is required'),
'nextInputSelector' => '#best_before_date',
'additionalCssClasses' => 'date-only-datetimepicker2',
'additionalGroupCssClasses' => $additionalGroupCssClasses,
'activateNumberPad' => GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_FIELD_NUMBER_PAD
))
@endif
@php
$additionalGroupCssClasses = '';
if (!GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING)
@ -63,7 +80,7 @@
@if(GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
@include('components.numberpicker', array(
'id' => 'price',
'label' => 'Price',
'label' => 'Price per stock unit',
'min' => 0,
'decimals' => $userSettings['stock_decimal_places_prices'],
'value' => '',

View File

@ -123,7 +123,7 @@
<input type="checkbox"
class="user-setting-control"
id="show_purchased_date_on_purchase"
data-setting-key="show_purchased_date_on_purchase"> {{ $__t('Show purchased date on purchase form (otherwise the purchased date defaults to today)') }}
data-setting-key="show_purchased_date_on_purchase"> {{ $__t('Show purchased date on purchase and inventory page (otherwise the purchased date defaults to today)') }}
</label>
</div>
</div>