100 lines
4.9 KiB
Plaintext
100 lines
4.9 KiB
Plaintext
@using Indotalent.ConfigBackEnd.Extensions
|
|
@using Indotalent.Features.Purchase.PurchaseOrder
|
|
@using Indotalent.Features.Purchase.PurchaseOrder.Cqrs
|
|
@using MudBlazor
|
|
@using Indotalent.Features.Root.Shared
|
|
@inject PurchaseOrderService PurchaseOrderService
|
|
@inject IDialogService DialogService
|
|
@inject ISnackbar Snackbar
|
|
|
|
<MudPaper Elevation="0" Outlined="true" Style="border-radius: 4px; border: 1px solid #E5E7EB;">
|
|
<div style="padding: 16px; border-bottom: 1px solid #E5E7EB; display: flex; justify-content: space-between; align-items: center; background-color: #F8FAFC;">
|
|
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Items</MudText>
|
|
@if (!ReadOnly)
|
|
{
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add" OnClick="OnAddClick" Size="Size.Small" Style="text-transform: none; font-weight: 700; border-radius: 4px;">
|
|
Add Item
|
|
</MudButton>
|
|
}
|
|
</div>
|
|
|
|
<MudTable Items="Items" Hover="true" Elevation="0" Dense="true" T="PurchaseOrderItemResponse">
|
|
<HeaderContent>
|
|
<MudTh Style="font-weight: 700;">Product</MudTh>
|
|
<MudTh Style="font-weight: 700; text-align: right;">UnitPrice</MudTh>
|
|
<MudTh Style="font-weight: 700; text-align: right;">Quantity</MudTh>
|
|
<MudTh Style="font-weight: 700; text-align: right;">Total</MudTh>
|
|
@if (!ReadOnly)
|
|
{
|
|
<MudTh Style="width: 100px; text-align: right; font-weight: 700;">Actions</MudTh>
|
|
}
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd DataLabel="Product">@context.ProductName</MudTd>
|
|
<MudTd DataLabel="UnitPrice" Style="text-align: right;">@context.UnitPrice?.ToString("N2")</MudTd>
|
|
<MudTd DataLabel="Quantity" Style="text-align: right;">@context.Quantity</MudTd>
|
|
<MudTd DataLabel="Total" Style="text-align: right; font-weight: 700;">@context.Total?.ToString("N2")</MudTd>
|
|
@if (!ReadOnly)
|
|
{
|
|
<MudTd Style="text-align: right;">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Edit" Size="Size.Small" Color="Color.Primary" OnClick="@(() => OnEditClick(context))" />
|
|
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small" Color="Color.Error" OnClick="@(() => OnDeleteClick(context))" />
|
|
</MudTd>
|
|
}
|
|
</RowTemplate>
|
|
</MudTable>
|
|
</MudPaper>
|
|
|
|
<script>
|
|
function downloadFile(fileName, contentType, base64String) {
|
|
const link = document.createElement('a');
|
|
link.download = fileName;
|
|
link.href = `data:${contentType};base64,${base64String}`;
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
document.body.removeChild(link);
|
|
}
|
|
</script>
|
|
<style>
|
|
.mud-table-styled .mud-table-row:hover { background-color: #F9FAFB !important; }
|
|
</style>
|
|
@code {
|
|
[Parameter] public string PurchaseOrderId { get; set; } = string.Empty;
|
|
[Parameter] public List<PurchaseOrderItemResponse> Items { get; set; } = new();
|
|
[Parameter] public bool ReadOnly { get; set; } = false;
|
|
[Parameter] public EventCallback OnChanged { get; set; }
|
|
|
|
private async Task OnAddClick()
|
|
{
|
|
var parameters = new DialogParameters { ["PurchaseOrderId"] = PurchaseOrderId };
|
|
var options = new DialogOptions { MaxWidth = MaxWidth.Small, FullWidth = true, CloseButton = true };
|
|
var dialog = await DialogService.ShowAsync<_PurchaseOrderItemCreateForm>("Add Item", parameters, options);
|
|
var result = await dialog.Result;
|
|
if (result != null && !result.Canceled) await OnChanged.InvokeAsync();
|
|
}
|
|
|
|
private async Task OnEditClick(PurchaseOrderItemResponse item)
|
|
{
|
|
var parameters = new DialogParameters { ["Data"] = item };
|
|
var options = new DialogOptions { MaxWidth = MaxWidth.Small, FullWidth = true, CloseButton = true };
|
|
var dialog = await DialogService.ShowAsync<_PurchaseOrderItemUpdateForm>("Edit Item", parameters, options);
|
|
var result = await dialog.Result;
|
|
if (result != null && !result.Canceled) await OnChanged.InvokeAsync();
|
|
}
|
|
|
|
private async Task OnDeleteClick(PurchaseOrderItemResponse item)
|
|
{
|
|
var parameters = new DialogParameters { ["ContentText"] = $"Are you sure you want to remove this item?" };
|
|
var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("Delete Confirmation", parameters, new DialogOptions { MaxWidth = MaxWidth.ExtraSmall, FullWidth = true });
|
|
var result = await dialog.Result;
|
|
if (result != null && !result.Canceled)
|
|
{
|
|
var success = await PurchaseOrderService.DeletePurchaseOrderItemAsync(item.Id!);
|
|
if (success)
|
|
{
|
|
Snackbar.Add("Removed successfully", Severity.Success);
|
|
await OnChanged.InvokeAsync();
|
|
}
|
|
}
|
|
}
|
|
} |