Docs‎ > ‎Reactive Logic Tutorial‎ > ‎

Make Ready

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 here.

Let's contrast the not ready and ready states of an order:

 Impact on Order Not Ready Order Ready
 Customer Balance No effect - balance not adjusted until you check out and make the order ready

 Balance adjusted by Orders amount_un_paid
 Product Quantities

No effect - inventory remains in stock, reorder not triggered

 Increase total_quantity_ordered for each ordered product
 Compute is_reorder_required


Requirements: Adjust Balance and Product Quantities

We can summarize Make Ready as follows:

 Step In the example Notes
 Epic Order Processing 
 User Story Make Order Ready 
 BehaviorAdjust 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.


We solve this transaction by declaring the following logic:

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.

We introduce Lineitem.is_ready, enabling us to define the following logic:

Implementation Notes:

  1. The LineItems.isReady Lineitems.is_ready Formula is a Parent Reference, so changes are Forward Chain altered Parent References to Children to each Lineitem
  2. That activates Lineitem logic, where the change to the Qualification Condition adjusts the Product.totalQtyOrdered
  3. That activates Product Logic, which computes products.is_reorder_required


The relevant Domain Objects are shown below. The numbered arrows reflect the logic flow, described in the log and Operation.

How to Run

Using the Rest lab:
  1. Select the Customers table, and the first Customer (Alpha and Sons)
  2. From the Orders tab, select the first order and press Zoom
  3. Set the "Is Ready" field to true, and click Save.
    Observe this fails with a credit limit check.
  4. Click Undo
  5. Reselect the first customer
  6. Increase their Credit Limit to 51, and save
  7. Repeat steps 2 and 3.
    Observe now succeeds.


Next, you 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.balanceorders.is_ready,
 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
 adjusts total_quantity_ordered   Product.is_reorder_required
 4 Formula Products.is_reorder_required  Products.total_quantity_ordered,
 computes is_reorder_required  


You can observe this processing flow in the log.

Click the thumbnail to enlarge the image.

Concepts Illustrated

This example illustrates both kinds of multi-table Forward Chaining:
  1. Parent Adjustment - from Orders to the customer balance
  2. 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, via the Orders table 

Michael Holleran,
Feb 16, 2016, 3:28 PM
Kahuna Sample Diagram.png
Michael Holleran,
Feb 16, 2016, 3:28 PM
Michael Holleran,
Feb 16, 2016, 3:28 PM
Sample Logic.png
Michael Holleran,
Feb 16, 2016, 3:28 PM
Screen Shot 2013-05-07 at 5.34.15 PM | May 7, 2013.png
Michael Holleran,
Feb 16, 2016, 3:28 PM
Screen Shot 2016-02-04 at 4.39.47 PM.png
Michael Holleran,
Feb 16, 2016, 3:28 PM