S++Business systems language
DEMO SOURCE · SPP / APP / PHYRead the book

petshop-05-checks.spp

petshop/fulfillment/petshop-05-checks.spp

Download original file · Petstore source contents

1domain petshop;23atomic check checkShipmentAgreementInput(ShipmentAgreement) {4    require(ShipmentAgreement.tracking != null && ShipmentAgreement.tracking != "", "TRACKING_REQUIRED");5}67atomic check checkShipmentEligibility(ShopOrder) {8    require(ShopOrder.status == OrderStatus.PAID, "ORDER_NOT_SHIPPABLE");9}1011atomic check checkDeliveryEligibility(ShopOrder) {12    require(ShopOrder.status == OrderStatus.SHIPPED, "ORDER_NOT_DELIVERABLE");13}1415atomic check checkReservedInventory(ShopOrder, StockLine[]) {16    for (OrderLine line : ShopOrder.lines) {17        boolean found = false;18        for (StockLine stock : StockLine[]) {19            if (stock.goods.sku == line.goods.sku) {20                int needed = 0;21                for (OrderLine ordered : ShopOrder.lines) {22                    if (ordered.goods.sku == line.goods.sku) {23                        needed += ordered.quantity;24                    }25                }26                require(stock.reserved >= needed, "RESERVATION_MISSING");27                found = true;28            }29        }30        require(found, "INVENTORY_ITEM_NOT_FOUND");31    }32}