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

petshop-05-checks.spp

petshop/order/petshop-05-checks.spp

Download original file · Petstore source contents

1domain petshop;23atomic check checkQuotationInput(Cart, Goods[]) {4    require(Cart.lines != null, "EMPTY_CART");5    int count = 0;6    for (CartLine line : Cart.lines) {7        require(line != null && line.quantity != null && line.quantity > 0, "INVALID_QUANTITY");8        boolean found = false;9        for (Goods product : Goods[]) {10            if (product.sku == line.goods.sku) {11                found = true;12            }13        }14        require(found, "PRODUCT_UNAVAILABLE");15        count++;16    }17    require(count > 0, "EMPTY_CART");18}1920atomic check checkUnpaidCancellationAgreementInput(UnpaidCancellationAgreement) {21    require(22        UnpaidCancellationAgreement.reason != null && UnpaidCancellationAgreement.reason != "",23        "REASON_REQUIRED"24    );25}2627atomic check checkUnpaidCancellation(ShopOrder) {28    require(ShopOrder.status == OrderStatus.UNPAID, "ORDER_NOT_CANCELLABLE");29}3031atomic check checkPaidCancellationAgreementInput(PaidCancellationAgreement) {32    require(33        PaidCancellationAgreement.reason != null && PaidCancellationAgreement.reason != "",34        "REASON_REQUIRED"35    );36}3738atomic check checkPaidCancellation(ShopOrder) {39    require(ShopOrder.status == OrderStatus.PAID, "ORDER_NOT_CANCELLABLE");40}4142atomic check checkOrderReservation(ShopOrder, StockLine[]) {43    for (OrderLine line : ShopOrder.lines) {44        boolean found = false;45        for (StockLine stock : StockLine[]) {46            if (stock.goods.sku == line.goods.sku) {47                int needed = 0;48                for (OrderLine ordered : ShopOrder.lines) {49                    if (ordered.goods.sku == line.goods.sku) {50                        needed += ordered.quantity;51                    }52                }53                require(stock.available >= needed, "INSUFFICIENT_STOCK");54                found = true;55            }56        }57        require(found, "INVENTORY_ITEM_NOT_FOUND");58    }59}