diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs index b2ea3d3..bf3eb46 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs @@ -22,28 +22,24 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic } public List GetPaymeants(ReportBindingModel model) { - var paymeants = _paymeantstorage.GetFullList(); - var list = new List(); - foreach(var paymeant in paymeants) - { - var record = new ReportPaymeantsViewModel - { - PaymeantID=paymeant.ID, - ClientID=paymeant.ClientID, - OrderID=paymeant.OrderID, - PayOption=paymeant.PayOption, - SumPayment=paymeant.SumPayment, - }; - list.Add(record); - } - return list; + return _paymeantstorage.GetFillteredList(new PaymeantSearchModel { + DateFrom = model.DateFrom, + DateTo = model.DateTo + }).Select(x => new ReportPaymeantsViewModel { + ID = x.ID, + DatePaymeant = x.DatePaymeant, + OrderID = x.OrderID, + ClientID = x.ClientID, + SumPayment = x.SumPayment, + PayOption = x.PayOption, + }).ToList(); } public void SavePaymeantToExcelFile(ReportBindingModel model) { _saveToExcel.CreateReport(new ExcelInfoClient { - FileName = model.ProductName, + //FileName = model.ProductName, Title = "Список оплат", Paymeants = _paymeantstorage.GetFullList(), }); @@ -53,7 +49,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic { _saveToWord.CreateDoc(new WordInfoClient { - FileName = model.ProductName, + //FileName = model.ProductName, Title = "Список оплат", ListPaymeant = _paymeantstorage.GetFullList(), }) ; diff --git a/ElectronicsShop/ElectronicsShopContracts/BindingModels/ReportBindingModel.cs b/ElectronicsShop/ElectronicsShopContracts/BindingModels/ReportBindingModel.cs index 9c3d9e6..23d818d 100644 --- a/ElectronicsShop/ElectronicsShopContracts/BindingModels/ReportBindingModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/BindingModels/ReportBindingModel.cs @@ -10,17 +10,8 @@ namespace ElectronicsShopContracts.BindingModels { public class ReportBindingModel { - public int? ID { get; set; } - public int? ClientID { get; set; } - public string? ProductName { get; set; } = string.Empty; - public double? ProductPrice { get; set; } - public PaymeantOption Status { get; set; } = PaymeantOption.Неоплачено; - public DateTime? DateStart { get; set; } - public DateTime? DateFinish { get; set; } - public Dictionary PaymeantProduct - { - get; - set; - } = new(); + public string FileName { get; set; } = string.Empty; + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } } } diff --git a/ElectronicsShop/ElectronicsShopContracts/SearchModels/PaymeantSearchModel.cs b/ElectronicsShop/ElectronicsShopContracts/SearchModels/PaymeantSearchModel.cs index 307d699..52575c0 100644 --- a/ElectronicsShop/ElectronicsShopContracts/SearchModels/PaymeantSearchModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/SearchModels/PaymeantSearchModel.cs @@ -12,6 +12,7 @@ namespace ElectronicsShopContracts.SearchModels public int? OrderID { get; set; } public double? SumPay { get; set; } public int? ClientID { get; set; } - public DateTime? DatePaymeant { get; set; } + public DateTime? DateFrom{ get; set; } + public DateTime? DateTo { get; set; } } } diff --git a/ElectronicsShop/ElectronicsShopContracts/ViewModels/ReportPaymeantsViewModel.cs b/ElectronicsShop/ElectronicsShopContracts/ViewModels/ReportPaymeantsViewModel.cs index da5c9cd..2969ba6 100644 --- a/ElectronicsShop/ElectronicsShopContracts/ViewModels/ReportPaymeantsViewModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/ViewModels/ReportPaymeantsViewModel.cs @@ -9,12 +9,11 @@ namespace ElectronicsShopContracts.ViewModels { public class ReportPaymeantsViewModel { - public int PaymeantID { get; set; } - + public int ID { get; set; } public int ClientID { get; set; } - public int OrderID { get; set; } public double SumPayment { get; set; } public PaymeantOption PayOption { get; set; } + public DateTime DatePaymeant { get; set; } } } diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/PaymeantStorage.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/PaymeantStorage.cs index d8602fd..13c519f 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/PaymeantStorage.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/PaymeantStorage.cs @@ -43,6 +43,12 @@ namespace ElectronicsShopDataBaseImplement.Implements { public List GetFillteredList(PaymeantSearchModel model) { using var context = new Database(); + if (!model.ID.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) { + return context.Paymeants + .Where(x => x.DatePaymeant >= model.DateFrom && x.DatePaymeant <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); + } return context.Paymeants .Where(x => x.ClientID == model.ClientID).Select(x => x.GetViewModel).ToList(); } diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240601013228_Init.Designer.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240605160339_InitMigration.Designer.cs similarity index 98% rename from ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240601013228_Init.Designer.cs rename to ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240605160339_InitMigration.Designer.cs index 68decab..2cb6c65 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240601013228_Init.Designer.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240605160339_InitMigration.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ElectronicsShopDataBaseImplement.Migrations { [DbContext(typeof(Database))] - [Migration("20240601013228_Init")] - partial class Init + [Migration("20240605160339_InitMigration")] + partial class InitMigration { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -194,6 +194,9 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.Property("ClientID") .HasColumnType("int"); + b.Property("DatePaymeant") + .HasColumnType("datetime2"); + b.Property("OrderID") .HasColumnType("int"); diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240601013228_Init.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240605160339_InitMigration.cs similarity index 98% rename from ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240601013228_Init.cs rename to ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240605160339_InitMigration.cs index e2457fc..a9330d9 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240601013228_Init.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240605160339_InitMigration.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace ElectronicsShopDataBaseImplement.Migrations { /// - public partial class Init : Migration + public partial class InitMigration : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -115,6 +115,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations ClientID = table.Column(type: "int", nullable: false), SumPayment = table.Column(type: "float", nullable: false), PayOption = table.Column(type: "int", nullable: false), + DatePaymeant = table.Column(type: "datetime2", nullable: false), PaymentID = table.Column(type: "int", nullable: true) }, constraints: table => diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/DatabaseModelSnapshot.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/DatabaseModelSnapshot.cs index 5132a1f..634e552 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/DatabaseModelSnapshot.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/DatabaseModelSnapshot.cs @@ -44,7 +44,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.HasKey("ID"); - b.ToTable("Clients", (string)null); + b.ToTable("Clients"); }); modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b => @@ -72,7 +72,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.HasIndex("EmployeeID"); - b.ToTable("CostItems", (string)null); + b.ToTable("CostItems"); }); modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Employee", b => @@ -97,7 +97,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.HasKey("ID"); - b.ToTable("Employees", (string)null); + b.ToTable("Employees"); }); modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.MessageInfo", b => @@ -127,7 +127,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.HasIndex("ClientID"); - b.ToTable("Messages", (string)null); + b.ToTable("Messages"); }); modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b => @@ -151,7 +151,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.HasIndex("ClientID"); - b.ToTable("Orders", (string)null); + b.ToTable("Orders"); }); modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.OrderProduct", b => @@ -177,7 +177,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.HasIndex("ProductID"); - b.ToTable("OrderProducts", (string)null); + b.ToTable("OrderProducts"); }); modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Paymeant", b => @@ -191,6 +191,9 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.Property("ClientID") .HasColumnType("int"); + b.Property("DatePaymeant") + .HasColumnType("datetime2"); + b.Property("OrderID") .HasColumnType("int"); @@ -207,7 +210,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.HasIndex("PaymentID"); - b.ToTable("Paymeants", (string)null); + b.ToTable("Paymeants"); }); modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Product", b => @@ -232,7 +235,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.HasIndex("CostItemID"); - b.ToTable("Products", (string)null); + b.ToTable("Products"); }); modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b => diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Paymeant.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Paymeant.cs index fc0b867..cb82a41 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Paymeant.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Paymeant.cs @@ -29,6 +29,8 @@ namespace ElectronicsShopDataBaseImplement.Models [Required] public PaymeantOption PayOption { get; set; } = PaymeantOption.Неоплачено; + public DateTime DatePaymeant { get; set; } + public static Paymeant? Create(PaymeantBindingModel? model) { if (model == null) @@ -42,6 +44,7 @@ namespace ElectronicsShopDataBaseImplement.Models SumPayment = model.SumPayment, PayOption = model.PayOption, ClientID = model.ClientID, + DatePaymeant = model.DatePaymeant }; } public void Update(PaymeantBindingModel? model) @@ -55,13 +58,13 @@ namespace ElectronicsShopDataBaseImplement.Models PayOption = model.PayOption; } - public PaymeantViewModel GetViewModel => new() - { + public PaymeantViewModel GetViewModel => new() { ID = ID, OrderID = OrderID, SumPayment = SumPayment, PayOption = PayOption, ClientID = ClientID, + DatePaymeant = DatePaymeant }; - } + } } diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs index 3812ef7..9e63387 100644 --- a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs +++ b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs @@ -78,10 +78,19 @@ namespace ElectronicsShopRestAPI.Controllers { throw; } } - [HttpPost] + [HttpGet] public List? GetReport(DateTime _start, DateTime _end) { - var dataSource = _reportLogic.GetPaymeants(new ReportBindingModel { }); - return dataSource; + try { + var dataSource = _reportLogic.GetPaymeants(new ReportBindingModel { + DateFrom = _start, + DateTo = _end + }); + return dataSource; + } + catch (Exception ex) { + _logger.LogError(ex, $"Ошибка получения данных"); + throw; + } } } } diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs index 729af30..f1d1894 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs @@ -10,6 +10,7 @@ using Newtonsoft.Json; using System.Diagnostics; using System.Reflection; using System.Runtime.Serialization; +using System.Text.RegularExpressions; using System.Xml.Serialization; namespace ElectronicsShopUserApp.Controllers { @@ -17,11 +18,9 @@ namespace ElectronicsShopUserApp.Controllers { private readonly ILogger _logger; private Dictionary _productList; public int Id; - //private readonly IOrderLogic _order; - public HomeController(ILogger logger/*, IOrderLogic orderLogic*/) { + public HomeController(ILogger logger) { _logger = logger; - //_order = orderLogic; _productList = new Dictionary(); } @@ -213,16 +212,6 @@ namespace ElectronicsShopUserApp.Controllers { Response.Redirect("OrderView"); } - [HttpGet] - public IActionResult Report() - { - return View(); - } - [HttpPost] - public void Report(int count) - { - - } [HttpGet] public IActionResult Message() { @@ -270,7 +259,8 @@ namespace ElectronicsShopUserApp.Controllers { OrderID = id, SumPayment = paysum, PayOption = PayOptionCalc(sum, paysum), - ClientID = APIClient.Client.ID + ClientID = APIClient.Client.ID, + DatePaymeant = DateTime.Now, }); Response.Redirect("Index"); } @@ -294,9 +284,28 @@ namespace ElectronicsShopUserApp.Controllers { } [HttpGet] - public IActionResult ReportMake(DateTime startDate, DateTime endDate) { - var _report = APIClient.GetRequset>($"api/main/getreport?_start={startDate}&_end={endDate}"); - return View(_report); + public IActionResult Report() { + if (APIClient.Client == null) { + return Redirect("~/Home/Enter"); + } + + return View(); + } + + [HttpPost] + public void Report(DateTime DateFrom, DateTime DateTo) { + if (DateTo == DateTime.MinValue || DateFrom > DateTo) { + throw new Exception(" "); + } + Response.Redirect($"ReportSearch?_datefrom={DateFrom}&_dateTo={DateTo}"); + } + + [HttpGet] + public IActionResult ReportSearch(DateTime _datefrom, DateTime _dateto) { + var reports = APIClient.GetRequset>($"api/client/getreport?_start={_datefrom}&_end={_dateto}"); + + (DateTime, DateTime, List) tuple = (_datefrom, _dateto, reports); + return View(tuple); } } } diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Report.cshtml b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Report.cshtml index 88841e1..4dc297f 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Report.cshtml +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Report.cshtml @@ -1,4 +1,6 @@ -@{ +@using ElectronicsShopContracts.SearchModels +@model PaymeantSearchModel +@{ ViewData["Title"] = "Report"; }
@@ -7,27 +9,20 @@
- +
- +
- +
- +
-
- - Сформировать - - - - - - - +
+
+
\ No newline at end of file diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/ReportSearch.cshtml b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/ReportSearch.cshtml new file mode 100644 index 0000000..8bb8c84 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/ReportSearch.cshtml @@ -0,0 +1,75 @@ +@using ElectronicsShopContracts.ViewModels + +@model (DateTime, DateTime, List) + +@{ + ViewData["Title"] = "Reports"; +} + +
+

+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+

+
+ + +
+ @{ + + + + + + + + + + + + @foreach (var item in Model.Item3) { + + + + + + + + } + +
+ Номер оплаты + + Номер заказа + + Статус оплаты + + Сумма оплаты + + Дата оплаты +
+ @Html.DisplayFor(modelItem => item.ID) + + @Html.DisplayFor(modelItem => item.OrderID) + + @Html.DisplayFor(modelItem => item.PayOption) + + @Html.DisplayFor(modelItem => item.SumPayment) + + @Html.DisplayFor(modelItem => item.DatePaymeant) +
+ } +
\ No newline at end of file