mirror of
https://github.com/stokebob/BealeEngineering.git
synced 2026-03-21 07:37:16 +00:00
54 lines
1.8 KiB
C#
54 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using CsvHelper;
|
|
|
|
namespace BealeEngineering.Core.Logic.Export
|
|
{
|
|
public class XeroInvoiceFlatFile
|
|
{
|
|
string sqlConnectionString;
|
|
|
|
public XeroInvoiceFlatFile(string sqlConnectionString)
|
|
{
|
|
this.sqlConnectionString = sqlConnectionString;
|
|
|
|
FileOutputPath =
|
|
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
|
|
+ @"\Dropbox\Beale Engineering Services Ltd\BE Accounts\Xero-Export-Invoices.csv";
|
|
}
|
|
|
|
public int InvoicesExported { get; private set; } = 0;
|
|
|
|
public string FileOutputPath { get; set; }
|
|
|
|
public void Execute()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(FileOutputPath))
|
|
{ throw new Exception("File path not set"); }
|
|
|
|
// read all invoice from db
|
|
var invoiceList = new Data.Database.Sale.ReadInvoice(sqlConnectionString).Read();
|
|
|
|
// map into xeroinvoice dto
|
|
var xeroInvoiceList = new Logic.Adapter.XeroInvoiceFlatFile().SaleInvoice(invoiceList);
|
|
if (xeroInvoiceList == null || !xeroInvoiceList.Any())
|
|
{ return; }
|
|
else { InvoicesExported = xeroInvoiceList.Count(); }
|
|
var xeroInvoiceDtoList = new Logic.Adapter.XeroInvoiceFlatFileDTO().XeroInvoiceFlatFile(xeroInvoiceList);
|
|
|
|
// create flatfile from dto
|
|
using (var writer = new StreamWriter(FileOutputPath))
|
|
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
|
|
{
|
|
csv.WriteRecords(xeroInvoiceDtoList);
|
|
//csv.WriteRecords(xeroInvoiceList);
|
|
}
|
|
}
|
|
}
|
|
}
|