Files
blazor-swm/Features/Purchase/PaymentDisburse/Components/_PaymentDisburseCreateForm.razor
T
2026-07-21 14:35:37 +07:00

216 lines
9.6 KiB
Plaintext

@using Indotalent.Features.Purchase.PaymentDisburse.Cqrs
@using Indotalent.Shared.Utils
@using MudBlazor
@inject PaymentDisburseService PaymentDisburseService
@inject ISnackbar Snackbar
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #DCEBFA;">
<div class="d-flex align-center gap-4">
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
<div>
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">Add Payment Disburse</MudText>
<MudText Typo="Typo.body2" Style="color: #64748b;">Process payment to vendor for an existing bill.</MudText>
</div>
</div>
</MudPaper>
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 4px; border: 1px solid #DCEBFA;">
<MudForm @ref="_form" Model="_model">
<MudGrid Spacing="3">
<MudItem xs="12"><MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Basic Information</MudText><MudDivider /></MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Payment Date</MudText>
<MudDatePicker @bind-Date="_model.PaymentDate"
Variant="Variant.Outlined" Margin="Margin.Dense" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-0">Bill Reference</MudText>
<MudSelect T="string" Value="_model.BillId"
ValueChanged="OnBillChanged"
For="@(() => _model.BillId)"
Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true"
AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
@foreach (var item in _lookup.Bills)
{
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
}
</MudSelect>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-0">Payment Method</MudText>
<MudSelect T="string" @bind-Value="_model.PaymentMethodId"
For="@(() => _model.PaymentMethodId)"
Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true"
AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
@foreach (var item in _lookup.PaymentMethods)
{
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
}
</MudSelect>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-0">Status</MudText>
<MudSelect T="Indotalent.Data.Enums.PaymentDisburseStatus" @bind-Value="_model.Status"
Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true"
AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
@foreach (var item in _lookup.Statuses)
{
<MudSelectItem Value="@((Indotalent.Data.Enums.PaymentDisburseStatus)item.Value)">@item.Name</MudSelectItem>
}
</MudSelect>
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Payment Amount</MudText>
<MudNumericField @bind-Value="_model.PaymentAmount"
Format="N2"
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
</MudItem>
<MudItem xs="12" sm="6">
<MudText Typo="Typo.subtitle2" Class="mb-1">Vendor</MudText>
<MudTextField Value="@_vendorName" ReadOnly="true"
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" Style="background-color: #f1f5f9;" />
</MudItem>
<MudItem xs="12">
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
<MudTextField @bind-Value="_model.Description"
For="@(() => _model.Description)"
Variant="Variant.Outlined" Margin="Margin.Dense" Lines="2" FullWidth="true" />
</MudItem>
<MudItem xs="12" Class="mt-6">
<_PaymentDisburseItemDataTable Items="_items" />
</MudItem>
<MudItem xs="12" sm="7"></MudItem>
<MudItem xs="12" sm="5">
<MudPaper Elevation="0" Outlined="true" Class="pa-4" Style="border-radius: 4px; background-color: #F8FAFC; border: 1px solid #DCEBFA;">
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;" Class="mb-4 d-block">Bill Commercial Summary</MudText>
<div class="d-flex justify-space-between mb-2">
<MudText Typo="Typo.body2">Sub Total</MudText>
<MudText Typo="Typo.body2" Style="font-weight: 700;">@_billSubTotal.ToString("N2")</MudText>
</div>
<div class="d-flex justify-space-between mb-2">
<MudText Typo="Typo.body2">Tax Amount</MudText>
<MudText Typo="Typo.body2" Style="font-weight: 700;">@_billTax.ToString("N2")</MudText>
</div>
<MudDivider Class="my-2" />
<div class="d-flex justify-space-between">
<MudText Typo="Typo.subtitle1" Style="font-weight: 900;">Grand Total</MudText>
<MudText Typo="Typo.subtitle1" Color="Color.Primary" Style="font-weight: 900;">@_billGrandTotal.ToString("N2")</MudText>
</div>
</MudPaper>
</MudItem>
</MudGrid>
<div class="d-flex justify-end gap-2 mt-8">
<MudButton OnClick="() => OnCancel.InvokeAsync()"
Variant="Variant.Outlined"
Disabled="_processing"
Style="border-radius: 4px; text-transform: none; font-weight: 700; border: 1px solid #e0e0e0;">
Cancel
</MudButton>
<MudButton Color="Color.Primary"
Variant="Variant.Filled"
OnClick="Submit"
Disabled="_processing"
Style="border-radius: 4px; text-transform: none; font-weight: 700;">
@if (_processing)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
}
else
{
<MudText>Process Disburse</MudText>
}
</MudButton>
</div>
</MudForm>
</MudPaper>
@code {
[Parameter] public EventCallback OnCancel { get; set; }
[Parameter] public EventCallback OnSuccess { get; set; }
private MudForm _form = default!;
private CreatePaymentDisburseRequest _model = new() { PaymentDate = DateTime.Today, Status = Indotalent.Data.Enums.PaymentDisburseStatus.Draft };
private PaymentDisburseLookupResponse _lookup = new();
private List<PaymentDisburseItemResponse> _items = new();
private string _vendorName = "";
private decimal _billSubTotal = 0;
private decimal _billTax = 0;
private decimal _billGrandTotal = 0;
private bool _processing = false;
protected override async Task OnInitializedAsync()
{
var res = await PaymentDisburseService.GetPaymentDisburseLookupAsync();
if (res != null && res.IsSuccess) _lookup = res.Value ?? new();
}
private async Task OnBillChanged(string billId)
{
_model.BillId = billId;
if (string.IsNullOrEmpty(billId))
{
ResetBillData();
return;
}
var res = await PaymentDisburseService.GetBillDetailForPaymentAsync(billId);
await Task.Delay(500);
if (res != null && res.IsSuccess && res.Value != null)
{
_items = res.Value.Items;
_vendorName = res.Value.VendorName ?? "";
_billSubTotal = res.Value.PurchaseOrderBeforeTaxAmount;
_billTax = res.Value.PurchaseOrderTaxAmount;
_billGrandTotal = res.Value.PurchaseOrderAfterTaxAmount;
_model.PaymentAmount = res.Value.PaymentAmount;
Snackbar.Add($"Bill {res.Value.BillNumber} items loaded.", Severity.Info);
}
}
private void ResetBillData()
{
_items.Clear();
_vendorName = "";
_billSubTotal = 0;
_billTax = 0;
_billGrandTotal = 0;
_model.PaymentAmount = 0;
}
private async Task Submit()
{
await _form.Validate();
if (!_form.IsValid) return;
_processing = true;
try
{
var response = await PaymentDisburseService.CreatePaymentDisburseAsync(_model);
await Task.Delay(500);
if (response != null && response.IsSuccess)
{
Snackbar.Add("Payment recorded successfully", Severity.Success);
await OnSuccess.InvokeAsync();
}
}
finally
{
_processing = false;
}
}
}