@page "/brmaintenance/invtycorrection" @using KWWebInvApp.Data; @inject IDialogService DialogService; @inject UserServices userService; Branch Inventory Correction Branch Inventory Correction Select a specific branch and select the table to edit from the grid. Get Record @if (branchItemLedger != null && branchItemLedger.modelno != null) { Inventory details of @selectedBranch branch @branchItemLedger.itemcode @branchItemLedger.remarks Edit the details below Update Record Reset } else { No Record to Show } @code { BranchServices.branch[]? branchList; string? selectedBranch, selectedModelNo; BranchItemLedgerServices.branchitemledger? branchItemLedger = null; bool disableStatusGetRecord = false, disableStatusSave = true; BranchServices.BranchServiceClient branchServiceClient = new(); ItemServices.ItemServiceClient itemServiceClient = new(); BranchItemLedgerServices.BranchItemLedgerServiceClient branchItemLedgerServiceClient = new(); protected override async Task OnInitializedAsync() { branchList = await branchServiceClient.GetDataAsync(); } async Task> SearchBranch(string value) { await Task.Delay(1); if (string.IsNullOrEmpty(value)) return branchList.Select(c=>c.brCode); return branchList.Where(c => c.brCode.Contains(value, StringComparison.InvariantCultureIgnoreCase)).Select(c=>c.brCode); } async Task> SearchModelNo(string value) { ItemServices.items[] itemList; if (string.IsNullOrEmpty(value) || value.Length < 2) { itemList = await itemServiceClient.GetTopDataAsync(10); return itemList.Select(c => c.modelno); } itemList = await itemServiceClient.GetItemListByModelnoStartsWithAsync(value); return itemList.Select(c => c.modelno); } async Task GetRecord() { if(string.IsNullOrEmpty(selectedBranch)) { var dialogParam = new DialogParameters(); dialogParam.Add("ContentText", "No branch. Please enter in the Branch field."); dialogParam.Add("ButtonText", "OK"); dialogParam.Add("Color", Color.Error); DialogService.Show("No Branch", dialogParam); return; } if (string.IsNullOrEmpty(selectedModelNo)) { var dialogParam = new DialogParameters(); dialogParam.Add("ContentText", "No model number. Please enter in the Model Number field"); dialogParam.Add("ButtonText", "OK"); dialogParam.Add("Color", Color.Error); DialogService.Show("No Mode Number", dialogParam); return; } disableStatusGetRecord = true; disableStatusSave = true; branchItemLedger = await branchItemLedgerServiceClient.GetRemoteDataByBrCodeModelnoAsync(selectedBranch, selectedModelNo); disableStatusGetRecord = false; disableStatusSave = false; } async Task SaveBranchItemLedger() { if (branchItemLedger == null) return; disableStatusGetRecord = true; disableStatusSave = true; branchItemLedger.remarks = $"|Manually edit by {userService?.CurrentUser?.fullName}. {DateTime.Now:MM/dd/yyyy} [{branchItemLedger.beginningqty} {branchItemLedger.inqty} {branchItemLedger.outqty} {branchItemLedger.sales} {branchItemLedger.adjustment} {branchItemLedger.endingqty}]"; int result = await branchItemLedgerServiceClient.UpdateRemoteBranchItemLedgerAsync(branchItemLedger); if(result > 0) { var dialogParam = new DialogParameters(); dialogParam.Add("ContentText", "Successfully updated the record"); dialogParam.Add("ButtonText", "OK"); dialogParam.Add("Color", Color.Info); DialogService.Show("Success", dialogParam); await ResetUpdateBranchItemLedger(); } else { var dialogParam = new DialogParameters(); dialogParam.Add("ContentText", "Failed to update the record"); dialogParam.Add("ButtonText", "OK"); dialogParam.Add("Color", Color.Error); DialogService.Show("Failed", dialogParam); disableStatusGetRecord = false; disableStatusSave = false; } } async Task ResetUpdateBranchItemLedger() { await Task.Delay(1); disableStatusGetRecord = false; disableStatusSave = true; branchItemLedger = null; } }