Advertisement
Marlingaming

Receipt API

Nov 2nd, 2022 (edited)
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. local Printer = peripheral.find("printer")
  2.  
  3. local function CheckPrinter()
  4. local Pass = true
  5. if Printer.getInkLevel() == 0 or Printer.getPaperLevel() == 0 then Pass = false end
  6. return Pass
  7. end
  8.  
  9. local function ReceiptHelp()
  10. term.setBackgroundColor(colors.black)
  11. term.setTextColor(colors.white)
  12. term.clear()
  13. term.setCursorPos(1,1)
  14. print("==Commands==")
  15. print("CheckPrinter : sees if printer is able to print")
  16. print("PrintReceipt : Company,Purchase,Title,Client,Items")
  17. print("==end==")
  18. end
  19.  
  20. local function PrintReceipt(Company,Purchase,Title,Client,Items)
  21. local Sub = 0
  22. for i = 1, #Items do
  23. Sub = Sub + Items[i][3]
  24. end
  25. local Taxes = (Sub*GovEc.GetTax("sales"))
  26. local total = Sub + Taxes
  27. local Layout = {"===Receipt===",Company.." "..Purchase,"Proof of Purchase",os.date(),"to order of "..Client,"-Items-"}
  28. if Client == "n" then Layout[5] = "Certificate" end
  29. for i = 1, #Items do
  30. Layout[#Layout + 1] = Items[i][1].." x"..Items[i][2].." $"..Items[i][3]
  31. end
  32. Layout[#Layout + 1] = "Subtotal : $"..Sub
  33. Layout[#Layout + 1] = "taxes : $"..Taxes
  34. Layout[#Layout + 1] = "total : $"..total
  35. Layout[#Layout + 1] = "==Official=Document=="
  36. Layout[#Layout + 1] = "created with authorization of"
  37. Layout[#Layout + 1] = "the State Government and bank"
  38. Printer.newPage()
  39. Printer.setTitle(Title)
  40. Printer.setCursorPos(1,1)
  41. for i = 1, #Layout do
  42. Printer.setCursorPos(1,i)
  43. Printer.write(Layout[i])
  44. end
  45. Printer.endPage()
  46. end
  47.  
  48. return {ReceiptHelp = ReceiptHelp, PrintReceipt = PrintReceipt, CheckPrinter = CheckPrinter}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement