Compare commits

...

2 Commits

Author SHA1 Message Date
Илья Федотов
f04063b44d fix 2024-08-02 14:36:23 +04:00
Илья Федотов
84442ed049 Date in reporst bv client 2024-08-01 22:33:30 +04:00
21 changed files with 119 additions and 63 deletions

View File

@ -113,7 +113,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
{ {
Email = model.Email Email = model.Email
}); });
if (element != null && element.Email == model.Email) if (element != null && element.ID != model.ID)
{ {
throw new InvalidOperationException("Клиент с такой почтой уже есть"); throw new InvalidOperationException("Клиент с такой почтой уже есть");
} }

View File

@ -93,7 +93,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic {
var element = _storage.GetElement(new EmployeeSearchModel { var element = _storage.GetElement(new EmployeeSearchModel {
Login = model.Login Login = model.Login
}); });
if (element != null && element.Login == model.Login) { if (element != null && element.ID != model.ID) {
throw new InvalidOperationException("Сотрудник с таким логином уже есть"); throw new InvalidOperationException("Сотрудник с таким логином уже есть");
} }
} }

View File

@ -71,6 +71,9 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
{ {
throw new ArgumentNullException("Сумма оплаты должна быть больше 0", nameof(model.SumPayment)); throw new ArgumentNullException("Сумма оплаты должна быть больше 0", nameof(model.SumPayment));
} }
if (string.IsNullOrEmpty(model.ClientID.ToString())) {
throw new ArgumentNullException("У оплаты должен быть клиент");
}
_logger.LogInformation($"Payment. ID:{model.ID}.Sum:{model.SumPayment}.OrderID:{model.OrderID}" + _logger.LogInformation($"Payment. ID:{model.ID}.Sum:{model.SumPayment}.OrderID:{model.OrderID}" +
$".PayOption{model.PayOption}"); $".PayOption{model.PayOption}");
} }

View File

@ -93,9 +93,12 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
if (model.Price <= 0) { if (model.Price <= 0) {
throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price)); throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price));
} }
if (string.IsNullOrEmpty(model.CostItemID.ToString())) {
throw new ArgumentNullException("Нет номера статьи затрат");
}
_logger.LogInformation($"Product. ID:{model.ID}.ProductName:{model.ProductName}.Price:{model.Price}.CostItemID:{model.CostItemID}"); _logger.LogInformation($"Product. ID:{model.ID}.ProductName:{model.ProductName}.Price:{model.Price}.CostItemID:{model.CostItemID}");
var element = _storage.GetElement(new ProductSearchModel { ProductName = model.ProductName }); var element = _storage.GetElement(new ProductSearchModel { ProductName = model.ProductName });
if (element != null && element.ProductName == model.ProductName) { if (element != null && element.ID != model.ID) {
throw new InvalidOperationException("Продукт с таким названием уже есть"); throw new InvalidOperationException("Продукт с таким названием уже есть");
} }
} }

View File

@ -82,8 +82,12 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
} }
// Получение списка товаров с указанием, в какие оплаты товар входит // Получение списка товаров с указанием, в какие оплаты товар входит
public List<ReportPaymeantProductsViewModel> GetPaymeantProducts(int _clientID) { public List<ReportPaymeantProductsViewModel> GetPaymeantProducts(ReportBindingModel model) {
var paymeants = _paymeantstorage.GetFillteredList(new PaymeantSearchModel { ClientID = _clientID }); var paymeants = _paymeantstorage.GetFillteredList(new PaymeantSearchModel {
ClientID = model.ClientID,
DateFrom = model.DateFrom,
DateTo = model.DateTo,
});
var list = new List<ReportPaymeantProductsViewModel>(); var list = new List<ReportPaymeantProductsViewModel>();
@ -112,21 +116,29 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
return list; return list;
} }
public byte[]? SavePaymeantToExcelFile(int _clientID) public byte[]? SavePaymeantToExcelFile(ReportBindingModel model)
{ {
var document = _saveToExcel.CreateReport(new ExcelInfoClient var document = _saveToExcel.CreateReport(new ExcelInfoClient
{ {
Title = "Список оплат и товаров", Title = "Список оплат и товаров",
PaymeantProducts = GetPaymeantProducts(_clientID) PaymeantProducts = GetPaymeantProducts(model),
DateFrom = model.DateFrom,
DateTo = model.DateTo
}); });
return document; return document;
} }
public byte[]? SavePaymeantToWordFile(int _clientID) public byte[]? SavePaymeantToWordFile(ReportBindingModel model)
{ {
var document = _saveToWord.CreateDoc(new WordInfoClient { var document = _saveToWord.CreateDoc(new WordInfoClient {
Title = "Список оплат", Title = "Список оплат",
ListPaymeant = _paymeantstorage.GetFillteredList(new PaymeantSearchModel { ClientID = _clientID }), ListPaymeant = _paymeantstorage.GetFillteredList(new PaymeantSearchModel {
ClientID = model.ClientID,
DateFrom = model.DateFrom,
DateTo = model.DateTo,
}),
DateFrom = model.DateFrom,
DateTo = model.DateTo,
}); });
return document; return document;
} }

View File

@ -22,7 +22,19 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
CellToName = "C1" CellToName = "C1"
}); });
uint rowIndex = 2; InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "A",
RowIndex = 2,
Text = $"С {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
StyleInfo = ExcelStyleInfoType.Title
});
MergeCells(new ExcelMergeParameters {
CellFromName = "A2",
CellToName = "H2"
});
uint rowIndex = 3;
foreach (var pp in info.PaymeantProducts) { foreach (var pp in info.PaymeantProducts) {
InsertCellInWorksheet(new ExcelCellParameters { InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "A", ColumnName = "A",
@ -42,18 +54,29 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
InsertCellInWorksheet(new ExcelCellParameters { InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "C", ColumnName = "C",
RowIndex = rowIndex, RowIndex = rowIndex,
Text = Count.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder StyleInfo = ExcelStyleInfoType.TextWithBroder
}); });
MergeCells(new ExcelMergeParameters {
CellFromName = $"B{rowIndex}",
CellToName = $"C{rowIndex}"
});
InsertCellInWorksheet(new ExcelCellParameters { InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "D", ColumnName = "D",
RowIndex = rowIndex, RowIndex = rowIndex,
Text = Count.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "E",
RowIndex = rowIndex,
Text = CostItem, Text = CostItem,
StyleInfo = ExcelStyleInfoType.TextWithBroder, StyleInfo = ExcelStyleInfoType.TextWithBroder,
}); });
InsertCellInWorksheet(new ExcelCellParameters { InsertCellInWorksheet(new ExcelCellParameters {
ColumnName = "E", ColumnName = "F",
RowIndex = rowIndex, RowIndex = rowIndex,
Text = Price.ToString(), Text = Price.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder, StyleInfo = ExcelStyleInfoType.TextWithBroder,

View File

@ -24,23 +24,22 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
} }
}); });
foreach (var pre in info.ListPaymeant) CreateParagraph(new WordParagraph {
{ Texts = new List<(string, WordTextProperties)> { ($"С {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
CreateParagraph(new WordParagraph new WordTextProperties { Bold = true, Size = "24", }) },
{ TextProperties = new WordTextProperties {
Texts = new List<(string, WordTextProperties)>
{ (pre.OrderID.ToString(), new WordTextProperties { Size = "24", Bold=true})},
TextProperties = new WordTextProperties
{
Size = "24", Size = "24",
JustificationType = WordJustificationType.Both JustificationType = WordJustificationType.Both
} }
}); });
foreach (var pre in info.ListPaymeant)
{
CreateParagraph(new WordParagraph CreateParagraph(new WordParagraph
{ {
Texts = new List<(string, WordTextProperties)> Texts = new List<(string, WordTextProperties)>
{ (pre.PayOption.ToString(), new WordTextProperties { Size = "20", Bold=false})}, { ($"Номер заказа: {pre.OrderID.ToString()}; Номер оплаты: {pre.ID.ToString()}; Статус оплаты: {pre.PayOption.ToString()}",
new WordTextProperties { Size = "24", Bold=false})},
TextProperties = new WordTextProperties TextProperties = new WordTextProperties
{ {
Size = "24", Size = "24",

View File

@ -5,6 +5,11 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels
public class ExcelInfoClient public class ExcelInfoClient
{ {
public string Title { get; set; } = string.Empty; public string Title { get; set; } = string.Empty;
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public List<ReportPaymeantProductsViewModel> PaymeantProducts { get; set; } = new(); public List<ReportPaymeantProductsViewModel> PaymeantProducts { get; set; } = new();
} }
} }

View File

@ -6,6 +6,11 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels
public class WordInfoClient public class WordInfoClient
{ {
public string Title { get; set; } = string.Empty; public string Title { get; set; } = string.Empty;
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public List<PaymeantViewModel> ListPaymeant { get; set; } = new(); public List<PaymeantViewModel> ListPaymeant { get; set; } = new();
} }
} }

View File

@ -13,15 +13,15 @@ namespace ElectronicsShopContracts.BusinessLogicContracts
public interface IReportClientLogic public interface IReportClientLogic
{ {
// получение списка товаров с указанием, в какие оплаты товар входит // получение списка товаров с указанием, в какие оплаты товар входит
List<ReportPaymeantProductsViewModel>? GetPaymeantProducts(int _clientID); List<ReportPaymeantProductsViewModel>? GetPaymeantProducts(ReportBindingModel model);
// получения списка оплат // получения списка оплат
List<ReportPaymeantsViewModel>? GetPaymeants(ReportBindingModel model); List<ReportPaymeantsViewModel>? GetPaymeants(ReportBindingModel model);
// Сохранение отчета оплат в .word // Сохранение отчета оплат в .word
byte[]? SavePaymeantToWordFile(int _clientID); byte[]? SavePaymeantToWordFile(ReportBindingModel model);
// Сохранение отчета оплат с товарами в .excel // Сохранение отчета оплат с товарами в .excel
byte[]? SavePaymeantToExcelFile(int _clientID); byte[]? SavePaymeantToExcelFile(ReportBindingModel model);
// Отчет оплаченных товаров в .pdf // Отчет оплаченных товаров в .pdf
PdfDocument SaveProductToPdfFile(ReportBindingModel model); PdfDocument SaveProductToPdfFile(ReportBindingModel model);

View File

@ -71,10 +71,6 @@ namespace ElectronicsShopDataBaseImplement.Implements
public List<ClientViewModel> GetFilteredList(ClientSearchModel model) public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{ {
if (string.IsNullOrEmpty(model.Email))
{
return new();
}
using var context = new Database(); using var context = new Database();
return context.Clients.Where(x => !string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO return context.Clients.Where(x => !string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO
.Contains(model.ClientFIO)).Select(x => x.GetViewModel).ToList(); .Contains(model.ClientFIO)).Select(x => x.GetViewModel).ToList();

View File

@ -57,15 +57,13 @@ namespace ElectronicsShopDataBaseImplement.Implements
.FirstOrDefault(x => (x.Login == model.Login && x.Password == model.Password)) .FirstOrDefault(x => (x.Login == model.Login && x.Password == model.Password))
?.GetViewModel; ?.GetViewModel;
} }
return new(); return context.Employees
.FirstOrDefault(x => (x.Login == model.Login))
?.GetViewModel;
} }
public List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model) public List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model)
{ {
if (string.IsNullOrEmpty(model.Login))
{
return new();
}
using var context = new Database(); using var context = new Database();
return context.Employees.Where(x => x.Login return context.Employees.Where(x => x.Login
.Contains(model.Login)) .Contains(model.Login))

View File

@ -88,11 +88,7 @@ namespace ElectronicsShopDataBaseImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
using var context = new Database(); using var context = new Database();
if (!model.ID.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) if (model.ClientID.HasValue) {
{
return new();
}
else if (model.ClientID.HasValue) {
return context.Orders return context.Orders
.Include (x => x.Products) .Include (x => x.Products)
.Where(x => x.ClientID == model.ClientID && x.Status == OrderStatus.Неоплачено) .Where(x => x.ClientID == model.ClientID && x.Status == OrderStatus.Неоплачено)

View File

@ -53,6 +53,12 @@ namespace ElectronicsShopDataBaseImplement.Implements {
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
else if (model.ClientID.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) {
return context.Paymeants
.Where(x => x.DatePaymeant >= model.DateFrom && x.DatePaymeant <= model.DateTo && x.ClientID == model.ClientID)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.ClientID.HasValue) { else if (model.ClientID.HasValue) {
return context.Paymeants return context.Paymeants

View File

@ -77,7 +77,6 @@ namespace ElectronicsShopDataBaseImplement.Implements
public List<ProductViewModel>? GetFilteredList(ProductSearchModel model) public List<ProductViewModel>? GetFilteredList(ProductSearchModel model)
{ {
using var context = new Database(); using var context = new Database();
if (model.CostItemID.HasValue && string.IsNullOrEmpty(model.ProductName)) { if (model.CostItemID.HasValue && string.IsNullOrEmpty(model.ProductName)) {
return context.Products return context.Products
.Where(x => x.CostItemID == model.CostItemID) .Where(x => x.CostItemID == model.CostItemID)

View File

@ -319,7 +319,7 @@ namespace ElectronicsShopEmployeeApp.Controllers {
[HttpGet] [HttpGet]
public IActionResult Report() { public IActionResult Report() {
if (APIEmployee.Employee == null) { if (APIEmployee.Employee == null) {
return RedirectToAction("~/Home/Index"); return Redirect("/Home/Index");
} }
return View(); return View();

View File

@ -175,9 +175,13 @@ namespace ElectronicsShopRestAPI.Controllers {
} }
[HttpGet] [HttpGet]
public byte[]? CreateXlsxReport (int _clientID) { public byte[]? CreateXlsxReport (int _clientID, string DateFrom, string DateTo) {
try { try {
var document = _reportLogic.SavePaymeantToExcelFile (_clientID); var document = _reportLogic.SavePaymeantToExcelFile (new ReportBindingModel {
ClientID = _clientID,
DateFrom = DateTime.Parse(DateFrom),
DateTo = DateTime.Parse(DateTo)
});
return document; return document;
} }
catch (Exception ex) { catch (Exception ex) {
@ -187,9 +191,13 @@ namespace ElectronicsShopRestAPI.Controllers {
} }
[HttpGet] [HttpGet]
public byte[]? CreateDocxReport (int _clientID) { public byte[]? CreateDocxReport (int _clientID, string DateFrom, string DateTo) {
try { try {
var document = _reportLogic.SavePaymeantToWordFile (_clientID); var document = _reportLogic.SavePaymeantToWordFile (new ReportBindingModel {
ClientID = _clientID,
DateFrom = DateTime.Parse(DateFrom),
DateTo = DateTime.Parse(DateTo)
});
return document; return document;
} }
catch (Exception ex) { catch (Exception ex) {
@ -212,7 +220,7 @@ namespace ElectronicsShopRestAPI.Controllers {
_mailWorker.MailSendAsync(new() { _mailWorker.MailSendAsync(new() {
MailAddress = model.ClientEmail, MailAddress = model.ClientEmail,
Subject = "Отчет", Subject = "Отчет",
Text = $"Отчет оплаченных товаров с {model.DateFrom} по {model.DateTo}", Text = $"Отчет оплаченных товаров с {model.DateFrom.ToShortDateString()} по {model.DateTo.ToShortDateString()}",
document = data document = data
}); });

View File

@ -194,12 +194,10 @@ namespace ElectronicsShopUserApp.Controllers {
} }
[HttpGet] [HttpGet]
public IActionResult DeleteProductOrder(int id) { public IActionResult DeleteProductOrder(int orderID, int id) {
var view = APIClient.GetRequset<OrderViewModel>($"api/main/getorder?_clientid={APIClient.Client?.ID}") APIClient.PostRequestStr($"api/main/deleteproductorder", orderID, id);
?? throw new Exception("Îøèáêà ïîëó÷åíèÿ ìîäåëè");
APIClient.PostRequestStr($"api/main/deleteproductorder", view.ID, id);
return Redirect($"https://localhost:7219/Home/EditOrder/{view.ID}"); return Redirect($"https://localhost:7219/Home/EditOrder/{orderID}");
} }
[HttpGet] [HttpGet]
@ -308,8 +306,9 @@ namespace ElectronicsShopUserApp.Controllers {
} }
[HttpGet] [HttpGet]
public IActionResult CreateExcelReport() { public IActionResult CreateExcelReport(string DateFrom, string DateTo) {
var fileMemStream = APIClient.GetRequset<byte[]>($"api/Client/CreateXlsxReport?_clientID={APIClient.Client?.ID}"); var fileMemStream = APIClient.GetRequset<byte[]>($"api/Client/CreateXlsxReport?_clientID={APIClient.Client?.ID}&DateFrom={DateFrom}&" +
$"DateTo={DateTo}");
if (fileMemStream == null) { if (fileMemStream == null) {
throw new Exception("Îøèáêà ñîçäàíèÿ îò÷åòà"); throw new Exception("Îøèáêà ñîçäàíèÿ îò÷åòà");
@ -319,8 +318,9 @@ namespace ElectronicsShopUserApp.Controllers {
} }
[HttpGet] [HttpGet]
public IActionResult CreateWordReport() { public IActionResult CreateWordReport(string DateFrom, string DateTo) {
var fileMemStream = APIClient.GetRequset<byte[]>($"api/client/CreateDocxReport?_clientID={APIClient.Client?.ID}"); var fileMemStream = APIClient.GetRequset<byte[]>($"api/client/CreateDocxReport?_clientID={APIClient.Client?.ID}&DateFrom={DateFrom}&" +
$"DateTo={DateTo}");
if (fileMemStream == null) { if (fileMemStream == null) {
throw new Exception("Îøèáêà ñîçäàíèÿ îò÷åòà"); throw new Exception("Îøèáêà ñîçäàíèÿ îò÷åòà");

View File

@ -66,7 +66,8 @@
</th> </th>
<td> <td>
<a class="btn btn-primary btn-sm" asp-action="DeleteProductOrder" style="background-color:red;" asp-route-ID="@item.Key">Удалить</a> <a class="btn btn-primary btn-sm" asp-action="DeleteProductOrder" style="background-color:red;" asp-route-orderID="@Model.Item1"
asp-route-ID="@item.Key">Удалить</a>
</td> </td>
</tr> </tr>
} }

View File

@ -25,8 +25,10 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-8"> <div class="col-8">
<a class="btn btn-primary btn-sm" asp-action="CreateWordReport" style="background-color:#335a95;">Экспорт отчета в .xlsx</a> <a class="btn btn-primary btn-sm" asp-action="CreateWordReport" asp-route-DateFrom="@Model.Item1"
<a class="btn btn-primary btn-sm" asp-action="CreateExcelReport" style="background-color:#04713A;">Экспорт отчета в .docx</a> asp-route-DateTo="@Model.Item2" style="background-color:#335a95;">Экспорт отчета в .xlsx</a>
<a class="btn btn-primary btn-sm" asp-action="CreateExcelReport" asp-route-DateFrom="@Model.Item1"
asp-route-DateTo="@Model.Item2" style="background-color:#04713A;">Экспорт отчета в .docx</a>
<a class="btn btn-primary btn-sm" asp-action="CreatePdfReport" asp-route-DateFrom="@Model.Item1" <a class="btn btn-primary btn-sm" asp-action="CreatePdfReport" asp-route-DateFrom="@Model.Item1"
asp-route-DateTo="@Model.Item2" style="background-color:#ad0d09;">отправить на Email отчет в .pdf</a> asp-route-DateTo="@Model.Item2" style="background-color:#ad0d09;">отправить на Email отчет в .pdf</a>
</div> </div>