Compare commits
2 Commits
45cf0818fc
...
f04063b44d
Author | SHA1 | Date | |
---|---|---|---|
|
f04063b44d | ||
|
84442ed049 |
@ -111,9 +111,9 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||
|
||||
var element = _storage.GetElement(new ClientSearchModel
|
||||
{
|
||||
Email= model.Email
|
||||
Email = model.Email
|
||||
});
|
||||
if (element != null && element.Email == model.Email)
|
||||
if (element != null && element.ID != model.ID)
|
||||
{
|
||||
throw new InvalidOperationException("Клиент с такой почтой уже есть");
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic {
|
||||
var element = _storage.GetElement(new EmployeeSearchModel {
|
||||
Login = model.Login
|
||||
});
|
||||
if (element != null && element.Login == model.Login) {
|
||||
if (element != null && element.ID != model.ID) {
|
||||
throw new InvalidOperationException("Сотрудник с таким логином уже есть");
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +71,9 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||
{
|
||||
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}" +
|
||||
$".PayOption{model.PayOption}");
|
||||
}
|
||||
|
@ -93,9 +93,12 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||
if (model.Price <= 0) {
|
||||
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}");
|
||||
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("Продукт с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
|
@ -82,8 +82,12 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||
}
|
||||
|
||||
// Получение списка товаров с указанием, в какие оплаты товар входит
|
||||
public List<ReportPaymeantProductsViewModel> GetPaymeantProducts(int _clientID) {
|
||||
var paymeants = _paymeantstorage.GetFillteredList(new PaymeantSearchModel { ClientID = _clientID });
|
||||
public List<ReportPaymeantProductsViewModel> GetPaymeantProducts(ReportBindingModel model) {
|
||||
var paymeants = _paymeantstorage.GetFillteredList(new PaymeantSearchModel {
|
||||
ClientID = model.ClientID,
|
||||
DateFrom = model.DateFrom,
|
||||
DateTo = model.DateTo,
|
||||
});
|
||||
|
||||
var list = new List<ReportPaymeantProductsViewModel>();
|
||||
|
||||
@ -112,21 +116,29 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||
return list;
|
||||
}
|
||||
|
||||
public byte[]? SavePaymeantToExcelFile(int _clientID)
|
||||
public byte[]? SavePaymeantToExcelFile(ReportBindingModel model)
|
||||
{
|
||||
var document = _saveToExcel.CreateReport(new ExcelInfoClient
|
||||
{
|
||||
Title = "Список оплат и товаров",
|
||||
PaymeantProducts = GetPaymeantProducts(_clientID)
|
||||
PaymeantProducts = GetPaymeantProducts(model),
|
||||
DateFrom = model.DateFrom,
|
||||
DateTo = model.DateTo
|
||||
});
|
||||
return document;
|
||||
}
|
||||
|
||||
public byte[]? SavePaymeantToWordFile(int _clientID)
|
||||
public byte[]? SavePaymeantToWordFile(ReportBindingModel model)
|
||||
{
|
||||
var document = _saveToWord.CreateDoc(new WordInfoClient {
|
||||
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;
|
||||
}
|
||||
|
@ -22,7 +22,19 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
|
||||
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) {
|
||||
InsertCellInWorksheet(new ExcelCellParameters {
|
||||
ColumnName = "A",
|
||||
@ -39,21 +51,32 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters {
|
||||
ColumnName = "C",
|
||||
InsertCellInWorksheet(new ExcelCellParameters {
|
||||
ColumnName = "C",
|
||||
RowIndex = rowIndex,
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
|
||||
MergeCells(new ExcelMergeParameters {
|
||||
CellFromName = $"B{rowIndex}",
|
||||
CellToName = $"C{rowIndex}"
|
||||
});
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters {
|
||||
ColumnName = "D",
|
||||
RowIndex = rowIndex,
|
||||
Text = Count.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters {
|
||||
ColumnName = "D",
|
||||
ColumnName = "E",
|
||||
RowIndex = rowIndex,
|
||||
Text = CostItem,
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder,
|
||||
});
|
||||
InsertCellInWorksheet(new ExcelCellParameters {
|
||||
ColumnName = "E",
|
||||
ColumnName = "F",
|
||||
RowIndex = rowIndex,
|
||||
Text = Price.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder,
|
||||
|
@ -24,29 +24,28 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
|
||||
}
|
||||
});
|
||||
|
||||
CreateParagraph(new WordParagraph {
|
||||
Texts = new List<(string, WordTextProperties)> { ($"С {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
|
||||
new WordTextProperties { Bold = true, Size = "24", }) },
|
||||
TextProperties = new WordTextProperties {
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Both
|
||||
}
|
||||
});
|
||||
|
||||
foreach (var pre in info.ListPaymeant)
|
||||
{
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)>
|
||||
{ (pre.OrderID.ToString(), new WordTextProperties { Size = "24", Bold=true})},
|
||||
{ ($"Номер заказа: {pre.OrderID.ToString()}; Номер оплаты: {pre.ID.ToString()}; Статус оплаты: {pre.PayOption.ToString()}",
|
||||
new WordTextProperties { Size = "24", Bold=false})},
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Both
|
||||
}
|
||||
});
|
||||
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)>
|
||||
{ (pre.PayOption.ToString(), new WordTextProperties { Size = "20", Bold=false})},
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Both
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var document = SaveWord(info);
|
||||
|
@ -5,6 +5,11 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels
|
||||
public class ExcelInfoClient
|
||||
{
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
public DateTime DateFrom { get; set; }
|
||||
|
||||
public DateTime DateTo { get; set; }
|
||||
|
||||
public List<ReportPaymeantProductsViewModel> PaymeantProducts { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,11 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels
|
||||
public class WordInfoClient
|
||||
{
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
public DateTime DateFrom { get; set; }
|
||||
|
||||
public DateTime DateTo { get; set; }
|
||||
|
||||
public List<PaymeantViewModel> ListPaymeant { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -13,15 +13,15 @@ namespace ElectronicsShopContracts.BusinessLogicContracts
|
||||
public interface IReportClientLogic
|
||||
{
|
||||
// получение списка товаров с указанием, в какие оплаты товар входит
|
||||
List<ReportPaymeantProductsViewModel>? GetPaymeantProducts(int _clientID);
|
||||
List<ReportPaymeantProductsViewModel>? GetPaymeantProducts(ReportBindingModel model);
|
||||
// получения списка оплат
|
||||
List<ReportPaymeantsViewModel>? GetPaymeants(ReportBindingModel model);
|
||||
|
||||
// Сохранение отчета оплат в .word
|
||||
byte[]? SavePaymeantToWordFile(int _clientID);
|
||||
byte[]? SavePaymeantToWordFile(ReportBindingModel model);
|
||||
|
||||
// Сохранение отчета оплат с товарами в .excel
|
||||
byte[]? SavePaymeantToExcelFile(int _clientID);
|
||||
byte[]? SavePaymeantToExcelFile(ReportBindingModel model);
|
||||
|
||||
// Отчет оплаченных товаров в .pdf
|
||||
PdfDocument SaveProductToPdfFile(ReportBindingModel model);
|
||||
|
@ -71,10 +71,6 @@ namespace ElectronicsShopDataBaseImplement.Implements
|
||||
|
||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new Database();
|
||||
return context.Clients.Where(x => !string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO
|
||||
.Contains(model.ClientFIO)).Select(x => x.GetViewModel).ToList();
|
||||
|
@ -57,15 +57,13 @@ namespace ElectronicsShopDataBaseImplement.Implements
|
||||
.FirstOrDefault(x => (x.Login == model.Login && x.Password == model.Password))
|
||||
?.GetViewModel;
|
||||
}
|
||||
return new();
|
||||
return context.Employees
|
||||
.FirstOrDefault(x => (x.Login == model.Login))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Login))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new Database();
|
||||
return context.Employees.Where(x => x.Login
|
||||
.Contains(model.Login))
|
||||
|
@ -88,11 +88,7 @@ namespace ElectronicsShopDataBaseImplement.Implements
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
if (!model.ID.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
else if (model.ClientID.HasValue) {
|
||||
if (model.ClientID.HasValue) {
|
||||
return context.Orders
|
||||
.Include (x => x.Products)
|
||||
.Where(x => x.ClientID == model.ClientID && x.Status == OrderStatus.Неоплачено)
|
||||
|
@ -53,6 +53,12 @@ namespace ElectronicsShopDataBaseImplement.Implements {
|
||||
.Select(x => x.GetViewModel)
|
||||
.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) {
|
||||
|
||||
return context.Paymeants
|
||||
|
@ -77,7 +77,6 @@ namespace ElectronicsShopDataBaseImplement.Implements
|
||||
public List<ProductViewModel>? GetFilteredList(ProductSearchModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
|
||||
if (model.CostItemID.HasValue && string.IsNullOrEmpty(model.ProductName)) {
|
||||
return context.Products
|
||||
.Where(x => x.CostItemID == model.CostItemID)
|
||||
|
@ -319,7 +319,7 @@ namespace ElectronicsShopEmployeeApp.Controllers {
|
||||
[HttpGet]
|
||||
public IActionResult Report() {
|
||||
if (APIEmployee.Employee == null) {
|
||||
return RedirectToAction("~/Home/Index");
|
||||
return Redirect("/Home/Index");
|
||||
}
|
||||
|
||||
return View();
|
||||
|
@ -175,9 +175,13 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public byte[]? CreateXlsxReport (int _clientID) {
|
||||
public byte[]? CreateXlsxReport (int _clientID, string DateFrom, string DateTo) {
|
||||
try {
|
||||
var document = _reportLogic.SavePaymeantToExcelFile (_clientID);
|
||||
var document = _reportLogic.SavePaymeantToExcelFile (new ReportBindingModel {
|
||||
ClientID = _clientID,
|
||||
DateFrom = DateTime.Parse(DateFrom),
|
||||
DateTo = DateTime.Parse(DateTo)
|
||||
});
|
||||
return document;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
@ -187,9 +191,13 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public byte[]? CreateDocxReport (int _clientID) {
|
||||
public byte[]? CreateDocxReport (int _clientID, string DateFrom, string DateTo) {
|
||||
try {
|
||||
var document = _reportLogic.SavePaymeantToWordFile (_clientID);
|
||||
var document = _reportLogic.SavePaymeantToWordFile (new ReportBindingModel {
|
||||
ClientID = _clientID,
|
||||
DateFrom = DateTime.Parse(DateFrom),
|
||||
DateTo = DateTime.Parse(DateTo)
|
||||
});
|
||||
return document;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
@ -212,7 +220,7 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
_mailWorker.MailSendAsync(new() {
|
||||
MailAddress = model.ClientEmail,
|
||||
Subject = "Отчет",
|
||||
Text = $"Отчет оплаченных товаров с {model.DateFrom} по {model.DateTo}",
|
||||
Text = $"Отчет оплаченных товаров с {model.DateFrom.ToShortDateString()} по {model.DateTo.ToShortDateString()}",
|
||||
document = data
|
||||
});
|
||||
|
||||
|
Binary file not shown.
@ -194,12 +194,10 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult DeleteProductOrder(int id) {
|
||||
var view = APIClient.GetRequset<OrderViewModel>($"api/main/getorder?_clientid={APIClient.Client?.ID}")
|
||||
?? throw new Exception("Îøèáêà ïîëó÷åíèÿ ìîäåëè");
|
||||
APIClient.PostRequestStr($"api/main/deleteproductorder", view.ID, id);
|
||||
public IActionResult DeleteProductOrder(int orderID, int id) {
|
||||
APIClient.PostRequestStr($"api/main/deleteproductorder", orderID, id);
|
||||
|
||||
return Redirect($"https://localhost:7219/Home/EditOrder/{view.ID}");
|
||||
return Redirect($"https://localhost:7219/Home/EditOrder/{orderID}");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -308,8 +306,9 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreateExcelReport() {
|
||||
var fileMemStream = APIClient.GetRequset<byte[]>($"api/Client/CreateXlsxReport?_clientID={APIClient.Client?.ID}");
|
||||
public IActionResult CreateExcelReport(string DateFrom, string DateTo) {
|
||||
var fileMemStream = APIClient.GetRequset<byte[]>($"api/Client/CreateXlsxReport?_clientID={APIClient.Client?.ID}&DateFrom={DateFrom}&" +
|
||||
$"DateTo={DateTo}");
|
||||
|
||||
if (fileMemStream == null) {
|
||||
throw new Exception("Îøèáêà ñîçäàíèÿ îò÷åòà");
|
||||
@ -319,8 +318,9 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreateWordReport() {
|
||||
var fileMemStream = APIClient.GetRequset<byte[]>($"api/client/CreateDocxReport?_clientID={APIClient.Client?.ID}");
|
||||
public IActionResult CreateWordReport(string DateFrom, string DateTo) {
|
||||
var fileMemStream = APIClient.GetRequset<byte[]>($"api/client/CreateDocxReport?_clientID={APIClient.Client?.ID}&DateFrom={DateFrom}&" +
|
||||
$"DateTo={DateTo}");
|
||||
|
||||
if (fileMemStream == null) {
|
||||
throw new Exception("Îøèáêà ñîçäàíèÿ îò÷åòà");
|
||||
|
@ -66,7 +66,8 @@
|
||||
</th>
|
||||
|
||||
<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>
|
||||
</tr>
|
||||
}
|
||||
|
@ -25,8 +25,10 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<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="CreateExcelReport" style="background-color:#04713A;">Экспорт отчета в .docx</a>
|
||||
<a class="btn btn-primary btn-sm" asp-action="CreateWordReport" asp-route-DateFrom="@Model.Item1"
|
||||
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"
|
||||
asp-route-DateTo="@Model.Item2" style="background-color:#ad0d09;">отправить на Email отчет в .pdf</a>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user