⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pay550_02.pas.svn-base

📁 这是一个功能齐全的,代码完整的ERP企业信息管理系统,现在上传和大家分享
💻 SVN-BASE
字号:
unit Pay550_02;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Bas100_01, Db, StdCtrls, Buttons, wwdbdatetimepicker, Mask, ExtCtrls, ComCtrls,
  ADODB, Menus, Variants, atScript, atPascal;

type
  TPay550_02Form = class(TBas100_01Form)
    bbtnOk: TBitBtn;
    bbtnExit: TBitBtn;
    cbReCalc: TCheckBox;
    qryHrm150: TADOQuery;
    qryHrm150H150_001: TAutoIncField;
    qryHrm150H150_002: TStringField;
    qryHrm150H150_003: TStringField;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    Bevel1: TBevel;
    lblDept: TLabel;
    lblFromEmpID: TLabel;
    lblTo: TLabel;
    lblYear: TLabel;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    cbDepart: TComboBox;
    cbYear: TComboBox;
    cbMonth: TComboBox;
    edtFromEmpID: TEdit;
    edtToEmpID: TEdit;
    Bevel2: TBevel;
    Label1: TLabel;
    ProgressBar1: TProgressBar;
    Label2: TLabel;
    ProgressBar2: TProgressBar;
    qryEmployee: TADOQuery;
    qryPay150: TADOQuery;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure bbtnOkClick(Sender: TObject);
    procedure bbtnExitClick(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure edtFromEmpIDKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure edtToEmpIDKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure cbYearChange(Sender: TObject);
    procedure cbMonthChange(Sender: TObject);
  private
    AStartDate,AEndDate:TDateTime;
    APeriod:Integer;
    procedure CalcByTrans(AItemNo:Integer;AEmpNo,AYear,AMonth:Integer;AIsCheck:Boolean);
    procedure CalcByFormalu(AItemNo:Integer;AEmpNo,AYear,AMonth,ADays,AHours:Integer);
    procedure CalcPay(AEmpNo,AYear,AMonth,ADays,AHours:Integer;AIsCheck:Boolean);
    procedure SetInterface;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Pay550_02Form: TPay550_02Form;

implementation

uses HwSelData, CommFun, SYSDATA;

{$R *.DFM}

//按考勤事务处理
procedure TPay550_02Form.CalcByTrans(AItemNo:Integer;AEmpNo,AYear,AMonth:Integer;AIsCheck:Boolean);
var
  S:String;
begin
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('select sum(P500_006) from PAY500 where P500_001='+IntToStr(AItemNo));
  SYSDM.qryQuery.SQL.Add(' and P500_005>='+GetDateString(AStartDate)+' and P500_005<='+GetDateString(AEndDate));
  SYSDM.qryQuery.SQL.Add(' and P500_004='+IntToStr(AEmpNo));
  if AIsCheck then SYSDM.qryQuery.SQL.Add(' and P500_007='+GetBoolean(True));
  SYSDM.qryQuery.Open;
  S:=SYSDM.qryQuery.Fields[0].AsString;
  if S='' then S:='0';

  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('insert into PAY550(P550_001,P550_002,P550_003,P550_004,P550_005,P550_006)');
  SYSDM.qryQuery.SQL.Add('select '+IntToStr(AYear)+','+IntToStr(AMonth)+','+IntToStr(AEmpNo)+','+IntToStr(AItemNo)+','+S+',0');
  SYSDM.qryQuery.ExecSQL;
end;

//按公式计算
procedure TPay550_02Form.CalcByFormalu(AItemNo:Integer;AEmpNo,AYear,AMonth,ADays,AHours:Integer);
var
  AStringList:TStringList;
  AItemID:string;
  AFormaluString:string;
  S:string;
  Scripter:TatPascalScripter;
begin
  AItemID:=qryPay150.FieldByName('P150_002').AsString;
  AFormaluString:=qryPay150.FieldByName('P150_006').Value;    //计算公式

  AStringList:=TStringList.Create;
  Scripter:=TatPascalScripter.Create(Application);
  Scripter.Compiled:=True;
  Scripter.SourceCode.Clear;
  try
    AStringList.Text:=ParseFormula(AFormaluString,AItemID,AItemNo,AStartDate,AEndDate,AEmpNo,AYear,AMonth,ADays,AHours);
    Scripter.SourceCode.AddStrings(AStringList);
    try
      Scripter.Compile;
      S:=VarToStr(Scripter.Execute);
      if S='' then S:='0';
    except
      ShowMsg(Scripter.SourceCode.Text,1);
      Abort;
    end;
    try
      SYSDM.qryQuery.Close;
      SYSDM.qryQuery.SQL.Clear;
      SYSDM.qryQuery.SQL.Add('insert into PAY550(P550_001,P550_002,P550_003,P550_004,P550_005,P550_006)');
      SYSDM.qryQuery.SQL.Add('select '+IntToStr(AYear)+','+IntToStr(AMonth)+','+IntToStr(AEmpNo)+','+IntToStr(AItemNo)+','+S+',0');
      SYSDM.qryQuery.ExecSQL;
    except
      ShowMsg(SYSDM.ADOC.Errors[0].Description+#13+SYSDM.qryQuery.SQL.Text,1);
      Abort;
    end;
  finally
    AStringList.Free;
    Scripter.Free;
  end;
end;

procedure TPay550_02Form.SetInterface;
begin
  Caption:=GetDBString('PAY55002001');  //计算
  lblDept.Caption:=GetDBString('PAY55002002');  //部门编号
  lblFromEmpID.Caption:=GetDBString('PAY55002003');  //员工编号
  lblTo.Caption:=GetDBString('PAY55002004');  //至
  lblYear.Caption:=GetDBString('PAY55002005');  //年份月份
  cbReCalc.Caption:=GetDBString('PAY55002006');  //重新计算否
  bbtnOk.Caption:=GetDBString('PAY55002007');  //确定(&O)
  bbtnExit.Caption:=GetDBString('PAY55002008');  //退出(&X)
  PageControl1.ActivePageIndex:=0;
end;

procedure TPay550_02Form.CalcPay(AEmpNo,AYear,AMonth,ADays,AHours:Integer;AIsCheck:Boolean);
var
  AItemNo:Integer;
  AItemID,AItemNm:string;
  AType:Integer;  //项目类型 
  ANo:Integer;
begin
  qryPay150.Close;
  qryPay150.SQL.Clear;
  qryPay150.SQL.Add('select top 1 P510A_001 from PAY510A');
  qryPay150.SQL.Add('where P510A_002='+IntToStr(AEmpNo)+' and P510A_004<='+GetDateString(AStartDate));
  qryPay150.SQL.Add('order by P510A_004 desc');
  qryPay150.Open;
  ANo:=qryPay150.Fields[0].Value;

  qryPay150.Close;
  qryPay150.SQL.Clear;
  qryPay150.SQL.Add('select * from PAY510B, PAY150 ');
  qryPay150.SQL.Add('where P510B_001='+IntToStr(ANo)+' and P510B_002=P150_001 and P510B_004='+GetBoolean(True));
  qryPay150.SQL.Add('order by P150_007');
  qryPay150.Open;
  ProgressBar1.Position:=0;
  ProgressBar1.Max:=qryPay150.RecordCount;
  qryPay150.First;
  while not qryPay150.Eof do
  begin
    AItemNo:=qryPay150.FieldByName('P150_001').Value;  //项目电脑编号
    AItemID:=qryPay150.FieldByName('P150_002').Value;  //项目编号
    AItemNm:=qryPay150.FieldByName('P150_003').Value;  //项目名称
    AType:=qryPay150.FieldByName('P150_004').Value;    //0=按考勤事务处理,1=按公式计算
    Application.ProcessMessages;
    ProgressBar1.Position:=ProgressBar1.Position+1;
    Label1.Caption:=GetDBString('PAY55002013')+'['+AItemID+']['+AItemNm+']...';  //正在计算薪资项目
    Update;
    case AType of
      0:CalcByTrans(AItemNo,AEmpNo,AYear,AMonth,AIsCheck);
      1:CalcByFormalu(AItemNo,AEmpNo,AYear,AMonth,ADays,AHours);
    end;
    qryPay150.Next;
  end;
{
  //PAY0003	工资尾数舍入('1'=每个工资项目舍入,'2'=仅实发工资舍入,'3'=不舍入)
  //PAY0004	尾数舍入方法('1'=四舍五入,'2'=自定义)
  if GetSysParams('PAY0003')='1' then
  begin
    if GetSysParams('PAY0004')='1' then select @P550_006=Round(@P550_006,0)
  end;
}
end;

procedure TPay550_02Form.FormCreate(Sender: TObject);
begin
  inherited;
  qryHrm150.Close;
  qryHrm150.SQL.Clear;
  if not ASuper then
    qryHrm150.SQL.Add('select H150_001,H150_002,H150_003 from HRM150 where H150_005 in (select S500C_002 from SYS500C where S500C_003=''DEP'' and S500C_004='+GetBoolean(True)+' and S500C_001='+IntToStr(AUserID)+') order by H150_002')
  else
    qryHrm150.SQL.Add('select H150_001,H150_002,H150_003 from HRM150 order by H150_002');
  qryHrm150.Open;

  //部门资料
  cbDepart.Items.Clear;
  cbDepart.Items.Add(GetDBString('COM00004007'));  //所有部门
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('select * from HRM100');
  SYSDM.qryQuery.Open;
  while not SYSDM.qryQuery.Eof do
  begin
    cbDepart.Items.Add(SYSDM.qryQuery.FieldByName('H100_002').Value);
    SYSDM.qryQuery.Next;
  end;
  cbDepart.ItemIndex:=0;

  GetYears(cbYear);
  GetMonths(StrToInt(cbYear.Text),cbMonth);

  //设置界面信息
  SetInterface;
  Label1.Alignment:=taLeftJustify;
  Label2.Alignment:=taLeftJustify;
end;

procedure TPay550_02Form.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
//
end;

procedure TPay550_02Form.bbtnOkClick(Sender: TObject);
var
  AFromEmpID,AToEmpID,AYear,AMonth:string;
  ADeptNo,AEmpNo,APeriod:Integer;
  AEmpID,AEmpNm:string;
  I:Integer;
  AMin:Integer;
  ASec:Double;
  ADays,AHours:Integer;
  S:String;
  AIsCheck:Boolean;
begin
  inherited;
//确定
  ADeptNo:=0;
  if cbDepart.ItemIndex<>0 then
    ADeptNo:=GetValue('select H100_001 from HRM100 where H100_002='+''''+cbDepart.Text+'''');
  AFromEmpID:=trim(edtFromEmpID.Text);
  AToEmpID:=trim(edtToEmpID.Text);
  AYear:=cbYear.Text;
  AMonth:=cbMonth.Text;

  if AFromEmpID>AToEmpID then
  begin
    ShowMsg('UMS10000076');  //起始员工编号不能大于结束编号
    edtFromEmpID.SetFocus;
    Abort;
  end;

  if (AYear='') or (AMonth='') then
  begin
    ShowMsg('UMS10000218');  //年份或月份不能为空
    if AYear='' then cbYear.SetFocus
    else if AMonth='' then cbMonth.SetFocus;
    Abort;
  end;

  //取得期段的起始结束日期
  GetPeriodDate(AYear,AMonth,AStartDate,AEndDate,APeriod);
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('select 1 from PAY550 where P550_006='+GetBoolean(True)+' and P550_001='+AYear+' and P550_002='+IntToStr(APeriod));
  SYSDM.qryQuery.Open;
  if not SYSDM.qryQuery.IsEmpty then
  begin
    ShowMsg('UMS10000215');  //本月数据已审核,不能重新计算
    Abort;
  end;

  Screen.Cursor:=crHourGlass;
  bbtnOk.Enabled:=False;
  AStartTime:=GetTickCount;
  PageControl1.ActivePageIndex:=1;
  //计薪天数(1=按每月实际天数,2=按固定天数(2-3位数字表示天数))
  ADays:=30;
  S:=trim(GetSysParams('PAY0001'));
  if copy(S,1,1)='1' then
    ADays:=GetValue('select C170_005-C170_004+1 from CWA170 where C170_001='+AYear+' and C170_002='+IntToStr(APeriod))
  else if copy(S,1,1)='2' then
    ADays:=StrToInt(copy(S,2,2));
  //每日开工时数
  AHours:=StrToInt(trim(GetSysParams('CWA0006')));
  //薪资考勤事务数据是否必须审核
  AIsCheck:=GetSysParams('PAY0006')='Y';

  if AFromEmpID='' then AFromEmpID:=VarToStr(GetValue('select min(H150_002) from HRM150'));
  if AToEmpID='' then AToEmpID:=VarToStr(GetValue('select max(H150_002) from HRM150'));

  //删除薪资数据
  Label2.Caption:=GetDBString('PAY55002009')+'...';  //正在删除薪资数据
  Update;
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('delete from PAY550 where P550_001='+AYear+' and P550_002='+IntToStr(APeriod));
  SYSDM.qryQuery.SQL.Add(' and exists(select 1 from HRM150 where P550_003=H150_001 and H150_002>='+''''+AFromEmpID+''''+' and H150_002<='+''''+AToEmpID+'''');
  SYSDM.qryQuery.SQL.Add(' and H150_012<>2 ');
  if ADeptNo<>0 then SYSDM.qryQuery.SQL.Add(' and H150_005='+IntToStr(ADeptNo));
  SYSDM.qryQuery.SQL.Add(')');
  SYSDM.qryQuery.ExecSQL;

  qryEmployee.Close;
  qryEmployee.SQL.Clear;
  qryEmployee.SQL.Add('select H150_001,H150_002,H150_003 from HRM150 where H150_012<>2 and H150_002>='+''''+AFromEmpID+''''+' and H150_002<='+''''+AToEmpID+'''');
  if ADeptNo<>0 then qryEmployee.SQL.Add(' and H150_005='+IntToStr(ADeptNo));
  qryEmployee.Open;
  ProgressBar2.Position:=0;
  ProgressBar2.Max:=qryEmployee.RecordCount;
  qryEmployee.First;
  I:=1;
  while not qryEmployee.Eof do
  begin
    AEmpNo:=qryEmployee.FieldByName('H150_001').Value;
    AEmpID:=qryEmployee.FieldByName('H150_002').Value;
    AEmpNm:=qryEmployee.FieldByName('H150_003').Value;
    Application.ProcessMessages;
    ProgressBar2.Position:=ProgressBar2.Position+1;
    Label2.Caption:=GetDBString('PAY55002010')+'['+AEmpID+']['+AEmpNm+']... '+IntToStr(I)+'/'+IntToStr(qryEmployee.RecordCount);  //正在计算员工的薪资
    Update;
    CalcPay(AEmpNo,StrToInt(AYear),APeriod,ADays,AHours,AIsCheck);
    qryEmployee.Next;
    I:=I+1;
  end;

  Screen.Cursor:=crDefault;
  bbtnOk.Enabled:=True;
  ARunTime:=(GetTickCount-AStartTime)/1000;
  AMin:=Round(ARunTime) div 60;
  ASec:=StrToFloat(FormatFloat('0.00',ARunTime))-AMin*60;
  ShowMsg(GetDBString('UMS10000246')+IntToStr(AMin)+GetDBString('PAY55002011')+' '+FloatToStr(ASec)+GetDBString('PAY55002012'),1);  //薪资计算成功,共计耗时:
  ModalResult:=1;
end;

procedure TPay550_02Form.bbtnExitClick(Sender: TObject);
begin
  inherited;
//退出
  Close;
end;

procedure TPay550_02Form.SpeedButton1Click(Sender: TObject);
begin
  inherited;
//员工编号查询1
  if not edtFromEmpID.Focused then edtFromEmpID.SetFocus;
  HwSelDataForm:=THwSelDataForm.Create(Application);
  HwSelDataForm.OpenSelData(qryHrm150,nil);
  if HwSelDataForm.ShowModal=1 then
  begin
    edtFromEmpID.Text:=qryHrm150.FieldByName('H150_002').AsString;
  end;
end;

procedure TPay550_02Form.SpeedButton2Click(Sender: TObject);
begin
  inherited;
//员工编号查询2
  if not edtToEmpID.Focused then edtToEmpID.SetFocus;
  HwSelDataForm:=THwSelDataForm.Create(Application);
  HwSelDataForm.OpenSelData(qryHrm150,nil);
  if HwSelDataForm.ShowModal=1 then
  begin
    edtToEmpID.Text:=qryHrm150.FieldByName('H150_002').AsString;
  end;
end;

procedure TPay550_02Form.edtFromEmpIDKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  inherited;
  if Key=vk_F4 then SpeedButton1.Click;
end;

procedure TPay550_02Form.edtToEmpIDKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  inherited;
  if Key=vk_F4 then SpeedButton2.Click;
end;

procedure TPay550_02Form.cbYearChange(Sender: TObject);
begin
  inherited;
  GetMonths(StrToInt(cbYear.Text),cbMonth);
end;

procedure TPay550_02Form.cbMonthChange(Sender: TObject);
begin
  inherited;
  //取得期段的起始结束日期
  GetPeriodDate(cbYear.Text,cbMonth.Text,AStartDate,AEndDate,APeriod);
end;

initialization
  RegisterClass(TPay550_02Form);

finalization
  UnRegisterClass(TPay550_02Form);

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -