|
@@ -94,9 +94,10 @@ public class InvoiceMYOBPoster : IMYOBPoster<Invoice, InvoiceMYOBPosterSettings>
|
|
|
foreach(var invoice in invoices)
|
|
|
{
|
|
|
MYOBInvoice myobInvoice;
|
|
|
+ Exception? error;
|
|
|
if(Guid.TryParse(invoice.PostedReference, out var myobID))
|
|
|
{
|
|
|
- if(!service.Get(ConnectionData, myobID).Get(out var newInvoice, out var error))
|
|
|
+ if(!service.Get(ConnectionData, myobID).Get(out var newInvoice, out error))
|
|
|
{
|
|
|
CoreUtils.LogException("", error, $"Failed to find Invoice in MYOB with id {myobID}");
|
|
|
results.AddFailed(invoice, $"Failed to find Invoice in MYOB with id {myobID}: {error.Message}");
|
|
@@ -115,12 +116,13 @@ public class InvoiceMYOBPoster : IMYOBPoster<Invoice, InvoiceMYOBPosterSettings>
|
|
|
|
|
|
if(customers.TryGetValue(invoice.CustomerLink.ID, out var customer))
|
|
|
{
|
|
|
- if(!CustomerMYOBPoster.MapCustomer(ConnectionData, customer).Get(out var customerID, out var error))
|
|
|
+ if(!CustomerMYOBPoster.MapCustomer(ConnectionData, customer).Get(out var customerID, out error))
|
|
|
{
|
|
|
CoreUtils.LogException("", error, $"Error while posting invoice {invoice.ID}");
|
|
|
results.AddFailed(invoice, error.Message);
|
|
|
continue;
|
|
|
}
|
|
|
+ myobInvoice.Customer ??= new();
|
|
|
myobInvoice.Customer.UID = customerID;
|
|
|
}
|
|
|
// myobInvoice.PromisedDate =
|
|
@@ -151,7 +153,7 @@ public class InvoiceMYOBPoster : IMYOBPoster<Invoice, InvoiceMYOBPosterSettings>
|
|
|
}
|
|
|
if(!Guid.TryParse(item.SellGL.PostedReference, out var accountID))
|
|
|
{
|
|
|
- if(AccountMYOBUtils.GetAccount(ConnectionData, item.SellGL.Code).Get(out accountID, out var error))
|
|
|
+ if(AccountMYOBUtils.GetAccount(ConnectionData, item.SellGL.Code).Get(out accountID, out error))
|
|
|
{
|
|
|
results.AddFragment(new GLCode { ID = item.SellGL.ID, PostedReference = accountID.ToString() });
|
|
|
}
|
|
@@ -162,6 +164,7 @@ public class InvoiceMYOBPoster : IMYOBPoster<Invoice, InvoiceMYOBPosterSettings>
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ line.Account ??= new();
|
|
|
line.Account.UID = accountID;
|
|
|
|
|
|
if(item.TaxCode.ID == Guid.Empty)
|
|
@@ -173,7 +176,7 @@ public class InvoiceMYOBPoster : IMYOBPoster<Invoice, InvoiceMYOBPosterSettings>
|
|
|
{
|
|
|
if (!ConnectionData.GetUID<TaxCodeService, MYOBTaxCode>(
|
|
|
new Filter<MYOBTaxCode>(x => x.Code).IsEqualTo(item.TaxCode.Code))
|
|
|
- .Get(out taxCodeID, out var error))
|
|
|
+ .Get(out taxCodeID, out error))
|
|
|
{
|
|
|
CoreUtils.LogException("", error, $"Failed to find TaxCode in MYOB with code {item.TaxCode.Code}");
|
|
|
failed = $"Failed to find TaxCode in MYOB with code {item.TaxCode.Code}: {error.Message}";
|
|
@@ -186,6 +189,7 @@ public class InvoiceMYOBPoster : IMYOBPoster<Invoice, InvoiceMYOBPosterSettings>
|
|
|
}
|
|
|
results.AddFragment(new TaxCode { ID = taxCodeID, PostedReference = taxCodeID.ToString() });
|
|
|
}
|
|
|
+ line.TaxCode ??= new();
|
|
|
line.TaxCode.UID = taxCodeID;
|
|
|
|
|
|
newLines[i] = line;
|
|
@@ -219,16 +223,15 @@ public class InvoiceMYOBPoster : IMYOBPoster<Invoice, InvoiceMYOBPosterSettings>
|
|
|
// Order
|
|
|
// OnlinePaymentMethod
|
|
|
|
|
|
- try
|
|
|
+ if(service.Save(ConnectionData, myobInvoice).Get(out var result, out error))
|
|
|
{
|
|
|
- var result = service.UpdateEx(ConnectionData.CompanyFile, myobInvoice, ConnectionData.CompanyFileCredentials);
|
|
|
invoice.PostedReference = result.UID.ToString();
|
|
|
results.AddSuccess(invoice);
|
|
|
}
|
|
|
- catch (Exception e)
|
|
|
+ else
|
|
|
{
|
|
|
- CoreUtils.LogException("", e, $"Error while posting invoice {invoice.ID}");
|
|
|
- results.AddFailed(invoice, e.Message);
|
|
|
+ CoreUtils.LogException("", error, $"Error while posting invoice {invoice.ID}");
|
|
|
+ results.AddFailed(invoice, error.Message);
|
|
|
}
|
|
|
}
|
|
|
|