Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[Shop Receipt API
- Sylvyrfysh - All Rights Reserved
- Unauthorized copying, and/or redistribution of this file, via any medium without express written permission of Sylvyrfysh (Nicholas Johnson) is strictly prohibited
- Proprietary and confidential
- Written by Nicholas Johnson <johnnic431@gmail.com>, June 24 2015
- ]]
- --[[ ex.
- ----Milianlou's Shop----
- Item Price
- Item1 f25
- Item2 f30
- Total f55
- Created at Day 6 12:55
- --Thanks for shopping!--
- ]]
- local printer=peripheral.wrap("left")
- local line=4;
- local function checkEnd(line)
- if line==25 then
- printer.endPage()
- line=1;
- if not printer.newPage() then return false; end
- printer.setPageTitle("Receipt")
- end
- end
- local function writeLeft(str,line)
- checkEnd(line)
- printer.setCursorPos(1,line)
- printer.write(str)
- end
- local function writeRight(str,line)
- checkEnd(line)
- printer.setCursorPos(26-#str,tonumber(line) or line)
- printer.write(str)
- end
- function printReceipt(cart)
- if not printer.newPage() then return false; end
- printer.setPageTitle("Receipt")
- printer.setCursorPos(1,1)
- printer.write("----Milianlou's Shop----")
- printer.setCursorPos(1,3)
- printer.write("Item Price")
- local tPrice=0;
- for t,y in pairs(cart) do
- writeLeft(y["itemName"],line)
- price="f"..y["price"]
- writeRight(price,line)
- line=line+1;
- tPrice=tPrice+y["price"]
- end
- line=line+1;
- writeLeft("Total",line)
- writeRight("f"..tPrice,line)
- line=line+1
- writeLeft("Created at Day "..os.day().." "..os.time(),line)
- printer.endPage()
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement