unit AccCloseOffu; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, DBGridEh, DB, kbmMemTable, ImgList,ADODB,DateUtils, Buttons, BusinessSkinForm, bsSkinCtrls, ExtCtrls, ComCtrls, bsSkinTabs; type TAddtionMonthlyFeeDataEvent = procedure(Sender : TObject; Msg : String) of Object; TfrmAccCloseOff = class(TForm) DBGridEh1: TDBGridEh; memTblPeriod: TkbmMemTable; dsrPeriod: TDataSource; memTblPeriodPERIOD: TStringField; memTblPeriodPYEAR: TIntegerField; memTblPeriodPMONTH: TIntegerField; memTblPeriodFDAY: TDateTimeField; memTblPeriodTDAY: TDateTimeField; memTblPeriodCLOSED: TStringField; ImageList1: TImageList; bsBusinessSkinForm1: TbsBusinessSkinForm; bbtnExcute: TbsSkinButton; bsSkinButton2: TbsSkinButton; memtotal: TkbmMemTable; memtotalID: TIntegerField; memtotalField16: TSmallintField; memtotalField: TIntegerField; memtotalField2: TSmallintField; memtotalField3: TSmallintField; memtotalField4: TDateField; memtotalField5: TStringField; memtotalField6: TStringField; memtotalField7: TStringField; memtotalField8: TStringField; memtotalField9: TStringField; memtotalField10: TFloatField; memtotalField11: TFloatField; memtotalField12: TFloatField; memtotalField13: TFloatField; memtotalField14: TFloatField; memtotalField15: TFloatField; memtotal1: TDataSource; kbmThreadDataSet1: TkbmThreadDataSet; t_ch_bank_genleg: TADOQuery; t_ch_cust_genleg: TADOQuery; t_ch_genleg: TADOQuery; memtotalRMB: TFloatField; memtotalRMB2: TFloatField; memtotalRMB3: TFloatField; bsSkinPageControl1: TbsSkinPageControl; bsSkinTabSheet1: TbsSkinTabSheet; bsSkinTabSheet2: TbsSkinTabSheet; DBGridLegBook: TDBGridEh; DBGridEh2: TDBGridEh; MemoMsg: TMemo; v_op_bscard: TADOQuery; v_op_bscard1: TDataSource; v_op_bscardDSDesigner2: TStringField; v_op_bscardDSDesigner3: TStringField; v_op_bscardDSDesigner4: TStringField; v_op_bscardDSDesigner5: TStringField; v_op_bscardDSDesigner6: TStringField; v_op_bscardDSDesigner7: TDateTimeField; v_op_bscardDSDesigner8: TStringField; v_op_bscardDSDesigner9: TStringField; v_op_bscardDSDesigner10: TStringField; v_op_bscardDSDesigner11: TStringField; v_op_bscardDSDesigner12: TStringField; v_op_bscardDSDesigner13: TStringField; v_op_bscardDSDesigner14: TStringField; v_op_bscardDSDesigner15: TStringField; v_op_bscardDSDesigner16: TStringField; v_op_bscardDSDesigner17: TStringField; v_op_bscardDSDesigner18: TStringField; v_op_bscardDSDesigner19: TStringField; v_op_bscardDSDesigner20: TStringField; v_op_bscardDSDesigner21: TDateTimeField; v_op_bscardDSDesigner22: TStringField; v_op_bscardDSDesigner23: TStringField; v_op_bscardDSDesigner24: TStringField; v_op_bscardDSDesigner25: TStringField; v_op_bscardDSDesigner26: TStringField; v_op_bscardDSDesigner27: TStringField; v_op_bscardDSDesigner28: TDateTimeField; v_op_bscardDSDesigner29: TStringField; v_op_bscardDSDesigner30: TStringField; v_op_bscardDSDesigner31: TStringField; v_op_bscardDSDesigner32: TStringField; v_op_bscardDSDesigner33: TIntegerField; v_op_bscardDSDesigner34: TStringField; v_op_bscardDSDesigner35: TStringField; v_op_bscardDSDesigner36: TStringField; v_op_bscardDSDesigner37: TDateTimeField; v_op_bscardDSDesigner38: TStringField; v_op_bscardDSDesigner39: TStringField; v_op_bscardDSDesigner40: TStringField; v_op_bscardDSDesigner41: TStringField; v_op_bscardDSDesigner42: TIntegerField; v_op_bscardDSDesigner43: TBCDField; v_op_bscardDSDesigner44: TBCDField; v_op_bscardDSDesigner47: TStringField; v_op_bscardUSD: TBCDField; v_op_bscardUSD2: TBCDField; v_op_bscardUSD3: TBCDField; v_op_bscardUSD4: TBCDField; v_op_bscardUSD5: TBCDField; v_op_bscardRMB: TBCDField; v_op_bscardRMB2: TBCDField; v_op_bscardRMB3: TBCDField; v_op_bscardRMB4: TBCDField; v_op_bscardRMB5: TBCDField; v_op_bscardDSDesigner48: TBCDField; v_op_bscardDSDesigner49: TBCDField; v_op_bscardDSDesigner50: TBCDField; v_op_bscardDSDesigner51: TStringField; v_op_bscardDSDesigner53: TBCDField; v_op_bscardDSDesigner54: TBCDField; v_op_bscardDSDesigner55: TBCDField; bsSkinPanel2: TbsSkinPanel; Label2: TLabel; Label3: TLabel; ComboBoxYear: TComboBox; EditYM: TEdit; bsSkinPanel1: TbsSkinPanel; Label1: TLabel; Panel1: TPanel; Label4: TLabel; Label5: TLabel; DateTimePicker1: TDateTimePicker; DateTimePicker2: TDateTimePicker; Button1: TButton; Button2: TButton; v_op_bscardDSDesigner1: TBCDField; v_op_bscardDSDesigner210: TBCDField; v_op_bscardDSDesigner310: TBCDField; v_op_bscardDSDesigner45: TBCDField; v_op_bscardDSDesigner52: TBCDField; v_op_bscardDSDesigner62: TBCDField; v_op_bscardDSDesigner72: TBCDField; v_op_bscardDSDesigner82: TBCDField; v_op_bscardDSDesigner92: TBCDField; v_op_bscardDSDesigner102: TBCDField; v_op_bscardDSDesigner: TBCDField; v_op_bscardTEU: TBCDField; procedure FormShow(Sender: TObject); procedure ComboBoxYearChange(Sender: TObject); procedure bbtnExcuteClick(Sender: TObject); procedure t_ch_bank_genlegAfterInsert(DataSet: TDataSet); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private aStep : SmallInt; procedure AddtionMonthlyFeeData(aYear, aMonth, aBsNo : String; Plus, CalcStl : Boolean; Proc : TAddtionMonthlyFeeDataEvent = nil); { Private declarations } public { Public declarations } ShowCtrls : Boolean; procedure UpdateAccDate(AccDate,toAccDate,SetAccDate:string); end; var frmAccCloseOff: TfrmAccCloseOff; implementation uses my_sys_function, u_main; {$R *.dfm} procedure TfrmAccCloseOff.AddtionMonthlyFeeData(aYear, aMonth, aBsNo : String; Plus, CalcStl : Boolean; Proc : TAddtionMonthlyFeeDataEvent = nil); var aQuery, aQuery2 : TAdoQuery; PlusChar : Char; I1, I2 : Integer; begin aQuery:=CreateAdoQuery; aQuery2:=CreateAdoQuery; if Plus then PlusChar:='+' else PlusChar:='-'; with aQuery do try //////添加已经审核的应收应付费用/////// Close;SQL.Clear; SQL.Add('Select c.客户名称, c.类型, c.币别,c.汇率, b.业务来源, b.来源明细,b.揽货人, b.业务类型,b.分部名称,b.销售部门'); SQL.Add(',Sum(ISNULL(c.金额,0)) as 金额'); SQL.Add('from t_ch_fee c, v_op_bscard b'); SQL.Add('where b.编号=c.编号 and c.金额<>0'); if strtobool(get_parameters_value(199,'false')) then begin if strtoint(get_parameters_value(140,'0'))=0 then SQL.Add(' and SUBSTRING(CONVERT(char(15),b.开船日期,111),1,7)='''+FormatDateTime('YYYY', EncodeDate(Logininfo.offyear,Logininfo.offmonth,1))+'/'+FormatDateTime('MM', EncodeDate(Logininfo.offyear,Logininfo.offmonth,1))+'''') else begin SQL.Add(' and b.开船日期>'''+FormatDateTime('YYYY-MM-DD',Logininfo.endday)+''' AND b.开船日期<'''+FormatDateTime('YYYY-MM-DD',Incmonth(Logininfo.endday)+1)+''''); end; end else begin if strtoint(get_parameters_value(140,'0'))=0 then SQL.Add(' and SUBSTRING(CONVERT(char(15),b.会计期间,111),1,7)='''+FormatDateTime('YYYY', EncodeDate(Logininfo.offyear,Logininfo.offmonth,1))+'/'+FormatDateTime('MM', EncodeDate(Logininfo.offyear,Logininfo.offmonth,1))+'''') else begin SQL.Add(' and b.会计期间>'''+FormatDateTime('YYYY-MM-DD',Logininfo.endday)+''' AND b.会计期间<'''+FormatDateTime('YYYY-MM-DD',Incmonth(Logininfo.endday)+1)+''''); end; end; if aBsNo<>'' then begin SQL.Add(' and b.业务编号='''+aBsNo+''''); end else begin SQL.Add(' and b.费用状态=''费用封帐'''); end; SQL.Add('Group By c.客户名称, c.类型, c.币别,c.汇率, b.业务来源, b.来源明细, b.揽货人, b.业务类型,b.分部名称,b.销售部门'); SQL.Add('Order By c.客户名称, c.类型, c.币别,c.汇率, b.业务来源, b.来源明细, b.揽货人, b.业务类型,b.分部名称,b.销售部门'); Open;First; I1:=0; I2:=RecordCount; while not Eof do begin Inc(I1); if Assigned(Proc) then Proc(nil, Format('应收应付数据:客户名称=%s, Rec : %d / %d', [aQuery.FieldByName('客户名称').AsString, I1, I2])); with aQuery2, SQL do begin Close;Clear; Add('Select Count(*) as rd from t_ch_custbalance'); Add('where 年='+aYear+' and 月='+aMonth); Add('and 客户名称='''+aQuery.FieldByName('客户名称').AsString+''''); Add('and 业务来源='''+aQuery.FieldByName('业务来源').AsString+''''); Add('and 来源明细='''+aQuery.FieldByName('来源明细').AsString+''''); Add('and 业务类型='''+aQuery.FieldByName('业务类型').AsString+''''); Add('and 揽货人='''+aQuery.FieldByName('揽货人').AsString+''''); Add('and 分部名称='''+aQuery.FieldByName('分部名称').AsString+''''); Add('and 销售部门='''+aQuery.FieldByName('销售部门').AsString+''''); Open; if Plus and (FieldByName('rd').AsInteger=0) then begin Close;Clear; Add('Insert Into t_ch_custbalance'); Add('(年,月,客户名称,业务来源,来源明细,业务类型,揽货人,分部名称,销售部门'); Add(',上月应收结余,本月应收发生,本月应收核销,本月应收结余,上月应收结余USD,本月应收发生USD'); Add(',本月应收核销USD,本月应收结余USD,上月应付结余,本月应付发生,本月应付核销,本月应付结余'); Add(',上月应付结余USD,本月应付发生USD,本月应付核销USD,本月应付结余USD'); Add(',上月应收结余合计,本月应收发生合计,本月应收核销合计,本月应收结余合计'); Add(',上月应付结余合计,本月应付发生合计,本月应付核销合计,本月应付结余合计)'); Add('Values('+aYear+','+aMonth+','''+aQuery.FieldByName('客户名称').AsString+''''); Add(','''+aQuery.FieldByName('业务来源').AsString+''''); Add(','''+aQuery.FieldByName('来源明细').AsString+''''); Add(','''+aQuery.FieldByName('业务类型').AsString+''''); Add(','''+aQuery.FieldByName('揽货人').AsString+''''); Add(','''+aQuery.FieldByName('分部名称').AsString+''''); Add(','''+aQuery.FieldByName('销售部门').AsString+''''); if aQuery.FieldByName('币别').AsString='RMB' then begin if aQuery.FieldByName('类型').AsString='收' then Add(',0,'+aQuery.FieldByName('金额').AsString+',0,'+aQuery.FieldByName('金额').AsString+',0,0,0,0,0,0,0,0,0,0,0,0,0,'+aQuery.FieldByName('金额').AsString+',0,'+aQuery.FieldByName('金额').AsString+',0,0,0,0)') else Add(',0,0,0,0,0,0,0,0,0,'+aQuery.FieldByName('金额').AsString+',0,'+aQuery.FieldByName('金额').AsString+',0,0,0,0,0,0,0,0,0,'+aQuery.FieldByName('金额').AsString+',0,'+aQuery.FieldByName('金额').AsString+')'); end else begin if aQuery.FieldByName('类型').AsString='收' then Add(',0,0,0,0,0,'+aQuery.FieldByName('金额').AsString+',0,'+aQuery.FieldByName('金额').AsString+',0,0,0,0,0,0,0,0,0,'+floattostr(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat)+',0,'+floattostr(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat)+',0,0,0,0)') else Add(',0,0,0,0,0,0,0,0,0,0,0,0,0,'+aQuery.FieldByName('金额').AsString+',0,'+aQuery.FieldByName('金额').AsString+',0,0,0,0,0,'+floattostr(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat)+',0,'+floattostr(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat)+')'); end; end else begin Close;Clear; Add('Update t_ch_custbalance Set'); if aQuery.FieldByName('币别').AsString='RMB' then begin if aQuery.FieldByName('类型').AsString='收' then begin Add('本月应收发生=本月应收发生'+PlusChar+aQuery.FieldByName('金额').AsString+',本月应收发生合计=本月应收发生合计'+PlusChar+aQuery.FieldByName('金额').AsString); Add(',本月应收结余=本月应收结余'+PlusChar+aQuery.FieldByName('金额').AsString+',本月应收结余合计=本月应收结余合计'+PlusChar+aQuery.FieldByName('金额').AsString); end else begin Add('本月应付发生=本月应付发生'+PlusChar+aQuery.FieldByName('金额').AsString+',本月应付发生合计=本月应付发生合计'+PlusChar+aQuery.FieldByName('金额').AsString); Add(',本月应付结余=本月应付结余'+PlusChar+aQuery.FieldByName('金额').AsString+',本月应付结余合计=本月应付结余合计'+PlusChar+aQuery.FieldByName('金额').AsString); end; end else begin if aQuery.FieldByName('类型').AsString='收' then begin Add('本月应收发生USD=本月应收发生USD'+PlusChar+aQuery.FieldByName('金额').AsString+',本月应收发生合计=本月应收发生合计'+PlusChar+floattostr(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat)); Add(',本月应收结余USD=本月应收结余USD'+PlusChar+aQuery.FieldByName('金额').AsString+',本月应收结余合计=本月应收结余合计'+PlusChar+floattostr(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat)); end else begin Add('本月应付发生USD=本月应付发生USD'+PlusChar+aQuery.FieldByName('金额').AsString+',本月应付发生合计=本月应付发生合计'+PlusChar+floattostr(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat)); Add(',本月应付结余USD=本月应付结余USD'+PlusChar+aQuery.FieldByName('金额').AsString+',本月应付结余合计=本月应付结余合计'+PlusChar+floattostr(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat)); end; end; Add('where 年='+aYear+' and 月='+aMonth); Add('and 客户名称='''+aQuery.FieldByName('客户名称').AsString+''''); Add('and 业务来源='''+aQuery.FieldByName('业务来源').AsString+''''); Add('and 来源明细='''+aQuery.FieldByName('来源明细').AsString+''''); Add('and 业务类型='''+aQuery.FieldByName('业务类型').AsString+''''); Add('and 揽货人='''+aQuery.FieldByName('揽货人').AsString+''''); Add('and 分部名称='''+aQuery.FieldByName('分部名称').AsString+''''); Add('and 销售部门='''+aQuery.FieldByName('销售部门').AsString+''''); end; // sql.SaveToFile('d:\1.txt'); ExecSQL; end; Next; end; if not CalcStl then exit; //////更正结算信息/////////// Close;SQL.Clear; SQL.Add('Select 客户名称, 类型, 原始币别 as 币别, 汇率,业务来源, 来源明细,揽货人,业务类型,分部名称,销售部门'); SQL.Add(',Sum(原始金额) as 金额'); SQL.Add('from v_fee_do_bscard_detail '); SQL.Add('where 1=1 '); if strtoint(get_parameters_value(140,'0'))=0 then SQL.Add(' and SUBSTRING(CONVERT(char(15),结算日期,111),1,7)='''+FormatDateTime('YYYY', EncodeDate(Logininfo.offyear,Logininfo.offmonth,1))+'/'+FormatDateTime('MM', EncodeDate(Logininfo.offyear,Logininfo.offmonth,1))+'''') else begin SQL.Add(' and 结算日期>'''+FormatDateTime('YYYY-MM-DD',Logininfo.endday)+''' AND 结算日期<'''+FormatDateTime('YYYY-MM-DD',Incmonth(Logininfo.endday+1))+''''); end; if aBsNo<>'' then SQL.Add('and b.业务编号='''+aBsNo+''''); SQL.Add('Group By 客户名称, 类型, 原始币别,汇率, 业务来源, 来源明细, 揽货人, 业务类型,分部名称,销售部门'); Open;First; I1:=0; I2:=RecordCount; while not Eof do begin Inc(I1); if Assigned(Proc) then Proc(nil, Format('实收实付数据:客户=%s, Rec : %d / %d', [aQuery.FieldByName('客户名称').AsString, I1, I2])); with aQuery2, SQL do begin Close;Clear; Add('Select Count(*) as rd from t_ch_custbalance'); Add('where 年='+aYear+' and 月='+aMonth); Add('and 客户名称='''+aQuery.FieldByName('客户名称').AsString+''''); Add('and 业务来源='''+aQuery.FieldByName('业务来源').AsString+''''); Add('and 来源明细='''+aQuery.FieldByName('来源明细').AsString+''''); Add('and 业务类型='''+aQuery.FieldByName('业务类型').AsString+''''); Add('and 揽货人='''+aQuery.FieldByName('揽货人').AsString+''''); Add('and 分部名称='''+aQuery.FieldByName('分部名称').AsString+''''); Add('and 销售部门='''+aQuery.FieldByName('销售部门').AsString+''''); Open; if Plus and (FieldByName('rd').AsInteger=0) then begin Close;Clear; Add('Insert Into t_ch_custbalance'); Add('(年,月,客户名称,业务来源,来源明细,业务类型,揽货人,分部名称,销售部门'); Add(',上月应收结余,本月应收发生,本月应收核销,本月应收结余,上月应收结余USD,本月应收发生USD'); Add(',本月应收核销USD,本月应收结余USD,上月应付结余,本月应付发生,本月应付核销,本月应付结余'); Add(',上月应付结余USD,本月应付发生USD,本月应付核销USD,本月应付结余USD'); Add(',上月应收结余合计,本月应收发生合计,本月应收核销合计,本月应收结余合计'); Add(',上月应付结余合计,本月应付发生合计,本月应付核销合计,本月应付结余合计)'); Add('Values('+aYear+','+aMonth+','''+aQuery.FieldByName('客户名称').AsString+''''); Add(','''+aQuery.FieldByName('业务来源').AsString+''''); Add(','''+aQuery.FieldByName('来源明细').AsString+''''); Add(','''+aQuery.FieldByName('业务类型').AsString+''''); Add(','''+aQuery.FieldByName('揽货人').AsString+''''); Add(','''+aQuery.FieldByName('分部名称').AsString+''''); Add(','''+aQuery.FieldByName('销售部门').AsString+''''); if aQuery.FieldByName('币别').AsString='RMB' then begin if aQuery.FieldByName('类型').AsString='收' then if aQuery.fieldbyname('金额').asfloat>=0 then Add(',0,0,'+aQuery.FieldByName('金额').AsString+',-'+aQuery.FieldByName('金额').AsString+',0,0,0,0,0,0,0,0,0,0,0,0,0,0,'+aQuery.FieldByName('金额').AsString+',-'+aQuery.FieldByName('金额').AsString+',0,0,0,0)') else Add(',0,0,'+aQuery.FieldByName('金额').AsString+','+floattostr(abs(aQuery.FieldByName('金额').Asfloat))+',0,0,0,0,0,0,0,0,0,0,0,0,0,0,'+aQuery.FieldByName('金额').AsString+','+floattostr(abs(aQuery.FieldByName('金额').Asfloat))+',0,0,0,0)') else if aQuery.fieldbyname('金额').asfloat>=0 then Add(',0,0,0,0,0,0,0,0,0,0,'+aQuery.FieldByName('金额').AsString+',-'+aQuery.FieldByName('金额').AsString+',0,0,0,0,0,0,0,0,0,0,'+aQuery.FieldByName('金额').AsString+',-'+aQuery.FieldByName('金额').AsString+')') else Add(',0,0,0,0,0,0,0,0,0,0,'+aQuery.FieldByName('金额').AsString+','+floattostr(abs(aQuery.FieldByName('金额').Asfloat))+',0,0,0,0,0,0,0,0,0,0,'+aQuery.FieldByName('金额').AsString+','+floattostr(abs(aQuery.FieldByName('金额').Asfloat))+')'); end else begin if aQuery.FieldByName('类型').AsString='收' then if aQuery.fieldbyname('金额').asfloat>=0 then Add(',0,0,0,0,0,0,'+aQuery.FieldByName('金额').AsString+',-'+aQuery.FieldByName('金额').AsString+',0,0,0,0,0,0,0,0,0,0,'+floattostr(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat)+',-'+floattostr(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat)+',0,0,0,0)') else Add(',0,0,0,0,0,0,'+aQuery.FieldByName('金额').AsString+','+floattostr(abs(aQuery.FieldByName('金额').Asfloat))+',0,0,0,0,0,0,0,0,0,0,'+floattostr(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat)+','+floattostr(Abs(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat))+',0,0,0,0)') else if aQuery.fieldbyname('金额').asfloat>=0 then Add(',0,0,0,0,0,0,0,0,0,0,0,0,0,0,'+aQuery.FieldByName('金额').AsString+',-'+aQuery.FieldByName('金额').AsString+',0,0,0,0,0,0,'+floattostr(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat)+',-'+floattostr(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat)+')') else Add(',0,0,0,0,0,0,0,0,0,0,0,0,0,0,'+aQuery.FieldByName('金额').AsString+','+floattostr(abs(aQuery.FieldByName('金额').Asfloat))+',0,0,0,0,0,0,'+floattostr(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat)+',-'+floattostr(abs(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat))+')'); end; end else begin Close;Clear; Add('Update t_ch_custbalance Set'); if aQuery.FieldByName('币别').AsString='RMB' then begin if aQuery.FieldByName('类型').AsString='收' then begin Add('本月应收核销=本月应收核销'+PlusChar+aQuery.FieldByName('金额').AsString+',本月应收核销合计=本月应收核销合计'+PlusChar+aQuery.FieldByName('金额').AsString); if aQuery.fieldbyname('金额').asfloat>=0 then Add(',本月应收结余=本月应收结余-'+aQuery.FieldByName('金额').AsString+',本月应收结余合计=本月应收结余合计-'+aQuery.FieldByName('金额').AsString) else Add(',本月应收结余=本月应收结余+'+floattostr(abs(aQuery.fieldbyname('金额').asfloat))+',本月应收结余合计=本月应收结余合计+'+floattostr(abs(aQuery.fieldbyname('金额').asfloat))); end else begin Add('本月应付核销=本月应付核销'+PlusChar+aQuery.FieldByName('金额').AsString+',本月应付核销合计=本月应付核销合计'+PlusChar+aQuery.FieldByName('金额').AsString); if aQuery.fieldbyname('金额').asfloat>=0 then Add(',本月应付结余=本月应付结余-'+aQuery.FieldByName('金额').AsString+',本月应付结余合计=本月应付结余合计-'+aQuery.FieldByName('金额').AsString) else Add(',本月应付结余=本月应付结余+'+floattostr(abs(aQuery.fieldbyname('金额').asfloat))+',本月应付结余合计=本月应付结余合计+'+floattostr(abs(aQuery.fieldbyname('金额').asfloat))); end; end else begin if aQuery.FieldByName('类型').AsString='收' then begin Add('本月应收核销USD=本月应收核销USD'+PlusChar+aQuery.FieldByName('金额').AsString+',本月应收核销合计=本月应收核销合计'+PlusChar+floattostr(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat)); if aQuery.fieldbyname('金额').asfloat>=0 then Add(',本月应收结余USD=本月应收结余USD-'+aQuery.FieldByName('金额').AsString+',本月应收结余合计=本月应收结余合计-'+floattostr(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat)) else Add(',本月应收结余USD=本月应收结余USD+'+floattostr(abs(aQuery.fieldbyname('金额').asfloat))+',本月应收结余合计=本月应收结余合计+'+floattostr(abs(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat))); end else begin Add('本月应付核销USD=本月应付核销USD'+PlusChar+aQuery.FieldByName('金额').AsString+',本月应付核销合计=本月应付核销合计'+PlusChar+floattostr(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat)); if aQuery.fieldbyname('金额').asfloat>=0 then Add(',本月应付结余USD=本月应付结余USD-'+aQuery.FieldByName('金额').AsString+',本月应付结余合计=本月应付结余合计-'+floattostr(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat)) else Add(',本月应付结余USD=本月应付结余USD+'+floattostr(abs(aQuery.fieldbyname('金额').asfloat))+',本月应付结余合计=本月应付结余合计+'+floattostr(abs(aQuery.FieldByName('金额').Asfloat*aQuery.FieldByName('汇率').Asfloat))); end; end; Add('where 年='+aYear+' and 月='+aMonth); Add('and 客户名称='''+aQuery.FieldByName('客户名称').AsString+''''); Add('and 业务来源='''+aQuery.FieldByName('业务来源').AsString+''''); Add('and 来源明细='''+aQuery.FieldByName('来源明细').AsString+''''); Add('and 业务类型='''+aQuery.FieldByName('业务类型').AsString+''''); Add('and 揽货人='''+aQuery.FieldByName('揽货人').AsString+''''); Add('and 分部名称='''+aQuery.FieldByName('分部名称').AsString+''''); Add('and 销售部门='''+aQuery.FieldByName('销售部门').AsString+''''); end; // if aQuery.FieldByName('客户名称').AsString='东旺' then // sql.SaveToFile('e:\e.txt'); ExecSQL; end; Next; end; finally Close; FreeAndNil(aQuery); aQuery2.Close; FreeAndNil(aQuery2); end; end; procedure TfrmAccCloseOff.FormShow(Sender: TObject); var aQuery : TAdoQuery; I : Integer; begin aStep:=0; Panel1.Visible:=false; //显示当前会计月 ComboBoxYear.Items.Clear; aQuery:=CreateAdoQuery; with aQuery do try EditYM.Text:=Format('%d 年 %d 月', [LoginInfo.OffYear, LoginInfo.OffMonth]); Close;SQL.Clear; SQL.Add('Select Distinct PYear from Period '); //order by period Open; First; while not Eof do begin ComboBoxYear.Items.Add(FieldByName('PYear').AsString); Next; end; ComboBoxYear.ItemIndex:=ComboBoxYear.Items.IndexOf(IntToStr(LoginInfo.OffYear)); Close;SQL.Clear; SQL.Add('Select * from Period order by period'); Open; memTblPeriod.Close; memTblPeriod.EmptyTable; memTblPeriod.Filtered:=false; memTblPeriod.Filter:='PYear='+ComboBoxYear.Items[ComboBoxYear.ItemIndex]; memTblPeriod.Filtered:=true; memTblPeriod.LoadFromDataSet(aQuery, []); finally Close;Free; end; end; procedure TfrmAccCloseOff.ComboBoxYearChange(Sender: TObject); begin with memTblPeriod do begin Filter:='PYear='+ComboBoxYear.Items[ComboBoxYear.ItemIndex]; if not Filtered then Filtered:=true; end; end; procedure TfrmAccCloseOff.bbtnExcuteClick(Sender: TObject); var aQuery, aQuery2 : TAdoQuery; TtlCount,offyear,offmonth,i,hc,nc,tyear,tmonth : Integer; aYear, aMonth,strdate,stredate,afyear,afMonth : String; bal,usdbal,rmbbal:double; YYYY,MM,DD :Word; begin //月末结账 aQuery:=CreateAdoQuery; aQuery2:=CreateAdoQuery; with aQuery do try Close;SQL.Clear; SQL.Add('select top 1 * from period where closed=''F'' order by period'); Open; offyear:=fieldbyname('pyear').asinteger; offmonth:=fieldbyname('pmonth').asinteger; if offmonth=1 then begin aYear:=inttostr(offyear-1); amonth:='12'; end else begin aYear:=inttostr(offyear); amonth:=inttostr(offmonth-1); end; if offmonth=12 then begin afYear:=inttostr(offyear+1); afmonth:='1'; end else begin afYear:=inttostr(offyear); afmonth:=inttostr(offmonth+1); end; bal:=0; usdbal:=0; rmbbal:=0; case aStep of 0 : begin { strdate:=FormatDateTime('YYYY-MM-DD',Logininfo.endday); stredate:=FormatDateTime('YYYY-MM-DD',Incmonth(Logininfo.endday)+1); } if strtoint(get_parameters_value(140,'0'))=0 then begin strdate:=FormatDateTime('YYYY-MM-DD',Logininfo.endday); YYYY:=YearOf(Incmonth(Logininfo.endday,2)); MM:=MonthOf(Incmonth(Logininfo.endday,2)); DD:=DaysInMonth(Incmonth(Logininfo.endday,2)); stredate:=FormatDateTime('YYYY-MM-DD',encodeDate(YYYY,MM,1)); end else begin strdate:=FormatDateTime('YYYY-MM-DD',Logininfo.endday); YYYY:=YearOf(Incmonth(Logininfo.endday,1)); MM:=MonthOf(Incmonth(Logininfo.endday,1)); stredate:=FormatDateTime('YYYY-MM-DD',encodeDate(YYYY,MM,strtoint(get_parameters_value(140,'0')))); end; // stredate:=FormatDateTime('YYYY-MM-DD',Incmonth(Logininfo.endday,2)); // ShowMessage(strdate+'________'+stredate); if strtobool(get_parameters_value(141,'false')) then begin i:=0; //本月发生的其他费用 memtotal.open; close;sql.clear; sql.Add('select * from v_op_fee where CONVERT(char(10), 结算日期, 120)>'''+strdate+''' and CONVERT(char(10), 结算日期, 120)<'''+stredate+''' order by 结算日期'); open; //showmessage(sql.Text+Inttostr(aQuery.recordcount)); first; while not eof do begin if fieldbyname('费用类型').AsInteger=1 then begin if fieldbyname('币别').AsString='' then begin if fieldbyname('人民币金额').Asfloat<>0 then begin memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=1; memtotal['年']:=offyear; memtotal['月']:=offmonth; memtotal['日']:=DayOf(FieldByName('结算日期').AsDateTime); memtotal['日期']:=FormatDateTime('YYYY-MM-DD',FieldByName('结算日期').AsDateTime); memtotal['摘要']:=fieldbyname('备注').asstring; memtotal['客户名称']:=fieldbyname('客户名称').asstring; if fieldbyname('结算方式').asstring='现金' then begin if trim(fieldbyname('银行代码').asstring)<>'' then begin memtotal['银行代码']:=fieldbyname('银行代码').asstring; memtotal['银行名称']:=fieldbyname('银行').asstring; end else memtotal['银行代码']:='现金' end else begin memtotal['银行代码']:=fieldbyname('银行代码').asstring; memtotal['银行名称']:=fieldbyname('银行').asstring; end; if fieldbyname('类型').AsString='收' then begin memtotal['借方金额']:=fieldbyname('人民币金额').Asfloat; memtotal['余额']:=bal+fieldbyname('人民币金额').Asfloat; memtotal['RMB借方金额']:=fieldbyname('人民币金额').Asfloat; end else begin memtotal['贷方金额']:=fieldbyname('人民币金额').Asfloat; memtotal['余额']:=bal-fieldbyname('人民币金额').Asfloat; memtotal['RMB贷方金额']:=fieldbyname('人民币金额').Asfloat; end; memtotal.post; end; if fieldbyname('美元金额').Asfloat<>0 then begin memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=1; memtotal['年']:=offyear; memtotal['月']:=offmonth; memtotal['日']:=DayOf(FieldByName('结算日期').AsDateTime); memtotal['日期']:=FormatDateTime('YYYY-MM-DD',FieldByName('结算日期').AsDateTime); memtotal['摘要']:=fieldbyname('备注').asstring; memtotal['客户名称']:=fieldbyname('客户名称').asstring; if fieldbyname('结算方式').asstring='现金' then begin if trim(fieldbyname('银行代码').asstring)<>'' then begin memtotal['银行代码']:=fieldbyname('银行代码').asstring; memtotal['银行名称']:=fieldbyname('银行').asstring; end else memtotal['银行代码']:='现金' end else begin memtotal['银行代码']:=fieldbyname('银行代码').asstring; memtotal['银行名称']:=fieldbyname('银行').asstring; end; if fieldbyname('类型').AsString='收' then begin memtotal['外币借方金额']:=fieldbyname('美元金额').Asfloat; memtotal['借方金额']:=fieldbyname('美元金额').Asfloat*GetUsdExrate(FormatDateTime('YYYY-MM-DD',FieldByName('结算日期').AsDateTime),FieldByName('币别').AsString); end else begin memtotal['外币贷方金额']:=fieldbyname('美元金额').Asfloat; memtotal['贷方金额']:=fieldbyname('美元金额').Asfloat*GetUsdExrate(FormatDateTime('YYYY-MM-DD',FieldByName('结算日期').AsDateTime),FieldByName('币别').AsString); end; memtotal.post; end; end else begin memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=1; memtotal['年']:=offyear; memtotal['月']:=offmonth; memtotal['日']:=DayOf(FieldByName('结算日期').AsDateTime); memtotal['日期']:=FieldByName('结算日期').AsDateTime; memtotal['摘要']:=fieldbyname('备注').asstring; memtotal['客户名称']:=fieldbyname('客户名称').asstring; if trim(fieldbyname('币别').AsString)='RMB' then begin if fieldbyname('结算方式').asstring='现金' then begin if trim(fieldbyname('银行代码').asstring)<>'' then begin memtotal['银行代码']:=fieldbyname('银行代码').asstring; memtotal['银行名称']:=fieldbyname('银行').asstring; end else memtotal['银行代码']:='现金' end else begin memtotal['银行代码']:=fieldbyname('银行代码').asstring; memtotal['银行名称']:=fieldbyname('银行').asstring; end; if fieldbyname('类型').AsString='收' then begin memtotal['借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['RMB借方金额']:=fieldbyname('结算金额').AsFloat; end else begin memtotal['贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['RMB贷方金额']:=fieldbyname('结算金额').AsFloat; end; end else begin if fieldbyname('结算方式').asstring='现金' then begin if trim(fieldbyname('银行代码').asstring)<>'' then begin memtotal['银行代码']:=fieldbyname('银行代码').asstring; memtotal['银行名称']:=fieldbyname('银行').asstring; end else memtotal['银行代码']:='现金' end else begin memtotal['银行代码']:=fieldbyname('银行代码').asstring; memtotal['银行名称']:=fieldbyname('银行').asstring; end; if fieldbyname('类型').AsString='收' then begin memtotal['外币借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['借方金额']:=fieldbyname('结算金额').AsFloat*GetUsdExrate(FormatDateTime('YYYY-MM-DD',FieldByName('结算日期').AsDateTime),FieldByName('币别').AsString); end else begin memtotal['外币贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['贷方金额']:=fieldbyname('结算金额').AsFloat*GetUsdExrate(FormatDateTime('YYYY-MM-DD',FieldByName('结算日期').AsDateTime),FieldByName('币别').AsString); end; end; memtotal.post; end; end else begin memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=1; memtotal['年']:=offyear; memtotal['月']:=offmonth; memtotal['日']:=DayOf(FieldByName('结算日期').AsDateTime); memtotal['日期']:=FieldByName('结算日期').AsDateTime; memtotal['摘要']:=fieldbyname('备注').asstring; memtotal['客户名称']:=fieldbyname('客户名称').asstring; if fieldbyname('结算方式').asstring='现金' then begin if trim(fieldbyname('银行代码').asstring)<>'' then begin memtotal['银行代码']:=fieldbyname('银行代码').asstring; memtotal['银行名称']:=fieldbyname('银行').asstring; end else memtotal['银行代码']:='现金' end else begin memtotal['银行代码']:=fieldbyname('银行代码').asstring; memtotal['银行名称']:=fieldbyname('银行').asstring; end; // memtotal['银行代码']:=fieldbyname('银行代码').asstring; // memtotal['银行名称']:=fieldbyname('银行').asstring; if trim(fieldbyname('币别').AsString)='RMB' then begin if (fieldbyname('类型').AsString='收费') or (fieldbyname('类型').AsString='收') then begin memtotal['借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['RMB借方金额']:=fieldbyname('结算金额').AsFloat; end else begin memtotal['贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['RMB贷方金额']:=fieldbyname('结算金额').AsFloat; end; end else begin if (fieldbyname('类型').AsString='收费') or (fieldbyname('类型').AsString='收') then begin memtotal['外币借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['借方金额']:=fieldbyname('结算金额').AsFloat*GetUsdExrate(FormatDateTime('YYYY-MM-DD',FieldByName('结算日期').AsDateTime),FieldByName('币别').AsString); end else begin memtotal['外币贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['贷方金额']:=fieldbyname('结算金额').AsFloat*GetUsdExrate(FormatDateTime('YYYY-MM-DD',FieldByName('结算日期').AsDateTime),FieldByName('币别').AsString); end; end; memtotal.post; end; Next; end; end; // ShowMessage(IntToStr(memtotal.RecordCount)); { memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=2; memtotal['年']:=offyear; memtotal['月']:=offmonth; memtotal['摘要']:='本月累计'; memtotal['借方金额']:=DR; memtotal['贷方金额']:=CR; memtotal['余额']:=bal; memtotal['外币借方金额']:=USDDR; memtotal['外币贷方金额']:=USDCR; memtotal['外币余额']:=usdbal; memtotal.post; } if strtobool(get_parameters_value(142,'false')) then begin close;sql.clear; if strtobool(get_parameters_value(199,'false')) then sql.Add('select count(*) as rd from v_op_bscard where 开船日期>'''+strdate+''' and 开船日期<'''+stredate+'''') else sql.Add('select count(*) as rd from v_op_bscard where 会计期间>'''+strdate+''' and 会计期间<'''+stredate+''''); open; ttlcount:=fieldbyname('rd').asinteger; close;sql.clear; if strtobool(get_parameters_value(199,'false')) then sql.Add('select count(*) as rd from v_op_bscard where 费用状态=''费用封帐'' and 开船日期>'''+strdate+''' and 开船日期<'''+stredate+'''') else sql.Add('select count(*) as rd from v_op_bscard where 费用状态=''费用封帐'' and 会计期间>'''+strdate+''' and 会计期间<'''+stredate+''''); open; hc:=fieldbyname('rd').asinteger; if (strtoint(get_parameters_value(137,'0'))=1) then begin //如果会计期间是本月但开船日期是下月统一成下月 close;sql.clear; sql.Add('select count(*) as rd from v_op_bscard where 业务类型=''普通货'' and 费用状态<>''费用封帐'' and 会计期间>'''+strdate+''' and 会计期间<'''+stredate+''' and 开船日期>='''+stredate+''''); open; if Recordset.RecordCount>0 then begin close;sql.clear; sql.Add('update t_op_seae set 会计期间=开船日期 where 业务类型=''普通货'' and 费用状态<>''费用封帐'' and 会计期间>'''+strdate+''' and 会计期间<'''+stredate+''' and 开船日期>='''+stredate+''''); ExecSQL; close;sql.clear; sql.Add('update t_op_seai set 会计期间=进口日期 where 业务类型=''普通货'' and 费用状态<>''费用封帐'' and 会计期间>'''+strdate+''' and 会计期间<'''+stredate+''' and 进口日期>='''+stredate+''''); ExecSQL; close;sql.clear; sql.Add('update t_op_aire set 会计期间=一程开航日期 where 业务类型=''普通货'' and 费用状态<>''费用封帐'' and 会计期间>'''+strdate+''' and 会计期间<'''+stredate+''' and 一程开航日期>='''+stredate+''''); ExecSQL; close;sql.clear; sql.Add('update t_op_airi set 会计期间=进口日期 where 业务类型=''普通货'' and 费用状态<>''费用封帐'' and 会计期间>'''+strdate+''' and 会计期间<'''+stredate+''' and 进口日期>='''+stredate+''''); ExecSQL; end; end; //查询出还未费用封帐的业务 close;sql.clear; if strtobool(get_parameters_value(199,'false')) then sql.Add('select count(*) as rd from v_op_bscard where 费用状态<>''费用封帐'' and 开船日期>'''+strdate+''' and 开船日期<'''+stredate+'''') else sql.Add('select count(*) as rd from v_op_bscard where 费用状态<>''费用封帐'' and 会计期间>'''+strdate+''' and 会计期间<'''+stredate+''''); open; nc:=fieldbyname('rd').asinteger; if nc<>0 then begin v_op_bscard.Close; v_op_bscard.sql.clear; if strtobool(get_parameters_value(199,'false')) then v_op_bscard.sql.Add('select * from v_op_bscard where 费用状态<>''费用封帐'' and 开船日期>'''+strdate+''' and 开船日期<'''+stredate+'''') else v_op_bscard.sql.Add('select * from v_op_bscard where 费用状态<>''费用封帐'' and 会计期间>'''+strdate+''' and 会计期间<'''+stredate+''''); v_op_bscard.Open; if MessageDlg('本期'+strdate+' 至 '+stredate+'尚有 '+inttostr(nc)+' 票业务没有费用封帐,是否将业务结转到下一期间',mtWarning,[mbyes,mbno],0)=mryes then begin Panel1.Visible:=true; DateTimePicker1.date:=Logininfo.endday; DateTimePicker1.date:=Incmonth(Logininfo.endday)+1; DateTimePicker2.date:=Logininfo.endday; DateTimePicker2.date:=Incmonth(Logininfo.endday)+1; MemoMsg.Clear; MemoMsg.Lines.Add('注意:'); MemoMsg.Lines.Add(' 转帐后所有本期应收、应付结算将不允许修改,如果确认要转帐,请点击“完成”按钮!'); MemoMsg.Font.Color:=clRed; bbtnExcute.Caption:='完成!'; aStep:=1; end else begin v_op_bscard.Close; v_op_bscard.sql.clear; if strtobool(get_parameters_value(199,'false')) then v_op_bscard.sql.Add('select * from v_op_bscard where 费用状态<>''费用封帐'' and 开船日期>'''+strdate+''' and 开船日期<'''+stredate+'''') else v_op_bscard.sql.Add('select * from v_op_bscard where 费用状态<>''费用封帐'' and 会计期间>'''+strdate+''' and 会计期间<'''+stredate+''''); v_op_bscard.Open; MemoMsg.Clear; MemoMsg.Lines.Add('注意:'); MemoMsg.Lines.Add(' 本期尚有 '+inttostr(nc)+' 票业务没有费用封帐!'); bbtnExcute.Enabled:=false; MemoMsg.Font.Color:=clRed; end; end else begin MemoMsg.Clear; MemoMsg.Lines.Add('注意:'); MemoMsg.Lines.Add(' 转帐后所有本期应收、应付结算将不允许修改,如果确认要转帐,请点击“完成”按钮!'); MemoMsg.Font.Color:=clRed; bbtnExcute.Caption:='完成!'; aStep:=1; end; end; end; 1 : begin bsSkinPanel1.Visible:=true; bsSkinPanel1.Update; bbtnExcute.Enabled:=false; frm_main.db.BeginTrans; //aYear、aMonth 实际上是下一期间 if strtobool(get_parameters_value(141,'false')) then begin //其他费用生成总账 Close;SQL.Clear; SQL.Add('Delete from t_ch_bank_genleg'); SQL.Add('where 年='+inttostr(offYear)+' and 月='+inttostr(offMonth)); ExecSQL; Close;SQL.Clear; SQL.Add('Delete from t_ch_cust_genleg'); SQL.Add('where 年='+inttostr(offYear)+' and 月='+inttostr(offMonth)); ExecSQL; Close;SQL.Clear; SQL.Add('Delete from t_ch_genleg'); SQL.Add('where 年='+inttostr(offYear)+' and 月='+inttostr(offMonth)); ExecSQL; Close;SQL.Clear; SQL.Add('Insert Into t_ch_bank_genleg'); SQL.Add('(年,月,银行代码,银行名称'); SQL.Add(',累计借方,累计贷方,累计余额,本月借方,本月贷方,本月余额'); SQL.Add(',USD累计借方,USD累计贷方,USD累计余额,USD本月借方,USD本月贷方,USD本月余额'); SQL.Add(',RMB累计借方,RMB累计贷方,RMB累计余额,RMB本月借方,RMB本月贷方,RMB本月余额)'); SQL.Add('Select '+IntToStr(OffYear)+','+IntToStr(OffMonth)); SQL.Add(',银行代码,银行名称'); SQL.Add(',累计借方,累计贷方,累计余额,0,0,0'); SQL.Add(',USD累计借方,USD累计贷方,USD累计余额,0,0,0'); SQL.Add(',RMB累计借方,RMB累计贷方,RMB累计余额,0,0,0'); SQL.Add('from t_ch_bank_genleg'); SQL.Add('where 年='+aYear+' and 月='+aMonth); ExecSQL; Close;SQL.Clear; SQL.Add('Insert Into t_ch_cust_genleg'); SQL.Add('(年,月,客户名称'); SQL.Add(',累计借方,累计贷方,累计余额,本月借方,本月贷方,本月余额'); SQL.Add(',USD累计借方,USD累计贷方,USD累计余额,USD本月借方,USD本月贷方,USD本月余额'); SQL.Add(',RMB累计借方,RMB累计贷方,RMB累计余额,RMB本月借方,RMB本月贷方,RMB本月余额)'); SQL.Add('Select '+IntToStr(OffYear)+','+IntToStr(OffMonth)); SQL.Add(',客户名称'); SQL.Add(',累计借方,累计贷方,累计余额,0,0,0'); SQL.Add(',USD累计借方,USD累计贷方,USD累计余额,0,0,0'); SQL.Add(',RMB累计借方,RMB累计贷方,RMB累计余额,0,0,0'); SQL.Add('from t_ch_cust_genleg'); SQL.Add('where 年='+aYear+' and 月='+aMonth); ExecSQL; Close;SQL.Clear; SQL.Add('Insert Into t_ch_genleg'); SQL.Add('(年,月'); SQL.Add(',累计借方,累计贷方,累计余额,本月借方,本月贷方,本月余额'); SQL.Add(',USD累计借方,USD累计贷方,USD累计余额,USD本月借方,USD本月贷方,USD本月余额'); SQL.Add(',RMB累计借方,RMB累计贷方,RMB累计余额,RMB本月借方,RMB本月贷方,RMB本月余额)'); SQL.Add('Select '+IntToStr(OffYear)+','+IntToStr(OffMonth)); SQL.Add(',累计借方+本月借方,累计贷方,累计余额,0,0,0'); SQL.Add(',USD累计借方,USD累计贷方,USD累计余额,0,0,0'); SQL.Add(',RMB累计借方,RMB累计贷方,RMB累计余额,0,0,0'); SQL.Add('from t_ch_genleg'); SQL.Add('where 年='+aYear+' and 月='+aMonth); ExecSQL; t_ch_bank_genleg.Close; t_ch_bank_genleg.Parameters.ParamByName('年').Value:=inttostr(offYear); t_ch_bank_genleg.Parameters.ParamByName('月').Value:=inttostr(offMonth); t_ch_bank_genleg.open; t_ch_cust_genleg.Close; t_ch_cust_genleg.Parameters.ParamByName('年').Value:=inttostr(offYear); t_ch_cust_genleg.Parameters.ParamByName('月').Value:=inttostr(offMonth); t_ch_cust_genleg.open; t_ch_genleg.Close; t_ch_genleg.Parameters.ParamByName('年').Value:=inttostr(offYear); t_ch_genleg.Parameters.ParamByName('月').Value:=inttostr(offMonth); t_ch_genleg.open; with memtotal do begin First; while not eof do begin if t_ch_genleg.IsEmpty then begin t_ch_genleg.Insert; t_ch_genleg.FieldByName('年').AsString:=inttostr(offyear); t_ch_genleg.FieldByName('月').AsString:=inttostr(offmonth); if memtotal.fieldbyname('借方金额').AsFloat<>0 then begin t_ch_genleg.FieldByName('累计借方').Asfloat:=memtotal.fieldbyname('借方金额').AsFloat; t_ch_genleg.FieldByName('本月借方').Asfloat:=memtotal.fieldbyname('借方金额').AsFloat; t_ch_genleg.FieldByName('累计余额').Asfloat:=t_ch_genleg.FieldByName('累计余额').Asfloat+memtotal.fieldbyname('借方金额').AsFloat; t_ch_genleg.FieldByName('本月余额').Asfloat:=t_ch_genleg.FieldByName('本月余额').Asfloat+memtotal.fieldbyname('借方金额').AsFloat; end; if memtotal.fieldbyname('贷方金额').AsFloat<>0 then begin t_ch_genleg.FieldByName('累计贷方').Asfloat:=memtotal.fieldbyname('贷方金额').AsFloat; t_ch_genleg.FieldByName('本月贷方').Asfloat:=memtotal.fieldbyname('贷方金额').AsFloat; t_ch_genleg.FieldByName('累计余额').Asfloat:=t_ch_genleg.FieldByName('累计余额').Asfloat-memtotal.fieldbyname('贷方金额').AsFloat; t_ch_genleg.FieldByName('本月余额').Asfloat:=t_ch_genleg.FieldByName('本月余额').Asfloat-memtotal.fieldbyname('贷方金额').AsFloat; end; if memtotal.fieldbyname('外币借方金额').AsFloat<>0 then begin t_ch_genleg.FieldByName('USD累计借方').Asfloat:=memtotal.fieldbyname('外币借方金额').AsFloat; t_ch_genleg.FieldByName('USD本月借方').Asfloat:=memtotal.fieldbyname('外币借方金额').AsFloat; t_ch_genleg.FieldByName('USD累计余额').Asfloat:=t_ch_genleg.FieldByName('USD累计余额').Asfloat+memtotal.fieldbyname('外币借方金额').AsFloat; t_ch_genleg.FieldByName('USD本月余额').Asfloat:=t_ch_genleg.FieldByName('USD本月余额').Asfloat+memtotal.fieldbyname('外币借方金额').AsFloat; end; if memtotal.fieldbyname('外币贷方金额').AsFloat<>0 then begin t_ch_genleg.FieldByName('USD累计贷方').Asfloat:=memtotal.fieldbyname('外币贷方金额').AsFloat; t_ch_genleg.FieldByName('USD本月贷方').Asfloat:=memtotal.fieldbyname('外币贷方金额').AsFloat; t_ch_genleg.FieldByName('USD累计余额').Asfloat:=t_ch_genleg.FieldByName('USD累计余额').Asfloat-memtotal.fieldbyname('外币贷方金额').AsFloat; t_ch_genleg.FieldByName('USD本月余额').Asfloat:=t_ch_genleg.FieldByName('USD本月余额').Asfloat-memtotal.fieldbyname('外币贷方金额').AsFloat; end; if memtotal.fieldbyname('RMB借方金额').AsFloat<>0 then begin t_ch_genleg.FieldByName('RMB累计借方').Asfloat:=memtotal.fieldbyname('RMB借方金额').AsFloat; t_ch_genleg.FieldByName('RMB本月借方').Asfloat:=memtotal.fieldbyname('RMB借方金额').AsFloat; t_ch_genleg.FieldByName('RMB累计余额').Asfloat:=t_ch_genleg.FieldByName('RMB累计余额').Asfloat+memtotal.fieldbyname('RMB借方金额').AsFloat; t_ch_genleg.FieldByName('RMB本月余额').Asfloat:=t_ch_genleg.FieldByName('RMB本月余额').Asfloat+memtotal.fieldbyname('RMB借方金额').AsFloat; end; if memtotal.fieldbyname('RMB贷方金额').AsFloat<>0 then begin t_ch_genleg.FieldByName('RMB累计贷方').Asfloat:=memtotal.fieldbyname('RMB贷方金额').AsFloat; t_ch_genleg.FieldByName('RMB本月贷方').Asfloat:=memtotal.fieldbyname('RMB贷方金额').AsFloat; t_ch_genleg.FieldByName('RMB累计余额').Asfloat:=t_ch_genleg.FieldByName('RMB累计余额').Asfloat-memtotal.fieldbyname('RMB贷方金额').AsFloat; t_ch_genleg.FieldByName('RMB本月余额').Asfloat:=t_ch_genleg.FieldByName('RMB本月余额').Asfloat-memtotal.fieldbyname('RMB贷方金额').AsFloat; end; t_ch_genleg.post; end else begin t_ch_genleg.Edit; if memtotal.fieldbyname('借方金额').AsFloat<>0 then begin t_ch_genleg.FieldByName('累计借方').Asfloat:=t_ch_genleg.FieldByName('累计借方').Asfloat+memtotal.fieldbyname('借方金额').AsFloat; t_ch_genleg.FieldByName('本月借方').Asfloat:=t_ch_genleg.FieldByName('本月借方').Asfloat+memtotal.fieldbyname('借方金额').AsFloat; t_ch_genleg.FieldByName('累计余额').Asfloat:=t_ch_genleg.FieldByName('累计余额').Asfloat+memtotal.fieldbyname('借方金额').AsFloat; t_ch_genleg.FieldByName('本月余额').Asfloat:=t_ch_genleg.FieldByName('本月余额').Asfloat+memtotal.fieldbyname('借方金额').AsFloat; end; if memtotal.fieldbyname('贷方金额').AsFloat<>0 then begin t_ch_genleg.FieldByName('累计贷方').Asfloat:=t_ch_genleg.FieldByName('累计贷方').Asfloat+memtotal.fieldbyname('贷方金额').AsFloat; t_ch_genleg.FieldByName('本月贷方').Asfloat:=t_ch_genleg.FieldByName('本月贷方').Asfloat+memtotal.fieldbyname('贷方金额').AsFloat; t_ch_genleg.FieldByName('累计余额').Asfloat:=t_ch_genleg.FieldByName('累计余额').Asfloat-memtotal.fieldbyname('贷方金额').AsFloat; t_ch_genleg.FieldByName('本月余额').Asfloat:=t_ch_genleg.FieldByName('本月余额').Asfloat-memtotal.fieldbyname('贷方金额').AsFloat; end; if memtotal.fieldbyname('外币借方金额').AsFloat<>0 then begin t_ch_genleg.FieldByName('USD累计借方').Asfloat:=t_ch_genleg.FieldByName('USD累计借方').Asfloat+memtotal.fieldbyname('外币借方金额').AsFloat; t_ch_genleg.FieldByName('USD本月借方').Asfloat:=t_ch_genleg.FieldByName('USD本月借方').Asfloat+memtotal.fieldbyname('外币借方金额').AsFloat; t_ch_genleg.FieldByName('USD累计余额').Asfloat:=t_ch_genleg.FieldByName('USD累计余额').Asfloat+memtotal.fieldbyname('外币借方金额').AsFloat; t_ch_genleg.FieldByName('USD本月余额').Asfloat:=t_ch_genleg.FieldByName('USD本月余额').Asfloat+memtotal.fieldbyname('外币借方金额').AsFloat; end; if memtotal.fieldbyname('外币贷方金额').AsFloat<>0 then begin t_ch_genleg.FieldByName('USD累计贷方').Asfloat:=t_ch_genleg.FieldByName('USD累计贷方').Asfloat+memtotal.fieldbyname('外币贷方金额').AsFloat; t_ch_genleg.FieldByName('USD本月贷方').Asfloat:=t_ch_genleg.FieldByName('USD本月贷方').Asfloat+memtotal.fieldbyname('外币贷方金额').AsFloat; t_ch_genleg.FieldByName('USD累计余额').Asfloat:=t_ch_genleg.FieldByName('USD累计余额').Asfloat-memtotal.fieldbyname('外币贷方金额').AsFloat; t_ch_genleg.FieldByName('USD本月余额').Asfloat:=t_ch_genleg.FieldByName('USD本月余额').Asfloat-memtotal.fieldbyname('外币贷方金额').AsFloat; end; if memtotal.fieldbyname('RMB借方金额').AsFloat<>0 then begin t_ch_genleg.FieldByName('RMB累计借方').Asfloat:=t_ch_genleg.FieldByName('RMB累计借方').Asfloat+memtotal.fieldbyname('RMB借方金额').AsFloat; t_ch_genleg.FieldByName('RMB本月借方').Asfloat:=t_ch_genleg.FieldByName('RMB本月借方').Asfloat+memtotal.fieldbyname('RMB借方金额').AsFloat; t_ch_genleg.FieldByName('RMB累计余额').Asfloat:=t_ch_genleg.FieldByName('RMB累计余额').Asfloat+memtotal.fieldbyname('RMB借方金额').AsFloat; t_ch_genleg.FieldByName('RMB本月余额').Asfloat:=t_ch_genleg.FieldByName('RMB本月余额').Asfloat+memtotal.fieldbyname('RMB借方金额').AsFloat; end; if memtotal.fieldbyname('RMB贷方金额').AsFloat<>0 then begin t_ch_genleg.FieldByName('RMB累计贷方').Asfloat:=t_ch_genleg.FieldByName('RMB累计贷方').Asfloat+memtotal.fieldbyname('RMB贷方金额').AsFloat; t_ch_genleg.FieldByName('RMB本月贷方').Asfloat:=t_ch_genleg.FieldByName('RMB本月贷方').Asfloat+memtotal.fieldbyname('RMB贷方金额').AsFloat; t_ch_genleg.FieldByName('RMB累计余额').Asfloat:=t_ch_genleg.FieldByName('RMB累计余额').Asfloat-memtotal.fieldbyname('RMB贷方金额').AsFloat; t_ch_genleg.FieldByName('RMB本月余额').Asfloat:=t_ch_genleg.FieldByName('RMB本月余额').Asfloat-memtotal.fieldbyname('RMB贷方金额').AsFloat; end; t_ch_genleg.post; end; if not t_ch_bank_genleg.Locate('银行代码',memtotal.Fieldbyname('银行代码').AsString,[]) then begin t_ch_bank_genleg.Insert; t_ch_bank_genleg.FieldByName('年').AsString:=inttostr(offyear); t_ch_bank_genleg.FieldByName('月').AsString:=inttostr(offmonth); t_ch_bank_genleg.FieldByName('银行代码').AsString:=memtotal.fieldbyname('银行代码').AsString; t_ch_bank_genleg.FieldByName('银行名称').AsString:=memtotal.fieldbyname('银行名称').AsString; if memtotal.fieldbyname('借方金额').AsFloat<>0 then begin t_ch_bank_genleg.FieldByName('累计借方').Asfloat:=memtotal.fieldbyname('借方金额').AsFloat; t_ch_bank_genleg.FieldByName('本月借方').Asfloat:=memtotal.fieldbyname('借方金额').AsFloat; t_ch_bank_genleg.FieldByName('累计余额').Asfloat:=t_ch_bank_genleg.FieldByName('累计余额').Asfloat+memtotal.fieldbyname('借方金额').AsFloat; t_ch_bank_genleg.FieldByName('本月余额').Asfloat:=t_ch_bank_genleg.FieldByName('本月余额').Asfloat+memtotal.fieldbyname('借方金额').AsFloat; end; if memtotal.fieldbyname('贷方金额').AsFloat<>0 then begin t_ch_bank_genleg.FieldByName('累计贷方').Asfloat:=memtotal.fieldbyname('贷方金额').AsFloat; t_ch_bank_genleg.FieldByName('本月贷方').Asfloat:=memtotal.fieldbyname('贷方金额').AsFloat; t_ch_bank_genleg.FieldByName('累计余额').Asfloat:=t_ch_bank_genleg.FieldByName('累计余额').Asfloat-memtotal.fieldbyname('贷方金额').AsFloat; t_ch_bank_genleg.FieldByName('本月余额').Asfloat:=t_ch_bank_genleg.FieldByName('本月余额').Asfloat-memtotal.fieldbyname('贷方金额').AsFloat; end; if memtotal.fieldbyname('外币借方金额').AsFloat<>0 then begin t_ch_bank_genleg.FieldByName('USD累计借方').Asfloat:=memtotal.fieldbyname('外币借方金额').AsFloat; t_ch_bank_genleg.FieldByName('USD本月借方').Asfloat:=memtotal.fieldbyname('外币借方金额').AsFloat; t_ch_bank_genleg.FieldByName('USD累计余额').Asfloat:=t_ch_bank_genleg.FieldByName('USD累计余额').Asfloat+memtotal.fieldbyname('外币借方金额').AsFloat; t_ch_bank_genleg.FieldByName('USD本月余额').Asfloat:=t_ch_bank_genleg.FieldByName('USD本月余额').Asfloat+memtotal.fieldbyname('外币借方金额').AsFloat; end; if memtotal.fieldbyname('外币贷方金额').AsFloat<>0 then begin t_ch_bank_genleg.FieldByName('USD累计贷方').Asfloat:=memtotal.fieldbyname('外币贷方金额').AsFloat; t_ch_bank_genleg.FieldByName('USD本月贷方').Asfloat:=memtotal.fieldbyname('外币贷方金额').AsFloat; t_ch_bank_genleg.FieldByName('USD累计余额').Asfloat:=t_ch_bank_genleg.FieldByName('USD累计余额').Asfloat-memtotal.fieldbyname('外币贷方金额').AsFloat; t_ch_bank_genleg.FieldByName('USD本月余额').Asfloat:=t_ch_bank_genleg.FieldByName('USD本月余额').Asfloat-memtotal.fieldbyname('外币贷方金额').AsFloat; end; if memtotal.fieldbyname('RMB借方金额').AsFloat<>0 then begin t_ch_bank_genleg.FieldByName('RMB累计借方').Asfloat:=memtotal.fieldbyname('RMB借方金额').AsFloat; t_ch_bank_genleg.FieldByName('RMB本月借方').Asfloat:=memtotal.fieldbyname('RMB借方金额').AsFloat; t_ch_bank_genleg.FieldByName('RMB累计余额').Asfloat:=t_ch_bank_genleg.FieldByName('RMB累计余额').Asfloat+memtotal.fieldbyname('RMB借方金额').AsFloat; t_ch_bank_genleg.FieldByName('RMB本月余额').Asfloat:=t_ch_bank_genleg.FieldByName('RMB本月余额').Asfloat+memtotal.fieldbyname('RMB借方金额').AsFloat; end; if memtotal.fieldbyname('RMB贷方金额').AsFloat<>0 then begin t_ch_bank_genleg.FieldByName('RMB累计贷方').Asfloat:=memtotal.fieldbyname('RMB贷方金额').AsFloat; t_ch_bank_genleg.FieldByName('RMB本月贷方').Asfloat:=memtotal.fieldbyname('RMB贷方金额').AsFloat; t_ch_bank_genleg.FieldByName('RMB累计余额').Asfloat:=t_ch_bank_genleg.FieldByName('RMB累计余额').Asfloat-memtotal.fieldbyname('RMB贷方金额').AsFloat; t_ch_bank_genleg.FieldByName('RMB本月余额').Asfloat:=t_ch_bank_genleg.FieldByName('RMB本月余额').Asfloat-memtotal.fieldbyname('RMB贷方金额').AsFloat; end; t_ch_bank_genleg.post; end else begin t_ch_bank_genleg.Edit; if memtotal.fieldbyname('借方金额').AsFloat<>0 then begin t_ch_bank_genleg.FieldByName('累计借方').Asfloat:=t_ch_bank_genleg.FieldByName('累计借方').Asfloat+memtotal.fieldbyname('借方金额').AsFloat; t_ch_bank_genleg.FieldByName('本月借方').Asfloat:=t_ch_bank_genleg.FieldByName('本月借方').Asfloat+memtotal.fieldbyname('借方金额').AsFloat; t_ch_bank_genleg.FieldByName('累计余额').Asfloat:=t_ch_bank_genleg.FieldByName('累计余额').Asfloat+memtotal.fieldbyname('借方金额').AsFloat; t_ch_bank_genleg.FieldByName('本月余额').Asfloat:=t_ch_bank_genleg.FieldByName('本月余额').Asfloat+memtotal.fieldbyname('借方金额').AsFloat; end; if memtotal.fieldbyname('贷方金额').AsFloat<>0 then begin t_ch_bank_genleg.FieldByName('累计贷方').Asfloat:=t_ch_bank_genleg.FieldByName('累计贷方').Asfloat+memtotal.fieldbyname('贷方金额').AsFloat; t_ch_bank_genleg.FieldByName('本月贷方').Asfloat:=t_ch_bank_genleg.FieldByName('本月贷方').Asfloat+memtotal.fieldbyname('贷方金额').AsFloat; t_ch_bank_genleg.FieldByName('累计余额').Asfloat:=t_ch_bank_genleg.FieldByName('累计余额').Asfloat-memtotal.fieldbyname('贷方金额').AsFloat; t_ch_bank_genleg.FieldByName('本月余额').Asfloat:=t_ch_bank_genleg.FieldByName('本月余额').Asfloat-memtotal.fieldbyname('贷方金额').AsFloat; end; if memtotal.fieldbyname('外币借方金额').AsFloat<>0 then begin t_ch_bank_genleg.FieldByName('USD累计借方').Asfloat:=t_ch_bank_genleg.FieldByName('USD累计借方').Asfloat+memtotal.fieldbyname('外币借方金额').AsFloat; t_ch_bank_genleg.FieldByName('USD本月借方').Asfloat:=t_ch_bank_genleg.FieldByName('USD本月借方').Asfloat+memtotal.fieldbyname('外币借方金额').AsFloat; t_ch_bank_genleg.FieldByName('USD累计余额').Asfloat:=t_ch_bank_genleg.FieldByName('USD累计余额').Asfloat+memtotal.fieldbyname('外币借方金额').AsFloat; t_ch_bank_genleg.FieldByName('USD本月余额').Asfloat:=t_ch_bank_genleg.FieldByName('USD本月余额').Asfloat+memtotal.fieldbyname('外币借方金额').AsFloat; end; if memtotal.fieldbyname('外币贷方金额').AsFloat<>0 then begin t_ch_bank_genleg.FieldByName('USD累计贷方').Asfloat:=t_ch_bank_genleg.FieldByName('USD累计贷方').Asfloat+memtotal.fieldbyname('外币贷方金额').AsFloat; t_ch_bank_genleg.FieldByName('USD本月贷方').Asfloat:=t_ch_bank_genleg.FieldByName('USD本月贷方').Asfloat+memtotal.fieldbyname('外币贷方金额').AsFloat; t_ch_bank_genleg.FieldByName('USD累计余额').Asfloat:=t_ch_bank_genleg.FieldByName('USD累计余额').Asfloat-memtotal.fieldbyname('外币贷方金额').AsFloat; t_ch_bank_genleg.FieldByName('USD本月余额').Asfloat:=t_ch_bank_genleg.FieldByName('USD本月余额').Asfloat-memtotal.fieldbyname('外币贷方金额').AsFloat; end; if memtotal.fieldbyname('RMB借方金额').AsFloat<>0 then begin t_ch_bank_genleg.FieldByName('RMB累计借方').Asfloat:=t_ch_bank_genleg.FieldByName('RMB累计借方').Asfloat+memtotal.fieldbyname('RMB借方金额').AsFloat; t_ch_bank_genleg.FieldByName('RMB本月借方').Asfloat:=t_ch_bank_genleg.FieldByName('RMB本月借方').Asfloat+memtotal.fieldbyname('RMB借方金额').AsFloat; t_ch_bank_genleg.FieldByName('RMB累计余额').Asfloat:=t_ch_bank_genleg.FieldByName('RMB累计余额').Asfloat+memtotal.fieldbyname('RMB借方金额').AsFloat; t_ch_bank_genleg.FieldByName('RMB本月余额').Asfloat:=t_ch_bank_genleg.FieldByName('RMB本月余额').Asfloat+memtotal.fieldbyname('RMB借方金额').AsFloat; end; if memtotal.fieldbyname('RMB贷方金额').AsFloat<>0 then begin t_ch_bank_genleg.FieldByName('RMB累计贷方').Asfloat:=t_ch_bank_genleg.FieldByName('RMB累计贷方').Asfloat+memtotal.fieldbyname('RMB贷方金额').AsFloat; t_ch_bank_genleg.FieldByName('RMB本月贷方').Asfloat:=t_ch_bank_genleg.FieldByName('RMB本月贷方').Asfloat+memtotal.fieldbyname('RMB贷方金额').AsFloat; t_ch_bank_genleg.FieldByName('RMB累计余额').Asfloat:=t_ch_bank_genleg.FieldByName('RMB累计余额').Asfloat-memtotal.fieldbyname('RMB贷方金额').AsFloat; t_ch_bank_genleg.FieldByName('RMB本月余额').Asfloat:=t_ch_bank_genleg.FieldByName('RMB本月余额').Asfloat-memtotal.fieldbyname('RMB贷方金额').AsFloat; end; t_ch_bank_genleg.post; end; if not t_ch_cust_genleg.Locate('客户名称',memtotal.Fieldbyname('客户名称').AsString,[]) then begin t_ch_cust_genleg.Insert; t_ch_cust_genleg.FieldByName('年').AsString:=inttostr(offyear); t_ch_cust_genleg.FieldByName('月').AsString:=inttostr(offmonth); t_ch_cust_genleg.FieldByName('客户名称').AsString:=memtotal.fieldbyname('客户名称').AsString; if memtotal.fieldbyname('借方金额').AsFloat<>0 then begin t_ch_cust_genleg.FieldByName('累计借方').Asfloat:=memtotal.fieldbyname('借方金额').AsFloat; t_ch_cust_genleg.FieldByName('本月借方').Asfloat:=memtotal.fieldbyname('借方金额').AsFloat; t_ch_cust_genleg.FieldByName('累计余额').Asfloat:=t_ch_cust_genleg.FieldByName('累计余额').Asfloat+memtotal.fieldbyname('借方金额').AsFloat; t_ch_cust_genleg.FieldByName('本月余额').Asfloat:=t_ch_cust_genleg.FieldByName('本月余额').Asfloat+memtotal.fieldbyname('借方金额').AsFloat; end; if memtotal.fieldbyname('贷方金额').AsFloat<>0 then begin t_ch_cust_genleg.FieldByName('累计贷方').Asfloat:=memtotal.fieldbyname('贷方金额').AsFloat; t_ch_cust_genleg.FieldByName('本月贷方').Asfloat:=memtotal.fieldbyname('贷方金额').AsFloat; t_ch_cust_genleg.FieldByName('累计余额').Asfloat:=t_ch_cust_genleg.FieldByName('累计余额').Asfloat-memtotal.fieldbyname('贷方金额').AsFloat; t_ch_cust_genleg.FieldByName('本月余额').Asfloat:=t_ch_cust_genleg.FieldByName('本月余额').Asfloat-memtotal.fieldbyname('贷方金额').AsFloat; end; if memtotal.fieldbyname('外币借方金额').AsFloat<>0 then begin t_ch_cust_genleg.FieldByName('USD累计借方').Asfloat:=memtotal.fieldbyname('外币借方金额').AsFloat; t_ch_cust_genleg.FieldByName('USD本月借方').Asfloat:=memtotal.fieldbyname('外币借方金额').AsFloat; t_ch_cust_genleg.FieldByName('USD累计余额').Asfloat:=t_ch_cust_genleg.FieldByName('USD累计余额').Asfloat+memtotal.fieldbyname('外币借方金额').AsFloat; t_ch_cust_genleg.FieldByName('USD本月余额').Asfloat:=t_ch_cust_genleg.FieldByName('USD本月余额').Asfloat+memtotal.fieldbyname('外币借方金额').AsFloat; end; if memtotal.fieldbyname('外币贷方金额').AsFloat<>0 then begin t_ch_cust_genleg.FieldByName('USD累计贷方').Asfloat:=memtotal.fieldbyname('外币贷方金额').AsFloat; t_ch_cust_genleg.FieldByName('USD本月贷方').Asfloat:=memtotal.fieldbyname('外币贷方金额').AsFloat; t_ch_cust_genleg.FieldByName('USD累计余额').Asfloat:=t_ch_cust_genleg.FieldByName('USD累计余额').Asfloat-memtotal.fieldbyname('外币贷方金额').AsFloat; t_ch_cust_genleg.FieldByName('USD本月余额').Asfloat:=t_ch_cust_genleg.FieldByName('USD本月余额').Asfloat-memtotal.fieldbyname('外币贷方金额').AsFloat; end; if memtotal.fieldbyname('RMB借方金额').AsFloat<>0 then begin t_ch_cust_genleg.FieldByName('RMB累计借方').Asfloat:=memtotal.fieldbyname('RMB借方金额').AsFloat; t_ch_cust_genleg.FieldByName('RMB本月借方').Asfloat:=memtotal.fieldbyname('RMB借方金额').AsFloat; t_ch_cust_genleg.FieldByName('RMB累计余额').Asfloat:=t_ch_cust_genleg.FieldByName('RMB累计余额').Asfloat+memtotal.fieldbyname('RMB借方金额').AsFloat; t_ch_cust_genleg.FieldByName('RMB本月余额').Asfloat:=t_ch_cust_genleg.FieldByName('RMB本月余额').Asfloat+memtotal.fieldbyname('RMB借方金额').AsFloat; end; if memtotal.fieldbyname('RMB贷方金额').AsFloat<>0 then begin t_ch_cust_genleg.FieldByName('RMB累计贷方').Asfloat:=memtotal.fieldbyname('RMB贷方金额').AsFloat; t_ch_cust_genleg.FieldByName('RMB本月贷方').Asfloat:=memtotal.fieldbyname('RMB贷方金额').AsFloat; t_ch_cust_genleg.FieldByName('RMB累计余额').Asfloat:=t_ch_cust_genleg.FieldByName('RMB累计余额').Asfloat-memtotal.fieldbyname('RMB贷方金额').AsFloat; t_ch_cust_genleg.FieldByName('RMB本月余额').Asfloat:=t_ch_cust_genleg.FieldByName('RMB本月余额').Asfloat-memtotal.fieldbyname('RMB贷方金额').AsFloat; end; t_ch_cust_genleg.post; end else begin t_ch_cust_genleg.Edit; if memtotal.fieldbyname('借方金额').AsFloat<>0 then begin t_ch_cust_genleg.FieldByName('累计借方').Asfloat:=t_ch_cust_genleg.FieldByName('累计借方').Asfloat+memtotal.fieldbyname('借方金额').AsFloat; t_ch_cust_genleg.FieldByName('本月借方').Asfloat:=t_ch_cust_genleg.FieldByName('本月借方').Asfloat+memtotal.fieldbyname('借方金额').AsFloat; t_ch_cust_genleg.FieldByName('累计余额').Asfloat:=t_ch_cust_genleg.FieldByName('累计余额').Asfloat+memtotal.fieldbyname('借方金额').AsFloat; t_ch_cust_genleg.FieldByName('本月余额').Asfloat:=t_ch_cust_genleg.FieldByName('本月余额').Asfloat+memtotal.fieldbyname('借方金额').AsFloat; end; if memtotal.fieldbyname('贷方金额').AsFloat<>0 then begin t_ch_cust_genleg.FieldByName('累计贷方').Asfloat:=t_ch_cust_genleg.FieldByName('累计贷方').Asfloat+memtotal.fieldbyname('贷方金额').AsFloat; t_ch_cust_genleg.FieldByName('本月贷方').Asfloat:=t_ch_cust_genleg.FieldByName('本月贷方').Asfloat+memtotal.fieldbyname('贷方金额').AsFloat; t_ch_cust_genleg.FieldByName('累计余额').Asfloat:=t_ch_cust_genleg.FieldByName('累计余额').Asfloat-memtotal.fieldbyname('贷方金额').AsFloat; t_ch_cust_genleg.FieldByName('本月余额').Asfloat:=t_ch_cust_genleg.FieldByName('本月余额').Asfloat-memtotal.fieldbyname('贷方金额').AsFloat; end; if memtotal.fieldbyname('外币借方金额').AsFloat<>0 then begin t_ch_cust_genleg.FieldByName('USD累计借方').Asfloat:=t_ch_cust_genleg.FieldByName('USD累计借方').Asfloat+memtotal.fieldbyname('外币借方金额').AsFloat; t_ch_cust_genleg.FieldByName('USD本月借方').Asfloat:=t_ch_cust_genleg.FieldByName('USD本月借方').Asfloat+memtotal.fieldbyname('外币借方金额').AsFloat; t_ch_cust_genleg.FieldByName('USD累计余额').Asfloat:=t_ch_cust_genleg.FieldByName('USD累计余额').Asfloat+memtotal.fieldbyname('外币借方金额').AsFloat; t_ch_cust_genleg.FieldByName('USD本月余额').Asfloat:=t_ch_cust_genleg.FieldByName('USD本月余额').Asfloat+memtotal.fieldbyname('外币借方金额').AsFloat; end; if memtotal.fieldbyname('外币贷方金额').AsFloat<>0 then begin t_ch_cust_genleg.FieldByName('USD累计贷方').Asfloat:=t_ch_cust_genleg.FieldByName('USD累计贷方').Asfloat+memtotal.fieldbyname('外币贷方金额').AsFloat; t_ch_cust_genleg.FieldByName('USD本月贷方').Asfloat:=t_ch_cust_genleg.FieldByName('USD本月贷方').Asfloat+memtotal.fieldbyname('外币贷方金额').AsFloat; t_ch_cust_genleg.FieldByName('USD累计余额').Asfloat:=t_ch_cust_genleg.FieldByName('USD累计余额').Asfloat-memtotal.fieldbyname('外币贷方金额').AsFloat; t_ch_cust_genleg.FieldByName('USD本月余额').Asfloat:=t_ch_cust_genleg.FieldByName('USD本月余额').Asfloat-memtotal.fieldbyname('外币贷方金额').AsFloat; end; if memtotal.fieldbyname('RMB借方金额').AsFloat<>0 then begin t_ch_cust_genleg.FieldByName('RMB累计借方').Asfloat:=t_ch_cust_genleg.FieldByName('RMB累计借方').Asfloat+memtotal.fieldbyname('RMB借方金额').AsFloat; t_ch_cust_genleg.FieldByName('RMB本月借方').Asfloat:=t_ch_cust_genleg.FieldByName('RMB本月借方').Asfloat+memtotal.fieldbyname('RMB借方金额').AsFloat; t_ch_cust_genleg.FieldByName('RMB累计余额').Asfloat:=t_ch_cust_genleg.FieldByName('RMB累计余额').Asfloat+memtotal.fieldbyname('RMB借方金额').AsFloat; t_ch_cust_genleg.FieldByName('RMB本月余额').Asfloat:=t_ch_cust_genleg.FieldByName('RMB本月余额').Asfloat+memtotal.fieldbyname('RMB借方金额').AsFloat; end; if memtotal.fieldbyname('RMB贷方金额').AsFloat<>0 then begin t_ch_cust_genleg.FieldByName('RMB累计贷方').Asfloat:=t_ch_cust_genleg.FieldByName('RMB累计借方').Asfloat+memtotal.fieldbyname('RMB贷方金额').AsFloat; t_ch_cust_genleg.FieldByName('RMB本月贷方').Asfloat:=t_ch_cust_genleg.FieldByName('RMB本月贷方').Asfloat+memtotal.fieldbyname('RMB贷方金额').AsFloat; t_ch_cust_genleg.FieldByName('RMB累计余额').Asfloat:=t_ch_cust_genleg.FieldByName('RMB累计余额').Asfloat-memtotal.fieldbyname('RMB贷方金额').AsFloat; t_ch_cust_genleg.FieldByName('RMB本月余额').Asfloat:=t_ch_cust_genleg.FieldByName('RMB本月余额').Asfloat-memtotal.fieldbyname('RMB贷方金额').AsFloat; end; t_ch_cust_genleg.post; end; Next; end; end; Close;SQL.Clear; SQL.Add('Delete from t_ch_bank_genleg'); SQL.Add('where 年='+afYear+' and 月='+afMonth); ExecSQL; Close;SQL.Clear; SQL.Add('Delete from t_ch_cust_genleg'); SQL.Add('where 年='+afYear+' and 月='+afMonth); ExecSQL; Close;SQL.Clear; SQL.Add('Delete from t_ch_genleg'); SQL.Add('where 年='+afYear+' and 月='+afMonth); ExecSQL; Close;SQL.Clear; SQL.Add('Insert Into t_ch_bank_genleg'); SQL.Add('(年,月,银行代码,银行名称'); SQL.Add(',累计借方,累计贷方,累计余额,本月借方,本月贷方,本月余额'); SQL.Add(',USD累计借方,USD累计贷方,USD累计余额,USD本月借方,USD本月贷方,USD本月余额'); SQL.Add(',RMB累计借方,RMB累计贷方,RMB累计余额,RMB本月借方,RMB本月贷方,RMB本月余额)'); SQL.Add('Select '+afYear+','+afMonth); SQL.Add(',银行代码,银行名称'); SQL.Add(',累计借方,累计贷方,累计余额,0,0,0'); SQL.Add(',USD累计借方,USD累计贷方,USD累计余额,0,0,0'); SQL.Add(',RMB累计借方,RMB累计贷方,RMB累计余额,0,0,0'); SQL.Add('from t_ch_bank_genleg'); SQL.Add('where 年='+IntToStr(OffYear)+' and 月='+IntToStr(OffMonth)); ExecSQL; Close;SQL.Clear; SQL.Add('Insert Into t_ch_cust_genleg'); SQL.Add('(年,月,客户名称'); SQL.Add(',累计借方,累计贷方,累计余额,本月借方,本月贷方,本月余额'); SQL.Add(',USD累计借方,USD累计贷方,USD累计余额,USD本月借方,USD本月贷方,USD本月余额'); SQL.Add(',RMB累计借方,RMB累计贷方,RMB累计余额,RMB本月借方,RMB本月贷方,RMB本月余额)'); SQL.Add('Select '+afYear+','+afMonth); SQL.Add(',客户名称'); SQL.Add(',累计借方,累计贷方,累计余额,0,0,0'); SQL.Add(',USD累计借方,USD累计贷方,USD累计余额,0,0,0'); SQL.Add(',RMB累计借方,RMB累计贷方,RMB累计余额,0,0,0'); SQL.Add('from t_ch_cust_genleg'); SQL.Add('where 年='+IntToStr(OffYear)+' and 月='+IntToStr(OffMonth)); ExecSQL; Close;SQL.Clear; SQL.Add('Insert Into t_ch_genleg'); SQL.Add('(年,月'); SQL.Add(',累计借方,累计贷方,累计余额,本月借方,本月贷方,本月余额'); SQL.Add(',USD累计借方,USD累计贷方,USD累计余额,USD本月借方,USD本月贷方,USD本月余额'); SQL.Add(',RMB累计借方,RMB累计贷方,RMB累计余额,RMB本月借方,RMB本月贷方,RMB本月余额)'); SQL.Add('Select '+afYear+','+afMonth); SQL.Add(',累计借方+本月借方,累计贷方,累计余额,0,0,0'); SQL.Add(',USD累计借方,USD累计贷方,USD累计余额,0,0,0'); SQL.Add(',RMB累计借方,RMB累计贷方,RMB累计余额,0,0,0'); SQL.Add('from t_ch_genleg'); SQL.Add('where 年='+IntToStr(OffYear)+' and 月='+IntToStr(OffMonth)); ExecSQL; end; if strtobool(get_parameters_value(142,'false')) then begin //业务费用生成总账 Close;SQL.Clear; SQL.Add('Delete from t_ch_custbalance'); SQL.Add('where 年='+inttostr(offYear)+' and 月='+inttostr(offMonth)); ExecSQL; Close;SQL.Clear; SQL.Add('Insert Into t_ch_custbalance'); SQL.Add('(年,月,客户名称,揽货人,业务来源,来源明细,业务类型,分部名称,销售部门'); SQL.Add(',上月应收结余,本月应收发生,本月应收核销,本月应收结余,上月应收结余USD,本月应收发生USD'); SQL.Add(',本月应收核销USD,本月应收结余USD,上月应付结余,本月应付发生,本月应付核销,本月应付结余'); SQL.Add(',上月应付结余USD,本月应付发生USD,本月应付核销USD,本月应付结余USD'); SQL.Add(',上月应收结余合计,本月应收发生合计,本月应收核销合计,本月应收结余合计'); SQL.Add(',上月应付结余合计,本月应付发生合计,本月应付核销合计,本月应付结余合计)'); SQL.Add('Select '+IntToStr(OffYear)+','+IntToStr(OffMonth)); SQL.Add(',客户名称,揽货人,业务来源,来源明细,业务类型,分部名称,销售部门'); SQL.Add(',本月应收结余,0,0,本月应收结余,本月应收结余USD,0'); SQL.Add(',0,本月应收结余USD,本月应付结余,0,0,本月应付结余'); SQL.Add(',本月应付结余USD,0,0,本月应付结余USD'); SQL.Add(',本月应收结余合计,0,0,本月应收结余合计'); SQL.Add(',本月应付结余合计,0,0,本月应付结余合计'); SQL.Add('from t_ch_custbalance'); SQL.Add('where 年='+aYear+' and 月='+aMonth); ExecSQL; AddtionMonthlyFeeData(IntToStr(OffYear), IntToStr(OffMonth), '', true, true); end; Close;SQL.Clear; SQL.Add('Update Period Set Closed=''T'''); SQL.Add('where pyear='+inttostr(offYear)+' and pmonth='+inttostr(offMonth)); ExecSQL; with memTblPeriod do begin Locate('PMonth', OffMonth, []); Edit; FieldByName('Closed').AsString:='T'; Post; end; Logininfo.offyear:=StrToInt(afYear); Logininfo.offmonth:=StrToInt(afmonth); if strtoint(get_parameters_value(140,'0'))=0 then Logininfo.endday:=EncodeDate(Logininfo.offyear, Logininfo.offmonth,1)-1 else begin if Logininfo.offmonth=1 then begin tYear:=Logininfo.offyear-1; tmonth:=12; end else begin tYear:=Logininfo.offyear; tmonth:=Logininfo.offmonth-1; end; Logininfo.endday:=EncodeDate(tyear,tmonth,strtoint(get_parameters_value(140,'0'))); end; if frm_main.db.InTransaction then frm_main.db.CommitTrans; if ComboBoxYear.ItemIndex<>ComboBoxYear.Items.IndexOf(afYear) then begin ComboBoxYear.ItemIndex:=ComboBoxYear.Items.IndexOf(afYear); ComboBoxYearChange(ComboBoxYear); end; MessageDlg('结帐工作已经完成!', mtWarning, [mbOk], 0); end; end; finally bsSkinPanel1.Visible:=false; Close; FreeAndNil(aQuery); aQuery2.Close; FreeAndNil(aQuery2); if frm_main.db.InTransaction then frm_main.db.RollbackTrans; end; end; procedure TfrmAccCloseOff.t_ch_bank_genlegAfterInsert(DataSet: TDataSet); begin DataSet.FieldByName('累计借方').AsFloat:=0; DataSet.FieldByName('累计贷方').AsFloat:=0; DataSet.FieldByName('累计余额').AsFloat:=0; DataSet.FieldByName('本月借方').AsFloat:=0; DataSet.FieldByName('本月贷方').AsFloat:=0; DataSet.FieldByName('本月余额').AsFloat:=0; DataSet.FieldByName('USD累计借方').AsFloat:=0; DataSet.FieldByName('USD累计贷方').AsFloat:=0; DataSet.FieldByName('USD累计余额').AsFloat:=0; DataSet.FieldByName('USD本月借方').AsFloat:=0; DataSet.FieldByName('USD本月贷方').AsFloat:=0; DataSet.FieldByName('USD本月余额').AsFloat:=0; DataSet.FieldByName('RMB累计借方').AsFloat:=0; DataSet.FieldByName('RMB累计贷方').AsFloat:=0; DataSet.FieldByName('RMB累计余额').AsFloat:=0; DataSet.FieldByName('RMB本月借方').AsFloat:=0; DataSet.FieldByName('RMB本月贷方').AsFloat:=0; DataSet.FieldByName('RMB本月余额').AsFloat:=0; end; procedure TfrmAccCloseOff.UpdateAccDate(AccDate,toAccDate,SetAccDate:string); var aAdoQuery:TAdoQuery; begin aAdoQuery:=CreateAdoQuery; with aAdoQuery do try aAdoQuery.Close; aAdoQuery.sql.clear; aAdoQuery.sql.Add('update t_op_seae set 会计期间='''+SetAccDate+''' where 费用状态<>''费用封帐'' and 会计期间>'''+AccDate+''' and 会计期间<'''+toAccDate+''''); aAdoQuery.Execsql; aAdoQuery.Close; aAdoQuery.sql.clear; aAdoQuery.sql.Add('update t_op_seai set 会计期间='''+SetAccDate+''' where 费用状态<>''费用封帐'' and 会计期间>'''+AccDate+''' and 会计期间<'''+toAccDate+''''); aAdoQuery.Execsql; aAdoQuery.Close; aAdoQuery.sql.clear; aAdoQuery.sql.Add('update t_op_aire set 会计期间='''+SetAccDate+''' where 费用状态<>''费用封帐'' and 会计期间>'''+AccDate+''' and 会计期间<'''+toAccDate+''''); aAdoQuery.Execsql; aAdoQuery.Close; aAdoQuery.sql.clear; aAdoQuery.sql.Add('update t_op_airi set 会计期间='''+SetAccDate+''' where 费用状态<>''费用封帐'' and 会计期间>'''+AccDate+''' and 会计期间<'''+toAccDate+''''); aAdoQuery.Execsql; finally aAdoQuery.free; end; end; procedure TfrmAccCloseOff.Button1Click(Sender: TObject); begin UpdateAccDate(FormatDateTime('YYYY-MM-DD',Logininfo.endday),FormatDateTime('YYYY-MM-DD',Incmonth(Logininfo.endday)+1),FormatdateTime('YYYY-MM-DD',DateTimePicker2.DateTime)); Panel1.Visible:=false; end; procedure TfrmAccCloseOff.Button2Click(Sender: TObject); begin Panel1.Visible:=false; bbtnExcute.Enabled:=false; end; end.