unit u_rp_hl_histry; 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; type Tfrm_rp_hl_histry = 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; Label1: TLabel; cbdate: TwwDBComboBox; Label3: TLabel; cbYear: TwwDBComboBox; Label13: TLabel; RxDBLookupCombo5: TRxDBLookupCombo; Label14: TLabel; wwDBComboBox14: TwwDBComboBox; RxDBLookupCombo3: TRxDBLookupCombo; bsSkinPageControl1: TbsSkinPageControl; bsSkinTabSheet1: TbsSkinTabSheet; bsSkinTabSheet2: TbsSkinTabSheet; dxDBGrid1: TdxDBGrid; dxDBGrid1Column5: TdxDBGridColumn; dxDBGridMaskColumn95: TdxDBGridMaskColumn; memtotal1: TDataSource; memtotal: TkbmMemTable; memtotalField: TStringField; memtotalField2: TFloatField; 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; Label4: TLabel; cbeYear: TwwDBComboBox; Chart1: TChart; bsSkinRadioGroup1: TbsSkinRadioGroup; RxDBLookupCombo10: TRxDBLookupCombo; Label22: TLabel; bsSkinCheckRadioBox2: TbsSkinCheckRadioBox; bsSkinCheckRadioBox1: TbsSkinCheckRadioBox; procedure bsSkinButton5Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure Panel1Resize(Sender: TObject); procedure bsSkinButton10Click(Sender: TObject); procedure bsSkinButton1Click(Sender: TObject); procedure bsSkinButton9Click(Sender: TObject); procedure bsSkinCheckRadioBox3Click(Sender: TObject); procedure bsSkinCheckRadioBox2Click(Sender: TObject); procedure FormShow(Sender: TObject); procedure N1101Click(Sender: TObject); procedure bsSkinRadioGroup1Click(Sender: TObject); private procedure do_1(str_bill:widestring); procedure GetNoFee; procedure Getcntr; procedure Getlirun; procedure Creatememtbl; function GetZhangQi(SaleID,Cust:String):String; function isChaoQi(SaleID,Cust:String):Boolean; function GetZhangQiNum(SaleID,Cust:String;aetd:TDateTime):Double; function GetZhangQiStr(SaleID,Cust:String):String; function getleftstr(substr:String;leng:integer;left:boolean=true):String; { Private declarations } public { Public declarations } end; var frm_rp_hl_histry: Tfrm_rp_hl_histry; FmDate,ToDate:String; sqlstr:WideString; implementation uses u_main, u_rp_no_seae_query,my_sys_function, u_rp_total_query, u_rp_no_total, u_sys_progress, u_rp_no_selfno; {$R *.dfm} function Tfrm_rp_hl_histry.GetZhangQi(SaleID,Cust:String):String; var aQuery:TADOQuery; S:String; begin if (FmDate='') then begin FmDate:='2006-01-01'; end; aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; // SQL.Add('Select * from t_crm_client_sales where 状态=''审核'' and 开始日期<='''+FmDate+''' and 结束日期>='''+ToDate+''' and 客户简称='''+Cust+''' and 揽货人='''+SaleID+''''); SQL.Add('Select * from t_crm_client_sales where 状态=''审核'' and 结束日期>'''+FmDate+''' and 客户简称='''+Cust+''' and 揽货人='''+SaleID+''''); Open; if not IsEmpty then begin first; S:=''; while not eof do begin S:=S+'开始日期:'+FormatDateTime('YYYY-MM-DD',FieldByName('开始日期').AsDateTime)+',结束日期'+FormatDateTime('YYYY-MM-DD',FieldByName('结束日期').AsDateTime); if FieldByName('结费类型').AsString='现结买单' then begin S:=S+'当月结算;'; end else if FieldByName('结费类型').AsString='约定天数' then begin S:=S+'约定天数,'+fieldByName('结费期限').AsString+'天;'; end else if FieldByName('结费类型').AsString='约定时间' then begin S:=S+'约定时间,'+FieldByName('类型模式').AsString+'月;'+FieldByName('结费日期').AsString+'日结算'; end else if FieldByName('结费类型').AsString='分阶段付费' then begin S:=S+'分阶段付费;'; end; Next; end; result:=S; end else begin Result:='无账期'; end; end; finally FreeAndNil(aQuery); end; end; procedure Tfrm_rp_hl_histry.do_1(str_bill:widestring); begin end; procedure Tfrm_rp_hl_histry.bsSkinButton5Click(Sender: TObject); begin close; end; procedure Tfrm_rp_hl_histry.FormClose(Sender: TObject; var Action: TCloseAction); begin frm_rp_hl_histry.Hide; frm_rp_hl_histry.ManualFloat(frm_rp_hl_histry.BoundsRect ); frm_main.freeTabs('frm_rp_hl_histry'); action:=cafree; frm_rp_hl_histry:=nil; end; procedure Tfrm_rp_hl_histry.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_hl_histry.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 if MonthDays[isLeapYear(YearOf(aDate)),strtoint(FormatDateTime('MM',aDate))]'' then SQL.Add(' and t_ch_fee.客户名称='''+RxDBLookupCombo5.DisplayValues[1]+''''); if RxDBLookupCombo3.DisplayValue<>'' then begin if wwDBComboBox14.Text='不等于' then SQL.Add(' and t_op_seae.揽货人<>'''+RxDBLookupCombo3.DisplayValues[0]+'''') else SQL.Add(' and t_op_seae.揽货人='''+RxDBLookupCombo3.DisplayValues[0]+''''); end; if RxDBLookupCombo10.DisplayValue<>'' then begin SQL.Add(' and t_op_seae.销售部门='''+RxDBLookupCombo10.DisplayValues[0]+''''); end; Open; if not IsEmpty then begin first; while not eof do begin if memtblDetail.Locate('年度',Ydate,[]) then begin memtblDetail.Edit; memtblDetail.FieldByName(sDate+'数量').AsFloat:=memtblDetail.FieldByName(sDate+'数量').AsFloat+FieldbyName('未收合计').AsFloat; memtblDetail.Post; end else begin memtblDetail.Insert; for i:=0 to memtbldetail.FieldCount-1 do begin if memtbldetail.Fields[i].FieldName='年度' then memtbldetail.Fields[i].AsString:=Ydate else memtbldetail.Fields[i].AsFloat:=0; end; memtblDetail.FieldByName(sDate+'数量').AsFloat:=memtblDetail.FieldByName(sDate+'数量').AsFloat+FieldbyName('未收合计').AsFloat; memtblDetail.Post; end; Next; end; end; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; CLOSE; SQL.Clear; SQL.Add('Select '); SQL.Add('sum(case v_fee_do_detail.类型 when ''收'' then (case v_fee_do_detail.原始币别 when ''USD'' then v_fee_do_detail.原始金额 else 0 end) else 0 end) as 未收USD,'); SQL.Add('sum(case v_fee_do_detail.类型 when ''收'' then (case v_fee_do_detail.原始币别 when ''USD'' then 0 else v_fee_do_detail.原始金额 end) else 0 end) as 未收RMB,'); SQL.Add('sum(case v_fee_do_detail.类型 when ''收'' then v_fee_do_detail.原始金额*v_fee_do_detail.汇率 else 0 end) as 未收合计'); SQL.Add('from v_fee_do_detail inner join t_op_seae on v_fee_do_detail.编号=t_op_seae.编号 where t_op_seae.'+datetype+'<='''+strdate+''' and v_fee_do_detail.结算日期>'''+strdate+''''); if RxDBLookupCombo5.DisplayValues[1]<>'' then SQL.Add(' and v_fee_do_detail.客户名称='''+RxDBLookupCombo5.DisplayValues[1]+''''); if RxDBLookupCombo3.DisplayValue<>'' then begin if wwDBComboBox14.Text='不等于' then SQL.Add(' and t_op_seae.揽货人<>'''+RxDBLookupCombo3.DisplayValues[0]+'''') else SQL.Add(' and t_op_seae.揽货人='''+RxDBLookupCombo3.DisplayValues[0]+''''); end; if RxDBLookupCombo10.DisplayValue<>'' then begin SQL.Add(' and t_op_seae.销售部门='''+RxDBLookupCombo10.DisplayValues[0]+''''); end; Open; if not IsEmpty then begin first; while not eof do begin if memtblDetail.Locate('年度',ydate,[]) then begin memtblDetail.Edit; memtblDetail.FieldByName(sDate+'数量').AsFloat:=memtblDetail.FieldByName(sDate+'数量').AsFloat+FieldbyName('未收合计').AsFloat; memtblDetail.Post; end else begin memtblDetail.Insert; for i:=0 to memtbldetail.FieldCount-1 do begin if memtbldetail.Fields[i].FieldName='年度' then memtbldetail.Fields[i].AsString:=ydate else memtbldetail.Fields[i].AsFloat:=0; end; memtblDetail.FieldByName(sDate+'数量').AsFloat:=memtblDetail.FieldByName(sDate+'数量').AsFloat+FieldbyName('未收合计').AsFloat; memtblDetail.Post; end; Next; end; end; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; aDate:=IncMonth(aDate,1); end; end; finally FreeAndNil(aQuery); freeAndNil(frm_sys_progress); end; end; procedure Tfrm_rp_hl_histry.Creatememtbl; var aDate,aToDate:TDate; sDate,aYear,aMonth,acaption:String; aColumn:TdxDBTreeListColumn; aBand:TdxTreeListBand; i:integer; begin dxDBGrid1.Bands.Clear; // dxDBGrid1.DestroyColumns; while dxDBGrid1.columncount>0 do begin dxDBGrid1.Columns[0].Destroy; end; memtblDetail.Close; memtblDetail.EmptyTable; if bsSkinRadioGroup1.ItemIndex=0 then begin acaption:='标箱'; end else if bsSkinRadioGroup1.ItemIndex=1 then begin acaption:='利润'; end else if bsSkinRadioGroup1.ItemIndex=2 then begin acaption:='欠费'; end; { memtblDetail.Fields.Clear; memtblDetail.FieldDefs.Clear; memtblDetail.FieldDefs.Add('年度', ftString, 20, false); } aBand:=dxDBGrid1.Bands.Add; aBand.Caption:='基本信息'; aColumn:=dxDBGrid1.CreateColumn(TdxDBGridColumn); aColumn.Caption:='年度'; aColumn.BandIndex:=0; aColumn.FieldName:='年度'; aBand:=dxDBGrid1.Bands.Add; aBand.Caption:=acaption; for i:=1 to 12 do begin aMonth:=getleftstr(inttostr(i),2); aColumn:=dxDBGrid1.CreateColumn(TdxDBGridColumn); aColumn.Caption:=aMonth+'月份'+acaption; aColumn.FieldName:=aMonth+'数量'; aColumn.SummaryFooterType:=cstAvg; aColumn.BandIndex:=1; // memtblDetail.FieldDefs.Add(aMonth+'数量',ftFloat, 0, false); end; aColumn:=dxDBGrid1.CreateColumn(TdxDBGridColumn); aColumn.Caption:='平均'+acaption; aColumn.FieldName:='平均数量'; aColumn.SummaryFooterType:=cstAvg; aColumn.BandIndex:=1; // memtblDetail.FieldDefs.Add('平均数量',ftFloat, 0, false); // memtblDetail.CreateTable; memtblDetail.Open; end; function Tfrm_rp_hl_histry.GetZhangQiNum(SaleID, Cust: String; aetd: TDateTime): Double; begin end; function Tfrm_rp_hl_histry.isChaoQi(SaleID, Cust: String): Boolean; begin end; procedure Tfrm_rp_hl_histry.bsSkinCheckRadioBox3Click(Sender: TObject); begin GetNoFee; end; procedure Tfrm_rp_hl_histry.bsSkinCheckRadioBox2Click(Sender: TObject); begin GetNoFee; end; function Tfrm_rp_hl_histry.GetZhangQiStr(SaleID, Cust: String): String; begin end; procedure Tfrm_rp_hl_histry.FormShow(Sender: TObject); begin cbyear.Items.IndexOf(FormatDateTime('YYYY',Now)); cbyear.text:=FormatDateTime('YYYY',Now); cbeyear.Items.IndexOf(FormatDateTime('YYYY',Now)); cbeyear.text:=FormatDateTime('YYYY',Now); cbdate.Items.IndexOf('31'); cbdate.text:='31'; end; procedure Tfrm_rp_hl_histry.N1101Click(Sender: TObject); begin chartpreview(frm_rp_hl_histry,chart1); end; function Tfrm_rp_hl_histry.getleftstr(substr: String; leng: integer; left: boolean=true): String; var str:String; begin str:=substr; if length(str)>=leng then begin result:=str; exit; end; while length(str)aToDate) do begin if MonthDays[isLeapYear(YearOf(aDate)),strtoint(FormatDateTime('MM',aDate))]='''+strbdate+''''); if RxDBLookupCombo5.DisplayValues[1]<>'' then SQL.Add(' and t_op_seae.委托单位='''+RxDBLookupCombo5.DisplayValues[1]+''''); if RxDBLookupCombo3.DisplayValue<>'' then begin if wwDBComboBox14.Text='不等于' then SQL.Add(' and t_op_seae.揽货人<>'''+RxDBLookupCombo3.DisplayValues[0]+'''') else SQL.Add(' and t_op_seae.揽货人='''+RxDBLookupCombo3.DisplayValues[0]+''''); end; if RxDBLookupCombo10.DisplayValue<>'' then begin SQL.Add(' and t_op_seae.销售部门='''+RxDBLookupCombo10.DisplayValues[0]+''''); end; Open; if not IsEmpty then begin first; while not eof do begin if memtblDetail.Locate('年度',Ydate,[]) then begin memtblDetail.Edit; memtblDetail.FieldByName(sDate+'数量').AsFloat:=memtblDetail.FieldByName(sDate+'数量').AsFloat+FieldbyName('数量').AsFloat; memtblDetail.Post; end else begin memtblDetail.Insert; for i:=0 to memtbldetail.FieldCount-1 do begin if memtbldetail.Fields[i].FieldName='年度' then memtbldetail.Fields[i].AsString:=Ydate else memtbldetail.Fields[i].AsFloat:=0; end; memtblDetail.FieldByName(sDate+'数量').AsFloat:=memtblDetail.FieldByName(sDate+'数量').AsFloat+FieldbyName('数量').AsFloat; memtblDetail.Post; end; Next; end; end; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; aDate:=IncMonth(aDate,1); end; end; finally FreeAndNil(aQuery); freeAndNil(frm_sys_progress); end; end; procedure Tfrm_rp_hl_histry.Getlirun; var aQuery:TAdoQuery; aDate,aToDate:TDate; strdate,strbdate,sDate,yDate,datetype:String; i:integer; // S:TChartSeries; begin // DBChart3.AddSeries(); datetype:='开船日期'; if (bsSkinCheckRadioBox1.Checked) then datetype:='预抵日期'; aQuery:=CreateAdoQuery; try with aQuery do begin aDate:=EncodeDate(strtoint(cbYear.Text),1,1); aToDate:=EncodeDate(strtoint(cbeYear.Text),12,2); if not ASSIGNED(frm_sys_progress) then frm_sys_progress:=tfrm_sys_progress.Create(application); frm_sys_progress.Show; frm_sys_progress.bsSkinGauge1.MaxValue:=MonthsBetween(aDate,aToDate)*2; frm_sys_progress.bsSkinGauge1.MinValue:=0; frm_sys_progress.bsSkinGauge1.Value:=0; frm_sys_progress.Update; while not (aDate>aToDate) do begin if MonthDays[isLeapYear(YearOf(aDate)),strtoint(FormatDateTime('MM',aDate))]='''+strbdate+''''); if RxDBLookupCombo5.DisplayValues[1]<>'' then SQL.Add(' and t_op_seae.委托单位='''+RxDBLookupCombo5.DisplayValues[1]+''''); if RxDBLookupCombo3.DisplayValue<>'' then begin if wwDBComboBox14.Text='不等于' then SQL.Add(' and t_op_seae.揽货人<>'''+RxDBLookupCombo3.DisplayValues[0]+'''') else SQL.Add(' and t_op_seae.揽货人='''+RxDBLookupCombo3.DisplayValues[0]+''''); end; if RxDBLookupCombo10.DisplayValue<>'' then begin SQL.Add(' and t_op_seae.销售部门='''+RxDBLookupCombo10.DisplayValues[0]+''''); end; Open; if not IsEmpty then begin first; while not eof do begin if memtblDetail.Locate('年度',Ydate,[]) then begin memtblDetail.Edit; memtblDetail.FieldByName(sDate+'数量').AsFloat:=memtblDetail.FieldByName(sDate+'数量').AsFloat+FieldbyName('数量').AsFloat; memtblDetail.Post; end else begin memtblDetail.Insert; for i:=0 to memtbldetail.FieldCount-1 do begin if memtbldetail.Fields[i].FieldName='年度' then memtbldetail.Fields[i].AsString:=Ydate else memtbldetail.Fields[i].AsFloat:=0; end; memtblDetail.FieldByName(sDate+'数量').AsFloat:=memtblDetail.FieldByName(sDate+'数量').AsFloat+FieldbyName('数量').AsFloat; memtblDetail.Post; end; Next; end; end; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; aDate:=IncMonth(aDate,1); end; end; finally FreeAndNil(aQuery); freeAndNil(frm_sys_progress); end; end; procedure Tfrm_rp_hl_histry.bsSkinRadioGroup1Click(Sender: TObject); begin bsSkinButton10.OnClick(sender); end; end.