From b81c950c39949650d422d9efcc93397bdf77d6de Mon Sep 17 00:00:00 2001 From: mmrbnjd Date: Sun, 8 Sep 2024 17:23:33 +0330 Subject: [PATCH] ... --- Back/Controllers/InvoicePaymentController.cs | 54 ++- Back/Program.cs | 1 + Back/Services/servInvoice.cs | 94 ++--- Back/Services/servInvoicePayment.cs | 23 +- Back/Validations/AUInvoicePayValidation.cs | 50 +-- Shared/DTOs/InvoiceDtos.cs | 1 + TaxPayerFull/CUSComponent/InvoicePays.razor | 344 +++++++++++++++--- TaxPayerFull/FixedValues.cs | 15 + .../Pages/UserPanel/InvoiceItem.razor | 12 +- 9 files changed, 468 insertions(+), 126 deletions(-) diff --git a/Back/Controllers/InvoicePaymentController.cs b/Back/Controllers/InvoicePaymentController.cs index ece360f..9a19099 100644 --- a/Back/Controllers/InvoicePaymentController.cs +++ b/Back/Controllers/InvoicePaymentController.cs @@ -1,4 +1,5 @@ using Back.Common; +using Back.Data.Contracts; using Back.Data.Models; using Back.Services; using Back.Validations; @@ -10,6 +11,7 @@ using Shared.DTOs; using System.Net; using System.Runtime.ConstrainedExecution; using System.Security.Cryptography; +using static Shared.DTOs._TaxPayer; namespace Back.Controllers { @@ -31,8 +33,13 @@ namespace Back.Controllers _servInvoice = servInvoice; } + [HttpGet("PaymentMethods")] + public async Task>>> PaymentMethods() + { + return Ok(await _servpay.GetPaymentMethods()); + } [HttpPost("AddPay")] - public async Task> AddItem([FromBody] InvoiceItemAction model) + public async Task> AddItem([FromBody] InvoiceItemAction model) { //-----GetUserAndCompany var claim = HttpContext.User.Claims.First(c => c.Type == "UserID"); @@ -49,12 +56,15 @@ namespace Back.Controllers if (invoice == null) return BadRequest(new List { "invoice notFound..." }); + //-------------pmt + List codings = await _servInvoice.GetCodingPMT(); + //----------------------- invoice.LastChangeUserID = Convert.ToInt32(UserID); if (await _servInvoice.UpdateInvoice(invoice)) { - return Ok(await _servpay.Add(new Data.Models.InvoicePayment + var item = await _servpay.Add(new Data.Models.InvoicePayment { InvoiceID = model.invoiceID, acn = model.item.acn, @@ -68,7 +78,21 @@ namespace Back.Controllers trn = model.item.trn, - })); + }); + return Ok(item!=null ?new InvoicePaymentDTO + { + ID = item.ID, + acn = item.acn, + iinn = item.acn, + pcn = item.acn, + PaymentDateTime = item.PaymentDateTime.ShamciToFormatShamci(), + pid = item.pid, + pmt = item.pmt, + pv = item.pv, + trmn = item.trmn, + trn = item.acn, + paymentMethod = item.pmt.HasValue ? codings.Where(w => w.Code == item.pmt.Value.ToString()).Select(s => s.Title).FirstOrDefault() : null, + } :null); } else return BadRequest(new List { "خطایی رخ داده" }); @@ -124,7 +148,29 @@ namespace Back.Controllers item.trn = model.item.trn; if (await _servInvoice.UpdateInvoice(invoice)) - return Ok(await _servpay.Update(item)); + { + var modelout = await _servpay.Update(item); + + //-------------pmt + List codings = await _servInvoice.GetCodingPMT(); + //----------------------- + + return Ok(modelout!=null ? new InvoicePaymentDTO + { + ID = modelout.ID, + acn = modelout.acn, + iinn = modelout.acn, + pcn = modelout.acn, + PaymentDateTime = modelout.PaymentDateTime.ShamciToFormatShamci(), + pid = modelout.pid, + pmt = modelout.pmt, + pv = modelout.pv, + trmn = modelout.trmn, + trn = modelout.acn, + paymentMethod = modelout.pmt.HasValue ? codings.Where(w => w.Code == modelout.pmt.Value.ToString()).Select(s => s.Title).FirstOrDefault() : null, + } : null); + } + else return BadRequest(new List { "خطایی رخ داده" }); diff --git a/Back/Program.cs b/Back/Program.cs index 682d7f7..3406d17 100644 --- a/Back/Program.cs +++ b/Back/Program.cs @@ -82,6 +82,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(c => new mpNuget.RestClient("09119660045", "C54S2")); string origins = "OriginTaxPayer"; diff --git a/Back/Services/servInvoice.cs b/Back/Services/servInvoice.cs index b3f8a49..9663807 100644 --- a/Back/Services/servInvoice.cs +++ b/Back/Services/servInvoice.cs @@ -10,15 +10,20 @@ namespace Back.Services public class servInvoice { private readonly IAsyncRepository _invoiceRepo; + private readonly IAsyncRepository _CodingRepo; private readonly IAsyncRepository _invoiceStatusChangPaymentRepo; private readonly CheckPermission _checkPermission; public servInvoice(IAsyncRepository invoiceRepo, CheckPermission checkPermission - , IAsyncRepository invoiceStatusChangPaymentRepo) + , IAsyncRepository invoiceStatusChangPaymentRepo, IAsyncRepository codingRepo) { _invoiceStatusChangPaymentRepo = invoiceStatusChangPaymentRepo; _invoiceRepo = invoiceRepo; _checkPermission = checkPermission; - + _CodingRepo = codingRepo; + } + public async Task> GetCodingPMT() + { + return await _CodingRepo.Get(w => w.FildID == 71).ToListAsync(); } public async Task GetInvoice(int CompanyID, int ID, bool notloaddelete = true) { @@ -33,18 +38,16 @@ namespace Back.Services } #endregion //----------------------- - var item= await invok - .Include(inc => inc.invoiceDetails) - .ThenInclude(inc => inc.cODItem) - .ThenInclude(inc => inc.CODUnit) - .Include(inc => inc.Customer) - .Include(inc => inc.sentTax) - .Include(inc => inc.payments) - .Include(inc => inc.pattern) - .ThenInclude(inc => inc.BillType) - - .FirstOrDefaultAsync(); - return new InvoiceDTO() + var item = await invok.Include(inc => inc.invoiceDetails) .ThenInclude(inc => inc.cODItem).ThenInclude(inc => inc.CODUnit).Include(inc => inc.Customer) + .Include(inc => inc.sentTax).Include(inc => inc.payments).Include(inc => inc.pattern).ThenInclude(inc => inc.BillType).FirstOrDefaultAsync(); + + //-------------pmt + List codings = new List(); + if (item != null) + codings =await GetCodingPMT(); + //----------------------- + + return new InvoiceDTO() { IsDeleted = item.IsDeleted, @@ -66,33 +69,33 @@ namespace Back.Services tvam = item.tvam, Udate = item.Udate.ShamciToFormatShamci(), inno = item.inno, - InvoiceSendTaxs = item.sentTax.OrderBy(o => o.ID).Select(s => new SentTaxDto() - { - Date = s.Date.ShamciToFormatShamci(), - Time = s.Time, - ID = s.ID, - InvoiceID = s.InvoiceID, - SentStatus = s.SentStatus, - InvoiceType = s.InvoiceType, - msgInvoiceType = s.InvoiceType.GetEnumDisplayName(), - msgSentStatus = s.SentStatus.GetEnumDisplayName() - }).ToList(), - items = item.invoiceDetails.OrderBy(o => o.ID).Select(x => new InvoiceItemDTO() - { - ID = x.ID, - CODID = x.CODID, - adis = x.adis, - am = x.am.Value, - dis = x.dis, - fee = x.fee.Value, - mu = x.unitTitle, - sstt = x.sstt, - tsstam = x.tsstam, - vam = x.vam, - vra = x.vra, - prdis = x.prdis - }).ToList(), - payments = + InvoiceSendTaxs = item.sentTax.OrderBy(o => o.ID).Select(s => new SentTaxDto() + { + Date = s.Date.ShamciToFormatShamci(), + Time = s.Time, + ID = s.ID, + InvoiceID = s.InvoiceID, + SentStatus = s.SentStatus, + InvoiceType = s.InvoiceType, + msgInvoiceType = s.InvoiceType.GetEnumDisplayName(), + msgSentStatus = s.SentStatus.GetEnumDisplayName() + }).ToList(), + items = item.invoiceDetails.OrderBy(o => o.ID).Select(x => new InvoiceItemDTO() + { + ID = x.ID, + CODID = x.CODID, + adis = x.adis, + am = x.am.Value, + dis = x.dis, + fee = x.fee.Value, + mu = x.unitTitle, + sstt = x.sstt, + tsstam = x.tsstam, + vam = x.vam, + vra = x.vra, + prdis = x.prdis + }).ToList(), + payments = item.payments.OrderBy(o => o.ID).Select(x => new InvoicePaymentDTO() { ID = x.ID, @@ -104,9 +107,10 @@ namespace Back.Services pmt = x.pmt, pv = x.pv, trmn = x.trmn, - trn = x.acn + trn = x.acn, + paymentMethod = x.pmt.HasValue ? codings.Where(w=>w.Code== x.pmt.Value.ToString()).Select(s=>s.Title).FirstOrDefault() : null, }).ToList() - }; + }; } @@ -144,7 +148,7 @@ namespace Back.Services .ThenInclude(inc => inc.CODUnit) //.Include(inc => inc.payments) .Include(inc => inc.pattern) - .OrderByDescending(o=>o.ID) + .OrderByDescending(o => o.ID) .Select(s => new InvoiceGridDTO() { @@ -232,7 +236,7 @@ namespace Back.Services .Include(inc => inc.sentTax) .Include(inc => inc.pattern) .Include(inc => inc.invoice) - .Include(inc=>inc.payments) + .Include(inc => inc.payments) .FirstOrDefaultAsync(); } public async Task DeleteInvoice(Invoice item) diff --git a/Back/Services/servInvoicePayment.cs b/Back/Services/servInvoicePayment.cs index beaeaea..153dc4a 100644 --- a/Back/Services/servInvoicePayment.cs +++ b/Back/Services/servInvoicePayment.cs @@ -9,17 +9,19 @@ namespace Back.Services public class servInvoicePayment { private readonly IAsyncRepository _Repo; - public servInvoicePayment(IAsyncRepository Repo) + private readonly IAsyncRepository _CodingRepo; + public servInvoicePayment(IAsyncRepository Repo, IAsyncRepository CodingRepo) { _Repo = Repo; + _CodingRepo = CodingRepo; } - public async Task Add(InvoicePayment item) + public async Task Add(InvoicePayment item) { - return await _Repo.AddBoolResultAsync(item); + return await _Repo.AddAsync(item); } - public async Task Update(InvoicePayment item) + public async Task Update(InvoicePayment item) { - return await _Repo.UpdateAsync(item); + return await _Repo.UpdateByObjAsync(item); } public async Task Delete(InvoicePayment item) { @@ -40,6 +42,15 @@ namespace Back.Services { return await _Repo.Get(w => w.InvoiceID == invoiceID && w.ID == ID && w.invoice.CompanyID == companyID).FirstOrDefaultAsync(); } - + public async Task>> GetPaymentMethods() + { + return await _CodingRepo.Get(w => w.FildID == 71) + .Select(s=>new IdName + { + ID=s.Code,Title=s.Title + }).ToListAsync(); + } + + } } diff --git a/Back/Validations/AUInvoicePayValidation.cs b/Back/Validations/AUInvoicePayValidation.cs index 24a0ce4..f9be89b 100644 --- a/Back/Validations/AUInvoicePayValidation.cs +++ b/Back/Validations/AUInvoicePayValidation.cs @@ -23,29 +23,7 @@ namespace Back.Validations }); }); - When(m => m.Item4 == eActionValidation.update || m.Item4 == eActionValidation.add, () => - { - - - RuleFor(r => r.Item3).Custom((model, context) => - { - if (model.pmt.HasValue && model.pmt.Value > 0 && model.pmt.Value < 9) - { - - } - else context.AddFailure("روش پرداخت مشخص نشده"); - }); - - //RuleFor(r => r).Custom(async (model, context) => - //{ - // if (model.Item3.dis != null && model.Item3.dis > 0) - // if (model.Item3.dis > model.Item3.am * model.Item3.fee) - // context.AddFailure("مبلغ تخفیف نمی تواند از (تعداد * مبلغ واحد) بیشتر باشد"); - - - //}); - }); RuleFor(r => r) .Custom((model, context) => { @@ -61,7 +39,33 @@ namespace Back.Validations if (model.Item4 == eActionValidation.update || model.Item4 == eActionValidation.add) { var totalpay = invoice.payments.Sum(s => s.pv).GetValueOrDefault() + model.Item3.pv; - if (totalpay > invoice.tbill) context.AddFailure("مجموع مبلغ پرداختی میبایست از مجموع صورتحساب کوچکتر باشد."); + if (totalpay > invoice.tbill) context.AddFailure("مجموع مبلغ پرداختی نمی تواند از مجموع صورتحساب بیشتر باشد."); + else + { + if (model.Item3.pmt.HasValue && model.Item3.pmt.Value > 0 && model.Item3.pmt.Value < 9) + { + if (string.IsNullOrEmpty(model.Item3.PaymentDateTime)) + { + context.AddFailure("تاریخ نمیتواند خالی باشد"); + } + else + { + string paydate = model.Item3.PaymentDateTime.Replace("/", ""); + if (paydate.Length == 8 && int.TryParse(paydate, out int _paydate)) + { + if (Convert.ToInt32(invoice.InvoiceDate) > _paydate) + { + context.AddFailure("تاریخ پرداخت نمیتواند از تاریخ صورتحساب عقبتر باشد"); + } + + } + else context.AddFailure("تاریخ صحیح نمی باشد"); + } + + } + else context.AddFailure("روش پرداخت مشخص نشده"); + } + } diff --git a/Shared/DTOs/InvoiceDtos.cs b/Shared/DTOs/InvoiceDtos.cs index 79bf618..cd28c63 100644 --- a/Shared/DTOs/InvoiceDtos.cs +++ b/Shared/DTOs/InvoiceDtos.cs @@ -131,6 +131,7 @@ namespace Shared.DTOs //روش پرداخت [MaxLength(2)] public int? pmt { get; set; } + public string? paymentMethod { get; set; } //شماره پیگیری/شماره مرجع [MaxLength(14)] public string? trn { get; set; } diff --git a/TaxPayerFull/CUSComponent/InvoicePays.razor b/TaxPayerFull/CUSComponent/InvoicePays.razor index 0d172f2..944f406 100644 --- a/TaxPayerFull/CUSComponent/InvoicePays.razor +++ b/TaxPayerFull/CUSComponent/InvoicePays.razor @@ -1,81 +1,331 @@ -@using Shared.DTOs +@using Front.Services +@using Shared.DTOs +@inject Fixedvalues fv; +@inject HttpClientController hc; + Data="invoice.payments" + OnRowClick="OnRowClick"> - - @context.ID - - + @context.iinn - + @context.acn - + @context.trmn - - @context.pmt + + @context.paymentMethod - + @context.trn - + @context.pcn - + @context.pid - + @context.PaymentDateTime - + @context.pv??.ToString("N0") - +
+
+ @if (add) + { + + } + else + { + + } -@code { - [Parameter] public ICollection payments { get; set; } - Grid grid = default!; +
+
+
+
+
+
+
+ + +
+
+ + + +
+
+ + +
+
+
+
+ + +
+
+ + + +
+
+ + +
+
+
+
+ + +
+
+ + + +
+
+ + +
+
+
+ @if (add) { - // payments = new List(); +
+ +
+ } + else + { +
+ +
+
+ +
+
+ +
+ } } - // private async Task AddEmployee() - // { - // // for the same employees collection, we are adding an object - // // explicit grid refresh required - // employees!.Add(CreateEmployee()); - // await grid.RefreshDataAsync(); - // } +
- // private void AddEmployee2() - // { - // // creates a shallow copy - // var emps = employees!.GetRange(0, employees.Count); - // emps.Add(CreateEmployee()); - // // now employees variable has a new reference. So no need to refresh the grid explicitly - // // explicit grid refresh is not required - // employees = emps; - // } +@* alert *@ +
+ - // private Employee1 CreateEmployee() - // { - // var emp = new Employee1(); - // emp.Id = employees!.Max(x => x.Id) + 1; - // emp.Name = $"Employee {emp.Id}"; - // emp.Designation = $"QA Engineer {emp.Id}"; - // emp.DOJ = new DateOnly(new Random().Next(1970, 2000), new Random().Next(1, 12), new Random().Next(1, 25)); - // emp.IsActive = true; - // return emp; - // } +
+@code { + bool add = true; + [Parameter] public InvoiceDTO invoice { get; set; } + Grid grid = default!; + InvoicePaymentDTO item; + List> pmts; + // alert + AlertColor alertColor = AlertColor.Primary; + IconName alertIconName = IconName.CheckCircleFill; + bool Hidealert = true; + string alertMessage = ""; + + protected override async Task OnParametersSetAsync() + { + item = new InvoicePaymentDTO(); + pmts = await fv.GetPaymentMethods(); + await base.OnParametersSetAsync(); + } +} +@functions { + private async Task OnRowClick(GridRowEventArgs args) + { + item = args.Item; + add = false; + } + async Task cancell() + { + add = true; + item = new InvoicePaymentDTO(); + } + async Task AddPay() + { + if (await Validation()) + { + var rsp = await hc.Post("InvoicePayment/AddPay", item); + if (rsp.IsSuccessStatusCode) + { + var request = await rsp.Content.ReadFromJsonAsync(); + + 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>(); + ShowDangerAlert(request[0]); + } + } + + + + } + async Task UpdatePay() + { + if (await Validation()) + { + var rsp = await hc.Put("InvoicePayment/UpdatePay", item); + if (rsp.IsSuccessStatusCode) + { + var request = await rsp.Content.ReadFromJsonAsync(); + + 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>(); + 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(); + + if (request) + { + invoice.payments.Add(item); + await grid.RefreshDataAsync(); + item = new InvoicePaymentDTO(); + } + + else ShowDangerAlert("خطایی در اجرای عملیات رخ داده"); + } + else + { + + var request = await rsp.Content.ReadFromJsonAsync>(); + ShowDangerAlert(request[0]); + } + } + } + private void ShowSuccessAlert(string msg) + { + Hidealert = false; + alertColor = AlertColor.Success; + alertIconName = IconName.CheckCircleFill; + alertMessage = msg; + } + private void ShowDangerAlert(string msg) + { + Hidealert = false; + alertColor = AlertColor.Danger; + alertIconName = IconName.ExclamationTriangleFill; + alertMessage = msg; + } + async Task Validation() + { + 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)) + { + if (Convert.ToInt32(invoice.InvoiceDate.Replace("/", "")) > _paydate) + { + ShowDangerAlert("تاریخ پرداخت نمیتواند از تاریخ صورتحساب عقبتر باشد"); + return false; + } + + } + else { ShowDangerAlert("تاریخ صحیح نمی باشد"); return false; } + } + + } + else { ShowDangerAlert("روش پرداخت مشخص نشده"); return false; } + + + return true; + } } \ No newline at end of file diff --git a/TaxPayerFull/FixedValues.cs b/TaxPayerFull/FixedValues.cs index 8c4487a..69b2257 100644 --- a/TaxPayerFull/FixedValues.cs +++ b/TaxPayerFull/FixedValues.cs @@ -12,6 +12,7 @@ namespace Front public readonly HttpClientController _hc; private List? Cus = null; private List>? Patterns = null; + private List>? PaymentMethods = null; private List>? Patternsbyinp = null; private List>? BillTypes = null; private List>? UnitsbyUnitTaxID = null; @@ -71,6 +72,20 @@ namespace Front return Patterns; } + public async Task>?> GetPaymentMethods() + { + if (PaymentMethods == null) + { + var request = await _hc.Get($"InvoicePayment/PaymentMethods"); + if (request.IsSuccessStatusCode) + { + PaymentMethods = await request.Content.ReadFromJsonAsync>>(); + } + } + + + return PaymentMethods; + } public async Task>?> GetPatternsbyinp() { if (Patternsbyinp == null) diff --git a/TaxPayerFull/Pages/UserPanel/InvoiceItem.razor b/TaxPayerFull/Pages/UserPanel/InvoiceItem.razor index 1046993..7cebc7b 100644 --- a/TaxPayerFull/Pages/UserPanel/InvoiceItem.razor +++ b/TaxPayerFull/Pages/UserPanel/InvoiceItem.razor @@ -366,7 +366,7 @@
-
+
@if (!invoice.IsDeleted && invoice.invoiceType != InvoiceType.Bidding && SendInvoice) {
@@ -469,6 +469,8 @@ { if (InvoiceID.HasValue) { + modal.Size = ModalSize.Large; + var parameters = new Dictionary(); parameters.Add("InvoiceID", InvoiceID); @@ -481,6 +483,14 @@ } private async Task OnClickPayment() { + if (invoice!=null) + { + modal.Size = ModalSize.ExtraLarge; + var parameters = new Dictionary(); + parameters.Add("invoice", invoice); + await modal.ShowAsync("پرداختی ها", parameters: parameters); + } + } private async Task CopyInvoice()