302 lines
13 KiB
Plaintext
302 lines
13 KiB
Plaintext
@using Indotalent.ConfigBackEnd.Extensions
|
|
@using Indotalent.Features.Sales.PaymentReceive.Cqrs
|
|
@using Indotalent.Features.Sales.PaymentReceive.Components
|
|
@using Indotalent.Shared.Utils
|
|
@using MudBlazor
|
|
@using Microsoft.JSInterop
|
|
@inject PaymentReceiveService PaymentReceiveService
|
|
@inject ISnackbar Snackbar
|
|
@inject IJSRuntime JSRuntime
|
|
|
|
<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;">@(ReadOnly ? "Details" : "Edit") Payment Receive</MudText>
|
|
<MudText Typo="Typo.body2" Style="color: #64748b;">@_model.AutoNumber</MudText>
|
|
</div>
|
|
</div>
|
|
@if (ReadOnly || !string.IsNullOrEmpty(_model.Id))
|
|
{
|
|
<MudButton Variant="Variant.Filled"
|
|
Color="Color.Info"
|
|
StartIcon="@(_isPrinting ? null : Icons.Material.Filled.Print)"
|
|
OnClick="DownloadPdf"
|
|
Disabled="_isPrinting"
|
|
Style="border-radius: 4px; text-transform: none; font-weight: 700; box-shadow: none;">
|
|
@if (_isPrinting)
|
|
{
|
|
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
|
|
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Generating Receipt...</MudText>
|
|
}
|
|
else
|
|
{
|
|
<MudText>Print Receipt</MudText>
|
|
}
|
|
</MudButton>
|
|
}
|
|
</MudPaper>
|
|
|
|
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; 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-0">Payment Date</MudText>
|
|
<MudDatePicker @bind-Date="_model.PaymentDate" ReadOnly="ReadOnly"
|
|
Variant="Variant.Outlined" Margin="Margin.Dense" />
|
|
</MudItem>
|
|
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-0">Invoice Reference</MudText>
|
|
<MudSelect T="string" Value="_model.InvoiceId"
|
|
ValueChanged="OnInvoiceChanged"
|
|
ReadOnly="ReadOnly"
|
|
Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true"
|
|
AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
|
@foreach (var item in _lookup.Invoices)
|
|
{
|
|
<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"
|
|
ReadOnly="ReadOnly"
|
|
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.PaymentReceiveStatus" @bind-Value="_model.Status"
|
|
ReadOnly="ReadOnly"
|
|
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.PaymentReceiveStatus)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"
|
|
ReadOnly="ReadOnly"
|
|
Format="N2"
|
|
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
|
</MudItem>
|
|
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Customer</MudText>
|
|
<MudTextField Value="@_customerName" 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"
|
|
ReadOnly="ReadOnly"
|
|
Variant="Variant.Outlined" Margin="Margin.Dense" Lines="2" FullWidth="true" />
|
|
</MudItem>
|
|
|
|
<MudItem xs="12" Class="mt-6">
|
|
<_PaymentReceiveItemDataTable 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: 0px; background-color: #F8FAFC; border: 1px solid #DCEBFA;">
|
|
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;" Class="mb-4 d-block">Invoice 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;">@_invoiceSubTotal.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;">@_invoiceTax.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;">@_invoiceGrandTotal.ToString("N2")</MudText>
|
|
</div>
|
|
</MudPaper>
|
|
</MudItem>
|
|
|
|
<MudItem xs="12" Class="mt-4">
|
|
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Audit History</MudText>
|
|
<MudDivider Class="mt-2 mb-4" />
|
|
</MudItem>
|
|
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2">Created At</MudText>
|
|
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@DateTimeExtensions.ToString(_model.CreatedAt)</MudText>
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2">Created By</MudText>
|
|
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@(!string.IsNullOrEmpty(_model.CreatedBy) ? _model.CreatedBy : "System")</MudText>
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2">Last Updated At</MudText>
|
|
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@DateTimeExtensions.ToString(_model.UpdatedAt)</MudText>
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2">Last Updated By</MudText>
|
|
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@(!string.IsNullOrEmpty(_model.UpdatedBy) ? _model.UpdatedBy : "System")</MudText>
|
|
</MudItem>
|
|
</MudGrid>
|
|
|
|
<div class="d-flex justify-end gap-2 mt-10">
|
|
<MudButton OnClick="() => OnCancel.InvokeAsync()"
|
|
Variant="Variant.Outlined"
|
|
Disabled="_processing"
|
|
Style="border-radius: 4px; border: 1px solid #e0e0e0; text-transform: none; font-weight: 700;">
|
|
@(ReadOnly ? "Back to List" : "Cancel")
|
|
</MudButton>
|
|
@if (!ReadOnly)
|
|
{
|
|
<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;">Updating...</MudText>
|
|
}
|
|
else
|
|
{
|
|
<MudText>Save Changes</MudText>
|
|
}
|
|
</MudButton>
|
|
}
|
|
</div>
|
|
</MudForm>
|
|
</MudPaper>
|
|
|
|
@code {
|
|
[Parameter] public UpdatePaymentReceiveRequest Data { get; set; } = new();
|
|
[Parameter] public bool ReadOnly { get; set; } = false;
|
|
[Parameter] public EventCallback OnCancel { get; set; }
|
|
[Parameter] public EventCallback OnSuccess { get; set; }
|
|
|
|
private MudForm _form = default!;
|
|
private UpdatePaymentReceiveRequest _model = new();
|
|
private List<PaymentReceiveItemResponse> _items = new();
|
|
private PaymentReceiveLookupResponse _lookup = new();
|
|
|
|
private string _customerName = "";
|
|
private decimal _invoiceSubTotal = 0;
|
|
private decimal _invoiceTax = 0;
|
|
private decimal _invoiceGrandTotal = 0;
|
|
|
|
private bool _processing = false;
|
|
private bool _isPrinting = false;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
var resLookup = await PaymentReceiveService.GetPaymentReceiveLookupAsync();
|
|
if (resLookup != null && resLookup.IsSuccess) _lookup = resLookup.Value ?? new();
|
|
|
|
_model = Data;
|
|
await LoadInvoiceDetails(_model.InvoiceId ?? "");
|
|
}
|
|
|
|
private async Task OnInvoiceChanged(string invoiceId)
|
|
{
|
|
if (ReadOnly || _model.InvoiceId == invoiceId) return;
|
|
_model.InvoiceId = invoiceId;
|
|
await LoadInvoiceDetails(invoiceId);
|
|
Snackbar.Add("Invoice items and amounts updated.", Severity.Info);
|
|
}
|
|
|
|
private async Task LoadInvoiceDetails(string invoiceId)
|
|
{
|
|
if (string.IsNullOrEmpty(invoiceId)) return;
|
|
|
|
try
|
|
{
|
|
var response = await PaymentReceiveService.GetInvoiceDetailForPaymentAsync(invoiceId);
|
|
await Task.Delay(500);
|
|
|
|
if (response != null && response.IsSuccess && response.Value != null)
|
|
{
|
|
_items = response.Value.Items;
|
|
_customerName = response.Value.CustomerName ?? "";
|
|
_invoiceSubTotal = response.Value.SalesOrderBeforeTaxAmount;
|
|
_invoiceTax = response.Value.SalesOrderTaxAmount;
|
|
_invoiceGrandTotal = response.Value.SalesOrderAfterTaxAmount;
|
|
|
|
if (!ReadOnly)
|
|
{
|
|
_model.PaymentAmount = response.Value.PaymentAmount;
|
|
}
|
|
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
|
}
|
|
}
|
|
|
|
private async Task DownloadPdf()
|
|
{
|
|
try
|
|
{
|
|
_isPrinting = true;
|
|
StateHasChanged();
|
|
await Task.Delay(1000);
|
|
|
|
var response = await PaymentReceiveService.GetPaymentReceiveByIdAsync(_model.Id!);
|
|
if (response != null && response.IsSuccess && response.Value != null)
|
|
{
|
|
var pdfBytes = PaymentReceivePdfGenerator.Generate(response.Value);
|
|
var fileName = $"Receipt_{response.Value.AutoNumber}.pdf";
|
|
var base64 = Convert.ToBase64String(pdfBytes);
|
|
await JSRuntime.InvokeVoidAsync("downloadFile", fileName, "application/pdf", base64);
|
|
Snackbar.Add("Receipt generated successfully.", Severity.Success);
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
_isPrinting = false;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
|
|
private async Task Submit()
|
|
{
|
|
await _form.Validate();
|
|
if (!_form.IsValid) return;
|
|
|
|
_processing = true;
|
|
try
|
|
{
|
|
var response = await PaymentReceiveService.UpdatePaymentReceiveAsync(_model);
|
|
await Task.Delay(500);
|
|
|
|
if (response != null && response.IsSuccess)
|
|
{
|
|
Snackbar.Add("Updated successfully", Severity.Success);
|
|
await OnSuccess.InvokeAsync();
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
_processing = false;
|
|
}
|
|
}
|
|
} |