Page 1 of 1

Stock Tansfer API sample code

PostPosted: Wed Mar 11, 2015 2:33 pm
by dimuthu
Hi Mike,

I need to create a stock transfer ( to increase the Qty ) for items in one of our custom programs. I could not find out any samples done for stock transfer in the API documentation of my version ( http://help.jiwa.com.au/Jiwa7/7.00.105/ ... index.aspx ).

There are samples done for the SalesOrder API. That helped a lot to use in my .net custom program.

Could you please send me same kind of sample for stock transfer.

Thanks
Dimuthu

Re: Stock Tansfer API sample code

PostPosted: Tue Mar 17, 2015 9:56 am
by Mike.Sheen
Hi Dimuthu,

The following snippet of code creates a new stock transfer and adds an item which is to have the SOH increased by a quantity of 5.

Code: Select all
JiwaApplication.Manager.Instance.Logon("JiwaMike", "JiwaDemo7115", JiwaODBC.database.AuthenticationModes.JiwaAuthentication, "Admin", "password")

Dim stockTransfer As JiwaStockTransfer.StockTransfer = JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of JiwaStockTransfer.StockTransfer)(Nothing)
stockTransfer.CreateNew()
stockTransfer.TransferDate = JiwaApplication.Manager.Instance.SysDateTime

Dim line As New JiwaStockTransfer.Line
line.FromInventory.PartNo = "External"

line.ToInventory.ReadRecordFromPartNo("1170")
line.TransferQuantity = 5
line.ToPartExpiryDate = JiwaApplication.Manager.Instance.SysDateTime   ' <-- The need for this seems to be a bug, but just setting the expiry date is a workaround - otherwise the Save method fails later.

stockTransfer.Lines.Add(line)
stockTransfer.Save()


Mike

Re: Stock Tansfer API sample code

PostPosted: Wed Mar 18, 2015 10:38 am
by dimuthu
Thanks Mike.

Re: Stock Tansfer API sample code

PostPosted: Wed Mar 18, 2015 5:13 pm
by dimuthu
Hi Mike,

Could you please assist me with this.

I tried your code but it didn't work. Not sure I'm doing something wrong.

After calling the "stockTransfer.Save()" method I called the "stockTransfer.ActivateRecord()". Then it throws me "Please save the stock take first. at JiwaFinancials.Jiwa.JiwaStockTransfer.StockTransfer.ActivateRecord() " error message. When I checked in Jiwa stock transfer has been created.

Also I need to get the TransferNo after calling the save method. I tried to get the value ( "TransferNo = stockTransfer.TransferNo.ToString" ) but no value is passed.

Is there any way that we can add items to a lines collection something within a FOR loop and finally call the save method ?

Could you please check my attached coding.

Regards
Dimuthu

Re: Stock Tansfer API sample code

PostPosted: Wed Mar 18, 2015 7:56 pm
by Mike.Sheen
Hi Dimuthu,

After saving you should always read the transfer before attempting to modify the transfer in any way.

You should obtain the RecID (NOT the TransferNo as you are) after saving, then read using the RecID. Then you can call the Activate method.

Also, omit the following lines:

Code: Select all
line.Clear()
line = Nothing


As the line you have added to the collection is a pointer to the item in the lines collection, by calling clear and setting it to nothing you are destroying the item now in the collection.

Mike

Re: Stock Tansfer API sample code

PostPosted: Thu Mar 19, 2015 11:51 am
by dimuthu
Thanks Mike. I did as you mentioned. Called the record activate method after the Read method.

.Save()
.Read(.RecID)

.ActivateRecord()

But when calling the "ActivateRecord()" , program throws "JiwaFinancials.Jiwa.JiwaApplication.Exceptions.RecordNotFoundException: General Ledger Account Not Found".

Regards
Dimuthu

Re: Stock Tansfer API sample code  Topic is solved

PostPosted: Thu Mar 19, 2015 3:33 pm
by Mike.Sheen
dimuthu wrote:Thanks Mike. I did as you mentioned. Called the record activate method after the Read method.

.Save()
.Read(.RecID)

.ActivateRecord()

But when calling the "ActivateRecord()" , program throws "JiwaFinancials.Jiwa.JiwaApplication.Exceptions.RecordNotFoundException: General Ledger Account Not Found".

Regards
Dimuthu


Dimuthu,

That works for me - my complete code is as follows:

Code: Select all
JiwaApplication.Manager.Instance.Logon("JiwaMike", "JiwaDemo7115", JiwaODBC.database.AuthenticationModes.JiwaAuthentication, "Admin", "password")

Dim stockTransfer As JiwaStockTransfer.StockTransfer = JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of JiwaStockTransfer.StockTransfer)(Nothing)
stockTransfer.CreateNew()
stockTransfer.TransferDate = JiwaApplication.Manager.Instance.SysDateTime

Dim line As New JiwaStockTransfer.Line
line.FromInventory.PartNo = "External"

line.ToInventory.ReadRecordFromPartNo("1170")
line.TransferQuantity = 5
line.ToPartExpiryDate = JiwaApplication.Manager.Instance.SysDateTime   ' <-- The need for this seems to be a bug, but just setting the expiry date is a workaround - otherwise the Save method fails later.

stockTransfer.Lines.Add(line)
stockTransfer.Save()

stockTransfer.Read(stockTransfer.RecID)
stockTransfer.ActivateRecord()


I'm guessing you've not tried this in the demo data? The above works fine for me in demo data. The message you are getting suggests there is a General Ledger account missing or not defined - it's the journal posting during the activate which requires the GL accounts and that will be what is throwing the exception. The journals associated with a transfer are the inventory value and inventory write on accounts - make sure the inventory items you are using have those accounts set, and if the stock transfer reason is configured to override the write on account that it also is configured to a valid account.

Also, if using warehouse masking then make sure the appropriate inventory value and write on accounts exist for the warehouse you are transferring in on.

Mike

Re: Stock Tansfer API sample code

PostPosted: Thu Mar 19, 2015 4:45 pm
by dimuthu
Thanks Mike. Found what causing the issue.

I had "line.ToInventory.InventoryID = Trim(ToInventoryID)" instead of "line.ToInventory.ReadRecordFromPartNo(Trim(Row("PartNo").ToString))"

Now it worked. Thanks for your help.

Regards
Dimuthu

Re: Stock Tansfer API sample code

PostPosted: Fri May 29, 2015 1:22 pm
by DannyC
Mike or Scott,

I am using this thread as a basis for developing a plugin to use the File Watcher to import a Stock Transfer.
I have figured out the bulk of the import & I can successfully import a CSV file into a new transfer.

My problem is when I am writing off stock (i.e To External).
Currently all stock transferred from an inventory item to External is displaying in red with available quantity = 0.
I do not know how to programatically get the SOH details so things like FromPartInventorySOHID, FromPartOriginalQuantity, AvailableQuantity and other required details such as the writeoff/on ledger codes.

Attached is my plugin so far. the main sub starts at line 638.
I am having trouble at line 678.

Cheers

Danny