Advertisement
lego11

PAGAMENTO BOLLETTE V3

May 11th, 2020
1,886
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --pagamento bollette V3 lego11
  2. os.pullEvent = os.pullEventRaw
  3.  
  4. --VARIABILI
  5.  lbl = "BN Credit"
  6.  tabr = {}
  7. m = peripheral.wrap("right") --magcard
  8. printer = peripheral.wrap("back") --stampante
  9. cb = peripheral.wrap("bottom") -- commandblock
  10.  
  11. function clear()
  12. term.clear()
  13. term.setCursorPos(1,1)
  14. end
  15.  
  16. function pinErrato()
  17. clear()
  18. print("Errore di verifica del PIN")
  19. print("")
  20. print("Premere un tasto per uscire")
  21. os.pullEvent("key")
  22. print("")
  23. print("Ritirare il Disco Bolletta Elettronico")
  24. disk.eject("left")
  25. sleep(1)
  26. os.reboot()
  27. end
  28.  
  29.  
  30. function cartaNonValida()
  31. clear()
  32. print("Carta non valida o corrotta.")
  33. print("")
  34. print("Premere un tasto per uscire")
  35. os.pullEvent("key")
  36. print("")
  37. print("Ritirare il Disco Bolletta Elettronico")
  38. disk.eject("left")
  39. sleep(1)
  40. os.reboot()
  41. end
  42.  
  43. function cartaVuota()
  44. clear()
  45. print("Carta smagnetizzata o vuota.")
  46. print("")
  47. print("Premere un tasto per uscire")
  48. os.pullEvent("key")
  49. print("")
  50. print("Ritirare il Disco Bolletta Elettronico")
  51. disk.eject("left")
  52. sleep(1)
  53. os.reboot()
  54. end
  55.  
  56. function preleva()
  57. tabr.t = tabc.t
  58. tabr.e = tabc.e
  59. tabr.p = tabc.p
  60. tabr.v = tostring(credito - prelievo)
  61. ncr = textutils.serialize(tabr)
  62. m.setInsertCardLight(true)
  63. m.beginWrite(ncr,lbl)
  64. os.pullEvent("mag_write_done")
  65. m.setInsertCardLight(false)
  66. end
  67.  
  68. s = peripheral.wrap("back")
  69. m = peripheral.wrap("right")
  70. lbl = "BN Credit"
  71.  
  72. function tocerror()
  73. clear()
  74. print("TOC ERROR")
  75. print("")
  76. print("Disco errato o danneggiato. Controllare il disco e ritentare l'operazione")
  77. print("")
  78. print("Premere un tasto qualsiasi per uscire.")
  79. os.pullEvent("key")
  80. disk.eject("left")
  81. os.reboot()
  82. end
  83.  
  84. clear()
  85. print("eRGB - Sistema Pagamento Bollette")
  86. print("")
  87. print("Inserire il Disco Bolletta Elettronica nel lettore floppy a sinistra")
  88. print("")
  89. print("IMPORTANTE:")
  90. print("NON estrarre il disco manualmente dal lettore!")
  91. print("Verrà riciclato o espulso automaticamente!")
  92. os.pullEvent("disk")
  93. etichetta = disk.getLabel("left")
  94. if string.find(etichetta, "DBE") == nil then
  95. tocerror()
  96. end
  97.  handle = assert(fs.open("disk/be", "r"), "ERRORE: disco non formattato")
  98.  bedisco = handle.readAll()
  99. handle.close()
  100.  tab = textutils.unserialize(bedisco) -- Tabella contenente le variabili
  101.  prelievo = tonumber(tab.totale)
  102.  
  103. clear()
  104. print("Inserire la carta di credito nel lettore a destra")
  105. m.setInsertCardLight(true)
  106. za,rawcarta = os.pullEvent("mag_swipe")
  107. m.setInsertCardLight(false)
  108.  
  109. if rawcarta == nil then
  110. cartaVuota()
  111. end
  112.  
  113. tabc = textutils.unserialize(rawcarta)
  114.  
  115. if type(tabc) ~= "table" then
  116. cartaNonValida()
  117. end
  118.  
  119. if tabc.t ~= "cc" then
  120. cartaNonValida()
  121. end
  122.  
  123. if tabc.e ~= "BN" then
  124. cartaNonValida()
  125. end
  126.  
  127. if tabc.p ~= "0000" then
  128. print("")
  129. print("Inserire il PIN e premere ENTER")
  130. print("")
  131.  pinUtente = read("#")
  132. if pinUtente ~= tabc.p then
  133. pinErrato()
  134. end
  135. end
  136.  
  137. credito = tonumber(tabc.v)
  138.  
  139. clear()
  140.  
  141. while true do
  142. print("La carta ha una disponibilità di "..credito.." IC.")
  143. print("")
  144. print("Bolletta del "..tab.date.." intestata a "..tab.UICnumber.." ")
  145. print("")
  146. print("Totale da pagare: "..prelievo.." IC")
  147. print("")
  148. print("")
  149. print("Per favore scegliere un'opzione utilizzando i tasti numerici e confermare con ENTER:")
  150. print("")
  151. print("[1] Pagare la bolletta SENZA ricevuta")
  152. print("[2] Pagare la bolletta CON ricevuta")
  153. print("[3] Esci senza pagare la bolletta")
  154. num=tonumber(read())
  155. if num == 1 then
  156. if prelievo > credito then
  157. clear()
  158. print("Disponibilità insufficiente")
  159. print("")
  160. print("Bolletta NON PAGATA.")
  161. print("Riprovare con un'altra carta di credito.")
  162. print("")
  163. print("Premere un tasto qualsiasi per uscire")
  164. os.pullEvent("key")
  165. disk.eject("left")
  166. print("Ritirare il Disco Bolletta Elettronica")
  167. sleep(5)
  168. os.reboot()
  169. end
  170. clear()
  171. print("Inserire nuovamente la carta per confermare il prelievo")
  172. preleva()
  173. print("")
  174. print("Attendere, autorizzazione pagamento in corso...")
  175. redstone.setOutput("top", true)
  176. sleep(5)
  177. redstone.setOutput("top", false)
  178. print("")
  179. print("Pagamento effettuato correttamente!")
  180. print("")
  181. print("La bolletta è stata registrata come 'pagata'")
  182.  mailsend = "mail send lego11 Bolletta PAGATA: "
  183. cb.setCommand(mailsend..tab.UICnumber)
  184. cb.runCommand()
  185. print("Grazie e arrivederci!")
  186. print("")
  187. print("Tra poco sarà possibile eseguire un'altra operazione.")
  188. sleep(5)
  189. os.reboot()
  190.  
  191. elseif num == 2 then
  192. if prelievo > credito then
  193. clear()
  194. print("Disponibilità insufficiente")
  195. print("")
  196. print("Bolletta NON PAGATA.")
  197. print("Riprovare con un'altra carta di credito.")
  198. print("")
  199. print("Premere un tasto qualsiasi per uscire")
  200. os.pullEvent("key")
  201. disk.eject("left")
  202. print("Ritirare il Disco Bolletta Elettronica")
  203. sleep(5)
  204. os.reboot()
  205. end
  206. clear()
  207. print("Inserire nuovamente la carta per confermare il prelievo")
  208. preleva()
  209. print("")
  210. print("Attendere, autorizzazione pagamento in corso...")
  211. redstone.setOutput("top", true)
  212. sleep(3)
  213. redstone.setOutput("top", false)
  214. if printer.getPaperLevel() == 0 or printer.getInkLevel() == 0 then
  215.  cartaInceppata = 0
  216. print("")
  217. print("Errore: Carta inceppata")
  218. print("")
  219. print("Impossibile stampare ricevuta. Il pagamento verrà comunque effettuato.")
  220. print("")
  221. else
  222. print("Attendere, stampa in corso della ricevuta...")
  223. printer.newPage()
  224. printer.setPageTitle("Ricevuta eRGB")
  225. printer.write("Ricevuta eRGB")
  226. printer.setCursorPos(1, 2)
  227. printer.setCursorPos(1, 4)
  228. printer.write("La Bolletta del: ")
  229. printer.setCursorPos(1, 6)
  230. printer.write(tab.date)
  231. printer.setCursorPos(1, 8)
  232. printer.write("del cliente: ")
  233. printer.setCursorPos(1, 10)
  234. printer.write(tab.UICnumber)
  235. printer.setCursorPos(1, 12)
  236. printer.write("con un totale di:")
  237. printer.setCursorPos(1, 14)
  238. printer.write(prelievo)
  239. printer.setCursorPos(10,14)
  240. printer.write("IC")
  241. printer.setCursorPos(1, 16)
  242. printer.write("e' stata pagata")
  243. printer.setCursorPos(1, 17)
  244. printer.write("correttamente.")
  245. printer.setCursorPos(1, 19)
  246. printer.write("Grazie per aver scelto")
  247. printer.setCursorPos(1, 20)
  248. printer.write("eRGB!")
  249. printer.endPage()
  250. sleep(2)
  251. print("Stampa: 25%")
  252. sleep(2)
  253. print("Stampa: 50%")
  254. sleep(2)
  255. print("Stampa: 75%")
  256. sleep(2)
  257. print("Stampa: 100%")
  258. sleep(2)
  259. print("")
  260. print("Ritirare la ricevuta")
  261. print("")
  262. end
  263. print("Pagamento effettuato correttamente!")
  264. print("")
  265. print("La bolletta è stata registrata come 'pagata'")
  266.  mailsend = "mail send lego11 Bolletta PAGATA: "
  267. cb.setCommand(mailsend..tab.UICnumber)
  268. if cartaInceppata == 0 then
  269. cb.runCommand()
  270. end
  271. print("Grazie e arrivederci!")
  272. print("")
  273. print("Tra poco sarà possibile eseguire un'altra operazione.")
  274. sleep(5)
  275. os.reboot()
  276. elseif num == 3 then clear() break end
  277. sleep(1)
  278. clear()
  279. end
  280. clear()
  281. print("Uscita comandata dall'utente")
  282. print("")
  283. print("Bolletta NON PAGATA.")
  284. print("")
  285. disk.eject("left")
  286. print("Ritirare il Disco Bolletta Elettronica")
  287. sleep(5)
  288. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement