From acab592172909bfd26bc8fb9fd7cb39f7ff7a4ce Mon Sep 17 00:00:00 2001 From: mmrbnjd Date: Sun, 28 Jul 2024 17:31:40 +0330 Subject: [PATCH] ... --- Back/Controllers/InvoiceController.cs | 84 +++++++++++++++++++- Back/Controllers/OrdersController.cs | 57 +++++++++++++ Back/Services/ServOrders.cs | 13 +++ Back/Services/ServPromotion.cs | 6 ++ TaxPayerFull/CUSComponent/OrderItemNew.razor | 40 +++++++++- 5 files changed, 194 insertions(+), 6 deletions(-) diff --git a/Back/Controllers/InvoiceController.cs b/Back/Controllers/InvoiceController.cs index 4f55378..8587046 100644 --- a/Back/Controllers/InvoiceController.cs +++ b/Back/Controllers/InvoiceController.cs @@ -256,13 +256,39 @@ namespace Back.Controllers IsDeleted = false, PatternID = Invoice.PatternID, setm = Invoice.setm, + cui = Invoice.cui, + crn = Invoice.crn, + CottageDateOfCustomsDeclaration = Invoice.CottageDateOfCustomsDeclaration, + ft = Invoice.ft, + cdcn = Invoice.cdcn, + insp = Invoice.insp, + billid = Invoice.billid, + pspd = Invoice.pspd, + scc = Invoice.scc, + scln = Invoice.scln, + seventeentax = Invoice.seventeentax, + tinc = Invoice.tinc, invoiceDetails = Invoice.invoiceDetails.Select(s => new InvoiceItem { CODID = s.CODID, am = s.am, fee = s.fee, dis = s.dis, - + bros = s.bros, + bsrn = s.bsrn, + consfee = s.consfee, + cut = s.cut, + exr = s.exr, + nw = s.nw, + odam = s.odam, + odr = s.odr, + odt = s.odt, + olam = s.olam, + olr = s.olr, + olt = s.olt, + spro = s.spro, + sscv = s.sscv, + ssrv = s.ssrv }).ToList() }, false); if (result > 0) @@ -285,13 +311,39 @@ namespace Back.Controllers IsDeleted = false, PatternID = Invoice.PatternID, setm = Invoice.setm, + cui = Invoice.cui, + crn = Invoice.crn, + CottageDateOfCustomsDeclaration = Invoice.CottageDateOfCustomsDeclaration, + ft = Invoice.ft, + cdcn = Invoice.cdcn, + insp = Invoice.insp, + billid = Invoice.billid, + pspd = Invoice.pspd, + scc = Invoice.scc, + scln = Invoice.scln, + seventeentax = Invoice.seventeentax, + tinc = Invoice.tinc, invoiceDetails = Invoice.invoiceDetails.Select(s => new InvoiceItem { CODID = s.CODID, am = s.am, fee = s.fee, dis = s.dis, - + bros = s.bros, + bsrn = s.bsrn, + consfee = s.consfee, + cut = s.cut, + exr = s.exr, + nw = s.nw, + odam = s.odam, + odr = s.odr, + odt = s.odt, + olam = s.olam, + olr = s.olr, + olt = s.olt, + spro = s.spro, + sscv = s.sscv, + ssrv = s.ssrv }).ToList() }, false); if (result1 > 0) @@ -326,13 +378,39 @@ namespace Back.Controllers IsDeleted = false, PatternID = Invoice.PatternID, setm = Invoice.setm, + cui = Invoice.cui, + crn = Invoice.crn, + CottageDateOfCustomsDeclaration = Invoice.CottageDateOfCustomsDeclaration, + ft = Invoice.ft, + cdcn = Invoice.cdcn, + insp = Invoice.insp, + billid = Invoice.billid, + pspd = Invoice.pspd, + scc = Invoice.scc, + scln = Invoice.scln, + seventeentax = Invoice.seventeentax, + tinc = Invoice.tinc, invoiceDetails = Invoice.invoiceDetails.Select(s => new InvoiceItem { CODID = s.CODID, am = s.am, fee = s.fee, dis = s.dis, - + bros = s.bros, + bsrn = s.bsrn, + consfee = s.consfee, + cut = s.cut, + exr = s.exr, + nw = s.nw, + odam = s.odam, + odr = s.odr, + odt = s.odt, + olam = s.olam, + olr = s.olr, + olt = s.olt, + spro = s.spro, + sscv = s.sscv, + ssrv = s.ssrv }).ToList() }, false); if (result2 > 0) diff --git a/Back/Controllers/OrdersController.cs b/Back/Controllers/OrdersController.cs index d949249..f3ca2aa 100644 --- a/Back/Controllers/OrdersController.cs +++ b/Back/Controllers/OrdersController.cs @@ -1,4 +1,5 @@ using Back.Common; +using Back.Data.Models; using Back.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; @@ -74,5 +75,61 @@ namespace Back.Controllers } else return BadRequest(new List { "در این وضعیت امکان ابطال نیست" }); } + [HttpPost("AddOrder")] + public async Task> AddOrder(PromotionDto item) + { + var claim = HttpContext.User.Claims.First(c => c.Type == "UserID"); + var UserID = claim.Value; + var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID)); + int CompanyID = user.RolUsers.First().CompanyID; + + Order order = new Order(); + order = new Order() + { + CompanyID = CompanyID, + ApprovalDate = DateTime.Now.ConvertMiladiToShamsi(), + DateCreate = DateTime.Now.ConvertMiladiToShamsi(), + Status = StatusOrder.Create, + UserID = Convert.ToInt32(UserID) + }; + if (item.ID<0) + { + var pricing = await _servPricing.GetPricing(); + //permission + order.OrderItems = item.promotionDetails.Select(s => new OrderItem + { + APrice = pricing.Where(w => w.PermissionID == s.PermissionID).Select(c => c.Price).FirstOrDefault(), + PermissionID = s.PermissionID, + Discount=0, + Tax=0, + CreditAmount=s.CreditAmount + }).ToList(); + } + else + { + //promotion + var pro=await _servPromotion.GetByPromotionID(item.ID); + if (pro == null) + return NotFound(); + + order.OrderItems=new List() + { + new OrderItem() + { + PromotionID=pro.ID, + APrice=pro.PromotionDetails.Sum(s=>s.TPrice), + CreditAmount=1, + Tax=0, + Discount=0 + } + }; + } + + var result= await _servOrders.AddOrder(order); + if (result > 0) + return Ok(result); + else return BadRequest(new List { "خطا در ثبت سفارش" }); + + } } } diff --git a/Back/Services/ServOrders.cs b/Back/Services/ServOrders.cs index 2549e9d..37bf38d 100644 --- a/Back/Services/ServOrders.cs +++ b/Back/Services/ServOrders.cs @@ -70,5 +70,18 @@ namespace Back.Services { return await _repoOrder.UpdateAsync(order); } + public async Task AddOrder(Order order) + { + try + { + var item = await _repoOrder.AddAsync(order); + return item.ID; + } + catch (Exception ex) + { + return -1; + + } + } } } diff --git a/Back/Services/ServPromotion.cs b/Back/Services/ServPromotion.cs index 18e5805..c359358 100644 --- a/Back/Services/ServPromotion.cs +++ b/Back/Services/ServPromotion.cs @@ -37,5 +37,11 @@ namespace Back.Services }).ToList() }).ToListAsync(); } + public async Task GetByPromotionID(int PromotionID) + { + return await _repoPromotion.Get(w => w.Status && w.ID == PromotionID) + .Include(inc => inc.PromotionDetails).ThenInclude(tinc => tinc.Permission) + .FirstOrDefaultAsync(); + } } } diff --git a/TaxPayerFull/CUSComponent/OrderItemNew.razor b/TaxPayerFull/CUSComponent/OrderItemNew.razor index d91f11a..6e7733a 100644 --- a/TaxPayerFull/CUSComponent/OrderItemNew.razor +++ b/TaxPayerFull/CUSComponent/OrderItemNew.razor @@ -163,7 +163,7 @@ { var itemFac= Selected.promotionDetails.Where(w => w.PermissionID == 3).FirstOrDefault(); if (itemFac!=null) - itemFac.CreditAmount = values[0]; + itemFac.CreditAmount = values[0]; var itemcod = Selected.promotionDetails.Where(w => w.PermissionID == 4).FirstOrDefault(); if (itemcod != null) @@ -180,10 +180,44 @@ TotalPrice = Selected.TotalPrice; } - + } public async Task NewOrder() { - + if (Selected!=null) + { + //--------- + var itemFac = Selected.promotionDetails.Where(w => w.PermissionID == 3).FirstOrDefault(); + if (itemFac != null) + itemFac.CreditAmount = values[0]; + + var itemcod = Selected.promotionDetails.Where(w => w.PermissionID == 4).FirstOrDefault(); + if (itemcod != null) + itemcod.CreditAmount = values[1]; + + var itemcus = Selected.promotionDetails.Where(w => w.PermissionID == 5).FirstOrDefault(); + if (itemcus != null) + itemcus.CreditAmount = values[2]; + + var itemtax = Selected.promotionDetails.Where(w => w.PermissionID == 16).FirstOrDefault(); + if (itemtax != null) + itemtax.CreditAmount = values[3]; + //--------- + var rsp = await hc.Post($"Orders/AddOrder", Selected); + if (rsp.IsSuccessStatusCode) + { + + } + else if (rsp.StatusCode==System.Net.HttpStatusCode.NotFound) + { + // ShowDangerAlert("سفارش یافت نشد"); + } + else + { + // var request = await rsp.Content.ReadFromJsonAsync>(); + // ShowDangerAlert(request[0]); + } + } + } }