Rejestry #1
This commit is contained in:
@@ -1,27 +1,27 @@
|
||||
using System.Globalization;
|
||||
using CsvHelper;
|
||||
using CsvHelper.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using FKGees.Services;
|
||||
|
||||
namespace FKGees;
|
||||
|
||||
public class App
|
||||
internal class App
|
||||
{
|
||||
private readonly DocumentsService _documentsService;
|
||||
private readonly IEnumerable<IDocumentDefinition> _docDefinitions;
|
||||
private readonly DecretsService _decretsService;
|
||||
private readonly PcmService _pcmService;
|
||||
private readonly Context _context;
|
||||
private ILogger<App> _logger;
|
||||
private readonly RegistersService _registersService;
|
||||
|
||||
public App(DocumentsService documentsService, ILogger<App> logger, IEnumerable<IDocumentDefinition> docDefinitions)
|
||||
public App(Context context, ILogger<App> logger, RegistersService registersService, DecretsService decretsService, PcmService pcmService)
|
||||
{
|
||||
_documentsService = documentsService;
|
||||
_context = context;
|
||||
_logger = logger;
|
||||
_docDefinitions = docDefinitions;
|
||||
_registersService = registersService;
|
||||
_decretsService = decretsService;
|
||||
_pcmService = pcmService;
|
||||
}
|
||||
|
||||
public async Task Run(string[] args)
|
||||
{
|
||||
var dataOd = DateTime.Today - TimeSpan.FromDays(1);
|
||||
var dataDo = DateTime.Today - TimeSpan.FromSeconds(1);
|
||||
if (args.Length == 0)
|
||||
{
|
||||
Console.WriteLine("Nie podano argumentów - wykonuję eksport 'Za wczoraj'");
|
||||
@@ -35,61 +35,27 @@ public class App
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!DateTime.TryParseExact(args[0], Constants.DefaultdateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dataOd))
|
||||
if (!DateTime.TryParseExact(args[0], Constants.DefaultdateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out var startDate))
|
||||
{
|
||||
Console.WriteLine("Niewłaściwy format DataOd");
|
||||
await Task.Delay(4000);
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
if (!DateTime.TryParseExact(args[1], Constants.DefaultdateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dataDo))
|
||||
if (!DateTime.TryParseExact(args[1], Constants.DefaultdateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out var endDate))
|
||||
{
|
||||
Console.WriteLine("Niewłaściwy format DataOd");
|
||||
await Task.Delay(4000);
|
||||
Environment.Exit(1);
|
||||
}
|
||||
endDate = endDate.AddDays(1) - TimeSpan.FromSeconds(1);
|
||||
_context.StatDate = startDate;
|
||||
_context.EndDate = endDate;
|
||||
}
|
||||
|
||||
var doctypes = _docDefinitions.Select(x => x.DocType)
|
||||
.ToArray();
|
||||
_context.PaymentForms = await _pcmService.FormyPlatnosci();
|
||||
|
||||
var doks = await _documentsService.Fetch(doctypes, dataOd, dataDo.AddDays(1) - TimeSpan.FromSeconds(1));
|
||||
|
||||
var result = new List<DecretsResult>();
|
||||
foreach (var docDefinition in _docDefinitions)
|
||||
{
|
||||
Console.WriteLine($"Export: {docDefinition.Type}");
|
||||
var res = await docDefinition.Process(doks);
|
||||
result.AddRange(res);
|
||||
}
|
||||
|
||||
Console.WriteLine("Eksport do pliku dekretów");
|
||||
Console.WriteLine();
|
||||
await using var writer = new StreamWriter("Export/dekrety.csv");
|
||||
|
||||
try
|
||||
{
|
||||
IWriterConfiguration conf = new CsvConfiguration(CultureInfo.InvariantCulture)
|
||||
{
|
||||
Delimiter = ";",
|
||||
Mode = CsvMode.RFC4180,
|
||||
ShouldQuote = quoteArgs => quoteArgs.Field != nameof(DecretsResult.Data)
|
||||
&& quoteArgs.Field != nameof(DecretsResult.DataWplywu)
|
||||
&& !DateTime.TryParseExact(quoteArgs.Field, Constants.DefaultdateFormat, CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.None, out _)
|
||||
};
|
||||
await using var csv = new CsvWriter(writer, conf);
|
||||
await csv.WriteRecordsAsync(result.OrderBy(x => x.Data));
|
||||
|
||||
Console.WriteLine("Eksport udany");
|
||||
await Task.Delay(5000);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "Error");
|
||||
Console.WriteLine("Eksport się nie udał");
|
||||
Console.WriteLine(e.Message);
|
||||
throw;
|
||||
}
|
||||
await _registersService.Process();
|
||||
await _decretsService.Process();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using FKGees.DocsDefinitions;
|
||||
using FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
namespace FKGees
|
||||
{
|
||||
|
||||
11
FKGees/Context.cs
Normal file
11
FKGees/Context.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
namespace FKGees;
|
||||
|
||||
public class Context
|
||||
{
|
||||
public string SymbolMag { get; set; }
|
||||
public DateTime StatDate { get; set; } = DateTime.Today - TimeSpan.FromDays(1);
|
||||
public DateTime EndDate { get; set; } = DateTime.Today - TimeSpan.FromSeconds(1);
|
||||
public List<FormaPlatnosci> PaymentForms { get; set; } = new();
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
using FKGees.Services;
|
||||
|
||||
public class FaktSprz : IDocumentDefinition
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class FaktSprz : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 33;
|
||||
public string Type => "FaktSprz";
|
||||
@@ -16,11 +18,11 @@ public class FaktSprz : IDocumentDefinition
|
||||
new Definition("332-0-24", "MA", "[sbr]"),
|
||||
];
|
||||
|
||||
private readonly DocumentsService _documentsService;
|
||||
private readonly PcmService _pcmService;
|
||||
|
||||
public FaktSprz(DocumentsService documentsService)
|
||||
public FaktSprz(PcmService pcmService)
|
||||
{
|
||||
_documentsService = documentsService;
|
||||
_pcmService = pcmService;
|
||||
}
|
||||
|
||||
public Task<List<DecretsResult>> Process(IReadOnlyList<Dok> documents)
|
||||
@@ -32,17 +34,17 @@ public class FaktSprz : IDocumentDefinition
|
||||
|
||||
foreach (var dok in toProcess)
|
||||
{
|
||||
var fakt = _documentsService.WzNrFaktury(dok.DokId);
|
||||
var fakt = _pcmService.WzNrFaktury(dok.DokId);
|
||||
Definitions.ForEach(d =>
|
||||
{
|
||||
var item = dok.FillKontr();
|
||||
item.Data = dok.DataPom.ToString(Constants.DefaultdateFormat);
|
||||
item.DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat);
|
||||
var item = dok.DecretKontr();
|
||||
item.Data = dok.DataPom;
|
||||
item.DataWplywu = dok.Data;
|
||||
item.Nr = dok.NrDok;
|
||||
item.Opis = fakt;
|
||||
item.StronaKonta = d.AccountSide;
|
||||
item.KontoFk = d.Account;
|
||||
item.Kwota = ProcessValue(dok, d.Expression);
|
||||
item.Kwota = ProcessValue(dok, d.Expression).AsString();
|
||||
|
||||
result.Add(item);
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class KorDetal : IDocumentDefinition
|
||||
public class KorDetal : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 8;
|
||||
public string Type => "KorDetal";
|
||||
@@ -20,14 +20,14 @@ public class KorDetal : IDocumentDefinition
|
||||
{
|
||||
Definitions.ForEach(d =>
|
||||
{
|
||||
var item = dok.FillKontr();
|
||||
item.Data = dok.DataPom.ToString(Constants.DefaultdateFormat);
|
||||
item.DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat);
|
||||
var item = dok.DecretKontr();
|
||||
item.Data = dok.DataPom;
|
||||
item.DataWplywu = dok.Data;
|
||||
item.Nr = dok.NrDok;
|
||||
item.Opis = dok.NrDok;
|
||||
item.StronaKonta = d.AccountSide;
|
||||
item.KontoFk = d.Account;
|
||||
item.Kwota = dok.Netto;
|
||||
item.Kwota = dok.Netto.AsString();
|
||||
|
||||
result.Add(item);
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class KpInne : IDocumentDefinition
|
||||
public class KpInne : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 51;
|
||||
public string Type => nameof(KpInne);
|
||||
@@ -25,13 +25,13 @@ public class KpInne : IDocumentDefinition
|
||||
{
|
||||
var item = new DecretsResult
|
||||
{
|
||||
Data = dok.DataPom.ToString(Constants.DefaultdateFormat),
|
||||
DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat),
|
||||
Data = dok.DataPom,
|
||||
DataWplywu = dok.Data,
|
||||
Nr = dok.NrDok,
|
||||
Opis = dok.TekstZaCo(),
|
||||
StronaKonta = d.AccountSide,
|
||||
KontoFk = d.Account,
|
||||
Kwota = Math.Abs(dok.Zaplacono)
|
||||
Kwota = Math.Abs(dok.Zaplacono).AsString()
|
||||
};
|
||||
|
||||
result.Add(item);
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class KpKasy : IDocumentDefinition
|
||||
public class KpKasy : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 51;
|
||||
public string Type => nameof(KpKasy);
|
||||
@@ -25,13 +25,13 @@ public class KpKasy : IDocumentDefinition
|
||||
{
|
||||
var item = new DecretsResult
|
||||
{
|
||||
Data = dok.DataPom.ToString(Constants.DefaultdateFormat),
|
||||
DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat),
|
||||
Data = dok.DataPom,
|
||||
DataWplywu = dok.Data,
|
||||
Nr = dok.NrDok,
|
||||
Opis = dok.TekstZaCo(),
|
||||
StronaKonta = d.AccountSide,
|
||||
KontoFk = d.Account,
|
||||
Kwota = Math.Abs(dok.Zaplacono)
|
||||
Kwota = Math.Abs(dok.Zaplacono).AsString()
|
||||
};
|
||||
|
||||
result.Add(item);
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class KpKaucjaZDokUtargu : IDocumentDefinition
|
||||
public class KpKaucjaZDokUtargu : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 53;
|
||||
public string Type => nameof(KpKaucjaZDokUtargu);
|
||||
@@ -23,13 +23,13 @@ public class KpKaucjaZDokUtargu : IDocumentDefinition
|
||||
{
|
||||
var item = new DecretsResult
|
||||
{
|
||||
Data = dok.DataPom.ToString(Constants.DefaultdateFormat),
|
||||
DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat),
|
||||
Data = dok.DataPom,
|
||||
DataWplywu = dok.Data,
|
||||
Nr = dok.NrDok,
|
||||
Opis = $"KAUCJA ZA OPAKOWANIA {dok.DokKasa?.Kasa.Nazwa ?? string.Empty}",
|
||||
StronaKonta = d.AccountSide,
|
||||
KontoFk = d.Account,
|
||||
Kwota = dok.Kwota1
|
||||
Kwota = dok.Kwota1.AsString()
|
||||
};
|
||||
|
||||
result.Add(item);
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class KpKaucjaZaOpakowania : IDocumentDefinition
|
||||
public class KpKaucjaZaOpakowania : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 51;
|
||||
public string Type => nameof(KpKaucjaZaOpakowania);
|
||||
@@ -22,14 +22,14 @@ public class KpKaucjaZaOpakowania : IDocumentDefinition
|
||||
{
|
||||
Definitions.ForEach(d =>
|
||||
{
|
||||
var item = dok.FillKontr();
|
||||
item.Data = dok.DataPom.ToString(Constants.DefaultdateFormat);
|
||||
item.DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat);
|
||||
var item = dok.DecretKontr();
|
||||
item.Data = dok.DataPom;
|
||||
item.DataWplywu = dok.Data;
|
||||
item.Nr = dok.NrDok;
|
||||
item.Opis = dok.TekstZaCo();
|
||||
item.StronaKonta = d.AccountSide;
|
||||
item.KontoFk = d.Account;
|
||||
item.Kwota = Math.Abs(dok.Zaplacono);
|
||||
item.Kwota = Math.Abs(dok.Zaplacono).AsString();
|
||||
|
||||
result.Add(item);
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class KpLotto : IDocumentDefinition
|
||||
public class KpLotto : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 51;
|
||||
public string Type => nameof(KpLotto);
|
||||
@@ -25,13 +25,13 @@ public class KpLotto : IDocumentDefinition
|
||||
{
|
||||
var item = new DecretsResult
|
||||
{
|
||||
Data = dok.DataPom.ToString(Constants.DefaultdateFormat),
|
||||
DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat),
|
||||
Data = dok.DataPom,
|
||||
DataWplywu = dok.Data,
|
||||
Nr = dok.NrDok,
|
||||
Opis = dok.TekstZaCo(),
|
||||
StronaKonta = d.AccountSide,
|
||||
KontoFk = d.Account,
|
||||
Kwota = Math.Abs(dok.Zaplacono)
|
||||
Kwota = Math.Abs(dok.Zaplacono).AsString()
|
||||
};
|
||||
|
||||
result.Add(item);
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class KpPaysafe : IDocumentDefinition
|
||||
public class KpPaysafe : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 51;
|
||||
public string Type => nameof(KpPaysafe);
|
||||
@@ -25,13 +25,13 @@ public class KpPaysafe : IDocumentDefinition
|
||||
{
|
||||
var item = new DecretsResult
|
||||
{
|
||||
Data = dok.DataPom.ToString(Constants.DefaultdateFormat),
|
||||
DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat),
|
||||
Data = dok.DataPom,
|
||||
DataWplywu = dok.Data,
|
||||
Nr = dok.NrDok,
|
||||
Opis = dok.TekstZaCo(),
|
||||
StronaKonta = d.AccountSide,
|
||||
KontoFk = d.Account,
|
||||
Kwota = Math.Abs(dok.Zaplacono)
|
||||
Kwota = Math.Abs(dok.Zaplacono).AsString()
|
||||
};
|
||||
|
||||
result.Add(item);
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class KpRachunki : IDocumentDefinition
|
||||
public class KpRachunki : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 51;
|
||||
public string Type => nameof(KpRachunki);
|
||||
@@ -25,13 +25,13 @@ public class KpRachunki : IDocumentDefinition
|
||||
{
|
||||
var item = new DecretsResult
|
||||
{
|
||||
Data = dok.DataPom.ToString(Constants.DefaultdateFormat),
|
||||
DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat),
|
||||
Data = dok.DataPom,
|
||||
DataWplywu = dok.Data,
|
||||
Nr = dok.NrDok,
|
||||
Opis = dok.TekstZaCo(),
|
||||
StronaKonta = d.AccountSide,
|
||||
KontoFk = d.Account,
|
||||
Kwota = Math.Abs(dok.Zaplacono)
|
||||
Kwota = Math.Abs(dok.Zaplacono).AsString()
|
||||
};
|
||||
|
||||
result.Add(item);
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class KwBony : IDocumentDefinition
|
||||
public class KwBony : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 51;
|
||||
public string Type => nameof(KwBony);
|
||||
@@ -22,14 +22,14 @@ public class KwBony : IDocumentDefinition
|
||||
{
|
||||
Definitions.ForEach(d =>
|
||||
{
|
||||
var item = dok.FillKontr();
|
||||
item.Data = dok.DataPom.ToString(Constants.DefaultdateFormat);
|
||||
item.DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat);
|
||||
var item = dok.DecretKontr();
|
||||
item.Data = dok.DataPom;
|
||||
item.DataWplywu = dok.Data;
|
||||
item.Nr = dok.NrDok;
|
||||
item.Opis = dok.TekstZaCo();
|
||||
item.StronaKonta = d.AccountSide;
|
||||
item.KontoFk = d.Account;
|
||||
item.Kwota = Math.Abs(dok.Zaplacono);
|
||||
item.Kwota = Math.Abs(dok.Zaplacono).AsString();
|
||||
|
||||
result.Add(item);
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class KwInne : IDocumentDefinition
|
||||
public class KwInne : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 51;
|
||||
public string Type => nameof(KwInne);
|
||||
@@ -22,14 +22,14 @@ public class KwInne : IDocumentDefinition
|
||||
{
|
||||
Definitions.ForEach(d =>
|
||||
{
|
||||
var item = dok.FillKontr();
|
||||
item.Data = dok.DataPom.ToString(Constants.DefaultdateFormat);
|
||||
item.DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat);
|
||||
var item = dok.DecretKontr();
|
||||
item.Data = dok.DataPom;
|
||||
item.DataWplywu = dok.Data;
|
||||
item.Nr = dok.NrDok;
|
||||
item.Opis = dok.TekstZaCo();
|
||||
item.StronaKonta = d.AccountSide;
|
||||
item.KontoFk = d.Account;
|
||||
item.Kwota = Math.Abs(dok.Zaplacono);
|
||||
item.Kwota = Math.Abs(dok.Zaplacono).AsString();
|
||||
|
||||
result.Add(item);
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class KwLotto : IDocumentDefinition
|
||||
public class KwLotto : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 51;
|
||||
public string Type => nameof(KwLotto);
|
||||
@@ -22,14 +22,14 @@ public class KwLotto : IDocumentDefinition
|
||||
{
|
||||
Definitions.ForEach(d =>
|
||||
{
|
||||
var item = dok.FillKontr();
|
||||
item.Data = dok.DataPom.ToString(Constants.DefaultdateFormat);
|
||||
item.DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat);
|
||||
var item = dok.DecretKontr();
|
||||
item.Data = dok.DataPom;
|
||||
item.DataWplywu = dok.Data;
|
||||
item.Nr = dok.NrDok;
|
||||
item.Opis = dok.TekstZaCo();
|
||||
item.StronaKonta = d.AccountSide;
|
||||
item.KontoFk = d.Account;
|
||||
item.Kwota = Math.Abs(dok.Zaplacono);
|
||||
item.Kwota = Math.Abs(dok.Zaplacono).AsString();
|
||||
|
||||
result.Add(item);
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class KwOpakowania : IDocumentDefinition
|
||||
public class KwOpakowania : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 51;
|
||||
public string Type => nameof(KwOpakowania);
|
||||
@@ -21,14 +21,14 @@ public class KwOpakowania : IDocumentDefinition
|
||||
{
|
||||
Definitions.ForEach(d =>
|
||||
{
|
||||
var item = dok.FillKontr();
|
||||
item.Data = dok.DataPom.ToString(Constants.DefaultdateFormat);
|
||||
item.DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat);
|
||||
var item = dok.DecretKontr();
|
||||
item.Data = dok.DataPom;
|
||||
item.DataWplywu = dok.Data;
|
||||
item.Nr = dok.NrDok;
|
||||
item.Opis = dok.TekstZaCo();
|
||||
item.StronaKonta = d.AccountSide;
|
||||
item.KontoFk = d.Account;
|
||||
item.Kwota = Math.Abs(dok.Zaplacono);
|
||||
item.Kwota = Math.Abs(dok.Zaplacono).AsString();
|
||||
|
||||
result.Add(item);
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class KwPolcard : IDocumentDefinition
|
||||
public class KwPolcard : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 51;
|
||||
public string Type => nameof(KwPolcard);
|
||||
@@ -22,14 +22,14 @@ public class KwPolcard : IDocumentDefinition
|
||||
{
|
||||
Definitions.ForEach(d =>
|
||||
{
|
||||
var item = dok.FillKontr();
|
||||
item.Data = dok.DataPom.ToString(Constants.DefaultdateFormat);
|
||||
item.DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat);
|
||||
var item = dok.DecretKontr();
|
||||
item.Data = dok.DataPom;
|
||||
item.DataWplywu = dok.Data;
|
||||
item.Nr = dok.NrDok;
|
||||
item.Opis = dok.TekstZaCo();
|
||||
item.StronaKonta = d.AccountSide;
|
||||
item.KontoFk = d.Account;
|
||||
item.Kwota = Math.Abs(dok.Zaplacono);
|
||||
item.Kwota = Math.Abs(dok.Zaplacono).AsString();
|
||||
|
||||
result.Add(item);
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class KwPomylkaKasjera : IDocumentDefinition
|
||||
public class KwPomylkaKasjera : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 51;
|
||||
public string Type => nameof(KwPomylkaKasjera);
|
||||
@@ -22,14 +22,14 @@ public class KwPomylkaKasjera : IDocumentDefinition
|
||||
{
|
||||
Definitions.ForEach(d =>
|
||||
{
|
||||
var item = dok.FillKontr();
|
||||
item.Data = dok.DataPom.ToString(Constants.DefaultdateFormat);
|
||||
item.DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat);
|
||||
var item = dok.DecretKontr();
|
||||
item.Data = dok.DataPom;
|
||||
item.DataWplywu = dok.Data;
|
||||
item.Nr = dok.NrDok;
|
||||
item.Opis = dok.TekstZaCo();
|
||||
item.StronaKonta = d.AccountSide;
|
||||
item.KontoFk = d.Account;
|
||||
item.Kwota = Math.Abs(dok.Zaplacono);
|
||||
item.Kwota = Math.Abs(dok.Zaplacono).AsString();
|
||||
|
||||
result.Add(item);
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class KwUtarg : IDocumentDefinition
|
||||
public class KwUtarg : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 51;
|
||||
public string Type => nameof(KwUtarg);
|
||||
@@ -22,14 +22,14 @@ public class KwUtarg : IDocumentDefinition
|
||||
{
|
||||
Definitions.ForEach(d =>
|
||||
{
|
||||
var item = dok.FillKontr();
|
||||
item.Data = dok.DataPom.ToString(Constants.DefaultdateFormat);
|
||||
item.DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat);
|
||||
var item = dok.DecretKontr();
|
||||
item.Data = dok.DataPom;
|
||||
item.DataWplywu = dok.Data;
|
||||
item.Nr = dok.NrDok;
|
||||
item.Opis = dok.TekstZaCo();
|
||||
item.StronaKonta = d.AccountSide;
|
||||
item.KontoFk = d.Account;
|
||||
item.Kwota = Math.Abs(dok.Zaplacono);
|
||||
item.Kwota = Math.Abs(dok.Zaplacono).AsString();
|
||||
|
||||
result.Add(item);
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class MmMinus : IDocumentDefinition
|
||||
public class MmMinus : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 6;
|
||||
public string Type => "Mm-";
|
||||
@@ -22,14 +22,14 @@ public class MmMinus : IDocumentDefinition
|
||||
{
|
||||
Definitions.ForEach(d =>
|
||||
{
|
||||
var item = dok.FillKontr();
|
||||
item.Data = dok.DataPom.ToString(Constants.DefaultdateFormat);
|
||||
item.DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat);
|
||||
var item = dok.DecretKontr();
|
||||
item.Data = dok.DataPom;
|
||||
item.DataWplywu = dok.Data;
|
||||
item.Nr = dok.NrDok;
|
||||
item.Opis = dok.TekstZaCo();
|
||||
item.StronaKonta = d.AccountSide;
|
||||
item.KontoFk = d.Account;
|
||||
item.Kwota = ProcessValue(dok, d.Expression);
|
||||
item.Kwota = ProcessValue(dok, d.Expression).AsString();
|
||||
|
||||
result.Add(item);
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class MmPlus : IDocumentDefinition
|
||||
public class MmPlus : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 3;
|
||||
public string Type => "Mm+";
|
||||
@@ -22,14 +22,14 @@ public class MmPlus : IDocumentDefinition
|
||||
{
|
||||
Definitions.ForEach(d =>
|
||||
{
|
||||
var item = dok.FillKontr();
|
||||
item.Data = dok.DataPom.ToString(Constants.DefaultdateFormat);
|
||||
item.DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat);
|
||||
var item = dok.DecretKontr();
|
||||
item.Data = dok.DataPom;
|
||||
item.DataWplywu = dok.Data;
|
||||
item.Nr = dok.NrDok;
|
||||
item.Opis = dok.TekstZaCo();
|
||||
item.StronaKonta = d.AccountSide;
|
||||
item.KontoFk = d.Account;
|
||||
item.Kwota = ProcessValue(dok, d.Expression);
|
||||
item.Kwota = ProcessValue(dok, d.Expression).AsString();
|
||||
|
||||
result.Add(item);
|
||||
});
|
||||
@@ -1,12 +1,11 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class Przecena : IDocumentDefinition
|
||||
public class Przecena : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 18;
|
||||
public string Type => "Pc";
|
||||
public List<Definition> Definitions { get; } =
|
||||
[
|
||||
new Definition("342-0-24", "MA", "[znr]"),
|
||||
[
|
||||
new Definition("342-0-24", "MA", "[snr]-[znr]"),
|
||||
new Definition("343-0-24", "MA", "[sbr]-[snr]"),
|
||||
new Definition("332-0-24", "WN", "[sbr]")
|
||||
@@ -23,14 +22,14 @@ public class Przecena : IDocumentDefinition
|
||||
{
|
||||
Definitions.ForEach(d =>
|
||||
{
|
||||
var item = dok.FillKontr();
|
||||
item.Data = dok.DataPom.ToString(Constants.DefaultdateFormat);
|
||||
item.DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat);
|
||||
var item = dok.DecretKontr();
|
||||
item.Data = dok.DataPom;
|
||||
item.DataWplywu = dok.Data;
|
||||
item.Nr = dok.NrDok;
|
||||
item.Opis = dok.TekstZaCo();
|
||||
item.StronaKonta = d.AccountSide;
|
||||
item.KontoFk = d.Account;
|
||||
item.Kwota = Processvalue(dok, d.Expression);
|
||||
item.Kwota = Processvalue(dok, d.Expression).AsString();
|
||||
|
||||
result.Add(item);
|
||||
});
|
||||
@@ -43,8 +42,12 @@ public class Przecena : IDocumentDefinition
|
||||
{
|
||||
switch(expression)
|
||||
{
|
||||
case "[znr]":
|
||||
return doc.PozDok.Sum(x => x.CenaMag);
|
||||
case "[snr]-[znr]":
|
||||
return doc.Netto - doc.NettoDet;
|
||||
case "[sbr]-[snr]":
|
||||
return doc.Podatek - doc.PodatekDet;
|
||||
case "[sbr]":
|
||||
return doc.Razem;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class Pz : IDocumentDefinition
|
||||
public class Pz : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 2;
|
||||
public string Type => "Pz";
|
||||
@@ -23,14 +23,14 @@ public class Pz : IDocumentDefinition
|
||||
{
|
||||
Definitions.ForEach(d =>
|
||||
{
|
||||
var item = dok.FillKontr();
|
||||
item.Data = dok.DataPom.ToString(Constants.DefaultdateFormat);
|
||||
item.DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat);
|
||||
var item = dok.DecretKontr();
|
||||
item.Data = dok.DataPom;
|
||||
item.DataWplywu = dok.Data;
|
||||
item.Nr = dok.NrDok;
|
||||
item.Opis = d.Account == "305-60-24" ? item.k_NIP : dok.NrDok;
|
||||
item.StronaKonta = d.AccountSide;
|
||||
item.KontoFk = d.Account;
|
||||
item.Kwota = ProcessValue(dok, d.Expression);
|
||||
item.Kwota = ProcessValue(dok, d.Expression).AsString();
|
||||
|
||||
result.Add(item);
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class PzFaktura : IDocumentDefinition
|
||||
public class PzFaktura : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 2;
|
||||
public string Type => "PzFaktura";
|
||||
@@ -26,15 +26,15 @@ public class PzFaktura : IDocumentDefinition
|
||||
{
|
||||
Definitions.ForEach(d =>
|
||||
{
|
||||
var item = dok.FillKontr();
|
||||
item.Data = dok.Data.ToString(Constants.DefaultdateFormat);
|
||||
var item = dok.DecretKontr();
|
||||
item.Data = dok.Data;
|
||||
item.DataWplywu = dok.RozliczaRozliczanyDok.FirstOrDefault()
|
||||
?.Dok.Data.ToString(Constants.DefaultdateFormat) ?? string.Empty;
|
||||
?.Dok.Data ?? null;
|
||||
item.Nr = dok.NrDok;
|
||||
item.Opis = dok.RozliczaRozliczanyDok.FirstOrDefault()?.Dok.NrDok ?? string.Empty;
|
||||
item.StronaKonta = d.AccountSide;
|
||||
item.KontoFk = d.Account;
|
||||
item.Kwota = ProcessValue(dok, d.Expression);
|
||||
item.Kwota = ProcessValue(dok, d.Expression).AsString();
|
||||
|
||||
result.Add(item);
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class RapFisk : IDocumentDefinition
|
||||
public class RapFisk : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 53;
|
||||
public string Type => "Rapfisk";
|
||||
@@ -31,13 +31,13 @@ public class RapFisk : IDocumentDefinition
|
||||
{
|
||||
k_Skrot = "Detal",
|
||||
k_Nazwa = "Odbiorca detaliczny",
|
||||
Data = dok.DataPom.ToString(Constants.DefaultdateFormat),
|
||||
DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat),
|
||||
Data = dok.DataPom,
|
||||
DataWplywu = dok.Data,
|
||||
Nr = dok.NrDok,
|
||||
Opis = dok.NrDok,
|
||||
StronaKonta = d.AccountSide,
|
||||
KontoFk = d.Account,
|
||||
Kwota = ProcessValue(dok, d.Expression)
|
||||
Kwota = ProcessValue(dok, d.Expression).AsString()
|
||||
};
|
||||
|
||||
result.Add(item);
|
||||
@@ -51,8 +51,8 @@ public class RapFisk : IDocumentDefinition
|
||||
{
|
||||
return expression switch
|
||||
{
|
||||
"[sbr]" => doc.NettoDet + doc.PodatekDet,
|
||||
"[svr]" => doc.Podatek,
|
||||
"[sbr]" => doc.Netto+ doc.Podatek + doc.NettoUslugi + doc.PodatekUslugi,
|
||||
"[svr]" => doc.Podatek + doc.PodatekUslugi,
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.DocsDefinitions;
|
||||
namespace FKGees.DocsDefinitions.Decrets;
|
||||
|
||||
public class Wz : IDocumentDefinition
|
||||
public class Wz : IDecretsDefinition
|
||||
{
|
||||
public int DocType => 2;
|
||||
public string Type => "Wz";
|
||||
@@ -23,14 +23,14 @@ public class Wz : IDocumentDefinition
|
||||
{
|
||||
Definitions.ForEach(d =>
|
||||
{
|
||||
var item = dok.FillKontr();
|
||||
item.Data = dok.DataPom.ToString(Constants.DefaultdateFormat);
|
||||
item.DataWplywu = dok.Data.ToString(Constants.DefaultdateFormat);
|
||||
var item = dok.DecretKontr();
|
||||
item.Data = dok.DataPom;
|
||||
item.DataWplywu = dok.Data;
|
||||
item.Nr = dok.NrDok;
|
||||
item.Opis = dok.NrDok;
|
||||
item.StronaKonta = d.AccountSide;
|
||||
item.KontoFk = d.Account;
|
||||
item.Kwota = ProcessValue(dok, d.Expression);
|
||||
item.Kwota = ProcessValue(dok, d.Expression).AsString();
|
||||
|
||||
result.Add(item);
|
||||
});
|
||||
92
FKGees/DocsDefinitions/Registers/Fa.cs
Normal file
92
FKGees/DocsDefinitions/Registers/Fa.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
namespace FKGees.DocsDefinitions.Registers;
|
||||
|
||||
public class Fa : IRegistersDefinition
|
||||
{
|
||||
public string Type => nameof(Fa).ToUpper();
|
||||
public int[] DocTypes => [33];
|
||||
|
||||
private readonly Context _context;
|
||||
|
||||
public Fa(Context context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public Task<List<RegistersResult>> Process(IReadOnlyList<Dok> documents)
|
||||
{
|
||||
var result = new List<RegistersResult>();
|
||||
|
||||
var docs = documents.Where(x => DocTypes.Contains(x.TypDok));
|
||||
|
||||
foreach (var dok in docs)
|
||||
{
|
||||
var item = dok.RegisterKontr();
|
||||
item.symbolmag = _context.SymbolMag;
|
||||
item.rodzaj = Type;
|
||||
item.nr = dok.NrDok;
|
||||
item.dwystawienia = dok.DataDod;
|
||||
item.dsprzedazy = dok.DataPom;
|
||||
item.dwplywu = dok.Data;
|
||||
item.OpisDok = dok.NrDok;
|
||||
item.platnosc = _context.PaymentForms.FirstOrDefault(x => x.FormaPlat == dok.FormaPlat)?.Tekst ?? string.Empty;
|
||||
item.kredyt = (-(dok.DoZaplaty - dok.Zaplacono)).AsString();
|
||||
item.termin = dok.DataDod.AddDays(dok.TerminPlat);
|
||||
|
||||
item.sn23 = (dok.Rozbicie(2300)?.Netto ?? 0).AsString();
|
||||
item.sn22 = (dok.Rozbicie(2200)?.Netto ?? 0).AsString();
|
||||
item.sn8 = (dok.Rozbicie(800)?.Netto ?? 0).AsString();
|
||||
item.sn7 = (dok.Rozbicie(700)?.Netto ?? 0).AsString();
|
||||
item.sn5 = (dok.Rozbicie(500)?.Netto ?? 0).AsString();
|
||||
item.sn3 = (dok.Rozbicie(300)?.Netto ?? 0).AsString();
|
||||
item.sn0 = (dok.Rozbicie(0)?.Netto ?? 0).AsString();
|
||||
item.snzw = (dok.Rozbicie(-1)?.Netto ?? 0).AsString();
|
||||
item.snr = dok.RozbicieDok.Sum(x => x.Netto).AsString();
|
||||
|
||||
item.sv23 = (dok.Rozbicie(2300)?.Podatek ?? 0).AsString();
|
||||
item.sv22 = (dok.Rozbicie(2200)?.Podatek ?? 0).AsString();
|
||||
item.sv8 = (dok.Rozbicie(800)?.Podatek ?? 0).AsString();
|
||||
item.sv7 = (dok.Rozbicie(700)?.Podatek ?? 0).AsString();
|
||||
item.sv5 = (dok.Rozbicie(500)?.Podatek ?? 0).AsString();
|
||||
item.sv3 = (dok.Rozbicie(300)?.Podatek ?? 0).AsString();
|
||||
item.svr = dok.RozbicieDok.Sum(x => x.Podatek).AsString();
|
||||
|
||||
item.sb23 = ((dok.Rozbicie(2300)?.Netto ?? 0) + (dok.Rozbicie(2300)?.Podatek ?? 0)).AsString();
|
||||
item.sb22 = ((dok.Rozbicie(2200)?.Netto ?? 0) + (dok.Rozbicie(2200)?.Podatek ?? 0)).AsString();
|
||||
item.sb8 = ((dok.Rozbicie(800)?.Netto ?? 0) + (dok.Rozbicie(800)?.Podatek ?? 0)).AsString();
|
||||
item.sb7 = ((dok.Rozbicie(700)?.Netto ?? 0) + (dok.Rozbicie(700)?.Podatek ?? 0)).AsString();
|
||||
item.sb5 = ((dok.Rozbicie(500)?.Netto ?? 0) + (dok.Rozbicie(500)?.Podatek ?? 0)).AsString();
|
||||
item.sb3 = ((dok.Rozbicie(300)?.Netto ?? 0) + (dok.Rozbicie(300)?.Podatek ?? 0)).AsString();
|
||||
item.sbr = dok.RozbicieDok.Sum(x => x.Podatek + x.Netto).AsString();
|
||||
|
||||
item.zn23 = (dok.Rozbicie(2300)?.NettoMag ?? 0).AsString();
|
||||
item.zn22 = (dok.Rozbicie(2200)?.NettoMag ?? 0).AsString();
|
||||
item.zn8 = (dok.Rozbicie(800)?.NettoMag ?? 0).AsString();
|
||||
item.zn7 = (dok.Rozbicie(700)?.NettoMag ?? 0).AsString();
|
||||
item.zn5 = (dok.Rozbicie(500)?.NettoMag ?? 0).AsString();
|
||||
item.zn3 = (dok.Rozbicie(300)?.NettoMag ?? 0).AsString();
|
||||
item.zn0 = (dok.Rozbicie(0)?.NettoMag ?? 0).AsString();
|
||||
item.znzw = (dok.Rozbicie(-1)?.NettoMag ?? 0).AsString();
|
||||
item.znr = dok.RozbicieDok.Sum(x => x.NettoMag ?? 0).AsString();
|
||||
|
||||
item.zv23 = (dok.Rozbicie(2300)?.PodatekMag ?? 0).AsString();
|
||||
item.zv22 = (dok.Rozbicie(2200)?.PodatekMag ?? 0).AsString();
|
||||
item.zv8 = (dok.Rozbicie(800)?.PodatekMag ?? 0).AsString();
|
||||
item.zv7 = (dok.Rozbicie(700)?.PodatekMag ?? 0).AsString();
|
||||
item.zv5 = (dok.Rozbicie(500)?.PodatekMag ?? 0).AsString();
|
||||
item.zv3 = (dok.Rozbicie(300)?.PodatekMag ?? 0).AsString();
|
||||
item.znr = dok.RozbicieDok.Sum(x => x.PodatekMag ?? 0).AsString();
|
||||
|
||||
item.zb23 = ((dok.Rozbicie(2300)?.NettoMag ?? 0) + (dok.Rozbicie(2300)?.PodatekMag ?? 0)).AsString();
|
||||
item.zb22 = ((dok.Rozbicie(2200)?.NettoMag ?? 0) + (dok.Rozbicie(2200)?.PodatekMag ?? 0)).AsString();
|
||||
item.zb8 = ((dok.Rozbicie(800)?.NettoMag ?? 0) + (dok.Rozbicie(800)?.PodatekMag ?? 0)).AsString();
|
||||
item.zb7 = ((dok.Rozbicie(700)?.NettoMag ?? 0) + (dok.Rozbicie(700)?.PodatekMag ?? 0)).AsString();
|
||||
item.zb5 = ((dok.Rozbicie(500)?.NettoMag ?? 0) + (dok.Rozbicie(500)?.PodatekMag ?? 0)).AsString();
|
||||
item.zb3 = ((dok.Rozbicie(300)?.NettoMag ?? 0) + (dok.Rozbicie(300)?.PodatekMag ?? 0)).AsString();
|
||||
item.zbr = dok.RozbicieDok.Sum(x => x.PodatekMag ?? 0 + x.NettoMag ?? 0).AsString();
|
||||
|
||||
result.Add(item);
|
||||
}
|
||||
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
}
|
||||
90
FKGees/DocsDefinitions/Registers/Fz.cs
Normal file
90
FKGees/DocsDefinitions/Registers/Fz.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
namespace FKGees.DocsDefinitions.Registers;
|
||||
|
||||
public class Fz : IRegistersDefinition
|
||||
{
|
||||
private readonly Context _context;
|
||||
public string Type => nameof(Fz).ToUpper();
|
||||
public int[] DocTypes => [31, 32];
|
||||
|
||||
public Fz(Context context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public Task<List<RegistersResult>> Process(IReadOnlyList<Dok> documents)
|
||||
{
|
||||
var result = new List<RegistersResult>();
|
||||
|
||||
var docs = documents.Where(x => DocTypes.Contains(x.TypDok));
|
||||
|
||||
foreach (var dok in docs)
|
||||
{
|
||||
var item = dok.RegisterKontr();
|
||||
item.symbolmag = _context.SymbolMag;
|
||||
item.rodzaj = Type;
|
||||
item.nr = dok.NrDok;
|
||||
item.dwystawienia = dok.DataDod;
|
||||
item.dsprzedazy = dok.DataPom;
|
||||
item.dwplywu = dok.Data;
|
||||
item.OpisDok = dok.NrDok;
|
||||
item.platnosc = _context.PaymentForms.FirstOrDefault(x => x.FormaPlat == dok.FormaPlat)?.Tekst ?? string.Empty;
|
||||
item.kredyt = (-(dok.DoZaplaty - dok.Zaplacono)).AsString();
|
||||
item.termin = dok.DataDod.AddDays(dok.TerminPlat);
|
||||
item.sn23 = (dok.Rozbicie(2300)?.NettoDet ?? 0).AsString();
|
||||
item.sn22 = (dok.Rozbicie(2200)?.NettoDet ?? 0).AsString();
|
||||
item.sn8 = (dok.Rozbicie(800)?.NettoDet ?? 0).AsString();
|
||||
item.sn7 = (dok.Rozbicie(700)?.NettoDet ?? 0).AsString();
|
||||
item.sn5 = (dok.Rozbicie(500)?.NettoDet ?? 0).AsString();
|
||||
item.sn3 = (dok.Rozbicie(300)?.NettoDet ?? 0).AsString();
|
||||
item.sn0 = (dok.Rozbicie(0)?.NettoDet ?? 0).AsString();
|
||||
item.snzw = (dok.Rozbicie(-1)?.NettoDet ?? 0).AsString();
|
||||
item.snr = dok.RozbicieDok.Sum(x => x.NettoDet).AsString();
|
||||
|
||||
item.sv23 = (dok.Rozbicie(2300)?.PodatekDet ?? 0).AsString();
|
||||
item.sv22 = (dok.Rozbicie(2200)?.PodatekDet ?? 0).AsString();
|
||||
item.sv8 = (dok.Rozbicie(800)?.PodatekDet ?? 0).AsString();
|
||||
item.sv7 = (dok.Rozbicie(700)?.PodatekDet ?? 0).AsString();
|
||||
item.sv5 = (dok.Rozbicie(500)?.PodatekDet ?? 0).AsString();
|
||||
item.sv3 = (dok.Rozbicie(300)?.PodatekDet ?? 0).AsString();
|
||||
item.svr = dok.RozbicieDok.Sum(x => x.PodatekDet).AsString();
|
||||
|
||||
item.sb23 = ((dok.Rozbicie(2300)?.NettoDet ?? 0) + (dok.Rozbicie(2300)?.PodatekDet ?? 0)).AsString();
|
||||
item.sb22 = ((dok.Rozbicie(2200)?.NettoDet ?? 0) + (dok.Rozbicie(2200)?.PodatekDet ?? 0)).AsString();
|
||||
item.sb8 = ((dok.Rozbicie(800)?.NettoDet ?? 0) + (dok.Rozbicie(800)?.PodatekDet ?? 0)).AsString();
|
||||
item.sb7 = ((dok.Rozbicie(700)?.NettoDet ?? 0) + (dok.Rozbicie(700)?.PodatekDet ?? 0)).AsString();
|
||||
item.sb5 = ((dok.Rozbicie(500)?.NettoDet ?? 0) + (dok.Rozbicie(500)?.PodatekDet ?? 0)).AsString();
|
||||
item.sb3 = ((dok.Rozbicie(300)?.NettoDet ?? 0) + (dok.Rozbicie(300)?.PodatekDet ?? 0)).AsString();
|
||||
item.sbr = dok.RozbicieDok.Sum(x => x.PodatekDet + x.NettoDet).AsString();
|
||||
|
||||
item.zn23 = (dok.Rozbicie(2300)?.Netto ?? 0).AsString();
|
||||
item.zn22 = (dok.Rozbicie(2200)?.Netto ?? 0).AsString();
|
||||
item.zn8 = (dok.Rozbicie(800)?.Netto ?? 0).AsString();
|
||||
item.zn7 = (dok.Rozbicie(700)?.Netto ?? 0).AsString();
|
||||
item.zn5 = (dok.Rozbicie(500)?.Netto ?? 0).AsString();
|
||||
item.zn3 = (dok.Rozbicie(300)?.Netto ?? 0).AsString();
|
||||
item.zn0 = (dok.Rozbicie(0)?.Netto ?? 0).AsString();
|
||||
item.znzw = (dok.Rozbicie(-1)?.Netto ?? 0).AsString();
|
||||
item.znr = dok.RozbicieDok.Sum(x => x.Netto).AsString();
|
||||
|
||||
item.zv23 = (dok.Rozbicie(2300)?.Podatek ?? 0).AsString();
|
||||
item.zv22 = (dok.Rozbicie(2200)?.Podatek ?? 0).AsString();
|
||||
item.zv8 = (dok.Rozbicie(800)?.Podatek ?? 0).AsString();
|
||||
item.zv7 = (dok.Rozbicie(700)?.Podatek ?? 0).AsString();
|
||||
item.zv5 = (dok.Rozbicie(500)?.Podatek ?? 0).AsString();
|
||||
item.zv3 = (dok.Rozbicie(300)?.Podatek ?? 0).AsString();
|
||||
item.znr = dok.RozbicieDok.Sum(x => x.Podatek).AsString();
|
||||
|
||||
item.zb23 = ((dok.Rozbicie(2300)?.Netto ?? 0) + (dok.Rozbicie(2300)?.Podatek ?? 0)).AsString();
|
||||
item.zb22 = ((dok.Rozbicie(2200)?.Netto ?? 0) + (dok.Rozbicie(2200)?.Podatek ?? 0)).AsString();
|
||||
item.zb8 = ((dok.Rozbicie(800)?.Netto ?? 0) + (dok.Rozbicie(800)?.Podatek ?? 0)).AsString();
|
||||
item.zb7 = ((dok.Rozbicie(700)?.Netto ?? 0) + (dok.Rozbicie(700)?.Podatek ?? 0)).AsString();
|
||||
item.zb5 = ((dok.Rozbicie(500)?.Netto ?? 0) + (dok.Rozbicie(500)?.Podatek ?? 0)).AsString();
|
||||
item.zb3 = ((dok.Rozbicie(300)?.Netto ?? 0) + (dok.Rozbicie(300)?.Podatek ?? 0)).AsString();
|
||||
item.zbr = dok.RozbicieDok.Sum(x => x.Podatek + x.Netto).AsString();
|
||||
|
||||
result.Add(item);
|
||||
}
|
||||
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FKGees;
|
||||
|
||||
public class DocumentsService
|
||||
{
|
||||
private readonly IDbContextFactory<PcmDbContext> _dbContextFactory;
|
||||
|
||||
public DocumentsService(IDbContextFactory<PcmDbContext> dbContextFactory)
|
||||
{
|
||||
_dbContextFactory = dbContextFactory;
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<Dok>> Fetch(int[] typdok, DateTime dataOd, DateTime dataDo)
|
||||
{
|
||||
await using var context = await _dbContextFactory.CreateDbContextAsync();
|
||||
context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||
|
||||
var documents = await context.Dok
|
||||
.Include(x => x.DokKontr).ThenInclude(x => x.Kontr)
|
||||
.Include(x => x.DokKasa)
|
||||
.Include(x => x.TekstDok)
|
||||
.Include(x => x.PozDok)
|
||||
.Include(x => x.RozliczaRozliczanyDok).ThenInclude(x => x.Dok)
|
||||
.Include(x => x.DokKasa).ThenInclude(x => x.Kasa)
|
||||
.Where(x => typdok.Contains(x.TypDok) && x.Data >= dataOd && x.Data <= dataDo)
|
||||
.ToListAsync();
|
||||
return documents;
|
||||
|
||||
}
|
||||
|
||||
public string WzNrFaktury(decimal dokId)
|
||||
{
|
||||
using var context = _dbContextFactory.CreateDbContext();
|
||||
context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||
|
||||
var dok = context.Rozlicza
|
||||
.Include(x => x.RozliczanyDok)
|
||||
.FirstOrDefault(x => x.DokId == dokId);
|
||||
|
||||
|
||||
return dok?.RozliczanyDok.NrDok ?? string.Empty;
|
||||
}
|
||||
}
|
||||
9
FKGees/Extensions/DecimalExtension.cs
Normal file
9
FKGees/Extensions/DecimalExtension.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace FKGees.Extensions;
|
||||
|
||||
internal static class DecimalExtension
|
||||
{
|
||||
internal static string AsString(this decimal value)
|
||||
{
|
||||
return value.ToString("0.00");
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
internal static class DokExtensions
|
||||
{
|
||||
internal static DecretsResult FillKontr(this Dok doc)
|
||||
internal static DecretsResult DecretKontr(this Dok doc)
|
||||
{
|
||||
var result = new DecretsResult
|
||||
{
|
||||
@@ -16,6 +16,27 @@ internal static class DokExtensions
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static RegistersResult RegisterKontr(this Dok doc)
|
||||
{
|
||||
var result = new RegistersResult
|
||||
{
|
||||
k_Nazwa = doc.TekstDok.FirstOrDefault(x => x.Znaczenie == 88)?.Tekst ?? string.Empty,
|
||||
k_Skrot = doc.TekstDok.FirstOrDefault(x => x.Znaczenie == 94)?.Tekst ?? string.Empty,
|
||||
k_Miejscowosc = doc.TekstDok.FirstOrDefault(x => x.Znaczenie == 91)?.Tekst ?? string.Empty,
|
||||
k_Ulica = doc.TekstDok.FirstOrDefault(x => x.Znaczenie == 89)?.Tekst ?? string.Empty,
|
||||
k_KodPocztowy = doc.TekstDok.FirstOrDefault(x => x.Znaczenie == 90)?.Tekst ?? string.Empty,
|
||||
k_Numer = doc.DokKontr?.Kontr.NrDomu ?? string.Empty,
|
||||
k_NIP = doc.TekstDok.FirstOrDefault(x => x.Znaczenie == 93)?.Tekst ?? string.Empty
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static RozbicieDok? Rozbicie(this Dok dok, short stawka)
|
||||
{
|
||||
var roz = dok.RozbicieDok.FirstOrDefault(x => x.Stawka == stawka);
|
||||
return roz;
|
||||
}
|
||||
|
||||
internal static string TekstZaCo(this Dok dok)
|
||||
{
|
||||
@@ -26,14 +47,5 @@ internal static class DokExtensions
|
||||
{
|
||||
return dok.TekstDok.FirstOrDefault(x => x.Znaczenie == 71)?.Tekst ?? string.Empty;
|
||||
}
|
||||
|
||||
internal static decimal NettoToBrutto(this decimal netto, int stawka)
|
||||
{
|
||||
if (stawka is -1 or 0)
|
||||
return netto;
|
||||
|
||||
var rate = (decimal) stawka / 10000;
|
||||
return netto + netto * rate;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +1,42 @@
|
||||
using FKGees.DocsDefinitions;
|
||||
using FKGees.DocsDefinitions.Decrets;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace FKGees.Extensions;
|
||||
|
||||
internal static class ServiceCollectionExtensions
|
||||
{
|
||||
internal static IServiceCollection AddDocumentsDefinitions(this IServiceCollection services)
|
||||
internal static IServiceCollection AddDecretsDefinitions(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<IDocumentDefinition, Przecena>();
|
||||
services.AddSingleton<IDocumentDefinition, MmPlus>();
|
||||
services.AddSingleton<IDocumentDefinition, MmMinus>();
|
||||
services.AddSingleton<IDocumentDefinition, Pz>();
|
||||
services.AddSingleton<IDocumentDefinition, Wz>();
|
||||
services.AddSingleton<IDocumentDefinition, PzFaktura>();
|
||||
services.AddSingleton<IDocumentDefinition, RapFisk>();
|
||||
services.AddSingleton<IDocumentDefinition, KorDetal>();
|
||||
services.AddSingleton<IDocumentDefinition, FaktSprz>();
|
||||
services.AddSingleton<IDocumentDefinition, KwBony>();
|
||||
services.AddSingleton<IDocumentDefinition, KwInne>();
|
||||
services.AddSingleton<IDocumentDefinition, KwLotto>();
|
||||
services.AddSingleton<IDocumentDefinition, KwOpakowania>();
|
||||
services.AddSingleton<IDocumentDefinition, KwPolcard>();
|
||||
services.AddSingleton<IDocumentDefinition, KwPomylkaKasjera>();
|
||||
services.AddSingleton<IDocumentDefinition, KwUtarg>();
|
||||
services.AddSingleton<IDocumentDefinition, KpInne>();
|
||||
services.AddSingleton<IDocumentDefinition, KpKasy>();
|
||||
services.AddSingleton<IDocumentDefinition, KpKaucjaZaOpakowania>();
|
||||
services.AddSingleton<IDocumentDefinition, KpKaucjaZDokUtargu>();
|
||||
services.AddSingleton<IDocumentDefinition, KpLotto>();
|
||||
services.AddSingleton<IDocumentDefinition, KpPaysafe>();
|
||||
services.AddSingleton<IDocumentDefinition, KpRachunki>();
|
||||
services.AddSingleton<IDecretsDefinition, Przecena>();
|
||||
services.AddSingleton<IDecretsDefinition, MmPlus>();
|
||||
services.AddSingleton<IDecretsDefinition, MmMinus>();
|
||||
services.AddSingleton<IDecretsDefinition, Pz>();
|
||||
services.AddSingleton<IDecretsDefinition, Wz>();
|
||||
services.AddSingleton<IDecretsDefinition, PzFaktura>();
|
||||
services.AddSingleton<IDecretsDefinition, RapFisk>();
|
||||
services.AddSingleton<IDecretsDefinition, KorDetal>();
|
||||
services.AddSingleton<IDecretsDefinition, FaktSprz>();
|
||||
services.AddSingleton<IDecretsDefinition, KwBony>();
|
||||
services.AddSingleton<IDecretsDefinition, KwInne>();
|
||||
services.AddSingleton<IDecretsDefinition, KwLotto>();
|
||||
services.AddSingleton<IDecretsDefinition, KwOpakowania>();
|
||||
services.AddSingleton<IDecretsDefinition, KwPolcard>();
|
||||
services.AddSingleton<IDecretsDefinition, KwPomylkaKasjera>();
|
||||
services.AddSingleton<IDecretsDefinition, KwUtarg>();
|
||||
services.AddSingleton<IDecretsDefinition, KpInne>();
|
||||
services.AddSingleton<IDecretsDefinition, KpKasy>();
|
||||
services.AddSingleton<IDecretsDefinition, KpKaucjaZaOpakowania>();
|
||||
services.AddSingleton<IDecretsDefinition, KpKaucjaZDokUtargu>();
|
||||
services.AddSingleton<IDecretsDefinition, KpLotto>();
|
||||
services.AddSingleton<IDecretsDefinition, KpPaysafe>();
|
||||
services.AddSingleton<IDecretsDefinition, KpRachunki>();
|
||||
return services;
|
||||
}
|
||||
|
||||
internal static IServiceCollection AddRegistersDefinitions(this IServiceCollection services)
|
||||
{
|
||||
services.AddScoped<IRegistersDefinition, Fz>();
|
||||
services.AddScoped<IRegistersDefinition, Fa>();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
global using Blink.Backoffice.Services.PcmDb;
|
||||
global using Blink.Backoffice.Services.PcmDb.Entities;
|
||||
global using FKGees.DocsDefinitions;
|
||||
global using FKGees.DocsDefinitions.Registers;
|
||||
global using FKGees.Extensions;
|
||||
global using FKGees.Interfaces;
|
||||
global using FKGees.Models;
|
||||
global using FKGees.Models;
|
||||
global using Microsoft.Extensions.Logging;
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FKGees.Interfaces;
|
||||
|
||||
public interface IDocumentDefinition
|
||||
public interface IDecretsDefinition
|
||||
{
|
||||
public int DocType { get; }
|
||||
public string Type { get; }
|
||||
8
FKGees/Interfaces/IRegistersDefinition.cs
Normal file
8
FKGees/Interfaces/IRegistersDefinition.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace FKGees.Interfaces;
|
||||
|
||||
public interface IRegistersDefinition
|
||||
{
|
||||
public string Type { get; }
|
||||
public int[] DocTypes { get; }
|
||||
Task<List<RegistersResult>> Process(IReadOnlyList<Dok> documents);
|
||||
}
|
||||
@@ -4,12 +4,12 @@ namespace FKGees.Models;
|
||||
|
||||
public class DecretsResult
|
||||
{
|
||||
public string Data { get; set; } = string.Empty;
|
||||
public string DataWplywu { get; set; } = string.Empty;
|
||||
public DateTime Data { get; set; }
|
||||
public DateTime? DataWplywu { get; set; }
|
||||
public string Nr { get; set; } = string.Empty;
|
||||
public string KontoFk { get; set; } = string.Empty;
|
||||
public string StronaKonta { get; set; } = string.Empty;
|
||||
public decimal Kwota { get; set; }
|
||||
public string Kwota { get; set; } = string.Empty;
|
||||
public string Opis { get; set; } = string.Empty;
|
||||
public string k_NIP { get; set; } = string.Empty;
|
||||
public string k_Skrot { get; set; } = string.Empty;
|
||||
|
||||
77
FKGees/Models/RegistersResult.cs
Normal file
77
FKGees/Models/RegistersResult.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||
|
||||
namespace FKGees.Models;
|
||||
|
||||
public class RegistersResult
|
||||
{
|
||||
public string symbolmag { get; set; } = string.Empty;
|
||||
public string rodzaj { get; set; } = string.Empty;
|
||||
public string nr { get; set; } = string.Empty;
|
||||
public DateTime dwystawienia { get; set; }
|
||||
public DateTime dsprzedazy { get; set; }
|
||||
public DateTime dwplywu { get; set; }
|
||||
public string teczka { get; set; } = string.Empty;
|
||||
public string OpisDok { get; set; } = string.Empty;
|
||||
public string komentarz { get; set; } = string.Empty;
|
||||
public string platnosc { get; set; } = string.Empty;
|
||||
public string kredyt { get; set; } = string.Empty;
|
||||
public DateTime termin { get; set; }
|
||||
public string k_NIP { get; set; } = string.Empty;
|
||||
public string k_Regon { get; set; } = string.Empty;
|
||||
public string k_Skrot { get; set; } = string.Empty;
|
||||
public string k_Nazwa { get; set; } = string.Empty;
|
||||
public string k_KodPocztowy { get; set; } = string.Empty;
|
||||
public string k_Miejscowosc { get; set; } = string.Empty;
|
||||
public string k_Ulica { get; set; } = string.Empty;
|
||||
public string k_Numer { get; set; } = string.Empty;
|
||||
public string k_Bank { get; set; } = string.Empty;
|
||||
public string k_KontoBankowe { get; set; } = string.Empty;
|
||||
public string sn23 { get; set; } = string.Empty;
|
||||
public string sn22 { get; set; } = string.Empty;
|
||||
public string sn8 { get; set; } = string.Empty;
|
||||
public string sn7 { get; set; } = string.Empty;
|
||||
public string sn5 { get; set; } = string.Empty;
|
||||
public string sn3 { get; set; } = string.Empty;
|
||||
public string sn0 { get; set; } = string.Empty;
|
||||
public string snzw { get; set; } = string.Empty;
|
||||
public string snr { get; set; } = string.Empty;
|
||||
public string sv23 { get; set; } = string.Empty;
|
||||
public string sv22 { get; set; } = string.Empty;
|
||||
public string sv8 { get; set; } = string.Empty;
|
||||
public string sv7 { get; set; } = string.Empty;
|
||||
public string sv5 { get; set; } = string.Empty;
|
||||
public string sv3 { get; set; } = string.Empty;
|
||||
public string svr { get; set; } = string.Empty;
|
||||
public string sb23 { get; set; } = string.Empty;
|
||||
public string sb22 { get; set; } = string.Empty;
|
||||
public string sb8 { get; set; } = string.Empty;
|
||||
public string sb7 { get; set; } = string.Empty;
|
||||
public string sb5 { get; set; } = string.Empty;
|
||||
public string sb3 { get; set; } = string.Empty;
|
||||
public string sbr { get; set; } = string.Empty;
|
||||
public string zn23 { get; set; } = string.Empty;
|
||||
public string zn22 { get; set; } = string.Empty;
|
||||
public string zn8 { get; set; } = string.Empty;
|
||||
public string zn7 { get; set; } = string.Empty;
|
||||
public string zn5 { get; set; } = string.Empty;
|
||||
public string zn3 { get; set; } = string.Empty;
|
||||
public string zn0 { get; set; } = string.Empty;
|
||||
public string znzw { get; set; } = string.Empty;
|
||||
public string znr { get; set; } = string.Empty;
|
||||
public string zv23 { get; set; } = string.Empty;
|
||||
public string zv22 { get; set; } = string.Empty;
|
||||
public string zv8 { get; set; } = string.Empty;
|
||||
public string zv7 { get; set; } = string.Empty;
|
||||
public string zv5 { get; set; } = string.Empty;
|
||||
public string zv3 { get; set; } = string.Empty;
|
||||
public string zvr { get; set; } = string.Empty;
|
||||
public string zb23 { get; set; } = string.Empty;
|
||||
public string zb22 { get; set; } = string.Empty;
|
||||
public string zb8 { get; set; } = string.Empty;
|
||||
public string zb7 { get; set; } = string.Empty;
|
||||
public string zb5 { get; set; } = string.Empty;
|
||||
public string zb3 { get; set; } = string.Empty;
|
||||
public string zbr { get; set; } = string.Empty;
|
||||
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
using FKGees;
|
||||
using FKGees.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog;
|
||||
using NLog.Extensions.Logging;
|
||||
|
||||
@@ -42,9 +42,10 @@ try
|
||||
|
||||
if (!Directory.Exists("Export"))
|
||||
Directory.CreateDirectory("Export");
|
||||
|
||||
|
||||
var app = servicesProvider.GetRequiredService<App>();
|
||||
app.Run(args).Wait();
|
||||
app.Run(args)
|
||||
.Wait();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -59,9 +60,14 @@ finally
|
||||
|
||||
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";
|
||||
|
||||
var services = new ServiceCollection()
|
||||
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";
|
||||
var symbolMag = config["SymbolMag"] ?? string.Empty;
|
||||
var context = new Context();
|
||||
context.SymbolMag = symbolMag;
|
||||
|
||||
|
||||
var services = new ServiceCollection()
|
||||
.AddLogging(loggingBuilder =>
|
||||
{
|
||||
loggingBuilder.ClearProviders();
|
||||
@@ -69,14 +75,19 @@ static IServiceCollection AddServices(IConfiguration config)
|
||||
loggingBuilder.AddNLog(config);
|
||||
})
|
||||
.AddSingleton<App>()
|
||||
.AddDocumentsDefinitions()
|
||||
.AddTransient<DocumentsService>()
|
||||
.AddSingleton(context)
|
||||
.AddTransient<CsvService>()
|
||||
.AddScoped<DecretsService>()
|
||||
.AddScoped<RegistersService>()
|
||||
.AddRegistersDefinitions()
|
||||
.AddDecretsDefinitions()
|
||||
.AddTransient<PcmService>()
|
||||
.AddDbContextFactory<PcmDbContext>(options =>
|
||||
{
|
||||
options.UseSqlServer(connectionString);
|
||||
options.UseModel(Blink.Backoffice.Services.PcmDb.CompiledEntities.PcmDbContextModel.Instance);
|
||||
options.EnableSensitiveDataLogging(false);
|
||||
});
|
||||
|
||||
return services;
|
||||
|
||||
return services;
|
||||
}
|
||||
44
FKGees/Services/CsvService.cs
Normal file
44
FKGees/Services/CsvService.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.Globalization;
|
||||
using CsvHelper;
|
||||
using CsvHelper.Configuration;
|
||||
using CsvHelper.TypeConversion;
|
||||
|
||||
namespace FKGees.Services;
|
||||
|
||||
internal class CsvService
|
||||
{
|
||||
private ILogger<App> _logger;
|
||||
|
||||
public CsvService(ILogger<App> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
internal async Task CsvExport<T>(string filePath, IEnumerable<T> records)
|
||||
{
|
||||
try
|
||||
{
|
||||
await using var writer = new StreamWriter(filePath);
|
||||
IWriterConfiguration conf = new CsvConfiguration(CultureInfo.InvariantCulture)
|
||||
{
|
||||
Delimiter = ";",
|
||||
Mode = CsvMode.RFC4180,
|
||||
ShouldQuote = quoteArgs => quoteArgs.Field != nameof(DecretsResult.Data)
|
||||
&& quoteArgs.Field != nameof(DecretsResult.DataWplywu)
|
||||
&& !DateTime.TryParseExact(quoteArgs.Field, Constants.DefaultdateFormat, CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.None, out _)
|
||||
};
|
||||
await using var csv = new CsvWriter(writer, conf);
|
||||
var options = new TypeConverterOptions { Formats = [Constants.DefaultdateFormat], NullValues = { string.Empty }};
|
||||
csv.Context.TypeConverterOptionsCache.AddOptions<DateTime>(options);
|
||||
csv.Context.TypeConverterOptionsCache.AddOptions<DateTime?>(options);
|
||||
|
||||
await csv.WriteRecordsAsync(records);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "Error");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
53
FKGees/Services/DecretsService.cs
Normal file
53
FKGees/Services/DecretsService.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
namespace FKGees.Services;
|
||||
|
||||
internal class DecretsService
|
||||
{
|
||||
private readonly PcmService _pcmService;
|
||||
private readonly CsvService _csvService;
|
||||
private readonly IEnumerable<IDecretsDefinition> _definitions;
|
||||
private readonly ILogger<DecretsService> _logger;
|
||||
private readonly Context _context;
|
||||
|
||||
public DecretsService(PcmService pcmService, CsvService csvService, IEnumerable<IDecretsDefinition> definitions, ILogger<DecretsService> logger, Context context)
|
||||
{
|
||||
_pcmService = pcmService;
|
||||
_csvService = csvService;
|
||||
_definitions = definitions;
|
||||
_logger = logger;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
internal async Task Process()
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("DecretsService - Start exports decrets, StartDate: {StartDate}, EndDate: {EndDate}", _context.StatDate , _context.EndDate);
|
||||
var doctypes = _definitions.Select(x => x.DocType)
|
||||
.ToArray();
|
||||
|
||||
var doks = await _pcmService.FetchDecretsDocuments(doctypes, _context.StatDate, _context.EndDate);
|
||||
|
||||
var result = new List<DecretsResult>();
|
||||
foreach (var docDefinition in _definitions)
|
||||
{
|
||||
_logger.LogInformation("DecretsService - Export type: {Type}", docDefinition.Type);
|
||||
Console.WriteLine($"Export: {docDefinition.Type}");
|
||||
var res = await docDefinition.Process(doks);
|
||||
result.AddRange(res);
|
||||
}
|
||||
|
||||
_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));
|
||||
Console.WriteLine("Eksport do pliku dekretów zakończony powodzeniem");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "DecretsService - Export failed");
|
||||
Console.WriteLine("Eksport do pliku dekretów zakończony niepowodzeniem");
|
||||
Console.WriteLine(e.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
73
FKGees/Services/PcmService.cs
Normal file
73
FKGees/Services/PcmService.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FKGees.Services;
|
||||
|
||||
public class PcmService
|
||||
{
|
||||
private readonly IDbContextFactory<PcmDbContext> _dbContextFactory;
|
||||
|
||||
public PcmService(IDbContextFactory<PcmDbContext> dbContextFactory)
|
||||
{
|
||||
_dbContextFactory = dbContextFactory;
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<Dok>> FetchDecretsDocuments(int[] typdok, DateTime dataOd, DateTime dataDo)
|
||||
{
|
||||
await using var context = await _dbContextFactory.CreateDbContextAsync();
|
||||
context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||
|
||||
var documents = await context.Dok
|
||||
.Include(x => x.DokKontr)
|
||||
.ThenInclude(x => x.Kontr)
|
||||
.Include(x => x.DokKasa)
|
||||
.Include(x => x.TekstDok)
|
||||
.Include(x => x.PozDok)
|
||||
.Include(x => x.RozliczaRozliczanyDok)
|
||||
.ThenInclude(x => x.Dok)
|
||||
.Include(x => x.DokKasa)
|
||||
.ThenInclude(x => x.Kasa)
|
||||
.Where(x => typdok.Contains(x.TypDok) && x.Data >= dataOd && x.Data <= dataDo)
|
||||
.ToListAsync();
|
||||
return documents;
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<Dok>> FetchRegistersDocuments(int[] typdok, DateTime dataOd, DateTime dataDo)
|
||||
{
|
||||
await using var context = await _dbContextFactory.CreateDbContextAsync();
|
||||
context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||
|
||||
var documents = await context.Dok
|
||||
.Include(x => x.DokKontr)
|
||||
.ThenInclude(x => x.Kontr)
|
||||
.Include(x => x.TekstDok)
|
||||
.Include(x => x.RozbicieDok)
|
||||
.Where(x => typdok.Contains(x.TypDok) && x.Data >= dataOd && x.Data <= dataDo)
|
||||
.ToListAsync();
|
||||
return documents;
|
||||
}
|
||||
|
||||
public string WzNrFaktury(decimal dokId)
|
||||
{
|
||||
using var context = _dbContextFactory.CreateDbContext();
|
||||
context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||
|
||||
var dok = context.Rozlicza
|
||||
.Include(x => x.RozliczanyDok)
|
||||
.FirstOrDefault(x => x.DokId == dokId);
|
||||
|
||||
return dok?.RozliczanyDok.NrDok ?? string.Empty;
|
||||
}
|
||||
|
||||
public async Task<List<FormaPlatnosci>> FormyPlatnosci()
|
||||
{
|
||||
await using var context = await _dbContextFactory.CreateDbContextAsync();
|
||||
context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||
var fplat = await context.FormaPlatnosci.Where(x => x.FormaPlat > 4).ToListAsync();
|
||||
fplat.Add(new FormaPlatnosci{ FormaPlat = 0, Tekst = "Gotówka"});
|
||||
fplat.Add(new FormaPlatnosci{ FormaPlat = 1, Tekst = "Przelew"});
|
||||
fplat.Add(new FormaPlatnosci{ FormaPlat = 2, Tekst = "Czek potwierdzony"});
|
||||
fplat.Add(new FormaPlatnosci{ FormaPlat = 3, Tekst = "Karta płatnicza"});
|
||||
fplat.Add(new FormaPlatnosci{ FormaPlat = 4, Tekst = "Inna"});
|
||||
return fplat;
|
||||
}
|
||||
}
|
||||
60
FKGees/Services/RegistersService.cs
Normal file
60
FKGees/Services/RegistersService.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -12,5 +12,6 @@
|
||||
"Login": "sa",
|
||||
"Password": "10Coma123",
|
||||
"Database": "HECZNAROWICE"
|
||||
}
|
||||
},
|
||||
"SymbolMag": "FajnySklep"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user