atdprocess.pas
来自「pasa人力资源考勤管理系统」· PAS 代码 · 共 1,026 行 · 第 1/5 页
PAS
1,026 行
Query2.sql.add('Update '+dest+' set kuanggong=isnull(kuanggong,0)+case when tempvalue>b.overtime then b.kgtime else 0 end '+
' from atd07010 as b where workno='''+workno+''' and rq='''+rq+''' ');
Query2.sql.add('Update '+dest+' set tempvalue=case when '+inttostr(early)+'>0 then 0 else abs('+inttostr(early)+') end where rq='''+rq+''' and workno='''+workno+''' ');
if adoatdsetearlycal.asboolean then //早退加基数
Query2.SQL.Add('Update '+dest+' set early=isnull(early,0)+case when tempvalue > b.earlytime then '+
' case when b.latestyle=1 then tempvalue else 1 end else 0 end '+
' from '+dest+' as a,atd07010 as b where a.rq='''+rq+''' and a.workno='''+workno+''' ')
else //早退不加基数
Query2.SQL.Add('Update '+dest+' set early=isnull(early,0)+case when tempvalue > b.earlytime then '+
' case when b.latestyle=1 then tempvalue - b.earlytime else 1 end else 0 end '+
' from '+dest+' as a,atd07010 as b where a.rq='''+rq+''' and a.workno='''+workno+''' ');
//计算旷工
Query2.sql.add('Update '+dest+' set kuanggong=isnull(kuanggong,0)+case when tempvalue>b.overtime then b.kgtime else 0 end '+
' from atd07010 as b where workno='''+workno+''' and rq='''+rq+''' ');
if adonormal.fieldbyname('addtime').asboolean then
if (factgo=null) or (factout=null) then
begin
process:=false; //若打卡资料不全则不标识通过
// Query2.sql.add('Update '+dest+' set kuanggong=isnull(kuanggong,0)+'+floattostr(facthours)+' where rq='''+rq+''' amd workno='''+workno+''' ');
end;
end;
//只要有一次未打卡就算其为旷工 旷工无出勤时数
if (factgo=null) or (factout=null) then
begin
process:=false; //若打卡资料不全则不标识通过
// Query2.sql.Add('Update '+dest+' set ot=isnull(ot,0)+'+floattostr(facthours)+' where rq='''+rq+''' and workno='''+workno+''' ');
end
else
if adonormal.fieldbyname('addtime').AsBoolean then
begin
try
Query2.sql.add('Update '+dest+' set ot=isnull(ot,0)+'+floattostr(facthours)+' where rq='''+rq+''' and workno='''+workno+''' ');
if adosalsetotkind.AsBoolean then //加班时数按总时数算
begin
adosaltotalot.open;
Query1.Close;
Query1.sql.Text:='Select * from atd33010 where workno='''+workno+' and monthy='''+Calcmonthy(rq)+''' ';
Query1.Open;
if Query1.eof then //本月还没有汇总资料
begin
Query3.close;
if adosaltotalot.eof then //若没有设定则计为默认加班
begin
AdoQuery1.Close;
AdoQuery1.sql.text:='Select * from '+ottable+' where workno='''+workno+''' and rq='''+rq+''' and otkind=''默认加班'' ';
AdoQuery1.open;
if AdoQuery1.Eof then
Query3.sql.text:='Insert into '+ottable+' (workno,rq,otkind,othours) values('''+workno+''','''+rq+''',''默认加班'','+floattostr(facthours)+' from sal16020 b'
else
Query3.sql.text:='Update '+ottable+' set othours=isnull(othours,0)+'+floattostr(facthours)+' where workno='''+workno+''' and rq='''+rq+''' and otkind=''默认加班'' ';
end else
begin
AdoQuery1.Close;
AdoQuery1.sql.text:='Select * from '+ottable+' where workno='''+workno+''' and rq='''+rq+''' and otkind=''默认加班'' ';
AdoQuery1.open;
if AdoQuery1.Eof then
Query3.SQL.Text:='Insert into '+ottable+' (workno,rq,otkin,othours) Select '''+workno+''','''+rq+''',b.otname,'+floattostr(facthours)+' from sal16020 b where b.minhours<='+floattostr(facthours)+' and b.maxhours>'+floattostr(facthours)+' '
else
Query3.sql.text:='Update '+ottable+' set othours=isnull(othours,0)+'+floattostr(facthours)+' from sal16020 b where b.minhours<='+floattostr(facthours)+' and b.maxhours>'+floattostr(facthours)+' and workno='''+workno+''' and rq='''+rq+''' ';
end;
Query3.ExecSQL;
end else //本月有汇总资料
begin
eveningot:=Query1.fieldbyname('othours').value;
Query3.Close;
Query3.sql.clear;
if adosaltotalot.Eof then //若没有设定则计为默认加班
Query3.sql.Add('Update '+ottable+' set othours=isnull(othours,0)+'+floattostr(facthours)+' where workno='''+workno+''' and rq='''+rq+''' and otkind=''默认加班'' ')
else
begin
Query2.close;
Query2.sql.text:='Select * from sal16020 where minhours<=(select othours from atd33010 where workno='''+workno+''' and monthy='''+monthy+''') and maxhours>(select othours from atd33010 where workno='''+workno+''' and monthy='''+calcmonthy(rq)+''') ';
Query2.Open;
if not Query2.eof then
begin //加班总时数超过某段则要分开成两种计算
if eveningot+facthours>Query2.fieldbyname('maxhours').value then
begin
Query3.SQL.Add('Insert into '+ottable+' select '''+workno+''','''+rq+''','''+Query2.fieldbyname('otname').value+''','+floattostr(Query2.fieldbyname('maxhours').value-eveningot)+' from atd25013 ');
Query3.SQL.Add('Insert into '+ottable+' select '''+workno+''','''+rq+''',b.otname,'+floattostr(eveningot+facthours)+'-b.minhours from sal16020 b where b.minhours<='+floattostr(eveningot+facthours)+' and maxhours>'+floattostr(eveningot+facthours)+' ');
end else
Query3.sql.add('Insert into '+ottable+' select '''+workno+''','''+rq+''','''+Query2.fieldbyname('otname').value+''','+floattostr(facthours)+' ');
end;
end;
end;
end //加班时数按总时数算
else
begin
//将加班类别归类
//加班超过某点则将其另计成深夜加班
//1800(A) 2200(B) 2330(C) A<B and B<C
if ((copy(factgo,12,5)<adosalsetotovertime.AsString) and (adosalsetotovertime.AsString<copy(factout,12,5))) then
begin
eveningot:=date1decdate2hour((formatdatetime('yyyy/mm/dd ',now)+copy(factout,12,5)),(formatdatetime('yyyy/mm/dd ',now)+adosalsetotovertime.AsString),0);
end; //A<B and B<C
//1800(A) 2200(B) 0330(C) A<B and C<B and C<A
if ((copy(factgo,12,5)<adosalsetotovertime.AsString) and (copy(factout,12,5)<adosalsetotovertime.AsString) and (copy(factout,12,5)<copy(factgo,12,5))) then
begin
eveningot:=date1decdate2hour((formatdatetime('yyyy/mm/dd ',now+1)+copy(factout,12,5)),(formatdatetime('yyyy/mm/dd ',now)+adosalsetotovertime.AsString),0);
end;
//1800(A) 0000(B) 0200(C) A>B and C>B and A>C
if ((copy(factgo,12,5)>adosalsetotovertime.AsString) and (copy(factout,12,5)>adosalsetotovertime.AsString) and (copy(factgo,12,5)>copy(factout,12,5))) then
begin
eveningot:=date1decdate2hour((formatdatetime('yyyy/mm/dd ',now)+copy(factout,12,5)),(formatdatetime('yyyy/mm/dd ',now)+adosalsetotovertime.AsString),0);
end;
//加班超过几小时计为超时加班
if (facthours>adosalsetothours.asfloat) then
begin
overtimeot:=facthours-adosalsetevening.AsFloat;
end;
//深夜(A)>超时(B) 5>3
if eveningot>overtimeot then
begin
if adosalsetcrosskind.AsBoolean then //按深夜加班
overtimeot:=0
else //按超时加班
eveningot:=eveningot-overtimeot; //5-3=2
end else //深夜(A)=超时(B) 5=5
if eveningot=overtimeot then
begin
if adosalsetcrosskind.AsBoolean then //按深夜加班
overtimeot:=0
else
eveningot:=0;
end else //深夜(A)<超时(B) 3<5
if eveningot<overtimeot then
begin
if adosalsetcrosskind.AsBoolean then //按深夜加班
overtimeot:=overtimeot-eveningot //5-3=2
else
eveningot:=0;
end;
Query1.close;
Query1.sql.clear;
Adoquery1.close; //查找存不存在此种类别的加班
Adoquery1.sql.text:='Select * from '+ottable+' as c where c.workno='''+workno+''' and c.rq='''+rq+''' and c.otkind='''+otkind+''' ';
Adoquery1.open;
if adoquery1.eof then //不存在则插入一笔
begin
Query1.sql.add('Insert into '+ottable+' (workno,rq,otkind,othours) select '''+workno+''','''+rq+''','''+otkind+''','+floattostr(facthours-eveningot-overtimeot)+' '+
' where (select count(*) from '+ottable+' as c where c.workno='''+workno+''' and c.rq='''+rq+''' and otkind='''+otkind+''')=0 ');
end else //否则累加
begin
Query1.sql.add('Update '+ottable+' set othours=isnull(othours,0)+'+floattostr(facthours)+' where workno='''+workno+''' and rq='''+rq+''' and otkind='''+otkind+''' ');
end;
if eveningot>0 then
begin
Adoquery1.close; //查找存不存在深夜加班
Adoquery1.sql.text:='Select * from '+ottable+' as c where c.workno='''+workno+''' and c.rq='''+rq+''' and c.otkind='''+otkind+''' ';
Adoquery1.open;
if adoquery1.eof then //不存在则插入一笔
begin
Query1.sql.add('Insert into '+ottable+' (workno,rq,otkind,othours) select '''+workno+''','''+rq+''',''深夜加班'','+floattostr(eveningot)+' '+
' where (select count(*) from '+ottable+' as c where c.workno='''+workno+''' and c.rq='''+rq+''' and otkind=''深夜加班'')=0 ');
end else //否则累加
begin
Query1.sql.add('Update '+ottable+' set othours=isnull(othours,0)+'+floattostr(facthours)+' where workno='''+workno+''' and rq='''+rq+''' and otkind=''深夜加班'' ');
end;
end;
if overtimeot>0 then
begin
Adoquery1.close; //查找存不存在超时加班
Adoquery1.sql.text:='Select * from '+ottable+' as c where c.workno='''+workno+''' and c.rq='''+rq+''' and c.otkind=''超时加班'' ';
Adoquery1.open;
if adoquery1.eof then //不存在则插入一笔
begin
Query1.sql.add('Insert into '+ottable+' (workno,rq,otkind,othours) select '''+workno+''','''+rq+''',''超时加班'','+floattostr(overtimeot)+' '+
' where (select count(*) from '+ottable+' as c where c.workno='''+workno+''' and c.rq='''+rq+''' and otkind=''超时加班'')=0 ');
end else //否则累加
begin
Query1.sql.add('Update '+ottable+' set othours=isnull(othours,0)+'+floattostr(facthours)+' where workno='''+workno+''' and rq='''+rq+''' and otkind=''超时加班'' ');
end;
end;
Query1.sql.savetofile('C:\ot.sql');
Query1.ExecSQL;
end;
except
application.messagebox(Pchar('计算工号为'+workno+'的员工的日出勤汇总时出错.'),'错误',mb_ok+mb_iconinformation);
end;
end//加班
else //正常上班
begin
//大夜班
//1800(A) 2200(B) 2330(C) A<B and B<C
if ((copy(factgo,12,5)<adosalsetotovertime.AsString) and (adosalsetotovertime.AsString<copy(factout,12,5))) then
begin
eveninghours:=date1decdate2hour((formatdatetime('yyyy/mm/dd ',now)+copy(factout,12,5)),(formatdatetime('yyyy/mm/dd ',now)+adosalsetotovertime.AsString),0);
end; //A<B and B<C
//1800(A) 2200(B) 0330(C) A<B and C<B and C<A
if ((copy(factgo,12,5)<adosalsetotovertime.AsString) and (copy(factout,12,5)<adosalsetotovertime.AsString) and (copy(factout,12,5)<copy(factgo,12,5))) then
begin
eveninghours:=date1decdate2hour((formatdatetime('yyyy/mm/dd ',now+1)+copy(factout,12,5)),(formatdatetime('yyyy/mm/dd ',now)+adosalsetotovertime.AsString),0);
end;
//1800(A) 0000(B) 0200(C) A>B and C>B and A>C
if ((copy(factgo,12,5)>adosalsetotovertime.AsString) and (copy(factout,12,5)>adosalsetotovertime.AsString) and (copy(factgo,12,5)>copy(factout,12,5))) then
begin
eveninghours:=date1decdate2hour((formatdatetime('yyyy/mm/dd ',now)+copy(factout,12,5)),(formatdatetime('yyyy/mm/dd ',now)+adosalsetotovertime.AsString),0);
end;
//正常出勤
Query2.sql.add('update '+dest+' set facthours=isnull(facthours,0)+'+floattostr(facthours-eveninghours)+' where rq='''+rq+''' and workno='''+workno+''' ');
//大夜班
Query2.sql.add('update '+dest+' set eveninghours=isnull(eveninghours,0)+'+floattostr(eveninghours)+' where
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?