Show stock userfields on the stock entry edit form

This commit is contained in:
Bernd Bestel
2022-04-06 19:08:17 +02:00
parent 4da546fc80
commit 76d6342156
3 changed files with 20 additions and 8 deletions

View File

@@ -462,7 +462,8 @@ class StockController extends BaseController
'stockEntry' => $this->getDatabase()->stock()->where('id', $args['entryId'])->fetch(), 'stockEntry' => $this->getDatabase()->stock()->where('id', $args['entryId'])->fetch(),
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'), 'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'),
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name', 'COLLATE NOCASE'), 'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name', 'COLLATE NOCASE'),
'locations' => $this->getDatabase()->locations()->orderBy('name', 'COLLATE NOCASE') 'locations' => $this->getDatabase()->locations()->orderBy('name', 'COLLATE NOCASE'),
'userfields' => $this->getUserfieldsService()->GetFields('stock')
]); ]);
} }

View File

@@ -41,15 +41,18 @@
jsonData.open = $("#open").is(":checked"); jsonData.open = $("#open").is(":checked");
Grocy.Api.Put("stock/entry/" + Grocy.EditObjectId, jsonData, Grocy.Api.Put("stock/entry/" + Grocy.EditObjectRowId, jsonData,
function(result) function(result)
{ {
var successMessage = __t('Stock entry successfully updated') + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoStockBookingEntry(\'' + result.id + '\',\'' + Grocy.EditObjectId + '\')"><i class="fa-solid fa-undo"></i> ' + __t("Undo") + '</a>'; Grocy.Components.UserfieldsForm.Save(function()
{
var successMessage = __t('Stock entry successfully updated') + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoStockBookingEntry(\'' + result.id + '\',\'' + Grocy.EditObjectRowId + '\')"><i class="fa-solid fa-undo"></i> ' + __t("Undo") + '</a>';
window.parent.postMessage(WindowMessageBag("StockEntryChanged", Grocy.EditObjectId), Grocy.BaseUrl); window.parent.postMessage(WindowMessageBag("StockEntryChanged", Grocy.EditObjectRowId), Grocy.BaseUrl);
window.parent.postMessage(WindowMessageBag("ShowSuccessMessage", successMessage), Grocy.BaseUrl); window.parent.postMessage(WindowMessageBag("ShowSuccessMessage", successMessage), Grocy.BaseUrl);
window.parent.postMessage(WindowMessageBag("Ready"), Grocy.BaseUrl); window.parent.postMessage(WindowMessageBag("Ready"), Grocy.BaseUrl);
window.parent.postMessage(WindowMessageBag("CloseAllModals"), Grocy.BaseUrl); window.parent.postMessage(WindowMessageBag("CloseAllModals"), Grocy.BaseUrl);
});
}, },
function(xhr) function(xhr)
{ {
@@ -118,5 +121,7 @@ $("#amount").on("focus", function(e)
{ {
$(this).select(); $(this).select();
}); });
Grocy.Components.UserfieldsForm.Load();
$("#amount").focus(); $("#amount").focus();
Grocy.FrontendHelpers.ValidateForm("stockentry-form"); Grocy.FrontendHelpers.ValidateForm("stockentry-form");

View File

@@ -5,7 +5,8 @@
@section('content') @section('content')
<script> <script>
Grocy.EditObjectId = {{ $stockEntry->id }}; Grocy.EditObjectId = "{{ $stockEntry->stock_id }}";
Grocy.EditObjectRowId = {{ $stockEntry->id }};
Grocy.EditObjectProductId = {{ $stockEntry->product_id }}; Grocy.EditObjectProductId = {{ $stockEntry->product_id }};
</script> </script>
@@ -140,6 +141,11 @@
</div> </div>
</div> </div>
@include('components.userfieldsform', array(
'userfields' => $userfields,
'entity' => 'stock'
))
<button id="save-stockentry-button" <button id="save-stockentry-button"
class="btn btn-success">{{ $__t('OK') }}</button> class="btn btn-success">{{ $__t('OK') }}</button>