Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local button1 = "Nuova Fattura"
- local button2 = "Riepilogo Fatture"
- local button3 = "Stampa fattura"
- local button4 = "Inserisci da capo"
- local button5 = "Annulla operazione"
- local button6 = "Home"
- local button7 = "Cancella storico"
- local button8 = "<--"
- local button9 = "-->"
- local button10 = "Annulla"
- local button11 = "Conferma"
- local x, y = 15,8
- local x1, y1 = 15, 12
- local x2, y2 = 1,14
- local x3, y3 = 1,16
- local x4, y4 = 1,18
- local x5, y5 = 1,19
- local x6, y6 = 10,19
- local x7, y7 = 35,19
- local x8, y8 = 47,19
- local x9, y9 = 15,10
- local x10, y10 = 30,10
- local array = {}
- local printer = peripheral.wrap("right")
- --menu functions
- function menu()
- drawMenu()
- --check if .Index file exist
- if fs.exists(".Index")==false then
- setData(0,".Index")
- end
- --check if .Storico file exist
- if fs.exists(".Storico")==false then
- count = #array
- for i=0, count do array[i]=nil end
- array[0]="0"
- setData(array,".Storico")
- end
- while true do
- local event, button, cx, cy = os.pullEvent()
- if event == "mouse_click" then
- if cx>=x-3 and cx <= (x+button2:len()+3) and ((cy==y-1) or (cy==y) or (cy==y+1)) then newBill()
- else if cx>=x1-3 and cx<= (x1+button2:len()+3) and ((cy==y1-1) or (cy==y1) or (cy==y1+1)) and button==1 then showBillList(1) end
- end
- end
- sleep(0.05)
- end
- end
- --draw the menu of the program
- function drawMenu()
- term.clear()
- term.setTextColor(colors.lightBlue)
- --blue box for button
- paintutils.drawLine(x-3, y-1, ((x+button2:len())+3), y-1, colors.blue)
- paintutils.drawLine(x-3, y, ((x+button2:len())+3), y, colors.blue)
- paintutils.drawLine(x-3, y+1, ((x+button2:len())+3), y+1, colors.blue)
- term.setCursorPos(x,y)
- term.write(button1)
- --blue box for button
- paintutils.drawLine(x1-3, y1-1, ((x1+button2:len())+3), y1-1, colors.blue)
- paintutils.drawLine(x1-3, y1, ((x1+button2:len())+3), y1, colors.blue)
- paintutils.drawLine(x1-3, y1+1, ((x1+button2:len())+3), y1+1, colors.blue)
- term.setCursorPos(x1,y1)
- term.write(button2)
- term.setBackgroundColor(colors.black)
- end
- --bill list functions
- --clear the bill list(y/n buttons)
- function clearList()
- term.clear()
- term.setTextColor(colors.lightBlue)
- term.setCursorPos(5,8)
- term.write("Cancellare tutto lo storico delle fatture??")
- term.setBackgroundColor(colors.blue)
- term.setCursorPos(x9,y9)
- term.write(button10)
- term.setCursorPos(x10,y10)
- term.write(button11)
- term.setBackgroundColor(colors.black)
- while true do
- local event, button, cx, cy = os.pullEvent()
- if event == "mouse_click" then
- if cx>=x9 and cx <= (x9+button10:len()) and cy == y9 then menu() end
- if cx>=x10 and cx <= (x10+button11:len()) and cy == y10 then
- fs.delete(".Index")
- fs.delete(".Storico")
- term.clear()
- term.setCursorPos(10,10)
- term.write("Cancellazione in corso attendere...")
- sleep(1)
- menu()
- end
- end
- end
- end
- --draw the buttons for the bill list page
- function drawBillListPage(page)
- term.setTextColor(colors.lightBlue)
- paintutils.drawLine(0, y5, 60, y5, colors.blue)
- term.setCursorPos(x5,y5)
- term.write(button6)
- term.setCursorPos(x6,y6)
- term.write(button7)
- term.setCursorPos(x7,y7)
- term.write(button8)
- tmp = page*6
- if page~=1 then term.write(" "..(tmp-5).."-"..tmp)
- else term.write(" "..(page).."-"..tmp) end
- term.setCursorPos(x8,y8)
- term.write(button9)
- term.setBackgroundColor(colors.black)
- end
- --print bill(max 6 for page)
- function showBillList(page)
- term.clear()
- array = getData(".Storico")
- i = page*12
- k = (((page-1)*12)+1)
- f = 0
- row = 1
- for k=k,i,1 do
- term.setCursorPos(1,row)
- term.write(array[k])
- row = row+1
- f = f+1
- if f==2 then
- row = row+1
- f=0
- end
- end
- drawBillListPage(page)
- while true do
- local event, button, cx, cy = os.pullEvent()
- if event == "mouse_click" then
- if cx>=x5 and cx <= (x5+button6:len()) and cy == y5 then menu()
- else if cx>=x6 and cx <= (x6+button7:len()) and cy == y6 then
- clearList()
- else if cx>=x7 and cx <= (x7+button8:len()) and cy == y7 then
- if page-1>0 then
- showBillList(page-1)
- end
- else if cx>=x8 and cx <= (x8+button8:len()) and cy == y8 then
- if (page*12)<#array then
- showBillList(page+1)
- end
- end
- end
- end
- sleep(0.05)
- end
- end
- end
- end
- --add a new bill to the bill array and update the bill list file
- function addToIndex(bill)
- i = getData(".Index")
- array = getData(".Storico")
- i = i+1
- array[i] = bill
- setData(array,".storico")
- setData(i,".Index")
- end
- --set a data on a file
- function setData(data,name)
- local file = fs.open(name,"w")
- file.write(textutils.serialize(data))
- file.close()
- end
- --get data from a file
- function getData(name)
- local file = fs.open(name,"r")
- local data = file.readAll()
- file.close()
- return textutils.unserialize(data)
- end
- --new bill functions
- --get parameter of new bill
- function newBill()
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.lightBlue)
- term.write("Inserire il nome del destinatario: ")
- term.setCursorPos(1,2)
- dest = read()
- term.setCursorPos(1,4)
- term.write("Inserire il nome del prodotto: ")
- term.setCursorPos(1,5)
- prod = read()
- term.setCursorPos(1,7)
- term.write("Inserire la quantita del prodotto: ")
- tmpbool = false
- t = 0
- while tmpbool==false do
- term.setCursorPos(1,8)
- term.clearLine()
- if(t ~= 0) then
- term.write("Deve essere un numero")
- sleep(0.5)
- term.clearLine()
- term.setCursorPos(1,8)
- end
- t=t+1
- qta = tonumber(read())
- if qta~=nil then tmpbool=true end
- end
- term.setCursorPos(1,10)
- term.write("Inserire il prezzo al pezzo del prodotto: ")
- tmpbool = false
- t = 0
- while tmpbool==false do
- term.setCursorPos(1,11)
- term.clearLine()
- if(t ~= 0) then
- term.write("Deve essere un numero")
- sleep(0.5)
- term.clearLine()
- term.setCursorPos(1,11)
- end
- t=t+1
- pPz = tonumber(read())
- if pPz~=nil then tmpbool=true end
- end
- tot = qta*pPz
- billPreview()
- end
- --show a preview before print(with options buttons)
- function billPreview()
- term.clear()
- term.setCursorPos(10,1)
- term.write("Anteprima Fattura")
- term.setCursorPos(1,2)
- term.write("Destinatario: ")
- term.setCursorPos(1,3)
- term.write(dest)
- term.setCursorPos(1,4)
- term.write("Prodotto: ")
- term.setCursorPos(1,5)
- term.write(prod)
- term.setCursorPos(1,6)
- term.write("Quantita: ")
- term.setCursorPos(1,7)
- term.write(qta)
- term.setCursorPos(1,8)
- term.write("Prezzo al pz: ")
- term.setCursorPos(1,9)
- term.write(pPz)
- term.setCursorPos(1,10)
- term.write("---------------------------------------------------")
- term.setCursorPos(1,11)
- term.write("Totale: ")
- term.setCursorPos(1,12)
- term.write(tot)
- term.setCursorPos(1,13)
- term.write("---------------------------------------------------")
- drawbutton()
- while true do
- local event, button, cx, cy = os.pullEvent()
- if event == "mouse_click" then
- --print and add the bill to the list
- if cx>=x2 and cx <= button2:len() and cy == y2 then
- prodt = string.sub(prod,0,15)
- tmp = "dest:"..dest
- addToIndex(tmp)
- tmp ="Prod:"..prodt.." qta:"..qta.." tot:"..tot
- addToIndex(tmp)
- print()
- --restart a new bill
- else if cx>=x3 and cx<= (x3+button3:len()) and cy == y3 and button==1 then newBill()
- --return to menu without print
- else if cx>=x4 and cx<= (x4+button4:len()) and cy == y4 and button==1 then menu() end
- end
- end
- sleep(0.05)
- end
- end
- end
- --print functions
- function print()
- --check if ink level is ok
- while printer.getInkLevel() == 0 do
- term.clear()
- term.setCursorPos(1,1)
- term.write("Errore! Inserire l'inchiostro nella stampante")
- sleep(0.10)
- end
- --check if paper level is ok
- while printer.getPaperLevel() == 0 do
- term.clear()
- term.setCursorPos(1,1)
- term.write("Errore! Inserire la carta nella stampante")
- sleep(0.10)
- end
- --set the new page for print
- term.clear()
- printer.newPage()
- term.clear()
- printer.setCursorPos(10,1)
- printer.write("Fattura")
- printer.setCursorPos(1,2)
- printer.write("Destinatario: ")
- printer.setCursorPos(1,3)
- printer.write(dest)
- printer.setCursorPos(1,5)
- printer.write("Prodotto: ")
- printer.setCursorPos(1,6)
- printer.write(prod)
- printer.setCursorPos(1,8)
- printer.write("Quantita: ")
- printer.setCursorPos(1,9)
- printer.write(qta)
- printer.setCursorPos(1,11)
- printer.write("Prezzo al pz: ")
- printer.setCursorPos(1,12)
- printer.write(pPz)
- printer.setCursorPos(1,14)
- printer.write("---------------------------------------------------")
- printer.setCursorPos(1,15)
- printer.write("Totale: ")
- printer.setCursorPos(1,16)
- printer.write(tot)
- printer.endPage()
- menu()
- end
- --draw the bill option buttons
- function drawbutton()
- term.setTextColor(colors.lightBlue)
- term.setBackgroundColor(colors.blue)
- term.setCursorPos(x2,y2)
- term.write(button3)
- term.setCursorPos(x3,y3)
- term.write(button4)
- term.setCursorPos(x4,y4)
- term.write(button5)
- term.setBackgroundColor(colors.black)
- end
- menu()
Add Comment
Please, Sign In to add comment