Advertisement
Guest User

Untitled

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