diff --git a/Back/Back.csproj b/Back/Back.csproj index fd97cd7..899d7e4 100644 --- a/Back/Back.csproj +++ b/Back/Back.csproj @@ -36,7 +36,7 @@ - ..\..\Dlls\Service.dll + ..\..\..\LocalGit\TaxPayerTools\Service\bin\Debug\Service.dll diff --git a/Back/Controllers/OrderssController.cs b/Back/Controllers/OrdersController.cs similarity index 60% rename from Back/Controllers/OrderssController.cs rename to Back/Controllers/OrdersController.cs index 44a3cab..d949249 100644 --- a/Back/Controllers/OrderssController.cs +++ b/Back/Controllers/OrdersController.cs @@ -1,4 +1,5 @@ -using Back.Services; +using Back.Common; +using Back.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -11,14 +12,14 @@ namespace Back.Controllers [Route("api/[controller]")] [Authorize] [ApiController] - public class OrderssController : ControllerBase + public class OrdersController : ControllerBase { private readonly ServOrders _servOrders; private readonly ServPromotion _servPromotion; private readonly ServPricing _servPricing; private readonly servUser _servUser; - public OrderssController(ServOrders servOrders, ServPromotion servPromotion, ServPricing servPricing, servUser servUser) + public OrdersController(ServOrders servOrders, ServPromotion servPromotion, ServPricing servPricing, servUser servUser) { _servOrders = servOrders; _servPricing = servPricing; @@ -51,7 +52,27 @@ namespace Back.Controllers var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID)); int CompanyID = user.RolUsers.First().CompanyID; - return Ok(await _servOrders.GetOrderItems(CompanyID, OrderID)); + return Ok(await _servOrders.GetOrderItems( OrderID, CompanyID)); + } + [HttpDelete("CancelOrder/{OrderID}")] + public async Task>> CancelOrder(int OrderID) + { + 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; + + var order =await _servOrders.GetOrder(OrderID, CompanyID); + if (order==null) + return NotFound(); + + if (order.Status==StatusOrder.Create) + { + order.Status = StatusOrder.Cancel; + order.ApprovalDate = DateTime.Now.ConvertMiladiToShamsi(); + return Ok(await _servOrders.UpdateOrder(order)); + } + else return BadRequest(new List { "در این وضعیت امکان ابطال نیست" }); } } } diff --git a/Back/Services/ServOrders.cs b/Back/Services/ServOrders.cs index 1ddd465..2549e9d 100644 --- a/Back/Services/ServOrders.cs +++ b/Back/Services/ServOrders.cs @@ -33,8 +33,8 @@ namespace Back.Services return await request .Select(w => new OrderDto { - ApprovalDate = w.ApprovalDate, - DateCreate = w.DateCreate, + ApprovalDate = w.ApprovalDate.ShamciToFormatShamci(), + DateCreate = w.DateCreate.ShamciToFormatShamci(), ID = w.ID, PreDiscount = w.PreDiscount, Status = w.Status, @@ -46,7 +46,9 @@ namespace Back.Services } public async Task> GetOrderItems(int OrderID,int CompanyID) { - return await _repoOrderItem.Get(w => w.OrderID == OrderID && w.Order.CompanyID== CompanyID) + return await _repoOrderItem.Get(w => w.OrderID == OrderID && w.Order.CompanyID == CompanyID) + .Include(inc=>inc.Permission) + .Include(inc=>inc.Promotion) .Select(s=>new OrderItemDto { OrderID = OrderID, @@ -55,9 +57,18 @@ namespace Back.Services Discount=s.Discount, ID = s.ID, Tax = s.Tax, - Type= s.PermissionID.HasValue && !s.PromotionID.HasValue ? "" : !s.PermissionID.HasValue && s.PromotionID.HasValue ? "تعرفه" : "نامشخص", - IDForType = s.PermissionID.HasValue && !s.PromotionID.HasValue ? s.PermissionID.Value : !s.PermissionID.HasValue && s.PromotionID.HasValue ? s.PromotionID.Value : 0 + Type= s.PermissionID.HasValue && !s.PromotionID.HasValue ? "سرویس" : !s.PermissionID.HasValue && s.PromotionID.HasValue ? "تعرفه" : "نامشخص", + IDForType = s.PermissionID.HasValue && !s.PromotionID.HasValue ? s.PermissionID.Value : !s.PermissionID.HasValue && s.PromotionID.HasValue ? s.PromotionID.Value : 0, + Title = s.PermissionID.HasValue && !s.PromotionID.HasValue ? s.Permission.Title : !s.PermissionID.HasValue && s.PromotionID.HasValue ? s.Promotion.Name : "", }).ToListAsync(); } + public async Task GetOrder(int OrderID, int CompanyID) + { + return await _repoOrder.Get(w => w.ID == OrderID && w.CompanyID == CompanyID) .FirstOrDefaultAsync(); + } + public async Task UpdateOrder(Order order) + { + return await _repoOrder.UpdateAsync(order); + } } } diff --git a/Shared/DTOs/OrderDto.cs b/Shared/DTOs/OrderDto.cs index ea60139..af56c60 100644 --- a/Shared/DTOs/OrderDto.cs +++ b/Shared/DTOs/OrderDto.cs @@ -23,9 +23,9 @@ namespace Shared.DTOs public decimal PreDiscount { get; set; } [Display(Name = "تخفیف سفارش")] public decimal TDiscount { get; set; } - [Display(Name = "مبلغ بغد از تخفیف")] + [Display(Name = "بغد از تخفیف")] public decimal lstDiscount { get; set; } - [Display(Name = "مبلغ مالیات")] + [Display(Name = "مالیات")] public decimal TTax { get; set; } [Display(Name = "مبلغ نهایی")] public decimal TPrice { get; set; } diff --git a/Shared/DTOs/OrderItemDto.cs b/Shared/DTOs/OrderItemDto.cs index 0060683..3d534f7 100644 --- a/Shared/DTOs/OrderItemDto.cs +++ b/Shared/DTOs/OrderItemDto.cs @@ -9,6 +9,7 @@ namespace Shared.DTOs public class OrderItemDto { public int ID { get; set; } + public string Title { get; set; } public int OrderID { get; set; } public string Type { get; set; } public int IDForType { get; set; } diff --git a/TaxPayerFull/CUSComponent/OrderItemRead.razor b/TaxPayerFull/CUSComponent/OrderItemRead.razor index 6cfa25b..00669a0 100644 --- a/TaxPayerFull/CUSComponent/OrderItemRead.razor +++ b/TaxPayerFull/CUSComponent/OrderItemRead.razor @@ -2,6 +2,8 @@ @using Shared.DTOs @inject HttpClientController hc; + + @* alert *@
-
+
- +
-
+
- +
- @if (order.Status!=StatusOrder.Create) + @if (order.Status != StatusOrder.Create) { -
+
- +
}
+
+
+
+ + + @context.Title + + + @context.Type + + + @context.CreditAmount + + + @context.APrice.ToString("N0") + + + @context.Discount.ToString("N0") + + + @context.Tax.ToString("N0") + + + @context.Total.ToString("N0") + + + +
+
+
+ +
+ + + +
+ +
+ + +
+ +
+ + +
+ + @*
+ + +
*@ +
+ + +
+
+ +
+
+ @if (order.Status == StatusOrder.Create) + { + + + + } + +
+ @code { #region Alert @@ -38,7 +119,9 @@ bool Hidealert = true; string alertMessage = ""; #endregion - + private ConfirmDialog dialog = default!; + public ActionInResultComponent result { get; set; } + Grid grid = default!; [Inject] protected PreloadService PreloadService { get; set; } = default!; [Parameter] public EventCallback OnMultipleOfThree { get; set; } [Parameter] public OrderDto order { get; set; } @@ -46,7 +129,7 @@ string titledateapp = "تاریخ"; protected override async Task OnParametersSetAsync() { - if (order.Status==StatusOrder.Cancel) + if (order.Status == StatusOrder.Cancel) { titledateapp += " ابطال"; } @@ -57,7 +140,13 @@ await base.OnParametersSetAsync(); } } -@functions{ +@functions { + private async Task> DataProvider(GridDataProviderRequest request) + { + OrderItems = await LoadOrderItem(); // call a service or an API to pull the employees + + return await Task.FromResult(request.ApplyTo(OrderItems)); + } private void ShowSuccessAlert(string msg) { Hidealert = false; @@ -72,14 +161,62 @@ alertIconName = IconName.ExclamationTriangleFill; alertMessage = msg; } - private async Task LoadOrderItem(){ + private async Task> LoadOrderItem() + { PreloadService.Show(SpinnerColor.Dark); - var rsp = await hc.Get($"Orderss/GetOrderDetails/{order.ID}"); - if (rsp.IsSuccessStatusCode) - OrderItems = await rsp.Content.ReadFromJsonAsync?>(); - else - ShowDangerAlert("خطایی در بارگیری"); + var rsp = await hc.Get($"Orders/GetOrderDetails/{order.ID}"); PreloadService.Hide(); + if (rsp.IsSuccessStatusCode) + return await rsp.Content.ReadFromJsonAsync?>(); + else + { + ShowDangerAlert("خطایی در بارگیری"); + return new List(); + } + + } + private async Task OnClickPay() + { + // result.Status = ComponentStatus.success; + // result.Action = ComponentAction.add; + // await OnMultipleOfThree.InvokeAsync(result); + + + } + private async Task OnClickCancel() + { + var confirmation = await dialog.ShowAsync( + title: "عملیات ابطال سفارش", + message1: $"از ابطال سفارش {order.ID}", + message2: "اطمینان دارید?"); + + if (confirmation) + { + + PreloadService.Show(SpinnerColor.Dark); + var rsp = await hc.Get($"Orders/CancelOrder/{order.ID}"); + PreloadService.Hide(); + if (rsp.IsSuccessStatusCode) + { + if(await rsp.Content.ReadFromJsonAsync()) + { + result.Status = ComponentStatus.success; + result.Action = ComponentAction.delete; + await OnMultipleOfThree.InvokeAsync(result); + } + else + ShowDangerAlert("خطای سیستمی"); + } + else if (rsp.StatusCode==System.Net.HttpStatusCode.NotFound) + ShowDangerAlert("سفارش یافت نشد"); + + else + { + var request = await rsp.Content.ReadFromJsonAsync>(); + ShowDangerAlert(request[0]); + } + } + } } \ No newline at end of file diff --git a/TaxPayerFull/Pages/UserPanel/Orders.razor b/TaxPayerFull/Pages/UserPanel/Orders.razor index 99c360b..ab4a6b4 100644 --- a/TaxPayerFull/Pages/UserPanel/Orders.razor +++ b/TaxPayerFull/Pages/UserPanel/Orders.razor @@ -148,7 +148,7 @@ itemsearch.PageSize = 10; itemsearch.PageIndex = pi; PreloadService.Show(SpinnerColor.Dark); - var rsp = await hc.Post("Orderss/GetAllOrder",itemsearch); + var rsp = await hc.Post("Orders/GetAllOrder",itemsearch); if (rsp.IsSuccessStatusCode) request = await rsp.Content.ReadFromJsonAsync?>(); else @@ -171,20 +171,15 @@ alertMessage = msg; } - public async Task CallBackItem(ActionInResultComponent result) + public async Task CallBackFromReadItem(ActionInResultComponent result) { if (result.Action == ComponentAction.add) { if (result.Status == ComponentStatus.success) - ShowSuccessAlert("سفارش جدید با موفقیت اضافه شد"); + ShowSuccessAlert("سفارش پرداخت شد"); } - else if (result.Action == ComponentAction.update) - { - if (result.Status == ComponentStatus.success) - ShowSuccessAlert("اطلاعات سفارش با موفقیت ویرایش شد"); - } else if (result.Action == ComponentAction.delete) { if (result.Status == ComponentStatus.success) @@ -200,10 +195,10 @@ { var parameters = new Dictionary(); - var item = request.list.Where(w => w.ID == ID).First().Clone(); + var item = request?.list.Where(w => w.ID == ID).First().Clone(); parameters.Add("order", item); - parameters.Add("OnMultipleOfThree", EventCallback.Factory.Create(this, CallBackItem)); - await modal.ShowAsync(title:$"سفارش {ID}", parameters: parameters); + parameters.Add("OnMultipleOfThree", EventCallback.Factory.Create(this, CallBackFromReadItem)); + await modal.ShowAsync(title:$"سفارش {ID}", parameters: parameters); } diff --git a/TaxPayerFull/Program.cs b/TaxPayerFull/Program.cs index ea0270a..670070e 100644 --- a/TaxPayerFull/Program.cs +++ b/TaxPayerFull/Program.cs @@ -37,10 +37,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");