Create SalesOrderLines - Taxid field issue  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Create SalesOrderLines - Taxid field issue

Postby Drew » Tue Nov 10, 2015 5:58 pm

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
Drew
Occasional Contributor
Occasional Contributor
 
Posts: 10
Joined: Mon Oct 12, 2015 5:21 pm

Re: Create SalesOrderLines - Taxid field issue  Topic is solved

Postby Scott.Pearce » Fri Nov 13, 2015 10:38 am

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.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 765
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 230

Re: Create SalesOrderLines - Taxid field issue

Postby Drew » Fri Nov 13, 2015 11:22 am

Thanks Chris
Trying to not be lazy...

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

Cheers
Drew
Drew
Occasional Contributor
Occasional Contributor
 
Posts: 10
Joined: Mon Oct 12, 2015 5:21 pm

Re: Create SalesOrderLines - Taxid field issue

Postby Scott.Pearce » Fri Nov 13, 2015 11:40 am

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.
Attachments
Plugin Add line to sales order.xml
(32.34 KiB) Downloaded 988 times
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 765
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 230

Re: Create SalesOrderLines - Taxid field issue

Postby Drew » Fri Nov 13, 2015 6:29 pm

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.
Drew
Occasional Contributor
Occasional Contributor
 
Posts: 10
Joined: Mon Oct 12, 2015 5:21 pm

Re: Create SalesOrderLines - Taxid field issue

Postby Scott.Pearce » Sat Nov 14, 2015 12:23 pm

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?
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 765
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 230

Re: Create SalesOrderLines - Taxid field issue

Postby Drew » Tue Nov 17, 2015 9:54 am

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.
Drew
Occasional Contributor
Occasional Contributor
 
Posts: 10
Joined: Mon Oct 12, 2015 5:21 pm


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 2 guests