mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-21 07:17:15 +00:00
Feature repricing min max (#10)
amazon settlement import/export improvements
This commit is contained in:
53
src/bnhtrade.Core/Logic/Export/SalesInvoice.cs
Normal file
53
src/bnhtrade.Core/Logic/Export/SalesInvoice.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Logic.Export
|
||||
{
|
||||
public class SalesInvoice
|
||||
{
|
||||
private string sqlConnectionString;
|
||||
private Logic.Log.LogEvent log = new Log.LogEvent();
|
||||
|
||||
public SalesInvoice(string sqlConnectionString)
|
||||
{
|
||||
this.sqlConnectionString = sqlConnectionString;
|
||||
}
|
||||
|
||||
public string GetNextTempInvoiceNumber()
|
||||
{
|
||||
var sequence = new Data.Database.Programmability.Sequence(sqlConnectionString);
|
||||
return "_tmp" + sequence.GetNext("ExportTempInvoiceNumber").ToString("00000000");
|
||||
}
|
||||
|
||||
public void AddTempInvoiceNumber(IEnumerable<Model.Account.IInvoice> invoiceList, bool overwriteExisting)
|
||||
{
|
||||
for (int i = 0; i < invoiceList.Count(); i++)
|
||||
{
|
||||
if (invoiceList.ElementAt(i).InvoiceNumber != null && overwriteExisting == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
invoiceList.ElementAt(i).InvoiceNumber = GetNextTempInvoiceNumber();
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveSalesInvoice(List<Model.Account.SalesInvoice> invoiceList)
|
||||
{
|
||||
// validate the list of invoices
|
||||
var validateInvoice = new Logic.Validate.SalesInvoice();
|
||||
validateInvoice.IsValidExportInvoice(invoiceList);
|
||||
if (validateInvoice.IsValidResult == false)
|
||||
{
|
||||
log.LogError("Invalid Sales invoice(s) found. See extended info.", validateInvoice.ValidationResultListToString());
|
||||
return;
|
||||
}
|
||||
validateInvoice = null;
|
||||
|
||||
// save to database
|
||||
new Data.Database.Export.CreateSalesInvoice(sqlConnectionString).Execute(invoiceList);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user