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 goods;101quantum int balance;102}103104take Goods as StockSupply {105Goods goods = Goods;106}107108Role StockLine {109Goods goods;110quantum int available;111quantum int reserved;112quantum int sold;113}114115take Goods as StockLine {116Goods goods = Goods;117}118119Contract InventoryOpeningAgreement {120Goods[] goods;121StockLine[] inventory;122}123124atomic calculate initializeInventory(Goods[], StockLine[], StockSupply[]) {125StockLine[] = new StockLine[] {126};127StockSupply[] = new StockSupply[] {128};129for (Goods product : Goods[]) {130StockLine stock = new StockLine();131stock.goods = product;132stock.available = 0;133stock.reserved = 0;134stock.sold = 0;135StockLine[] = append(StockLine[], stock);136StockSupply source = new StockSupply();137source.goods = product;138source.balance = 0;139StockSupply[] = append(StockSupply[], source);140}141}142143quantum update reserveInventory(StockLine[], ShopOrder) {144for (StockLine stock : StockLine[]) {145for (OrderLine line : ShopOrder.lines) {146if (stock.goods.sku == line.goods.sku) {147stock.available -= line.quantity;148stock.reserved += line.quantity;149}150}151}152}153154quantum update shipInventory(StockLine[], ShipmentAgreement) {155for (StockLine stock : StockLine[]) {156for (OrderLine line : ShipmentAgreement.order.lines) {157if (stock.goods.sku == line.goods.sku) {158stock.reserved -= line.quantity;159stock.sold += line.quantity;160}161}162}163}164165quantum update releaseUnpaidInventory(StockLine[], UnpaidCancellationAgreement) {166for (StockLine stock : StockLine[]) {167for (OrderLine line : UnpaidCancellationAgreement.order.lines) {168if (stock.goods.sku == line.goods.sku) {169stock.reserved -= line.quantity;170stock.available += line.quantity;171}172}173}174}175176quantum update releasePaidInventory(StockLine[], PaidCancellationAgreement) {177for (StockLine stock : StockLine[]) {178for (OrderLine line : PaidCancellationAgreement.order.lines) {179if (stock.goods.sku == line.goods.sku) {180stock.reserved -= line.quantity;181stock.available += line.quantity;182}183}184}185}186187quantum update returnInventory(StockLine[], ReturnRefundAgreement) {188for (StockLine stock : StockLine[]) {189for (OrderLine line : ReturnRefundAgreement.order.lines) {190if (stock.goods.sku == line.goods.sku) {191stock.sold -= line.quantity;192stock.available += line.quantity;193}194}195}196}197198atomic calculate prepareInventoryOpening(Goods[], StockLine[], InventoryOpeningAgreement) {199InventoryOpeningAgreement.goods = Goods[];200InventoryOpeningAgreement.inventory = StockLine[];201}202203Scenario serial openInventory(Goods[], StockLine[], StockSupply[], InventoryOpeningAgreement) {204initializeInventory;205prepareInventoryOpening;206transaction {207insertStockLine;208insertStockSupply;209}210}211212Reference PetReservationAgreement from petshop.PetReservationAgreement {213Goods goods;214int quantity;215}216217quantum update reserveRequestedInventory(StockLine[], PetReservationAgreement) {218for (StockLine item : StockLine[]) {219if (item.goods.sku == PetReservationAgreement.goods.sku) {220item.available -= PetReservationAgreement.quantity;221item.reserved += PetReservationAgreement.quantity;222}223}224}225226Reference StockReceiptAgreement from petshop.StockReceiptAgreement {227Goods goods;228StockLine stock;229StockSupply source;230int quantity;231}232233quantum update receiveInventory(StockLine, StockSupply, StockReceiptAgreement) {234StockSupply.balance -= StockReceiptAgreement.quantity;235StockLine.available += StockReceiptAgreement.quantity;236}