Bug fix Sale.UpdateInvoice class

This commit is contained in:
2020-02-05 15:33:06 +00:00
parent 229d9eccec
commit 0198d12549
3 changed files with 19 additions and 12 deletions

View File

@@ -148,7 +148,8 @@ namespace BealeEngineering.Accounts
dialogText = "Import complete." + Environment.NewLine + Environment.NewLine dialogText = "Import complete." + Environment.NewLine + Environment.NewLine
+ importXeroInvoice.InvoicesProcessed + " invoice(s) found" + Environment.NewLine + importXeroInvoice.InvoicesProcessed + " invoice(s) found" + Environment.NewLine
+ importXeroInvoice.InvoicesCreated + " invoice(s) created" + Environment.NewLine + importXeroInvoice.InvoicesCreated + " invoice(s) created" + Environment.NewLine
+ importXeroInvoice.InvoicesUpdated + " invoice(s) updated" + Environment.NewLine; + importXeroInvoice.InvoicesUpdated + " invoice(s) updated" + Environment.NewLine
+ importXeroInvoice.InvoicesSkipped + " invoice(s) skipped" + Environment.NewLine;
MessageBox.Show(dialogText); MessageBox.Show(dialogText);
} }

View File

@@ -14,6 +14,7 @@ namespace BealeEngineering.Core.Data.Database.Sale
private int recordsCreated = 0; private int recordsCreated = 0;
private int recordsUpdated = 0; private int recordsUpdated = 0;
private int invoicesProcessed = 0; private int invoicesProcessed = 0;
private int invoicesSkipped = 0;
public UpdateInvoice(string sqlConnectionString) : base(sqlConnectionString) public UpdateInvoice(string sqlConnectionString) : base(sqlConnectionString)
{ {
@@ -22,6 +23,7 @@ namespace BealeEngineering.Core.Data.Database.Sale
public int RecordsCreated { get { return recordsCreated; } } public int RecordsCreated { get { return recordsCreated; } }
public int RecordsUpdated { get { return recordsUpdated; } } public int RecordsUpdated { get { return recordsUpdated; } }
public int InvoicesProcessed { get { return invoicesProcessed; } } public int InvoicesProcessed { get { return invoicesProcessed; } }
public int InvoicesSkipped { get { return invoicesSkipped; } }
public void ByInvoice(Model.Sale.Invoice invoice, bool insertNew = false) public void ByInvoice(Model.Sale.Invoice invoice, bool insertNew = false)
{ {
var invoiceList = new List<Model.Sale.Invoice> { invoice }; var invoiceList = new List<Model.Sale.Invoice> { invoice };
@@ -32,6 +34,7 @@ namespace BealeEngineering.Core.Data.Database.Sale
recordsCreated = 0; recordsCreated = 0;
recordsUpdated = 0; recordsUpdated = 0;
invoicesProcessed = 0; invoicesProcessed = 0;
invoicesSkipped = 0;
// check the list // check the list
if (invoiceList == null || !invoiceList.Any()) { return; } if (invoiceList == null || !invoiceList.Any()) { return; }
@@ -103,18 +106,19 @@ namespace BealeEngineering.Core.Data.Database.Sale
OUTPUT INSERTED.SaleInvoiceID OUTPUT INSERTED.SaleInvoiceID
VALUES( VALUES(
(SELECT ContactID FROM Contact WHERE ContactName = @contactName) (SELECT ContactID FROM Contact WHERE ContactName = @contactName)
@saleInvoiceNumber ,@saleInvoiceNumber
@invoiceDate ,@invoiceDate
@dateDue ,@dateDue
@reference ,@reference
@currencyCode ,@currencyCode
@invoiceTotal ,@invoiceTotal
@taxTotal ,@taxTotal
@isCreditNote ,@isCreditNote
)"; )";
} }
else else
{ {
invoicesSkipped += 1;
continue; continue;
} }
@@ -198,7 +202,7 @@ namespace BealeEngineering.Core.Data.Database.Sale
} }
} }
} }
if (InvoicesProcessed == (RecordsCreated + RecordsUpdated)) if (InvoicesProcessed == (RecordsCreated + RecordsUpdated + invoicesSkipped))
{ {
scope.Complete(); scope.Complete();
} }

View File

@@ -21,6 +21,7 @@ namespace BealeEngineering.Core.Logic.Import
public int InvoicesProcessed { get; private set; } = 0; public int InvoicesProcessed { get; private set; } = 0;
public int InvoicesSkipped { get; private set; } = 0;
public void ByFilePath(string filePath, bool updateContacts = true) public void ByFilePath(string filePath, bool updateContacts = true)
{ {
@@ -44,13 +45,14 @@ namespace BealeEngineering.Core.Logic.Import
if (dbInvoiceData.Any()) if (dbInvoiceData.Any())
{ {
var updateInvoice = new Data.Database.Sale.UpdateInvoice(sqlConnectionString); var updateInvoice = new Data.Database.Sale.UpdateInvoice(sqlConnectionString);
updateInvoice.ByInvoiceList(dbInvoiceData); updateInvoice.ByInvoiceList(dbInvoiceData, true);
InvoicesCreated = updateInvoice.RecordsCreated; InvoicesCreated = updateInvoice.RecordsCreated;
InvoicesUpdated = updateInvoice.RecordsUpdated; InvoicesUpdated = updateInvoice.RecordsUpdated;
InvoicesProcessed = updateInvoice.InvoicesProcessed; InvoicesProcessed = updateInvoice.InvoicesProcessed;
InvoicesSkipped = updateInvoice.InvoicesSkipped;
if (InvoicesProcessed != (InvoicesCreated + InvoicesUpdated)) if (InvoicesProcessed != (InvoicesCreated + InvoicesUpdated + InvoicesSkipped))
{ throw new Exception("Error importing invoices"); } { throw new Exception("Error importing invoices"); }
} }
} }