Syntax to get to inventory MinSOH, Safety Min, Safety max  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Syntax to get to inventory MinSOH, Safety Min, Safety max

Postby DannyC » Mon Feb 22, 2021 3:34 pm

I've got this code
Code: Select all
        JiwaFinancials.Jiwa.JiwaApplication.Manager manager = item.Manager;
        JiwaFinancials.Jiwa.JiwaInventory.Inventory inventory = manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaInventory.Inventory>(null);
      inventory.Read(item.InventoryID);

but I don't know the correct syntax to get to the data in the Figures tab, i.e. the MinSOH, Safety Min and Safety Max.
I assume it's something like
Code: Select all
inventory.OrderLevels
or maybe its
Code: Select all
inventory.Months
I'm guessing I need to pass in a INT for the month to get or set the relevant value?

Neither of those properties have subproperties to read and write the values for MinSOH, Safety Min and Safety Max.

Of course I can do it the cheats way and just do a SQL SELECT or UPDATE but I figure I could do it via the object model. Or do I just go down the SQL way?
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Syntax to get to inventory MinSOH, Safety Min, Safety ma

Postby Mike.Sheen » Mon Feb 22, 2021 3:39 pm

You need to use the RetrieveOrderLevel method of the OrderLevels property... eg:

Code: Select all
Inventory.OrderLevels.RetrieveOrderLevel(month, logicalWarehouse)


You can iterate the months :

Code: Select all
For Each month As JiwaInventory.Month In Inventory.Months


and that handles the first parameter you need. For the logical warehouses, either you use a specific logical warehouse (like as if you checked the "Specific Warehouse" checkbox on the inventory maintenance form), or you do a nested iteration of all warehouses:

Code: Select all
For Each physicalWarehouse As JiwaApplication.Inventory.Warehouse.PhysicalWarehouse In Manager.PhysicalWarehouseCollection
    For Each logicalWarehouse As JiwaApplication.Inventory.Warehouse.LogicalWarehouse In physicalWarehouse.LogicalWarehouseCollection
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Syntax to get to inventory MinSOH, Safety Min, Safety ma

Postby Mike.Sheen » Mon Feb 22, 2021 3:42 pm

Forgot to mention, it's not just OrderLevels.RetrieveOrderLevel but SalesHistorys.RetrieveSalesHistory, Budgets.RetrieveBudget, BOMUsages.Retrieve, BOMFinishedGoods.Retrieve, JobUsages.Retrieve and JobFinishedGoods.Retrieve as well.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Syntax to get to inventory MinSOH, Safety Min, Safety ma

Postby DannyC » Mon Feb 22, 2021 4:59 pm

Thanks Mike.
Another question related to the logical warehouse. Here's my code:
Code: Select all
private void Check_MinSOH(JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine item)
{
    JiwaFinancials.Jiwa.JiwaApplication.Manager manager = item.Manager;
    JiwaFinancials.Jiwa.JiwaInventory.Inventory inventory = manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaInventory.Inventory>(null);
   inventory.Read(item.InventoryID);
   
   
   foreach(JiwaFinancials.Jiwa.JiwaInventory.Month month in inventory.Months)
   {
      if (month.Index == System.DateTime.Now.Month)
      {   
         JiwaFinancials.Jiwa.JiwaInventory.OrderLevel orderLevel = inventory.OrderLevels.RetrieveOrderLevel(month, item.SalesOrderLines.SalesOrder.LogicalWarehouseResidingIn);
         MessageBox.Show(orderLevel.MinSOHUnits.ToString());
      }
   }
}


It doesn't like inventory.OrderLevels.RetrieveOrderLevel(month, item.SalesOrderLines.SalesOrder.LogicalWarehouseResidingIn) because item.SalesOrderLines.SalesOrder.LogicalWarehouseResidingIn should be JiwaApplication.Inventory.Warehouse.LogicalWarehouse. At least thats how I am interpreting the error I'm getting.
How can I convert one to the other?
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Syntax to get to inventory MinSOH, Safety Min, Safety ma

Postby SBarnes » Tue Feb 23, 2021 6:32 am

One is JiwaFinancials.Jiwa.JiwaApplication.Entities.LogicalWarehouse but the second is JiwaFinancials.Jiwa.JiwaApplication.Inventory.Warehouse.LogicalWarehouse which is just a class that implements INotfyPropertyChanged even though Jiwa uses it in a collection, not sure why it is not a real collection item, probably because it doesn't need to be and it means you don't need a collection item factory to create it.

So change

Code: Select all
JiwaFinancials.Jiwa.JiwaInventory.OrderLevel orderLevel = inventory.OrderLevels.RetrieveOrderLevel(month, item.SalesOrderLines.SalesOrder.LogicalWarehouseResidingIn);


to the following that will create the second class in line and set the property

Code: Select all
JiwaFinancials.Jiwa.JiwaInventory.OrderLevel orderLevel = inventory.OrderLevels.RetrieveOrderLevel(month,  new JiwaFinancials.Jiwa.JiwaApplication.Inventory.Warehouse.LogicalWarehouse() { IN_LogicalID = item.SalesOrderLines.SalesOrder.LogicalWarehouseResidingIn.IN_LogicalID} );


Whilst that may make it compile it may not work because RetrieveOrderLevel uses object equality on the warehouse not just the logical id to find a match, you may actually need to do the following which will require a using clause for System.Linq

Code: Select all
var olevels = inventory.OrderLevels.Cast<JiwaFinancials.Jiwa.JiwaInventory.OrderLevel>(); //get the order levels collection as a list of order levels using cast
var olevel = olevels.Where(l =>l.LogicalWarehouse.IN_LogicalID == item.SalesOrderLines.SalesOrder.LogicalWarehouseResidingIn.IN_LogicalID  && l.Month == month).FirstOrDefault(); // find the order level based upon which one matches the logical warehouse and month using linq where
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Syntax to get to inventory MinSOH, Safety Min, Safety ma

Postby DannyC » Wed Feb 24, 2021 3:40 pm

Still can't get this to play nicely.

I thought I might be able to get the correct warehouse by doing this:
Code: Select all
JiwaFinancials.Jiwa.JiwaApplication.Inventory.Warehouse.LogicalWarehouse inventorywhouse;

foreach(JiwaFinancials.Jiwa.JiwaApplication.Inventory.Warehouse.LogicalWarehouse in_warehouse in JiwaFinancials.Jiwa.JiwaApplication.Inventory.Warehouse.LogicalWarehouseCollection)
{
   if (in_warehouse.IN_LogicalID == item.SalesOrderLines.SalesOrder.LogicalWarehouseResidingIn.IN_LogicalID)
   {
      inventorywhouse = in_warehouse;
   }
}


but despite the word 'collection' appearing in JiwaFinancials.Jiwa.JiwaApplication.Inventory.Warehouse.LogicalWarehouseCollection it doesn't seem to be a collection of JiwaFinancials.Jiwa.JiwaApplication.Inventory.Warehouse.LogicalWarehouse.

EDIT: I'm getting error 'object reference not set to an instance of an object' on my MessageBox.Show line.
It's because orderLevel is null from this line even though I believe I have a valid month & warehouse
Code: Select all
JiwaFinancials.Jiwa.JiwaInventory.OrderLevel orderLevel = inventory.OrderLevels.RetrieveOrderLevel(month, inventorywhouse);


And the underlying cause might be that
Code: Select all
inventory.OrderLevels.Count
is returning 0!

Why would that be when I have a couple of warehouses with MinSOH levels saved?
I'm using a Jiwa demo database.
Last edited by DannyC on Wed Feb 24, 2021 5:39 pm, edited 3 times in total.
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Syntax to get to inventory MinSOH, Safety Min, Safety ma

Postby SBarnes » Wed Feb 24, 2021 4:39 pm

If you are after an explanation of LINQ take a look at https://www.tutorialsteacher.com/linq/linq-tutorials although there are plenty more around, the big advantage to LINQ is ORMLite
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Syntax to get to inventory MinSOH, Safety Min, Safety ma

Postby Mike.Sheen » Wed Feb 24, 2021 4:44 pm

DannyC wrote:Still can't get this to play nicely.


Take a look at this - it's ripped straight from the DisplayFigures() method of the Inventory Maintenance form:

Code: Select all
For Each month As JiwaInventory.Month In Inventory.Months
   For Each physicalWarehouse As JiwaApplication.Inventory.Warehouse.PhysicalWarehouse In Manager.PhysicalWarehouseCollection
      For Each logicalWarehouse As JiwaApplication.Inventory.Warehouse.LogicalWarehouse In physicalWarehouse.LogicalWarehouseCollection

         Dim orderlevel As JiwaInventory.OrderLevel = Inventory.OrderLevels.RetrieveOrderLevel(month, logicalWarehouse)
         Dim salesHistory As JiwaInventory.SalesHistory = Inventory.SalesHistorys.RetrieveSalesHistory(month, logicalWarehouse)
         Dim budget As JiwaInventory.Budget = Inventory.Budgets.RetrieveBudget(month, logicalWarehouse)

         Dim BOMUsage As JiwaInventory.Usage = Inventory.BOMUsages.Retrieve(month, logicalWarehouse)
         Dim BOMFinishedGoods As JiwaInventory.Usage = Inventory.BOMFinishedGoods.Retrieve(month, logicalWarehouse)
         Dim jobUsage As JiwaInventory.Usage = Inventory.JobUsages.Retrieve(month, logicalWarehouse)
         Dim jobFinishedGoods As JiwaInventory.Usage = Inventory.JobFinishedGoods.Retrieve(month, logicalWarehouse)
      Next
   Next
Next
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Syntax to get to inventory MinSOH, Safety Min, Safety ma

Postby DannyC » Wed Feb 24, 2021 5:48 pm

I'll try that Mike but

Code: Select all
inventory.OrderLevels.Count
is returning 0!

Why would that be when I have a couple of warehouses with MinSOH levels saved for this particular item (FYI it's a 11901 - External Slim DVD writer - DRXS77UB)?
I'm using a Jiwa demo database.

Might be why
Code: Select all
JiwaFinancials.Jiwa.JiwaInventory.OrderLevel orderLevel = inventory.OrderLevels.RetrieveOrderLevel(month, inventorywhouse);
is returning null
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Syntax to get to inventory MinSOH, Safety Min, Safety ma

Postby Mike.Sheen » Wed Feb 24, 2021 5:52 pm

DannyC wrote:I'll try that Mike but

Code: Select all
inventory.OrderLevels.Count
is returning 0!

Why would that be when I have a couple of warehouses with MinSOH levels saved for this particular item (FYI it's a 11901 - External Slim DVD writer - DRXS77UB)?
I'm using a Jiwa demo database.

Might be why
Code: Select all
JiwaFinancials.Jiwa.JiwaInventory.OrderLevel orderLevel = inventory.OrderLevels.RetrieveOrderLevel(month, inventorywhouse);
is returning null


Those figures are lazy loaded by the form - we don't read them unless you have the tab selected.

You need to call Inventory.OrderLevels.Read() to explicitly read them. Same goes for SalesHistorys, Budgets, BOMUsages, BOMFinishedGoods, JobUsages and JobFinishedGoods
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Next

Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 18 guests