Make Order Ready Example

Make Order Ready Example
lac31
Placed orders are often placed in a "Shopping Cart" state (
order.is_ready == false
), where they do not affect Customer balance and Product quantities. Later, the end user might "check out" and make the order ready. This triggers a number of logic functions described on this page.
The following table contrasts the Not Ready and Ready states of an order:
Impact on
Order Not Ready
Order Ready
Customer Balance
No effect. The balance is not adjusted until you check out and make the order ready.
The balance is adjusted by Orders 
amount_un_paid
 .
Product Quantities
No effect. The inventory remains in stock and the reorder is not triggered.
Increase 
total_quantity_ordered
 for each ordered product Compute 
is_reorder_required
 .
In this article:
 
 
Problem
Requirements:
 Adjust Balance and Product Quantities
The following table summarizes Make Ready:
Step
In the example
Notes
Epic
Order Processing
 
User Story
Make Order Ready
 
Behavior
Adjust customer balance when order.is_ready=true
 
Behavior
Adjust product total_qty_ordered when order.is_ready=true
 
 
Set is_reorder_required
iff (onHand - qtyOrdered) < reorderQty
The challenge is that Product is not directly related to Orders, so, while Product wants to sum LineItem quantities, it cannot directly reference the Order 
isReady
 state.
Solution
API Creator solves this transaction by declaring the following logic: CA Technologies  
Since the Customer has a sum:
Derive customers.balance as sum(ordersList.amount_un_paid) where is_ready = true
The Balance is increased due to the qualification condition change (
is_ready
) now being met. You can define the following logic using 
Lineitem.is_ready
. The 
LineItems.isReady Lineitems.is_ready
 formula is a parent reference, so changes are forward chain altered parent references to children to each Lineitem. This formula activates line item logic, where the change to the qualification condition adjusts the 
Product.totalQtyOrdered
 . The line item logic activates product logic, which computes 
products.is_reorder_required
.
For more information:
Context
The following image shows the relevant domain objects. The numbered arrows reflect the logic flow, described in the log and operation.
  CA Technologies.png  
How to Run
  1. In Data Explorer, select the Customers table and the first Customer (Alpha and Sons).
  2. From the Orders tab, select the first order and click 
    Zoom
    .
  3. Set the 
    Is Ready
     to true, and then click 
    Save
    .
  4. Observe this fails with a credit limit check.
  5. Click 
    Undo
    .
  6. Reselect the first customer and increase their Credit Limit to 51, and click 
    Save
    .
  7. Repeat steps 1 and 2.
  8. Observe now succeeds.
  9. Define one or more rules that solve the identified behavior, Check Credit. The logic triggered by each LineItems insertion is summarized as follows:
 
Step
 
 
Object
 
 
Watches
 
 
Reacts by
 
 
Which chains to
 
1 - Adjust Sum
Customer.balance
orders.is_ready, orders.amount_un_paid
Adjusts balance
Validation checkCredit (not shown)
2 - Cascade parent reference
LineItems.Is_ready
orders.is_ready
Computes Is_ready
Orders.amount_un_paid
3 - Adjust sum
Products.total_quantity_ordered
LineItems.Is_ready LineItems.quantity_ordered
Adjusts total_quantity_ordered
Product.is_reorder_required
4 - Formula
Products.is_reorder_required
Products.total_quantity_ordered, Products.on_hand, Products.reorder_quantity
Computes is_reorder_required
For more information about forward chaining and parent adjustment, see Logic Execution.
Observe this processing flow in the log.
Concepts Illustrated
This example illustrates both kinds of multi-table forward chaining:
  • Parent adjustment from Orders to the customer balance.
  • Child cascade from Order 
    is_ready
     to LineItems.
The credit check illustrates the most common business logic pattern: Constraining a derived result. It also illustrates the replicate junction pattern, wherein the Product sum references the Orders 
is_ready
 , by way of the Orders table.
For more information about forward chaining, including constraining chained derivations patterns and the replication junction pattern, see Logic Patterns.