李鼎文 徐昌欣 郭偉
中圖分類號:C37 文獻標識:A 文章編號:1674-1145(2018)8-203-04
摘要 本文介紹了某公司考勤加班統計的規則、原始考勤數據進行預先數據處理的方法,文中依據考勤規則進行了統計,介紹了相應的統計代碼,并通過Ⅶ編寫的程序實現自動統計,最后文章介紹了應用效果。
關鍵詞 考勤管理 加班時間統計 數據處理 VB
目前,企業在進行考勤管理的過程中,一般采用了考勤機來對考勤進行記錄,并進行一系列考勤情況統計,比如遲到早退人員統計、曠工人數統計、請假情況統計、加班情況統計等,其中加班情況統計是經常進行的一種。在有的中小企業中,只有考勤機記錄的初始記錄,沒有進一步的考勤統計分析軟件,怎樣利用考勤初始記錄,進行考勤加班統計,是中小企業常常面對的問題。本人在工作中,利用VB編寫小程序,通過對考勤初始數據的進行預處理,然后對加班情況進行統計,取代了手工進行考勤加班計算的狀況,減輕了考勤統計人員的工作量,并提高了工作的準確性。本人將考勤加班統計的方法、部分源碼及計算過程整理出來,以饗讀者。
一、考勤加班統計規則的設定
為方便進行考勤管理,必須首先設定考勤規則,讓員工有考勤依據,方能準確的打卡,知道自己的考勤情況。某企業中,對考勤加班統計規則設計如下:
1.平時上班時間,每天5點半以后算下班,6點之后刷卡算加班。
2.節假日全天可算加班。
3.平時上班時間,加班超過2.5個小時以上,給予一次餐補。
4.節假日加班,一次加班時間超過3個小時,給予一次餐補,7小時以上,兩次餐補封頂。二、考勤原始數據處理某企業中,考勤刷卡的原始數據如下圖所示,該數據是由考勤機的記錄導出的excel數據。
原始數據包括部門、姓名、考勤號、刷卡時間、記錄狀態、機器號等六個數據項。在進行考勤加班統計之前,需要對原始數據進行三個方面的預處理:1.去掉一次刷卡記錄下來的多次刷卡記錄。2.標注是正常上班時間還是節假日。3.取出正常上班時間超出18:00的刷卡數據,做為加班統計的依據。
1.去掉多次刷卡數據,將刷卡數據間隔小于5分鐘的數據去掉,即原始數據的間隔小于0.08的,刪除后面的數據。代碼如下:
For i=1 To totalnum-1 Step 1
If sheet ds.Cells(i,3)=sheet ds.Cells(i+1,3)And Year(sheet ds.Cells(i,4))=Year(sheet ds.Cells(i+1,4))And Month(sheet ds.Cells(i,4))=Month(sheet ds.Cells(i+1,4))And Day(sheet ds.Cells(i,4))=Day(sheet ds.Cells(i+1,4))And Round((Hour(sheet ds.Cells(i+1,4))-Hour(sheet ds.Cells(i,4))+(Minute(sheet ds.Cells(i+1,4))-Minute(sheet ds.Cells(i,4)))/6f), 2)<=0.08 Then
p=p+1
Else
sheet_ds1.Cells(i-p,1)=sheet ds.Cells(i,2)
sheet_ds1.Cells(i-p,2)=sheet ds.Cells(i,4)
sheet_ds1.Cells(i-p,3)=sheet ds.Cells(i,5)
shret_ds1.Cells(i-p,4)=sheet ds,Cells(i,3)
p=0
2.對原始數據標注是平時上班時間還是節假日。首先通過人機界面確定哪些是休息日,再逐一標注,如果是平時刷卡數據第五列標注為0,如果是節假日刷卡數據第五列標注為1。代碼如下:
Do While sheet so.Cells(totalnum,3) 統計記錄條數
totalnum=totalnum+1
Loop
totalnum=totalnum+1
For i=2 To tatalnum Step 1
sheet ds.Cells(i-1,1)=sheet so.Cells(i,1)
sheet ds.Cers(i-1,2)=sheet so.Cells(i,2)
sheet ds.Cells(i-1,3)=sheet so.Cells(i,3)
sleet ds.Cells(i-1,4)=sheet so.Cells(i,4)
sheet ds.Cells(i-1,5)=0
Forj=1 Tok-1Step 2
If Day(sheet so.Cells(i,4)=a(j)Then
sheet ds.Cells(i-1,5)=1
End If
Next j
Next i
3.取出正常上班時間超出18:00的刷卡數據。
If sheet_ds1. Cells(i,3)=0 And Hour(sheet_ds1.Cells(i,2))>=18Then '平時刷卡時間過了18:00的記錄
sheet ds2.Cells(i-p,1)=sbeet_ds1.Cells(i,1)
sheet ds2.Cells(i-p,2)=sheet_ds1.Cells(i,2)
sheet ds2.Cells(i-p,3)=sheet_ds1.Cells(i,3)
sheet ds2.Cells(i-p,7)=sheet_ds1.Celis(i,4)
totalnum1=totalnum1+1
Else
p=p+1
End If
End If
Next i
三、依據統計規則對預處理后的數據進行計算
1.以考勤號為關鍵字,統計當日休息時段刷卡的次數,及將刷卡次數累加計入第四列。
For i=1 To totalnum1 Step 1 '計算打卡記錄數
If(Day(sheet_ds 2.Cells(i,2)))=(Day(sheet_ds2.Cells(i+1,2)))And(Manth(sheet_ds2.Cells,2)))=(Month(sheet_ds2.Cells(i+1,2)))And(Year(sheet_ds2.Cells(i,2)))=(Year(sheet_ds2.Cells(i+1,2)))And(sheet_ds2.Cells(i,7)=sheet_ds2.Cells(i+1,7))Then
b=b+1
Else
sheet ds2.Cells(i,4)=b
b=1
End If
Next i
2.依據刷卡次數區分奇數次和偶數次刷卡,并按平時加班及休息日加班分別對加班時間進行統計,并計算餐補。這一共有三種情況:
(1)正常上班時間、休假時間的偶數次打卡,此時計算兩次刷卡記錄之差即為加班時間。然后分別按照正常上班時間和休假時間的餐補計算規則,統計餐補數量即可。即正常上班時加班時間超過2.5小時,給予一次餐補,休假時間一次加班時間超過3小時,給予一次餐補,7小時以上給予兩次餐補,將餐補結果計入第6列。
For i=1 To totalnum1 Step 1 '統計加班時間If sheet_ds2.Cells(i,4)And(sheet_ds2.Cells(i,4)Mod2=0)Then '正常上班時間、休假時間,偶數次打卡
sheet ds2.Cells(i,5)=0
sheet ds2.Cells(i,6)=0
For j=0 To sheet ds2.Cells(i,4)-2 Step 2
sheet_ds2.Cells(i,5)=Round((sheet_ds2.Cells(i,5)+Hour(sheet_ds2.Cells(i-j,2))-Hour(sheet_ds2.Cells(i-j-1,2))+(Minute(sheet_ds2.Cells(i-j,2))-Minute(sheet_ds2.Cells(i-j-1,2)))/60),2)
If Round((HOUr(sheet_ds2.Cells(i-j,2))-Hoor(sheet_ds2.Cells(i-j-1,2))+(Minute(sheet_ds2.Cells(i-j,2))-Minute(sheet_ds2.Cells(i-j-1,2)))/60),2)>2.5 Andsheet ds2.Cells(i,3)=0 Then '統計餐補
sheet_ds2.Cells(i,6)=i
Else
If Round((Hour(sheet_ds2.Cells(i-j.2))-Hour(sheet_ds2.Cells(i-j-1,2))+(Minute(sheet_ds2.Cells(i-j,2))-Minute(sheet_ds2.Cells(i-j-1,2)))/60),2)>=7 Andsheet_ds2.Cells(i,3)=1 Then
sheet_ds2.Cells(i,6)=2
End If
If Round((Hour(sheet_ds2.Cells(i-j,2))-Hour(sheet_ds2.Cells(i-j-1,2))+(Minute(sheet_ds2.Cells(i-j,2))-Minute(sheet_ds2.Cells(i-j-1,2)))/60), 2)>3 AndRound((Hour(sheet_ds2.Cells(i-j, 2))-Hour(sheet_ds2.Cells(i-j-1,2))+(Minute(sheet_ds2.Cells(i-j,2))-Minnee(sheet_ds2.Cells(i-j-1, 2)))/60),2)<7 Andsheet_ds2.Cells(i,3)=1 And sheet_ds2.Cells(i,6)<2 Then'統計餐補
sheet_ds2.Cells(i,6)=sheet_ds2.Cells(i,6)+1
End If'
End If.
Next j
(2)正常上班時間奇數次打卡,此時計算最后一次刷卡與17:30之差即為加班時間,然后依據加班時間和餐補規則計算餐補。
If sheet_ds2.Cells(i,4)And sheet_ds2.Cells(i,3)=0 And(sheet_ds2.Cell(i,4)Mod2=1)Then' 正常上班時間,奇數次打卡
sheet_ds2.Cells(i,5)=0
sheet_ds2.Cells(i,6)=0
sheet_ds2.Cells(i,5)=Round/(Hour(sheet_ds2.Cells(i-sheet_ds2.Cells(i,4)+1,2))-17+(Minute(sheet_ds2.Cells(i-sheet_ds2.Cells(i,4)+1,2))-30)/60),2)
If sheet_ds2.Cells(i,5)>2.5 Then'統計餐補
sheet_ds2.Cells(i,6)=1
End If
If shell_ds2.Cells(i,4)>1 Then
For j=0 To sheet_ds2.Cells(i,4)-3 Step 2
sheet_ds2.Cells(i,5)=Round((sheet_ds2.Cells(i,5)+Hour(sheet_ds2.Cells(i-j,2))-Hour(sheet-ds2.Cells(i-j-1,2))+(Minute(sheet_ds2.Cells(i-j,2))-Minute(sheet_ds2.Cells(i-j-1, 2)))/60),2)
If Round((Hour(sheet_ds2.Cells(i-j,2))-Hour(sheet_ds2.Cells(i-j-1,2))+(Minute(sheet_ds2.Cells(i-j,2))-Minute(sheet_ds2.Cells(i-j-1,2)))/60),2)>2.5 Then統計餐補
sheet_ds2.Cells(i,6)=1
End If
Next j
End If
End If
(3)休假時間奇數次打卡,此時計算第一次刷卡與最后一次刷卡之差即為加班時間,然后依據加班時間和餐補規則計算餐補即可。
If sheet_ds2.Cells(i,4)And sheet_ds2.Cells(i,3)=1 And(sheet_ds2.Cells(i,4)Mod 2=1)Then '休假時間,奇數次打卡
sheet_ds2.Cells(i,6)=0
sheet_ds2.Cells(i,5)=Round((Hour(sheet_ds2.Cells(i,2))-Hour(sheet_ds2.Cells(i-sheet_ds2.Cells(i,4)+1,2))+(Minute)sheet_ds2.Cells(i,2))-Minute(sheet_ds2.Cells(i-sheet_ds2.Cells(i,4)+1,2)))/60),2)
If sheet_ds2.Cells(i,5)>3 And sheet_ds2.Cells(i,5)<7 And sheet_ds2.Cells(i,6)<2 Then '統計餐補
sheet_ds2.Cells(i,6)=sheet_ds2.Cells(i,6)+1
Else
If sheet_da2.Cells(i,5)>=7 Then
sheet_ds2.Cells(i,6)=2
End If
End If
End If
End If
Next i
四、依據得到的結果,制作報表計算每日加班時間和當月加班總時間,及每日餐補數和該月餐補數。程序如下:
pk=2
For i=1 To totalnum1 Step 1'制作報表
If sheet ds2.Cells(i,4)Then
sheet_ds3.Cells(pk,1)=sheet_ds2.Cells(i,1)
sheet_ds3.Cells(pk,2)=sheet_ds2.Cells(i,7)
sheet_ds3.Cells(pk,3)=DateSerial(Year(sheet_ds2.Cells(i,2)),Month(sheet_ds2.Cells(i,2)),Day(sheet_ds2.Cells(i,2)))
sheet_ds3.Cells(pk,4)=sheet-ds2.Cells(i,5)
sheet_ds3.Cells(pk,5)=sheet_ds2.Cells(i,6)
pk=pk+1
End If
Next i
totaladd=sheet_ds3.Cells(2,4)
totalcount=sheet_ds3.Cells(2,5)
For i=2 To pk+1 Step1
if(sheet_ds3.Celts(i,2)=sheet_ds3.Cells(i+1,2))Then
totladd=tataladd+sheet_ds3.cells(i+1,4)
totalcount=totalcount+sheet_ds3.Cells(i+1,5)
Else
sheet_ds3.Cells(i,6)=totaladd
sheet_ds3.Cells(i,7)=totalcount
totaladd=sheet_ds3.Cells(i+1,4)
totalcount=sheet_ds3.Cells(i,1,5)
End If
Next i
End If
五、運行效果
(一)程序界面
通過人工輸入休息日,來區分正常上班時間和節假日日期,點擊加班統計即可進行統計計算。
1.統計過程。
通過不斷建立Worksheet,逐層遞進得進行計算,最后得到最后的統計結果。
(1)標注是平時工作日還是節假日。
(2)去掉時間間隔小于5分鐘的數據并取出正常工作日18:00以后的數據。
(3)計算當日刷卡次數,并統計加班時間及餐補。
(4)最終統計結果。
六、應用效果
該統計軟件已經在某公司穩定運行了一段時間,減輕了考勤統計人員的工作量,提高了統計的準確性,保障了公司的考勤管理工作的穩定運行,取得了較好的管理效能。
參考文獻:
[1]唐勇.RFID身份識別考勤系統設計[J].2013(6).
[2]劉宇.基于WEB的企業定制考勤系統的設計與實現[J].2013(11).
[3]楊洋.基于-NET的人事考勤管理系統的設計與開發[J].2011(6).