@using Indotalent.Features.Sales.PaymentReceive.Cqrs @using Indotalent.Shared.Utils @using MudBlazor @inject PaymentReceiveService PaymentReceiveService @inject ISnackbar Snackbar Add Payment Receive Process customer payment for an existing invoice. Basic Information Payment Date Invoice Reference @foreach (var item in _lookup.Invoices) { @item.Name } Payment Method @foreach (var item in _lookup.PaymentMethods) { @item.Name } Status @foreach (var item in _lookup.Statuses) { @item.Name } Payment Amount Customer Description <_PaymentReceiveItemDataTable Items="_items" /> Invoice Commercial Summary Sub Total @_invoiceSubTotal.ToString("N2") Tax Amount @_invoiceTax.ToString("N2") Grand Total @_invoiceGrandTotal.ToString("N2") Cancel @if (_processing) { Processing... } else { Process Payment } @code { [Parameter] public EventCallback OnCancel { get; set; } [Parameter] public EventCallback OnSuccess { get; set; } private MudForm _form = default!; private CreatePaymentReceiveRequest _model = new() { PaymentDate = DateTime.Today, Status = Indotalent.Data.Enums.PaymentReceiveStatus.Draft }; private PaymentReceiveLookupResponse _lookup = new(); private List _items = new(); private string _customerName = ""; private decimal _invoiceSubTotal = 0; private decimal _invoiceTax = 0; private decimal _invoiceGrandTotal = 0; private bool _processing = false; protected override async Task OnInitializedAsync() { var res = await PaymentReceiveService.GetPaymentReceiveLookupAsync(); if (res != null && res.IsSuccess) _lookup = res.Value ?? new(); } private async Task OnInvoiceChanged(string invoiceId) { _model.InvoiceId = invoiceId; if (string.IsNullOrEmpty(invoiceId)) { ResetInvoiceData(); return; } var res = await PaymentReceiveService.GetInvoiceDetailForPaymentAsync(invoiceId); await Task.Delay(500); if (res != null && res.IsSuccess && res.Value != null) { _items = res.Value.Items; _customerName = res.Value.CustomerName ?? ""; _invoiceSubTotal = res.Value.SalesOrderBeforeTaxAmount; _invoiceTax = res.Value.SalesOrderTaxAmount; _invoiceGrandTotal = res.Value.SalesOrderAfterTaxAmount; _model.PaymentAmount = res.Value.PaymentAmount; Snackbar.Add($"Invoice {res.Value.InvoiceNumber} items loaded.", Severity.Info); } } private void ResetInvoiceData() { _items.Clear(); _customerName = ""; _invoiceSubTotal = 0; _invoiceTax = 0; _invoiceGrandTotal = 0; _model.PaymentAmount = 0; } private async Task Submit() { await _form.Validate(); if (!_form.IsValid) return; _processing = true; try { var response = await PaymentReceiveService.CreatePaymentReceiveAsync(_model); await Task.Delay(500); if (response != null && response.IsSuccess) { Snackbar.Add("Payment recorded successfully", Severity.Success); await OnSuccess.InvokeAsync(); } } finally { _processing = false; } } }