Advertisement
Guest User

work

a guest
May 27th, 2015
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.20 KB | None | 0 0
  1. leapyear = 2016
  2. months = {31,28,31,30,31,30,31,31,30,31,30,31}
  3. year = 2015
  4. month = 1
  5. day = 1
  6. date = os.day()
  7. todaysdate = 1
  8. monthnames = {"January","February","March","April","May","June","July","August","September","October","November","December"}
  9. mon = monthnames[month]
  10. week = 5
  11. weekdays = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}
  12. weekday = weekdays[week]
  13. hour = "00"
  14. minute = "00"
  15. second = "00"
  16. word = ""
  17. job = ""
  18. pay = ""
  19. xSize, ySize = term.getSize()
  20. currenttime12 = 0
  21. currenttime24 = 0
  22. logselection = 1
  23. scrollstart = 1
  24. scrollend = scrollstart + ySize - 1
  25.  
  26. function convertdate()
  27.   term.clear()
  28.   term.setCursorPos(1,1)
  29.   print("Refreshing...")
  30.   currenttime12 = textutils.formatTime(os.time(),false)
  31.   currenttime24 = textutils.formatTime(os.time(),true)
  32.   date = os.day()
  33.   while todaysdate ~= date do
  34.     if todaysdate < date then
  35.       week = week + 1
  36.       if week > 7 then
  37.         week = 1
  38.       end
  39.       day = day + 1
  40.       for i=1,12 do
  41.         if month == i and day > months[i] then
  42.           day = 1
  43.           month = month + 1
  44.           if month > 12 then
  45.             month = 1
  46.             year = year + 1
  47.             if year == leapyear then
  48.               months[2] = 29
  49.             else
  50.               while year > leapyear do
  51.                 leapyear = leapyear + 4
  52.               end
  53.               months[2] = 28
  54.             end
  55.           end
  56.         end
  57.       end
  58.       todaysdate = todaysdate + 1
  59.     elseif todaysdate > date then
  60.       week = week - 1
  61.       if week < 1 then
  62.         week = 7
  63.       end
  64.       day = day - 1
  65.       for i=1,12 do
  66.         if day < 1 then
  67.           month = month - 1
  68.           if month < 1 then
  69.             month = 12
  70.             year = year - 1
  71.             while year <= leapyear-4 do
  72.               leapyear = leapyear - 4
  73.               if year == leapyear then
  74.                 months[2] = 29
  75.               else
  76.                 months[2] = 28
  77.               end
  78.             end
  79.           end
  80.           day = months[month]
  81.         end
  82.       end
  83.       todaysdate = todaysdate - 1
  84.     end
  85.     mon = monthnames[month]
  86.     weekday = weekdays[week]
  87.   end
  88. end
  89.  
  90. function typenum()
  91.   event, button, xPos, yPos = os.pullEvent()
  92.   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
  93.     word = string.sub(word, 2, 2)..button
  94.   elseif event == "key" and button == 14 and string.len(word) > 0 then
  95.     word = "0"..string.sub(word, 1, 1)
  96.   end
  97. end
  98.  
  99. function insertlog()
  100.   if xPos >= 1 and xPos <= 2 and yPos == 9 then
  101.     while true do
  102.       paintutils.drawLine(1,9,2,9,colors.white)
  103.       term.setCursorPos(1,9)
  104.       term.setTextColor(colors.black)
  105.       write(hour)
  106.       word = hour
  107.       typenum()
  108.       hour = word
  109.       if hour ~= nil and tonumber(hour) > 24 then
  110.         hour = "0"..string.sub(hour, 2, 2)
  111.       end
  112.       paintutils.drawLine(1,9,2,9,colors.black)
  113.       term.setCursorPos(1,9)
  114.       term.setTextColor(colors.white)
  115.       write(hour)
  116.       if (event ~= "key" and button ~= 14) and event ~= "char" then
  117.         break
  118.       end
  119.     end
  120.   end
  121.   if xPos >= 4 and xPos <= 5 and yPos == 9 then
  122.     while true do
  123.       paintutils.drawLine(4,9,5,9,colors.white)
  124.       term.setCursorPos(4,9)
  125.       term.setTextColor(colors.black)
  126.       write(minute)
  127.       word = minute
  128.       typenum()
  129.       minute = word
  130.       if tonumber(minute) > 59 then
  131.         minute = "0"..string.sub(minute, 2, 2)
  132.       end
  133.       paintutils.drawLine(4,9,5,9,colors.black)
  134.       term.setCursorPos(4,9)
  135.       term.setTextColor(colors.white)
  136.       write(minute)
  137.       if (event ~= "key" and button ~= 14) and event ~= "char" then
  138.         break
  139.       end
  140.     end
  141.   end
  142.   if xPos >= 7 and xPos <= 8 and yPos == 9 then
  143.     while true do
  144.       paintutils.drawLine(7,9,8,9,colors.white)
  145.       term.setCursorPos(7,9)
  146.       term.setTextColor(colors.black)
  147.       write(second)
  148.       word = second
  149.       typenum()
  150.       second = word
  151.       if tonumber(second) > 59 then
  152.         second = "0"..string.sub(second, 2, 2)
  153.       end
  154.       paintutils.drawLine(7,9,8,9,colors.black)
  155.       term.setCursorPos(7,9)
  156.       term.setTextColor(colors.white)
  157.       write(second)
  158.       if (event ~= "key" and button ~= 14) and event ~= "char" then
  159.         break
  160.       end
  161.     end
  162.   end
  163.   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
  164.     if job ~= "" and pay ~= "" then
  165.       if fs.exists("workclock/worklog") == false then
  166.         recentlog = fs.open("workclock/recentlog","w")
  167.         lastrecent = fs.open("workclock/lastrecent","w")
  168.         worklog = fs.open("workclock/worklog","w")
  169.         worklog.writeLine(job)
  170.         worklog.writeLine("$"..pay)
  171.         recentlog.writeLine(month.."/"..day.."/"..year.." "..hour..":"..minute..":"..second)
  172.         recentlog.close()
  173.         lastrecent.close()
  174.         worklog.close()
  175.         hour = "00"
  176.         minute = "00"
  177.         second = "00"
  178.       else
  179.         worklog = fs.open("workclock/worklog","r")
  180.         local joblog = worklog.readLine()
  181.         local paylog = worklog.readLine()
  182.         worklog.close()
  183.         if job ~= joblog or pay ~= string.sub(paylog, 2, string.len(paylog)) then
  184.           paintutils.drawFilledBox(1,13,29,ySize,colors.black)
  185.           term.setCursorPos(1,13)
  186.           print("Click here to confirm changing job/pay.")
  187.           print("Click here to cancel.")
  188.           event, button, xPos, yPos = os.pullEvent()
  189.           while true do
  190.             if event == "mouse_click" and button == 1 and xPos >= 1 and xPos <= 39 and yPos == 13 then
  191.               completeweek()
  192.               completeweek()
  193.               local transferlog = ""
  194.               worklog = fs.open("workclock/worklog","r")
  195.               transferlog = worklog.readAll()
  196.               worklog.close()
  197.               oldlog = fs.open("workclock/oldlog","a")
  198.               oldlog.writeLine(transferlog)
  199.               oldlog.close()
  200.               recentlog = fs.open("workclock/recentlog","w")
  201.               lastrecent = fs.open("workclock/lastrecent","w")
  202.               worklog = fs.open("workclock/worklog","w")
  203.               worklog.writeLine(job)
  204.               worklog.writeLine("$"..pay)
  205.               worklog.writeLine("Older logs saved to")
  206.               worklog.writeLine("'workclock/oldlog'.")
  207.               recentlog.writeLine(month.."/"..day.."/"..year.." "..hour..":"..minute..":"..second)
  208.               recentlog.close()
  209.               lastrecent.close()
  210.               worklog.close()
  211.               paintutils.drawFilledBox(1,13,29,ySize,colors.black)
  212.               term.setCursorPos(1,13)
  213.               print("Older logs saved to")
  214.               print("'workclock/oldlog'.")
  215.               break
  216.             elseif event == "mouse_click" and button == 1 and xPos >= 1 and xPos <= 21 and yPos == 14 then
  217.               paintutils.drawFilledBox(1,13,29,ySize,colors.black)
  218.               job = joblog
  219.               pay = string.sub(paylog, 2, string.len(paylog))
  220.               break
  221.             end
  222.           end
  223.           hour = "00"
  224.           minute = "00"
  225.           second = "00"
  226.         else
  227.           recentlog = fs.open("workclock/recentlog","a")
  228.           recentlog.writeLine(month.."/"..day.."/"..year.." "..hour..":"..minute..":"..second)
  229.           recentlog.close()
  230.           hour = "00"
  231.           minute = "00"
  232.           second = "00"
  233.         end
  234.       end
  235.     end
  236.   end
  237. end
  238.  
  239. function completeweek()
  240.   local workweek = {}
  241.   local n = 0
  242.  
  243.   recentlog = fs.open("workclock/recentlog","r")
  244.   repeat
  245.     n = n + 1
  246.     workweek[n] = recentlog.readLine()
  247.   until workweek[n] == nil
  248.   recentlog.close()
  249.  
  250.   if workweek[1] ~= nil then
  251.     for i=1,#workweek do
  252.       workweek[i] = string.sub(workweek[i], string.len(workweek[i])-7, string.len(workweek[i]))
  253.     end
  254.  
  255.     local workhr = {}
  256.     local workmin = {}
  257.     local worksec = {}
  258.  
  259.     for i=1,#workweek do
  260.       workhr[i] = string.sub(workweek[i], 1, 2)
  261.     end
  262.     for i=1,#workweek do
  263.       workmin[i] = string.sub(workweek[i], 4, 5)
  264.     end
  265.     for i=1,#workweek do
  266.       worksec[i] = string.sub(workweek[i], 7, 8)
  267.     end
  268.  
  269.     local totalhr = 0
  270.     local totalmin = 0
  271.     local totalsec = 0
  272.  
  273.     for i=1,#workhr do
  274.       totalhr = totalhr + tonumber(workhr[i])
  275.     end
  276.     for i=1,#workmin do
  277.       totalmin = totalmin + tonumber(workmin[i])
  278.     end
  279.     for i=1,#worksec do
  280.       totalsec = totalsec + tonumber(worksec[i])
  281.     end
  282.  
  283.     while totalsec > 60 do
  284.       totalsec = totalsec - 60
  285.       totalmin = totalmin + 1
  286.     end
  287.     while totalmin > 60 do
  288.       totalmin = totalmin - 60
  289.       totalhr = totalhr + 1
  290.     end
  291.  
  292.     local payout = math.floor((((totalsec / 60 + totalmin) / 60 + totalhr) * tonumber(pay)) * 100) / 100
  293.  
  294.     recentlog = fs.open("workclock/recentlog","a")
  295.     recentlog.writeLine("Total time: "..totalhr..":"..totalmin..":"..totalsec)
  296.     recentlog.writeLine("Total pay: "..payout)
  297.     recentlog.close()
  298.   end
  299.   local transferlog = ""
  300.  
  301.   lastrecent = fs.open("workclock/lastrecent","r")
  302.   transferlog = lastrecent.readAll()
  303.   lastrecent.close()
  304.  
  305.   worklog = fs.open("workclock/worklog","a")
  306.   worklog.writeLine(transferlog)
  307.   worklog.close()
  308.  
  309.   recentlog = fs.open("workclock/recentlog","r")
  310.   transferlog = recentlog.readAll()
  311.   recentlog.close()
  312.  
  313.   lastrecent = fs.open("workclock/lastrecent","w")
  314.   lastrecent.writeLine(transferlog)
  315.   lastrecent.close()
  316.  
  317.   recentlog = fs.open("workclock/recentlog","w")
  318.   recentlog.write("")
  319.   recentlog.close()
  320. end
  321.  
  322. function textinput(limit)
  323.   event, button, xPos, yPos = os.pullEvent()
  324.   if event == "char" and string.len(word) <= limit then
  325.     word = word..button
  326.   elseif event == "key" and button == 14 then
  327.     if string.len(word) <= 1 then
  328.       word = ""
  329.     else
  330.       word = string.sub(word, 1, string.len(word)-1)
  331.     end
  332.   end
  333. end
  334.  
  335. function numberinput(limit)
  336.   local originallimit = limit
  337.   event, button, xPos, yPos = os.pullEvent()
  338.   if event == "char"
  339.   and (button == "0" or button == "1" or button == "2" or button == "3" or button == "4"
  340.   or button == "5" or button == "6" or button == "7" or button == "8" or button == "9" or button == ".")
  341.   and string.len(word) <= limit and string.sub(word, string.len(word)-2, string.len(word)-2) ~= "." then
  342.     word = word..button
  343.     if (button == "." and (string.sub(word, string.len(word)-2, string.len(word)-2) == "."
  344.     or string.sub(word, string.len(word)-1, string.len(word)-1) == "."))
  345.     or (word == "0" and string.len(word) == 1) then
  346.       word = string.sub(word, 1, string.len(word)-1)
  347.     end
  348.   elseif event == "key" and button == 14 then
  349.     if string.len(word) <= 1 then
  350.       word = ""
  351.     else
  352.       word = string.sub(word, 1, string.len(word)-1)
  353.     end
  354.   end
  355. end
  356.  
  357. function logselect(selection)
  358.   local n = 0
  359.   recentlogdisplay = {}
  360.   lastrecentdisplay = {}
  361.   worklogdisplay = {}
  362.   recentlog = fs.open("workclock/recentlog","r")
  363.   lastrecent = fs.open("workclock/lastrecent","r")
  364.   worklog = fs.open("workclock/worklog","r")
  365.   repeat
  366.     n = n + 1
  367.     recentlogdisplay[n] = recentlog.readLine()
  368.   until recentlogdisplay[n] == nil
  369.   n = 0
  370.   repeat
  371.     n = n + 1
  372.     lastrecentdisplay[n] = lastrecent.readLine()
  373.   until lastrecentdisplay[n] == nil
  374.   n = 0
  375.   repeat
  376.     n = n + 1
  377.     worklogdisplay[n] = worklog.readLine()
  378.   until worklogdisplay[n] == nil
  379.   recentlog.close()
  380.   lastrecent.close()
  381.   worklog.close()
  382.   logdisplay = {}
  383.   if selection == 1 then
  384.     logdisplay = recentlogdisplay
  385.   elseif selection == 2 then
  386.     logdisplay = lastrecentdisplay
  387.   elseif selection == 3 then
  388.     logdisplay = worklogdisplay
  389.   end
  390.   if #logdisplay < ySize then
  391.     scrollend = #logdisplay
  392.   else
  393.     scrollend = scrollstart + ySize - 1
  394.   end
  395.   n = 0
  396.   local scrollpos = scrollstart
  397.   while scrollpos <= scrollend do
  398.     n = n + 1
  399.     term.setCursorPos(31,n)
  400.     write(logdisplay[scrollpos])
  401.     scrollpos = scrollpos + 1
  402.   end
  403. end
  404.  
  405. if fs.exists("workclock/worklog") then
  406.   worklog = fs.open("workclock/worklog","r")
  407.   job = worklog.readLine()
  408.   pay = worklog.readLine()
  409.   worklog.close()
  410.   pay = string.sub(pay, 2, string.len(pay))
  411. end
  412.  
  413. convertdate()
  414. while true do
  415.   term.clear()
  416.   term.setCursorPos(1,1)
  417.   print(month.."/"..day.."/"..year)
  418.   print(weekday..", "..mon.." "..day..", "..year)
  419.   print(currenttime12)
  420.   print(currenttime24)
  421.   print("")
  422.   print("Refresh Date   Exit")
  423.   print("Job: "..job)
  424.   print("Pay: $"..pay)
  425.   print(hour..":"..minute..":"..second)
  426.   print("Update Log")
  427.   print("Week complete")
  428.   print(" This Week  Last Week  Older ")
  429.   if fs.exists("workclock/worklog") then
  430.     logselect(logselection)
  431.   end
  432.   term.setBackgroundColor(colors.gray)
  433.   term.setTextColor(colors.black)
  434.   if logselection == 1 then
  435.     term.setCursorPos(1,12)
  436.     write(" This Week ")
  437.   elseif logselection == 2 then
  438.     term.setCursorPos(12,12)
  439.     write(" Last Week ")
  440.   elseif logselection == 3 then
  441.     term.setCursorPos(23,12)
  442.     write(" Older ")
  443.   end
  444.   term.setBackgroundColor(colors.black)
  445.   term.setTextColor(colors.white)
  446.   event, button, xPos, yPos = os.pullEvent()
  447.   if event == "mouse_click" and button == 1 then
  448.     if xPos >= 1 and xPos <= 12 and yPos == 6 then
  449.       convertdate()
  450.     elseif xPos >= 16 and xPos <= 19 and yPos == 6 then
  451.       break
  452.     elseif xPos >= 6 and xPos <= 29 and yPos == 7 then
  453.       while true do
  454.         paintutils.drawLine(6,7,29,7,colors.white)
  455.         term.setTextColor(colors.black)
  456.         term.setCursorPos(6,7)
  457.         write(job)
  458.         word = job
  459.         textinput(23)
  460.         job = word
  461.         paintutils.drawLine(6,7,29,7,colors.black)
  462.         term.setTextColor(colors.white)
  463.         term.setCursorPos(6,7)
  464.         write(job)
  465.         if event ~= "char" and (event ~= "key" and button ~= 14) then
  466.           break
  467.         end
  468.       end
  469.     elseif xPos >= 7 and xPos <= 29 and yPos == 8 then
  470.       while true do
  471.         paintutils.drawLine(7,8,29,8,colors.white)
  472.         term.setTextColor(colors.black)
  473.         term.setCursorPos(7,8)
  474.         write(pay)
  475.         word = pay
  476.         numberinput(22)
  477.         pay = word
  478.         paintutils.drawLine(7,8,29,8,colors.black)
  479.         term.setTextColor(colors.white)
  480.         term.setCursorPos(7,8)
  481.         write(pay)
  482.         if event ~= "char" and (event ~= "key" and button ~= 14) then
  483.           break
  484.         end
  485.       end
  486.     elseif xPos >= 1 and xPos <= 10 and yPos >= 9 and yPos <= 10 then
  487.       insertlog()
  488.     elseif xPos >= 1 and xPos <= 18 and yPos == 11 then
  489.       if fs.exists("workclock/worklog") then
  490.         completeweek()
  491.       end
  492.     elseif yPos == 12 then
  493.       if xPos >= 1 and xPos <= 11 then
  494.         logselection = 1
  495.       elseif xPos >= 12 and xPos <= 22 then
  496.         logselection = 2
  497.       elseif xPos >= 23 and xPos <= 29 then
  498.         logselection = 3
  499.       end
  500.     end
  501.   elseif event == "mouse_scroll" then
  502.     scrollstart = scrollstart + button
  503.     scrollend = scrollend + button
  504.     if scrollstart < 1 or scrollend > #logdisplay then
  505.       scrollstart = scrollstart - button
  506.       scrollend = scrollend - button
  507.     end
  508.   end
  509. end
  510. shell.run("clear")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement