Job Cost Entry file watcher  Topic is solved

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

Job Cost Entry file watcher

Postby neil.interactit » Wed Dec 23, 2020 11:17 am

Hey guys,

Most of the file watchers I have built create sales order entries. I now have a requirement to create a job cost entry batch.

The requirement is that a CSV file will produce job cost entry batch with each CSV line adding a detail line to the batch. Each detail line's job costing is matched from the CSV job no (and is always the stage B costing), and its item matched from the CSV inventory part no.

I'm stuck zeroing in on the correct entities and methods to do this. I've trawled the forums and even scanned through the object browser, but I can't locate anything that looks suitable.

Here's my pseudocode. I'm hoping its just a matter of substituting the correct entity class names, and tweaking the Create/Read methods.

Code: Select all
            var jobCostEntry = manager.BusinessLogicFactory.CreateBusinessLogic<JobCostEntry>(null);
            jobCostEntry.CreateNew();
            jobCostEntry.Reference = "REFERENCE";
            foreach (var csvLine in csvLines)
            {
                var jobCosting = manager.EntityFactory.CreateEntity<JobCode>();
                jobCosting.ReadRecordFromJobNo(csvLine.JobNo, Stage.B);
                var inventory = manager.EntityFactory.CreateEntity<Inventory>();
                inventory.ReadRecordFromPartNo(csvLine.PartNo);
                jobCostEntry.JobCostEntryLines.AddInventoryItem(jobCosting.JobCostingID, inventory.InventoryID, ref newKey);
                var orderLine = jobCostEntry.SalesOrderLines[newKey.ToString()];
                orderLine.QuantityOrdered = csvLine.Qty;
                orderLine.Save();
            }
            jobCostEntry.Save();

Thanks in advance!

Cheers,
Neil
neil.interactit
Kohai
Kohai
 
Posts: 232
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: Job Cost Entry file watcher

Postby SBarnes » Wed Dec 23, 2020 4:43 pm

Hi Neil,

What you are after is in the namespace JiwaFinancials.Jiwa.JiwaJobCosting in JiwaJobCosting.dll and probably the Job class also the factory you want is the Business Logic Factory not the Entity Factory the Entity Logic factory this is for another set of classes which are designed for quick reads from the database not the business logic.

To read a record you use ReadRecord on the object and given I would assume the Job Number is in the csv set the seed type to job number.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Job Cost Entry file watcher

Postby neil.interactit » Wed Jan 06, 2021 11:41 am

Thanks Stuart. I was over complicating with factory creation, where it turned out some entities where just POCOs.

Hi guys,
I now have a plugin that runs without error. Trouble is that it isn't adding a job cost entry batch! There are no runtime exceptions, so I'm not sure where to adjust, as I was expecting the jobCostEntry.NewRecord() / jobCostEntry.Save() combo to at least create something, even if it wasn't yet correct ...

Code: Select all
    var jobCostEntry = manager.BusinessLogicFactory.CreateBusinessLogic<CostEntry>(null);
    jobCostEntry.NewRecord(CostEntry.ItemType.Material);
    jobCostEntry.Reference = "TEST Toner issued";
    foreach (var csvLine in csvLines)
    {
        var line = new Line(manager);
        var job = manager.BusinessLogicFactory.CreateBusinessLogic<Job>(null);
        job.ReadRecord(Job.ReadModes.FirstRecord, FilterString: "OrderNo = '" + csvLine.OrderNo + "'");
        line.Stage.ReadRecordFromFullJobNo(job.JobNumber + "-010-B");

        line.NonInventoryItem = false;
        var inventory = manager.EntityFactory.CreateEntity<Inventory>();
        inventory.ReadRecordFromPartNo(csvLine.PartNo);
        var inventoryLineDetail = new LineDetail {InventoryID = inventory.RecID};
        line.InventoryLineDetails.Add(ref inventoryLineDetail);

        line.Qty = csvLine.Quantity;

        jobCostEntry.Lines.Add(ref line);
    }
    jobCostEntry.Save();

Can you advise where I am going wrong?

Cheers,
Neil
neil.interactit
Kohai
Kohai
 
Posts: 232
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: Job Cost Entry file watcher

Postby SBarnes » Wed Jan 06, 2021 12:18 pm

There is an ErrorMessage string property on the object, I would suggest having a look at the property and see if it gives you any help as it looks like the save code fills this in when there are issues.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Job Cost Entry file watcher

Postby neil.interactit » Fri Jan 08, 2021 2:07 pm

Thanks Stuart. Yes, that exposed an error that I was missing ...

"No item selected for line 1"

Trouble is, this now has me stumped! I've decompiled a fair bit of code exploring this, but can't seem to latch on to the correct approach.

Cheers,
Neil
neil.interactit
Kohai
Kohai
 
Posts: 232
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: Job Cost Entry file watcher

Postby SBarnes » Fri Jan 08, 2021 5:19 pm

Your error is related to the lines property and the following code, near as I can tell the component Id should be an inventory ID, unfortunately I have done very little with Job Costing to be of much more help.


Code: Select all
 while (enumerator.MoveNext())
        {
            Line current = (Line) enumerator.Current;
            num13++;
            if (!current.NonInventoryItem && (current.ComponentID.Trim().Length == 0))
            {
                this._ErrMessage = "No item selected for line " + num13.ToString();
                flag = false;
                goto Label_40B7;
            }
        }
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Job Cost Entry file watcher

Postby neil.interactit » Tue Jan 12, 2021 8:41 am

Thanks Stuart. My decompiler (JetBrains) won't decompile that section of code, so I can't explore the context.

Might have to wait for the guys to get back from leave and advise where I've gone astray!

Thanks again,
Neil
neil.interactit
Kohai
Kohai
 
Posts: 232
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: Job Cost Entry file watcher

Postby SBarnes » Tue Jan 12, 2021 8:51 am

Try

Code: Select all
line.ComponentID= inventory.InventoryID;


after

Code: Select all
inventory.ReadRecordFromPartNo(csvLine.PartNo);


that might be all it needs
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Job Cost Entry file watcher

Postby neil.interactit » Thu Jan 14, 2021 3:33 pm

Perfect! Many thanks Stuart!

In case anyone else ends up here, this is the final working code ...

Code: Select all
    var jobCostEntry = manager.BusinessLogicFactory.CreateBusinessLogic<CostEntry>(null);
    jobCostEntry.NewRecord(CostEntry.ItemType.Material);
    jobCostEntry.Reference = "TEST Toner issued";
    foreach (var csvLine in csvLines)
    {
        var line = new Line(manager);
        var job = manager.BusinessLogicFactory.CreateBusinessLogic<Job>(null);
        job.ReadRecord(Job.ReadModes.FirstRecord, FilterString: "OrderNo = '" + csvLine.OrderNo + "'");
        line.Stage.ReadRecordFromFullJobNo(job.JobNumber + "-010-B");

        line.NonInventoryItem = false;
        var inventory = manager.EntityFactory.CreateEntity<Inventory>();
        inventory.ReadRecordFromPartNo(csvLine.PartNo);
        line.ComponentID = inventory.InventoryID;
        var inventoryLineDetail = new LineDetail { InventoryID = inventory.RecID };
        line.InventoryLineDetails.Add(ref inventoryLineDetail);

        line.Qty = csvLine.Quantity;

        jobCostEntry.AddItem(ref line);
    }
    jobCostEntry.Save();

Cheers,
Neil
neil.interactit
Kohai
Kohai
 
Posts: 232
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: Job Cost Entry file watcher

Postby Scott.Pearce » Thu Jan 14, 2021 3:35 pm

Nice work.
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

Next

Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 0 guests