diff --git a/FKGees/Constants.cs b/FKGees/Constants.cs index e80ae36..0e07713 100644 --- a/FKGees/Constants.cs +++ b/FKGees/Constants.cs @@ -12,6 +12,7 @@ namespace FKGees public const string Login = "DbSettings:Login"; public const string Password = "DbSettings:Password"; public const string Database = "DbSettings:Database"; + public const string Timeout = "DbSettings:Timeout"; } public static readonly Dictionary KwTekstyDod = new() diff --git a/FKGees/Context.cs b/FKGees/Context.cs index 4207919..a10c6dc 100644 --- a/FKGees/Context.cs +++ b/FKGees/Context.cs @@ -1,6 +1,4 @@ - - -namespace FKGees; +namespace FKGees; public class Context { @@ -8,4 +6,6 @@ public class Context public DateTime StatDate { get; set; } = DateTime.Today - TimeSpan.FromDays(1); public DateTime EndDate { get; set; } = DateTime.Today - TimeSpan.FromSeconds(1); public List PaymentForms { get; set; } = new(); + public string RegistersFileName { get; set; } + public string DecretsFileName { get; set; } } \ No newline at end of file diff --git a/FKGees/DocsDefinitions/Decrets/KpKaucjaZDokUtargu.cs b/FKGees/DocsDefinitions/Decrets/KpKaucjaZDokUtargu.cs index a190169..f962240 100644 --- a/FKGees/DocsDefinitions/Decrets/KpKaucjaZDokUtargu.cs +++ b/FKGees/DocsDefinitions/Decrets/KpKaucjaZDokUtargu.cs @@ -15,7 +15,9 @@ public class KpKaucjaZDokUtargu : IDecretsDefinition var result = new List(); var toProcess = documents - .Where(x => x.TypDok == DocType && x.Kwota1 != 0); + .Where(x => x.TypDok == DocType && x.Kwota1 != 0) + .GroupBy(x => x.Data); + foreach (var dok in toProcess) { @@ -23,13 +25,13 @@ public class KpKaucjaZDokUtargu : IDecretsDefinition { var item = new DecretsResult { - Data = dok.DataPom, - DataWplywu = dok.Data, - Nr = dok.NrDok, - Opis = $"KAUCJA ZA OPAKOWANIA {dok.DokKasa?.Kasa.Nazwa ?? string.Empty}", + Data = dok.Key, + DataWplywu = dok.Key, + Nr = string.Join(", ",dok.Select(z => z.NrDok)), + Opis = "KAUCJA ZA OPAKOWANIA-SPRZEDAŻ", StronaKonta = d.AccountSide, KontoFk = d.Account, - Kwota = dok.Kwota1.AsString() + Kwota = dok.Sum(x => x.Kwota1).AsString() }; result.Add(item); diff --git a/FKGees/DocsDefinitions/Decrets/KwKaucjaZDokUtargu.cs b/FKGees/DocsDefinitions/Decrets/KwKaucjaZDokUtargu.cs new file mode 100644 index 0000000..54fd1ae --- /dev/null +++ b/FKGees/DocsDefinitions/Decrets/KwKaucjaZDokUtargu.cs @@ -0,0 +1,43 @@ +namespace FKGees.DocsDefinitions.Decrets; + +public class KwKaucjaZDokUtargu : IDecretsDefinition +{ + public int DocType => 53; + public string Type => nameof(KwKaucjaZDokUtargu); + public List Definitions { get; } = + [ + new Definition("100-1-24", "MA", "[sbr]"), + new Definition("139-1-24", "WN", "[sbr]") + ]; + + public Task> Process(IReadOnlyList documents) + { + var result = new List(); + + var toProcess = documents + .Where(x => x.TypDok == DocType && x.Kwota2 != 0) + .GroupBy(x => x.Data); + + + foreach (var dok in toProcess) + { + Definitions.ForEach(d => + { + var item = new DecretsResult + { + Data = dok.Key, + DataWplywu = dok.Key, + Nr = string.Join(", ",dok.Select(z => z.NrDok)), + Opis = "KAUCJA ZA OPAKOWANIA-ZWROT", + StronaKonta = d.AccountSide, + KontoFk = d.Account, + Kwota = dok.Sum(x => x.Kwota2).AsString() + }; + + result.Add(item); + }); + } + + return Task.FromResult(result); + } +} \ No newline at end of file diff --git a/FKGees/DocsDefinitions/Decrets/RapFisk.cs b/FKGees/DocsDefinitions/Decrets/RapFisk.cs index 15836d3..56e0d6c 100644 --- a/FKGees/DocsDefinitions/Decrets/RapFisk.cs +++ b/FKGees/DocsDefinitions/Decrets/RapFisk.cs @@ -51,8 +51,8 @@ public class RapFisk : IDecretsDefinition { return expression switch { - "[sbr]" => doc.Netto+ doc.Podatek + doc.NettoUslugi + doc.PodatekUslugi, - "[svr]" => doc.Podatek + doc.PodatekUslugi, + "[sbr]" => doc.Razem - doc.Kwota1 + doc.Kwota2, + "[svr]" => doc.Podatek, _ => 0 }; } diff --git a/FKGees/DocsDefinitions/Decrets/Wz.cs b/FKGees/DocsDefinitions/Decrets/Wz.cs index c1ec9cd..62c4ea4 100644 --- a/FKGees/DocsDefinitions/Decrets/Wz.cs +++ b/FKGees/DocsDefinitions/Decrets/Wz.cs @@ -2,7 +2,7 @@ public class Wz : IDecretsDefinition { - public int DocType => 2; + public int DocType => 5; public string Type => "Wz"; public List Definitions { get; } = [ diff --git a/FKGees/Extensions/ServiceCollectionExtensions.cs b/FKGees/Extensions/ServiceCollectionExtensions.cs index 1b93892..0fabd3d 100644 --- a/FKGees/Extensions/ServiceCollectionExtensions.cs +++ b/FKGees/Extensions/ServiceCollectionExtensions.cs @@ -27,6 +27,7 @@ internal static class ServiceCollectionExtensions services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/FKGees/Program.cs b/FKGees/Program.cs index 6acfa27..3bbb13b 100644 --- a/FKGees/Program.cs +++ b/FKGees/Program.cs @@ -62,11 +62,22 @@ static IServiceCollection AddServices(IConfiguration config) { var connectionString = $"Server={config[Constants.DbConfig.Host]},{config[Constants.DbConfig.Port]};Database={config[Constants.DbConfig.Database]};User Id={config[Constants.DbConfig.Login]}; Password={config[Constants.DbConfig.Password]};TrustServerCertificate=True"; + + if (!int.TryParse(config[Constants.DbConfig.Timeout], out var dbTimeout) || dbTimeout < 30) + { + dbTimeout = 30; + } + var symbolMag = config["SymbolMag"] ?? string.Empty; - var context = new Context(); - context.SymbolMag = symbolMag; - - + var nazwaPlikuRejestry = config["NazwaPlikuRejestry"] ?? "rejestry.txt"; + var nazwaPlikuDekrety = config["NazwaPlikuDekrety"] ?? "dekrety.txt"; + var context = new Context + { + SymbolMag = symbolMag, + RegistersFileName = nazwaPlikuRejestry, + DecretsFileName = nazwaPlikuDekrety + }; + var services = new ServiceCollection() .AddLogging(loggingBuilder => { @@ -84,7 +95,10 @@ static IServiceCollection AddServices(IConfiguration config) .AddTransient() .AddDbContextFactory(options => { - options.UseSqlServer(connectionString); + options.UseSqlServer(connectionString, o => + { + o.CommandTimeout(dbTimeout); + }); options.UseModel(Blink.Backoffice.Services.PcmDb.CompiledEntities.PcmDbContextModel.Instance); options.EnableSensitiveDataLogging(false); }); diff --git a/FKGees/Services/DecretsService.cs b/FKGees/Services/DecretsService.cs index a4a3760..f8361d3 100644 --- a/FKGees/Services/DecretsService.cs +++ b/FKGees/Services/DecretsService.cs @@ -22,6 +22,8 @@ internal class DecretsService try { _logger.LogInformation("DecretsService - Start exports decrets, StartDate: {StartDate}, EndDate: {EndDate}", _context.StatDate , _context.EndDate); + Console.WriteLine(); + Console.WriteLine("Export dekretów"); var doctypes = _definitions.Select(x => x.DocType) .ToArray(); @@ -39,7 +41,7 @@ internal class DecretsService _logger.LogInformation("DecretsService - Export success"); Console.WriteLine("Eksport do pliku dekretów"); Console.WriteLine(); - await _csvService.CsvExport("Export/dekrety.csv", result.OrderBy(x => x.Data).ThenBy(x => x.Nr)); + await _csvService.CsvExport($"Export/{_context.DecretsFileName}", result.OrderBy(x => x.Data).ThenBy(x => x.Nr)); Console.WriteLine("Eksport do pliku dekretów zakończony powodzeniem"); } catch (Exception e) diff --git a/FKGees/Services/RegistersService.cs b/FKGees/Services/RegistersService.cs index ee98669..a11388c 100644 --- a/FKGees/Services/RegistersService.cs +++ b/FKGees/Services/RegistersService.cs @@ -22,18 +22,24 @@ internal class RegistersService { try { + _logger.LogInformation("RegistersService - Start exports registers, StartDate: {StartDate}, EndDate: {EndDate}", _context.StatDate , _context.EndDate); + Console.WriteLine(); + Console.WriteLine("Export rejestrów"); + var result = new List(); foreach (var definition in _definitions) { + _logger.LogInformation("RegistersService - Export type: {Type}", definition.Type); + Console.WriteLine($"Export: {definition.Type}"); 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)); + await _csvService.CsvExport($"Export/{_context.RegistersFileName}", result.OrderBy(x => x.dwystawienia)); Console.WriteLine("Eksport do pliku rejestrów zakończony powodzeniem"); } catch (Exception e) @@ -44,17 +50,4 @@ internal class RegistersService throw; } } - - private async Task> 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(); - } } \ No newline at end of file diff --git a/FKGees/appsettings.json b/FKGees/appsettings.json index d804c80..7eb8cdd 100644 --- a/FKGees/appsettings.json +++ b/FKGees/appsettings.json @@ -11,7 +11,10 @@ "Port": "1433", "Login": "sa", "Password": "10Coma123", - "Database": "HECZNAROWICE" + "Database": "HECZNAROWICE", + "Timeout": 666 }, - "SymbolMag": "FajnySklep" + "SymbolMag": "FajnySklep", + "NazwaPlikuDekrety": "dekrety.txt", + "NazwaPlikuRejestry": "rejestry.txt" }