Page 1 of 2

Job Cost Entry file watcher

PostPosted: Wed Dec 23, 2020 11:17 am
by neil.interactit
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

Re: Job Cost Entry file watcher

PostPosted: Wed Dec 23, 2020 4:43 pm
by SBarnes
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.

Re: Job Cost Entry file watcher

PostPosted: Wed Jan 06, 2021 11:41 am
by neil.interactit
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

Re: Job Cost Entry file watcher

PostPosted: Wed Jan 06, 2021 12:18 pm
by SBarnes
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.

Re: Job Cost Entry file watcher

PostPosted: Fri Jan 08, 2021 2:07 pm
by neil.interactit
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

Re: Job Cost Entry file watcher

PostPosted: Fri Jan 08, 2021 5:19 pm
by SBarnes
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;
            }
        }

Re: Job Cost Entry file watcher

PostPosted: Tue Jan 12, 2021 8:41 am
by neil.interactit
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

Re: Job Cost Entry file watcher

PostPosted: Tue Jan 12, 2021 8:51 am
by SBarnes
Try

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


after

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


that might be all it needs

Re: Job Cost Entry file watcher

PostPosted: Thu Jan 14, 2021 3:33 pm
by neil.interactit
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

Re: Job Cost Entry file watcher

PostPosted: Thu Jan 14, 2021 3:35 pm
by Scott.Pearce
Nice work.