Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Register = (products, cash, salesTax) => {
- this.products = {}, this.cash = cash, this.salesTax = salesTax;
- // parse comma separted price list
- // attach product name as key in this.products
- // value is an object with props
- // sku : number,
- // price : number,
- // taxable: boolean
- this.transactionLog = {};
- // will contain objects of all previous transactions
- // key will be transactionId and value will be log of products
- /*
- ex:
- 163235835: {
- date: dateTime,
- items: [items]
- total: totalPrice
- }
- */
- };
- Register.prototype.viewBalance = () => {
- // Returns total balance in register currently
- return this.cash;
- };
- Register.prototype.deductFromRegisterBalance = (cashToBeDeducted) => {
- // deduct cashToBeDeducted from this.cash
- };
- Register.prototype.addToRegisterBalance = (cashToBeAdded) => {
- // add cashToBeAdded to this.cash
- };
- Register.prototype.addTransaction = (transactionId, transactionLog) => {
- this.transactionLog[transactionId] = transactionLog;
- // Adds a new, completed transaction to the log
- };
- // For every transaction, instantiate a new instance of Transaction.
- // When transaction is complete, add to Register
- const Transaction = (productId) => {
- this.currentTransaction = [];
- this.transactionId = Number;
- this.transactionTime = Date.now();
- this.transactionTotal = 0;
- // push new items to currenTransaction
- // summing transactionTotal for each item added
- // to find item price, lookup itemName in this.products[<product>].price
- }
- Transaction.prototype.showCurrentItem = () => {
- // Get last item added to this.currentTransaction
- // Get current balance with this.transactionTotal
- // Print both values for customer to see
- }
- Transaction.prototype.finishTransaction = (cashSumFromCustomer) => {
- const calculateChange = (transactionTotal, cash) => {
- // Takes in 2 numbers, total $ of transaction, and cash received from customer
- // Deducts transactionTotal from cash
- // change is to be given with largest bills first,
- // and smalled # of change
- return change;
- }
- // Log total for customer to see
- console.log(calculateChange(this.transactionTotal, cashSumFromCustomer));
- return calculateChange(this.transactionTotal, cashSumFromCustomer);
- }
Add Comment
Please, Sign In to add comment