unit u_rp_ch_genleg; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, bsSkinCtrls, ExtCtrls, ComCtrls, bsSkinTabs, DB, ADODB,DateUtils, dxExEdtr, dxDBTLCl, dxGrClms, dxDBGrid, dxTL, dxDBCtrl, dxCntner, kbmMemTable, kbmMemBinaryStreamFormat, Menus, StdCtrls, wwdbdatetimepicker, Grids, DBGridEh, Mask, wwdbedit, Wwdotdot, Wwdbcomb,teeprevi, RxLookup, TeEngine, Series, TeeProcs, Chart, DbChart, DBGrids, TeeFunci, bsSkinBoxCtrls; type Tfrm_rp_ch_genleg = class(TForm) Panel1: TPanel; bsSkinPanel2: TbsSkinPanel; bsSkinButton10: TbsSkinButton; bsSkinButton9: TbsSkinButton; bsSkinButton1: TbsSkinButton; bsSkinButton5: TbsSkinButton; SaveDialog: TSaveDialog; kbmBinaryStreamFormat1: TkbmBinaryStreamFormat; kbmThreadDataSet1: TkbmThreadDataSet; PopupMenu1: TPopupMenu; N1101: TMenuItem; memtblDetail: TkbmMemTable; p_total1: TDataSource; bsSkinPanel1: TbsSkinPanel; Label13: TLabel; RxDBLookupCombo5: TRxDBLookupCombo; bsSkinPageControl1: TbsSkinPageControl; bsSkinTabSheet1: TbsSkinTabSheet; memtotal1: TDataSource; memtotal: TkbmMemTable; memtblDetailField: TStringField; memtblDetailField01: TFloatField; memtblDetailField02: TFloatField; memtblDetailField03: TFloatField; memtblDetailField04: TFloatField; memtblDetailField05: TFloatField; memtblDetailField06: TFloatField; memtblDetailField07: TFloatField; memtblDetailField08: TFloatField; memtblDetailField09: TFloatField; memtblDetailField10: TFloatField; memtblDetailField11: TFloatField; memtblDetailField12: TFloatField; memtblDetailField2: TFloatField; bsSkinRadioGroup1: TbsSkinRadioGroup; memtotalField: TIntegerField; memtotalID: 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; memtotalField16: TSmallintField; cbemonth: TwwDBComboBox; Label5: TLabel; Label6: TLabel; cbeYear: TwwDBComboBox; Label4: TLabel; Label2: TLabel; cbmonth: TwwDBComboBox; Label1: TLabel; cbYear: TwwDBComboBox; Label3: TLabel; t_ch_genleg: TADOQuery; Label7: TLabel; RxDBLookupCombo1: TRxDBLookupCombo; t_ch_cust_genleg: TADOQuery; t_ch_bank_genleg: TADOQuery; DataSource1: TDataSource; memtotalRMB: TFloatField; memtotalRMB2: TFloatField; memtotalRMB3: TFloatField; memtotalField17: TStringField; memtotalField18: TStringField; memtotalField19: TStringField; memtotalField20: TStringField; Label17: TLabel; RxDBLookupCombo8: TRxDBLookupCombo; Label18: TLabel; RxDBLookupCombo10: TRxDBLookupCombo; Label8: TLabel; RxDBLookupCombo2: TRxDBLookupCombo; Label9: TLabel; Edit1: TEdit; ADOQuery_cost: TADOQuery; ADOQuery_cost1: TDataSource; dxDBGrid1: TdxDBGrid; dxDBGrid1Column1: TdxDBGridColumn; dxDBGrid1Column2: TdxDBGridColumn; dxDBGrid1Column3: TdxDBGridColumn; dxDBGrid1Column4: TdxDBGridColumn; dxDBGrid1Column5: TdxDBGridColumn; dxDBGrid1Column6: TdxDBGridColumn; dxDBGrid1Column7: TdxDBGridColumn; dxDBGrid1Column8: TdxDBGridColumn; dxDBGrid1Column9: TdxDBGridColumn; dxDBGrid1Column10: TdxDBGridColumn; dxDBGrid1Column11: TdxDBGridColumn; dxDBGrid1Column12: TdxDBGridColumn; dxDBGrid1Column13: TdxDBGridColumn; dxDBGrid1Column14: TdxDBGridColumn; dxDBGrid1Column15: TdxDBGridColumn; dxDBGrid1Column16: TdxDBGridColumn; dxDBGrid1Column17: TdxDBGridColumn; bsSkinComboBox1: TbsSkinComboBox; Label10: TLabel; PopupMenu2: TPopupMenu; N14: TMenuItem; N13: TMenuItem; procedure bsSkinButton5Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure Panel1Resize(Sender: TObject); procedure bsSkinButton10Click(Sender: TObject); procedure bsSkinButton9Click(Sender: TObject); procedure FormShow(Sender: TObject); procedure bsSkinRadioGroup1Click(Sender: TObject); procedure DBGridLegBookDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumnEh; State: TGridDrawState); procedure bsSkinButton1Click(Sender: TObject); procedure bsSkinPanel1Resize(Sender: TObject); procedure dxDBGrid3CustomDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxDBTreeListColumn; const AText: String; AFont: TFont; var AColor: TColor; ASelected, AFocused: Boolean; var ADone: Boolean); procedure dxDBGrid1CustomDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxDBTreeListColumn; const AText: String; AFont: TFont; var AColor: TColor; ASelected, AFocused: Boolean; var ADone: Boolean); procedure bsSkinComboBox1Change(Sender: TObject); procedure N14Click(Sender: TObject); private function GetBankName(Accid:string):String; procedure Getgenleg; procedure Getcust; procedure Getbank; { Private declarations } public { Public declarations } end; var frm_rp_ch_genleg: Tfrm_rp_ch_genleg; FmDate,ToDate:String; sqlstr:WideString; implementation uses u_main, my_sys_function,u_sys_progress, u_data_share; {$R *.dfm} procedure Tfrm_rp_ch_genleg.bsSkinButton5Click(Sender: TObject); begin close; end; procedure Tfrm_rp_ch_genleg.FormClose(Sender: TObject; var Action: TCloseAction); begin savereggrid(dxdbgrid1,caption+'1'); ADOQuery_cost.Close; frm_rp_ch_genleg.Hide; frm_rp_ch_genleg.ManualFloat(frm_rp_ch_genleg.BoundsRect ); frm_main.freeTabs('frm_rp_ch_genleg'); action:=cafree; frm_rp_ch_genleg:=nil; end; procedure Tfrm_rp_ch_genleg.Panel1Resize(Sender: TObject); var i:integer; begin i:=round(bsSkinPanel2.Width/7); bsSkinButton10.Width:=i; bsSkinButton9.Width:=i; bsSkinButton1.Width:=i; end; procedure Tfrm_rp_ch_genleg.bsSkinButton10Click(Sender: TObject); var barse:TBarSeries; begin if cbyear.Text='' then begin MessageDlg('统计年不能为空!',mtWarning,[mbOk],0); exit; end; if cbeyear.Text='' then begin MessageDlg('统计年不能为空!',mtWarning,[mbOk],0); exit; end; if strtoint(cbeyear.Text)aToDate) do begin strdate:=FormatDateTime('YYYY-MM-DD',EncodeDate(strtoint(FormatDateTime('YYYY',aDate)),strtoint(FormatDateTime('MM',aDate)),MonthDays[isLeapYear(strtoint(FormatDateTime('YYYY',aDate))),strtoint(FormatDateTime('MM',aDate))])); stredate:=FormatDateTime('YYYY-MM-DD',aDate); sDate:=FormatDateTime('YYYYMM',aDate); aTopDate:=IncMonth(aDate,-1); if fb then begin t_ch_genleg.Close; t_ch_genleg.Parameters.ParamByName('年').Value:=YearOf(aTopDate); t_ch_genleg.Parameters.ParamByName('月').Value:=MonthOf(aTopDate); t_ch_genleg.open; if not t_ch_genleg.IsEmpty then begin memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=0; memtotal['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日']:=DayOf(aDate); memtotal['日期']:=aDate; memtotal['摘要']:='期初余额'; bal:=t_ch_genleg.fieldbyname('累计余额').AsFloat; usdbal:=t_ch_genleg.fieldbyname('USD累计余额').AsFloat; rmbbal:=t_ch_genleg.fieldbyname('RMB累计余额').AsFloat; memtotal['余额']:=t_ch_genleg.fieldbyname('累计余额').AsFloat; memtotal['外币余额']:=t_ch_genleg.fieldbyname('USD累计余额').AsFloat; memtotal['RMB余额']:=t_ch_genleg.fieldbyname('RMB累计余额').AsFloat; fb:=false; memtotal.post; inc(i); end else begin memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=0; memtotal['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日']:=DayOf(aDate); memtotal['日期']:=aDate; memtotal['摘要']:='期初余额'; bal:=0; usdbal:=0; rmbbal:=0; memtotal['余额']:=0; memtotal['外币余额']:=0; memtotal['RMB余额']:=0; fb:=false; memtotal.post; inc(i); end; end; DR:=0; CR:=0; USDDR:=0; USDCR:=0; RMBDR:=0; RMBCR:=0; close;sql.clear; sql.Add('select * from v_op_fee where 结算日期>='''+stredate+''' and 结算日期<='''+strdate+''''); if bank<>'' then sql.Add('and (银行代码='''+bank+''' or 美元银行代码='''+bank+''')'); sql.Add('order by 结算日期'); open; 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['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日']:=DayOf(FieldByName('结算日期').AsDateTime); memtotal['日期']:=FieldByName('结算日期').AsDateTime; memtotal['摘要']:=fieldbyname('备注').asstring; memtotal['凭证号']:=fieldbyname('凭证号码').asstring; memtotal['客户名称']:=fieldbyname('客户名称').asstring; memtotal['银行名称']:=GetBankName(fieldbyname('银行代码').asstring); memtotal['相关部门']:=fieldbyname('相关部门').asstring; memtotal['相关人员']:=fieldbyname('相关人员').asstring; memtotal['相关号码']:=fieldbyname('相关号码').asstring; memtotal['费用名称']:=fieldbyname('费用名称').asstring; if fieldbyname('类型').AsString='收' then begin memtotal['借方金额']:=fieldbyname('人民币金额').Asfloat; memtotal['余额']:=bal+fieldbyname('人民币金额').Asfloat; memtotal['RMB借方金额']:=fieldbyname('人民币金额').Asfloat; memtotal['RMB余额']:=rmbbal+fieldbyname('人民币金额').Asfloat; bal:=bal+fieldbyname('人民币金额').Asfloat; DR:=DR+fieldbyname('人民币金额').Asfloat; rmbbal:=rmbbal+fieldbyname('人民币金额').Asfloat; RMBDR:=RMBDR+fieldbyname('人民币金额').Asfloat; end else begin memtotal['贷方金额']:=fieldbyname('人民币金额').Asfloat; memtotal['余额']:=bal-fieldbyname('人民币金额').Asfloat; memtotal['RMB贷方金额']:=fieldbyname('人民币金额').Asfloat; memtotal['RMB余额']:=rmbbal-fieldbyname('人民币金额').Asfloat; bal:=bal-fieldbyname('人民币金额').Asfloat; CR:=CR+fieldbyname('人民币金额').Asfloat; rmbbal:=rmbbal-fieldbyname('人民币金额').Asfloat; RMBCR:=RMBCR+fieldbyname('人民币金额').Asfloat; end; memtotal.post; end; if fieldbyname('美元金额').Asfloat<>0 then begin memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=1; memtotal['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日']:=DayOf(FieldByName('结算日期').AsDateTime); memtotal['日期']:=FieldByName('结算日期').AsDateTime; memtotal['摘要']:=fieldbyname('备注').asstring; memtotal['凭证号']:=fieldbyname('凭证号码').asstring; memtotal['客户名称']:=fieldbyname('客户名称').asstring; memtotal['银行名称']:=GetBankName(fieldbyname('银行代码').asstring); memtotal['相关部门']:=fieldbyname('相关部门').asstring; memtotal['相关人员']:=fieldbyname('相关人员').asstring; memtotal['相关号码']:=fieldbyname('相关号码').asstring; memtotal['费用名称']:=fieldbyname('费用名称').asstring; if fieldbyname('类型').AsString='收' then begin memtotal['外币借方金额']:=fieldbyname('美元金额').Asfloat; memtotal['外币余额']:=usdbal+fieldbyname('美元金额').Asfloat; memtotal['借方金额']:=fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); memtotal['余额']:=bal+fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); usdbal:=usdbal+fieldbyname('美元金额').Asfloat; bal:=bal+fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); USDDR:=USDDR+fieldbyname('美元金额').Asfloat; DR:=DR+fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); end else begin memtotal['外币贷方金额']:=fieldbyname('美元金额').Asfloat; memtotal['外币余额']:=usdbal-fieldbyname('美元金额').Asfloat; usdbal:=usdbal-fieldbyname('美元金额').Asfloat; memtotal['贷方金额']:=fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); memtotal['余额']:=bal-fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); bal:=bal-fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); USDCR:=USDCR+fieldbyname('美元金额').Asfloat; CR:=CR+fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); end; memtotal.post; end; end else begin memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=1; memtotal['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日']:=DayOf(FieldByName('结算日期').AsDateTime); memtotal['日期']:=FieldByName('结算日期').AsDateTime; memtotal['摘要']:=fieldbyname('备注').asstring; memtotal['凭证号']:=fieldbyname('凭证号码').asstring; memtotal['客户名称']:=fieldbyname('客户名称').asstring; memtotal['银行名称']:=GetBankName(fieldbyname('银行代码').asstring); memtotal['相关部门']:=fieldbyname('相关部门').asstring; memtotal['相关人员']:=fieldbyname('相关人员').asstring; memtotal['相关号码']:=fieldbyname('相关号码').asstring; memtotal['费用名称']:=fieldbyname('费用名称').asstring; if trim(fieldbyname('币别').AsString)='RMB' then begin if fieldbyname('类型').AsString='收' then begin memtotal['借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['余额']:=bal+fieldbyname('结算金额').AsFloat; memtotal['RMB借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['RMB余额']:=rmbbal+fieldbyname('结算金额').AsFloat; bal:=bal+fieldbyname('结算金额').AsFloat; DR:=DR+fieldbyname('结算金额').AsFloat; rmbbal:=rmbbal+fieldbyname('结算金额').AsFloat; RMBDR:=RMBDR+fieldbyname('结算金额').AsFloat; end else begin memtotal['贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['余额']:=bal-fieldbyname('结算金额').AsFloat; memtotal['RMB贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['RMB余额']:=rmbbal-fieldbyname('结算金额').AsFloat; bal:=bal-fieldbyname('结算金额').AsFloat; CR:=CR+fieldbyname('结算金额').AsFloat; rmbbal:=rmbbal-fieldbyname('结算金额').AsFloat; RMBCR:=RMBCR+fieldbyname('结算金额').AsFloat; end; end else begin if fieldbyname('类型').AsString='收' then begin memtotal['外币借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['外币余额']:=usdbal+fieldbyname('结算金额').AsFloat; usdbal:=usdbal+fieldbyname('结算金额').AsFloat; USDDR:=USDDR+fieldbyname('结算金额').AsFloat; memtotal['借方金额']:=fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); memtotal['余额']:=bal+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); bal:=bal+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); DR:=DR+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); end else begin memtotal['外币贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['外币余额']:=usdbal-fieldbyname('结算金额').AsFloat; usdbal:=usdbal-fieldbyname('结算金额').AsFloat; USDCR:=USDCR+fieldbyname('结算金额').AsFloat; memtotal['贷方金额']:=fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); memtotal['余额']:=bal-fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); bal:=bal-fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); CR:=CR+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); end; end; memtotal.post; end; end else begin memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=1; memtotal['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日']:=DayOf(FieldByName('结算日期').AsDateTime); memtotal['日期']:=FieldByName('结算日期').AsDateTime; memtotal['摘要']:=fieldbyname('备注').asstring; memtotal['凭证号']:=fieldbyname('凭证号码').asstring; memtotal['客户名称']:=fieldbyname('客户名称').asstring; memtotal['银行名称']:=GetBankName(fieldbyname('银行代码').asstring); memtotal['相关部门']:=fieldbyname('相关部门').asstring; memtotal['相关人员']:=fieldbyname('相关人员').asstring; memtotal['相关号码']:=fieldbyname('相关号码').asstring; memtotal['费用名称']:=fieldbyname('费用名称').asstring; if trim(fieldbyname('币别').AsString)='RMB' then begin if fieldbyname('类型').AsString='收' then begin memtotal['借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['余额']:=bal+fieldbyname('结算金额').AsFloat; memtotal['RMB借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['RMB余额']:=rmbbal+fieldbyname('结算金额').AsFloat; bal:=bal+fieldbyname('结算金额').AsFloat; DR:=DR+fieldbyname('结算金额').AsFloat; rmbbal:=rmbbal+fieldbyname('结算金额').AsFloat; RMBDR:=RMBDR+fieldbyname('结算金额').AsFloat; end else begin memtotal['贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['余额']:=bal-fieldbyname('结算金额').AsFloat; memtotal['RMB贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['RMB余额']:=rmbbal-fieldbyname('结算金额').AsFloat; bal:=bal-fieldbyname('结算金额').AsFloat; CR:=CR+fieldbyname('结算金额').AsFloat; rmbbal:=rmbbal-fieldbyname('结算金额').AsFloat; RMBCR:=RMBCR+fieldbyname('结算金额').AsFloat; end; end else begin if fieldbyname('类型').AsString='收' then begin memtotal['外币借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['外币余额']:=usdbal+fieldbyname('结算金额').AsFloat; usdbal:=usdbal+fieldbyname('结算金额').AsFloat; USDDR:=USDDR+fieldbyname('结算金额').AsFloat; memtotal['借方金额']:=fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); memtotal['余额']:=bal+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); bal:=bal+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); DR:=DR+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); end else begin memtotal['外币贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['外币余额']:=usdbal-fieldbyname('结算金额').AsFloat; usdbal:=usdbal-fieldbyname('结算金额').AsFloat; USDCR:=USDCR+fieldbyname('结算金额').AsFloat; memtotal['贷方金额']:=fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); memtotal['余额']:=bal-fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); bal:=bal-fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); CR:=CR+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); end; end; memtotal.post; end; inc(i); Next; end; inc(i); memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=2; memtotal['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日期']:=FieldByName('结算日期').AsDateTime; // memtotal['日']:=DayOf(aDate); memtotal['摘要']:='本月累计'; memtotal['借方金额']:=DR; memtotal['贷方金额']:=CR; memtotal['余额']:=bal; memtotal['外币借方金额']:=USDDR; memtotal['外币贷方金额']:=USDCR; memtotal['外币余额']:=usdbal; memtotal['RMB借方金额']:=RMBDR; memtotal['RMB贷方金额']:=RMBCR; memtotal['RMB余额']:=rmbbal; memtotal.post; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; aDate:=IncMonth(aDate,1); inc(i); end; end; finally FreeAndNil(aQuery); freeAndNil(frm_sys_progress); end; end; procedure Tfrm_rp_ch_genleg.FormShow(Sender: TObject); begin cbYear.ItemIndex:=cbYear.Items.IndexOf(inttostr(Logininfo.offyear)); cbmonth.ItemIndex:=cbmonth.Items.IndexOf(inttostr(Logininfo.offmonth)); cbeyear.Items.IndexOf(FormatDateTime('YYYY',Now)); cbeyear.text:=FormatDateTime('YYYY',Now); cbemonth.Items.IndexOf(FormatDateTime('MM',Now)); cbemonth.text:=FormatDateTime('MM',Now); loadreggrid(dxdbgrid1,false,caption+'1'); ADOQuery_cost.Open; end; procedure Tfrm_rp_ch_genleg.Getcust; var aQuery:TAdoQuery; aDate,aTopDate,aToDate:TDate; cust,strdate,stredate,sDate:String; i:integer; DR,CR,bal,USDDR,USDCR,usdbal,RMBDR,RMBCR,rmbbal:double; fb:boolean; begin cust:=RxDBLookupCombo5.DisplayValues[1]; try aQuery:=CreateAdoQuery; with aQuery do begin aDate:=EncodeDate(strtoint(cbYear.Text),strtoint(cbmonth.Text),1); aToDate:=EncodeDate(strtoint(cbeYear.Text),strtoint(cbemonth.Text),2); if not ASSIGNED(frm_sys_progress) then frm_sys_progress:=tfrm_sys_progress.Create(application); frm_sys_progress.Show; if MonthsBetween(aDate,aToDate)=0 then frm_sys_progress.bsSkinGauge1.MaxValue:=1 else frm_sys_progress.bsSkinGauge1.MaxValue:=MonthsBetween(aDate,aToDate); frm_sys_progress.bsSkinGauge1.MinValue:=0; frm_sys_progress.bsSkinGauge1.Value:=0; frm_sys_progress.Update; i:=0; bal:=0; usdbal:=0; rmbbal:=0; DR:=0; CR:=0; USDDR:=0; USDCR:=0; RMBDR:=0; RMBCR:=0; fb:=true; while not (aDate>aToDate) do begin strdate:=FormatDateTime('YYYY-MM-DD',EncodeDate(strtoint(FormatDateTime('YYYY',aDate)),strtoint(FormatDateTime('MM',aDate)),MonthDays[isLeapYear(strtoint(FormatDateTime('YYYY',aDate))),strtoint(FormatDateTime('MM',aDate))])); stredate:=FormatDateTime('YYYY-MM-DD',aDate); sDate:=FormatDateTime('YYYYMM',aDate); aTopDate:=IncMonth(aDate,-1); if fb then begin t_ch_cust_genleg.Close; t_ch_cust_genleg.Parameters.ParamByName('年').Value:=YearOf(aTopDate); t_ch_cust_genleg.Parameters.ParamByName('月').Value:=MonthOf(aTopDate); t_ch_cust_genleg.Parameters.ParamByName('客户名称').Value:=cust; t_ch_cust_genleg.open; if not t_ch_cust_genleg.IsEmpty then begin memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=0; memtotal['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日']:=DayOf(aDate); memtotal['日期']:=aDate; memtotal['摘要']:='期初余额'; bal:=t_ch_cust_genleg.fieldbyname('累计余额').AsFloat; usdbal:=t_ch_cust_genleg.fieldbyname('USD累计余额').AsFloat; rmbbal:=t_ch_cust_genleg.fieldbyname('RMB累计余额').AsFloat; memtotal['余额']:=t_ch_cust_genleg.fieldbyname('累计余额').AsFloat; memtotal['外币余额']:=t_ch_cust_genleg.fieldbyname('USD累计余额').AsFloat; memtotal['RMB余额']:=t_ch_cust_genleg.fieldbyname('RMB累计余额').AsFloat; fb:=false; memtotal.post; inc(i); end else begin memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=0; memtotal['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日']:=DayOf(aDate); memtotal['日期']:=aDate; memtotal['摘要']:='期初余额'; bal:=0; usdbal:=0; rmbbal:=0; memtotal['余额']:=0; memtotal['外币余额']:=0; memtotal['RMB余额']:=0; fb:=false; memtotal.post; inc(i); end; end; DR:=0; CR:=0; USDDR:=0; USDCR:=0; RMBDR:=0; RMBCR:=0; close;sql.clear; sql.Add('select * from v_op_fee where 结算日期>='''+stredate+''' and 结算日期<='''+strdate+''' and 客户名称='''+cust+''' order by 结算日期'); open; 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['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日']:=DayOf(FieldByName('结算日期').AsDateTime); memtotal['日期']:=FieldByName('结算日期').AsDateTime; memtotal['摘要']:=fieldbyname('备注').asstring; memtotal['凭证号']:=fieldbyname('凭证号码').asstring; memtotal['客户名称']:=fieldbyname('客户名称').asstring; memtotal['银行名称']:=GetBankName(fieldbyname('银行代码').asstring); memtotal['相关部门']:=fieldbyname('相关部门').asstring; memtotal['相关人员']:=fieldbyname('相关人员').asstring; memtotal['相关号码']:=fieldbyname('相关号码').asstring; memtotal['费用名称']:=fieldbyname('费用名称').asstring; if fieldbyname('类型').AsString='收' then begin memtotal['借方金额']:=fieldbyname('人民币金额').Asfloat; memtotal['余额']:=bal+fieldbyname('人民币金额').Asfloat; memtotal['RMB借方金额']:=fieldbyname('人民币金额').Asfloat; memtotal['RMB余额']:=bal+fieldbyname('人民币金额').Asfloat; bal:=bal+fieldbyname('人民币金额').Asfloat; DR:=DR+fieldbyname('人民币金额').Asfloat; rmbbal:=rmbbal+fieldbyname('人民币金额').Asfloat; RMBDR:=RMBDR+fieldbyname('人民币金额').Asfloat; end else begin memtotal['贷方金额']:=fieldbyname('人民币金额').Asfloat; memtotal['余额']:=bal-fieldbyname('人民币金额').Asfloat; memtotal['RMB贷方金额']:=fieldbyname('人民币金额').Asfloat; memtotal['RMB余额']:=bal-fieldbyname('人民币金额').Asfloat; bal:=bal-fieldbyname('人民币金额').Asfloat; CR:=CR+fieldbyname('人民币金额').Asfloat; rmbbal:=rmbbal-fieldbyname('人民币金额').Asfloat; RMBCR:=RMBCR+fieldbyname('人民币金额').Asfloat; end; memtotal.post; end; if fieldbyname('美元金额').Asfloat<>0 then begin memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=1; memtotal['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日']:=DayOf(FieldByName('结算日期').AsDateTime); memtotal['日期']:=FieldByName('结算日期').AsDateTime; memtotal['摘要']:=fieldbyname('备注').asstring; memtotal['凭证号']:=fieldbyname('凭证号码').asstring; memtotal['客户名称']:=fieldbyname('客户名称').asstring; memtotal['银行名称']:=GetBankName(fieldbyname('银行代码').asstring); memtotal['相关部门']:=fieldbyname('相关部门').asstring; memtotal['相关人员']:=fieldbyname('相关人员').asstring; memtotal['相关号码']:=fieldbyname('相关号码').asstring; memtotal['费用名称']:=fieldbyname('费用名称').asstring; if fieldbyname('类型').AsString='收' then begin memtotal['外币借方金额']:=fieldbyname('美元金额').Asfloat; memtotal['外币余额']:=usdbal+fieldbyname('美元金额').Asfloat; memtotal['借方金额']:=fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); memtotal['余额']:=bal+fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); usdbal:=usdbal+fieldbyname('美元金额').Asfloat; bal:=bal+fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); USDDR:=USDDR+fieldbyname('美元金额').Asfloat; DR:=DR+fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); end else begin memtotal['外币贷方金额']:=fieldbyname('美元金额').Asfloat; memtotal['外币余额']:=usdbal-fieldbyname('美元金额').Asfloat; usdbal:=usdbal-fieldbyname('美元金额').Asfloat; memtotal['贷方金额']:=fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); memtotal['余额']:=bal-fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); bal:=bal-fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); USDCR:=USDCR+fieldbyname('美元金额').Asfloat; CR:=CR+fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); end; memtotal.post; end; end else begin memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=1; memtotal['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日']:=DayOf(FieldByName('结算日期').AsDateTime); memtotal['日期']:=FieldByName('结算日期').AsDateTime; memtotal['摘要']:=fieldbyname('备注').asstring; memtotal['凭证号']:=fieldbyname('凭证号码').asstring; memtotal['客户名称']:=fieldbyname('客户名称').asstring; memtotal['银行名称']:=GetBankName(fieldbyname('银行代码').asstring); memtotal['相关部门']:=fieldbyname('相关部门').asstring; memtotal['相关人员']:=fieldbyname('相关人员').asstring; memtotal['相关号码']:=fieldbyname('相关号码').asstring; memtotal['费用名称']:=fieldbyname('费用名称').asstring; if trim(fieldbyname('币别').AsString)='RMB' then begin if fieldbyname('类型').AsString='收' then begin memtotal['借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['余额']:=bal+fieldbyname('结算金额').AsFloat; memtotal['RMB借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['RMB余额']:=bal+fieldbyname('结算金额').AsFloat; bal:=bal+fieldbyname('结算金额').AsFloat; DR:=DR+fieldbyname('结算金额').AsFloat; rmbbal:=rmbbal+fieldbyname('结算金额').AsFloat; RMBDR:=RMBDR+fieldbyname('结算金额').AsFloat; end else begin memtotal['贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['余额']:=bal-fieldbyname('结算金额').AsFloat; memtotal['RMB贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['RMB余额']:=bal-fieldbyname('结算金额').AsFloat; bal:=bal-fieldbyname('结算金额').AsFloat; CR:=CR+fieldbyname('结算金额').AsFloat; rmbbal:=rmbbal-fieldbyname('结算金额').AsFloat; RMBCR:=RMBCR+fieldbyname('结算金额').AsFloat; end; end else begin if fieldbyname('类型').AsString='收' then begin memtotal['外币借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['外币余额']:=usdbal+fieldbyname('结算金额').AsFloat; usdbal:=usdbal+fieldbyname('结算金额').AsFloat; USDDR:=USDDR+fieldbyname('结算金额').AsFloat; memtotal['借方金额']:=fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); memtotal['余额']:=bal+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); bal:=bal+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); DR:=DR+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); end else begin memtotal['外币贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['外币余额']:=usdbal-fieldbyname('结算金额').AsFloat; usdbal:=usdbal-fieldbyname('结算金额').AsFloat; USDCR:=USDCR+fieldbyname('结算金额').AsFloat; memtotal['贷方金额']:=fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); memtotal['余额']:=bal-fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); bal:=bal-fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); CR:=CR+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); end; end; memtotal.post; end; end else begin memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=1; memtotal['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日']:=DayOf(FieldByName('结算日期').AsDateTime); memtotal['日期']:=FieldByName('结算日期').AsDateTime; memtotal['摘要']:=fieldbyname('备注').asstring; memtotal['凭证号']:=fieldbyname('凭证号码').asstring; memtotal['客户名称']:=fieldbyname('客户名称').asstring; memtotal['银行名称']:=GetBankName(fieldbyname('银行代码').asstring); memtotal['相关部门']:=fieldbyname('相关部门').asstring; memtotal['相关人员']:=fieldbyname('相关人员').asstring; memtotal['相关号码']:=fieldbyname('相关号码').asstring; memtotal['费用名称']:=fieldbyname('费用名称').asstring; if trim(fieldbyname('币别').AsString)='RMB' then begin if fieldbyname('类型').AsString='收' then begin memtotal['借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['余额']:=bal+fieldbyname('结算金额').AsFloat; memtotal['RMB借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['RMB余额']:=bal+fieldbyname('结算金额').AsFloat; bal:=bal+fieldbyname('结算金额').AsFloat; DR:=DR+fieldbyname('结算金额').AsFloat; rmbbal:=rmbbal+fieldbyname('结算金额').AsFloat; RMBDR:=RMBDR+fieldbyname('结算金额').AsFloat; end else begin memtotal['贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['余额']:=bal-fieldbyname('结算金额').AsFloat; memtotal['RMB贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['RMB余额']:=bal-fieldbyname('结算金额').AsFloat; bal:=bal-fieldbyname('结算金额').AsFloat; CR:=CR+fieldbyname('结算金额').AsFloat; rmbbal:=rmbbal-fieldbyname('结算金额').AsFloat; RMBCR:=RMBCR+fieldbyname('结算金额').AsFloat; end; end else begin if fieldbyname('类型').AsString='收' then begin memtotal['外币借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['外币余额']:=usdbal+fieldbyname('结算金额').AsFloat; usdbal:=usdbal+fieldbyname('结算金额').AsFloat; USDDR:=USDDR+fieldbyname('结算金额').AsFloat; memtotal['借方金额']:=fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); memtotal['余额']:=bal+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); bal:=bal+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); DR:=DR+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); end else begin memtotal['外币贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['外币余额']:=usdbal-fieldbyname('结算金额').AsFloat; usdbal:=usdbal-fieldbyname('结算金额').AsFloat; USDCR:=USDCR+fieldbyname('结算金额').AsFloat; memtotal['贷方金额']:=fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); memtotal['余额']:=bal-fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); bal:=bal-fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); CR:=CR+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); end; end; memtotal.post; end; inc(i); Next; end; inc(i); memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=2; memtotal['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日期']:=FieldByName('结算日期').AsDateTime; // memtotal['日']:=DayOf(aDate); memtotal['摘要']:='本月累计'; memtotal['借方金额']:=DR; memtotal['贷方金额']:=CR; memtotal['余额']:=bal; memtotal['外币借方金额']:=USDDR; memtotal['外币贷方金额']:=USDCR; memtotal['外币余额']:=usdbal; memtotal['RMB借方金额']:=RMBDR; memtotal['RMB贷方金额']:=RMBCR; memtotal['RMB余额']:=rmbbal; memtotal.post; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; aDate:=IncMonth(aDate,1); inc(i); end; end; finally FreeAndNil(aQuery); freeAndNil(frm_sys_progress); end; end; function Tfrm_rp_ch_genleg.GetBankName(accid:string):String; var aQuery:TAdoQuery; begin aQuery:=CreateAdoQuery; with aQuery do try Close;sql.Clear; sql.Add('select 银行名称 from t_sys_bank'); sql.Add('where 代码='''+accid+''''); Open; if Recordcount<>0 then result:=fieldbyname('银行名称').AsString else result:=''; finally freeAndNil(aQuery); end; end; procedure Tfrm_rp_ch_genleg.Getbank; var aQuery:TAdoQuery; aDate,aTopDate,aToDate:TDate; bank,strdate,stredate,sDate:String; i:integer; DR,CR,bal,USDDR,USDCR,usdbal,RMBDR,RMBCR,rmbbal:double; fb:boolean; begin if RxDBLookupCombo1.DisplayValues[1]='现金' then bank:='现金' else bank:=RxDBLookupCombo1.DisplayValues[0]; try aQuery:=CreateAdoQuery; with aQuery do begin aDate:=EncodeDate(strtoint(cbYear.Text),strtoint(cbmonth.Text),1); aToDate:=EncodeDate(strtoint(cbeYear.Text),strtoint(cbemonth.Text),2); if not ASSIGNED(frm_sys_progress) then frm_sys_progress:=tfrm_sys_progress.Create(application); frm_sys_progress.Show; if MonthsBetween(aDate,aToDate)=0 then frm_sys_progress.bsSkinGauge1.MaxValue:=1 else frm_sys_progress.bsSkinGauge1.MaxValue:=MonthsBetween(aDate,aToDate); frm_sys_progress.bsSkinGauge1.MinValue:=0; frm_sys_progress.bsSkinGauge1.Value:=0; frm_sys_progress.Update; i:=0; bal:=0; usdbal:=0; rmbbal:=0; DR:=0; CR:=0; USDDR:=0; USDCR:=0; RMBDR:=0; RMBCR:=0; fb:=true; while not (aDate>aToDate) do begin strdate:=FormatDateTime('YYYY-MM-DD',EncodeDate(strtoint(FormatDateTime('YYYY',aDate)),strtoint(FormatDateTime('MM',aDate)),MonthDays[isLeapYear(strtoint(FormatDateTime('YYYY',aDate))),strtoint(FormatDateTime('MM',aDate))])); stredate:=FormatDateTime('YYYY-MM-DD',aDate); sDate:=FormatDateTime('YYYYMM',aDate); aTopDate:=IncMonth(aDate,-1); if fb then begin t_ch_bank_genleg.Close; t_ch_bank_genleg.Parameters.ParamByName('年').Value:=YearOf(aTopDate); t_ch_bank_genleg.Parameters.ParamByName('月').Value:=MonthOf(aTopDate); t_ch_bank_genleg.Parameters.ParamByName('银行代码').Value:=bank; t_ch_bank_genleg.open; if not t_ch_bank_genleg.IsEmpty then begin memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=0; memtotal['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日']:=DayOf(aDate); memtotal['日期']:=aDate; memtotal['摘要']:='期初余额'; bal:=t_ch_bank_genleg.fieldbyname('累计余额').AsFloat; usdbal:=t_ch_bank_genleg.fieldbyname('USD累计余额').AsFloat; rmbbal:=t_ch_bank_genleg.fieldbyname('RMB累计余额').AsFloat; memtotal['余额']:=t_ch_bank_genleg.fieldbyname('累计余额').AsFloat; memtotal['外币余额']:=t_ch_bank_genleg.fieldbyname('USD累计余额').AsFloat; memtotal['RMB余额']:=t_ch_bank_genleg.fieldbyname('RMB累计余额').AsFloat; fb:=false; memtotal.post; inc(i); end else begin memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=0; memtotal['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日']:=DayOf(aDate); memtotal['日期']:=aDate; memtotal['摘要']:='期初余额'; bal:=0; usdbal:=0; rmbbal:=0; memtotal['余额']:=0; memtotal['外币余额']:=0; memtotal['RMB余额']:=0; fb:=false; memtotal.post; inc(i); end; end; DR:=0; CR:=0; USDDR:=0; USDCR:=0; RMBDR:=0; RMBCR:=0; close;sql.clear; sql.Add('select * from v_op_fee'); sql.Add('where 结算日期>='''+stredate+''' and 结算日期<='''+strdate+''''); sql.Add('and (银行代码='''+bank+''' or 美元银行代码='''+bank+''')'); if trim(RxDBLookupCombo8.Value)<>'' then //相关部门 begin sql.Add('and 相关部门='''+trim(RxDBLookupCombo8.Value)+''''); end; if trim(RxDBLookupCombo10.Value)<>'' then //相关人员 begin sql.Add('and 相关人员='''+trim(RxDBLookupCombo10.Value)+''''); end; if trim(RxDBLookupCombo2.Value)<>'' then //费用名称 begin sql.Add('and 费用名称='''+trim(RxDBLookupCombo2.Value)+''' '); end; if trim(Edit1.text)<>'' then //相关号码 begin sql.Add('and 相关号码 like ''%'+trim(Edit1.text)+'%'''); end; sql.Add('order by 结算日期'); open; first; while not eof do begin if fieldbyname('费用类型').AsInteger=1 then begin if fieldbyname('币别').AsString='' then begin if (fieldbyname('银行代码').asstring=bank) and (fieldbyname('人民币金额').Asfloat<>0) then begin memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=1; memtotal['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日']:=DayOf(FieldByName('结算日期').AsDateTime); memtotal['日期']:=FieldByName('结算日期').AsDateTime; memtotal['摘要']:=fieldbyname('备注').asstring; memtotal['凭证号']:=fieldbyname('凭证号码').asstring; memtotal['客户名称']:=fieldbyname('客户名称').asstring; memtotal['银行名称']:=GetBankName(fieldbyname('银行代码').asstring); memtotal['相关部门']:=fieldbyname('相关部门').asstring; memtotal['相关人员']:=fieldbyname('相关人员').asstring; memtotal['相关号码']:=fieldbyname('相关号码').asstring; memtotal['费用名称']:=fieldbyname('费用名称').asstring; if fieldbyname('类型').AsString='收' then begin memtotal['借方金额']:=fieldbyname('人民币金额').Asfloat; memtotal['余额']:=bal+fieldbyname('人民币金额').Asfloat; memtotal['RMB借方金额']:=fieldbyname('人民币金额').Asfloat; memtotal['RMB余额']:=bal+fieldbyname('人民币金额').Asfloat; bal:=bal+fieldbyname('人民币金额').Asfloat; DR:=DR+fieldbyname('人民币金额').Asfloat; rmbbal:=rmbbal+fieldbyname('人民币金额').Asfloat; RMBDR:=RMBDR+fieldbyname('人民币金额').Asfloat; end else begin memtotal['贷方金额']:=fieldbyname('人民币金额').Asfloat; memtotal['余额']:=bal-fieldbyname('人民币金额').Asfloat; memtotal['RMB贷方金额']:=fieldbyname('人民币金额').Asfloat; memtotal['RMB余额']:=bal-fieldbyname('人民币金额').Asfloat; bal:=bal-fieldbyname('人民币金额').Asfloat; CR:=CR+fieldbyname('人民币金额').Asfloat; rmbbal:=rmbbal-fieldbyname('人民币金额').Asfloat; RMBCR:=RMBCR+fieldbyname('人民币金额').Asfloat; end; memtotal.post; end; if (fieldbyname('美元银行代码').asstring=bank) and (fieldbyname('美元金额').Asfloat<>0) then begin memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=1; memtotal['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日']:=DayOf(FieldByName('结算日期').AsDateTime); memtotal['日期']:=FieldByName('结算日期').AsDateTime; memtotal['摘要']:=fieldbyname('备注').asstring; memtotal['凭证号']:=fieldbyname('凭证号码').asstring; memtotal['客户名称']:=fieldbyname('客户名称').asstring; memtotal['银行名称']:=GetBankName(fieldbyname('银行代码').asstring); memtotal['相关部门']:=fieldbyname('相关部门').asstring; memtotal['相关人员']:=fieldbyname('相关人员').asstring; memtotal['相关号码']:=fieldbyname('相关号码').asstring; memtotal['费用名称']:=fieldbyname('费用名称').asstring; if fieldbyname('类型').AsString='收' then begin memtotal['外币借方金额']:=fieldbyname('美元金额').Asfloat; memtotal['外币余额']:=usdbal+fieldbyname('美元金额').Asfloat; memtotal['借方金额']:=fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); memtotal['余额']:=bal+fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); usdbal:=usdbal+fieldbyname('美元金额').Asfloat; bal:=bal+fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); USDDR:=USDDR+fieldbyname('美元金额').Asfloat; DR:=DR+fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); end else begin memtotal['外币贷方金额']:=fieldbyname('美元金额').Asfloat; memtotal['外币余额']:=usdbal-fieldbyname('美元金额').Asfloat; usdbal:=usdbal-fieldbyname('美元金额').Asfloat; memtotal['贷方金额']:=fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); memtotal['余额']:=bal-fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); bal:=bal-fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); USDCR:=USDCR+fieldbyname('美元金额').Asfloat; CR:=CR+fieldbyname('美元金额').Asfloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); end; memtotal.post; end; end else begin memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=1; memtotal['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日']:=DayOf(FieldByName('结算日期').AsDateTime); memtotal['日期']:=FieldByName('结算日期').AsDateTime; memtotal['摘要']:=fieldbyname('备注').asstring; memtotal['凭证号']:=fieldbyname('凭证号码').asstring; memtotal['客户名称']:=fieldbyname('客户名称').asstring; memtotal['银行名称']:=GetBankName(fieldbyname('银行代码').asstring); memtotal['相关部门']:=fieldbyname('相关部门').asstring; memtotal['相关人员']:=fieldbyname('相关人员').asstring; memtotal['相关号码']:=fieldbyname('相关号码').asstring; memtotal['费用名称']:=fieldbyname('费用名称').asstring; if trim(fieldbyname('币别').AsString)='RMB' then begin if fieldbyname('类型').AsString='收' then begin memtotal['借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['余额']:=bal+fieldbyname('结算金额').AsFloat; memtotal['RMB借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['RMB余额']:=bal+fieldbyname('结算金额').AsFloat; bal:=bal+fieldbyname('结算金额').AsFloat; DR:=DR+fieldbyname('结算金额').AsFloat; rmbbal:=rmbbal+fieldbyname('结算金额').AsFloat; RMBDR:=RMBDR+fieldbyname('结算金额').AsFloat; end else begin memtotal['贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['余额']:=bal-fieldbyname('结算金额').AsFloat; memtotal['RMB贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['RMB余额']:=bal-fieldbyname('结算金额').AsFloat; bal:=bal-fieldbyname('结算金额').AsFloat; CR:=CR+fieldbyname('结算金额').AsFloat; rmbbal:=rmbbal-fieldbyname('结算金额').AsFloat; RMBCR:=RMBCR+fieldbyname('结算金额').AsFloat; end; end else begin if fieldbyname('类型').AsString='收' then begin memtotal['外币借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['外币余额']:=usdbal+fieldbyname('结算金额').AsFloat; usdbal:=usdbal+fieldbyname('结算金额').AsFloat; USDDR:=USDDR+fieldbyname('结算金额').AsFloat; memtotal['借方金额']:=fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); memtotal['余额']:=bal+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); bal:=bal+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); DR:=DR+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); end else begin memtotal['外币贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['外币余额']:=usdbal-fieldbyname('结算金额').AsFloat; usdbal:=usdbal-fieldbyname('结算金额').AsFloat; USDCR:=USDCR+fieldbyname('结算金额').AsFloat; memtotal['贷方金额']:=fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); memtotal['余额']:=bal-fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); bal:=bal-fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); CR:=CR+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); end; end; memtotal.post; end; end else begin memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=1; memtotal['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日']:=DayOf(FieldByName('结算日期').AsDateTime); memtotal['日期']:=FieldByName('结算日期').AsDateTime; memtotal['摘要']:=fieldbyname('备注').asstring; memtotal['凭证号']:=fieldbyname('凭证号码').asstring; memtotal['客户名称']:=fieldbyname('客户名称').asstring; memtotal['银行名称']:=GetBankName(fieldbyname('银行代码').asstring); memtotal['相关部门']:=fieldbyname('相关部门').asstring; memtotal['相关人员']:=fieldbyname('相关人员').asstring; memtotal['相关号码']:=fieldbyname('相关号码').asstring; memtotal['费用名称']:=fieldbyname('费用名称').asstring; if trim(fieldbyname('币别').AsString)='RMB' then begin if fieldbyname('类型').AsString='收' then begin memtotal['借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['余额']:=bal+fieldbyname('结算金额').AsFloat; memtotal['RMB借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['RMB余额']:=bal+fieldbyname('结算金额').AsFloat; bal:=bal+fieldbyname('结算金额').AsFloat; DR:=DR+fieldbyname('结算金额').AsFloat; rmbbal:=rmbbal+fieldbyname('结算金额').AsFloat; RMBDR:=RMBDR+fieldbyname('结算金额').AsFloat; end else begin memtotal['贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['余额']:=bal-fieldbyname('结算金额').AsFloat; memtotal['RMB贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['RMB余额']:=bal-fieldbyname('结算金额').AsFloat; bal:=bal-fieldbyname('结算金额').AsFloat; CR:=CR+fieldbyname('结算金额').AsFloat; rmbbal:=rmbbal-fieldbyname('结算金额').AsFloat; RMBCR:=RMBCR+fieldbyname('结算金额').AsFloat; end; end else begin if fieldbyname('类型').AsString='收' then begin memtotal['外币借方金额']:=fieldbyname('结算金额').AsFloat; memtotal['外币余额']:=usdbal+fieldbyname('结算金额').AsFloat; usdbal:=usdbal+fieldbyname('结算金额').AsFloat; USDDR:=USDDR+fieldbyname('结算金额').AsFloat; memtotal['借方金额']:=fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); memtotal['余额']:=bal+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); bal:=bal+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); DR:=DR+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); end else begin memtotal['外币贷方金额']:=fieldbyname('结算金额').AsFloat; memtotal['外币余额']:=usdbal-fieldbyname('结算金额').AsFloat; usdbal:=usdbal-fieldbyname('结算金额').AsFloat; USDCR:=USDCR+fieldbyname('结算金额').AsFloat; memtotal['贷方金额']:=fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); memtotal['余额']:=bal-fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); bal:=bal-fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); CR:=CR+fieldbyname('结算金额').AsFloat*GetUsdExrate(FieldByName('结算日期').asstring,FieldByName('币别').asstring); end; end; memtotal.post; end; inc(i); Next; end; inc(i); memtotal.Append; memtotal['ID']:=i; memtotal['类型']:=2; memtotal['年']:=YearOf(aDate); memtotal['月']:=MonthOf(aDate); memtotal['日期']:=FieldByName('结算日期').AsDateTime; // memtotal['日']:=DayOf(aDate); memtotal['摘要']:='本月累计'; memtotal['借方金额']:=DR; memtotal['贷方金额']:=CR; memtotal['余额']:=bal; memtotal['外币借方金额']:=USDDR; memtotal['外币贷方金额']:=USDCR; memtotal['外币余额']:=usdbal; memtotal['RMB借方金额']:=RMBDR; memtotal['RMB贷方金额']:=RMBCR; memtotal['RMB余额']:=rmbbal; memtotal.post; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; aDate:=IncMonth(aDate,1); inc(i); end; end; finally FreeAndNil(aQuery); freeAndNil(frm_sys_progress); end; end; procedure Tfrm_rp_ch_genleg.bsSkinRadioGroup1Click(Sender: TObject); begin // bsSkinButton10.OnClick(sender); memtotal.EmptyTable; if bsSkinRadioGroup1.ItemIndex=0 then begin Label13.Visible:=false; RxDBLookupCombo5.Visible:=false; Label7.Visible:=true; RxDBLookupCombo1.Visible:=true; // dxDBGrid1Column7.Visible:=false; end else if bsSkinRadioGroup1.ItemIndex=1 then begin Label13.Visible:=true; RxDBLookupCombo5.Visible:=true; Label7.Visible:=false; RxDBLookupCombo1.Visible:=false; // dxDBGrid1Column7.Visible:=false; end else if bsSkinRadioGroup1.ItemIndex=2 then begin Label13.Visible:=false; RxDBLookupCombo5.Visible:=false; Label7.Visible:=true; RxDBLookupCombo1.Visible:=true; dxDBGrid1Column7.Visible:=false; end; end; procedure Tfrm_rp_ch_genleg.DBGridLegBookDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumnEh; State: TGridDrawState); begin { if memtotal.FieldByName('类型').AsInteger=0 then begin DBGridLegBook.Canvas.Brush.Color:=$00B7EBEC; DBGridLegBook.Canvas.Font.Color:=clBlack; end; if memtotal.FieldByName('类型').AsInteger=2 then begin DBGridLegBook.Canvas.Brush.Color:=$00AFCEF1; DBGridLegBook.Canvas.Font.Color:=clBlack; end; DBGridLegBook.DefaultDrawColumnCell(Rect, DataCol, Column, State); } end; procedure Tfrm_rp_ch_genleg.bsSkinButton1Click(Sender: TObject); begin grid_save_xls(dxdbgrid1); end; procedure Tfrm_rp_ch_genleg.bsSkinPanel1Resize(Sender: TObject); begin // end; procedure Tfrm_rp_ch_genleg.dxDBGrid3CustomDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxDBTreeListColumn; const AText: String; AFont: TFont; var AColor: TColor; ASelected, AFocused: Boolean; var ADone: Boolean); begin { if Trim(ANode.Strings[dxDBGrid3Column17.Index])='0' then AColor:=$00B7EBEC; if Trim(ANode.Strings[dxDBGrid3Column17.Index])='2' then AColor:=$00AFCEF1; } end; procedure Tfrm_rp_ch_genleg.dxDBGrid1CustomDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxDBTreeListColumn; const AText: String; AFont: TFont; var AColor: TColor; ASelected, AFocused: Boolean; var ADone: Boolean); begin if Trim(ANode.Strings[dxDBGrid1Column17.Index])='0' then AColor:=$00B7EBEC; if Trim(ANode.Strings[dxDBGrid1Column17.Index])='2' then AColor:=$00AFCEF1; end; procedure Tfrm_rp_ch_genleg.bsSkinComboBox1Change(Sender: TObject); begin // case bsSkinComboBox1.itemindex of 0: begin dxDBGrid1Column8.Visible:=True; dxDBGrid1Column9.Visible:=True; dxDBGrid1Column10.Visible:=True; dxDBGrid1Column11.Visible:=True; dxDBGrid1Column12.Visible:=True; dxDBGrid1Column13.Visible:=True; end; 1: begin dxDBGrid1Column8.Visible:=True; dxDBGrid1Column9.Visible:=True; dxDBGrid1Column10.Visible:=True; dxDBGrid1Column11.Visible:=False; dxDBGrid1Column12.Visible:=False; dxDBGrid1Column13.Visible:=False; end; 2: begin dxDBGrid1Column8.Visible:=False; dxDBGrid1Column9.Visible:=False; dxDBGrid1Column10.Visible:=False; dxDBGrid1Column11.Visible:=True; dxDBGrid1Column12.Visible:=True; dxDBGrid1Column13.Visible:=True; end; end; end; procedure Tfrm_rp_ch_genleg.N14Click(Sender: TObject); begin update_grid_view_all(dxdbgrid1); end; end.