Report view

This commit is contained in:
Илья Федотов 2024-06-06 17:21:39 +04:00
parent d82516c526
commit 403f2c1c79
13 changed files with 173 additions and 82 deletions

View File

@ -22,28 +22,24 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
}
public List<ReportPaymeantsViewModel> GetPaymeants(ReportBindingModel model)
{
var paymeants = _paymeantstorage.GetFullList();
var list = new List<ReportPaymeantsViewModel>();
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(),
}) ;

View File

@ -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<int, IProductModel> PaymeantProduct
{
get;
set;
} = new();
public string FileName { get; set; } = string.Empty;
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -43,6 +43,12 @@ namespace ElectronicsShopDataBaseImplement.Implements {
public List<PaymeantViewModel> 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();
}

View File

@ -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
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -194,6 +194,9 @@ namespace ElectronicsShopDataBaseImplement.Migrations
b.Property<int>("ClientID")
.HasColumnType("int");
b.Property<DateTime>("DatePaymeant")
.HasColumnType("datetime2");
b.Property<int>("OrderID")
.HasColumnType("int");

View File

@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace ElectronicsShopDataBaseImplement.Migrations
{
/// <inheritdoc />
public partial class Init : Migration
public partial class InitMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
@ -115,6 +115,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
ClientID = table.Column<int>(type: "int", nullable: false),
SumPayment = table.Column<double>(type: "float", nullable: false),
PayOption = table.Column<int>(type: "int", nullable: false),
DatePaymeant = table.Column<DateTime>(type: "datetime2", nullable: false),
PaymentID = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>

View File

@ -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<int>("ClientID")
.HasColumnType("int");
b.Property<DateTime>("DatePaymeant")
.HasColumnType("datetime2");
b.Property<int>("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 =>

View File

@ -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
};
}
}
}

View File

@ -78,10 +78,19 @@ namespace ElectronicsShopRestAPI.Controllers {
throw;
}
}
[HttpPost]
[HttpGet]
public List<ReportPaymeantsViewModel>? 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;
}
}
}
}

View File

@ -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<HomeController> _logger;
private Dictionary<int, (IProductModel, int)> _productList;
public int Id;
//private readonly IOrderLogic _order;
public HomeController(ILogger<HomeController> logger/*, IOrderLogic orderLogic*/) {
public HomeController(ILogger<HomeController> logger) {
_logger = logger;
//_order = orderLogic;
_productList = new Dictionary<int, (IProductModel, int)>();
}
@ -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<List<ReportPaymeantsViewModel>>($"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<List<PaymeantViewModel>>($"api/client/getreport?_start={_datefrom}&_end={_dateto}");
(DateTime, DateTime, List<PaymeantViewModel>) tuple = (_datefrom, _dateto, reports);
return View(tuple);
}
}
}

View File

@ -1,4 +1,6 @@
@{
@using ElectronicsShopContracts.SearchModels
@model PaymeantSearchModel
@{
ViewData["Title"] = "Report";
}
<div class="text-center">
@ -7,27 +9,20 @@
<form method="post">
<div class="align-content-center row mb-3">
<div class="col-sm-auto">
<label for="startDate">С:</label>
<label>С:</label>
</div>
<div class="col-3">
<input name="startDate" id="startDate" class="form-control" type="date" />
<input name="DateFrom" id="datefrom" type="date" />
</div>
<div class="col-sm-auto">
<label for="endDate">По:</label>
<label>По:</label>
</div>
<div class="col-3">
<input name="endDate" id="endDate" class="form-control" type="date" />
<input name="DateTo" id="dateto" type="date" />
</div>
<div>
<th>
<a class="btn btn-primary btn-sm" asp-action="ReportMake">Сформировать</a>
</th>
<th>
</th>
<th>
</th>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Cформировать отчет" class="btn btn-primary" /></div>
</div>
</div>
</form>

View File

@ -0,0 +1,75 @@
@using ElectronicsShopContracts.ViewModels
@model (DateTime, DateTime, List<PaymeantViewModel>)
@{
ViewData["Title"] = "Reports";
}
<div class="text-center">
<h1 class="row align-items-center mb-3">
<div class="text-center">
<label>Отчет по оплатам:</label>
</div>
<div class="col-sm-auto">
<label>С:</label>
</div>
<div class="col-sm-auto">
<input name="DateFrom" id="datefrom" type="text" value="@Model.Item1.Date.ToString("d")" readonly/>
</div>
<div class="col-sm-auto">
<label>По:</label>
</div>
<div class="col-sm-auto">
<input name="DateTo" id="dateto" type="text" value="@Model.Item2.Date.ToString("d")" readonly />
</div>
</h1>
</div>
<div class="text-center">
@{
<table class="table">
<thead>
<tr>
<th>
Номер оплаты
</th>
<th>
Номер заказа
</th>
<th>
Статус оплаты
</th>
<th>
Сумма оплаты
</th>
<th>
Дата оплаты
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Item3) {
<tr>
<th>
@Html.DisplayFor(modelItem => item.ID)
</th>
<th>
@Html.DisplayFor(modelItem => item.OrderID)
</th>
<th>
@Html.DisplayFor(modelItem => item.PayOption)
</th>
<th>
@Html.DisplayFor(modelItem => item.SumPayment)
</th>
<th>
@Html.DisplayFor(modelItem => item.DatePaymeant)
</th>
</tr>
}
</tbody>
</table>
}
</div>