Page 1 of 1

Create SalesOrderLines - Taxid field issue

PostPosted: Tue Nov 10, 2015 5:58 pm
by Drew
How to Create a SalesOrderLines?

this is the code i have

Code: Select all
JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Logon(JiwaSqlServer, JiwaDatabaseName, JiwaFinancials.Jiwa.JiwaODBC.database.AuthenticationModes.JiwaAuthentication, JiwaAdmin, JiwaPassword);

var salesOrder = JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder>(null);
salesOrder.CreateNew(JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder.NewSalesOrderTypes.e_NewSalesOrder, (debtorseed ?? quote.billing_account_id), debtorseed != null);

salesOrder.Reference = quote.id;
salesOrder.OrderNo = quote.description;
salesOrder.Save();

var iID = salesOrder.InvoiceID;
salesOrder = JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder>(null);
salesOrder .Read(iID);

var trc = new TaxRateCollection(TaxRates.TaxRateTypes.GSTAdjustmentsout);

var sol = new SalesOrderLine(trc)
{
HistoryID = soh.RecID,
InventoryID = GetJiwaInvetoryID(product.name, jiwaConnection),
PartNo = product.name,
Description = product.description,
InvoicePrice = Convert.ToDecimal(product.total_amount),
QuantityOrdered = Convert.ToDecimal(product.quantity)
};

salesOrder.SalesOrderLines.Add(sol);
salesOrder.Save(); //<--- Here i get Error


The error that I recieve is :
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in JiwaSales.dll
Additional information: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_SO_Lines_TaxID". The conflict occurred in database "GeneticsAus_Jiwa1", table "dbo.TX_Main", column 'TaxID'.

I assume I am doing something not right with the new TaxRateCollection.

Any help will be appreciated.

Drew

Re: Create SalesOrderLines - Taxid field issue  Topic is solved

PostPosted: Fri Nov 13, 2015 10:38 am
by Scott.Pearce
You should refactor your code to use:

Code: Select all
salesOrder.SalesOrderLines.AddInventoryItem()


If you really don't want to do that because laziness, you could try:

Code: Select all
var sol = new SalesOrderLine(salesOrder.GstTaxRates)


Our code uses the AddInventoryItem() method so I advise using that. AddInventoryItem() sets up a lot of default stuff for your line and make sure everything is cool before adding it, so you wont getting any nasty surprises later, like during save.

Re: Create SalesOrderLines - Taxid field issue

PostPosted: Fri Nov 13, 2015 11:22 am
by Drew
Thanks Chris
Trying to not be lazy...

what is the value(object) needed for AddInventoryItem ( , , ref object NewKey) ?

Cheers
Drew

Re: Create SalesOrderLines - Taxid field issue

PostPosted: Fri Nov 13, 2015 11:40 am
by Scott.Pearce
NewKey is returned as a string that contains the recID of the line. This can be used for figuring which line on the UI maps to the line in the business logic.

I've attached a plugin that demonstrates adding a line using AddInventoryItem.

Re: Create SalesOrderLines - Taxid field issue

PostPosted: Fri Nov 13, 2015 6:29 pm
by Drew
ok new error.
have tried a few different inventoryID with all the same error.

not sure whats wrong now?

and using the "lazy way" is still getting the same error..

Code: Select all
object newLineKey = "";
salesOrder.SalesOrderLines.AddInventoryItem("16B94E623EFA4CC6B6BA", SalesOrderLineCollection.SalesOrderLineInventorySeedTypes.e_SalesOrderLineInventoryID, ref newLineKey);


Error
An unhandled exception of type 'System.Exception' occurred in JiwaSales.dll
Additional information: This inventory item does not have an 'Assigned Value' ledger account attached.

Re: Create SalesOrderLines - Taxid field issue

PostPosted: Sat Nov 14, 2015 12:23 pm
by Scott.Pearce
Are you able to add those same items ok using the normal Jiwa UI? Are the tax rates configured correctly and attached appropriately to the inventory items? Have you tested using the standard Jiwa demo database?

Re: Create SalesOrderLines - Taxid field issue

PostPosted: Tue Nov 17, 2015 9:54 am
by Drew
Well dang.
Can't do it in JIWA same error. hrm.

Ok so my client is remaking my UAT database so this should work.

Thanks Scott.

Will let you know how it goes.