Introduction
Before starting to build your Supply application there are a few concept you must familiarize yourself with:
In this document:
Loading data from a ledger
Why?
- To read data previously saved into a ledger
Here is the calculate expression:
coalesce(instance('ledger')/ledgerdb/ledger[@entity-id=case_id]/section[@section-id='balance']/entry[@id=current()/../@id], 0)
instance('commcaresession')/session/data/case_id
Let’s break this down:
coalesce([big scary ledger reference], 0)
just says use the leger reference, and if you don’t find a value, use 0.
This is in case it is the first time filling in a form that touches that value.
Looking at the ledger reference
instance('ledger')/ledgerdb/ledger[@entity-id=case_id]/section[@section-id='balance']/entry[@id=current()/../@id]
case_id: put here the id of the case where you want to get your ledger from. For example instance('commcaresession')/session/data/case_id = the current case ID.
So instance('ledger')/ledgerdb/ledger[@entity-id=instance('commcaresession')/session/data/case_id]
Says grab the ledger for this case
/section[@section-id='balance']
Says grab the section called “balance” (this corresponds to the “balance ID”). You could use here 'stock', 'consumption' ...
/entry[@id=current()/../@id]
Says grab the entry value with the ID of the current product
This is pretty scary expression. Feel free to ask for help with it, though it shouldn’t vary too much per form.
Setting up organizations for supply chain
Organizations can be used to do case sharing and therefore allow supply-point cases and ledgers to be shared between users.
Furthermore using organization levels will allow the configuration of different complex use cases:
- stock management workflow
- superviser/supervised
- ...
Tracks Stock: allow the organization to track stock, i.e. define ledgers.
Own Cases: allow the organization to own the case data, i.e. all the cases saved by the user will be owned by the organization:
- all users linked to the same location will be able to see the cases of this organization (same location case-sharing)
- all users linked to a parent location, with the parameter "view child data" activated, will be able to see the cases of this organization (parent child case-sharing)
View Child Data: allow the organization to see the case data of its child organizations
Summing data across all products
This is standard app-builder stuff, and can be done using the sum() function.
Outside the repeat group do a sum of a question inside the repeat group.
For example: sum(/data/products/item/data_product_payment) will sum the values of each product data_product_payment.
PS: the additional hidden word “item” in the path that is inserted due to the model iteration structure.