diff --git a/Back/Validations/AUInvoicePayValidation.cs b/Back/Validations/AUInvoicePayValidation.cs index f9be89b..707f41a 100644 --- a/Back/Validations/AUInvoicePayValidation.cs +++ b/Back/Validations/AUInvoicePayValidation.cs @@ -27,19 +27,24 @@ namespace Back.Validations RuleFor(r => r) .Custom((model, context) => { - if (model.Item2 != null && model.Item2 > 0) - { - var invoice = servInvoice.GetInvoiceByInvoiceID(model.Item1, model.Item2).Result; - if (invoice == null) - context.AddFailure("صورتحساب یافت نشد"); - - - else + if (model.Item2 != null && model.Item2 > 0) { - if (model.Item4 == eActionValidation.update || model.Item4 == eActionValidation.add) + var invoice = servInvoice.GetInvoiceByInvoiceID(model.Item1, model.Item2).Result; + if (invoice == null) + context.AddFailure("صورتحساب یافت نشد"); + + + else { - var totalpay = invoice.payments.Sum(s => s.pv).GetValueOrDefault() + model.Item3.pv; - if (totalpay > invoice.tbill) context.AddFailure("مجموع مبلغ پرداختی نمی تواند از مجموع صورتحساب بیشتر باشد."); + if (model.Item4 == eActionValidation.update || model.Item4 == eActionValidation.add) + { + if (model.Item3.pv <= 0) + { + context.AddFailure("مبلغ پرداختی باید بیشتر از صفر باشد."); + } + + var totalpay = invoice.payments.Sum(s => s.pv).GetValueOrDefault() + model.Item3.pv; + if (totalpay > invoice.tbill) context.AddFailure("مجموع مبلغ پرداختی نمی تواند از مجموع صورتحساب بیشتر باشد."); else { if (model.Item3.pmt.HasValue && model.Item3.pmt.Value > 0 && model.Item3.pmt.Value < 9) @@ -50,13 +55,23 @@ namespace Back.Validations } else { + var today = Convert.ToInt32(DateTime.Now.ConvertMiladiToShamsi()); string paydate = model.Item3.PaymentDateTime.Replace("/", ""); + if (paydate.Length == 8 && int.TryParse(paydate, out int _paydate)) { - if (Convert.ToInt32(invoice.InvoiceDate) > _paydate) + if (today >= _paydate) { - context.AddFailure("تاریخ پرداخت نمیتواند از تاریخ صورتحساب عقبتر باشد"); + if (Convert.ToInt32(invoice.InvoiceDate) > _paydate) + { + context.AddFailure("تاریخ پرداخت نمیتواند از تاریخ صورتحساب عقبتر باشد"); + } } + else + { + context.AddFailure("تاریخ پرداخت نمی تواند از امروز جلوتر باشد"); + } + } else context.AddFailure("تاریخ صحیح نمی باشد"); @@ -67,7 +82,7 @@ namespace Back.Validations } - } + } if (servTaxPayer.ExistSuccessfulorSendorpendingInvoice(invoice).Result) context.AddFailure("این صورتحساب به سازمان ارسال شده" + '\n' + diff --git a/Shared/DTOs/InvoiceDtos.cs b/Shared/DTOs/InvoiceDtos.cs index cd28c63..49e2e35 100644 --- a/Shared/DTOs/InvoiceDtos.cs +++ b/Shared/DTOs/InvoiceDtos.cs @@ -120,31 +120,31 @@ namespace Shared.DTOs public class InvoicePaymentDTO { public int? ID { get; set; } - [MaxLength(9)] + //[MaxLength(9)] public string? iinn { get; set; } //شماره پذیرنده فروشگاهی - [MaxLength(14)] + //[MaxLength(14)] public string? acn { get; set; } //شماره پایانه - [MaxLength(8)] + //[MaxLength(8)] public string? trmn { get; set; } //روش پرداخت - [MaxLength(2)] + //[MaxLength(2)] public int? pmt { get; set; } public string? paymentMethod { get; set; } //شماره پیگیری/شماره مرجع - [MaxLength(14)] + //[MaxLength(14)] public string? trn { get; set; } //شماره کارت پرداخت کننده صورتحساب - [MaxLength(16)] + //[MaxLength(16)] public string? pcn { get; set; } //شماره/شناسه ملی/کد فراگیر اتباع غیر ایرانی پرداخت کننده صورتحساب [MaxLength(12)] public string? pid { get; set; } //تاریخ و زمان پرداخت - public string? PaymentDateTime { get; set; } + public string? PaymentDateTime { get; set; } = DateTime.Now.ConvertMiladiToShamsiinFront().ShamciToFormatShamciinFront(); //مبلغ پرداختی - [MaxLength(18)] + //[MaxLength(18)] public long? pv { get; set; } } diff --git a/TaxPayerFull/CUSComponent/InvoicePays.razor b/TaxPayerFull/CUSComponent/InvoicePays.razor index 944f406..bf2fe6e 100644 --- a/TaxPayerFull/CUSComponent/InvoicePays.razor +++ b/TaxPayerFull/CUSComponent/InvoicePays.razor @@ -1,4 +1,5 @@ @using Front.Services +@using Shared @using Shared.DTOs @inject Fixedvalues fv; @inject HttpClientController hc; @@ -7,7 +8,8 @@ TItem="InvoicePaymentDTO" Class="table table-hover table-bordered table-striped mt-3" Data="invoice.payments" - OnRowClick="OnRowClick"> + OnRowClick="OnRowClick" + Responsive="true"> @@ -34,8 +36,8 @@ @context.PaymentDateTime - - @context.pv??.ToString("N0") + + @context.pv.Value.ToString("N0") @@ -128,6 +130,14 @@ +
+
+ +
+
@if (add) { @@ -151,22 +161,15 @@
} - } + -@* alert *@ -
- -
@code { bool add = true; [Parameter] public InvoiceDTO invoice { get; set; } @@ -182,6 +185,7 @@ protected override async Task OnParametersSetAsync() { item = new InvoicePaymentDTO(); + pmts = await fv.GetPaymentMethods(); await base.OnParametersSetAsync(); } @@ -199,9 +203,15 @@ } async Task AddPay() { + if (await Validation()) { - var rsp = await hc.Post("InvoicePayment/AddPay", item); + var sentItem = new InvoiceItemAction() + { + invoiceID = invoice.ID, + item = item + }; + var rsp = await hc.Post>("InvoicePayment/AddPay", sentItem); if (rsp.IsSuccessStatusCode) { var request = await rsp.Content.ReadFromJsonAsync(); @@ -230,7 +240,11 @@ { if (await Validation()) { - var rsp = await hc.Put("InvoicePayment/UpdatePay", item); + var rsp = await hc.Put>("InvoicePayment/UpdatePay", new InvoiceItemAction() + { + invoiceID = invoice.ID, + item = item + }); if (rsp.IsSuccessStatusCode) { var request = await rsp.Content.ReadFromJsonAsync(); @@ -294,6 +308,10 @@ } async Task Validation() { + if (item.pv<=0) + { + ShowDangerAlert("مبلغ پرداختی باید بیشتر از صفر باشد."); + } if (invoice.tbill < invoice.payments.Sum(s => s.pv) + item.pv) { ShowDangerAlert("مجموع مبلغ پرداختی نمی تواند از مجموع صورتحساب بیشتر باشد."); @@ -312,11 +330,20 @@ string paydate = item.PaymentDateTime.Replace("/", ""); if (paydate.Length == 8 && int.TryParse(paydate, out int _paydate)) { - if (Convert.ToInt32(invoice.InvoiceDate.Replace("/", "")) > _paydate) + var today = Convert.ToInt32(DateTime.Now.ConvertMiladiToShamsiinFront()); + if (today >= _paydate) { - ShowDangerAlert("تاریخ پرداخت نمیتواند از تاریخ صورتحساب عقبتر باشد"); - return false; + if (Convert.ToInt32(invoice.InvoiceDate.Replace("/", "")) > _paydate) + { + ShowDangerAlert("تاریخ پرداخت نمیتواند از تاریخ صورتحساب عقبتر باشد"); + return false; + } } + else + { + ShowDangerAlert("تاریخ پرداخت نمی تواند از امروز جلوتر باشد"); + } + } else { ShowDangerAlert("تاریخ صحیح نمی باشد"); return false; } diff --git a/TaxPayerFull/Program.cs b/TaxPayerFull/Program.cs index b3c5965..9180e1b 100644 --- a/TaxPayerFull/Program.cs +++ b/TaxPayerFull/Program.cs @@ -36,10 +36,10 @@ builder.Services.AddScoped(sp => new UserAuthenticationDTO() //builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://195.88.208.142:7075/api/") }); //Home -//builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("https://localhost:7075/api/") }); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("https://localhost:7075/api/") }); //farzan -builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://localhost:5271/api/") }); +//builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://localhost:5271/api/") }); CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("fa-Ir");