inventory.spp
inventory/inventory.spp
Download original file · Petstore source contents
1domain inventory;23Reference Goods from petshop.Goods {4business("Goods number used for selection, inventory and settled order lines") String sku;5String category;6String name;7String description;8BigDecimal(19, 2) price;9boolean active;10}1112Reference Buyer from petshop.Buyer {13business("Membership account number used to identify the buyer and verify order ownership") String membershipNumber;14business("Registration number of the linked customer-domain subject") String customerNumber;15String name;16String email;17String address;18MemberTier tier;19BigDecimal(19, 2) wallet;20}2122Reference Merchant from petshop.Merchant {23String customerNumber;24String name;25String email;26String address;27String tradingName;28String shopName;29BigDecimal(19, 2) cash;30}3132Reference OrderLine from petshop.OrderLine {33String lineNumber;34Goods goods;35String name;36int quantity;37BigDecimal(19, 2) unitPrice;38BigDecimal(19, 2) amount;39}4041Reference ShopOrder from petshop.ShopOrder {42business("Order reference presented to the buyer") String orderNumber;43Buyer buyer;44OrderStatus status;45OrderLine[] lines;46int reservedQuantity;47BigDecimal(19, 2) subtotal;48BigDecimal(19, 2) discount;49BigDecimal(19, 2) shipping;50BigDecimal(19, 2) total;51String address;52String tracking;53String reason;54}5556Reference Receipt from petshop.Receipt {57business("Business receipt number") String receiptNumber;58Buyer buyer;59ShopOrder order;60ReceiptStatus status;61OrderStatus orderStatus;62}6364Reference ShipmentAgreement from petshop.ShipmentAgreement {65Buyer buyer;66ShopOrder order;67String tracking;68Receipt receipt;69int shippedQuantity;70}7172Reference UnpaidCancellationAgreement from petshop.UnpaidCancellationAgreement {73Buyer buyer;74ShopOrder order;75String reason;76Receipt receipt;77int releasedQuantity;78}7980Reference PaidCancellationAgreement from petshop.PaidCancellationAgreement {81Buyer buyer;82Merchant seller;83ShopOrder order;84String reason;85Receipt receipt;86int releasedQuantity;87BigDecimal(19, 2) refundAmount;88}8990Reference ReturnRefundAgreement from petshop.ReturnRefundAgreement {91Buyer buyer;92Merchant seller;93ShopOrder order;94Receipt receipt;95int returnedQuantity;96BigDecimal(19, 2) refundAmount;97}9899Role StockSupply {100Goods;101quantum int balance;102}103104Role StockLine {105Goods;106quantum int available;107quantum int reserved;108quantum int sold;109}110111Contract InventoryOpeningAgreement {112Goods[] goods;113StockLine[] inventory;114}115116atomic calculate initializeInventory(Goods[], StockLine[], StockSupply[]) {117stockLines = new StockLine[] {118};119stockSupplys = new StockSupply[] {120};121for (Goods product : goodss) {122StockLine stock = new StockLine();123stock.goods = product;124125stockLines = append(stockLines, stock);126StockSupply source = new StockSupply();127source.goods = product;128129stockSupplys = append(stockSupplys, source);130}131}132133quantum update reserveInventory(StockLine[], ShopOrder) {134for (StockLine stock : stockLines) {135for (OrderLine line : shopOrder.lines) {136if (stock.goods.sku == line.goods.sku) {137stock.available -> stock.reserved : line.quantity;138}139}140}141}142143quantum update shipInventory(StockLine[], ShipmentAgreement) {144for (StockLine stock : stockLines) {145for (OrderLine line : shipmentAgreement.order.lines) {146if (stock.goods.sku == line.goods.sku) {147stock.reserved -> stock.sold : line.quantity;148}149}150}151}152153quantum update releaseUnpaidInventory(StockLine[], UnpaidCancellationAgreement) {154for (StockLine stock : stockLines) {155for (OrderLine line : unpaidCancellationAgreement.order.lines) {156if (stock.goods.sku == line.goods.sku) {157stock.reserved -> stock.available : line.quantity;158}159}160}161}162163quantum update releasePaidInventory(StockLine[], PaidCancellationAgreement) {164for (StockLine stock : stockLines) {165for (OrderLine line : paidCancellationAgreement.order.lines) {166if (stock.goods.sku == line.goods.sku) {167stock.reserved -> stock.available : line.quantity;168}169}170}171}172173quantum update returnInventory(StockLine[], ReturnRefundAgreement) {174for (StockLine stock : stockLines) {175for (OrderLine line : returnRefundAgreement.order.lines) {176if (stock.goods.sku == line.goods.sku) {177stock.sold -> stock.available : line.quantity;178}179}180}181}182183atomic calculate prepareInventoryOpening(Goods[], StockLine[], InventoryOpeningAgreement) {184inventoryOpeningAgreement.goods = goodss;185inventoryOpeningAgreement.inventory = stockLines;186}187188Scenario serial openInventory(Goods[], StockLine[], StockSupply[], InventoryOpeningAgreement) {189initializeInventory;190prepareInventoryOpening;191transaction {192insertStockLine;193insertStockSupply;194}195}196197Reference PetReservationAgreement from petshop.PetReservationAgreement {198Goods goods;199int quantity;200}201202quantum update reserveRequestedInventory(StockLine[], PetReservationAgreement) {203for (StockLine item : stockLines) {204if (item.goods.sku == petReservationAgreement.goods.sku) {205item.available -> item.reserved : petReservationAgreement.quantity;206}207}208}209210Reference StockReceiptAgreement from petshop.StockReceiptAgreement {211Goods goods;212StockLine stock;213StockSupply source;214int quantity;215}216217quantum update receiveInventory(StockLine, StockSupply, StockReceiptAgreement) {218stockSupply.balance -> stockLine.available : stockReceiptAgreement.quantity;219}