Advertisement
Guest User

cash

a guest
Mar 8th, 2014
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.71 KB | None | 0 0
  1. local maxX = 25
  2. local maxY = 21
  3. local total = 0
  4. local storeName = "Classic's General Store"
  5. local CashierID = {"00000"}
  6. local CashierName = {"ClassicRockFan"}
  7. local i = #CashierID
  8. local cashierName = " "
  9. local restart = true
  10. local valid = nil
  11. local p = peripheral.wrap("printer_1")
  12. local m = peripheral.wrap("monitor_0")
  13. local inventoryItems = {"blah1", "blah2"}
  14. local inventoryPrice = {5, 10}
  15. local inventory = textutils.serialize(inventoryItems)
  16. local printInv = true
  17. function login()
  18. while valid == nil do
  19.   if restart == true then
  20.    term.clear()
  21.    term.setCursorPos(1,1)
  22.   end
  23.  term.write("Enter your cashier ID: ")
  24.  inputID = read()
  25.  print("Validating ID...")
  26.  sleep(1)
  27.  for i = 1, i do
  28.    if inputID == CashierID[i] then
  29.      cashierName = CashierName[i]
  30.      valid = true
  31.    else
  32.      valid = nil
  33.    end
  34.  end
  35.  if valid == true then
  36.    register()
  37.  else
  38.    print("Invalid ID")
  39.    sleep(2)
  40.    restart = true
  41.  end
  42. end
  43. end
  44.  
  45. function PrintCenter(msg)
  46.  msgLen = string.len(msg)
  47.  screenWidth,_=p.getPageSize()
  48.  xCoords = tonumber(math.ceil((screenWidth/2) - (msgLen/2)))
  49.  _,termY = p.getCursorPos()
  50.  p.setCursorPos(xCoords, termY)
  51.  p.write(msg)
  52. end
  53. function register()
  54.   term.clear()
  55.   term.setCursorPos(1,1)
  56.   print(storeName.."Computer.  Cashier: "..cashierName)
  57.   term.setCursorPos(1,3)
  58.   print("[1]  Print Recepit")
  59.   print("[2]  Do Inventory")
  60.   print("[3]  Logout")
  61.   term.setCursorPos(1,7)
  62.   term.write("What would you like to do: ")
  63.   action = read()
  64.   if action == "1" then
  65.    p.newPage()
  66.    p.setPageTitle(storeName.." Receipt")
  67.    p.setCursorPos(1,maxY-1)
  68.    PrintCenter("Your Cashier was "..cashierName)
  69.    p.setCursorPos(1,maxY)
  70.    PrintCenter("Thank You!")
  71.    while true do
  72.    if printInv == true then
  73.     p.setCursorPos(1,1)
  74.     print(inventory)
  75.     printInv = false
  76.    elseif printInv == false then
  77.     print("Enter the Inventory Number of the purchased Items")
  78.     term.write("(Leave blank to print): ")
  79.     purchased = read()
  80.     if #purchased == 0 then
  81.       printInv = done
  82.     else
  83.      purchased = tonumber(purchased)
  84.      term.write("Enter how many were purchased: ")
  85.      numPurchased = read()
  86.      numBought = tonumber(numpurchased)
  87.      if numBought == nil then
  88.        print("Invalid Entry")
  89.        printInv = true
  90.      else
  91.       price = inventoryPrice[purchased]
  92.       itemTotal = price*numBought
  93.       total = total+itemTotal
  94.       m.clear()
  95.       m.print(total)  
  96.       printInv = true
  97.     end
  98.    end
  99.    elseif printInv == done then
  100.      p.endPage()
  101.    end
  102.   end  
  103.   elseif action == "2" then
  104.      print("test2")
  105.   elseif action == "3" then
  106.       print("test3")
  107.   else
  108.     print("Invalid Input")
  109.   end
  110. end
  111.  
  112. --login()
  113. register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement