This commit is contained in:
parent
cd21f23715
commit
13f475d64b
@ -14,22 +14,22 @@ namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper
|
||||
|
||||
private readonly IGoodStorage _goodStorage;
|
||||
|
||||
private readonly IUserStorage _userStorage;
|
||||
|
||||
private readonly AbstractSaveToExcel _saveToExcel;
|
||||
|
||||
private readonly AbstractSaveToWord _saveToWord;
|
||||
|
||||
private readonly AbstractSaveToPdf _saveToPdf;
|
||||
|
||||
private readonly AbstractMailWorker _mailWorker;
|
||||
|
||||
public ReportStorekeeperLogic(IComponentStorage componentStorage, AbstractSaveToExcel abstractSaveToExcel, AbstractSaveToWord abstractSaveToWord, IGoodStorage goodStorage, AbstractMailWorker abstractMailWorker, IUserStorage userStorage)
|
||||
public ReportStorekeeperLogic(IComponentStorage componentStorage, AbstractSaveToExcel abstractSaveToExcel, AbstractSaveToWord abstractSaveToWord, IGoodStorage goodStorage, AbstractMailWorker abstractMailWorker, AbstractSaveToPdf saveToPdf)
|
||||
{
|
||||
_componentStorage = componentStorage;
|
||||
_saveToExcel = abstractSaveToExcel;
|
||||
_saveToWord = abstractSaveToWord;
|
||||
_goodStorage = goodStorage;
|
||||
_mailWorker = abstractMailWorker;
|
||||
_userStorage = userStorage;
|
||||
_saveToPdf = saveToPdf;
|
||||
}
|
||||
public List<ReportBuildGoodViewModel> GetBuildGood(List<GoodViewModel> goods)
|
||||
{
|
||||
@ -119,15 +119,24 @@ namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper
|
||||
|
||||
public bool SendReportOnMail(ReportBindingModel model)
|
||||
{
|
||||
var user = _userStorage.GetElement(new() { Id = model.UserId });
|
||||
if (user == null) return false;
|
||||
model.FileName = "temp.pdf";
|
||||
_saveToPdf.CreateComponentsReport(new PdfInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Отчет по комплектующим",
|
||||
DateFrom = model.DateFrom,
|
||||
DateTo = model.DateTo,
|
||||
ReportComponents = GetComponents(model)
|
||||
});
|
||||
byte[] file = File.ReadAllBytes(model.FileName);
|
||||
File.Delete(model.FileName);
|
||||
|
||||
_mailWorker.MailSendAsync(new()
|
||||
{
|
||||
MailAddress = user.Email,
|
||||
MailAddress = model.UserEmail,
|
||||
Subject = "Отчет по комплектующим",
|
||||
Text = $"Отчет по полученным вами комлектующим за период с {model.DateFrom} по {model.DateTo} в формате Pdf.",
|
||||
//File = file
|
||||
File = file
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts
|
||||
/// <param name="model"></param>
|
||||
public void SendByMailPurchaseReport(ReportBindingModel model)
|
||||
{
|
||||
byte[] file = _saveToPdf.GetPurchaseReportFile(new()
|
||||
_saveToPdf.GetPurchaseReportFile(new()
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Отчет по покупкам",
|
||||
@ -160,6 +160,9 @@ namespace HardwareShopContracts.BusinessLogicsContracts
|
||||
DateTo = model.DateTo,
|
||||
ReportPurchases = GetPurchase(model)
|
||||
});
|
||||
byte[] file = File.ReadAllBytes(model.FileName);
|
||||
File.Delete(model.FileName);
|
||||
|
||||
_mailKitWorker.MailSendAsync(new()
|
||||
{
|
||||
MailAddress = model.UserEmail,
|
||||
|
@ -11,6 +11,7 @@
|
||||
<PackageReference Include="MailKit" Version="4.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||
<PackageReference Include="System.Text.Encoding" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -7,7 +7,7 @@ namespace HardwareShopBusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToPdf
|
||||
{
|
||||
public byte[] GetPurchaseReportFile(PdfInfo info)
|
||||
public void GetPurchaseReportFile(PdfInfo info)
|
||||
{
|
||||
CreatePdf(info);
|
||||
|
||||
@ -74,9 +74,51 @@ namespace HardwareShopBusinessLogic.OfficePackage
|
||||
}
|
||||
}
|
||||
|
||||
return GetFile(info);
|
||||
SavePdf(info);
|
||||
}
|
||||
|
||||
public void CreateComponentsReport(PdfInfo info)
|
||||
{
|
||||
CreatePdf(info);
|
||||
CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center });
|
||||
CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center });
|
||||
|
||||
CreateTable(new List<string> { "5cm", "5cm", "3cm" });
|
||||
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { "Комплектующее", "Товар/Сборка", "Количество" },
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
|
||||
foreach (var record in info.ReportComponents)
|
||||
{
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { record.ComponentName, "", "" },
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
foreach (var goodOrBuild in record.GoodOrBuilds)
|
||||
{
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { "", goodOrBuild.Item1, goodOrBuild.Item2.ToString() },
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
}
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { "Итого", "", record.TotalCount.ToString() },
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
}
|
||||
|
||||
SavePdf(info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание doc-файла
|
||||
@ -109,11 +151,5 @@ namespace HardwareShopBusinessLogic.OfficePackage
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
protected abstract void SavePdf(PdfInfo info);
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение отправляем файл
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
protected abstract byte[] GetFile(PdfInfo info);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.DocumentObjectModel.Tables;
|
||||
using MigraDoc.Rendering;
|
||||
|
||||
|
||||
namespace HardwareShopBusinessLogic.OfficePackage.Implements
|
||||
{
|
||||
public class SaveToPdf : AbstractSaveToPdf
|
||||
@ -107,16 +108,9 @@ namespace HardwareShopBusinessLogic.OfficePackage.Implements
|
||||
{
|
||||
Document = _document
|
||||
};
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
renderer.RenderDocument();
|
||||
renderer.PdfDocument.Save(info.FileName);
|
||||
}
|
||||
|
||||
protected override byte[] GetFile(PdfInfo info)
|
||||
{
|
||||
SavePdf(info);
|
||||
byte[] file = File.ReadAllBytes(info.FileName);
|
||||
File.Delete(info.FileName);
|
||||
return file;
|
||||
}
|
||||
}
|
||||
}
|
@ -440,6 +440,7 @@ namespace HardwareShopStorekeeperApp.Controllers
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
}
|
||||
reportModel.UserId = APIClient.User.Id;
|
||||
reportModel.UserEmail = APIClient.User.Email;
|
||||
APIClient.PostRequest("api/report/componentsreportsendonmail", reportModel);
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,6 @@ namespace HardwareShopRestApi.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
string subject =
|
||||
_reportStorekeeperLogic.SendReportOnMail(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
Loading…
Reference in New Issue
Block a user