Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- leapyear = 2016
- months = {31,28,31,30,31,30,31,31,30,31,30,31}
- year = 2015
- month = 1
- day = 1
- date = os.day()
- todaysdate = 1
- monthnames = {"January","February","March","April","May","June","July","August","September","October","November","December"}
- mon = monthnames[month]
- week = 5
- weekdays = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}
- weekday = weekdays[week]
- hour = "00"
- minute = "00"
- second = "00"
- word = ""
- job = ""
- pay = ""
- xSize, ySize = term.getSize()
- currenttime12 = 0
- currenttime24 = 0
- logselection = 1
- scrollstart = 1
- scrollend = scrollstart + ySize - 1
- function convertdate()
- term.clear()
- term.setCursorPos(1,1)
- print("Refreshing...")
- currenttime12 = textutils.formatTime(os.time(),false)
- currenttime24 = textutils.formatTime(os.time(),true)
- date = os.day()
- while todaysdate ~= date do
- if todaysdate < date then
- week = week + 1
- if week > 7 then
- week = 1
- end
- day = day + 1
- for i=1,12 do
- if month == i and day > months[i] then
- day = 1
- month = month + 1
- if month > 12 then
- month = 1
- year = year + 1
- if year == leapyear then
- months[2] = 29
- else
- while year > leapyear do
- leapyear = leapyear + 4
- end
- months[2] = 28
- end
- end
- end
- end
- todaysdate = todaysdate + 1
- elseif todaysdate > date then
- week = week - 1
- if week < 1 then
- week = 7
- end
- day = day - 1
- for i=1,12 do
- if day < 1 then
- month = month - 1
- if month < 1 then
- month = 12
- year = year - 1
- while year <= leapyear-4 do
- leapyear = leapyear - 4
- if year == leapyear then
- months[2] = 29
- else
- months[2] = 28
- end
- end
- end
- day = months[month]
- end
- end
- todaysdate = todaysdate - 1
- end
- mon = monthnames[month]
- weekday = weekdays[week]
- end
- end
- function typenum()
- event, button, xPos, yPos = os.pullEvent()
- if event == "char" and (button == "0" or button == "1" or button == "2" or button == "3" or button == "4" or button == "5" or button == "6" or button == "7" or button == "8" or button == "9") then
- word = string.sub(word, 2, 2)..button
- elseif event == "key" and button == 14 and string.len(word) > 0 then
- word = "0"..string.sub(word, 1, 1)
- end
- end
- function insertlog()
- if xPos >= 1 and xPos <= 2 and yPos == 9 then
- while true do
- paintutils.drawLine(1,9,2,9,colors.white)
- term.setCursorPos(1,9)
- term.setTextColor(colors.black)
- write(hour)
- word = hour
- typenum()
- hour = word
- if hour ~= nil and tonumber(hour) > 24 then
- hour = "0"..string.sub(hour, 2, 2)
- end
- paintutils.drawLine(1,9,2,9,colors.black)
- term.setCursorPos(1,9)
- term.setTextColor(colors.white)
- write(hour)
- if (event ~= "key" and button ~= 14) and event ~= "char" then
- break
- end
- end
- end
- if xPos >= 4 and xPos <= 5 and yPos == 9 then
- while true do
- paintutils.drawLine(4,9,5,9,colors.white)
- term.setCursorPos(4,9)
- term.setTextColor(colors.black)
- write(minute)
- word = minute
- typenum()
- minute = word
- if tonumber(minute) > 59 then
- minute = "0"..string.sub(minute, 2, 2)
- end
- paintutils.drawLine(4,9,5,9,colors.black)
- term.setCursorPos(4,9)
- term.setTextColor(colors.white)
- write(minute)
- if (event ~= "key" and button ~= 14) and event ~= "char" then
- break
- end
- end
- end
- if xPos >= 7 and xPos <= 8 and yPos == 9 then
- while true do
- paintutils.drawLine(7,9,8,9,colors.white)
- term.setCursorPos(7,9)
- term.setTextColor(colors.black)
- write(second)
- word = second
- typenum()
- second = word
- if tonumber(second) > 59 then
- second = "0"..string.sub(second, 2, 2)
- end
- paintutils.drawLine(7,9,8,9,colors.black)
- term.setCursorPos(7,9)
- term.setTextColor(colors.white)
- write(second)
- if (event ~= "key" and button ~= 14) and event ~= "char" then
- break
- end
- end
- end
- if (event == "mouse_click" and button == 1 and xPos >= 1 and xPos <= 10 and yPos == 10) or (event == "key" and (button == 28 or button == 156)) then
- if job ~= "" and pay ~= "" then
- if fs.exists("workclock/worklog") == false then
- recentlog = fs.open("workclock/recentlog","w")
- lastrecent = fs.open("workclock/lastrecent","w")
- worklog = fs.open("workclock/worklog","w")
- worklog.writeLine(job)
- worklog.writeLine("$"..pay)
- recentlog.writeLine(month.."/"..day.."/"..year.." "..hour..":"..minute..":"..second)
- recentlog.close()
- lastrecent.close()
- worklog.close()
- hour = "00"
- minute = "00"
- second = "00"
- else
- worklog = fs.open("workclock/worklog","r")
- local joblog = worklog.readLine()
- local paylog = worklog.readLine()
- worklog.close()
- if job ~= joblog or pay ~= string.sub(paylog, 2, string.len(paylog)) then
- paintutils.drawFilledBox(1,13,29,ySize,colors.black)
- term.setCursorPos(1,13)
- print("Click here to confirm changing job/pay.")
- print("Click here to cancel.")
- event, button, xPos, yPos = os.pullEvent()
- while true do
- if event == "mouse_click" and button == 1 and xPos >= 1 and xPos <= 39 and yPos == 13 then
- completeweek()
- completeweek()
- local transferlog = ""
- worklog = fs.open("workclock/worklog","r")
- transferlog = worklog.readAll()
- worklog.close()
- oldlog = fs.open("workclock/oldlog","a")
- oldlog.writeLine(transferlog)
- oldlog.close()
- recentlog = fs.open("workclock/recentlog","w")
- lastrecent = fs.open("workclock/lastrecent","w")
- worklog = fs.open("workclock/worklog","w")
- worklog.writeLine(job)
- worklog.writeLine("$"..pay)
- worklog.writeLine("Older logs saved to")
- worklog.writeLine("'workclock/oldlog'.")
- recentlog.writeLine(month.."/"..day.."/"..year.." "..hour..":"..minute..":"..second)
- recentlog.close()
- lastrecent.close()
- worklog.close()
- paintutils.drawFilledBox(1,13,29,ySize,colors.black)
- term.setCursorPos(1,13)
- print("Older logs saved to")
- print("'workclock/oldlog'.")
- break
- elseif event == "mouse_click" and button == 1 and xPos >= 1 and xPos <= 21 and yPos == 14 then
- paintutils.drawFilledBox(1,13,29,ySize,colors.black)
- job = joblog
- pay = string.sub(paylog, 2, string.len(paylog))
- break
- end
- end
- hour = "00"
- minute = "00"
- second = "00"
- else
- recentlog = fs.open("workclock/recentlog","a")
- recentlog.writeLine(month.."/"..day.."/"..year.." "..hour..":"..minute..":"..second)
- recentlog.close()
- hour = "00"
- minute = "00"
- second = "00"
- end
- end
- end
- end
- end
- function completeweek()
- local workweek = {}
- local n = 0
- recentlog = fs.open("workclock/recentlog","r")
- repeat
- n = n + 1
- workweek[n] = recentlog.readLine()
- until workweek[n] == nil
- recentlog.close()
- if workweek[1] ~= nil then
- for i=1,#workweek do
- workweek[i] = string.sub(workweek[i], string.len(workweek[i])-7, string.len(workweek[i]))
- end
- local workhr = {}
- local workmin = {}
- local worksec = {}
- for i=1,#workweek do
- workhr[i] = string.sub(workweek[i], 1, 2)
- end
- for i=1,#workweek do
- workmin[i] = string.sub(workweek[i], 4, 5)
- end
- for i=1,#workweek do
- worksec[i] = string.sub(workweek[i], 7, 8)
- end
- local totalhr = 0
- local totalmin = 0
- local totalsec = 0
- for i=1,#workhr do
- totalhr = totalhr + tonumber(workhr[i])
- end
- for i=1,#workmin do
- totalmin = totalmin + tonumber(workmin[i])
- end
- for i=1,#worksec do
- totalsec = totalsec + tonumber(worksec[i])
- end
- while totalsec > 60 do
- totalsec = totalsec - 60
- totalmin = totalmin + 1
- end
- while totalmin > 60 do
- totalmin = totalmin - 60
- totalhr = totalhr + 1
- end
- local payout = math.floor((((totalsec / 60 + totalmin) / 60 + totalhr) * tonumber(pay)) * 100) / 100
- recentlog = fs.open("workclock/recentlog","a")
- recentlog.writeLine("Total time: "..totalhr..":"..totalmin..":"..totalsec)
- recentlog.writeLine("Total pay: "..payout)
- recentlog.close()
- end
- local transferlog = ""
- lastrecent = fs.open("workclock/lastrecent","r")
- transferlog = lastrecent.readAll()
- lastrecent.close()
- worklog = fs.open("workclock/worklog","a")
- worklog.writeLine(transferlog)
- worklog.close()
- recentlog = fs.open("workclock/recentlog","r")
- transferlog = recentlog.readAll()
- recentlog.close()
- lastrecent = fs.open("workclock/lastrecent","w")
- lastrecent.writeLine(transferlog)
- lastrecent.close()
- recentlog = fs.open("workclock/recentlog","w")
- recentlog.write("")
- recentlog.close()
- end
- function textinput(limit)
- event, button, xPos, yPos = os.pullEvent()
- if event == "char" and string.len(word) <= limit then
- word = word..button
- elseif event == "key" and button == 14 then
- if string.len(word) <= 1 then
- word = ""
- else
- word = string.sub(word, 1, string.len(word)-1)
- end
- end
- end
- function numberinput(limit)
- local originallimit = limit
- event, button, xPos, yPos = os.pullEvent()
- if event == "char"
- and (button == "0" or button == "1" or button == "2" or button == "3" or button == "4"
- or button == "5" or button == "6" or button == "7" or button == "8" or button == "9" or button == ".")
- and string.len(word) <= limit and string.sub(word, string.len(word)-2, string.len(word)-2) ~= "." then
- word = word..button
- if (button == "." and (string.sub(word, string.len(word)-2, string.len(word)-2) == "."
- or string.sub(word, string.len(word)-1, string.len(word)-1) == "."))
- or (word == "0" and string.len(word) == 1) then
- word = string.sub(word, 1, string.len(word)-1)
- end
- elseif event == "key" and button == 14 then
- if string.len(word) <= 1 then
- word = ""
- else
- word = string.sub(word, 1, string.len(word)-1)
- end
- end
- end
- function logselect(selection)
- local n = 0
- recentlogdisplay = {}
- lastrecentdisplay = {}
- worklogdisplay = {}
- recentlog = fs.open("workclock/recentlog","r")
- lastrecent = fs.open("workclock/lastrecent","r")
- worklog = fs.open("workclock/worklog","r")
- repeat
- n = n + 1
- recentlogdisplay[n] = recentlog.readLine()
- until recentlogdisplay[n] == nil
- n = 0
- repeat
- n = n + 1
- lastrecentdisplay[n] = lastrecent.readLine()
- until lastrecentdisplay[n] == nil
- n = 0
- repeat
- n = n + 1
- worklogdisplay[n] = worklog.readLine()
- until worklogdisplay[n] == nil
- recentlog.close()
- lastrecent.close()
- worklog.close()
- logdisplay = {}
- if selection == 1 then
- logdisplay = recentlogdisplay
- elseif selection == 2 then
- logdisplay = lastrecentdisplay
- elseif selection == 3 then
- logdisplay = worklogdisplay
- end
- if #logdisplay < ySize then
- scrollend = #logdisplay
- else
- scrollend = scrollstart + ySize - 1
- end
- n = 0
- local scrollpos = scrollstart
- while scrollpos <= scrollend do
- n = n + 1
- term.setCursorPos(31,n)
- write(logdisplay[scrollpos])
- scrollpos = scrollpos + 1
- end
- end
- if fs.exists("workclock/worklog") then
- worklog = fs.open("workclock/worklog","r")
- job = worklog.readLine()
- pay = worklog.readLine()
- worklog.close()
- pay = string.sub(pay, 2, string.len(pay))
- end
- convertdate()
- while true do
- term.clear()
- term.setCursorPos(1,1)
- print(month.."/"..day.."/"..year)
- print(weekday..", "..mon.." "..day..", "..year)
- print(currenttime12)
- print(currenttime24)
- print("")
- print("Refresh Date Exit")
- print("Job: "..job)
- print("Pay: $"..pay)
- print(hour..":"..minute..":"..second)
- print("Update Log")
- print("Week complete")
- print(" This Week Last Week Older ")
- if fs.exists("workclock/worklog") then
- logselect(logselection)
- end
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.black)
- if logselection == 1 then
- term.setCursorPos(1,12)
- write(" This Week ")
- elseif logselection == 2 then
- term.setCursorPos(12,12)
- write(" Last Week ")
- elseif logselection == 3 then
- term.setCursorPos(23,12)
- write(" Older ")
- end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- event, button, xPos, yPos = os.pullEvent()
- if event == "mouse_click" and button == 1 then
- if xPos >= 1 and xPos <= 12 and yPos == 6 then
- convertdate()
- elseif xPos >= 16 and xPos <= 19 and yPos == 6 then
- break
- elseif xPos >= 6 and xPos <= 29 and yPos == 7 then
- while true do
- paintutils.drawLine(6,7,29,7,colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(6,7)
- write(job)
- word = job
- textinput(23)
- job = word
- paintutils.drawLine(6,7,29,7,colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(6,7)
- write(job)
- if event ~= "char" and (event ~= "key" and button ~= 14) then
- break
- end
- end
- elseif xPos >= 7 and xPos <= 29 and yPos == 8 then
- while true do
- paintutils.drawLine(7,8,29,8,colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(7,8)
- write(pay)
- word = pay
- numberinput(22)
- pay = word
- paintutils.drawLine(7,8,29,8,colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(7,8)
- write(pay)
- if event ~= "char" and (event ~= "key" and button ~= 14) then
- break
- end
- end
- elseif xPos >= 1 and xPos <= 10 and yPos >= 9 and yPos <= 10 then
- insertlog()
- elseif xPos >= 1 and xPos <= 18 and yPos == 11 then
- if fs.exists("workclock/worklog") then
- completeweek()
- end
- elseif yPos == 12 then
- if xPos >= 1 and xPos <= 11 then
- logselection = 1
- elseif xPos >= 12 and xPos <= 22 then
- logselection = 2
- elseif xPos >= 23 and xPos <= 29 then
- logselection = 3
- end
- end
- elseif event == "mouse_scroll" then
- scrollstart = scrollstart + button
- scrollend = scrollend + button
- if scrollstart < 1 or scrollend > #logdisplay then
- scrollstart = scrollstart - button
- scrollend = scrollend - button
- end
- end
- end
- shell.run("clear")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement