Guest User

Untitled

a guest
May 26th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. const Register = (products, cash, salesTax) => {
  2. this.products = {}, this.cash = cash, this.salesTax = salesTax;
  3. // parse comma separted price list
  4. // attach product name as key in this.products
  5. // value is an object with props
  6. // sku : number,
  7. // price : number,
  8. // taxable: boolean
  9. this.transactionLog = {};
  10. // will contain objects of all previous transactions
  11. // key will be transactionId and value will be log of products
  12. /*
  13. ex:
  14. 163235835: {
  15. date: dateTime,
  16. items: [items]
  17. total: totalPrice
  18. }
  19. */
  20. };
  21.  
  22. Register.prototype.viewBalance = () => {
  23. // Returns total balance in register currently
  24. return this.cash;
  25. };
  26.  
  27. Register.prototype.deductFromRegisterBalance = (cashToBeDeducted) => {
  28. // deduct cashToBeDeducted from this.cash
  29. };
  30.  
  31. Register.prototype.addToRegisterBalance = (cashToBeAdded) => {
  32. // add cashToBeAdded to this.cash
  33. };
  34.  
  35. Register.prototype.addTransaction = (transactionId, transactionLog) => {
  36. this.transactionLog[transactionId] = transactionLog;
  37. // Adds a new, completed transaction to the log
  38. };
  39.  
  40.  
  41. // For every transaction, instantiate a new instance of Transaction.
  42. // When transaction is complete, add to Register
  43. const Transaction = (productId) => {
  44. this.currentTransaction = [];
  45. this.transactionId = Number;
  46. this.transactionTime = Date.now();
  47. this.transactionTotal = 0;
  48. // push new items to currenTransaction
  49. // summing transactionTotal for each item added
  50. // to find item price, lookup itemName in this.products[<product>].price
  51. }
  52.  
  53. Transaction.prototype.showCurrentItem = () => {
  54. // Get last item added to this.currentTransaction
  55. // Get current balance with this.transactionTotal
  56. // Print both values for customer to see
  57. }
  58.  
  59. Transaction.prototype.finishTransaction = (cashSumFromCustomer) => {
  60. const calculateChange = (transactionTotal, cash) => {
  61. // Takes in 2 numbers, total $ of transaction, and cash received from customer
  62. // Deducts transactionTotal from cash
  63. // change is to be given with largest bills first,
  64. // and smalled # of change
  65. return change;
  66. }
  67. // Log total for customer to see
  68. console.log(calculateChange(this.transactionTotal, cashSumFromCustomer));
  69. return calculateChange(this.transactionTotal, cashSumFromCustomer);
  70. }
Add Comment
Please, Sign In to add comment