Advertisement
Guest User

frmWorkerPayroll

a guest
Jan 26th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.95 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.  
  240. Function ReturnAmIn(ByVal timeSeconds As Integer) As Integer
  241. Dim temp As Integer = 0
  242.  
  243. If timeSeconds < 25260 Then '07:01:00
  244. temp = 25200 ' 06:30:00
  245. Console.WriteLine("7:00")
  246. End If
  247.  
  248. If timeSeconds < 23460 Then '06:31:00
  249. temp = 23400 ' 06:30:00
  250. Console.WriteLine("30")
  251. End If
  252.  
  253. If timeSeconds < 22260 Then '06:11:00
  254. temp = 21600
  255. End If
  256. timeSeconds = temp
  257. Return timeSeconds
  258. End Function
  259.  
  260. Function ReturnBreakOut(ByVal timeSeconds As Integer) As Integer
  261. If timeSeconds > 43200 Then '12:00:00
  262. timeSeconds = 43200 ' 12:00:00
  263. End If
  264.  
  265. Return timeSeconds
  266. End Function
  267.  
  268. Function ReturnBreakIn(ByVal timeSeconds As Integer) As Integer
  269. If timeSeconds < 47460 Then '13:11:00
  270. timeSeconds = 46800 ' 13:00:00
  271. End If
  272.  
  273. Return timeSeconds
  274. End Function
  275.  
  276. Function ReturnPmOut(ByVal timeSeconds As Integer) As Integer
  277. If timeSeconds > 53999 And timeSeconds < 57660 Then ' 14:59:59 16:01:00.
  278. timeSeconds = 54000 ' 3PM
  279. End If
  280.  
  281. If getTimeOutPMHours > 64799 And getTimeOutPMHours < 65700 Then 'HERO? 6pm to 6:30pm
  282. timeSeconds = 64800 ' reset to 6PM
  283. End If
  284. Return timeSeconds
  285. End Function
  286.  
  287. Function ReturnHalfAfterNoonIn(ByVal timeSeconds As Integer) As Integer
  288. If timeSeconds > 32400 And timeSeconds < 40260 Then '09:00:00 11:11:00
  289. timeSeconds = 39600 ' 11:00:00
  290. End If
  291. Return timeSeconds
  292. End Function
  293.  
  294. Function ReturnHalfAfterNoonOut(ByVal timeSeconds As Integer) As Integer
  295. If timeSeconds > 32400 And timeSeconds < 40260 Then '09:00:00 11:11:00
  296. timeSeconds = 39600 ' 11:00:00
  297. End If
  298. Return timeSeconds
  299. End Function
  300.  
  301. Function ReturnHalfAmOut(ByVal timeSeconds As Integer) As Integer
  302. If timeSeconds < 53999 Then 'less than 3PM
  303. timeSeconds = 36000 ' 10:00
  304. End If
  305.  
  306. If timeSeconds > 53999 And timeSeconds < 57660 Then
  307. timeSeconds = 54000 ' 3PM
  308. End If
  309. Return timeSeconds
  310. End Function
  311. ' shows the time in hours and time out hours of the worker goes here
  312. Public Sub showWorkingHours()
  313.  
  314. 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")) & "'"
  315. Console.WriteLine(getQuery)
  316. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  317. getReader = getCommand.ExecuteReader
  318. lateSummary = 0
  319. Dim temp4 As Integer = 0
  320.  
  321. While getReader.Read
  322. temp4 += 1
  323. ' getting the time in and time out of the worker
  324. getTimeInAMHours = If(IsDBNull(getReader.Item("cAMIN")) = True, 0, getReader.Item("cAMIN"))
  325. getTimeOutAMHours = If(IsDBNull(getReader.Item("cAMOUT")) = True, 0, getReader.Item("cAMOUT"))
  326. getTimeInPMHours = If(IsDBNull(getReader.Item("cPMIN")) = True, 0, getReader.Item("cPMIN"))
  327. getTimeOutPMHours = If(IsDBNull(getReader.Item("cPMOUT")) = True, 0, getReader.Item("cPMOUT"))
  328.  
  329. Console.Write(" AMIN:" & getTimeInAMHours)
  330. Console.Write(" AMOUT:" & getTimeOutAMHours)
  331. Console.Write(" PMIN:" & getTimeInPMHours)
  332. Console.Write(" PMOUT:" & getTimeOutPMHours)
  333.  
  334. If getTimeInAMHours <> 0 And getTimeOutAMHours <> 0 Then
  335. 'VALID
  336.  
  337. If getTimeInPMHours = 0 Then
  338. 'HALF DAY
  339. Console.WriteLine("HALF DAY!")
  340. If getTimeInAMHours < 28800 Then
  341. 'HALF DAY MORNING
  342.  
  343. getTimeInAMHours = returnAmIn(getTimeInAMHours)
  344.  
  345.  
  346. Else
  347. 'HALFDAY AFTERNOON
  348.  
  349. getTimeInAMHours = ReturnHalfAfterNoonIn(getTimeInAMHours)
  350.  
  351. End If
  352.  
  353. getTimeOutAMHours = ReturnHalfAmOut(getTimeOutAMHours)
  354.  
  355.  
  356.  
  357. Else
  358. 'WHOLE DAY
  359. getTimeInAMHours = ReturnAmIn(getTimeInAMHours)
  360. getTimeOutAMHours = ReturnBreakOut(getTimeOutAMHours)
  361. getTimeInPMHours = ReturnBreakIn(getTimeInPMHours)
  362. getTimeOutPMHours = ReturnPmOut(getTimeOutPMHours)
  363.  
  364. End If
  365.  
  366.  
  367. lateSummary += If(getTimeInAMHours = 0, 0, If(getTimeInAMHours > 21599, getTimeInAMHours - 21600, 0)) + If(getTimeInPMHours = 0, 0, If(getTimeInPMHours > 21599, getTimeInPMHours - 46800, 0))
  368.  
  369.  
  370. iWorkingHours = (getTimeOutAMHours - getTimeInAMHours) + (getTimeOutPMHours - getTimeInPMHours)
  371.  
  372. getWorkingHours += If(iWorkingHours > 28800, 28800, iWorkingHours)
  373.  
  374.  
  375.  
  376. iOverTime = If(iWorkingHours > 28800, iWorkingHours - 28800, 0) 'if working hours > 8hours then OT yan
  377.  
  378. getOverTimeHours += iOverTime
  379.  
  380. Console.WriteLine("AMIN:" & getTimeInAMHours)
  381. Console.WriteLine("AMOUT:" & getTimeOutAMHours)
  382. Console.WriteLine("PMIN:" & getTimeInPMHours)
  383. Console.WriteLine("PMOUT:" & getTimeOutPMHours)
  384. Console.WriteLine("lateSummary:" & lateSummary)
  385. Console.WriteLine("getWorkingHours:" & getWorkingHours)
  386. Console.WriteLine("Overtime:" & getOverTimeHours)
  387.  
  388. Else
  389. iWorkingHours = 0
  390. getWorkingHours += 0
  391. iOverTime = 0
  392. getOverTimeHours += 0
  393.  
  394. End If
  395.  
  396.  
  397. getTimeInAMHours = Nothing
  398. getTimeOutAMHours = Nothing
  399. getTimeInPMHours = Nothing
  400. getTimeOutPMHours = Nothing
  401.  
  402. End While
  403.  
  404. getReader.Close()
  405. getPresentDays = temp4
  406. getWorkingHours = getWorkingHours / 3600
  407. lateSummary = lateSummary / 3600
  408.  
  409. Console.WriteLine("SUM: {0} / {1} / {2} ", lateSummary, getWorkingHours, getPresentDays)
  410.  
  411. txtWorkingHours.Text = getWorkingHours
  412.  
  413. ' refresh working hours
  414.  
  415.  
  416.  
  417. End Sub
  418.  
  419. Public Sub showPresentDays()
  420.  
  421. ' getting the present days goes here
  422. 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 & "'"
  423. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  424. getReader = getCommand.ExecuteReader
  425.  
  426. While getReader.Read
  427.  
  428. ' calculate the present days
  429. getPresentDays = getPresentDays + 1
  430.  
  431. End While
  432.  
  433. getReader.Close()
  434.  
  435. End Sub
  436.  
  437. ' shows the overtime hour of the worker
  438. Public Sub showOverTimeHours()
  439.  
  440. ' getting the overtime hour of the worker
  441. 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 & "'"
  442. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  443. getReader = getCommand.ExecuteReader
  444.  
  445. While getReader.Read
  446.  
  447. ' get the over time hour
  448. getOverTimeHours = (getReader.Item("over_time"))
  449.  
  450. While loopOverTime < getOverTimeHours
  451.  
  452. ' get the hours
  453. getWorkerOverTime = getWorkerOverTime + 1
  454.  
  455. loopOverTime = loopOverTime + 1
  456.  
  457. End While
  458. ' refresh loop
  459. loopOverTime = 17
  460.  
  461. End While
  462.  
  463. getReader.Close()
  464.  
  465.  
  466.  
  467. End Sub
  468.  
  469. ' shows the late hour of the worker
  470. Public Sub showLateHours()
  471.  
  472. ' getting the late hour of the worker
  473. 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 & "'"
  474. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  475. getReader = getCommand.ExecuteReader
  476.  
  477. While getReader.Read
  478.  
  479. getLateHours = (getReader.Item("late_hour"))
  480.  
  481. ' get the late hour
  482. While loopLateTime < getLateHours
  483.  
  484. ' get the hours
  485. getWorkerLateTime = getWorkerLateTime + 1
  486.  
  487. loopLateTime = loopLateTime + 1
  488.  
  489. End While
  490.  
  491. ' passing the late value
  492. passLateTime = getWorkerLateTime
  493.  
  494. ' refresh loop
  495. loopLateTime = 8
  496.  
  497. End While
  498.  
  499. getReader.Close()
  500.  
  501. End Sub
  502.  
  503.  
  504.  
  505. ' inputted deductions
  506.  
  507. 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
  508.  
  509. calculateTotalDeduction = Val(txtSSS.Text) + Val(txtPagIbig.Text) + Val(txtLateSummary.Text) + Val(txtOthers.Text) + Val(txtPHILHEALTH.Text)
  510.  
  511. calculateNetPay = Val(txtGrossPay.Text) - Val(calculateTotalDeduction)
  512.  
  513. txtTotalDeduction.Text = Decimal.Round(calculateTotalDeduction, 2).ToString("f2")
  514.  
  515. txtNetPay.Text = Decimal.Round(calculateNetPay, 2).ToString("f2")
  516.  
  517. End Sub
  518.  
  519. 'Private Sub txtPagIbig_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPagIbig.TextChanged
  520.  
  521. ' calculateTotalDeduction = Val(txtSSS.Text) + Val(txtPagIbig.Text) + Val(txtLateSummary.Text) + Val(txtOthers.Text)
  522.  
  523. ' calculateNetPay = Val(txtGrossPay.Text) - Val(calculateTotalDeduction)
  524.  
  525. ' txtTotalDeduction.Text = Decimal.Round(calculateTotalDeduction, 2).ToString("f2")
  526.  
  527. ' txtNetPay.Text = Decimal.Round(calculateNetPay, 2).ToString("f2")
  528.  
  529. 'End Sub
  530.  
  531. 'Private Sub txtLateSummary_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
  532.  
  533. ' calculateTotalDeduction = Val(txtSSS.Text) + Val(txtPagIbig.Text) + Val(txtLateSummary.Text) + Val(txtOthers.Text)
  534.  
  535. ' calculateNetPay = Val(txtGrossPay.Text) - Val(calculateTotalDeduction)
  536.  
  537. ' txtTotalDeduction.Text = Decimal.Round(calculateTotalDeduction, 2).ToString("f2")
  538.  
  539. ' txtNetPay.Text = Decimal.Round(calculateNetPay, 2).ToString("f2")
  540.  
  541. 'End Sub
  542.  
  543.  
  544. 'Private Sub txtOthers_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtOthers.TextChanged
  545.  
  546.  
  547. ' calculateTotalDeduction = Val(txtSSS.Text) + Val(txtPagIbig.Text) + Val(txtLateSummary.Text) + Val(txtOthers.Text)
  548.  
  549. ' calculateNetPay = Val(txtGrossPay.Text) - Val(calculateTotalDeduction)
  550.  
  551. ' txtTotalDeduction.Text = Decimal.Round(calculateTotalDeduction, 2).ToString("f2")
  552.  
  553. ' txtNetPay.Text = Decimal.Round(calculateNetPay, 2).ToString("f2")
  554.  
  555. 'End Sub
  556.  
  557. ' calculate the worker wage goes here
  558. Public Sub calculateWage()
  559.  
  560. ' calculate the net pay
  561. '
  562.  
  563. getGrossPay = (Val(txtRatePerHour.Text) * Val(txtWorkingHours.Text)) + (Val(txtOverTime.Text) * Val(txtOverTimeHours.Text))
  564. ' getLateSummary = getWorkerLateTime * lateSummary
  565. ' getTotalDeduction = Val(txtSSS.Text) + Val(txtPagIbig.Text) + Val(txtLateSummary.Text)
  566. lateSummary = lateSummary * Val(txtRatePerHour.Text)
  567. txtLateSummary.Text = Decimal.Round(lateSummary, 2).ToString("f2")
  568. txtGrossPay.Text = Decimal.Round(getGrossPay, 2).ToString("f2")
  569. txtTotalDeduction.Text = Decimal.Round(getLateSummary, 2).ToString("f2")
  570. getNetPay = Val(txtGrossPay.Text) - getLateSummary
  571.  
  572. txtNetPay.Text = Decimal.Round(getNetPay, 2).ToString("f2")
  573.  
  574.  
  575. End Sub
  576.  
  577.  
  578. ' set the variable to nothing
  579. Public Sub refreshVariables()
  580.  
  581. getPresentDays = Nothing
  582. getMinDate = Nothing
  583. getMaxDate = Nothing
  584. getWorkerID = Nothing
  585. getWorkerFullname = Nothing
  586. getWorkerDesignation = Nothing
  587. getWorkerOverTime = Nothing
  588. getWorkerLateTime = Nothing
  589.  
  590. End Sub
  591.  
  592.  
  593. ' clear all inputted text fields
  594. Public Sub clearTextFields()
  595.  
  596. txtSearchWorkerID.Clear()
  597. txtWorkerID.Clear()
  598. txtWorkerFullname.Clear()
  599. txtDesignation.Clear()
  600. txtPresentDays.Clear()
  601. txtWorkingHours.Clear()
  602. txtGrossPay.Clear()
  603. txtRatePerHour.Clear()
  604. txtPagIbig.Clear()
  605. txtPHILHEALTH.Clear()
  606.  
  607. txtOthers.Clear()
  608. txtOverTime.Clear()
  609. txtOverTimeHours.Clear()
  610. txtLateSummary.Clear()
  611. txtPagIbig.Clear()
  612. txtSSS.Clear()
  613. txtTotalDeduction.Clear()
  614. txtNetPay.Clear()
  615. dtpFrom.Text = Date.Now
  616. dtpTo.Text = Date.Now
  617.  
  618.  
  619. End Sub
  620.  
  621.  
  622. ' assign information into textfields
  623. Public Sub WorkeyPay()
  624. Dim ot As Decimal = (getOverTimeHours / 3600)
  625. txtOverTimeHours.Text = Decimal.Round(ot, 2).ToString("f2")
  626. Console.WriteLine("HAHAHA" & Decimal.Round(ot, 2).ToString("f2"))
  627.  
  628. txtPresentDays.Text = getPresentDays
  629. dtpTo.Text = getMaxDate
  630. dtpFrom.Text = getMinDate
  631. txtWorkerID.Text = getWorkerID
  632. txtWorkerFullname.Text = getWorkerFullname
  633. txtDesignation.Text = getWorkerDesignation
  634. txtRatePerHour.Text = Decimal.Round(getDesignationAmount, 2).ToString("f2")
  635. txtOverTime.Text = Decimal.Round(getDesignationAmount, 2).ToString("f2")
  636.  
  637. End Sub
  638.  
  639. ' increment the pay id goes here
  640. Public Sub incrementPayID()
  641.  
  642. getQuery = "SELECT wage.wage_id AS 'increment_number' FROM wage ORDER BY wage.wage_id DESC LIMIT 1"
  643. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  644. getReader = getCommand.ExecuteReader
  645.  
  646. While getReader.Read
  647.  
  648. getIncrementPayNumbers = (getReader.Item("increment_number").ToString) + 1
  649.  
  650. End While
  651.  
  652. getReader.Close()
  653.  
  654. End Sub
  655.  
  656.  
  657. ' get the worker wage goes here
  658. Public Sub submitWorkerWage()
  659.  
  660. If txtWorkerID.Text = "" Then
  661.  
  662. MsgBox("Please select worker ID", MsgBoxStyle.Information)
  663. txtSearchWorkerID.Focus()
  664.  
  665. Else
  666.  
  667. If MsgBox(Space(15) & "Worker ID: " & txtWorkerID.Text & vbCrLf & "Are you sure you want to pay?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
  668.  
  669. ' declare variable to hold the key
  670. Dim getDeductionID As Integer = Nothing
  671.  
  672. ' get the deduction id
  673. getQuery = "SELECT wage.deduction_id FROM wage WHERE wage.worker_id ='" & getWorkerID & "'"
  674. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  675. getReader = getCommand.ExecuteReader
  676.  
  677. If getReader.Read = True Then
  678.  
  679. getDeductionID = (getReader.Item("deduction_id").ToString)
  680.  
  681. End If
  682.  
  683. getReader.Close()
  684.  
  685. ' remove the previous deduction
  686. getQuery = "DELETE FROM deduction WHERE deduction.deduction_id ='" & getDeductionID & "'"
  687. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  688. getReader = getCommand.ExecuteReader
  689.  
  690. getReader.Close()
  691.  
  692. ' remove the previous wage
  693. getQuery = "DELETE FROM wage WHERE wage.worker_id ='" & getWorkerID & "'"
  694. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  695. getReader = getCommand.ExecuteReader
  696.  
  697. getReader.Close()
  698.  
  699. ' refresh increment id
  700. incrementPayID()
  701.  
  702. ' get the wage/deduction of the worker
  703. getQuery = "INSERT INTO wage VALUES('" & getIncrementPayNumbers & "','" & txtPresentDays.Text & "','" & Val(txtRatePerHour.Text) * Val(txtWorkingHours.Text) & _
  704. "','" & Val(txtOverTime.Text) * Val(txtOverTimeHours.Text) & "','" & Date.Today.ToString("yyyy-MM-dd") & "','" & txtWorkerID.Text & "','" & getIncrementPayNumbers & "','" & _
  705. frmLogin.getStaffID & "', '" & txtOverTimeHours.Text & "','" & txtWorkingHours.Text & "','" & txtNetPay.Text & "','" & txtGrossPay.Text & "')"
  706. Console.WriteLine(getQuery)
  707.  
  708. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  709.  
  710. getReader = getCommand.ExecuteReader
  711.  
  712. getReader.Close()
  713.  
  714. getQuery = "INSERT INTO deduction VALUES('" & getIncrementPayNumbers & "','" & txtPHILHEALTH.Text & "','" & txtSSS.Text & "','" & txtPagIbig.Text & "','" & txtLateSummary.Text & "','" & txtOthers.Text & "','" & Date.Today.ToString("yyyy-MM-dd") & "')"
  715. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  716. getReader = getCommand.ExecuteReader
  717.  
  718. getReader.Close()
  719.  
  720. MsgBox("Successfully saved!", MsgBoxStyle.Information)
  721.  
  722. ' remove the dtr of the worker
  723. deleteWorkerDTR()
  724.  
  725. ' refresh textfields
  726. clearTextFields()
  727.  
  728. ' refresh increment id
  729. incrementPayID()
  730.  
  731.  
  732. End If
  733.  
  734. End If
  735.  
  736. End Sub
  737.  
  738. ' remove the dtr of the worker after pay
  739. Private Sub deleteWorkerDTR()
  740.  
  741. ' remove the dtr
  742. getQuery = "DELETE FROM dtr WHERE dtr.worker_id ='" & txtWorkerID.Text & "'"
  743. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  744. getReader = getCommand.ExecuteReader
  745.  
  746. getReader.Close()
  747.  
  748. End Sub
  749.  
  750.  
  751.  
  752. Private Sub btnViewRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewRecord.Click
  753. Try
  754. If txtSearchWorkerID.Text = "" Then
  755. MsgBox("Please select worker ID", MsgBoxStyle.Information)
  756. txtSearchWorkerID.Focus()
  757. Exit Sub
  758. Else
  759. Dim f As New frmViewWorkerRecords
  760. f.workerID = txtWorkerID.Text
  761. f.sDate = dtpFrom.Value
  762. f.eDate = dtpTo.Value
  763. f.ShowDialog()
  764. frmViewWorkerRecords.txtTotalLateHours.Text = passLateTime
  765. frmViewWorkerRecords.txtTotalWorkHours.Text = txtWorkingHours.Text
  766. frmViewWorkerRecords.txtTotalOverTimeHours.Text = txtOverTimeHours.Text
  767. 'frmViewWorkerRecords.Show()
  768. End If
  769. Catch ex As Exception
  770.  
  771. End Try
  772. End Sub
  773.  
  774. ' remove dtr of the worker absent
  775. Private Sub workerAbsent()
  776.  
  777. getQuery = "DELETE FROM dtr WHERE dtr.time_OUT IS NULL AND dtr.worker_id ='" & getWorkerID & "'"
  778. getCommand = New MySqlCommand(getQuery, MySQLConnection)
  779. getReader = getCommand.ExecuteReader
  780.  
  781. getReader.Close()
  782.  
  783. End Sub
  784.  
  785. Private Sub frmWorkerPayroll_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
  786. frmMainMenu.Show()
  787. Me.Hide()
  788. frmViewWorkerRecords.Hide()
  789. End Sub
  790.  
  791. Private Sub frmWorkerPayroll_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  792.  
  793.  
  794. With txtSearchWorkerID
  795. .AutoCompleteCustomSource = SourceSuggestion
  796. .AutoCompleteMode = AutoCompleteMode.SuggestAppend
  797. .AutoCompleteSource = AutoCompleteSource.CustomSource
  798. End With
  799. End Sub
  800. Dim SourceSuggestion As New AutoCompleteStringCollection
  801. Private Sub cbSearch_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbSearch.SelectionChangeCommitted
  802. SourceSuggestion.Clear()
  803.  
  804. If cbSearch.SelectedIndex = 0 Then
  805. Dim dt As New DataTable
  806. Dim da As New MySqlDataAdapter("SELECT worker_id FROM worker", ConnectionString)
  807. da.Fill(dt)
  808.  
  809. For Each dr As DataRow In dt.Rows
  810. SourceSuggestion.Add(dr(0))
  811. Next
  812. ElseIf cbSearch.SelectedIndex = 1 Then
  813. Dim dt As New DataTable
  814. Dim da As New MySqlDataAdapter("SELECT worker_fullname FROM worker", ConnectionString)
  815. da.Fill(dt)
  816.  
  817. For Each dr As DataRow In dt.Rows
  818. SourceSuggestion.Add(dr(0))
  819. Next
  820. End If
  821. End Sub
  822. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement