Отчеты_поручитель

This commit is contained in:
Табеев Александр 2024-05-29 15:50:02 +04:00
parent 4c12ecf513
commit 766b50e33a
18 changed files with 150 additions and 80 deletions

View File

@ -52,7 +52,7 @@ namespace ServiceStationBusinessLogic.BusinessLogics
return true;
}
public GuarantorViewModel? ReadElement(GuarantorSearchModel model)
public GuarantorViewModel? ReadElement(GuarantorSearchModel? model)
{
if (model == null)
{

View File

@ -1,4 +1,5 @@
using ServiceStationBusinessLogic.OfficePackage;
using DocumentFormat.OpenXml.Drawing;
using ServiceStationBusinessLogic.OfficePackage;
using ServiceStationBusinessLogic.OfficePackage.HelperModels;
using ServiceStationContracts.BindingModels;
using ServiceStationContracts.BusinessLogicsContracts;
@ -19,16 +20,18 @@ namespace ServiceStationBusinessLogic.BusinessLogics
private readonly ISparePartStorage _sparepartStorage;
private readonly IRepairStorage _repairStorage;
private readonly ITechnicalWorkStorage _techWorkStorage;
private readonly IWorkStorage _workStorage;
private readonly AbstractSaveToExcelGuarantor _saveToExcel;
private readonly AbstractSaveToWordGuarantor _saveToWord;
private readonly AbstractSaveToPdfGuarantor _saveToPdf;
public GuarantorReportLogic(IDefectStorage defectStorage, ISparePartStorage sparepartStorage, IRepairStorage repairStorage, ITechnicalWorkStorage techWorkStorage, AbstractSaveToExcelGuarantor saveToExcel, AbstractSaveToPdfGuarantor saveToPdf, AbstractSaveToWordGuarantor saveToWord)
public GuarantorReportLogic(IDefectStorage defectStorage, ISparePartStorage sparepartStorage, IRepairStorage repairStorage, ITechnicalWorkStorage techWorkStorage, AbstractSaveToExcelGuarantor saveToExcel, AbstractSaveToPdfGuarantor saveToPdf, AbstractSaveToWordGuarantor saveToWord, IWorkStorage workStorage)
{
_defectStorage = defectStorage;
_sparepartStorage = sparepartStorage;
_repairStorage = repairStorage;
_techWorkStorage = techWorkStorage;
_workStorage = workStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
@ -40,8 +43,6 @@ namespace ServiceStationBusinessLogic.BusinessLogics
List<ReportDefectsViewModel> allList = new List<ReportDefectsViewModel>();
double price = 0;
var defects = _defectStorage.GetFullList();
List<SparePartViewModel> spareparts = new List<SparePartViewModel>();
foreach (var sparepartId in Ids)
@ -58,6 +59,7 @@ namespace ServiceStationBusinessLogic.BusinessLogics
foreach (var sparepart in spareparts)
{
double price = 0;
var rec = new ReportDefectsViewModel
{
SparePartName = sparepart.SparePartName,
@ -65,7 +67,10 @@ namespace ServiceStationBusinessLogic.BusinessLogics
};
foreach (var defect in defects)
{
var repair = _repairStorage.GetElement(new RepairSearchModel
var repair = new RepairViewModel();
if (defect.RepairId.HasValue)
{
repair = _repairStorage.GetElement(new RepairSearchModel
{
Id = defect.RepairId,
});
@ -78,13 +83,14 @@ namespace ServiceStationBusinessLogic.BusinessLogics
}
}
}
}
rec.FullPrice = price;
allList.Add(rec);
}
return allList;
}
public List<ReportSparePartsViewModel> GetSpareParts(ReportGuarantorBindingModel model)
public List<ReportSparePartsViewModel> GetSpareParts(PdfReportBindingModel model)
{
List<ReportSparePartsViewModel> allList = new List<ReportSparePartsViewModel>();
@ -95,6 +101,9 @@ namespace ServiceStationBusinessLogic.BusinessLogics
GuarantorId = model.GuarantorId,
});
List<WorkViewModel> workList = _workStorage.GetFullList();
List<(WorkViewModel, int)> works = new();
foreach (var repair in repairList)
{
foreach (var sparepart in repair.RepairSpareParts.Values)
@ -107,23 +116,44 @@ namespace ServiceStationBusinessLogic.BusinessLogics
RepairStartDate = repair.RepairStartDate,
RepairPrice = repair.RepairPrice,
});
foreach (var work in workList)
{
if (work.WorkSpareParts.ContainsKey(sparepart.Id))
{
int contains = 0;
foreach (var workk in works)
{
var sparepartt = _sparepartStorage.GetElement(new SparePartSearchModel { Id = workk.Item2 });
if (workk.Item2 == sparepart.Id && workk.Item1.WorkName == work.WorkName)
{
contains++;
}
}
if (contains == 0)
{
works.Add(new(work, sparepart.Id));
}
}
}
}
}
List<TechnicalWorkViewModel> techWorkList = _techWorkStorage.GetFilteredList(new TechnicalWorkSearchModel
foreach (var work in works)
{
DateFrom = model.DateFrom,
DateTo = model.DateTo,
});
foreach (var techWork in techWorkList)
if (work.Item1.TechnicalWorkId.HasValue)
{
var techWork = _techWorkStorage.GetElement(new TechnicalWorkSearchModel { Id = work.Item1.TechnicalWorkId });
var sparepart = _sparepartStorage.GetElement(new SparePartSearchModel { Id = work.Item2 });
allList.Add(new ReportSparePartsViewModel
{
SparePartName = sparepart.SparePartName,
SparePartPrice = sparepart.SparePartPrice,
WorkType = techWork.WorkType,
TechnicalWorkDate = techWork.DateStartWork,
TechnicalWorkPrice = techWork.WorkPrice,
});
});;
}
}
return allList;
}
@ -132,7 +162,7 @@ namespace ServiceStationBusinessLogic.BusinessLogics
{
_saveToWord.CreateDoc(new WordInfoGuarantor
{
FileName = model.FileName,
FileStream = model.FileStream,
Title = "Список неисправностей",
DefectsBySparePart = GetDefects(model.Ids!)
});
@ -142,13 +172,13 @@ namespace ServiceStationBusinessLogic.BusinessLogics
{
_saveToExcel.CreateReport(new ExcelInfoGuarantor
{
FileName = model.FileName,
FileStream = model.FileStream,
Title = "Список работ",
DefectsBySparePart = GetDefects(model.Ids!)
});
}
public void SaveSparePartsToPdfFile(ReportGuarantorBindingModel model)
public void SaveSparePartsToPdfFile(PdfReportBindingModel model)
{
if (model.DateFrom == null)
{

View File

@ -33,7 +33,6 @@ namespace ServiceStationBusinessLogic.BusinessLogics
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
@ -48,7 +47,6 @@ namespace ServiceStationBusinessLogic.BusinessLogics
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
@ -85,20 +83,16 @@ namespace ServiceStationBusinessLogic.BusinessLogics
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(RepairBindingModel model)
{
CheckModel(model);
if (_repairStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
@ -119,13 +113,11 @@ namespace ServiceStationBusinessLogic.BusinessLogics
_logger.LogInformation("AddSparePartToRepair find. Id:{Id}", element.Id);
element.RepairSpareParts.Clear();
foreach (int sparepart in spareparts)
{
if (!element.RepairSpareParts.Keys.Contains(sparepart))
{
element.RepairSpareParts.Add(sparepart, new SparePartViewModel() { Id = sparepart });
}
}
_repairStorage.Update(new RepairBindingModel()
{

View File

@ -29,7 +29,7 @@ namespace ServiceStationBusinessLogic.MailWorker
objMailMessage.Body = info.Text;
objMailMessage.SubjectEncoding = Encoding.UTF8;
objMailMessage.BodyEncoding = Encoding.UTF8;
Attachment attachment = new Attachment(Directory.GetCurrentDirectory().Replace("ServiceStationRestApi", "ServiceStationExecutorApp") + "\\Reports\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf));
Attachment attachment = new Attachment(Directory.GetCurrentDirectory() + "\\Reports\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf));
objMailMessage.Attachments.Add(attachment);
objSmtpClient.UseDefaultCredentials = false;

View File

@ -10,6 +10,7 @@ namespace ServiceStationBusinessLogic.OfficePackage.HelperModels
public class ExcelInfoGuarantor
{
public string FileName { get; set; } = string.Empty;
public Stream FileStream { get; set; } = new MemoryStream();
public string Title { get; set; } = string.Empty;
public List<ReportDefectsViewModel> DefectsBySparePart { get; set; } = new();
}

View File

@ -10,6 +10,7 @@ namespace ServiceStationBusinessLogic.OfficePackage.HelperModels
public class WordInfoGuarantor
{
public string FileName { get; set; } = string.Empty;
public Stream FileStream { get; set; } = new MemoryStream();
public string Title { get; set; } = string.Empty;
public List<ReportDefectsViewModel> DefectsBySparePart { get; set; } = new();
}

View File

@ -192,7 +192,7 @@ namespace ServiceStationBusinessLogic.OfficePackage.Implements
protected override void CreateExcel(ExcelInfoGuarantor info)
{
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook);
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileStream, SpreadsheetDocumentType.Workbook);
var workbookpart = _spreadsheetDocument.AddWorkbookPart();
workbookpart.Workbook = new Workbook();

View File

@ -74,7 +74,7 @@ namespace ServiceStationBusinessLogic.OfficePackage.Implements
protected override void CreateWord(WordInfoGuarantor info)
{
_wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document);
_wordDocument = WordprocessingDocument.Create(info.FileStream, WordprocessingDocumentType.Document);
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
_docBody = mainPart.Document.AppendChild(new Body());

View File

@ -12,6 +12,8 @@ namespace ServiceStationContracts.BindingModels
public int ExecutorId { get; set; }
public int GuarantorId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }

View File

@ -8,7 +8,7 @@ namespace ServiceStationContracts.BindingModels
{
public class ReportGuarantorBindingModel
{
public string FileName { get; set; } = string.Empty;
public Stream FileStream { get; set; } = new MemoryStream();
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public int GuarantorId { get; set; }

View File

@ -11,12 +11,12 @@ namespace ServiceStationContracts.BusinessLogicsContracts
public interface IGuarantorReportLogic
{
List<ReportDefectsViewModel> GetDefects(List<int> Ids);
List<ReportSparePartsViewModel> GetSpareParts(ReportGuarantorBindingModel model);
List<ReportSparePartsViewModel> GetSpareParts(PdfReportBindingModel model);
void SaveDefectsToWordFile(ReportGuarantorBindingModel model);
void SaveDefectsToExcelFile(ReportGuarantorBindingModel model);
void SaveSparePartsToPdfFile(ReportGuarantorBindingModel model);
void SaveSparePartsToPdfFile(PdfReportBindingModel model);
}
}

View File

@ -3,6 +3,7 @@ using ServiceStationContracts.BindingModels;
using ServiceStationContracts.BusinessLogicsContracts;
using ServiceStationContracts.SearchModels;
using ServiceStationContracts.ViewModels;
using ServiceStationDatabaseImplement.Models;
using ServiceStationGuarantorApp.Models;
using System.Diagnostics;
using System.Runtime.InteropServices.ComTypes;
@ -217,7 +218,7 @@ namespace ServiceStationGuarantorApp.Controllers
List<ReportSparePartsViewModel> spareparts;
try
{
spareparts = _report.GetSpareParts(new ReportGuarantorBindingModel
spareparts = _report.GetSpareParts(new PdfReportBindingModel
{
GuarantorId = APIGuarantor.Guarantor.Id,
DateFrom = dateFrom,
@ -305,11 +306,11 @@ namespace ServiceStationGuarantorApp.Controllers
{
return RedirectToAction("Enter");
}
return View();
return View(APIGuarantor.GetRequest<List<SparePartViewModel>>($"api/main/getsparepartlist?guarantorId={APIGuarantor.Guarantor.Id}"));
}
[HttpPost]
public void CreateRepair(string repairName, double repairPrice)
public void CreateRepair(string repairName, double repairPrice, int[] sparepart)
{
if (APIGuarantor.Guarantor == null)
{
@ -321,6 +322,10 @@ namespace ServiceStationGuarantorApp.Controllers
RepairName = repairName,
RepairPrice = repairPrice
});
APIGuarantor.PostRequest("api/main/addspareparttorepair", Tuple.Create(
new RepairSearchModel() { RepairName = repairName },
sparepart
));
Response.Redirect("ListRepairs");
}
@ -332,11 +337,11 @@ namespace ServiceStationGuarantorApp.Controllers
return RedirectToAction("Enter");
}
ViewBag.Repairs = APIGuarantor.GetRequest<List<RepairViewModel>>($"api/main/getrepairlist?guarantorId={APIGuarantor.Guarantor.Id}");
return View();
return View(APIGuarantor.GetRequest<List<SparePartViewModel>>($"api/main/getsparepartlist?guarantorId={APIGuarantor.Guarantor.Id}"));
}
[HttpPost]
public void UpdateRepair(int repair, string RepairName, double RepairPrice)
public void UpdateRepair(int repair, string RepairName, double RepairPrice, int[] sparepart)
{
if (APIGuarantor.Guarantor == null)
{
@ -357,6 +362,10 @@ namespace ServiceStationGuarantorApp.Controllers
RepairName = RepairName,
RepairPrice = RepairPrice
});
APIGuarantor.PostRequest("api/main/addspareparttorepair", Tuple.Create(
new RepairSearchModel() { Id = repair },
sparepart
));
Response.Redirect("ListRepairs");
}
@ -592,7 +601,7 @@ namespace ServiceStationGuarantorApp.Controllers
}
[HttpPost]
public void ListDefectSparePartToFile(int[] Ids, string type)
public IActionResult ListDefectSparePartToFile(int[] Ids, string type)
{
if (APIGuarantor.Guarantor == null)
{
@ -616,21 +625,29 @@ namespace ServiceStationGuarantorApp.Controllers
if (type == "docx")
{
APIGuarantor.PostRequest("api/report/createguarantorreporttoword", new ReportGuarantorBindingModel
using (var stream = new MemoryStream())
{
Ids = res,
FileName = Directory.GetCurrentDirectory() + "\\Reports\\wordfile.docx"
_report.SaveDefectsToWordFile(new ReportGuarantorBindingModel
{
FileStream = stream,
Ids = res
});
Response.Redirect("GetWordFile");
stream.Seek(0, SeekOrigin.Begin);
return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "wordfile.docx");
}
}
else
{
APIGuarantor.PostRequest("api/report/createguarantorreporttoexcel", new ReportGuarantorBindingModel
using (var stream = new MemoryStream())
{
Ids = res,
FileName = Directory.GetCurrentDirectory() + "\\Reports\\excelfile.xlsx"
_report.SaveDefectsToExcelFile(new ReportGuarantorBindingModel
{
FileStream = stream,
Ids = res
});
Response.Redirect("GetExcelFile");
stream.Seek(0, SeekOrigin.Begin);
return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "excelfile.xlsx");
}
}
}
@ -654,14 +671,20 @@ namespace ServiceStationGuarantorApp.Controllers
{
throw new Exception("Email пуст");
}
APIGuarantor.PostRequest("api/report/createguarantorreporttopdf", new ReportGuarantorBindingModel
APIGuarantor.PostRequest("api/report/createguarantorreporttopdf", new PdfReportBindingModel
{
FileName = Directory.GetCurrentDirectory() + "\\Reports\\pdffile.pdf",
FileName = Directory.GetCurrentDirectory().Replace("ServiceStationGuarantorApp", "ServiceStationRestApi") + "\\Reports\\pdffile.pdf",
DateFrom = dateFrom,
DateTo = dateTo,
GuarantorId = APIGuarantor.Guarantor.Id,
});
Response.Redirect("GetPdfFile");
APIGuarantor.PostRequest("api/report/sendpdftomail", new MailSendInfoBindingModel
{
MailAddress = guarantorEmail,
Subject = "Отчет по запчастям",
Text = "Отчет по запчастям с " + dateFrom.ToShortDateString() + " по " + dateTo.ToShortDateString()
});
Response.Redirect("ListSparePartsToPdf");
}
public IActionResult BindingRepairToDefects()
@ -686,6 +709,7 @@ namespace ServiceStationGuarantorApp.Controllers
Id = defect,
RepairId = repair
});
Response.Redirect("BindingRepairToDefects");
}
}
}

View File

@ -31,6 +31,22 @@
<th scope="col" class="fs-5">Цена</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr style="height: 75px">
<td>
<input type="checkbox" class="form-check-input" name="Ids[]" value="@item.Id" id="@item.Id">
</td>
<td>
@Html.DisplayFor(modelItem => item.SparePartName)
</td>
<td>
@Html.DisplayFor(modelItem => item.SparePartPrice)
</td>
</tr>
}
</tbody>
</table>
<div class="d-flex justify-content-center">

View File

@ -13,22 +13,22 @@
<div class="card-body">
<div class="form-group pb-3">
<label>Номер телефона</label>
<input type="text" name="number" class="form-control" placeholder="Введите номер телефона" />
<input type="text" name="number" value="@Model.GuarantorNumber" class="form-control" placeholder="Введите номер телефона" />
</div>
<div class="form-group pb-3">
<label>Электронная почта</label>
<input type="text" name="email" class="form-control" placeholder="Введите электронную почту" />
<input type="text" name="email" value="@Model.GuarantorEmail" class="form-control" placeholder="Введите электронную почту" />
</div>
<div class="form-group pb-3">
<label>ФИО</label>
<input type="text" name="FIO" class="form-control" placeholder="Введите ФИО" />
<input type="text" name="FIO" value="@Model.GuarantorFIO" class="form-control" placeholder="Введите ФИО" />
</div>
<div class="form-group pb-3">
<label>Пароль</label>
<input type="text" name="password" class="form-control" placeholder="Введите пароль" />
<input type="text" name="password" value="@Model.GuarantorPassword" class="form-control" placeholder="Введите пароль" />
</div>
<div class="form-group d-flex justify-content-center">

View File

@ -83,11 +83,11 @@ namespace ServiceStationRestApi.Controllers
}
[HttpPost]
public void CreateGuarantorReportToPdf(ReportGuarantorBindingModel model)
public void CreateGuarantorReportToPdf(PdfReportBindingModel model)
{
try
{
_guarantorReportLogic.SaveSparePartsToPdfFile(new ReportGuarantorBindingModel
_guarantorReportLogic.SaveSparePartsToPdfFile(new PdfReportBindingModel
{
FileName = model.FileName,
DateFrom = model.DateFrom,

View File

@ -17,4 +17,8 @@
<ProjectReference Include="..\ServiceStationDatabaseImplement\ServiceStationDatabaseImplement.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Reports\" />
</ItemGroup>
</Project>