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
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
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(),
'products' => $this->getDatabase()->products()->where('active = 1')->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");
Grocy.Api.Put("stock/entry/" + Grocy.EditObjectId, jsonData,
Grocy.Api.Put("stock/entry/" + Grocy.EditObjectRowId, jsonData,
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("ShowSuccessMessage", successMessage), Grocy.BaseUrl);
window.parent.postMessage(WindowMessageBag("Ready"), Grocy.BaseUrl);
window.parent.postMessage(WindowMessageBag("CloseAllModals"), Grocy.BaseUrl);
window.parent.postMessage(WindowMessageBag("StockEntryChanged", Grocy.EditObjectRowId), Grocy.BaseUrl);
window.parent.postMessage(WindowMessageBag("ShowSuccessMessage", successMessage), Grocy.BaseUrl);
window.parent.postMessage(WindowMessageBag("Ready"), Grocy.BaseUrl);
window.parent.postMessage(WindowMessageBag("CloseAllModals"), Grocy.BaseUrl);
});
},
function(xhr)
{
@ -118,5 +121,7 @@ $("#amount").on("focus", function(e)
{
$(this).select();
});
Grocy.Components.UserfieldsForm.Load();
$("#amount").focus();
Grocy.FrontendHelpers.ValidateForm("stockentry-form");

View File

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