Default supplier part number  Topic is solved

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

Default supplier part number

Postby SBarnes » Mon Apr 12, 2021 2:47 pm

How can you check through the business object that the default supplier has a part number set?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Default supplier part number  Topic is solved

Postby Scott.Pearce » Mon Apr 12, 2021 4:14 pm

Basically , look at:

Code: Select all
inventoryObject.Regions[defaultRegionID].Suppliers[defaultSupplierID].SupplierPartNo


A more code-complete example would be:

Code: Select all
JiwaFinancials.Jiwa.JiwaInventory.Inventory inventoryObject = (JiwaFinancials.Jiwa.JiwaInventory.Inventory)sender;

string defaultRegionID = null;

foreach(JiwaFinancials.Jiwa.JiwaInventory.Region existingRegion in inventoryObject.Regions)
{
   if(existingRegion.DefaultRegion == true)
   {
      defaultRegionID = existingRegion.RecID;
      break;
   }
}

if(defaultRegionID == null)
{
   throw new Exception("No default region configured.");
}
   

string defaultSupplierID = null;
   
foreach(JiwaFinancials.Jiwa.JiwaInventory.Supplier existingSupplier in inventoryObject.Regions[defaultRegionID].Suppliers)
{
   if(existingSupplier.IsDefault == true)
   {
      defaultSupplierID = existingSupplier.RecID;
      break;
   }            
}

if(defaultSupplierID == null)
{
   throw new Exception(string.Format("No default supplier exists for part no '{0}' in region '{1}'.", inventoryObject.PartNo, inventoryObject.Regions[defaultRegionID].Name));   
}

if(inventoryObject.Regions[defaultRegionID].Suppliers[defaultSupplierID].SupplierPartNo == null || inventoryObject.Regions[defaultRegionID].Suppliers[defaultSupplierID].SupplierPartNo.Trim().Length == 0)
{
   MessageBox.Show("No default supplier part no. set");
}
else
{
   MessageBox.Show(string.Format("Part no. '{0}' has a default supplier part no. of '{1}' for the default region.", inventoryObject.PartNo, inventoryObject.Regions[defaultRegionID].Suppliers[defaultSupplierID].SupplierPartNo));
}   
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: Default supplier part number

Postby SBarnes » Mon Apr 12, 2021 4:26 pm

Thanks Scott

I was hoping there was a default method, this as an extension method should work also from what you gave me

Code: Select all
        public static string DefaultPartNo(this JiwaFinancials.Jiwa.JiwaInventory.Inventory inventory)
        {
            string defpartno = "";
            JiwaFinancials.Jiwa.JiwaInventory.Region defregion = inventory.Regions.Cast<JiwaFinancials.Jiwa.JiwaInventory.Region>().Where(r => r.DefaultRegion).FirstOrDefault();
            if (defregion != null)
            {
                JiwaFinancials.Jiwa.JiwaInventory.Supplier defsupplier = defregion.Suppliers.Cast<JiwaFinancials.Jiwa.JiwaInventory.Supplier>().Where(s => s.IsDefault).FirstOrDefault();
                if (defsupplier != null)
                {
                    defpartno = defsupplier.SupplierPartNo;
                }

            }

            return defpartno;
        }
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 2 guests