Files
moadiran/TaxPayerFull/CUSComponent/InvoicePays.razor

358 lines
14 KiB
Plaintext
Raw Normal View History

2024-09-08 17:23:33 +03:30
@using Front.Services
2024-09-08 21:50:17 +03:30
@using Shared
2024-09-08 17:23:33 +03:30
@using Shared.DTOs
@inject Fixedvalues fv;
@inject HttpClientController hc;
2024-09-07 16:50:34 +03:30
<Grid @ref="grid"
TItem="InvoicePaymentDTO"
Class="table table-hover table-bordered table-striped mt-3"
2024-09-08 17:23:33 +03:30
Data="invoice.payments"
2024-09-08 21:50:17 +03:30
OnRowClick="OnRowClick"
Responsive="true">
2024-09-07 16:50:34 +03:30
<GridColumns>
2024-09-08 17:23:33 +03:30
<GridColumn TItem="InvoicePaymentDTO" TextAlignment="Alignment.Center" HeaderTextAlignment="Alignment.Center" HeaderText="شماره سوییچ پرداخت" PropertyName="iinn">
2024-09-07 16:50:34 +03:30
@context.iinn
</GridColumn>
2024-09-08 17:23:33 +03:30
<GridColumn TItem="InvoicePaymentDTO" TextAlignment="Alignment.Center" HeaderTextAlignment="Alignment.Center" HeaderText="شماره پذیرنده فروشگاهی" PropertyName="acn">
2024-09-07 16:50:34 +03:30
@context.acn
</GridColumn>
2024-09-08 17:23:33 +03:30
<GridColumn TItem="InvoicePaymentDTO" TextAlignment="Alignment.Center" HeaderTextAlignment="Alignment.Center" HeaderText="شماره پایانه" PropertyName="trmn">
2024-09-07 16:50:34 +03:30
@context.trmn
</GridColumn>
2024-09-08 17:23:33 +03:30
<GridColumn TItem="InvoicePaymentDTO" TextAlignment="Alignment.Center" HeaderTextAlignment="Alignment.Center" HeaderText="روش پرداخت" PropertyName="paymentMethod">
@context.paymentMethod
2024-09-07 16:50:34 +03:30
</GridColumn>
2024-09-08 17:23:33 +03:30
<GridColumn TItem="InvoicePaymentDTO" TextAlignment="Alignment.Center" HeaderTextAlignment="Alignment.Center" HeaderText="شماره پیگیری/شماره مرجع" PropertyName="trn">
2024-09-07 16:50:34 +03:30
@context.trn
</GridColumn>
2024-09-08 17:23:33 +03:30
<GridColumn TItem="InvoicePaymentDTO" TextAlignment="Alignment.Center" HeaderTextAlignment="Alignment.Center" HeaderText="شماره کارت" PropertyName="pcn">
2024-09-07 16:50:34 +03:30
@context.pcn
</GridColumn>
2024-09-08 17:23:33 +03:30
<GridColumn TItem="InvoicePaymentDTO" TextAlignment="Alignment.Center" HeaderTextAlignment="Alignment.Center" HeaderText="شماره/شناسه ملی/کد فراگیر اتباع غیر ایرانی" PropertyName="pid">
2024-09-07 16:50:34 +03:30
@context.pid
</GridColumn>
2024-09-08 17:23:33 +03:30
<GridColumn TItem="InvoicePaymentDTO" TextAlignment="Alignment.Center" HeaderTextAlignment="Alignment.Center" HeaderText="تاریخ" PropertyName="PaymentDateTime">
2024-09-07 16:50:34 +03:30
@context.PaymentDateTime
</GridColumn>
2024-09-08 21:50:17 +03:30
<GridColumn TItem="InvoicePaymentDTO" TextAlignment="Alignment.Center" HeaderTextAlignment="Alignment.Center" HeaderText="مبلغ(ریال)" PropertyName="pv">
@context.pv.Value.ToString("N0")
2024-09-07 16:50:34 +03:30
</GridColumn>
</GridColumns>
</Grid>
2024-09-08 17:23:33 +03:30
<div class="row g-3">
<div class="form-group col-md-1">
@if (add)
{
<label class="col-sm-6 col-form-label">جدید</label>
}
else
{
<label class="col-sm-6 col-form-label">اطلاعات پرداخت</label>
}
</div>
<div class="form-group col-md-11">
<hr class="hr" />
</div>
</div>
<div class="row g-3">
<div class="form-group col-md-4">
<label class="col-sm-6 col-form-label">شماره سوییچ پرداخت</label>
<InputText onkeypress="return event.charCode &gt;= 48 &amp;&amp; event.charCode &lt;= 57" style="text-align: center" maxlength="9" class="form-control" @bind-Value="item.iinn" Placeholder="شماره سوییچ پرداخت" />
</div>
<div class="form-group col-md-4">
<label class="col-sm-6 col-form-label">شماره پذیرنده فروشگاهی</label>
<InputText onkeypress="return event.charCode &gt;= 48 &amp;&amp; event.charCode &lt;= 57" style="text-align: center" maxlength="14" type="text" class="form-control" @bind-Value="item.acn" Placeholder="شماره پذیرنده فروشگاهی" />
</div>
<div class="form-group col-md-4">
<label class="col-sm-6 col-form-label">شماره پایانه</label>
<InputText onkeypress="return event.charCode &gt;= 48 &amp;&amp; event.charCode &lt;= 57" style="text-align: center" maxlength="8" type="text" class="form-control" @bind-Value="item.trmn" Placeholder="شماره پایانه" />
</div>
</div>
<div class="row g-3">
<div class="form-group col-md-4">
<label class="col-sm-4 col-form-label" for="inputinvoicepmt">روش پرداخت</label>
<select @bind="item.pmt" class="form-control" aria-label="Default select example" id="inputinvoicepmt">
@if (!item.pmt.HasValue)
{
<option value="0" style="color: #b5b5b5" selected>انتخاب کنید...</option>
}
else
{
<option value="0" style="color: #b5b5b5">انتخاب کنید...</option>
}
@if (pmts != null)
{
foreach (var _item in pmts)
{
if (item.pmt == Convert.ToInt32(_item.ID))
{
<option value="@_item.ID" selected>@_item.Title</option>
}
else
{
<option value="@_item.ID">@_item.Title</option>
}
}
}
2024-09-07 16:50:34 +03:30
2024-09-08 17:23:33 +03:30
</select>
</div>
<div class="form-group col-md-4">
<label class="col-sm-6 col-form-label">شماره پیگیری/شماره مرجع</label>
<InputText onkeypress="return event.charCode &gt;= 48 &amp;&amp; event.charCode &lt;= 57" style="text-align: center" maxlength="14" type="text" class="form-control" @bind-Value="item.trn" Placeholder="شماره پیگیری/شماره مرجع" />
</div>
<div class="form-group col-md-4">
<label class="col-sm-6 col-form-label">شماره کارت</label>
<InputText onkeypress="return event.charCode &gt;= 48 &amp;&amp; event.charCode &lt;= 57" style="text-align: center" maxlength="16" type="text" class="form-control" @bind-Value="item.pcn" Placeholder="شماره کارت" />
</div>
</div>
<div class="row g-3">
<div class="form-group col-md-4">
<label class="col-sm-10 col-form-label">شماره/شناسه ملی/کد فراگیر اتباع غیر ایرانی</label>
<InputText onkeypress="return event.charCode &gt;= 48 &amp;&amp; event.charCode &lt;= 57" style="text-align: center" maxlength="12" type="text" class="form-control" @bind-Value="item.pid" Placeholder="شماره/شناسه ملی/کد فراگیر اتباع غیر ایرانی" />
</div>
<div class="form-group col-md-4">
<label class="col-sm-6 col-form-label">تاریخ</label>
<InputText type="text" style="text-align: center" class="form-control" @bind-Value="item.PaymentDateTime" Placeholder="تاریخ" />
</div>
<div class="form-group col-md-4">
<label class="col-sm-6 col-form-label">مبلغ</label>
<CurrencyInput TValue="long?" @bind-Value="item.pv" Locale="fa-Ir" Placeholder="مبلغ" style="text-align: center" />
</div>
</div>
2024-09-08 21:50:17 +03:30
<div class="row g-3">
<div class="form-group col-md-4">
<Alert hidden="@Hidealert" Color="@alertColor" Dismissable="false">
<Icon Name="@alertIconName" class="me-2"></Icon>
@alertMessage
</Alert>
</div>
</div>
2024-09-08 17:23:33 +03:30
<div class="row g-3">
@if (add)
{
<div class="form-group col-md-2">
<Button class="mt-3" Color="ButtonColor.Success" @onclick="AddPay" Type="ButtonType.Button">
جدید
</Button>
</div>
}
else
{
<div class="form-group col-md-2">
<Button class="mt-3" Color="ButtonColor.Info" @onclick="AddPay" 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>
</div>
<div class="form-group col-md-2">
<Button class="mt-3" Color="ButtonColor.Primary" @onclick="cancell" Type="ButtonType.Button">
2024-09-08 21:50:17 +03:30
انصراف
2024-09-08 17:23:33 +03:30
</Button>
</div>
}
2024-09-08 21:50:17 +03:30
2024-09-08 17:23:33 +03:30
</div>
2024-09-07 16:50:34 +03:30
@code {
2024-09-08 17:23:33 +03:30
bool add = true;
[Parameter] public InvoiceDTO invoice { get; set; }
2024-09-07 16:50:34 +03:30
Grid<InvoicePaymentDTO> grid = default!;
2024-09-08 17:23:33 +03:30
InvoicePaymentDTO item;
List<IdName<string>> pmts;
// alert
AlertColor alertColor = AlertColor.Primary;
IconName alertIconName = IconName.CheckCircleFill;
bool Hidealert = true;
string alertMessage = "";
2024-09-07 16:50:34 +03:30
2024-09-08 17:23:33 +03:30
protected override async Task OnParametersSetAsync()
{
item = new InvoicePaymentDTO();
2024-09-08 21:50:17 +03:30
2024-09-08 17:23:33 +03:30
pmts = await fv.GetPaymentMethods();
await base.OnParametersSetAsync();
}
}
@functions {
private async Task OnRowClick(GridRowEventArgs<InvoicePaymentDTO> args)
{
item = args.Item;
add = false;
}
async Task cancell()
{
add = true;
item = new InvoicePaymentDTO();
}
async Task AddPay()
{
2024-09-08 21:50:17 +03:30
2024-09-08 17:23:33 +03:30
if (await Validation())
{
2024-09-08 21:50:17 +03:30
var sentItem = new InvoiceItemAction<InvoicePaymentDTO>()
{
invoiceID = invoice.ID,
item = item
};
var rsp = await hc.Post<InvoiceItemAction<InvoicePaymentDTO>>("InvoicePayment/AddPay", sentItem);
2024-09-08 17:23:33 +03:30
if (rsp.IsSuccessStatusCode)
{
var request = await rsp.Content.ReadFromJsonAsync<InvoicePaymentDTO>();
2024-09-07 16:50:34 +03:30
2024-09-08 17:23:33 +03:30
if (request != null && request.ID.HasValue)
{
invoice.payments.Add(request);
await grid.RefreshDataAsync();
item = new InvoicePaymentDTO();
}
else ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
}
else
{
var request = await rsp.Content.ReadFromJsonAsync<List<string>>();
ShowDangerAlert(request[0]);
}
}
}
async Task UpdatePay()
{
if (await Validation())
{
2024-09-08 21:50:17 +03:30
var rsp = await hc.Put<InvoiceItemAction<InvoicePaymentDTO>>("InvoicePayment/UpdatePay", new InvoiceItemAction<InvoicePaymentDTO>()
{
invoiceID = invoice.ID,
item = item
});
2024-09-08 17:23:33 +03:30
if (rsp.IsSuccessStatusCode)
{
var request = await rsp.Content.ReadFromJsonAsync<InvoicePaymentDTO>();
if (request != null && request.ID.HasValue)
{
invoice.payments.Add(request);
await grid.RefreshDataAsync();
item = new InvoicePaymentDTO();
}
else ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
}
else
{
var request = await rsp.Content.ReadFromJsonAsync<List<string>>();
ShowDangerAlert(request[0]);
}
}
}
async Task DeletePay()
{
if (item.ID.HasValue)
{
var rsp = await hc.Delete($"InvoicePayment/DeletePay/{item.ID.Value}");
if (rsp.IsSuccessStatusCode)
{
var request = await rsp.Content.ReadFromJsonAsync<bool>();
if (request)
{
invoice.payments.Add(item);
await grid.RefreshDataAsync();
item = new InvoicePaymentDTO();
}
else ShowDangerAlert("خطایی در اجرای عملیات رخ داده");
}
else
{
var request = await rsp.Content.ReadFromJsonAsync<List<string>>();
ShowDangerAlert(request[0]);
}
}
}
private void ShowSuccessAlert(string msg)
{
Hidealert = false;
alertColor = AlertColor.Success;
alertIconName = IconName.CheckCircleFill;
alertMessage = msg;
}
private void ShowDangerAlert(string msg)
2024-09-07 16:50:34 +03:30
{
2024-09-08 17:23:33 +03:30
Hidealert = false;
alertColor = AlertColor.Danger;
alertIconName = IconName.ExclamationTriangleFill;
alertMessage = msg;
2024-09-07 16:50:34 +03:30
}
2024-09-08 17:23:33 +03:30
async Task<bool> Validation()
{
2024-09-08 21:50:17 +03:30
if (item.pv<=0)
{
ShowDangerAlert("مبلغ پرداختی باید بیشتر از صفر باشد.");
}
2024-09-08 17:23:33 +03:30
if (invoice.tbill < invoice.payments.Sum(s => s.pv) + item.pv)
{
ShowDangerAlert("مجموع مبلغ پرداختی نمی تواند از مجموع صورتحساب بیشتر باشد.");
return false;
}
if (item.pmt.HasValue && item.pmt.Value > 0 && item.pmt.Value < 9)
{
if (string.IsNullOrEmpty(item.PaymentDateTime))
{
ShowDangerAlert("تاریخ نمیتواند خالی باشد");
return false;
}
else
{
string paydate = item.PaymentDateTime.Replace("/", "");
if (paydate.Length == 8 && int.TryParse(paydate, out int _paydate))
{
2024-09-08 21:50:17 +03:30
var today = Convert.ToInt32(DateTime.Now.ConvertMiladiToShamsiinFront());
if (today >= _paydate)
2024-09-08 17:23:33 +03:30
{
2024-09-08 21:50:17 +03:30
if (Convert.ToInt32(invoice.InvoiceDate.Replace("/", "")) > _paydate)
{
ShowDangerAlert("تاریخ پرداخت نمیتواند از تاریخ صورتحساب عقبتر باشد");
return false;
}
2024-09-08 17:23:33 +03:30
}
2024-09-08 21:50:17 +03:30
else
{
ShowDangerAlert("تاریخ پرداخت نمی تواند از امروز جلوتر باشد");
}
2024-09-08 17:23:33 +03:30
}
else { ShowDangerAlert("تاریخ صحیح نمی باشد"); return false; }
}
2024-09-07 16:50:34 +03:30
2024-09-08 17:23:33 +03:30
}
else { ShowDangerAlert("روش پرداخت مشخص نشده"); return false; }
return true;
}
2024-09-07 16:50:34 +03:30
}