unit u_rp_drstl_self; 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, bsSkinBoxCtrls, DBGrids, wwdblook; type Tfrm_rp_drstl_self = class(TForm) Panel1: TPanel; bsSkinPanel2: TbsSkinPanel; bsSkinButton10: TbsSkinButton; bsSkinButton9: TbsSkinButton; bsSkinButton1: TbsSkinButton; bsSkinButton5: TbsSkinButton; p_total_client1: TDataSource; p_total_sales1: TDataSource; SaveDialog: TSaveDialog; bsSkinPageControl4: TbsSkinPageControl; bsSkinTabSheet3: TbsSkinTabSheet; dxDBGrid3: TdxDBGrid; dxDBGrid3Column22: TdxDBGridColumn; dxDBGridColumn59: TdxDBGridColumn; dxDBGridColumn60: TdxDBGridColumn; dxDBGridColumn61: TdxDBGridColumn; dxDBGridColumn62: TdxDBGridColumn; dxDBGridColumn63: TdxDBGridColumn; dxDBGridColumn64: TdxDBGridColumn; dxDBGridColumn65: TdxDBGridColumn; dxDBGridColumn66: TdxDBGridColumn; dxDBGridColumn67: TdxDBGridColumn; dxDBGridColumn68: TdxDBGridColumn; dxDBGridColumn69: TdxDBGridColumn; dxDBGridColumn70: TdxDBGridColumn; dxDBGridColumn71: TdxDBGridColumn; dxDBGridColumn72: TdxDBGridColumn; dxDBGridColumn73: TdxDBGridColumn; dxDBGridColumn74: TdxDBGridColumn; dxDBGridColumn75: TdxDBGridColumn; dxDBGridColumn76: TdxDBGridColumn; dxDBGridColumn77: TdxDBGridColumn; dxDBGridColumn78: TdxDBGridColumn; dxDBGridColumn79: TdxDBGridColumn; p_accept_bill: TADOStoredProc; p_accept_bill1: TDataSource; kbmBinaryStreamFormat1: TkbmBinaryStreamFormat; kbmThreadDataSet1: TkbmThreadDataSet; memtblrpt_total2: TkbmMemTable; PopupMenu1: TPopupMenu; N1: TMenuItem; N2: TMenuItem; N1101: TMenuItem; memtblrpt_total1: TDataSource; memtblDetail: TkbmMemTable; memtblField: TkbmMemTable; memtblFieldFieldName: TStringField; memtblFieldDisplayName: TStringField; memtblFieldlength: TIntegerField; memtblFieldFooterSum: TSmallintField; bstab1: TbsSkinTabSheet; bsSkinPanel1: TbsSkinPanel; bsSkinPageControl1: TbsSkinPageControl; tab1: TbsSkinTabSheet; bsSkinTabSheet2: TbsSkinTabSheet; tab3: TbsSkinTabSheet; tab4: TbsSkinTabSheet; dxDBGrid2: TdxDBGrid; dxDBGridColumn18: TdxDBGridColumn; dxDBGridColumn22: TdxDBGridColumn; dxDBGrid4: TdxDBGrid; dxDBGridColumn1: TdxDBGridColumn; dxDBGridColumn2: TdxDBGridColumn; dxDBGrid4Column3: TdxDBGridColumn; dxDBGrid6: TdxDBGrid; dxDBGridColumn3: TdxDBGridColumn; dxDBGridColumn4: TdxDBGridColumn; dxDBGridColumn5: TdxDBGridColumn; dxDBGrid7: TdxDBGrid; dxDBGridColumn6: TdxDBGridColumn; dxDBGridMaskColumn2: TdxDBGridMaskColumn; dxDBGridMaskColumn3: TdxDBGridMaskColumn; dxDBGridMaskColumn4: TdxDBGridMaskColumn; dxDBGridMaskColumn5: TdxDBGridMaskColumn; dxDBGridMaskColumn6: TdxDBGridMaskColumn; dxDBGridColumn10: TdxDBGridColumn; dxDBGridColumn11: TdxDBGridColumn; dxDBGridColumn12: TdxDBGridColumn; dxDBGridColumn13: TdxDBGridColumn; dxDBGridColumn14: TdxDBGridColumn; dxDBGridColumn15: TdxDBGridColumn; dxDBGridColumn16: TdxDBGridColumn; dxDBGridColumn17: TdxDBGridColumn; dxDBGridColumn19: TdxDBGridColumn; dxDBGridColumn20: TdxDBGridColumn; dxDBGridColumn21: TdxDBGridColumn; dxDBGridColumn23: TdxDBGridColumn; dxDBGridColumn24: TdxDBGridColumn; dxDBGridColumn25: TdxDBGridColumn; dxDBGridDateColumn1: TdxDBGridDateColumn; dxDBGridColumn26: TdxDBGridColumn; dxDBGridMaskColumn7: TdxDBGridMaskColumn; dxDBGridMaskColumn8: TdxDBGridMaskColumn; dxDBGridMaskColumn9: TdxDBGridMaskColumn; dxDBGridMaskColumn10: TdxDBGridMaskColumn; dxDBGridMaskColumn11: TdxDBGridMaskColumn; dxDBGridMaskColumn12: TdxDBGridMaskColumn; dxDBGridDateColumn2: TdxDBGridDateColumn; dxDBGridMaskColumn13: TdxDBGridMaskColumn; dxDBGridMaskColumn14: TdxDBGridMaskColumn; dxDBGridMaskColumn15: TdxDBGridMaskColumn; dxDBGridMaskColumn16: TdxDBGridMaskColumn; dxDBGridMaskColumn17: TdxDBGridMaskColumn; dxDBGridColumn27: TdxDBGridColumn; dxDBGridColumn28: TdxDBGridColumn; dxDBGridMaskColumn18: TdxDBGridMaskColumn; dxDBGridMaskColumn19: TdxDBGridMaskColumn; dxDBGridMaskColumn20: TdxDBGridMaskColumn; dxDBGridMaskColumn21: TdxDBGridMaskColumn; dxDBGridMaskColumn22: TdxDBGridMaskColumn; dxDBGridMaskColumn23: TdxDBGridMaskColumn; dxDBGridMaskColumn24: TdxDBGridMaskColumn; dxDBGridMaskColumn25: TdxDBGridMaskColumn; dxDBGridMaskColumn26: TdxDBGridMaskColumn; dxDBGridMaskColumn27: TdxDBGridMaskColumn; dxDBGridMaskColumn28: TdxDBGridMaskColumn; dxDBGridMaskColumn29: TdxDBGridMaskColumn; dxDBGridMaskColumn30: TdxDBGridMaskColumn; dxDBGridMaskColumn31: TdxDBGridMaskColumn; dxDBGridMaskColumn32: TdxDBGridMaskColumn; dxDBGridMaskColumn33: TdxDBGridMaskColumn; dxDBGridMaskColumn34: TdxDBGridMaskColumn; dxDBGridMaskColumn35: TdxDBGridMaskColumn; dxDBGridMaskColumn36: TdxDBGridMaskColumn; dxDBGridMaskColumn37: TdxDBGridMaskColumn; dxDBGridColumn29: TdxDBGridColumn; dxDBGridColumn30: TdxDBGridColumn; dxDBGridColumn31: TdxDBGridColumn; dxDBGridColumn32: TdxDBGridColumn; mem_total_sales: TkbmMemTable; mem_total_client: TkbmMemTable; mem_total_dept: TkbmMemTable; p_total_dept1: TDataSource; p_total1: TDataSource; mem_total_deptField: TStringField; mem_total_deptField2: TFloatField; mem_total_salesField: TStringField; mem_total_salesField2: TStringField; mem_total_clientField: TStringField; mem_total_clientField2: TStringField; dxDBGrid2Column3: TdxDBGridColumn; dxDBGrid4Column4: TdxDBGridColumn; dxDBGrid6Column5: TdxDBGridColumn; mem_client: TkbmMemTable; StringField1: TStringField; StringField2: TStringField; FloatField1: TFloatField; mem_clientField: TFloatField; dxDBGrid7Column64: TdxDBGridColumn; dxDBGrid4Column5: TdxDBGridColumn; dxDBGrid4Column6: TdxDBGridColumn; dxDBGrid6Column6: TdxDBGridColumn; dxDBGrid7Column65: TdxDBGridColumn; memtblrpt_total2Field: TStringField; memtblrpt_total2Field2: TStringField; memtblrpt_total2Field3: TStringField; memtblrpt_total2Field4: TIntegerField; memtblrpt_total2Field5: TIntegerField; memtblrpt_total2Field6: TStringField; memtblrpt_total2Field7: TStringField; memtblrpt_total2Field8: TStringField; memtblrpt_total2Field9: TDateTimeField; memtblrpt_total2USD: TFloatField; memtblrpt_total2USD2: TFloatField; memtblrpt_total2USD3: TFloatField; memtblrpt_total2RMB: TFloatField; memtblrpt_total2RMB2: TFloatField; memtblrpt_total2RMB3: TFloatField; memtblrpt_total2Field11: TFloatField; memtblrpt_total2Field12: TFloatField; memtblrpt_total2Field13: TFloatField; memtblrpt_total2Field14: TFloatField; memtblrpt_total2Field15: TFloatField; memtblrpt_total2Field16: TFloatField; memtblrpt_total2Field17: TFloatField; memtblrpt_total2Field19: TIntegerField; memtblrpt_total2Field20: TStringField; memtblrpt_total2Field21: TStringField; memtblrpt_total2Field22: TStringField; memtblrpt_total2Field23: TStringField; memtblrpt_total2Field24: TStringField; memtblrpt_total2Field25: TStringField; memtblrpt_total2Field26: TStringField; memtblrpt_total2Field27: TStringField; memtblrpt_total2Field28: TStringField; memtblrpt_total2Field29: TIntegerField; memtblrpt_total2Field30: TStringField; memtblrpt_total2Field31: TFloatField; memtblrpt_total2Field32: TFloatField; memtblrpt_total2Field1: TIntegerField; memtblrpt_total2Field210: TIntegerField; memtblrpt_total2Field33: TIntegerField; memtblrpt_total2Field42: TIntegerField; memtblrpt_total2Field52: TIntegerField; memtblrpt_total2Field62: TIntegerField; memtblrpt_total2Field72: TIntegerField; memtblrpt_total2Field82: TIntegerField; memtblrpt_total2Field92: TIntegerField; memtblrpt_total2Field102: TIntegerField; memtblrpt_total2Field34: TIntegerField; memtblrpt_total2TEU: TIntegerField; memtblrpt_total2Field35: TStringField; memtblrpt_total2Field36: TStringField; memtblrpt_total2Field37: TStringField; memtblrpt_total2Field38: TStringField; memtblrpt_total2Field39: TStringField; memtblrpt_total2Field40: TStringField; memtblrpt_total2Field41: TStringField; memtblrpt_total2Field43: TStringField; memtblrpt_total2Field44: TStringField; memtblrpt_total2Field45: TStringField; memtblrpt_total2Field46: TStringField; memtblrpt_total2Field47: TStringField; memtblrpt_total2Field48: TStringField; memtblrpt_total2Field50: TStringField; memtblrpt_total2Field10: TDateField; memtblrpt_total2Field18: TDateField; bsSkinButton12: TbsSkinButton; PopupMenu2: TPopupMenu; N10: TMenuItem; N11: TMenuItem; N14: TMenuItem; N13: TMenuItem; N12: TMenuItem; N15: TMenuItem; N16: TMenuItem; mem_clientUSD: TFloatField; mem_clientRMB: TFloatField; mem_clientFloatField: TFloatField; mem_clientFloatField2: TFloatField; mem_clientmonth: TkbmMemTable; StringField3: TStringField; StringField4: TStringField; FloatField2: TFloatField; FloatField3: TFloatField; FloatField4: TFloatField; FloatField5: TFloatField; FloatField6: TFloatField; FloatField7: TFloatField; mem_clientmonthStringField: TStringField; mem_clientsum: TkbmMemTable; StringField5: TStringField; StringField6: TStringField; FloatField8: TFloatField; FloatField9: TFloatField; FloatField10: TFloatField; FloatField11: TFloatField; FloatField12: TFloatField; FloatField13: TFloatField; memtblrpt_total2Field51: TStringField; memtblrpt_total2StringField: TStringField; mem_sum: TkbmMemTable; StringField7: TStringField; StringField8: TStringField; FloatField14: TFloatField; FloatField15: TFloatField; FloatField16: TFloatField; FloatField17: TFloatField; FloatField18: TFloatField; FloatField19: TFloatField; mem_clientField2: TStringField; dxDBGrid7Column66: TdxDBGridColumn; mem_clientsumField: TStringField; memtblrpt_total2Field53: TStringField; dxDBGrid7Column67: TdxDBGridColumn; memtblrpt_total2Field54: TStringField; memtblrpt_total2Field55: TFloatField; memtblrpt_total2Field56: TFloatField; mem_total_deptFloatField: TFloatField; mem_total_deptFloatField2: TFloatField; dxDBGrid2Column4: TdxDBGridColumn; dxDBGrid6Column9: TdxDBGridColumn; mem_clientmonth1: TDataSource; mem_clientmonthUSD: TFloatField; mem_clientmonthUSD2: TFloatField; mem_clientmonthRMB: TFloatField; mem_clientmonthRMB2: TFloatField; mem_clientmonthFloatField: TFloatField; mem_clientmonthFloatField2: TFloatField; mem_clientmonthFloatField3: TFloatField; mem_clientmonthFloatField4: TFloatField; mem_clientmonthFloatField5: TFloatField; mem_clientmonthFloatField6: TFloatField; mem_clientmonthIntegerField: TIntegerField; mem_clientmonthDateTimeField: TDateTimeField; memtblrpt_total2Field57: TDateField; dxDBGrid7Column68: TdxDBGridColumn; mem_total_deptField3: TStringField; dxDBGrid2Column5: TdxDBGridColumn; mem_total_salesFloatField: TFloatField; mem_total_salesFloatField2: TFloatField; mem_total_salesStringField: TStringField; mem_total_salesFloatField3: TFloatField; mem_total_clientFloatField: TFloatField; mem_total_clientFloatField2: TFloatField; mem_total_clientStringField: TStringField; mem_total_clientFloatField3: TFloatField; memtblrpt_total2Field49: TStringField; memtblrpt_total2Field58: TStringField; memtblrpt_total2Field59: TStringField; dxDBGrid7Column69: TdxDBGridColumn; dxDBGrid7Column70: TdxDBGridColumn; memtblrpt_total2FloatField: TFloatField; dxDBGrid7Column71: TdxDBGridColumn; bsSkinComboBox1: TbsSkinComboBox; Label1: TLabel; memtblrpt_total: TkbmMemTable; memtblrpt_totalField: TStringField; memtblrpt_totalField2: TStringField; memtblrpt_totalField3: TStringField; memtblrpt_totalField6: TStringField; memtblrpt_totalField7: TStringField; memtblrpt_totalField8: TStringField; memtblrpt_totalField9: TDateTimeField; memtblrpt_totalUSD: TFloatField; memtblrpt_totalUSD2: TFloatField; memtblrpt_totalUSD3: TFloatField; memtblrpt_totalRMB: TFloatField; memtblrpt_totalRMB2: TFloatField; memtblrpt_totalRMB3: TFloatField; memtblrpt_totalField11: TFloatField; memtblrpt_totalField12: TFloatField; memtblrpt_totalField13: TFloatField; memtblrpt_totalField14: TFloatField; memtblrpt_totalField15: TFloatField; memtblrpt_totalField16: TFloatField; memtblrpt_totalField17: TFloatField; memtblrpt_totalUSD4: TFloatField; memtblrpt_totalField19: TIntegerField; memtblrpt_totalField20: TStringField; memtblrpt_totalField21: TStringField; memtblrpt_totalField22: TStringField; memtblrpt_totalField23: TStringField; memtblrpt_totalField24: TStringField; memtblrpt_totalField25: TStringField; memtblrpt_totalField26: TStringField; memtblrpt_totalField27: TStringField; memtblrpt_totalField28: TStringField; memtblrpt_totalField29: TIntegerField; memtblrpt_totalField30: TStringField; memtblrpt_totalField31: TFloatField; memtblrpt_totalField32: TFloatField; memtblrpt_totalField1: TIntegerField; memtblrpt_totalField210: TIntegerField; memtblrpt_totalField33: TIntegerField; memtblrpt_totalField42: TIntegerField; memtblrpt_totalField52: TIntegerField; memtblrpt_totalField62: TIntegerField; memtblrpt_totalField72: TIntegerField; memtblrpt_totalField82: TIntegerField; memtblrpt_totalField92: TIntegerField; memtblrpt_totalField102: TIntegerField; memtblrpt_totalField34: TIntegerField; memtblrpt_totalTEU: TIntegerField; memtblrpt_totalField35: TStringField; memtblrpt_totalField36: TStringField; memtblrpt_totalField37: TStringField; memtblrpt_totalField38: TStringField; memtblrpt_totalField39: TStringField; memtblrpt_totalField40: TStringField; memtblrpt_totalField41: TStringField; memtblrpt_totalField43: TStringField; memtblrpt_totalField44: TStringField; memtblrpt_totalField45: TStringField; memtblrpt_totalField46: TStringField; memtblrpt_totalField47: TStringField; memtblrpt_totalField48: TStringField; memtblrpt_totalField50: TStringField; memtblrpt_totalField10: TDateField; memtblrpt_totalField18: TDateField; memtblrpt_totalField51: TStringField; memtblrpt_totalStringField: TStringField; memtblrpt_totalField53: TStringField; memtblrpt_totalField54: TStringField; memtblrpt_totalField55: TFloatField; memtblrpt_totalField56: TFloatField; memtblrpt_totalField57: TDateField; wwDBLookupCombo49: TwwDBLookupCombo; Label2: TLabel; bsSkinButton2: TbsSkinButton; memtblrpt_totalField4: TStringField; Label24: TLabel; wwDBDateTimePicker5: TwwDBDateTimePicker; Label26: TLabel; wwDBDateTimePicker6: TwwDBDateTimePicker; memtblrpt_totalField5: TIntegerField; dxDBGrid7Column72: TdxDBGridColumn; bsSkinTabSheet5: TbsSkinTabSheet; dxDBGrid1: TdxDBGrid; dxDBGrid1Column1: TdxDBGridMaskColumn; dxDBGrid1Column17: TdxDBGridColumn; dxDBGrid1Column4: TdxDBGridMaskColumn; dxDBGrid1Column6: TdxDBGridColumn; dxDBGrid1Column7: TdxDBGridColumn; dxDBGrid1Column8: TdxDBGridColumn; dxDBGrid1Column11: TdxDBGridMaskColumn; dxDBGrid1Column12: TdxDBGridDateColumn; dxDBGrid1Column15: TdxDBGridColumn; dxDBGrid1Column16: TdxDBGridColumn; dxDBGrid1Column13: TdxDBGridMaskColumn; dxDBGrid1Column14: TdxDBGridDateColumn; dxDBGrid1Column18: TdxDBGridColumn; dxDBGrid1Column19: TdxDBGridColumn; dxDBGrid1Column20: TdxDBGridColumn; t_ch_fee_balance1: TDataSource; t_ch_fee_balance: TADOQuery; PopupMenu3: TPopupMenu; MenuItem1: TMenuItem; MenuItem2: TMenuItem; MenuItem3: TMenuItem; MenuItem4: TMenuItem; MenuItem5: TMenuItem; MenuItem6: TMenuItem; MenuItem7: TMenuItem; dxDBGrid7Column73: TdxDBGridColumn; dxDBGrid1Column21: TdxDBGridColumn; dxDBGrid1Column22: TdxDBGridColumn; dxDBGrid7Column74: TdxDBGridColumn; dxDBGrid6Column7: TdxDBGridColumn; mem_total_clientField3: TStringField; memtblrpt_totalField49: TStringField; 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 dxDBGrid5DblClick(Sender: TObject); procedure dxDBGrid6DblClick(Sender: TObject); procedure dxDBGrid7DblClick(Sender: TObject); procedure dxDBGrid8DblClick(Sender: TObject); procedure bsSkinButton15Click(Sender: TObject); procedure bsSkinCheckRadioBox3Click(Sender: TObject); procedure bsSkinCheckRadioBox2Click(Sender: TObject); procedure bsSkinButton12Click(Sender: TObject); procedure N10Click(Sender: TObject); procedure N14Click(Sender: TObject); procedure N12Click(Sender: TObject); procedure N16Click(Sender: TObject); procedure bsSkinButton2Click(Sender: TObject); procedure dxDBGrid7Click(Sender: TObject); procedure MenuItem1Click(Sender: TObject); procedure MenuItem3Click(Sender: TObject); procedure MenuItem5Click(Sender: TObject); procedure MenuItem7Click(Sender: TObject); procedure FormShow(Sender: TObject); private procedure do_1(str_bill:widestring); procedure GetNoFee; procedure Creatememtbl; function GetZhangQi(SaleID,Cust:String):String; function isChaoQi(SaleID,Cust:String):Boolean; function GetZhangQiNum(SaleID,Cust:String;aetd:TDateTime;out zqstr:string):Double; function GetZhangQiStr(SaleID,Cust:String):String; function GetBetwMonth(aBe, aEe: TDate): Integer; { Private declarations } public { Public declarations } end; var frm_rp_drstl_self: Tfrm_rp_drstl_self; FmDate,ToDate,zhangdate: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_code_skjlset, u_data_share; {$R *.dfm} function Tfrm_rp_drstl_self.GetBetwMonth(aBe, aEe: TDate): Integer; var bYear,bMonth,bDate,eYear,eMonth,eDate:Word; begin DecodeDate(aBe,bYear,bMonth,bDate); DecodeDate(aEe,eYear,eMonth,eDate); if bYear=eYear then Result:=Abs(bMonth-eMonth) else begin if bYear>eYear then begin Result:=bMonth+(12-eMonth); end else begin Result:=eMonth+(12-bMonth); end; end; end; function Tfrm_rp_drstl_self.GetZhangQi(SaleID,Cust:String):String; var aQuery:TADOQuery; S,sub: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 if StrToIntDef(FieldByName('类型模式').AsString,0)=0 then sub:='当月' else if StrToIntDef(FieldByName('类型模式').AsString,0)=1 then sub:='次1月' else if StrToIntDef(FieldByName('类型模式').AsString,0)=2 then sub:='次2月' else if StrToIntDef(FieldByName('类型模式').AsString,0)=3 then sub:='次3月' else sub:='次'+inttostr(StrToIntDef(FieldByName('类型模式').AsString,0))+'月'; if FieldByName('日期模式').AsString='固定' then S:=sub+FieldByName('结费日期').AsString+'日' else S:=sub; 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_drstl_self.do_1(str_bill:widestring); begin end; procedure Tfrm_rp_drstl_self.bsSkinButton5Click(Sender: TObject); begin close; end; procedure Tfrm_rp_drstl_self.FormClose(Sender: TObject; var Action: TCloseAction); begin savereggrid(dxdbgrid1,caption+'1'); savereggrid(dxdbgrid7,caption+'7'); frm_rp_drstl_self.Hide; frm_rp_drstl_self.ManualFloat(frm_rp_drstl_self.BoundsRect ); frm_main.freeTabs('frm_rp_drstl_self'); action:=cafree; frm_rp_drstl_self:=nil; end; procedure Tfrm_rp_drstl_self.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_drstl_self.bsSkinButton10Click(Sender: TObject); var zdate:Tdate; num:double; j,btdays:integer; zqstr,sdate:string; function getstlDate(Cust,SaleID:String;aetdDate:TDatetime):TDateTime; var aQuery2:TADOQuery; aYear,aMonth,aDay,bDay:word; aStlDate:TDateTime; begin aQuery2:=CreateAdoQuery; aStlDate:=aetdDate; try with aQuery2 do begin Close;SQL.Clear; SQL.Add('Select * from t_crm_client_sales where 状态=''审核'' and 开始日期<='''+FormatDateTime('YYYY-MM-DD',aStlDate)+''' and 结束日期>='''+FormatDateTime('YYYY-MM-DD',aStlDate)+''' and 客户简称='''+Cust+''' and 揽货人='''+SaleID+''''); Open; if not IsEmpty then begin if FieldByName('结费类型').AsString='现结买单' then begin Result:=aStlDate; end else if FieldByName('结费类型').AsString='约定天数' then begin result:=aStlDate+fieldByName('结费期限').AsInteger; end else if FieldByName('结费类型').AsString='约定时间' then begin if FieldByName('日期模式').AsString='固定' then begin DecodeDate(IncMonth(aStlDate,StrToIntDef(FieldByName('类型模式').AsString,0)),aYear,aMonth,aDay); bDay:=DaysInMonth(EncodeDate(aYear,aMonth,1)); if fieldByName('结费日期').AsInteger>bDay then result:=EncodeDate(aYear,aMonth,bDay) else if fieldByName('结费日期').AsInteger>0 then result:=EncodeDate(aYear,aMonth,fieldByName('结费日期').AsInteger) else result:=EncodeDate(aYear,aMonth,1); end else result:=IncMonth(aStlDate,StrToIntDef(FieldByName('类型模式').AsString,0)); end else if FieldByName('结费类型').AsString='分阶段付费' then begin DecodeDate(IncMonth(aStlDate,StrToIntDef(FieldByName('类型模式').AsString,0)),aYear,aMonth,aDay); if aDay>fieldByName('结束日期').AsInteger then begin bDay:=DaysInMonth(EncodeDate(aYear,aMonth,1)); if fieldByName('结费日期2').AsInteger>bDay then result:=EncodeDate(aYear,aMonth,bDay) else if fieldByName('结费日期2').AsInteger>0 then result:=EncodeDate(aYear,aMonth,fieldByName('结费日期2').AsInteger) else result:=EncodeDate(aYear,aMonth,1) end else begin bDay:=DaysInMonth(EncodeDate(aYear,aMonth,1)); if fieldByName('结费日期').AsInteger>bDay then result:=EncodeDate(aYear,aMonth,bDay) else if fieldByName('结费日期').AsInteger>0 then result:=EncodeDate(aYear,aMonth,fieldByName('结费日期').AsInteger) else result:=EncodeDate(aYear,aMonth,1); end; end else begin Result:=aStlDate; end; end else begin Result:=aStlDate; end; end; finally FreeAndNil(aQuery2); end; end; begin if (wwDBLookupCombo49.Text='') then begin ShowMessage('请选择统计方案!'); exit; end; if (bsSkinComboBox1.Text='实际开船日期') then sdate:='预抵日期' else sdate:='开船日期'; try frm_rp_total_query:=tfrm_rp_total_query.Create (self); rp_seae_query_num:=5; rp_seae_query_type:=5; rp_seae_query_limited:='0033'; rp_seae_query_str:='我的收款'; frm_rp_total_query.ShowModal; finally frm_rp_total_query.Free; end; if not p_accept_bill.Active then Exit; if p_accept_bill.IsEmpty then Exit; zdate:=date; { if zhangdate='' then zdate:=date else zdate:=StrToDateDef(zhangdate,date); } memtblrpt_total.DisableControls; memtblrpt_total.LoadFromDataSet(p_accept_bill,[mtcpostructure,mtcpoProperties,mtcpoFieldIndex]); // p_accept_bill.Close; { memtblrpt_total.open; p_accept_bill.First; while not p_accept_bill.eof do begin if (p_accept_bill.FieldByName('应收合计').AsFloat=0.00) or p_accept_bill.FieldByName('应收合计').IsNull then else begin memtblrpt_total.insert; for j:=0 to p_accept_bill.FieldCount-1 do begin if memtblrpt_total.FindField(p_accept_bill.Fields[j].FieldName)<>nil then begin memtblrpt_total.FieldByName(p_accept_bill.Fields[j].FieldName).Value:=p_accept_bill.Fields[j].Value; end; end; memtblrpt_total.post; end; p_accept_bill.next; end; } // memtblrpt_total.SortOn('开船日期',[]); memtblrpt_total.FieldByName('奖励合计').ReadOnly:=false; memtblrpt_total.FieldByName('奖励比例').ReadOnly:=false; memtblrpt_total.FieldByName('收款区间').ReadOnly:=false; memtblrpt_total.FieldByName('收回天数').ReadOnly:=false; { memtblrpt_total.FieldByName('是否超期').ReadOnly:=false; memtblrpt_total.FieldByName('应结日期').ReadOnly:=false; memtblrpt_total.FieldByName('客户合计').ReadOnly:=false; memtblrpt_total.FieldByName('月份合计').ReadOnly:=false; memtblrpt_total.FieldByName('客户账期').ReadOnly:=false; } memtblrpt_total.First; mem_client.Close; mem_client.EmptyTable; mem_client.Open; mem_clientsum.Close; mem_clientsum.EmptyTable; mem_clientsum.Open; mem_clientmonth.Close; mem_clientmonth.EmptyTable; mem_clientmonth.Open; if not ASSIGNED(frm_sys_progress) then frm_sys_progress:=tfrm_sys_progress.Create(application); frm_sys_progress.Show; frm_sys_progress.bsSkinGauge1.MaxValue:=memtblrpt_total.RecordCount; frm_sys_progress.bsSkinGauge1.MinValue:=0; frm_sys_progress.bsSkinGauge1.Value:=0; frm_sys_progress.Update; memtblrpt_total.First; while not memtblrpt_total.eof do begin frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; btdays:=DaysBetween(memtblrpt_total.FieldByName('结算完毕时间').AsDateTime,memtblrpt_total.FieldByName(sdate).AsDateTime); memtblrpt_total.Edit; memtblrpt_total.FieldByName('收回天数').AsInteger:=btdays; // if memtblrpt_total.FieldByName('结算完毕时间').AsDateTime>=memtblrpt_total.FieldByName(sdate).AsDateTime then // else btdays if (btdays>frm_data_share.t_sys_skjlset.FieldByName('项目开始天数1').AsInteger) and (btdays<=frm_data_share.t_sys_skjlset.FieldByName('项目结束天数1').AsInteger) then begin memtblrpt_total.FieldByName('收款区间').AsString:=frm_data_share.t_sys_skjlset.fieldbyname('项目名称1').AsString; memtblrpt_total.FieldByName('奖励比例').AsString:=frm_data_share.t_sys_skjlset.fieldbyname('项目奖励比例1').AsString+'%'; memtblrpt_total.FieldByName('奖励合计').AsFloat:=memtblrpt_total.FieldByName('结算金额').AsFloat*frm_data_share.t_sys_skjlset.fieldbyname('项目奖励比例1').AsFloat/100; end; if (btdays>frm_data_share.t_sys_skjlset.FieldByName('项目开始天数2').AsInteger) and (btdays<=frm_data_share.t_sys_skjlset.FieldByName('项目结束天数2').AsInteger) then begin memtblrpt_total.FieldByName('收款区间').AsString:=frm_data_share.t_sys_skjlset.fieldbyname('项目名称2').AsString; memtblrpt_total.FieldByName('奖励比例').AsString:=frm_data_share.t_sys_skjlset.fieldbyname('项目奖励比例2').AsString+'%'; memtblrpt_total.FieldByName('奖励合计').AsFloat:=memtblrpt_total.FieldByName('结算金额').AsFloat*frm_data_share.t_sys_skjlset.fieldbyname('项目奖励比例2').AsFloat/100; end; if (btdays>frm_data_share.t_sys_skjlset.FieldByName('项目开始天数3').AsInteger) and (btdays<=frm_data_share.t_sys_skjlset.FieldByName('项目结束天数3').AsInteger) then begin memtblrpt_total.FieldByName('收款区间').AsString:=frm_data_share.t_sys_skjlset.fieldbyname('项目名称3').AsString; memtblrpt_total.FieldByName('奖励比例').AsString:=frm_data_share.t_sys_skjlset.fieldbyname('项目奖励比例3').AsString+'%'; memtblrpt_total.FieldByName('奖励合计').AsFloat:=memtblrpt_total.FieldByName('结算金额').AsFloat*frm_data_share.t_sys_skjlset.fieldbyname('项目奖励比例3').AsFloat/100; end; if (btdays>frm_data_share.t_sys_skjlset.FieldByName('项目开始天数4').AsInteger) and (btdays<=frm_data_share.t_sys_skjlset.FieldByName('项目结束天数4').AsInteger) then begin memtblrpt_total.FieldByName('收款区间').AsString:=frm_data_share.t_sys_skjlset.fieldbyname('项目名称4').AsString; memtblrpt_total.FieldByName('奖励比例').AsString:=frm_data_share.t_sys_skjlset.fieldbyname('项目奖励比例4').AsString+'%'; memtblrpt_total.FieldByName('奖励合计').AsFloat:=memtblrpt_total.FieldByName('结算金额').AsFloat*frm_data_share.t_sys_skjlset.fieldbyname('项目奖励比例4').AsFloat/100; end; memtblrpt_total.Post; // ShowMessage(memtblrpt_total.fieldbyname('主提单号').AsString); { if memtblrpt_total.FieldByName('应结日期').AsDateTime<=zDate then begin memtblrpt_total.Edit; memtblrpt_total.FieldByName('是否超期').AsInteger:=1; memtblrpt_total.FieldByName('超期月数').AsInteger:=MonthsBetween(zdate,memtblrpt_total.FieldByName('应结日期').AsDateTime); memtblrpt_total.FieldByName('超期天数').AsInteger:=DaysBetween(ZDate,memtblrpt_total.FieldByName('应结日期').AsDatetime); memtblrpt_total.Post; end else begin if mem_client.Locate('客户名称;揽货人',VarArrayOf([memtblrpt_total.FieldByName('客户名称').asstring,memtblrpt_total.FieldByName('揽货人').AsStRING]),[]) then begin if mem_client.FieldByName('帐期额度').AsFloat<=0 then begin memtblrpt_total.Edit; memtblrpt_total.FieldByName('是否超期').AsInteger:=0; memtblrpt_total.FieldByName('超期月数').AsInteger:=0; memtblrpt_total.FieldByName('超期天数').AsInteger:=0; memtblrpt_total.Post; end else if mem_client.FieldByName('帐期额度').AsFloat=-1 then begin end else begin if (mem_client.FieldByName('欠费合计').AsFloat+memtblrpt_total.FieldByName('差额合计').AsFloat)>mem_client.FieldByName('帐期额度').AsFloat then begin memtblrpt_total.Edit; memtblrpt_total.FieldByName('是否超期').AsInteger:=1; memtblrpt_total.Post; end else begin mem_client.Edit; mem_client.FieldByName('欠费合计').AsFloat:=mem_client.FieldByName('欠费合计').AsFloat+memtblrpt_total.FieldByName('差额合计').AsFloat; mem_client.FieldByName('未收USD').AsFloat:=mem_client.FieldByName('未收USD').AsFloat+memtblrpt_total.FieldByName('未收USD').AsFloat; mem_client.FieldByName('未收RMB').AsFloat:=mem_client.FieldByName('未收RMB').AsFloat+memtblrpt_total.FieldByName('未收RMB').AsFloat; mem_client.FieldByName('未收合计').AsFloat:=mem_client.FieldByName('未收合计').AsFloat+memtblrpt_total.FieldByName('未收合计').AsFloat; mem_client.FieldByName('未付合计').AsFloat:=mem_client.FieldByName('未付合计').AsFloat+memtblrpt_total.FieldByName('未付合计').AsFloat; mem_client.Post; end; end; end else begin mem_client.Insert; mem_client.FieldByName('揽货人').AsString:=memtblrpt_total.FieldByName('揽货人').AsString; mem_client.FieldByName('客户名称').AsString:=memtblrpt_total.FieldByName('客户名称').AsString; mem_client.FieldByName('欠费合计').AsFloat:=memtblrpt_total.FieldByName('差额合计').AsFloat; mem_client.FieldByName('未收USD').AsFloat:=memtblrpt_total.FieldByName('未收USD').AsFloat; mem_client.FieldByName('未收RMB').AsFloat:=memtblrpt_total.FieldByName('未收RMB').AsFloat; mem_client.FieldByName('未收合计').AsFloat:=memtblrpt_total.FieldByName('未收合计').AsFloat; mem_client.FieldByName('未付合计').AsFloat:=memtblrpt_total.FieldByName('未付合计').AsFloat; num:=GetZhangQiNum(memtblrpt_total.FieldByName('揽货人').AsString,memtblrpt_total.FieldByName('客户名称').AsString,memtblrpt_total.FieldByName('开船日期').AsDateTime,zqstr); mem_client.FieldByName('帐期额度').AsFloat:=num; mem_client.FieldByName('客户账期').AsString:=zqstr; mem_client.Post; if mem_client.FieldByName('帐期额度').AsFloat<=0 then begin memtblrpt_total.Edit; memtblrpt_total.FieldByName('是否超期').AsInteger:=0; memtblrpt_total.FieldByName('超期月数').AsInteger:=0; memtblrpt_total.FieldByName('超期天数').AsInteger:=0; memtblrpt_total.Post; end else if mem_client.FieldByName('欠费合计').AsFloat>mem_client.FieldByName('帐期额度').AsFloat then begin memtblrpt_total.Edit; memtblrpt_total.FieldByName('是否超期').AsInteger:=1; memtblrpt_total.Post; end; end; end; if mem_clientmonth.Locate('客户名称;月份',VarArrayOf([memtblrpt_total.FieldByName('客户名称').asstring,memtblrpt_total.FieldByName('月份').AsStRING]),[]) then begin mem_clientmonth.Edit; mem_clientmonth.FieldByName('欠费合计').AsFloat:=mem_clientmonth.FieldByName('欠费合计').AsFloat+memtblrpt_total.FieldByName('差额合计').AsFloat; mem_clientmonth.FieldByName('未收USD').AsFloat:=mem_clientmonth.FieldByName('未收USD').AsFloat+memtblrpt_total.FieldByName('未收USD').AsFloat; mem_clientmonth.FieldByName('未收RMB').AsFloat:=mem_clientmonth.FieldByName('未收RMB').AsFloat+memtblrpt_total.FieldByName('未收RMB').AsFloat; mem_clientmonth.FieldByName('未收合计').AsFloat:=mem_clientmonth.FieldByName('未收合计').AsFloat+memtblrpt_total.FieldByName('未收合计').AsFloat; mem_clientmonth.FieldByName('未付合计').AsFloat:=mem_clientmonth.FieldByName('未付合计').AsFloat+memtblrpt_total.FieldByName('未付合计').AsFloat; mem_clientmonth.FieldByName('应收USD').AsFloat:=mem_clientmonth.FieldByName('应收USD').AsFloat+memtblrpt_total.FieldByName('应收USD').AsFloat; mem_clientmonth.FieldByName('已收USD').AsFloat:=mem_clientmonth.FieldByName('已收USD').AsFloat+memtblrpt_total.FieldByName('已收USD').AsFloat; mem_clientmonth.FieldByName('应收RMB').AsFloat:=mem_clientmonth.FieldByName('应收RMB').AsFloat+memtblrpt_total.FieldByName('应收RMB').AsFloat; mem_clientmonth.FieldByName('已收RMB').AsFloat:=mem_clientmonth.FieldByName('已收RMB').AsFloat+memtblrpt_total.FieldByName('已收RMB').AsFloat; mem_clientmonth.FieldByName('应收合计').AsFloat:=mem_clientmonth.FieldByName('应收合计').AsFloat+memtblrpt_total.FieldByName('应收合计').AsFloat; mem_clientmonth.FieldByName('已收合计').AsFloat:=mem_clientmonth.FieldByName('已收合计').AsFloat+memtblrpt_total.FieldByName('已收合计').AsFloat; mem_clientmonth.FieldByName('应付合计').AsFloat:=mem_clientmonth.FieldByName('应付合计').AsFloat+memtblrpt_total.FieldByName('应付合计').AsFloat; mem_clientmonth.FieldByName('已付合计').AsFloat:=mem_clientmonth.FieldByName('已付合计').AsFloat+memtblrpt_total.FieldByName('已付合计').AsFloat; mem_clientmonth.Post; end else begin mem_clientmonth.Insert; mem_clientmonth.FieldByName('揽货人').AsString:=memtblrpt_total.FieldByName('揽货人').AsString; mem_clientmonth.FieldByName('客户名称').AsString:=memtblrpt_total.FieldByName('客户名称').AsString; mem_clientmonth.FieldByName('月份').AsString:=memtblrpt_total.FieldByName('月份').AsString; mem_clientmonth.FieldByName('欠费合计').AsFloat:=memtblrpt_total.FieldByName('差额合计').AsFloat; mem_clientmonth.FieldByName('未收USD').AsFloat:=memtblrpt_total.FieldByName('未收USD').AsFloat; mem_clientmonth.FieldByName('未收RMB').AsFloat:=memtblrpt_total.FieldByName('未收RMB').AsFloat; mem_clientmonth.FieldByName('未收合计').AsFloat:=memtblrpt_total.FieldByName('未收合计').AsFloat; mem_clientmonth.FieldByName('未付合计').AsFloat:=memtblrpt_total.FieldByName('未付合计').AsFloat; mem_clientmonth.FieldByName('应收USD').AsFloat:=memtblrpt_total.FieldByName('应收USD').AsFloat; mem_clientmonth.FieldByName('已收USD').AsFloat:=memtblrpt_total.FieldByName('已收USD').AsFloat; mem_clientmonth.FieldByName('应收RMB').AsFloat:=memtblrpt_total.FieldByName('应收RMB').AsFloat; mem_clientmonth.FieldByName('已收RMB').AsFloat:=memtblrpt_total.FieldByName('已收RMB').AsFloat; mem_clientmonth.FieldByName('应收合计').AsFloat:=memtblrpt_total.FieldByName('应收合计').AsFloat; mem_clientmonth.FieldByName('已收合计').AsFloat:=memtblrpt_total.FieldByName('已收合计').AsFloat; mem_clientmonth.FieldByName('应付合计').AsFloat:=memtblrpt_total.FieldByName('应付合计').AsFloat; mem_clientmonth.FieldByName('已付合计').AsFloat:=memtblrpt_total.FieldByName('已付合计').AsFloat; mem_clientmonth.FieldByName('超期天数').AsString:=memtblrpt_total.FieldByName('超期天数').AsString; mem_clientmonth.FieldByName('应结日期').AsString:=memtblrpt_total.FieldByName('应结日期').AsString; mem_clientmonth.Post; end; if mem_clientsum.Locate('客户名称',VarArrayOf([memtblrpt_total.FieldByName('客户名称').asstring]),[]) then begin mem_clientsum.Edit; mem_clientsum.FieldByName('欠费合计').AsFloat:=mem_clientsum.FieldByName('欠费合计').AsFloat+memtblrpt_total.FieldByName('差额合计').AsFloat; mem_clientsum.FieldByName('未收USD').AsFloat:=mem_clientsum.FieldByName('未收USD').AsFloat+memtblrpt_total.FieldByName('未收USD').AsFloat; mem_clientsum.FieldByName('未收RMB').AsFloat:=mem_clientsum.FieldByName('未收RMB').AsFloat+memtblrpt_total.FieldByName('未收RMB').AsFloat; mem_clientsum.FieldByName('未收合计').AsFloat:=mem_clientsum.FieldByName('未收合计').AsFloat+memtblrpt_total.FieldByName('未收合计').AsFloat; mem_clientsum.FieldByName('未付合计').AsFloat:=mem_clientsum.FieldByName('未付合计').AsFloat+memtblrpt_total.FieldByName('未付合计').AsFloat; mem_clientsum.Post; end else begin // num:=GetZhangQiNum(memtblrpt_total.FieldByName('揽货人').AsString,memtblrpt_total.FieldByName('客户名称').AsString,memtblrpt_total.FieldByName('开船日期').AsDateTime,zqstr); mem_clientsum.Insert; mem_clientsum.FieldByName('揽货人').AsString:=memtblrpt_total.FieldByName('揽货人').AsString; mem_clientsum.FieldByName('客户名称').AsString:=memtblrpt_total.FieldByName('客户名称').AsString; mem_clientsum.FieldByName('客户账期').AsString:=GetZhangQi(memtblrpt_total.FieldByName('揽货人').AsString,memtblrpt_total.FieldByName('客户名称').asstring); mem_clientsum.FieldByName('欠费合计').AsFloat:=memtblrpt_total.FieldByName('差额合计').AsFloat; mem_clientsum.FieldByName('未收USD').AsFloat:=memtblrpt_total.FieldByName('未收USD').AsFloat; mem_clientsum.FieldByName('未收RMB').AsFloat:=memtblrpt_total.FieldByName('未收RMB').AsFloat; mem_clientsum.FieldByName('未收合计').AsFloat:=memtblrpt_total.FieldByName('未收合计').AsFloat; mem_clientsum.FieldByName('未付合计').AsFloat:=memtblrpt_total.FieldByName('未付合计').AsFloat; mem_clientsum.Post; end; } memtblrpt_total.Next; end; memtblrpt_total.EnableControls; freeAndNil(frm_sys_progress); GetNoFee; // mem_clientmonth.SortOn('客户名称;收款区间',[]); end; procedure Tfrm_rp_drstl_self.bsSkinButton1Click(Sender: TObject); begin with SaveDialog do begin DefaultExt :='xls'; Filter := '(*.xls)|*.xls'; if Execute then begin if tab1.Showing then dxDBGrid2.SaveToXLS(FileName,true) else if bsSkinTabSheet2.Showing then dxDBGrid4.SaveToXLS(FileName,true) else if tab3.Showing then dxDBGrid6.SaveToXLS(FileName,true) else if tab4.Showing then dxDBGrid7.SaveToXLS(FileName,true) else if bsSkinTabSheet5.Showing then dxDBGrid1.SaveToXLS(FileName,true) end; end; end; procedure Tfrm_rp_drstl_self.bsSkinButton9Click(Sender: TObject); begin sys_print('业务综合欠费',2,nil,nil,nil,nil,p_total_dept1,p_total_sales1,p_total_client1,memtblrpt_total1,p_total1,nil,nil); end; procedure Tfrm_rp_drstl_self.dxDBGrid5DblClick(Sender: TObject); begin fee_view(p_accept_bill.fieldbyname('编号').asstring); end; procedure Tfrm_rp_drstl_self.dxDBGrid6DblClick(Sender: TObject); begin // fee_view(p_accept_fee.fieldbyname('编号').asstring); end; procedure Tfrm_rp_drstl_self.dxDBGrid7DblClick(Sender: TObject); begin // fee_view(p_pay_bill.fieldbyname('编号').asstring); end; procedure Tfrm_rp_drstl_self.dxDBGrid8DblClick(Sender: TObject); begin // fee_view(p_pay_fee.fieldbyname('编号').asstring); end; procedure Tfrm_rp_drstl_self.bsSkinButton15Click(Sender: TObject); var str_bill:widestring; begin str_bill:=''; if trim(str_bill)='' then begin str_bill:='where '+open_data('0033','v_op_bscard.揽货人','v_op_bscard.操作员','v_op_bscard.客服员','no','no'); end else begin str_bill:=str_bill+' and '+open_data('0033','v_op_bscard.揽货人','v_op_bscard.操作员','v_op_bscard.客服员','no','no'); end; if str_bill='' then str_bill:='where t_ch_fee.金额<>t_ch_fee.结算金额 ' else str_bill:=str_bill+' and t_ch_fee.金额<>t_ch_fee.结算金额 '; do_1(str_bill); GetNoFee; end; procedure Tfrm_rp_drstl_self.GetNoFee; var aQuery,aQuery2:TAdoQuery; sumbal:Double; hvcg:Boolean; aYear,aMonth,aDay,bDay:word; sDate,S:string; begin aQuery:=CreateAdoQuery; aQuery2:=CreateAdoQuery; try if memtblrpt_total.IsEmpty then exit; // Creatememtbl; mem_total_sales.Close; mem_total_sales.EmptyTable; mem_total_sales.Open; mem_total_client.Close; mem_total_client.EmptyTable; mem_total_client.Open; mem_total_dept.Close; mem_total_dept.EmptyTable; mem_total_dept.Open; if not ASSIGNED(frm_sys_progress) then frm_sys_progress:=tfrm_sys_progress.Create(application); frm_sys_progress.Show; frm_sys_progress.bsSkinGauge1.MaxValue:=memtblrpt_total.RecordCount; frm_sys_progress.bsSkinGauge1.MinValue:=0; frm_sys_progress.bsSkinGauge1.Value:=0; frm_sys_progress.Update; memtblrpt_total.First; with memtblrpt_total do begin while not eof do begin frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; if mem_total_sales.Locate('销售部门;揽货人;收款区间',VarArrayOf([memtblrpt_total.FieldByName('销售部门').asstring,memtblrpt_total.FieldByName('揽货人').AsStRING,memtblrpt_total.FieldByName('收款区间').asstring]),[]) then begin mem_total_sales.Edit; if (memtblrpt_total.FieldByName('ISADD').AsInteger=1) then mem_total_sales.FieldByName('合计应收').AsFloat:=mem_total_sales.FieldByName('合计应收').AsFloat+memtblrpt_total.FieldByName('应收合计').AsFloat; mem_total_sales.FieldByName('实收合计').AsFloat:=mem_total_sales.FieldByName('实收合计').AsFloat+memtblrpt_total.FieldByName('结算金额').AsFloat; mem_total_sales.FieldByName('奖励合计').AsFloat:=mem_total_sales.FieldByName('奖励合计').AsFloat+memtblrpt_total.FieldByName('奖励合计').AsFloat; mem_total_sales.Post; end else begin mem_total_sales.Insert; mem_total_sales.FieldByName('揽货人').AsString:=memtblrpt_total.FieldByName('揽货人').AsString; mem_total_sales.FieldByName('销售部门').AsString:=memtblrpt_total.FieldByName('销售部门').AsString; mem_total_sales.FieldByName('收款区间').AsString:=memtblrpt_total.FieldByName('收款区间').AsString; if (memtblrpt_total.FieldByName('ISADD').AsInteger=1) then mem_total_sales.FieldByName('合计应收').AsFloat:=mem_total_sales.FieldByName('合计应收').AsFloat+memtblrpt_total.FieldByName('应收合计').AsFloat; mem_total_sales.FieldByName('实收合计').AsFloat:=mem_total_sales.FieldByName('实收合计').AsFloat+memtblrpt_total.FieldByName('结算金额').AsFloat; mem_total_sales.FieldByName('奖励合计').AsFloat:=mem_total_sales.FieldByName('奖励合计').AsFloat+memtblrpt_total.FieldByName('奖励合计').AsFloat; mem_total_sales.Post; end; if mem_total_dept.Locate('销售部门;收款区间',VarArrayOf([memtblrpt_total.FieldByName('销售部门').asstring,memtblrpt_total.FieldByName('收款区间').asstring]),[]) then begin mem_total_dept.Edit; if (memtblrpt_total.FieldByName('ISADD').AsInteger=1) then mem_total_dept.FieldByName('合计应收').AsFloat:=mem_total_dept.FieldByName('合计应收').AsFloat+memtblrpt_total.FieldByName('应收合计').AsFloat; mem_total_dept.FieldByName('实收合计').AsFloat:=mem_total_dept.FieldByName('实收合计').AsFloat+memtblrpt_total.FieldByName('结算金额').AsFloat; mem_total_dept.FieldByName('奖励合计').AsFloat:=mem_total_dept.FieldByName('奖励合计').AsFloat+memtblrpt_total.FieldByName('奖励合计').AsFloat; mem_total_dept.Post; end else begin mem_total_dept.Insert; mem_total_dept.FieldByName('销售部门').AsString:=memtblrpt_total.FieldByName('销售部门').AsString; mem_total_dept.FieldByName('收款区间').AsString:=memtblrpt_total.FieldByName('收款区间').AsString; if (memtblrpt_total.FieldByName('ISADD').AsInteger=1) then mem_total_dept.FieldByName('合计应收').AsFloat:=mem_total_dept.FieldByName('合计应收').AsFloat+memtblrpt_total.FieldByName('应收合计').AsFloat; mem_total_dept.FieldByName('实收合计').AsFloat:=mem_total_dept.FieldByName('实收合计').AsFloat+memtblrpt_total.FieldByName('结算金额').AsFloat; mem_total_dept.FieldByName('奖励合计').AsFloat:=mem_total_dept.FieldByName('奖励合计').AsFloat+memtblrpt_total.FieldByName('奖励合计').AsFloat; mem_total_dept.Post; end; if mem_total_client.Locate('客户名称;揽货人;收款区间',VarArrayOf([memtblrpt_total.FieldByName('委托单位').asstring,memtblrpt_total.FieldByName('揽货人').AsStRING,memtblrpt_total.FieldByName('收款区间').asstring]),[]) then begin mem_total_client.Edit; mem_total_client.FieldByName('合计应收').AsFloat:=mem_total_client.FieldByName('合计应收').AsFloat+memtblrpt_total.FieldByName('应收合计').AsFloat; if (memtblrpt_total.FieldByName('ISADD').AsInteger=1) then mem_total_client.FieldByName('实收合计').AsFloat:=mem_total_client.FieldByName('实收合计').AsFloat+memtblrpt_total.FieldByName('结算金额').AsFloat; mem_total_client.FieldByName('奖励合计').AsFloat:=mem_total_client.FieldByName('奖励合计').AsFloat+memtblrpt_total.FieldByName('奖励合计').AsFloat; mem_total_client.Post; end else begin mem_total_client.Insert; mem_total_client.FieldByName('揽货人').AsString:=memtblrpt_total.FieldByName('揽货人').AsString; mem_total_client.FieldByName('客户名称').AsString:=memtblrpt_total.FieldByName('委托单位').AsString; mem_total_client.FieldByName('委托单位全称').AsString:=memtblrpt_total.FieldByName('委托单位全称').AsString; if (memtblrpt_total.FieldByName('ISADD').AsInteger=1) then mem_total_client.FieldByName('合计应收').AsFloat:=mem_total_client.FieldByName('合计应收').AsFloat+memtblrpt_total.FieldByName('应收合计').AsFloat; mem_total_client.FieldByName('实收合计').AsFloat:=mem_total_client.FieldByName('实收合计').AsFloat+memtblrpt_total.FieldByName('结算金额').AsFloat; mem_total_client.FieldByName('奖励合计').AsFloat:=mem_total_client.FieldByName('奖励合计').AsFloat+memtblrpt_total.FieldByName('奖励合计').AsFloat; mem_total_client.Post; end; next; end; end; dxDBGrid2.FullExpand; dxDBGrid4.FullExpand; dxDBGrid6.FullExpand; dxDBGrid7.FullExpand; // memtblDetail.SortOn('揽货人;客户名称',[mtcoDescending]); finally freeAndNil(aQuery); freeAndNil(aQuery2); freeAndNil(frm_sys_progress); end; end; procedure Tfrm_rp_drstl_self.Creatememtbl; var aDate,aToDate:TDate; sDate,aYear,aMonth:String; aColumn:TdxDBTreeListColumn; aBand:TdxTreeListBand; i:integer; begin if (fmDate='') or (ToDate='') then exit; end; function Tfrm_rp_drstl_self.GetZhangQiNum(SaleID, Cust: String; aetd: TDateTime;out zqstr:string): Double; var aQuery:TAdoQuery; sub:string; begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select * from t_crm_client_sales where 状态=''审核'' and 开始日期<='''+FormatDateTime('YYYY-MM-DD',aetd)+''' and 结束日期>='''+FormatDateTime('YYYY-MM-DD',aetd)+''' and 客户简称='''+Cust+''' and 揽货人='''+SaleID+''''); Open; if not IsEmpty then begin if FieldByName('结费金额').IsNull or (FieldByName('结费金额').AsFloat<=0) then begin Result:=0; end else begin Result:=FieldByName('结费金额').AsFloat; end; if FieldByName('结费类型').AsString='现结买单' then begin zqstr:=zqstr+'当月结算;'; end else if FieldByName('结费类型').AsString='约定天数' then begin zqstr:=zqstr+'约定天数,['+fieldByName('结费期限').AsString+']天'; end else if FieldByName('结费类型').AsString='约定时间' then begin if StrToIntDef(FieldByName('类型模式').AsString,0)=0 then sub:='当月' else if StrToIntDef(FieldByName('类型模式').AsString,0)=1 then sub:='次1月' else if StrToIntDef(FieldByName('类型模式').AsString,0)=2 then sub:='次2月' else if StrToIntDef(FieldByName('类型模式').AsString,0)=3 then sub:='次3月' else sub:='次'+inttostr(StrToIntDef(FieldByName('类型模式').AsString,0))+'月'; if FieldByName('日期模式').AsString='固定' then zqstr:=sub+FieldByName('结费日期').AsString+'日' else zqstr:=sub; end else if FieldByName('结费类型').AsString='分阶段付费' then begin zqstr:=zqstr+'分阶段付费;'; end; end else begin Result:=-1; end; end; finally FreeAndNil(aQuery); end; end; function Tfrm_rp_drstl_self.isChaoQi(SaleID, Cust: String): Boolean; begin end; procedure Tfrm_rp_drstl_self.bsSkinCheckRadioBox3Click(Sender: TObject); begin GetNoFee; end; procedure Tfrm_rp_drstl_self.bsSkinCheckRadioBox2Click(Sender: TObject); begin GetNoFee; end; function Tfrm_rp_drstl_self.GetZhangQiStr(SaleID, Cust: String): String; var aQuery:TADOQuery; begin aQuery:=CreateAdoQuery; Result:=''; try with aQuery do begin Close;SQL.Clear; sql.Add(' select distinct SUBSTRING(CONVERT(char(15), dbo.v_op_bscard.开船日期, 111), 1, 7) from v_op_bscard left join t_ch_fee on t_ch_fee.编号=v_op_bscard.编号 '); sql.Add(sqlstr); sql.Add(' and t_ch_fee.客户名称='''+Cust+''' and v_op_bscard.揽货人='''+SaleID+''''); Open; if not IsEmpty then begin first; while not eof do begin if Result='' then result:=Fields[0].value else Result:=Result+','+Fields[0].value; Next; end; Result:=Result+'的欠费' end else result:=''; end; finally FreeAndNil(aQuery); end; end; procedure Tfrm_rp_drstl_self.bsSkinButton12Click(Sender: TObject); begin if bsSkinButton12.Caption='展开' then begin dxdbgrid2.FullExpand; dxdbgrid4.FullExpand; dxdbgrid6.FullExpand; dxdbgrid7.FullExpand; bsSkinButton12.Caption:='合并'; end else begin dxdbgrid2.FullCollapse; dxdbgrid4.FullCollapse; dxdbgrid6.FullCollapse; dxdbgrid7.FullCollapse; bsSkinButton12.Caption:='展开'; end; end; procedure Tfrm_rp_drstl_self.N10Click(Sender: TObject); begin update_grid_view_no(dxDBGrid7); exit; end; procedure Tfrm_rp_drstl_self.N14Click(Sender: TObject); begin update_grid_view_all(dxdbgrid7); exit; end; procedure Tfrm_rp_drstl_self.N12Click(Sender: TObject); begin update_grid(dxdbgrid7,220); exit; end; procedure Tfrm_rp_drstl_self.N16Click(Sender: TObject); begin grid_save_xls(dxdbgrid7); exit; end; procedure Tfrm_rp_drstl_self.bsSkinButton2Click(Sender: TObject); begin try frm_code_skjlset:=Tfrm_code_skjlset.Create (self); frm_code_skjlset.ShowModal; finally frm_code_skjlset.Free; end; end; procedure Tfrm_rp_drstl_self.dxDBGrid7Click(Sender: TObject); begin t_ch_fee_balance.Close; t_ch_fee_balance.Parameters.ParamByName('BSNO').Value:=memtblrpt_total.FIELDBYNAME('编号').AsString; t_ch_fee_balance.Open; end; procedure Tfrm_rp_drstl_self.MenuItem1Click(Sender: TObject); begin update_grid_view_no(dxDBGrid1); exit; end; procedure Tfrm_rp_drstl_self.MenuItem3Click(Sender: TObject); begin update_grid_view_all(dxdbgrid1); exit; end; procedure Tfrm_rp_drstl_self.MenuItem5Click(Sender: TObject); begin update_grid(dxdbgrid1,221); exit; end; procedure Tfrm_rp_drstl_self.MenuItem7Click(Sender: TObject); begin grid_save_xls(dxdbgrid1); exit; end; procedure Tfrm_rp_drstl_self.FormShow(Sender: TObject); begin loadreggrid(dxdbgrid1,false,caption+'1'); loadreggrid(dxdbgrid7,false,caption+'7'); dxdbgrid1.ShowSummaryFooter:=true; end; end.