Placed Orders are typically placed in a "Shopping Cart" state (order.is_ready == false), where they do not affect Customer balance and Product quantities until a subsequent Make Order Ready transaction is executed.  So, we need to devise logic that, when an Order is "made ready" (PUT a purchase order, setting order.is_ready == true)...

  1. increases the customer balances and 
     
  2. adjusts Product quantities, and if reorderQuantity is exceeded, set reorderRequired

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.

Similarly, we don't want to reduce Product inventory, and set reorder flags, until Purchaseorders are marked as ready. So, we need to define logic to make this happen.

This is a bit more challenging, since the Product is not directly related to Orders, so that the qualification condition cannot reference orders.is_ready.  So, 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 Sums' Qualification Condition adjusts the Product.totalQtyOrdered
  3. That activates Product Logic, which computes products.is_reorder_required