You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
KWWebInvApp/Pages/BranchMaintenance/InventoryCorrection.razor

201 lines
8.6 KiB
Plaintext

@page "/brmaintenance/invtycorrection"
@attribute [Authorize]
@using KWWebInvApp.Data;
@using KWWebInvApp.Services;
@inject IDialogService DialogService;
@inject IAuthenticationService AuthenticationStateService;
<PageTitle>Branch Inventory Correction</PageTitle>
<MudText Typo="Typo.h4" GutterBottom="true">Branch Inventory Correction</MudText>
<MudText Typo="Typo.body1" GutterBottom="true">Select a specific branch and select the table to edit from the grid.</MudText>
<MudGrid>
<MudItem sm="12">
<MudCard>
<MudCardContent>
<MudGrid>
<MudItem xs="12" md="5">
<MudAutocomplete T="string" Label="Enter Branch Code" @bind-Value="selectedBranch" SearchFunc="@SearchBranch" CoerceValue=false />
</MudItem>
<MudItem xs="12" md="4">
<MudTextField T="string" Label="Enter Model No." @bind-Value="modelNo" />
</MudItem>
<MudItem xs="12" md="3">
<MudButton Variant="Variant.Filled" Color="Color.Primary" ButtonType="ButtonType.Button" OnClick="GetRecord" FullWidth="true" Disabled=@disableStatusGetRecord>Get Record</MudButton>
</MudItem>
</MudGrid>
</MudCardContent>
</MudCard>
</MudItem>
</MudGrid>
@if (branchItemLedger != null && branchItemLedger.modelno != null)
{
<MudText Typo="Typo.body1" Class="my-5 mt-10">Inventory details of @selectedBranch branch</MudText>
<EditForm Model="@branchItemLedger" OnValidSubmit="SaveBranchItemLedger">
<MudGrid>
<MudItem sm="12">
<MudCard>
<MudCardContent>
<MudGrid>
<MudItem sm="12" md="4">
<MudField Label="@branchItemLedger.modelno" Variant="Variant.Outlined">@branchItemLedger.itemcode</MudField>
</MudItem>
<MudItem sm="12" md="8">
<MudField Label="Remarks" Variant="Variant.Outlined">@branchItemLedger.remarks</MudField>
</MudItem>
<MudItem sm="12">
<MudField Label="New Remarks" Variant="Variant.Outlined">@newRemarks</MudField>
</MudItem>
<MudItem sm="12">
<MudText Typo="Typo.body1"><b>Remarks</b> above is the existing value of remarks on particular item while <b>New Remarks</b> is the remarks that will be added to Remarks after changes had been saved.</MudText>
</MudItem>
</MudGrid>
<MudText Typo="Typo.body1" Class="my-3" Color="Color.Primary">Edit the details below</MudText>
<MudGrid>
<MudItem sm="12" md="2">
<MudTextField T="int" Label="Beginning Qty" @bind-Value="branchItemLedger.beginningqty" />
</MudItem>
<MudItem sm="12" md="2">
<MudTextField T="int" Label="In Qty" @bind-Value="branchItemLedger.inqty" />
</MudItem>
<MudItem sm="12" md="2">
<MudTextField T="int" Label="Out Qty" @bind-Value="branchItemLedger.outqty" />
</MudItem>
<MudItem sm="12" md="2">
<MudTextField T="int" Label="Sales Qty" @bind-Value="branchItemLedger.sales" />
</MudItem>
<MudItem sm="12" md="2">
<MudTextField T="int" Label="Adjustment" @bind-Value="branchItemLedger.adjustment" />
</MudItem>
<MudItem sm="12" md="2">
<MudTextField T="int" Label="Ending Qty" @bind-Value="branchItemLedger.endingqty" />
</MudItem>
</MudGrid>
</MudCardContent>
<MudCardActions>
<MudButton Class="ma-3" Variant="Variant.Filled" Color="Color.Primary" ButtonType="ButtonType.Submit" Disabled=@disableStatusSave>Update Record</MudButton>
<MudButton Class="ma-3" Variant="Variant.Filled" Color="Color.Secondary" OnClick="ResetUpdateBranchItemLedger">Reset</MudButton>
</MudCardActions>
</MudCard>
</MudItem>
</MudGrid>
</EditForm>
}
else
{
<MudText Typo="Typo.caption">No Record to Show</MudText>
}
@code {
BranchServices.branch[]? branchList;
string? selectedBranch, modelNo, newRemarks;
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<IEnumerable<string>> 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 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<MessageDialogs.WarningDialog>("No Branch", dialogParam);
return;
}
if (string.IsNullOrEmpty(modelNo))
{
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<MessageDialogs.WarningDialog>("No Mode Number", dialogParam);
return;
}
disableStatusGetRecord = true;
disableStatusSave = true;
var currentUser = await AuthenticationStateService.GetAuthenticatedUserAsync();
branchItemLedger = await branchItemLedgerServiceClient.GetRemoteDataByBrCodeModelnoAsync(selectedBranch, modelNo);
newRemarks = $"Manually edit by {currentUser?.fullName}. {DateTime.Now:MM/dd/yyyy hh:mm:sstt}";
disableStatusGetRecord = false;
disableStatusSave = false;
}
async Task SaveBranchItemLedger()
{
if (branchItemLedger == null)
return;
disableStatusGetRecord = true;
disableStatusSave = true;
var currentUser = await AuthenticationStateService.GetAuthenticatedUserAsync();
branchItemLedger.remarks = $"|Manually edit by {currentUser?.fullName}. {DateTime.Now:MM/dd/yyyy hh:mm:sstt} [{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<MessageDialogs.WarningDialog>("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<MessageDialogs.WarningDialog>("Failed", dialogParam);
disableStatusGetRecord = false;
disableStatusSave = false;
}
}
async Task ResetUpdateBranchItemLedger()
{
await Task.Delay(1);
disableStatusGetRecord = false;
disableStatusSave = true;
branchItemLedger = null;
}
}