60 lines
2.3 KiB
C#
60 lines
2.3 KiB
C#
namespace FKGees.Services;
|
|
|
|
internal class RegistersService
|
|
{
|
|
private readonly PcmService _pcmService;
|
|
private readonly CsvService _csvService;
|
|
private readonly IEnumerable<IRegistersDefinition> _definitions;
|
|
private readonly ILogger<DecretsService> _logger;
|
|
private readonly Context _context;
|
|
|
|
public RegistersService(PcmService pcmService, CsvService csvService, IEnumerable<IRegistersDefinition> definitions,
|
|
ILogger<DecretsService> logger, Context context)
|
|
{
|
|
_pcmService = pcmService;
|
|
_csvService = csvService;
|
|
_definitions = definitions;
|
|
_logger = logger;
|
|
_context = context;
|
|
}
|
|
|
|
public async Task Process()
|
|
{
|
|
try
|
|
{
|
|
var result = new List<RegistersResult>();
|
|
|
|
foreach (var definition in _definitions)
|
|
{
|
|
var docs = await _pcmService.FetchRegistersDocuments(definition.DocTypes, _context.StatDate, _context.EndDate);
|
|
result.AddRange(await definition.Process(docs));
|
|
}
|
|
|
|
_logger.LogInformation("RegistersService - Export success");
|
|
Console.WriteLine("Eksport do pliku rejestrów");
|
|
Console.WriteLine();
|
|
await _csvService.CsvExport("Export/rejestry.csv", result.OrderBy(x => x.dwystawienia));
|
|
Console.WriteLine("Eksport do pliku rejestrów zakończony powodzeniem");
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_logger.LogError(e, "RegistersService - Export failed");
|
|
Console.WriteLine("Eksport do pliku rejestrów zakończony niepowodzeniem");
|
|
Console.WriteLine(e.Message);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
private async Task<List<FormaPlatnosci>> GetPaymentForms()
|
|
{
|
|
var paymentForms = await _pcmService.FormyPlatnosci();
|
|
paymentForms.Add(new FormaPlatnosci {FormaPlat = 0, Tekst = "Gotówka"});
|
|
paymentForms.Add(new FormaPlatnosci {FormaPlat = 1, Tekst = "Przelew"});
|
|
paymentForms.Add(new FormaPlatnosci {FormaPlat = 2, Tekst = "Czek potwierdzony"});
|
|
paymentForms.Add(new FormaPlatnosci {FormaPlat = 3, Tekst = "Karta płatnicza"});
|
|
paymentForms.Add(new FormaPlatnosci {FormaPlat = 4, Tekst = "Inna"});
|
|
|
|
return paymentForms.OrderBy(x => x.FormaPlat)
|
|
.ToList();
|
|
}
|
|
} |