Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Cashinator {
- //initialize the cash register with a price list in a simple comma-delimited format.
- // The price list contains product names, SKU's (stock-keeping units, i.e., the product id),
- // the price per unit, and whether the product is taxable. (Staple groceries are typically not taxable.)
- // initialize the register with a starting amount of money, a sales tax percentage.
- constructor(pricelist, startingMoney, salesTax){
- this.pricelist = pricelist.parseCSV; //seems like price list is a csvfile, parse csv will turn into an object with SKU as key
- this.balance = startingMoney || 0;
- this.salesTax = salesTax || 0;
- this.transactions = [];
- this.lastTransactionId = 0;
- this.inProgressTransaction;
- }
- showBalance(){
- //display current balance on screen
- }
- // view a report of all the transactions that have occurred since register initialization.
- // Transactions are listed by id, # of items purchased, and the transaction amount.
- showTransactionReport(){
- //for each transaction in transaction array
- //print id, items.length, total
- }
- //search all items purchased since register initialization. I can do a partial string match on product name
- searchRegisterItems(searchString){
- //?? not sure point of this function
- }
- startTransaction(){
- //increment the lastTransactionId
- //create a new Transaction, passing in new id
- //set this transaction to the inProgressTransaction
- }
- scanItem(sku){
- //get the item from the pricelist used skuKey
- //call transaction.addItem to add to array
- //call display.displayCustomer(item, transaction.subtotal) to show the updated running values
- }
- endTransaction(){
- //call transaction.transaction end
- //
- }
- handleCustomerMoney(){
- }
- }
- class Transaction{
- constructor(id){
- this.id = id;
- this.createdAt = Date.now();
- this.items = []
- this.subtotal = 0;
- this.nonTaxableAmount = 0; //we could do a reduce function, but it will be more efficient to just add to values as they are added
- }
- // As a cashier, I can scan one item, whereupon that item is added to the transaction.
- addItem(item){
- //push the item to the items array
- //add item.price to subtotal
- }
- transactionEnd(taxRate){
- //calculate this.total and set it
- //Apply sales tax to (subtotal - nonTaxableAmount)
- //add subtotal+tax to nonTaxableAmount
- }
- printReciept(){
- //for each item in the items array, print details
- //print subtotal and total
- }
- }
- class Display{
- constructor(){
- this.currentDisplay = ''
- }
- displayCustomer(item, subtotal){
- this.currentDisplay = //formatted item and subtotal
- }
- displayFinal(total){
- //show the final total of the transation
- }
- displayCashier(){
- //if the inProgressTransaction is undefined, show the currrent Cashinator balance
- //else, show displayCustomer
- }
- }
Add Comment
Please, Sign In to add comment