Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.04 KB | None | 0 0
  1. Imports MySql.Data.MySqlClient
  2.  
  3. Public Class frmWorkerPayroll
  4. ' declaring variables
  5. Private getQuery As String = Nothing
  6. Private getCommand As MySqlCommand
  7. Private getReader As MySqlDataReader
  8. Private getMinDate As DateTime
  9. Private getMaxDate As DateTime
  10. Private getPresentDays As Integer = Nothing
  11. Private getWorkerID As String = Nothing
  12. Private getWorkerFullname As String = Nothing
  13. Private getWorkerDesignation As String = Nothing
  14. Private getWorkingHours As Decimal = Nothing
  15. Private getTimeInAMHours As Integer = Nothing
  16. Private getTimeOutAMHours As Integer = Nothing
  17. Private getTimeInPMHours As Integer = Nothing
  18. Private getTimeOutPMHours As Integer = Nothing
  19. Private getDesignationAmount As Decimal = Nothing
  20. Private getDesignationID As Integer = Nothing
  21. Private getOverTimeHours As Decimal = Nothing
  22. Private getWorkerOverTime As Integer = Nothing
  23. Private getLateHours As Integer = Nothing
  24. Private getWorkerLateTime As Integer = Nothing
  25. Private loopOverTime As Integer = 17
  26. Private loopLateTime As Integer = 8
  27. Private getIncrementPayNumbers As Integer = 1
  28. Private passLateTime = Nothing
  29. Private lateSummary As Decimal = 0
  30.  
  31. Private iWorkingHours = 0, iOverTime As Integer = 0
  32.  
  33. ' declare variable to get decimal point
  34. Private getGrossPay As Decimal = Nothing
  35. Private getLateSummary As Decimal = Nothing
  36. Private getTotalDeduction As Decimal = Nothing
  37. Private getTotalOT As Decimal = Nothing
  38. Private getNetPay As Decimal = Nothing
  39. Private calculateTotalDeduction As Decimal = Nothing
  40. Private calculateNetPay As Decimal = Nothing
  41.  
  42.  
  43. 'modified
  44.  
  45.  
  46. Private Sub btnSearchWorkerID_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearchWorkerID.Click
  47. Try
  48.  
  49. getPresentDays = Nothing
  50. getWorkerID = Nothing
  51. getWorkerFullname = Nothing
  52. getWorkerDesignation = Nothing
  53. getWorkingHours = Nothing
  54. getTimeInAMHours = Nothing
  55. getTimeOutAMHours = Nothing
  56. getTimeInPMHours = Nothing
  57. getTimeOutPMHours = Nothing
  58. getDesignationAmount = Nothing
  59. getDesignationID = Nothing
  60. getOverTimeHours = Nothing
  61. getWorkerOverTime = Nothing
  62. getLateHours = Nothing
  63. getWorkerLateTime = Nothing
  64. loopOverTime = 17
  65. loopLateTime = 8
  66. getIncrementPayNumbers = 1
  67. passLateTime = Nothing
  68. lateSummary = 0
  69. iWorkingHours = 0
  70. iOverTime = 0
  71. getGrossPay = Nothing
  72. getLateSummary = Nothing
  73. getTotalDeduction = Nothing
  74. getTotalOT = Nothing
  75. getNetPay = Nothing
  76. calculateTotalDeduction = Nothing
  77. calculateNetPay = Nothing
  78. ' workerAbsent()
  79. payWorkerID()
  80. Catch ex As Exception
  81.  
  82. End Try
  83.  
  84. End Sub
  85.  
  86. Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
  87. Try
  88. submitWorkerWage()
  89. Catch ex As Exception
  90.  
  91. End Try
  92. End Sub
  93.  
  94.  
  95. Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
  96.  
  97. Try
  98. If MsgBox("Are you sure you want to close?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
  99.  
  100. frmMainMenu.Show()
  101. Me.Hide()
  102. frmViewWorkerRecords.Hide()
  103.  
  104. End If
  105. Catch ex As Exception
  106.  
  107. End Try
  108.  
  109. End Sub
  110.  
  111.  
  112. ' getting the FromDate and ToDate goes here
  113. Public Sub payWorkerID()
  114. If cbSearch.SelectedIndex = -1 Then
  115.  
  116. MsgBox("Please select to be search", MsgBoxStyle.Information)
  117. cbSearch.Focus()
  118. Exit Sub
  119. ElseIf txtSearchWorkerID.Text = "" Then
  120.  
  121. If cbSearch.SelectedIndex = 0 Then
  122.  
  123. MsgBox("Please enter worker id to be search", MsgBoxStyle.Information)
  124. txtSearchWorkerID.Focus()
  125.  
  126. ElseIf cbSearch.SelectedIndex = 1 Then
  127.  
  128. MsgBox("Please enter worker fullname to be search", MsgBoxStyle.Information)
  129. txtSearchWorkerID.Focus()
  130.  
  131. End If
  132.  
  133. Else
  134.  
  135. If cbSearch.SelectedIndex = 0 Then
  136. getQuery = "SELECT worker.worker_id, worker.worker_fullname, designation.designation_name, designation.designation_amount FROM worker, designation WHERE worker.designation_id = designation.designation_id AND worker.worker_id ='" & txtSearchWorkerID.Text & "'"
  137. Else
  138. getQuery = "SELECT worker.worker_id, worker.worker_fullname, designation.designation_name, designation.designation_amount FROM worker, designation WHERE worker.designation_id = designation.designation_id AND worker.worker_fullname ='" & txtSearchWorkerID.Text & "'"
  139. End If
  140.  
  141.  
  142. End If
  143.  
  144.  
  145. ' getting the worker id, worker fullname and worker designation
  146. ' getQuery = "SELECT worker.worker_id, worker.worker_fullname, designation.designation_name, designation.designation_amount FROM worker, designation WHERE worker.designation_id = designation.designation_id AND worker.worker_id ='" & txtSearchWorkerID.Text & "'"
  147. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  148. getReader = getCommand.ExecuteReader
  149.  
  150.  
  151. If txtSearchWorkerID.Text = "" Then
  152.  
  153. MsgBox("Please enter worker id to search", MsgBoxStyle.Information)
  154. txtSearchWorkerID.Focus()
  155.  
  156. ElseIf getReader.Read = True Then
  157.  
  158. ' getting the worker informations
  159. getWorkerID = (getReader.Item("worker_id").ToString)
  160. getWorkerFullname = (getReader.Item("worker_fullname").ToString)
  161. getWorkerDesignation = (getReader.Item("designation_name").ToString)
  162. getDesignationAmount = (getReader.Item("designation_amount").ToString)
  163.  
  164. getReader.Close()
  165.  
  166. ' getting the dtr record if the worker works
  167. getQuery = "SELECT dtr.worker_id FROM dtr, worker WHERE dtr.worker_id ='" & getWorkerID & "' AND worker.worker_id ='" & getWorkerID & "'"
  168. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  169. getReader = getCommand.ExecuteReader
  170.  
  171. ' worker absent
  172. If getReader.Read = False Then
  173.  
  174. MsgBox(Space(15) & "Worker : " & txtSearchWorkerID.Text & vbCrLf & "Don't have an attendance records", MsgBoxStyle.Information)
  175.  
  176. ' refresh fields
  177. clearTextFields()
  178.  
  179. Else
  180.  
  181.  
  182. getReader.Close()
  183.  
  184. ' '' shows the FromDate and ToDate
  185. ''getQuery = "SELECT MIN(dtr.date) as 'FromDate', MAX(dtr.date) as 'ToDate' FROM dtr, worker WHERE dtr.worker_id ='" & txtSearchWorkerID.Text & "' AND worker.worker_id ='" & txtSearchWorkerID.Text & "'"
  186. ''getCommand = New MySqlCommand(getQuery, MySQLConnection)
  187. ''getReader = getCommand.ExecuteReader
  188.  
  189. ''If getReader.Read = True Then
  190.  
  191. getMinDate = dtpFrom.Value
  192. getMaxDate = dtpTo.Value
  193.  
  194. ''End If
  195.  
  196. ''getReader.Close()
  197.  
  198.  
  199. ' calculate the present days
  200. showPresentDays()
  201.  
  202. ' calculate the working hours
  203. showWorkingHours()
  204.  
  205. '' calculate the over time hours
  206. 'showOverTimeHours()
  207.  
  208. '' calculate the late hours
  209. 'showLateHours()
  210.  
  211. '' display informations
  212. WorkeyPay()
  213.  
  214. '' perform calculations
  215. calculateWage()
  216.  
  217. '' refresh variables
  218. 'refreshVariables()
  219.  
  220. End If
  221.  
  222. getReader.Close()
  223.  
  224. Else
  225.  
  226. MsgBox(Space(5) & "Worker : " & txtSearchWorkerID.Text & vbCrLf & "Sorry no data found", MsgBoxStyle.Information)
  227.  
  228. ' refresh fields
  229. clearTextFields()
  230.  
  231. End If
  232.  
  233.  
  234. getReader.Close()
  235.  
  236.  
  237.  
  238. End Sub
  239. Function ReturnAmIn(ByVal timeSeconds As Integer) As Integer
  240. Dim temp As Integer = 0
  241.  
  242. If timeSeconds < 32460 Then '09:01:00
  243. temp = 30600 ' 08:30:00
  244. End If
  245.  
  246. If timeSeconds < 30660 Then '08:31:00
  247. temp = 30600 ' 08:30:00
  248. End If
  249.  
  250. If timeSeconds < 29460 Then '08:11:00
  251. temp = 28800 '8:00:00
  252. End If
  253. timeSeconds = temp
  254. Return timeSeconds
  255. End Function
  256.  
  257. Function ReturnBreakOut(ByVal timeSeconds As Integer) As Integer
  258. If timeSeconds > 43200 Then '12:00:00
  259. timeSeconds = 43200 ' 12:00:00
  260. End If
  261.  
  262. Return timeSeconds
  263. End Function
  264.  
  265. Function ReturnBreakIn(ByVal timeSeconds As Integer) As Integer
  266. If timeSeconds < 47460 Then '13:11:00
  267. timeSeconds = 46800 ' 13:00:00
  268. End If
  269.  
  270. Return timeSeconds
  271. End Function
  272.  
  273. Function ReturnPmOut(ByVal timeSeconds As Integer) As Integer
  274. If timeSeconds > 61199 And timeSeconds < 64799 Then ' 16:59:59 18:01:00.
  275. timeSeconds = 61200 ' 5PM
  276. End If
  277.  
  278. 'If getTimeOutPMHours > 64799 And getTimeOutPMHours < 65700 Then 'HERO? 6pm to 6:30pm
  279. ' timeSeconds = 64800 ' reset to 6PM
  280. 'End If
  281. Return timeSeconds
  282. End Function
  283.  
  284. Function ReturnHalfAfterNoonIn(ByVal timeSeconds As Integer) As Integer
  285. If timeSeconds > 39600 And timeSeconds < 47460 Then '11:00:00 13:11:00
  286. timeSeconds = 46800 ' 13:00:00
  287. End If
  288. Return timeSeconds
  289. End Function
  290.  
  291. Function ReturnHalfAfterNoonOut(ByVal timeSeconds As Integer) As Integer
  292. If timeSeconds > 39600 And timeSeconds < 47460 Then '11:00:00 13:11:00
  293. timeSeconds = 46800 ' 13:00:00
  294. End If
  295. Return timeSeconds
  296. End Function
  297.  
  298. Function ReturnHalfAmOut(ByVal timeSeconds As Integer) As Integer
  299. If timeSeconds < 46800 Then 'less than 10Am
  300. timeSeconds = 43200 ' 12:00:00
  301. End If
  302.  
  303. If timeSeconds > 46800 And timeSeconds < 64800 Then
  304. timeSeconds = 61200 ' 5PM
  305. End If
  306. Return timeSeconds
  307. End Function
  308. ' shows the time in hours and time out hours of the worker goes here
  309. Public Sub showWorkingHours()
  310.  
  311. getQuery = "SELECT TIME_TO_SEC(`AM_IN`)'cAMIN',TIME_TO_SEC(`AM_OUT`)'cAMOUT',TIME_TO_SEC(`PM_IN`)'cPMIN',TIME_TO_SEC(`PM_OUT`)'cPMOUT', coalesce(TIME_TO_SEC(`OverTime`),0)'cOverTime', `AM_IN`, `AM_OUT`, `PM_IN`, `PM_OUT`, `spdate`, `OverTime` FROM dtr, worker WHERE dtr.worker_id ='" & getWorkerID & "' AND worker.worker_id ='" & getWorkerID & "' AND dtr.spdate BETWEEN '" & Format(getMinDate.ToString("yyyy-MM-dd")) & "' AND '" & Format(getMaxDate.ToString("yyyy-MM-dd")) & "'"
  312. Console.WriteLine(getQuery)
  313. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  314. getReader = getCommand.ExecuteReader
  315. lateSummary = 0
  316. Dim temp4 As Integer = 0
  317.  
  318. While getReader.Read
  319. temp4 += 1
  320. ' getting the time in and time out of the worker
  321. getTimeInAMHours = If(IsDBNull(getReader.Item("cAMIN")) = True, 0, getReader.Item("cAMIN"))
  322. getTimeOutAMHours = If(IsDBNull(getReader.Item("cAMOUT")) = True, 0, getReader.Item("cAMOUT"))
  323. getTimeInPMHours = If(IsDBNull(getReader.Item("cPMIN")) = True, 0, getReader.Item("cPMIN"))
  324. getTimeOutPMHours = If(IsDBNull(getReader.Item("cPMOUT")) = True, 0, getReader.Item("cPMOUT"))
  325.  
  326. Console.Write(" AMIN:" & getTimeInAMHours)
  327. Console.Write(" AMOUT:" & getTimeOutAMHours)
  328. Console.Write(" PMIN:" & getTimeInPMHours)
  329. Console.Write(" PMOUT:" & getTimeOutPMHours)
  330.  
  331. If getTimeInAMHours <> 0 And getTimeOutAMHours <> 0 Then
  332. 'VALID
  333.  
  334. If getTimeInPMHours = 0 Then
  335. 'HALF DAY
  336. Console.WriteLine("HALF DAY!")
  337. If getTimeInAMHours < 28800 Then
  338. 'HALF DAY MORNING
  339.  
  340. getTimeInAMHours = returnAmIn(getTimeInAMHours)
  341.  
  342.  
  343. Else
  344. 'HALFDAY AFTERNOON
  345.  
  346. getTimeInAMHours = ReturnHalfAfterNoonIn(getTimeInAMHours)
  347.  
  348. End If
  349.  
  350. getTimeOutAMHours = ReturnHalfAmOut(getTimeOutAMHours)
  351.  
  352.  
  353.  
  354. Else
  355. 'WHOLE DAY
  356. getTimeInAMHours = ReturnAmIn(getTimeInAMHours)
  357. getTimeOutAMHours = ReturnBreakOut(getTimeOutAMHours)
  358. getTimeInPMHours = ReturnBreakIn(getTimeInPMHours)
  359. getTimeOutPMHours = ReturnPmOut(getTimeOutPMHours)
  360.  
  361. End If
  362.  
  363. If getTimeInAMHours < 36000 Then
  364.  
  365. lateSummary += If(getTimeInAMHours = 0, 0, If(getTimeInAMHours > 28799, getTimeInAMHours - 28800, 0)) + If(getTimeInPMHours = 0, 0, If(getTimeInPMHours > 46799, getTimeInPMHours - 46800, 0))
  366. Else
  367.  
  368. lateSummary += getTimeInAMHours - 46800
  369. End If
  370.  
  371. iWorkingHours = (getTimeOutAMHours - getTimeInAMHours) + (getTimeOutPMHours - getTimeInPMHours)
  372.  
  373. getWorkingHours += If(iWorkingHours > 28800, 28800, iWorkingHours)
  374.  
  375.  
  376.  
  377. iOverTime = If(iWorkingHours > 28800, iWorkingHours - 28800, 0) 'if working hours > 8hours then OT yan
  378.  
  379. getOverTimeHours += iOverTime
  380.  
  381. Console.WriteLine("AMIN:" & getTimeInAMHours)
  382. Console.WriteLine("AMOUT:" & getTimeOutAMHours)
  383. Console.WriteLine("PMIN:" & getTimeInPMHours)
  384. Console.WriteLine("PMOUT:" & getTimeOutPMHours)
  385. Console.WriteLine("lateSummary:" & lateSummary)
  386. Console.WriteLine("getWorkingHours:" & getWorkingHours)
  387. Console.WriteLine("Overtime:" & getOverTimeHours)
  388.  
  389. Else
  390. iWorkingHours = 0
  391. getWorkingHours += 0
  392. iOverTime = 0
  393. getOverTimeHours += 0
  394.  
  395. End If
  396.  
  397.  
  398. getTimeInAMHours = Nothing
  399. getTimeOutAMHours = Nothing
  400. getTimeInPMHours = Nothing
  401. getTimeOutPMHours = Nothing
  402.  
  403. End While
  404.  
  405. getReader.Close()
  406. getPresentDays = temp4
  407. getWorkingHours = getWorkingHours / 3600
  408. lateSummary = lateSummary / 3600
  409.  
  410. Console.WriteLine("SUM: {0} / {1} / {2} ", lateSummary, getWorkingHours, getPresentDays)
  411.  
  412. txtWorkingHours.Text = getWorkingHours
  413.  
  414. ' refresh working hours
  415.  
  416.  
  417.  
  418. End Sub
  419.  
  420. Public Sub showPresentDays()
  421.  
  422. ' getting the present days goes here
  423. getQuery = "SELECT dtr.spdate FROM dtr, worker WHERE dtr.spdate BETWEEN '" & Format(getMinDate.ToString("yyyy-MM-dd")) & "' AND '" & Format(getMaxDate.ToString("yyyy-MM-dd")) & "' AND dtr.worker_id ='" & getWorkerID & "' AND worker.worker_id ='" & getWorkerID & "'"
  424. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  425. getReader = getCommand.ExecuteReader
  426.  
  427. While getReader.Read
  428.  
  429. ' calculate the present days
  430. getPresentDays = getPresentDays + 1
  431.  
  432. End While
  433.  
  434. getReader.Close()
  435.  
  436. End Sub
  437.  
  438. ' shows the overtime hour of the worker
  439. Public Sub showOverTimeHours()
  440.  
  441. ' getting the overtime hour of the worker
  442. getQuery = "SELECT HOUR(dtr.time_out) as 'over_time' FROM dtr, worker WHERE dtr.time_out IS NOT NULL AND worker.worker_id ='" & getWorkerID & "' AND dtr.worker_id ='" & txtSearchWorkerID.Text & "'"
  443. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  444. getReader = getCommand.ExecuteReader
  445.  
  446. While getReader.Read
  447.  
  448. ' get the over time hour
  449. getOverTimeHours = (getReader.Item("over_time"))
  450.  
  451. While loopOverTime < getOverTimeHours
  452.  
  453. ' get the hours
  454. getWorkerOverTime = getWorkerOverTime + 1
  455.  
  456. loopOverTime = loopOverTime + 1
  457.  
  458. End While
  459. ' refresh loop
  460. loopOverTime = 17
  461.  
  462. End While
  463.  
  464. getReader.Close()
  465.  
  466.  
  467.  
  468. End Sub
  469.  
  470. ' shows the late hour of the worker
  471. Public Sub showLateHours()
  472.  
  473. ' getting the late hour of the worker
  474. getQuery = "SELECT HOUR(dtr.time_in) AS 'late_hour' FROM dtr, worker WHERE dtr.time_out IS NOT NULL AND worker.worker_id ='" & getWorkerID & "' AND dtr.worker_id ='" & getWorkerID & "'"
  475. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  476. getReader = getCommand.ExecuteReader
  477.  
  478. While getReader.Read
  479.  
  480. getLateHours = (getReader.Item("late_hour"))
  481.  
  482. ' get the late hour
  483. While loopLateTime < getLateHours
  484.  
  485. ' get the hours
  486. getWorkerLateTime = getWorkerLateTime + 1
  487.  
  488. loopLateTime = loopLateTime + 1
  489.  
  490. End While
  491.  
  492. ' passing the late value
  493. passLateTime = getWorkerLateTime
  494.  
  495. ' refresh loop
  496. loopLateTime = 8
  497.  
  498. End While
  499.  
  500. getReader.Close()
  501.  
  502. End Sub
  503.  
  504.  
  505.  
  506. ' inputted deductions
  507.  
  508. Private Sub txtSSS_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSSS.TextChanged, txtPHILHEALTH.TextChanged, txtPagIbig.TextChanged, txtLateSummary.TextChanged, txtOthers.TextChanged
  509.  
  510. calculateTotalDeduction = Val(txtSSS.Text) + Val(txtPagIbig.Text) + Val(txtLateSummary.Text) + Val(txtOthers.Text) + Val(txtPHILHEALTH.Text)
  511.  
  512. calculateNetPay = Val(txtGrossPay.Text) - Val(calculateTotalDeduction)
  513.  
  514. txtTotalDeduction.Text = Decimal.Round(calculateTotalDeduction, 2).ToString("f2")
  515.  
  516. txtNetPay.Text = Decimal.Round(calculateNetPay, 2).ToString("f2")
  517.  
  518. End Sub
  519.  
  520. 'Private Sub txtPagIbig_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPagIbig.TextChanged
  521.  
  522. ' calculateTotalDeduction = Val(txtSSS.Text) + Val(txtPagIbig.Text) + Val(txtLateSummary.Text) + Val(txtOthers.Text)
  523.  
  524. ' calculateNetPay = Val(txtGrossPay.Text) - Val(calculateTotalDeduction)
  525.  
  526. ' txtTotalDeduction.Text = Decimal.Round(calculateTotalDeduction, 2).ToString("f2")
  527.  
  528. ' txtNetPay.Text = Decimal.Round(calculateNetPay, 2).ToString("f2")
  529.  
  530. 'End Sub
  531.  
  532. 'Private Sub txtLateSummary_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
  533.  
  534. ' calculateTotalDeduction = Val(txtSSS.Text) + Val(txtPagIbig.Text) + Val(txtLateSummary.Text) + Val(txtOthers.Text)
  535.  
  536. ' calculateNetPay = Val(txtGrossPay.Text) - Val(calculateTotalDeduction)
  537.  
  538. ' txtTotalDeduction.Text = Decimal.Round(calculateTotalDeduction, 2).ToString("f2")
  539.  
  540. ' txtNetPay.Text = Decimal.Round(calculateNetPay, 2).ToString("f2")
  541.  
  542. 'End Sub
  543.  
  544.  
  545. 'Private Sub txtOthers_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtOthers.TextChanged
  546.  
  547.  
  548. ' calculateTotalDeduction = Val(txtSSS.Text) + Val(txtPagIbig.Text) + Val(txtLateSummary.Text) + Val(txtOthers.Text)
  549.  
  550. ' calculateNetPay = Val(txtGrossPay.Text) - Val(calculateTotalDeduction)
  551.  
  552. ' txtTotalDeduction.Text = Decimal.Round(calculateTotalDeduction, 2).ToString("f2")
  553.  
  554. ' txtNetPay.Text = Decimal.Round(calculateNetPay, 2).ToString("f2")
  555.  
  556. 'End Sub
  557.  
  558. ' calculate the worker wage goes here
  559. Public Sub calculateWage()
  560.  
  561. ' calculate the net pay
  562. '
  563.  
  564. getGrossPay = (Val(txtRatePerHour.Text) * Val(txtWorkingHours.Text)) + (Val(txtOverTime.Text) * Val(txtOverTimeHours.Text))
  565. ' getLateSummary = getWorkerLateTime * lateSummary
  566. ' getTotalDeduction = Val(txtSSS.Text) + Val(txtPagIbig.Text) + Val(txtLateSummary.Text)
  567. lateSummary = lateSummary * Val(txtRatePerHour.Text)
  568. txtLateSummary.Text = Decimal.Round(lateSummary, 2).ToString("f2")
  569. txtGrossPay.Text = Decimal.Round(getGrossPay, 2).ToString("f2")
  570. txtTotalDeduction.Text = Decimal.Round(getLateSummary, 2).ToString("f2")
  571. getNetPay = Val(txtGrossPay.Text) - getLateSummary
  572.  
  573. txtNetPay.Text = Decimal.Round(getNetPay, 2).ToString("f2")
  574.  
  575.  
  576. End Sub
  577.  
  578.  
  579. ' set the variable to nothing
  580. Public Sub refreshVariables()
  581.  
  582. getPresentDays = Nothing
  583. getMinDate = Nothing
  584. getMaxDate = Nothing
  585. getWorkerID = Nothing
  586. getWorkerFullname = Nothing
  587. getWorkerDesignation = Nothing
  588. getWorkerOverTime = Nothing
  589. getWorkerLateTime = Nothing
  590.  
  591. End Sub
  592.  
  593.  
  594. ' clear all inputted text fields
  595. Public Sub clearTextFields()
  596.  
  597. txtSearchWorkerID.Clear()
  598. txtWorkerID.Clear()
  599. txtWorkerFullname.Clear()
  600. txtDesignation.Clear()
  601. txtPresentDays.Clear()
  602. txtWorkingHours.Clear()
  603. txtGrossPay.Clear()
  604. txtRatePerHour.Clear()
  605. txtPagIbig.Clear()
  606. txtPHILHEALTH.Clear()
  607.  
  608. txtOthers.Clear()
  609. txtOverTime.Clear()
  610. txtOverTimeHours.Clear()
  611. txtLateSummary.Clear()
  612. txtPagIbig.Clear()
  613. txtSSS.Clear()
  614. txtTotalDeduction.Clear()
  615. txtNetPay.Clear()
  616. dtpFrom.Text = Date.Now
  617. dtpTo.Text = Date.Now
  618.  
  619.  
  620. End Sub
  621.  
  622.  
  623. ' assign information into textfields
  624. Public Sub WorkeyPay()
  625. Dim ot As Decimal = (getOverTimeHours / 3600)
  626. txtOverTimeHours.Text = Decimal.Round(ot, 2).ToString("f2")
  627. Console.WriteLine("HAHAHA" & Decimal.Round(ot, 2).ToString("f2"))
  628.  
  629. txtPresentDays.Text = getPresentDays
  630. dtpTo.Text = getMaxDate
  631. dtpFrom.Text = getMinDate
  632. txtWorkerID.Text = getWorkerID
  633. txtWorkerFullname.Text = getWorkerFullname
  634. txtDesignation.Text = getWorkerDesignation
  635. txtRatePerHour.Text = Decimal.Round(getDesignationAmount, 2).ToString("f2")
  636. txtOverTime.Text = Decimal.Round(getDesignationAmount, 2).ToString("f2")
  637.  
  638. End Sub
  639.  
  640. ' increment the pay id goes here
  641. Public Sub incrementPayID()
  642.  
  643. getQuery = "SELECT wage.wage_id AS 'increment_number' FROM wage ORDER BY wage.wage_id DESC LIMIT 1"
  644. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  645. getReader = getCommand.ExecuteReader
  646.  
  647. While getReader.Read
  648.  
  649. getIncrementPayNumbers = (getReader.Item("increment_number").ToString) + 1
  650.  
  651. End While
  652.  
  653. getReader.Close()
  654.  
  655. End Sub
  656.  
  657.  
  658. ' get the worker wage goes here
  659. Public Sub submitWorkerWage()
  660.  
  661. If txtWorkerID.Text = "" Then
  662.  
  663. MsgBox("Please select worker ID", MsgBoxStyle.Information)
  664. txtSearchWorkerID.Focus()
  665.  
  666. Else
  667.  
  668. If MsgBox(Space(15) & "Worker ID: " & txtWorkerID.Text & vbCrLf & "Are you sure you want to pay?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
  669.  
  670. ' declare variable to hold the key
  671. Dim getDeductionID As Integer = Nothing
  672.  
  673. ' get the deduction id
  674. getQuery = "SELECT wage.deduction_id FROM wage WHERE wage.worker_id ='" & getWorkerID & "'"
  675. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  676. getReader = getCommand.ExecuteReader
  677.  
  678. If getReader.Read = True Then
  679.  
  680. getDeductionID = (getReader.Item("deduction_id").ToString)
  681.  
  682. End If
  683.  
  684. getReader.Close()
  685.  
  686. ' remove the previous deduction
  687. getQuery = "DELETE FROM deduction WHERE deduction.deduction_id ='" & getDeductionID & "'"
  688. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  689. getReader = getCommand.ExecuteReader
  690.  
  691. getReader.Close()
  692.  
  693. ' remove the previous wage
  694. getQuery = "DELETE FROM wage WHERE wage.worker_id ='" & getWorkerID & "'"
  695. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  696. getReader = getCommand.ExecuteReader
  697.  
  698. getReader.Close()
  699.  
  700. ' refresh increment id
  701. incrementPayID()
  702.  
  703. ' get the wage/deduction of the worker
  704. getQuery = "INSERT INTO wage VALUES('" & getIncrementPayNumbers & "','" & txtPresentDays.Text & "','" & Val(txtRatePerHour.Text) * Val(txtWorkingHours.Text) & _
  705. "','" & Val(txtOverTime.Text) * Val(txtOverTimeHours.Text) & "','" & Date.Today.ToString("yyyy-MM-dd") & "','" & txtWorkerID.Text & "','" & getIncrementPayNumbers & "','" & _
  706. frmLogin.getStaffID & "', '" & txtOverTimeHours.Text & "','" & txtWorkingHours.Text & "','" & txtNetPay.Text & "','" & txtGrossPay.Text & "')"
  707. Console.WriteLine(getQuery)
  708.  
  709. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  710.  
  711. getReader = getCommand.ExecuteReader
  712.  
  713. getReader.Close()
  714.  
  715. getQuery = "INSERT INTO deduction VALUES('" & getIncrementPayNumbers & "','" & txtPHILHEALTH.Text & "','" & txtSSS.Text & "','" & txtPagIbig.Text & "','" & txtLateSummary.Text & "','" & txtOthers.Text & "','" & Date.Today.ToString("yyyy-MM-dd") & "')"
  716. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  717. getReader = getCommand.ExecuteReader
  718.  
  719. getReader.Close()
  720.  
  721. MsgBox("Successfully saved!", MsgBoxStyle.Information)
  722.  
  723. ' remove the dtr of the worker
  724. deleteWorkerDTR()
  725.  
  726. ' refresh textfields
  727. clearTextFields()
  728.  
  729. ' refresh increment id
  730. incrementPayID()
  731.  
  732.  
  733. End If
  734.  
  735. End If
  736.  
  737. End Sub
  738.  
  739. ' remove the dtr of the worker after pay
  740. Private Sub deleteWorkerDTR()
  741.  
  742. ' remove the dtr
  743. getQuery = "DELETE FROM dtr WHERE dtr.worker_id ='" & txtWorkerID.Text & "'"
  744. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  745. getReader = getCommand.ExecuteReader
  746.  
  747. getReader.Close()
  748.  
  749. End Sub
  750.  
  751.  
  752.  
  753. Private Sub btnViewRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewRecord.Click
  754. Try
  755. If txtSearchWorkerID.Text = "" Then
  756. MsgBox("Please select worker ID", MsgBoxStyle.Information)
  757. txtSearchWorkerID.Focus()
  758. Exit Sub
  759. Else
  760. Dim f As New frmViewWorkerRecords
  761. f.workerID = txtWorkerID.Text
  762. f.sDate = dtpFrom.Value
  763. f.eDate = dtpTo.Value
  764. f.ShowDialog()
  765. frmViewWorkerRecords.txtTotalLateHours.Text = passLateTime
  766. frmViewWorkerRecords.txtTotalWorkHours.Text = txtWorkingHours.Text
  767. frmViewWorkerRecords.txtTotalOverTimeHours.Text = txtOverTimeHours.Text
  768. 'frmViewWorkerRecords.Show()
  769. End If
  770. Catch ex As Exception
  771.  
  772. End Try
  773. End Sub
  774.  
  775. ' remove dtr of the worker absent
  776. Private Sub workerAbsent()
  777.  
  778. getQuery = "DELETE FROM dtr WHERE dtr.time_OUT IS NULL AND dtr.worker_id ='" & getWorkerID & "'"
  779. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  780. getReader = getCommand.ExecuteReader
  781.  
  782. getReader.Close()
  783.  
  784. End Sub
  785.  
  786. Private Sub frmWorkerPayroll_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
  787. frmMainMenu.Show()
  788. Me.Hide()
  789. frmViewWorkerRecords.Hide()
  790. End Sub
  791.  
  792. Private Sub frmWorkerPayroll_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  793.  
  794.  
  795. With txtSearchWorkerID
  796. .AutoCompleteCustomSource = SourceSuggestion
  797. .AutoCompleteMode = AutoCompleteMode.SuggestAppend
  798. .AutoCompleteSource = AutoCompleteSource.CustomSource
  799. End With
  800. End Sub
  801. Dim SourceSuggestion As New AutoCompleteStringCollection
  802. Private Sub cbSearch_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbSearch.SelectionChangeCommitted
  803. SourceSuggestion.Clear()
  804.  
  805. If cbSearch.SelectedIndex = 0 Then
  806. Dim dt As New DataTable
  807. Dim da As New MySqlDataAdapter("SELECT worker_id FROM worker", ConnectionString)
  808. da.Fill(dt)
  809.  
  810. For Each dr As DataRow In dt.Rows
  811. SourceSuggestion.Add(dr(0))
  812. Next
  813. ElseIf cbSearch.SelectedIndex = 1 Then
  814. Dim dt As New DataTable
  815. Dim da As New MySqlDataAdapter("SELECT worker_fullname FROM worker", ConnectionString)
  816. da.Fill(dt)
  817.  
  818. For Each dr As DataRow In dt.Rows
  819. SourceSuggestion.Add(dr(0))
  820. Next
  821. End If
  822. End Sub
  823. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement