Extending the Inventory CSV Import

Samples and Examples of using the Jiwa 7 framework - including plugins, stand-alone applications and scripts.

Extending the Inventory CSV Import

Postby Mike.Sheen » Thu Oct 29, 2015 11:21 am

In this sample, we extend the Inventory CSV import to allow the import of the P1...P10 selling prices.

So, if the user supplies a file with any of these prices it can be mapped and imported into Jiwa (either as a new product or as an update to an existing product).

What's of interest here is how this is extended. The Import object has a property named "DestinationPropertyCollection" - this collection is a list of all the properties which can be mapped. It is a collection of DestinationProperty - which has the following properties:



PropertyDescription
CaptionThe text to show the user in the mapping drop-down
AliasesA list of possible aliases to try and map from the source file
SetterMethodThe logic to use for setting the value


The SetterMethod is what enables the flexibility to extend the inventory import. We can add a new property mapping and supply the code as the SetterMethod to provide custom logic.

Here's an excerpt from the plugin which shows how we deal with the P1 selling price:

Code: Select all
destinationPropertyCollection.Add(new JiwaFinancials.Jiwa.JiwaInventory.Import.DestinationProperty("Inventory.P1", "P1 Sell Price",
                           delegate(JiwaFinancials.Jiwa.JiwaInventory.Inventory inventory, string value, string rowData, string[] row, int rowNo, JiwaFinancials.Jiwa.JiwaInventory.Import.Mapping mapping)
                           {
                           inventory.SellingPrices["P1"].Price = Microsoft.VisualBasic.Information.IsNumeric(value) ? Decimal.Parse(value) : inventory.SellingPrices["P1"].Price;
                           },
                           new String[] {"P1", "P1 Price"}));


The delegate in the above excerpt is invoked on import - per row of the source csv. We effectively are creating an anonymous method in which we are given the value from the csv and the inventory business logic as parameters (as well as the entire CSV row for good measure), and inside that method we define the code to execute.

So, with the attached plugin and a source csv file which looks like this:

Code: Select all
Part No, Description, P1, P2
1089-AX, Network System - Custom Specifications, 150.00, 99.89
1089-J,Desktop - Custom Specifications (Advanced), 155.00, 991.89


The inventory import now looks like this (note the new P1 and P2 mappings):

Import sell prices.PNG
Screenshot showing Inventory import


Attached is the plugin.
Attachments
Plugin Import P1...P10 Selling Prices.xml
Sample Plugin
(75.96 KiB) Downloaded 201 times
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

Return to Samples and Examples

Who is online

Users browsing this forum: No registered users and 1 guest

cron