This repository has been archived by the owner on Feb 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
65 lines (54 loc) · 2.16 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
namespace EzPay.Export
{
using System.Collections.Generic;
using System.IO;
using System.Linq;
using EzPay.IO;
using EzPay.IO.ExportWrappers;
using EzPay.Model;
using EzPay.Model.Entities;
using EzPay.Services;
using EzPay.Services.Utilities;
using Microsoft.EntityFrameworkCore;
/// <summary>
/// Console app triggering exports
/// </summary>
public class Program
{
private static IEzPayRepository _ctx;
private static readonly DirectoryInfo rootDir = new DirectoryInfo(@"C:\ezpay");
private static IConfigFile config;
private static bool _local;
/// <summary>
/// Entry point for Console App
/// </summary>
/// <param name="args">Optional args</param>
public static void Main(string[] args)
{
_local = false;
config = new ConfigFile();
config.LoadConfig(new FileInfo(Path.Combine(rootDir.FullName, "priv", "appsettings.txt")));
var exportRoot = new DirectoryInfo(Path.Combine(rootDir.FullName, "export"));
if (!exportRoot.Exists)
{
Console.WriteLine("Export share is not available!");
}
var options = new DbContextOptionsBuilder();
options.UseSqlServer(_local ? config.GetConfigValue("SQLExpress") : config.GetConfigValue("SQL"));
_ctx = new EzPaySqlServerContext(options.Options);
var settleExports = _ctx.GetSet<Settlement>().Include(b => b.Bills)
.Include(s => s.Type).Select(c => new SettlementExport(c));
var payExports = _ctx.GetSet<Payment>().Select(p => new PaymentExport(p));
var date = $"{DateTime.Now.AddDays(-1):yyyyMMdd}";
Exporter.ExportRecords(
settleExports,
Path.Combine(exportRoot.FullName, $"SETTLEMENTS_{date}.txt"),
"VAT;TIME;BILLS;DOWNPAYMENT;INSTALLMENTS;INTEREST");
Exporter.ExportRecords(
payExports,
Path.Combine(exportRoot.FullName, $"PAYMENTS_{date}.txt"),
"BILL_ID;TIME;AMOUNT;METHOD");
}
}
}