This commit is contained in:
mmrbnjd
2024-09-09 17:11:28 +03:30
parent 7d7b352b51
commit 5ba30cf970
3 changed files with 70 additions and 47 deletions

View File

@@ -3,8 +3,9 @@
@using Shared.DTOs
@inject Fixedvalues fv;
@inject HttpClientController hc;
<ConfirmDialog @ref="dialog" />
<Grid @ref="grid"
AllowRowClick="true"
TItem="InvoicePaymentDTO"
Class="table table-hover table-bordered table-striped mt-3"
Data="invoice.payments"
@@ -130,6 +131,7 @@
<CurrencyInput TValue="long?" @bind-Value="item.pv" Locale="fa-Ir" Placeholder="مبلغ" style="text-align: center" />
</div>
</div>
<br />
<div class="row g-3">
<div class="form-group col-md-4">
<Alert hidden="@Hidealert" Color="@alertColor" Dismissable="false">
@@ -138,39 +140,40 @@
</Alert>
</div>
</div>
<div class="row g-3">
@if (add)
{
<div class="form-group col-md-2">
<div class="row g-3">
<div class="form-group col-md-6">
<Button class="mt-3" Color="ButtonColor.Success" @onclick="AddPay" Type="ButtonType.Button">
جدید
</Button>
</div>
</div>
</div>
}
else
{
<div class="form-group col-md-2">
<Button class="mt-3" Color="ButtonColor.Info" @onclick="AddPay" Type="ButtonType.Button">
{ <div class="row g-3">
<div class="form-group col-md-6">
<Button class="mt-3" Color="ButtonColor.Info" @onclick="UpdatePay" Type="ButtonType.Button">
ویرایش
</Button>
</div>
<div class="form-group col-md-2">
<Button class="mt-3" Color="ButtonColor.Danger" @onclick="AddPay" Type="ButtonType.Button">
<Button class="mt-3" Color="ButtonColor.Danger" @onclick="DeletePay" Type="ButtonType.Button">
حذف
</Button>
</div>
<div class="form-group col-md-2">
<Button class="mt-3" Color="ButtonColor.Primary" @onclick="cancell" Type="ButtonType.Button">
انصراف
</Button>
</div>
</div>
</div>
}
</div>
@code {
private ConfirmDialog dialog = default!;
bool add = true;
[Parameter] public InvoiceDTO invoice { get; set; }
Grid<InvoicePaymentDTO> grid = default!;
@@ -193,17 +196,19 @@
@functions {
private async Task OnRowClick(GridRowEventArgs<InvoicePaymentDTO> args)
{
Hidealert = true;
item = args.Item;
add = false;
}
async Task cancell()
{
Hidealert = true;
add = true;
item = new InvoicePaymentDTO();
}
async Task AddPay()
{
Hidealert = true;
if (await Validation())
{
var sentItem = new InvoiceItemAction<InvoicePaymentDTO>()
@@ -221,6 +226,7 @@
invoice.payments.Add(request);
await grid.RefreshDataAsync();
item = new InvoicePaymentDTO();
ShowSuccessAlert("پرداخت ثبت شد");
}
else ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
@@ -238,6 +244,7 @@
}
async Task UpdatePay()
{
Hidealert = true;
if (await Validation())
{
var rsp = await hc.Put<InvoiceItemAction<InvoicePaymentDTO>>("InvoicePayment/UpdatePay", new InvoiceItemAction<InvoicePaymentDTO>()
@@ -251,9 +258,12 @@
if (request != null && request.ID.HasValue)
{
invoice.payments.Remove(item);
invoice.payments.Add(request);
await grid.RefreshDataAsync();
item = new InvoicePaymentDTO();
add = true;
ShowSuccessAlert("تغییرات با موفقیت اعمال شد");
}
else ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
@@ -268,29 +278,41 @@
}
async Task DeletePay()
{
if (item.ID.HasValue)
var confirmation = await dialog.ShowAsync(
title: "عملیات حذف پرداخت",
message1: $"از حذف پرداخت",
message2: "اطمینان دارید?");
if (confirmation)
{
var rsp = await hc.Delete($"InvoicePayment/DeletePay/{item.ID.Value}");
if (rsp.IsSuccessStatusCode)
Hidealert = true;
if (item.ID.HasValue)
{
var request = await rsp.Content.ReadFromJsonAsync<bool>();
if (request)
var rsp = await hc.Delete($"InvoicePayment/DeletePay/{item.ID.Value}");
if (rsp.IsSuccessStatusCode)
{
invoice.payments.Add(item);
await grid.RefreshDataAsync();
item = new InvoicePaymentDTO();
var request = await rsp.Content.ReadFromJsonAsync<bool>();
if (request)
{
invoice.payments.Remove(item);
await grid.RefreshDataAsync();
item = new InvoicePaymentDTO();
add = true;
ShowSuccessAlert("پرداخت خذف شد");
}
else ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
}
else
{
else ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
}
else
{
var request = await rsp.Content.ReadFromJsonAsync<List<string>>();
ShowDangerAlert(request[0]);
var request = await rsp.Content.ReadFromJsonAsync<List<string>>();
ShowDangerAlert(request[0]);
}
}
}
}
private void ShowSuccessAlert(string msg)
{
@@ -308,9 +330,10 @@
}
async Task<bool> Validation()
{
if (item.pv<=0)
if (item.pv==null || item.pv <= 0)
{
ShowDangerAlert("مبلغ پرداختی باید بیشتر از صفر باشد.");
ShowDangerAlert("مبلغ پرداختی باید بیشتر از صفر باشد.");
return false;
}
if (invoice.tbill < invoice.payments.Sum(s => s.pv) + item.pv)
{
@@ -341,7 +364,7 @@
}
else
{
ShowDangerAlert("تاریخ پرداخت نمی تواند از امروز جلوتر باشد");
ShowDangerAlert("تاریخ پرداخت نمی تواند از امروز جلوتر باشد"); return false;
}