In this article we will build on top of Lesson 1 the Products, with the folowing two perspectives:
Adding the ability keep track of purchases for the products defined in the Lesson 1 the Products.
Adding support for catalogs and tab editors.
Solving the business problem requires a few new entities. First we need to be able to register purchases, each purchase will have at least a supplier, a date, a number and a list of products with quantities.
A purchase can be either a purchase order or an purchase invoice. Here is an example of how the actual business document may look like:
Looking at the document we determine the we need the following entities:
Now, the ER diagram shoud look like this:
Notice that we start adding relationships between entities.
We will create the following entities:
Click the Develop app, and then click on the Customization sets menu.
In the page that opens, click the Add button located above the list.
In the page that opens, under the Edit section, fill in the Name of the customization set (e.g., purchase_invoices). Configure the properties using the same technique described in Lesson 1: The Products.
Select the Relationships tab, click the Add button for each relationship, and fill in the Relationship name, Entity name, Type name, and Foreign entity name:
| Relationship name | Entity name | Type name | Foreign entity name |
|---|---|---|---|
| purchase_invoice_supplier | purchase_invoice | n:1 | supplier |
| purchase_invoice_purchase_invoice_item | purchase_invoice | p:c | purchase_invoice_item |
| purchase_invoice_item_product | purchase_invoice_item | n:1 | product |
Publish the entities the same way as described in Lesson 1 the Products.
The search view and edit view for the supplier entity should be created in the same way as described for the product entity in Lesson 1 the Products and naming it "supplierSearch" and ".supplierEditor".
For the purchase_invoice entity the views will be a bit different because they include catalogs and a parent-child relationship.
In Kodall entities in the parent-child relationships are handled in the same life-cycle as the parent.
Catalogs are the logical user interface unit that facilitate working with related entities. In search views catalogs are used as filters based on related entities (e.g., searching for products in a given product category) and in edit views are used as inputs helping the user select the related entity using a display name rather than its key (e.g., selecting the supplier for a invoice by name).
In this example we will build two catalogs:
Click the Develop app, and then click on the Catalog menu.
In page that opens click the Add button located above the list.
In the page that opens, under the Catalog section, fill the Name of the catalog, in this case "supplierList".
Select the Fetch tab, and enter the folowing fetch query:
FETCH supplier (key, name AS value)
Click the Execute button, located above, to test the query. The result should appear under the query and should contain only the column names and a empty result set.
Click the Save button.
Follow the same steps as in the previous example only changing the name to "productList" and the fetch query to:
FETCH product (key, name AS value)
Click the Develop app, and then click on the Search views menu.
Click the Add button located above the list.
In page that opens, under the Search section, fill the following fields with:
Select the Filters tab, click the Add button for each row, and enter the following:
| Title | Argument name | Input type | Catalog | Operator | Property name |
|---|---|---|---|---|---|
| Supplier | supplier_key | FixedList | supplierList | IsEqual | key |
| Number | invoice_number | String | Contains | number | |
| Date (from) | invoice_date_from | Date | IsGreaterOrEqual | date | |
| Date (to) | invoice_date_to | Date | IsLessOrEqual | date |
Notice the Catalog column. It is used for inputs of type FixedList and DynamicList. In this example we are using the supplierList catalog defined earlier.
Select the Fetch tab, and enter the folowing fetch query:
FETCH purchase_invoice (key GROUP BY, number, date) {
supplier TO id_supplier (name AS supplierName GROUP BY) FILTER AND (${supplier_key}),
purchase_invoice_item TO id_purchase_invoice (SUM(amount) AS invoice_amount)
}
FILTER AND (${invoice_number},${invoice_date_from},${invoice_date_to})
Click the Execute button, located above, to test the query. The result should appear under the query and should contain only the column names and a empty result set.
Select the Columns tab, click the Add button for each row, and enter the folowing:
| Display name | Column name | View type |
|---|---|---|
| Invoice number | number | String |
| Supplier name | supplierName | String |
| Invoice date | date | Date |
| Amount | invoice_amount | Decimal |
Click the Save button.
Click the Develop app, and then click on the Edit views menu.
Click the Add button located above the list.
In the page that opens, under the Editor section, fill the following fields with:
For this entity we will create an edit view with tabs. Each tab has its own elements (inputs).
Select the Tabs tab, click the Add button, fill Title = Invoice, and click the navigate arrow next to the Input tab field.
Under the Tab section, fill the following fields with:
Click the Add button for each row, and enter the folowing:
| Title | Property name | Navigate edit view | Column index | Is separator | Input type | Catalog |
|---|---|---|---|---|---|---|
| Purchase invoice | 0 | Yes | ||||
| Supplier | id_supplier | 0 | No | FixedList | supplierList | |
| Number | number | 0 | No | String | ||
| Date | date | 0 | No | Date | ||
| Terms | terms | 0 | No | LargeText |
Click the Save button and then the Close button.
Select the Tabs tab, click the Add button, fill:
and click the navigate arrow next to the Input tab field.
Under the Tab section, fill the following fields with:
Click the Add button for each row, and enter the folowing:
| Title | Property name | Navigate edit view | Input type | Catalog | Read only |
|---|---|---|---|---|---|
| Product | id_product | .productEditor | FixedList | productList | No |
| Unit price | unit_price | Decimal | No | ||
| Quantity | quantity | Decimal | No | ||
| Amount | amount | Decimal | Yes |
Click the Save button to save the edit view tab.
Click the Save button to save the edit view.
Click the Develop app, and then click on the Search views menu.
In page that opens locate the search view with the title "Purchase invoices" and name "purchaseInvoiceSearch", check it in the and click the Edit button located above the list.
In the page that opens, under the Edit section, fill the following fields with:
Click the Save button.
Click the Develop app, and then click on the Menus menu.
In page that opens locate the menu with the name "Inventory", check it in the and click the Edit button located above the list.
Click the Add button located above the list and enter the following:
| Name | Node item key |
|---|---|
| Suppliers | #search\$supplierSearch |
| Purchase invoices | #search\$purchaseInvoiceSearch |
Click the Save button.
Now you should be able to track of your purchases, suppliers and products.