fact Vendor {
  string vendorName;

  Store* stores {
    Store store : store.vendor = this and not store.isClosed
  }

  money centralAccountBalance {
    sum transfer.amountTransferedToCentralAccount
      Store store : store.vendor = this
      StoreDateOfBusiness storeDateOfBusiness : storeDateOfBusiness.store = store
      Transfer transfer : transfer.storeDateOfBusiness = storeDateOfBusiness
  }
}

fact Store {
  Vendor vendor;
  string storeName;

  bool isClosed {
    exists CloseStore close : close.closedStore = this
  }
}

fact DateOfBusiness {
  date date;
}

fact StoreDateOfBusiness {
  Store store;
  DateOfBusiness dateOfBusiness;

  Purchase* purchases {
    Purchase purchase : purchase.storeDateOfBusiness = this and not purchase.isVoided
  }

  Transaction* transactions {
    Transaction transaction : transaction.storeDateOfBusiness = this and not transaction.isVoided
  }
}

fact Card {
  Vendor vendor;
  string cardNumber;

  money balance {
    sum purchase.purchaseAmount + sum transaction.increaseInValue - sum serviceFee.fee
      Purchase purchase : purchase.card = this and not purchase.isVoided
      Transaction transaction : transaction.initialPurchase = purchase and not transaction.isVoided
      ServiceFee serviceFee : serviceFee.initialPurchase = purchase and not serviceFee.isVoided
  }

  bool hasMultiplePurchases {
    count purchase > 1
      Purchase purchase : purchase.card = this and not purchase.isVoided
  }
}

fact Purchase {
  Card card;
  StoreDateOfBusiness storeDateOfBusiness;
  money purchaseAmount;

  bool isVoided {
    exists VoidPurchase void : void.voidedPurchase = this
  }
}

fact Transaction {
  Purchase initialPurchase;
  StoreDateOfBusiness storeDateOfBusiness;
  money increaseInValue;

  bool isVoided {
    exists VoidTransaction void : void.voidedTransaction = this
  }
}

fact AddValue : Transaction {
}

fact Redeem : Transaction {
}

fact VoidTransaction {
  Transaction voidedTransaction;
}

fact VoidPurchase {
  Purchase voidedPurchase;
}

fact Transfer {
  StoreDateOfBusiness storeDateOfBusiness;
  Purchase* purchases;
  Transaction* transactions;

  money amountTransferredToCentralAccount {
    sum purchase.purchaseAmount + transaction.increaseInValue
      Purchase purchase in purchases
      Transaction transaction in transactions
  }
}

fact ServiceFee {
  Purchase initialPurchase;
  money fee;

  bool isVoided {
    exists VoidServiceFee void : void.voidedServiceFee = this
  }
}

fact VoidServiceFee {
  ServiceFee voidedServiceFee;
}

fact CloseStore {
  Store closedStore;
}

Last edited May 19, 2009 at 4:06 PM by MichaelLPerry1971, version 4

Comments

No comments yet.