//{$DEFINE NXIANCHENG } unit u_rp_no_seae_query; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, BusinessSkinForm, RxLookup, wwdbdatetimepicker, StdCtrls, Mask,comobj, wwdbedit, Wwdotdot, Wwdbcomb, bsSkinCtrls, ComCtrls,inifiles, DB, ADODB, wwdblook, bsSkinTabs, dxExEdtr, dxDBCtrl, dxDBGrid, dxTL, dxDBTLCl, dxGrClms, dxCntner; type Tfrm_rp_no_seae_query = class(TForm) bsBusinessSkinForm1: TbsBusinessSkinForm; bsSkinPageControl1: TbsSkinPageControl; bsSkinTabSheet1: TbsSkinTabSheet; bsSkinTabSheet2: TbsSkinTabSheet; bsSkinGroupBox1: TbsSkinGroupBox; Label10: TLabel; Label5: TLabel; Label8: TLabel; Label11: TLabel; Label9: TLabel; Label22: TLabel; Label23: TLabel; Label14: TLabel; Label16: TLabel; Label15: TLabel; Label1: TLabel; Label32: TLabel; Label39: TLabel; Label40: TLabel; Label6: TLabel; Label7: TLabel; Label12: TLabel; Label17: TLabel; Label125: TLabel; Label30: TLabel; Label19: TLabel; Label20: TLabel; Label21: TLabel; Label47: TLabel; Label24: TLabel; Label124: TLabel; Label26: TLabel; Label28: TLabel; Label29: TLabel; Label44: TLabel; Label31: TLabel; wwDBComboBox18: TwwDBComboBox; wwDBDateTimePicker1: TwwDBDateTimePicker; wwDBComboBox6: TwwDBComboBox; wwDBDateTimePicker2: TwwDBDateTimePicker; wwDBComboBox19: TwwDBComboBox; wwDBDateTimePicker3: TwwDBDateTimePicker; wwDBComboBox11: TwwDBComboBox; wwDBDateTimePicker4: TwwDBDateTimePicker; wwDBComboBox21: TwwDBComboBox; RxDBLookupCombo2: TRxDBLookupCombo; wwDBComboBox28: TwwDBComboBox; RxDBLookupCombo10: TRxDBLookupCombo; RxDBLookupCombo12: TRxDBLookupCombo; wwDBComboBox29: TwwDBComboBox; wwDBComboBox14: TwwDBComboBox; RxDBLookupCombo3: TRxDBLookupCombo; wwDBComboBox25: TwwDBComboBox; RxDBLookupCombo6: TRxDBLookupCombo; wwDBComboBox24: TwwDBComboBox; RxDBLookupCombo4: TRxDBLookupCombo; wwDBComboBox3: TwwDBComboBox; Edit1: TEdit; wwDBComboBox38: TwwDBComboBox; Edit9: TEdit; wwDBComboBox43: TwwDBComboBox; wwDBComboBox44: TwwDBComboBox; wwDBComboBox45: TwwDBComboBox; RxDBLookupCombo15: TRxDBLookupCombo; wwDBComboBox15: TwwDBComboBox; Edit2: TEdit; Edit3: TEdit; wwDBComboBox16: TwwDBComboBox; wwDBComboBox7: TwwDBComboBox; Edit4: TEdit; Edit5: TEdit; wwDBComboBox8: TwwDBComboBox; bsSkinPanel1: TbsSkinPanel; Label18: TLabel; wwDBComboBox36: TwwDBComboBox; wwDBLookupCombo49: TwwDBLookupCombo; wwDBComboBox35: TwwDBComboBox; Edit7: TEdit; wwDBComboBox17: TwwDBComboBox; wwDBComboBox9: TwwDBComboBox; wwDBComboBox10: TwwDBComboBox; wwDBComboBox12: TwwDBComboBox; wwDBComboBox20: TwwDBComboBox; wwDBComboBox22: TwwDBComboBox; wwDBComboBox52: TwwDBComboBox; wwDBComboBox23: TwwDBComboBox; wwDBComboBox26: TwwDBComboBox; RxDBLookupCombo7: TRxDBLookupCombo; wwDBLookupCombo52: TwwDBLookupCombo; wwDBComboBox27: TwwDBComboBox; wwDBComboBox32: TwwDBComboBox; RxDBLookupCombo8: TRxDBLookupCombo; wwDBComboBox34: TwwDBComboBox; wwDBComboBox37: TwwDBComboBox; wwDBComboBox39: TwwDBComboBox; RxDBLookupCombo11: TRxDBLookupCombo; wwDBComboBox40: TwwDBComboBox; RxDBLookupCombo13: TRxDBLookupCombo; Edit8: TEdit; wwDBComboBox46: TwwDBComboBox; bsSkinGroupBox4: TbsSkinGroupBox; Label13: TLabel; Label25: TLabel; Label37: TLabel; Label38: TLabel; Label43: TLabel; Label46: TLabel; Label3: TLabel; Label4: TLabel; Label27: TLabel; wwDBComboBox13: TwwDBComboBox; RxDBLookupCombo5: TRxDBLookupCombo; wwDBComboBox30: TwwDBComboBox; wwDBComboBox31: TwwDBComboBox; RxDBLookupCombo1: TRxDBLookupCombo; wwDBComboBox41: TwwDBComboBox; wwDBComboBox42: TwwDBComboBox; RxDBLookupCombo16: TRxDBLookupCombo; wwDBComboBox48: TwwDBComboBox; wwDBComboBox49: TwwDBComboBox; wwDBComboBox53: TwwDBComboBox; RxDBLookupCombo19: TRxDBLookupCombo; wwDBComboBox4: TwwDBComboBox; wwDBDateTimePicker5: TwwDBDateTimePicker; wwDBComboBox5: TwwDBComboBox; wwDBDateTimePicker6: TwwDBDateTimePicker; wwDBComboBox33: TwwDBComboBox; Edit6: TEdit; bsSkinGroupBox2: TbsSkinGroupBox; Label2: TLabel; wwDBComboBox1: TwwDBComboBox; wwDBComboBox2: TwwDBComboBox; bsSkinCheckRadioBox2: TbsSkinCheckRadioBox; bsSkinButton1: TbsSkinButton; bsSkinButton10: TbsSkinButton; bsSkinButton5: TbsSkinButton; bsSkinCheckRadioBox1: TbsSkinCheckRadioBox; bsSkinGroupBox3: TbsSkinGroupBox; bsSkinPanel2: TbsSkinPanel; bsSkinButton2: TbsSkinButton; bsSkinButton4: TbsSkinButton; bsSkinPanel3: TbsSkinPanel; Label33: TLabel; Label34: TLabel; Label35: TLabel; Label36: TLabel; RxDBLookupCombo14: TRxDBLookupCombo; wwDBComboBox47: TwwDBComboBox; wwDBComboBox50: TwwDBComboBox; query_bit: TwwDBComboBox; query_str_int: TEdit; query_date: TwwDBDateTimePicker; RxDBLookupList1: TRxDBLookupList; bsSkinGroupBox5: TbsSkinGroupBox; bsSkinPanel4: TbsSkinPanel; bsSkinButton3: TbsSkinButton; bsSkinButton7: TbsSkinButton; bsSkinButton6: TbsSkinButton; bsSkinButton9: TbsSkinButton; dxDBGrid1: TdxDBGrid; dxDBGrid1Column1: TdxDBGridPickColumn; dxDBGrid1Column2: TdxDBGridMaskColumn; dxDBGrid1Column3: TdxDBGridPickColumn; dxDBGrid1Column4: TdxDBGridMaskColumn; dxDBGrid2: TdxDBGrid; dxDBGrid2SQ_ID: TdxDBGridMaskColumn; t_sys_query: TADOQuery; t_sys_query_detail: TADOQuery; t_sys_queryfields: TADOQuery; t_sys_query_detail1: TDataSource; t_sys_query1: TDataSource; t_sys_queryfields1: TDataSource; Label41: TLabel; wwDBComboBox51: TwwDBComboBox; wwDBComboBox54: TwwDBComboBox; bsSkinCheckRadioBox3: TbsSkinCheckRadioBox; bsSkinCheckRadioBox4: TbsSkinCheckRadioBox; bsSkinCheckRadioBox5: TbsSkinCheckRadioBox; procedure bsSkinButton10Click(Sender: TObject); procedure bsSkinButton5Click(Sender: TObject); procedure FormShow(Sender: TObject); procedure bsSkinButton1Click(Sender: TObject); function get_no_str(table_str:string;date_query:string):widestring; procedure do_10(str_bill:widestring); procedure wwDBComboBox18KeyPress(Sender: TObject; var Key: Char); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure bsSkinButton2Click(Sender: TObject); procedure bsSkinButton4Click(Sender: TObject); procedure bsSkinButton6Click(Sender: TObject); procedure bsSkinButton9Click(Sender: TObject); procedure RxDBLookupCombo14Change(Sender: TObject); procedure t_sys_queryAfterInsert(DataSet: TDataSet); procedure t_sys_query_detailAfterScroll(DataSet: TDataSet); procedure t_sys_query_detailBeforePost(DataSet: TDataSet); private procedure loadFindIni ; procedure writeFindIni ; procedure noDrShen; { Private declarations } public { Public declarations } rp_seae_query_str:string; s_private:string; procedure InitmemtableinvData; end; var frm_rp_no_seae_query: Tfrm_rp_no_seae_query; no_seae_query_bs:integer; no_seae_query_limited:string; no_seae_query_fee:integer; no_seae_query_table:string; implementation uses my_sys_function, u_rp_no_seae_accept, u_rp_no_total, u_rp_in_seae, u_rp_no_seai, u_rp_in_seai, u_rp_no_aire, u_rp_no_airi, u_rp_in_aire, u_rp_in_airi, u_rp_in_total, u_data_share, u_main; {$R *.dfm} procedure Tfrm_rp_no_seae_query.do_10(str_bill:widestring); begin frm_rp_in_total.p_bill.close; frm_rp_in_total.p_bill.Parameters.ParamByName('SQLStr').value:= 'SELECT t_ch_fee.编号, t_ch_fee.客户名称,SUM(case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then t_ch_fee.金额 else 0 end) as 应开USD,' +'SUM(case t_ch_fee.币别 when '+''''+'USD'+''''+' then t_ch_fee.开票金额' +' else 0 end) as 已开USD,SUM(case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then t_ch_fee.金额-t_ch_fee.开票金额' +' else 0 end) as 未开USD,SUM(case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then 0 else t_ch_fee.金额*t_ch_fee.汇率' +' end) as 应开RMB,SUM(case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then 0 else t_ch_fee.开票金额*t_ch_fee.汇率' +' end) as 已开RMB,SUM(case t_ch_fee.币别 when '+''''+'USD'+''''+' then 0' +' else (t_ch_fee.金额-t_ch_fee.开票金额)*t_ch_fee.汇率' +' end) as 未开RMB,sum(t_ch_fee.金额*t_ch_fee.汇率) as 应开合计,' +' sum(t_ch_fee.开票金额*t_ch_fee.汇率) as 已开合计,' +' sum((t_ch_fee.金额-t_ch_fee.开票金额)*t_ch_fee.汇率) as 未开合计,' +'SUM(case t_ch_fee.币别 when '+''''+'USD'+''''+' then t_ch_fee.结算金额' +' else 0 end) as 已收USD,' +'SUM(case t_ch_fee.币别 when '+''''+'RMB'+''''+' then t_ch_fee.结算金额' +' else 0 end) as 已收RMB,' +' sum(t_ch_fee.开票金额*t_ch_fee.汇率) as 已收合计,' +' SUM(case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then (case when t_ch_fee.金额>0 then (case when t_ch_fee.开票金额>t_ch_fee.结算金额 then (t_ch_fee.开票金额-t_ch_fee.结算金额) else 0 end)' +' else (case when t_ch_fee.开票金额0 then (case when t_ch_fee.开票金额>t_ch_fee.结算金额 then (t_ch_fee.开票金额-t_ch_fee.结算金额) else 0 end)' +' else (case when t_ch_fee.开票金额0 then (case when t_ch_fee.开票金额>t_ch_fee.结算金额 then (t_ch_fee.开票金额-t_ch_fee.结算金额) else 0 end)' +' else (case when t_ch_fee.开票金额0 then (case when t_ch_fee.结算金额>t_ch_fee.开票金额 then (t_ch_fee.结算金额-t_ch_fee.开票金额) else 0 end)' +' else (case when t_ch_fee.结算金额0 then (case when t_ch_fee.结算金额>t_ch_fee.开票金额 then (t_ch_fee.结算金额-t_ch_fee.开票金额) else 0 end)' +' else (case when t_ch_fee.结算金额0 then (case when t_ch_fee.结算金额>t_ch_fee.开票金额 then (t_ch_fee.结算金额-t_ch_fee.开票金额) else 0 end)' +' else (case when t_ch_fee.结算金额0 then (case when t_ch_fee.开票金额>t_ch_fee.结算金额 then (t_ch_fee.开票金额-t_ch_fee.结算金额) else 0 end)' +' else (case when t_ch_fee.开票金额0 then (case when t_ch_fee.开票金额>t_ch_fee.结算金额 then (t_ch_fee.开票金额-t_ch_fee.结算金额) else 0 end)' +' else (case when t_ch_fee.开票金额0 then (case when t_ch_fee.开票金额>t_ch_fee.结算金额 then (t_ch_fee.开票金额-t_ch_fee.结算金额) else 0 end)' +' else (case when t_ch_fee.开票金额0 then (case when t_ch_fee.结算金额>t_ch_fee.开票金额 then (t_ch_fee.结算金额-t_ch_fee.开票金额) else 0 end)' +' else (case when t_ch_fee.结算金额0 then (case when t_ch_fee.结算金额>t_ch_fee.开票金额 then (t_ch_fee.结算金额-t_ch_fee.开票金额) else 0 end)' +' else (case when t_ch_fee.结算金额0 then (case when t_ch_fee.结算金额>t_ch_fee.开票金额 then (t_ch_fee.结算金额-t_ch_fee.开票金额) else 0 end)' +' else (case when t_ch_fee.结算金额0 then (case when t_ch_fee.开票金额>t_ch_fee.结算金额 then (t_ch_fee.开票金额-t_ch_fee.结算金额) else 0 end)' +' else (case when t_ch_fee.开票金额0 then (case when t_ch_fee.开票金额>t_ch_fee.结算金额 then (t_ch_fee.开票金额-t_ch_fee.结算金额) else 0 end)' +' else (case when t_ch_fee.开票金额0 then (case when t_ch_fee.开票金额>t_ch_fee.结算金额 then (t_ch_fee.开票金额-t_ch_fee.结算金额) else 0 end)' +' else (case when t_ch_fee.开票金额0 then (case when t_ch_fee.结算金额>t_ch_fee.开票金额 then (t_ch_fee.结算金额-t_ch_fee.开票金额) else 0 end)' +' else (case when t_ch_fee.结算金额0 then (case when t_ch_fee.结算金额>t_ch_fee.开票金额 then (t_ch_fee.结算金额-t_ch_fee.开票金额) else 0 end)' +' else (case when t_ch_fee.结算金额0 then (case when t_ch_fee.结算金额>t_ch_fee.开票金额 then (t_ch_fee.结算金额-t_ch_fee.开票金额) else 0 end)' +' else (case when t_ch_fee.结算金额0 then (case when t_ch_fee.开票金额>t_ch_fee.结算金额 then (t_ch_fee.开票金额-t_ch_fee.结算金额) else 0 end)' +' else (case when t_ch_fee.开票金额0 then (case when t_ch_fee.开票金额>t_ch_fee.结算金额 then (t_ch_fee.开票金额-t_ch_fee.结算金额) else 0 end)' +' else (case when t_ch_fee.开票金额0 then (case when t_ch_fee.开票金额>t_ch_fee.结算金额 then (t_ch_fee.开票金额-t_ch_fee.结算金额) else 0 end)' +' else (case when t_ch_fee.开票金额0 then (case when t_ch_fee.结算金额>t_ch_fee.开票金额 then (t_ch_fee.结算金额-t_ch_fee.开票金额) else 0 end)' +' else (case when t_ch_fee.结算金额0 then (case when t_ch_fee.结算金额>t_ch_fee.开票金额 then (t_ch_fee.结算金额-t_ch_fee.开票金额) else 0 end)' +' else (case when t_ch_fee.结算金额0 then (case when t_ch_fee.结算金额>t_ch_fee.开票金额 then (t_ch_fee.结算金额-t_ch_fee.开票金额) else 0 end)' +' else (case when t_ch_fee.结算金额'no'then begin if trim(str_bill)='' then begin str_bill:='where '+open_data(no_seae_query_limited,table_str+'揽货人',table_str+'操作员',table_str+'客服员','no','no'); end else begin str_bill:=str_bill+' and '+open_data(no_seae_query_limited,table_str+'揽货人',table_str+'操作员',table_str+'客服员','no','no'); end; end; str_bill:=query_tiaojian(1,str_bill,table_str+date_query,wwDBComboBox18.text,wwDBDateTimePicker1.text); str_bill:=query_tiaojian(1,str_bill,table_str+date_query,wwDBComboBox6.text,wwDBDateTimePicker2.text); str_bill:=query_tiaojian(1,str_bill,table_str+'委托单位',wwDBComboBox21.text,RxDBLookupCombo2.DisplayValues[1]); str_bill:=query_tiaojian(1,str_bill,table_str+'收货人',wwDBComboBox26.text,RxDBLookupCombo7.DisplayValues[1]); str_bill:=query_tiaojian(1,str_bill,table_str+'代理',wwDBComboBox32.text,RxDBLookupCombo8.DisplayValues[1]); str_bill:=query_tiaojian(1,str_bill,'t_ch_fee.客户名称',wwDBComboBox13.text,RxDBLookupCombo5.DisplayValues[1]); str_bill:=query_tiaojian(1,str_bill,'t_ch_fee.币别',wwDBComboBox41.text,RxDBLookupCombo1.DisplayValues[0]); str_bill:=query_tiaojian(1,str_bill,'t_ch_fee.费用名称',wwDBComboBox42.text,RxDBLookupCombo16.DisplayValues[1]); str_bill:=query_tiaojian(1,str_bill,'t_ch_fee.类型',wwDBComboBox30.text,wwDBComboBox31.text); str_bill:=query_tiaojian(3,str_bill,'t_ch_fee.是否垫付',wwDBComboBox48.text,wwDBComboBox49.text); str_bill:=query_tiaojian(2,str_bill,'t_ch_fee.财务税率',wwDBComboBox33.text,Edit6.text); str_bill:=query_tiaojian(1,str_bill,'t_ch_fee.第三方',wwDBComboBox53.text,RxDBLookupCombo19.DisplayValues[1]); str_bill:=query_tiaojian(1,str_bill,'t_ch_fee.审核日期',wwDBComboBox4.text,wwDBDateTimePicker5.text); str_bill:=query_tiaojian(1,str_bill,'t_ch_fee.审核日期',wwDBComboBox5.text,wwDBDateTimePicker6.text); if wwDBComboBox2.Text<>'' then begin if wwDBComboBox1.Text='等于' then begin if str_bill='' then begin str_bill:=' where t_crm_client.'+wwDBComboBox2.Text+'=1 ' end else begin str_bill:=str_bill+' and t_crm_client.'+wwDBComboBox2.Text+'=1 ' end; end else if wwDBComboBox1.Text='不等于' then begin if str_bill='' then begin str_bill:=' where (t_crm_client.'+wwDBComboBox2.Text+'<>1 or (t_crm_client.'+wwDBComboBox2.Text+' is null))'; end else begin str_bill:=str_bill+' and (t_crm_client.'+wwDBComboBox2.Text+'<>1 or (t_crm_client.'+wwDBComboBox2.Text+' is null))'; end; end; end; case no_seae_query_fee of 1: begin 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.结算金额'; end; 2: begin if str_bill='' then str_bill:='where t_ch_fee.结算金额<>0' else str_bill:=str_bill+' and t_ch_fee.结算金额<>0'; end; 4: begin if str_bill='' then str_bill:='where t_ch_fee.金额<>t_ch_fee.结算金额 and 类型=''收'' ' else str_bill:=str_bill+' and t_ch_fee.金额<>t_ch_fee.结算金额 and 类型=''收'' '; end; end; result:=str_bill; end; procedure Tfrm_rp_no_seae_query.bsSkinButton10Click(Sender: TObject); begin wwDBDateTimePicker1.Clear; wwDBDateTimePicker2.Clear; wwDBDateTimePicker3.Clear; wwDBDateTimePicker4.Clear; wwDBDateTimePicker5.clear; wwDBDateTimePicker6.clear; RxDBLookupCombo4.ClearValue; RxDBLookupCombo3.ClearValue; RxDBLookupCombo6.ClearValue; RxDBLookupCombo2.ClearValue; RxDBLookupCombo7.ClearValue; RxDBLookupCombo10.ClearValue; RxDBLookupCombo12.ClearValue; RxDBLookupCombo15.ClearValue; RxDBLookupCombo8.ClearValue; RxDBLookupCombo11.ClearValue; RxDBLookupCombo13.ClearValue; RxDBLookupCombo5.ClearValue; RxDBLookupCombo1.ClearValue; RxDBLookupCombo16.ClearValue; RxDBLookupCombo19.ClearValue; Edit1.text:=''; Edit9.text:=''; wwDBComboBox44.text:=''; wwDBComboBox31.text:=''; wwDBComboBox2.text:=''; wwDBComboBox49.text:=''; wwDBComboBox9.text:=''; wwDBComboBox12.text:=''; wwDBComboBox20.text:=''; wwDBComboBox39.text:=''; wwDBComboBox40.text:=''; Edit2.text:=''; Edit3.text:=''; Edit4.text:=''; Edit5.text:=''; Edit6.text:=''; Edit8.text:=''; wwDBLookupCombo49.text:=''; Edit7.text:=''; wwDBComboBox53.text:=''; wwDBComboBox54.text:=''; wwDBLookupCombo52.text:=''; end; procedure Tfrm_rp_no_seae_query.bsSkinButton5Click(Sender: TObject); begin close; end; procedure Tfrm_rp_no_seae_query.FormShow(Sender: TObject); begin loadFindIni; frm_data_share.t_crm_client_all.requery; frm_data_share.t_sys_employee.requery; frm_data_share.t_sys_department.requery; t_sys_queryfields.open; t_sys_query.Parameters.ParamByName('查询类型').Value:=rp_seae_query_str; t_sys_query.Parameters.ParamByName('录入人').Value:=employee; t_sys_query.open; t_sys_query_detail.open; end; procedure Tfrm_rp_no_seae_query.bsSkinButton1Click(Sender: TObject); var str_bill,str_seae,str_seai,str_aire,str_airi,str_airtruck,str_railway ,sqltext,sqlInv,constr ,tempstr,clientstr,tempstr2,str_feesum:widestring; sl:tstrings; DBQueryThread2,DBQueryThread3,DBQueryThread4,DBQueryThread5,DBQueryThread6,DBQueryThread7:TDBQueryThread; DBQueryThread1:TDBADOQueryThread; W: DWord; H: THandle; str_zr,str_seaezr:WideString; begin if bsSkinCheckRadioBox3.Checked then str_zr:=''; if bsSkinCheckRadioBox4.Checked then str_zr:=' and v_op_bscard_all.是否直入=''是'' ' ; if bsSkinCheckRadioBox5.Checked then str_zr:=' and v_op_bscard_all.是否直入=''否'' ' ; if bsSkinCheckRadioBox3.Checked then str_seaezr:=''; if bsSkinCheckRadioBox4.Checked then str_seaezr:=' and t_op_seae.是否直入=''是'' ' ; if bsSkinCheckRadioBox5.Checked then str_seaezr:=' and t_op_seae.是否直入=''否'' ' ; writeFindIni; tempstr2:=''; s_private:=''; str_feesum:=''; str_feesum:= 'SUM(' +'CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应收USD' +',SUM(' +'CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 已收USD' +',SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +') as 未收USD' //收RMB +',SUM(' +'CASE t_ch_fee.类型' +' WHEN '+''''+'收'+'''' +' THEN (' +'case t_ch_fee.币别' +' when '+''''+'RMB'+'''' +' then t_ch_fee.金额*t_ch_fee.汇率' +' else 0 end)' +'ELSE 0 ' +'END' +') as 应收RMB' +',SUM(' +'CASE t_ch_fee.类型 ' +' WHEN '+''''+'收'+'''' +' THEN (' +' case t_ch_fee.币别 ' +' when '+''''+'RMB'+'''' +' then t_ch_fee.结算金额*t_ch_fee.汇率 else 0 end' +') ELSE 0 ' +'END' +') as 已收RMB' +',SUM(' +'CASE t_ch_fee.类型 ' +' WHEN '+''''+'收'+'''' +' THEN (' +' case t_ch_fee.币别 when '+''''+'RMB'+'''' +' then (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 else 0 end) ' +' ELSE 0 END' +' ) as 未收RMB' // 其它应收 +',SUM(' +'CASE t_ch_fee.类型' +' WHEN '+''''+'收'+'''' +' THEN (' +'case t_ch_fee.币别' +' when '+''''+'RMB'+''''+' then 0' +' when '+''''+'USD'+''''+' then 0' +' else t_ch_fee.金额 ' +' end)' +'ELSE 0 ' +'END' +') as 应收其它' +',SUM(' +'CASE t_ch_fee.类型 ' +' WHEN '+''''+'收'+'''' +' THEN (' +'case t_ch_fee.币别' +' when '+''''+'RMB'+''''+' then 0' +' when '+''''+'USD'+''''+' then 0' +' else t_ch_fee.结算金额 ' +' end)' +' ELSE 0 ' +'END' +') as 已收其它' +',SUM(' +'CASE t_ch_fee.类型 ' +' WHEN '+''''+'收'+'''' +' THEN (' +'case t_ch_fee.币别' +' when '+''''+'RMB'+''''+' then 0' +' when '+''''+'USD'+''''+' then 0' +' else t_ch_fee.金额-t_ch_fee.结算金额 ' +' end)' +' ELSE 0 END' +' ) as 未收其它' // 其它应付 +',SUM(' +'CASE t_ch_fee.类型' +' WHEN '+''''+'付'+'''' +' THEN (' +'case t_ch_fee.币别' +' when '+''''+'RMB'+''''+' then 0' +' when '+''''+'USD'+''''+' then 0' +' else t_ch_fee.金额 ' +' end)' +'ELSE 0 ' +'END' +') as 应付其它' +',SUM(' +'CASE t_ch_fee.类型 ' +' WHEN '+''''+'付'+'''' +' THEN (' +'case t_ch_fee.币别' +' when '+''''+'RMB'+''''+' then 0' +' when '+''''+'USD'+''''+' then 0' +' else t_ch_fee.结算金额 ' +' end)' +' ELSE 0 ' +'END' +') as 已付其它' +',SUM(' +'CASE t_ch_fee.类型 ' +' WHEN '+''''+'付'+'''' +' THEN (' +'case t_ch_fee.币别' +' when '+''''+'RMB'+''''+' then 0' +' when '+''''+'USD'+''''+' then 0' +' else t_ch_fee.金额-t_ch_fee.结算金额 ' +' end)' +' ELSE 0 END' +' ) as 未付其它' //收合计 +',SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已收合计' +',SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未收合计' //付 USD +',SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应付USD' +',SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 已付USD' +',SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 未付USD' //付RMB +',SUM(' +'CASE t_ch_fee.类型' +' WHEN '+''''+'付'+'''' +' THEN (' +'case t_ch_fee.币别' +' when '+''''+'RMB'+'''' +' then t_ch_fee.金额*t_ch_fee.汇率' +' else 0 end)' +'ELSE 0 ' +'END' +') as 应付RMB' +',SUM(' +'CASE t_ch_fee.类型 ' +' WHEN '+''''+'付'+'''' +' THEN (' +' case t_ch_fee.币别 ' +' when '+''''+'RMB'+'''' +' then t_ch_fee.结算金额*t_ch_fee.汇率 else 0 end' +') ELSE 0 ' +'END' +') as 已付RMB' +',SUM(' +'CASE t_ch_fee.类型 ' +' WHEN '+''''+'付'+'''' +' THEN (' +' case t_ch_fee.币别 when '+''''+'RMB'+'''' +' then (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 else 0 end) ' +' ELSE 0 END' +' ) as 未付RMB' { //付 RMB +',SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应付RMB' +',SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB' +',SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未付RMB' } //付合计 +',SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已付合计' +',SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未付合计' //差额 USD +',SUM(' +' CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +') as 差额USD' //差额 RMB +',SUM(' +'CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END' +' ) as 差额RMB' //差额 合计 +',SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*汇率 ELSE 0 END) as 差额合计'; // if (strtobool(get_parameters_value(64,'false'))=true) and (if_open('206')=false and if_open('207')=false and if_open('208')=false and if_open('209')=false and if_open('351')=false ) then begin s_private:=' and t_ch_fee.机密<>1 '; end; if no_seae_query_bs=5 then begin if bsSkinTabSheet2.Showing then begin str_seae:=frm_rp_no_seae_query.get_no_str('t_op_seae.','开船日期'); str_seai:=frm_rp_no_seae_query.get_no_str('t_op_seai.','进口日期'); str_aire:=frm_rp_no_seae_query.get_no_str('t_op_aire.','一程开航日期'); str_airi:=frm_rp_no_seae_query.get_no_str('t_op_airi.','进口日期'); str_airtruck:=frm_rp_no_seae_query.get_no_str('t_op_airtruck.','发车日期'); str_railway:=frm_rp_no_seae_query.get_no_str('t_op_railway.','发车日期'); str_bill:=frm_rp_no_seae_query.get_no_str('v_op_bscard_all.','开船日期'); if (wwDBComboBox22.text<>'') and (wwDBComboBox20.text<>'') then begin if wwDBComboBox22.text='等于' then begin if wwDBComboBox20.text='海运出口' then begin str_seai:=str_seai+' and 1=2 '; str_aire:=str_aire+' and 1=2 '; str_airi:=str_airi+' and 1=2 '; str_airtruck:=str_airtruck+' and 1=2 '; str_railway:=str_railway+' and 1=2 '; end; if wwDBComboBox20.text='海运进口' then begin str_seae:=str_seae+' and 1=2 '; str_aire:=str_aire+' and 1=2 '; str_airi:=str_airi+' and 1=2 '; str_airtruck:=str_airtruck+' and 1=2 '; str_railway:=str_railway+' and 1=2 '; end; if wwDBComboBox20.text='空运出口' then begin str_seai:=str_seai+' and 1=2 '; str_seae:=str_seae+' and 1=2 '; str_airi:=str_airi+' and 1=2 '; str_airtruck:=str_airtruck+' and 1=2 '; str_railway:=str_railway+' and 1=2 '; end; if wwDBComboBox20.text='空运进口' then begin str_seai:=str_seai+' and 1=2 '; str_aire:=str_aire+' and 1=2 '; str_seae:=str_seae+' and 1=2 '; str_airtruck:=str_airtruck+' and 1=2 '; str_railway:=str_railway+' and 1=2 '; end; if wwDBComboBox20.text='监管车' then begin str_seai:=str_seai+' and 1=2 '; str_aire:=str_aire+' and 1=2 '; str_airi:=str_airi+' and 1=2 '; str_seae:=str_seae+' and 1=2 '; str_railway:=str_railway+' and 1=2 '; end; if wwDBComboBox20.text='铁路运输' then begin str_seai:=str_seai+' and 1=2 '; str_aire:=str_aire+' and 1=2 '; str_airi:=str_airi+' and 1=2 '; str_seae:=str_seae+' and 1=2 '; str_airtruck:=str_airtruck+' and 1=2 '; end; end; if wwDBComboBox22.text='不等于' then begin if wwDBComboBox20.text='海运出口' then begin str_seae:=str_seae+' and 1=2 '; end; if wwDBComboBox20.text='海运进口' then begin str_seai:=str_seai+' and 1=2 '; end; if wwDBComboBox20.text='空运出口' then begin str_aire:=str_aire+' and 1=2 '; end; if wwDBComboBox20.text='空运进口' then begin str_airi:=str_airi+' and 1=2 '; end; if wwDBComboBox20.text='监管车' then begin str_airtruck:=str_airtruck+' and 1=2 '; end; if wwDBComboBox20.text='铁路运输' then begin str_railway:=str_railway+' and 1=2 '; end; end; end; if wwDBComboBox23.ItemIndex=1 then begin str_seai:=str_seai+' and 1=2 '; str_aire:=str_aire+' and 1=2 '; str_airi:=str_airi+' and 1=2 '; str_airtruck:=str_airtruck+' and 1=2 '; str_railway:=str_railway+' and 1=2 '; end; if bsSkinCheckRadioBox4.Checked then str_seae:=query_tiaojian(1,str_seae,'t_op_seae.是否直入','等于','是'); if bsSkinCheckRadioBox5.Checked then str_seae:=query_tiaojian(1,str_seae,'t_op_seae.是否直入','等于','否'); str_seae:=query_tiaojian(1,str_seae,'t_op_seae.业务类型',wwDBComboBox43.text,wwDBComboBox44.text); str_seai:=query_tiaojian(1,str_seai,'t_op_seai.业务类型',wwDBComboBox43.text,wwDBComboBox44.text); str_seae:=query_tiaojian(1,str_seae,'t_op_seae.船名',wwDBComboBox36.text,wwDBLookupCombo49.text); str_seae:=query_tiaojian(1,str_seae,'t_op_seae.航次',wwDBComboBox35.text,Edit7.text); str_seae:=query_tiaojian(3,str_seae,'t_op_seae.是否退舱',wwDBComboBox52.text,wwDBComboBox23.text); str_seae:=query_tiaojian(1,str_seae,'t_op_seae.业务来源',wwDBComboBox39.text,RxDBLookupCombo11.DisplayValue); str_seae:=query_tiaojian(1,str_seae,'t_op_seae.来源明细',wwDBComboBox40.text,RxDBLookupCombo13.DisplayValue); str_seae:=query_tiaojian(1,str_seae,'t_op_seae.箱号封号',wwDBComboBox46.text,Edit8.text); str_seae:=query_tiaojian(3,str_seae,'t_op_seae.香港付费',wwDBComboBox34.text,wwDBComboBox37.text); str_seai:=query_tiaojian(1,str_seai,'t_op_seai.船名',wwDBComboBox36.text,wwDBLookupCombo49.text); str_seai:=query_tiaojian(1,str_seai,'t_op_seai.航次',wwDBComboBox35.text,Edit7.text); str_seai:=query_tiaojian(1,str_seai,'t_op_seai.业务来源',wwDBComboBox39.text,RxDBLookupCombo11.DisplayValue); str_seai:=query_tiaojian(1,str_seai,'t_op_seai.来源明细',wwDBComboBox40.text,RxDBLookupCombo13.DisplayValue); str_aire:=query_tiaojian(1,str_aire,'t_op_aire.一程航班',wwDBComboBox35.text,Edit7.text); str_airi:=query_tiaojian(1,str_airi,'t_op_airi.航班号',wwDBComboBox35.text,Edit7.text); str_aire:=query_tiaojian(1,str_aire,'t_op_aire.业务来源',wwDBComboBox39.text,RxDBLookupCombo11.DisplayValue); str_aire:=query_tiaojian(1,str_aire,'t_op_aire.来源明细',wwDBComboBox40.text,RxDBLookupCombo13.DisplayValue); str_airi:=query_tiaojian(1,str_airi,'t_op_airi.业务来源',wwDBComboBox39.text,RxDBLookupCombo11.DisplayValue); str_airi:=query_tiaojian(1,str_airi,'t_op_airi.来源明细',wwDBComboBox40.text,RxDBLookupCombo13.DisplayValue); str_airtruck:=query_tiaojian(1,str_airtruck,'t_op_airtruck.SA车号',wwDBComboBox35.text,Edit7.text); str_railway:=query_tiaojian(1,str_railway,'t_op_railway.车号',wwDBComboBox35.text,Edit7.text); str_railway:=query_tiaojian(1,str_railway,'t_op_railway.是否还箱',wwDBComboBox51.text,wwDBComboBox54.text); str_bill:=query_tiaojian(1,str_bill,'v_op_bscard_all.船名',wwDBComboBox36.text,wwDBLookupCombo49.text); str_bill:=query_tiaojian(1,str_bill,'v_op_bscard_all.航次',wwDBComboBox35.text,Edit7.text); str_bill:=query_tiaojian(1,str_bill,'v_op_bscard_all.业务类型',wwDBComboBox22.text,wwDBComboBox20.text); str_bill:=query_tiaojian(3,str_bill,'v_op_bscard_all.是否退舱',wwDBComboBox52.text,wwDBComboBox23.text); str_bill:=query_tiaojian(1,str_bill,'v_op_bscard_all.是否还箱',wwDBComboBox51.text,wwDBComboBox54.text); str_bill:=query_tiaojian(3,str_bill,'v_op_bscard_all.香港付费',wwDBComboBox34.text,wwDBComboBox37.text); str_bill:=query_tiaojian(1,str_bill,'v_op_bscard_all.卸货港',wwDBComboBox27.text,wwDBLookupCombo52.text); str_bill:=query_tiaojian(1,str_bill,'v_op_bscard_all.业务来源',wwDBComboBox39.text,RxDBLookupCombo11.DisplayValue); str_bill:=query_tiaojian(1,str_bill,'v_op_bscard_all.来源明细',wwDBComboBox40.text,RxDBLookupCombo13.DisplayValue); str_bill:=query_tiaojian(1,str_bill,'v_op_bscard_all.箱号封号',wwDBComboBox46.text,Edit8.text); str_aire:=query_tiaojian(1,str_aire,'t_op_aire.业务类型',wwDBComboBox43.text,wwDBComboBox44.text); str_airi:=query_tiaojian(1,str_airi,'t_op_airi.业务类型',wwDBComboBox43.text,wwDBComboBox44.text); str_airtruck:=query_tiaojian(1,str_airtruck,'t_op_airtruck.业务类型',wwDBComboBox43.text,wwDBComboBox44.text); str_bill:=query_tiaojian(1,str_bill,'v_op_bscard_all.业务种类',wwDBComboBox43.text,wwDBComboBox44.text); bsSkinPanel1.Visible:=true; if no_seae_query_fee=4 then begin tempstr:=' and isnull(DATEDIFF([day],v_op_bscard_all.开船日期, GETDATE())-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)' +' else (case t_crm_client_sales.结费类型 when ''约定时间'' then' +' ( DATEDIFF([day],v_op_bscard_all.开船日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期,v_op_bscard_all.开船日期)))) else 0 end) end),DATEDIFF([day],v_op_bscard_all.开船日期, GETDATE()))>0'; str_seae:=str_seae+' and isnull(DATEDIFF([day],t_op_seae.开船日期, GETDATE())-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)' +' else (case t_crm_client_sales.结费类型 when ''约定时间'' then' +' ( DATEDIFF([day],t_op_seae.开船日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期,t_op_seae.开船日期)))) else 0 end) end),DATEDIFF([day],t_op_seae.开船日期, GETDATE()))>0'; str_seai:=str_seai+' and isnull(DATEDIFF([day],t_op_seai.进口日期, GETDATE())-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)' +' else (case t_crm_client_sales.结费类型 when ''约定时间'' then' +' ( DATEDIFF([day],t_op_seai.进口日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期,t_op_seai.进口日期)))) else 0 end) end),DATEDIFF([day],t_op_seai.进口日期, GETDATE()))>0'; str_aire:=str_aire+' and isnull(DATEDIFF([day],t_op_aire.一程开航日期, GETDATE())-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)' +' else (case t_crm_client_sales.结费类型 when ''约定时间'' then' +' ( DATEDIFF([day],t_op_aire.一程开航日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期,t_op_aire.一程开航日期)))) else 0 end) end),DATEDIFF([day],t_op_aire.一程开航日期, GETDATE()))>0'; str_airi:=str_airi+' and isnull(DATEDIFF([day],t_op_airi.进口日期, GETDATE())-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)' +' else (case t_crm_client_sales.结费类型 when ''约定时间'' then' +' ( DATEDIFF([day],t_op_airi.进口日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期,t_op_airi.进口日期)))) else 0 end) end),DATEDIFF([day],t_op_airi.进口日期, GETDATE()))>0'; str_airtruck:=str_airtruck+' and isnull(DATEDIFF([day],t_op_airtruck.发车日期, GETDATE())-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)' +' else (case t_crm_client_sales.结费类型 when ''约定时间'' then' +' ( DATEDIFF([day],t_op_airtruck.发车日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期,t_op_airtruck.发车日期)))) else 0 end) end),DATEDIFF([day],t_op_airtruck.发车日期, GETDATE()))>0'; clientstr:=' left join t_crm_client on t_ch_fee.客户名称=t_crm_client.客户简称 '; end else begin //tempstr:=' and 1=1 '; end; if no_seae_query_fee=5 then begin tempstr:=' and v_op_bscard_all.编号 in (select 编号 from t_op_gain where 合计已付<>0 and ((合计应收=0) or (合计应收<>合计已收))) '; str_seae:=str_seae+' and t_op_seae.编号 in (select 编号 from t_op_gain where 合计已付<>0 and ((合计应收=0) or (合计应收<>合计已收)))'; str_seai:=str_seai+' and t_op_seai.编号 in (select 编号 from t_op_gain where 合计已付<>0 and ((合计应收=0) or (合计应收<>合计已收)))'; str_aire:=str_aire+' and t_op_aire.编号 in (select 编号 from t_op_gain where 合计已付<>0 and ((合计应收=0) or (合计应收<>合计已收)))'; str_airi:=str_airi+' and t_op_airi.编号 in (select 编号 from t_op_gain where 合计已付<>0 and ((合计应收=0) or (合计应收<>合计已收)))'; str_airtruck:=str_airtruck+' and t_op_airtruck.编号 in (select 编号 from t_op_gain where 合计已付<>0 and ((合计应收=0) or (合计应收<>合计已收)))'; end; if no_seae_query_fee=6 then begin tempstr:=' and v_op_bscard_all.编号 in (select 编号 from t_op_gain where 合计已收<>0 and ((合计应付=0) or (合计应付<>合计已付))) '; str_seae:=str_seae+' and t_op_seae.编号 in (select 编号 from t_op_gain where 合计已收<>0 and ((合计应付=0) or (合计应付<>合计已付)))'; str_seai:=str_seai+' and t_op_seai.编号 in (select 编号 from t_op_gain where 合计已收<>0 and ((合计应付=0) or (合计应付<>合计已付)))'; str_aire:=str_aire+' and t_op_aire.编号 in (select 编号 from t_op_gain where 合计已收<>0 and ((合计应付=0) or (合计应付<>合计已付)))'; str_airi:=str_airi+' and t_op_airi.编号 in (select 编号 from t_op_gain where 合计已收<>0 and ((合计应付=0) or (合计应付<>合计已付)))'; str_airtruck:=str_airtruck+' and t_op_airtruck.编号 in (select 编号 from t_op_gain where 合计已收<>0 and ((合计应付=0) or (合计应付<>合计已付)))'; end; if wwDBComboBox2.Text<>'' then begin clientstr:=' left join t_crm_client on t_ch_fee.客户名称=t_crm_client.客户简称 '; end else begin clientstr:=' '; end; end else begin if query_wanneng_error(t_sys_query_detail)then begin showmessage('‘或’的条件必须在2个以上!!'); exit; end; str_bill:=query_wanneng(t_sys_query_detail); end; if strtobool(get_parameters_value(191,'false')) then tempstr2:=' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 and t_crm_client_sales.揽货人=v_op_bscard_all.揽货人 and t_crm_client_sales.开始日期<=v_op_bscard_all.开船日期 and v_op_bscard_all.开船日期<=t_crm_client_sales.结束日期 ' else tempstr2:=' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 and t_crm_client_sales.开始日期<=v_op_bscard_all.开船日期 and v_op_bscard_all.开船日期<=t_crm_client_sales.结束日期 '; {$IFDEF NXIANCHENG} frm_rp_no_total.p_accept_bill.close; frm_rp_no_total.p_accept_bill.Connection:=frm_main.db; frm_rp_no_total.p_accept_bill1.DataSet:=frm_rp_no_total.p_accept_bill; {$ELSE} sqltext:= {$ENDIF} 'SELECT t_ch_fee.编号, t_ch_fee.客户名称' +',SUM(' +'case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then t_ch_fee.金额 else 0 end' +') as 应收USD,' +'SUM(' +'case t_ch_fee.币别 when '+''''+'USD'+''''+' then t_ch_fee.结算金额' +' else 0 end' +') as 已收USD' +',SUM(' +'case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then t_ch_fee.金额-t_ch_fee.结算金额' +' else 0 end' +') as 未收USD' +',SUM(' +'case t_ch_fee.币别' +' when '+''''+'RMB'+''''+' then ROUND(t_ch_fee.金额*t_ch_fee.汇率,2)' +' else 0' +' end' +') as 应收RMB' +',SUM(' +'case t_ch_fee.币别' +' when '+''''+'RMB'+''''+' then ROUND(t_ch_fee.结算金额*t_ch_fee.汇率,2)' +' else 0' +' end' +') as 已收RMB' +',SUM(' +' case t_ch_fee.币别 when '+''''+'RMB'+''''+' then ' +' ROUND((t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率,2)' +' else 0' +' end' +') as 未收RMB' // +',SUM(' +'case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then 0' +' when '+''''+'RMB'+''''+' then 0' +' else ROUND(t_ch_fee.金额,2)' +' end' +') as 应收其它' +',SUM(' +'case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then 0' +' when '+''''+'RMB'+''''+' then 0' +' else ROUND(t_ch_fee.结算金额,2)' +' end' +') as 已收其它' +',SUM(' +' case t_ch_fee.币别' +' when '+''''+'USD'+'''' +' then 0' +' when '+''''+'RMB'+''''+' then 0' +' else ROUND((t_ch_fee.金额-t_ch_fee.结算金额),2)' +' end' +') as 未收其它' // +',sum(ROUND(t_ch_fee.金额*t_ch_fee.汇率,2)) as 应收合计,' +' sum(ROUND(t_ch_fee.结算金额*t_ch_fee.汇率,2)) as 已收合计,' +' sum(ROUND((t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率,2)) as 未收合计,' +'v_op_bscard_all.业务编号, v_op_bscard_all.会计期间, v_op_bscard_all.主提单号,' +'v_op_bscard_all.分提单号, v_op_bscard_all.委托编号, v_op_bscard_all.装运方式,' +'v_op_bscard_all.委托单位,v_op_bscard_all.收货人,v_op_bscard_all.发货人, v_op_bscard_all.业务类型, v_op_bscard_all.业务状态, v_op_bscard_all.费用状态, v_op_bscard_all.经营单位,' +'v_op_bscard_all.航次, v_op_bscard_all.船名, v_op_bscard_all.开船日期,' +'v_op_bscard_all.装货港, v_op_bscard_all.卸货港, v_op_bscard_all.目的地, v_op_bscard_all.货物名称,' +'v_op_bscard_all.件数, v_op_bscard_all.重量, v_op_bscard_all.尺码,' +'v_op_bscard_all.箱型1, v_op_bscard_all.箱型2, v_op_bscard_all.箱型3,' +'v_op_bscard_all.箱型4, v_op_bscard_all.箱型5, v_op_bscard_all.箱型6,' +'v_op_bscard_all.箱型7, v_op_bscard_all.箱型8, v_op_bscard_all.箱型9,' +'v_op_bscard_all.箱型10, v_op_bscard_all.其他箱型,' +'v_op_bscard_all.箱TEU, v_op_bscard_all.集装箱, v_op_bscard_all.操作员,' +'v_op_bscard_all.揽货人, v_op_bscard_all.客服员, v_op_bscard_all.航线,v_op_bscard_all.场站,v_op_bscard_all.提单签发状态, t_op_gain.利润率,' +'v_op_bscard_all.船公司, v_op_bscard_all.货代公司, v_op_bscard_all.报关行,v_op_bscard_all.报关单号,v_op_bscard_all.报检单号,v_op_bscard_all.操作部门,v_op_bscard_all.销售部门' +',v_op_bscard_all.接单日期,v_op_bscard_all.录入日期,v_op_bscard_all.订舱单号,v_op_bscard_all.业务来源,' +'DATEDIFF([day],v_op_bscard_all.开船日期, GETDATE()) AS 实际天数,' +'isnull(DATEDIFF([day],v_op_bscard_all.开船日期, GETDATE())-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)' +' else (case t_crm_client_sales.结费类型 when ''约定时间'' then' +' ( DATEDIFF([day],v_op_bscard_all.开船日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期,DATEADD(Day,-Day(v_op_bscard_all.开船日期)+1,v_op_bscard_all.开船日期))))) else 0 end) end)' +',DATEDIFF([day],v_op_bscard_all.开船日期, GETDATE())) as 超期天数,' +'(case t_crm_client_sales.结费类型 ' +' when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0) ' +' when ''约定时间'' then CAST(t_crm_client_sales.类型模式 AS int)*30+isnull(t_crm_client_sales.结费日期,0) ' +' else 0 ' +' end) as 协议天数, ' +'(case when round((case when v_op_bscard_all.重量/1000>v_op_bscard_all.尺码 then v_op_bscard_all.重量/1000 ' +'else v_op_bscard_all.尺码 end),4)>1 then ' +'round((case when v_op_bscard_all.重量/1000>v_op_bscard_all.尺码 then v_op_bscard_all.重量/1000 else ' +'v_op_bscard_all.尺码 end),4) else ' +'1 end) as 计费吨 '// // +',icUsd.发票号码 USD发票号码,icUsd.实际金额 usd发票金额,icRMB.发票号码 RMB发票号码,icRMB.实际金额 RMB发票金额' +' FROM t_ch_fee inner join v_op_bscard_all on v_op_bscard_all.编号=t_ch_fee.编号 ' +str_zr +tempstr2 +' left join t_op_gain on t_ch_fee.编号=t_op_gain.编号 ' // +' LEFT OUTER JOIN t_ch_invoice icUsd ON (V_op_bscard_All.主提单号 = icUsd.提单号 and icUsd.提单号<>'''' and not icUsd.提单号 is null and icUsd.币别=''USD'' and icUsd.是否废除=0 and t_ch_fee.客户名称=icUsd.客户名称)' // +' LEFT OUTER JOIN t_ch_invoice icRMB ON (V_op_bscard_All.主提单号 = icRMB.提单号 and icRMB.提单号<>'''' and not icRMB.提单号 is null and icRMB.币别=''RMB'' and icRMB.是否废除=0 and t_ch_fee.客户名称=icRMB.客户名称) ' +clientstr +str_bill+' and t_ch_fee.类型='+''''+'收'+'''' +s_private +tempstr +' GROUP BY t_ch_fee.编号, t_ch_fee.客户名称,' +'v_op_bscard_all.业务编号, v_op_bscard_all.会计期间, v_op_bscard_all.主提单号,' +'v_op_bscard_all.分提单号, v_op_bscard_all.委托编号, v_op_bscard_all.装运方式,' +'v_op_bscard_all.委托单位,v_op_bscard_all.收货人,v_op_bscard_all.发货人, v_op_bscard_all.业务类型,v_op_bscard_all.业务状态, v_op_bscard_all.费用状态,v_op_bscard_all.经营单位,' +'v_op_bscard_all.航次, v_op_bscard_all.船名, v_op_bscard_all.开船日期,' +'v_op_bscard_all.装货港, v_op_bscard_all.卸货港, v_op_bscard_all.目的地,v_op_bscard_all.货物名称, ' +'v_op_bscard_all.件数, v_op_bscard_all.重量, v_op_bscard_all.尺码,' +'v_op_bscard_all.箱型1, v_op_bscard_all.箱型2, v_op_bscard_all.箱型3,' +'v_op_bscard_all.箱型4, v_op_bscard_all.箱型5, v_op_bscard_all.箱型6,' +'v_op_bscard_all.箱型7, v_op_bscard_all.箱型8, v_op_bscard_all.箱型9,' +'v_op_bscard_all.箱型10,v_op_bscard_all.其他箱型,' +'v_op_bscard_all.箱TEU, v_op_bscard_all.集装箱, v_op_bscard_all.操作员,' +'v_op_bscard_all.揽货人, v_op_bscard_all.客服员, v_op_bscard_all.航线,v_op_bscard_all.场站,v_op_bscard_all.提单签发状态,t_op_gain.利润率, ' +'v_op_bscard_all.船公司, v_op_bscard_all.货代公司, v_op_bscard_all.报关行,v_op_bscard_all.报关单号,v_op_bscard_all.报检单号,v_op_bscard_all.操作部门,v_op_bscard_all.销售部门' +',v_op_bscard_all.接单日期,v_op_bscard_all.录入日期,v_op_bscard_all.订舱单号,v_op_bscard_all.业务来源,' +'DATEDIFF([day],v_op_bscard_all.开船日期, GETDATE()),' +'isnull(DATEDIFF([day],v_op_bscard_all.开船日期, GETDATE())-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)' +' else (case t_crm_client_sales.结费类型 when ''约定时间'' then' +' ( DATEDIFF([day],v_op_bscard_all.开船日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期, DATEADD(Day,-Day(v_op_bscard_all.开船日期)+1,v_op_bscard_all.开船日期) )))) else 0 end) end)' +',DATEDIFF([day],v_op_bscard_all.开船日期, GETDATE())),' +'(case t_crm_client_sales.结费类型 ' +' when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0) ' +' when ''约定时间'' then CAST(t_crm_client_sales.类型模式 AS int)*30+isnull(t_crm_client_sales.结费日期,0) ' +' else 0' +' end),' +'(case when round((case when v_op_bscard_all.重量/1000>v_op_bscard_all.尺码 then v_op_bscard_all.重量/1000 ' +'else v_op_bscard_all.尺码 end),4)>1 then ' +'round((case when v_op_bscard_all.重量/1000>v_op_bscard_all.尺码 then v_op_bscard_all.重量/1000 else ' +'v_op_bscard_all.尺码 end),4) else ' +'1 end)' // +',icUsd.发票号码,icUsd.实际金额,icRMB.发票号码,icRMB.实际金额' +default_sort_two(53,'v_op_bscard_all','t_ch_fee.客户名称','',''); /// showmessage(sqltext); // showmessage(sqltext); if no_seae_query_fee<>4 then begin sqlInv:= ' SELECT DISTINCT t_ch_fee.客户名称, V_op_bscard_All.主提单号,t_ch_invoice.币别,' +' CASE WHEN t_ch_invoice.币别 = ''USD'' THEN 实际金额 ELSE 0 END AS USD发票金额, ' +' CASE WHEN t_ch_invoice.币别 = ''RMB'' THEN 实际金额 ELSE 0 END AS RMB发票金额, ' +' CASE WHEN t_ch_invoice.币别 = ''USD'' THEN 发票号码 ELSE '''' END AS USD发票号码, ' +' CASE WHEN t_ch_invoice.币别 = ''RMB'' THEN 发票号码 ELSE '''' END AS RMB发票号码 ' +' FROM t_ch_fee ' +' INNER JOIN V_op_bscard_All ON V_op_bscard_All.编号 = t_ch_fee.编号 ' +' LEFT OUTER JOIN t_ch_invoice ON (V_op_bscard_All.主提单号 = t_ch_invoice.提单号 and t_ch_invoice.提单号<>'''' and not t_ch_invoice.提单号 is null and t_ch_invoice.是否废除=0 and t_ch_fee.客户名称=t_ch_invoice.客户名称)' +clientstr +str_bill+' and t_ch_fee.类型='+''''+'收'+'''' +tempstr; frm_rp_no_total.ADOQueryINV.sql.TEXT:=sqlInv; frm_rp_no_total.ADOQueryINV.Open; // showmessage(frm_rp_no_total.ADOQueryINV.sql.TEXT); InitmemtableinvData; end; //showmessage(sqltext); {$IFDEF NXIANCHENG} {$ELSE} constr:=connect_string('main.ini'); frm_rp_no_total.p_accept_bill.ConnectionString:=constr; DBQueryThread1:=TDBADOQueryThread.Create(frm_rp_no_total.p_accept_bill,sqltext,frm_rp_no_total.p_accept_bill1); // ShowMessage(sqltext); {$ENDIF} if no_seae_query_fee=4 then begin tempstr:=' and isnull(DATEDIFF([day],v_op_bscard_all.开船日期, GETDATE())-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)' +' else (case t_crm_client_sales.结费类型 when ''约定时间'' then' +' ( DATEDIFF([day],v_op_bscard_all.开船日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期,v_op_bscard_all.开船日期)))) else 0 end) end),DATEDIFF([day],v_op_bscard_all.开船日期, GETDATE()))>0'; end else begin // tempstr:=' and 1=1 '; end; {$IFDEF NXIANCHENG} frm_rp_no_total.p_accept_fee.close; frm_rp_no_total.p_accept_fee.Connection:=frm_main.db; frm_rp_no_total.p_accept_fee1.DataSet:=frm_rp_no_total.p_accept_fee; frm_rp_no_total.p_accept_fee.Parameters.ParamByName('SQLStr').value:= {$ELSE} sqltext:= {$ENDIF} 'SELECT t_ch_fee.ch_id,t_ch_fee.编号,t_ch_fee.对帐编号 ,t_ch_fee.客户名称, t_ch_fee.费用名称,t_ch_fee.税率,t_ch_fee.不含税金额,t_ch_fee.税额,t_ch_fee.财务税率,t_ch_fee.财务不含税价,t_ch_fee.财务税额,t_ch_fee.币别' +',' +'case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then t_ch_fee.金额 else 0 end' +' as 应收USD' +',' +'case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then t_ch_fee.结算金额 else 0 end' +' as 已收USD' +',' +'case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end' +' as 未收USD' +',' +'case t_ch_fee.币别' +' when '+''''+'RMB'+''''+' then t_ch_fee.金额 else 0 end' +' as 应收RMB' +',' +'case t_ch_fee.币别' +' when '+''''+'RMB'+''''+' then t_ch_fee.结算金额 else 0 end' +' as 已收RMB' +',' +'case t_ch_fee.币别' +' when '+''''+'RMB'+''''+' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end' +' as 未收RMB' +',' +' case t_ch_fee.币别' +' when '+''''+'USD'+'''' +' then 0' +' when '+''''+'RMB'+''''+' then 0' +' else ROUND((t_ch_fee.金额),2)' +' end' +' as 应收其它' +',' +' case t_ch_fee.币别' +' when '+''''+'USD'+'''' +' then 0' +' when '+''''+'RMB'+''''+' then 0' +' else ROUND((t_ch_fee.结算金额),2)' +' end' +' as 已收其它' +',' +' case t_ch_fee.币别' +' when '+''''+'USD'+'''' +' then 0' +' when '+''''+'RMB'+''''+' then 0' +' else ROUND((t_ch_fee.金额-t_ch_fee.结算金额),2)' +' end' +' as 未收其它' +',t_ch_fee.金额 as 应收金额,' +'t_ch_fee.结算金额 as 已收金额,(t_ch_fee.金额-t_ch_fee.结算金额) as 未收金额,' +'t_ch_fee.标准 as 标准,t_ch_fee.单价 as 单价,t_ch_fee.数量 as 数量,t_ch_fee.备注 as 费用备注,' +'v_op_bscard_all.业务编号, v_op_bscard_all.会计期间, v_op_bscard_all.主提单号,' +'v_op_bscard_all.分提单号, v_op_bscard_all.委托编号, v_op_bscard_all.装运方式,' +'v_op_bscard_all.委托单位,v_op_bscard_all.收货人,v_op_bscard_all.发货人, v_op_bscard_all.业务类型,v_op_bscard_all.业务状态, v_op_bscard_all.费用状态,v_op_bscard_all.经营单位,' +'v_op_bscard_all.航次, v_op_bscard_all.船名, v_op_bscard_all.开船日期,' +'v_op_bscard_all.装货港, v_op_bscard_all.卸货港, v_op_bscard_all.目的地,v_op_bscard_all.货物名称, ' +'v_op_bscard_all.件数, v_op_bscard_all.重量, v_op_bscard_all.尺码,' +'v_op_bscard_all.箱型1, v_op_bscard_all.箱型2, v_op_bscard_all.箱型3,' +'v_op_bscard_all.箱型4, v_op_bscard_all.箱型5, v_op_bscard_all.箱型6,' +'v_op_bscard_all.箱型7, v_op_bscard_all.箱型8, v_op_bscard_all.箱型9,' +'v_op_bscard_all.箱型10,v_op_bscard_all.其他箱型,' +'v_op_bscard_all.箱TEU, v_op_bscard_all.集装箱, v_op_bscard_all.操作员,' +'v_op_bscard_all.揽货人, v_op_bscard_all.客服员, v_op_bscard_all.航线,v_op_bscard_all.场站,' +'v_op_bscard_all.船公司, v_op_bscard_all.货代公司, v_op_bscard_all.报关行,v_op_bscard_all.报关单号,v_op_bscard_all.报检单号,v_op_bscard_all.操作部门,v_op_bscard_all.销售部门,' +'(case when round((case when v_op_bscard_all.重量/1000>v_op_bscard_all.尺码 then v_op_bscard_all.重量/1000 ' +'else v_op_bscard_all.尺码 end),4)>1 then ' +'round((case when v_op_bscard_all.重量/1000>v_op_bscard_all.尺码 then v_op_bscard_all.重量/1000 else ' +'v_op_bscard_all.尺码 end),4) else ' +'1 end) as 计费吨 ' +'FROM t_ch_fee inner join v_op_bscard_all on v_op_bscard_all.编号=t_ch_fee.编号 ' +str_zr +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 and t_crm_client_sales.开始日期<=v_op_bscard_all.开船日期 and v_op_bscard_all.开船日期<=t_crm_client_sales.结束日期 ' +clientstr +str_bill+' and t_ch_fee.类型='+''''+'收'+'''' +s_private +tempstr +default_sort_two(53,'v_op_bscard_all','t_ch_fee.客户名称','',''); {$IFDEF NXIANCHENG} frm_rp_no_total.p_accept_fee.Open; {$ELSE} frm_rp_no_total.p_accept_fee.ConnectionString:=constr; DBQueryThread2:=TDBQueryThread.Create(frm_rp_no_total.p_accept_fee,sqltext,frm_rp_no_total.p_accept_fee1); {$ENDIF} if not bsSkinCheckRadioBox2.Checked then begin {$IFDEF NXIANCHENG} frm_rp_no_total.p_pay_bill.close; frm_rp_no_total.p_pay_bill.Connection:=frm_main.db; frm_rp_no_total.p_pay_bill1.DataSet:=frm_rp_no_total.p_pay_bill; frm_rp_no_total.p_pay_bill.Parameters.ParamByName('SQLStr').value:= {$ELSE} sqltext:= {$ENDIF} 'SELECT t_ch_fee.编号, t_ch_fee.客户名称' +',SUM(' +'case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then t_ch_fee.金额 else 0 end' +') as 应付USD,' +'SUM(' +'case t_ch_fee.币别 when '+''''+'USD'+''''+' then t_ch_fee.结算金额' +' else 0 end' +') as 已付USD' +',SUM(' +'case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then t_ch_fee.金额-t_ch_fee.结算金额' +' else 0 end' +') as 未付USD' +',SUM(' +'case t_ch_fee.币别' +' when '+''''+'RMB'+''''+' then ROUND(t_ch_fee.金额*t_ch_fee.汇率,2)' +' else 0' +' end' +') as 应付RMB' +',SUM(' +'case t_ch_fee.币别' +' when '+''''+'RMB'+''''+' then ROUND(t_ch_fee.结算金额*t_ch_fee.汇率,2)' +' else 0' +' end' +') as 已付RMB' +',SUM(' +' case t_ch_fee.币别 when '+''''+'RMB'+''''+' then ' +' ROUND((t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率,2)' +' else 0' +' end' +') as 未付RMB' // +',SUM(' +'case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then 0' +' when '+''''+'RMB'+''''+' then 0' +' else ROUND(t_ch_fee.金额,2)' +' end' +') as 应付其它' +',SUM(' +'case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then 0' +' when '+''''+'RMB'+''''+' then 0' +' else ROUND(t_ch_fee.结算金额,2)' +' end' +') as 已付其它' +',SUM(' +' case t_ch_fee.币别' +' when '+''''+'USD'+'''' +' then 0' +' when '+''''+'RMB'+''''+' then 0' +' else ROUND((t_ch_fee.金额-t_ch_fee.结算金额),2)' +' end' +') as 未付其它' // +',sum(ROUND(t_ch_fee.金额*t_ch_fee.汇率,2)) as 应付合计,' +' sum(ROUND(t_ch_fee.结算金额*t_ch_fee.汇率,2)) as 已付合计,' +' sum(ROUND((t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率,2)) as 未付合计,' +'v_op_bscard_all.业务编号, v_op_bscard_all.会计期间, v_op_bscard_all.主提单号,' +'v_op_bscard_all.分提单号, v_op_bscard_all.委托编号, v_op_bscard_all.装运方式,' +'v_op_bscard_all.委托单位,v_op_bscard_all.收货人,v_op_bscard_all.发货人, v_op_bscard_all.业务类型,v_op_bscard_all.业务状态, v_op_bscard_all.费用状态,v_op_bscard_all.经营单位,' +'v_op_bscard_all.航次, v_op_bscard_all.船名, v_op_bscard_all.开船日期,' +'v_op_bscard_all.装货港, v_op_bscard_all.卸货港, v_op_bscard_all.目的地, v_op_bscard_all.货物名称, ' +'v_op_bscard_all.件数, v_op_bscard_all.重量, v_op_bscard_all.尺码,' +'v_op_bscard_all.箱型1, v_op_bscard_all.箱型2, v_op_bscard_all.箱型3,' +'v_op_bscard_all.箱型4, v_op_bscard_all.箱型5, v_op_bscard_all.箱型6,' +'v_op_bscard_all.箱型7, v_op_bscard_all.箱型8, v_op_bscard_all.箱型9,' +'v_op_bscard_all.箱型10,v_op_bscard_all.其他箱型,' +'v_op_bscard_all.箱TEU, v_op_bscard_all.集装箱, v_op_bscard_all.操作员,' +'v_op_bscard_all.揽货人, v_op_bscard_all.客服员, v_op_bscard_all.航线,v_op_bscard_all.场站,v_op_bscard_all.提单签发状态, t_op_gain.利润率,' +'v_op_bscard_all.船公司, v_op_bscard_all.货代公司, v_op_bscard_all.报关行,v_op_bscard_all.报关单号,v_op_bscard_all.报检单号,v_op_bscard_all.操作部门,v_op_bscard_all.销售部门,v_op_bscard_all.接单日期,v_op_bscard_all.录入日期,' +'DATEDIFF([day],v_op_bscard_all.开船日期, GETDATE()) AS 实际天数,' +'isnull(DATEDIFF([day],v_op_bscard_all.开船日期, GETDATE())-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)' +' else (case t_crm_client_sales.结费类型 when ''约定时间'' then' +' ( DATEDIFF([day],v_op_bscard_all.开船日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期,DATEADD(Day,-Day(v_op_bscard_all.开船日期)+1,v_op_bscard_all.开船日期))))) else 0 end) end)' +',DATEDIFF([day],v_op_bscard_all.开船日期, GETDATE())) as 超期天数,' +'(case t_crm_client_sales.结费类型 ' +' when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0) ' +' when ''约定时间'' then CAST(t_crm_client_sales.类型模式 AS int)*30+isnull(t_crm_client_sales.结费日期,0) ' +' else 0 ' +' end) as 协议天数, ' +'(case when round((case when v_op_bscard_all.重量/1000>v_op_bscard_all.尺码 then v_op_bscard_all.重量/1000 ' +'else v_op_bscard_all.尺码 end),4)>1 then ' +'round((case when v_op_bscard_all.重量/1000>v_op_bscard_all.尺码 then v_op_bscard_all.重量/1000 else ' +'v_op_bscard_all.尺码 end),4) else ' +'1 end) as 计费吨' +' FROM t_ch_fee inner join v_op_bscard_all on v_op_bscard_all.编号=t_ch_fee.编号 ' +str_zr +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +' left join t_op_gain on t_ch_fee.编号=t_op_gain.编号 ' +clientstr +str_bill+' and t_ch_fee.类型='+''''+'付'+'''' +tempstr +s_private +' GROUP BY t_ch_fee.编号, t_ch_fee.客户名称,' +'v_op_bscard_all.业务编号, v_op_bscard_all.会计期间, v_op_bscard_all.主提单号,' +'v_op_bscard_all.分提单号, v_op_bscard_all.委托编号, v_op_bscard_all.装运方式,' +'v_op_bscard_all.委托单位,v_op_bscard_all.收货人,v_op_bscard_all.发货人, v_op_bscard_all.业务类型,v_op_bscard_all.业务状态, v_op_bscard_all.费用状态,v_op_bscard_all.经营单位,' +'v_op_bscard_all.航次, v_op_bscard_all.船名, v_op_bscard_all.开船日期,' +'v_op_bscard_all.装货港, v_op_bscard_all.卸货港, v_op_bscard_all.目的地, v_op_bscard_all.货物名称,' +'v_op_bscard_all.件数, v_op_bscard_all.重量, v_op_bscard_all.尺码,' +'v_op_bscard_all.箱型1, v_op_bscard_all.箱型2, v_op_bscard_all.箱型3,' +'v_op_bscard_all.箱型4, v_op_bscard_all.箱型5, v_op_bscard_all.箱型6,' +'v_op_bscard_all.箱型7, v_op_bscard_all.箱型8, v_op_bscard_all.箱型9,' +'v_op_bscard_all.箱型10, v_op_bscard_all.其他箱型,' +'v_op_bscard_all.箱TEU, v_op_bscard_all.集装箱, v_op_bscard_all.操作员,' +'v_op_bscard_all.揽货人, v_op_bscard_all.客服员, v_op_bscard_all.航线,v_op_bscard_all.场站, v_op_bscard_all.提单签发状态,t_op_gain.利润率, ' +'v_op_bscard_all.船公司, v_op_bscard_all.货代公司, v_op_bscard_all.报关行,v_op_bscard_all.报关单号,v_op_bscard_all.报检单号,v_op_bscard_all.操作部门,v_op_bscard_all.销售部门,v_op_bscard_all.接单日期,v_op_bscard_all.录入日期,' +'DATEDIFF([day],v_op_bscard_all.开船日期, GETDATE()),' +'isnull(DATEDIFF([day],v_op_bscard_all.开船日期, GETDATE())-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)' +' else (case t_crm_client_sales.结费类型 when ''约定时间'' then' +' ( DATEDIFF([day],v_op_bscard_all.开船日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期, DATEADD(Day,-Day(v_op_bscard_all.开船日期)+1,v_op_bscard_all.开船日期) )))) else 0 end) end)' +',DATEDIFF([day],v_op_bscard_all.开船日期, GETDATE())),' +'(case t_crm_client_sales.结费类型 ' +' when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0) ' +' when ''约定时间'' then CAST(t_crm_client_sales.类型模式 AS int)*30+isnull(t_crm_client_sales.结费日期,0) ' +' else 0' +' end),' +'(case when round((case when v_op_bscard_all.重量/1000>v_op_bscard_all.尺码 then v_op_bscard_all.重量/1000 ' +'else v_op_bscard_all.尺码 end),4)>1 then ' +'round((case when v_op_bscard_all.重量/1000>v_op_bscard_all.尺码 then v_op_bscard_all.重量/1000 else ' +'v_op_bscard_all.尺码 end),4) else ' +'1 end)' +default_sort_two(53,'v_op_bscard_all','t_ch_fee.客户名称','',''); // showmessage(tempstr); // showmessage(sqltext); {$IFDEF NXIANCHENG} frm_rp_no_total.p_pay_bill.Open; {$ELSE} frm_rp_no_total.p_pay_bill.ConnectionString:=constr; DBQueryThread3:=TDBQueryThread.Create(frm_rp_no_total.p_pay_bill,sqltext,frm_rp_no_total.p_pay_bill1); {$ENDIF} {$IFDEF NXIANCHENG} frm_rp_no_total.p_pay_fee.close; frm_rp_no_total.p_pay_fee.Connection:=frm_main.db; frm_rp_no_total.p_pay_fee.DataSet:=frm_rp_no_total.p_pay_fee; frm_rp_no_total.p_pay_fee.Parameters.ParamByName('SQLStr').value:= {$ELSE} sqltext:= {$ENDIF} 'SELECT t_ch_fee.ch_id,t_ch_fee.编号, t_ch_fee.客户名称, t_ch_fee.费用名称,t_ch_fee.税率,t_ch_fee.不含税金额,t_ch_fee.税额,t_ch_fee.财务税率,t_ch_fee.财务不含税价,t_ch_fee.财务税额,t_ch_fee.币别,t_ch_fee.金额 as 应付金额' +',' +'case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then t_ch_fee.金额 else 0 end' +' as 应付USD' +',' +'case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then t_ch_fee.结算金额 else 0 end' +' as 已付USD' +',' +'case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end' +' as 未付USD' +',' +'case t_ch_fee.币别' +' when '+''''+'RMB'+''''+' then t_ch_fee.金额 else 0 end' +' as 应付RMB' +',' +'case t_ch_fee.币别' +' when '+''''+'RMB'+''''+' then t_ch_fee.结算金额 else 0 end' +' as 已付RMB' +',' +'case t_ch_fee.币别' +' when '+''''+'RMB'+''''+' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end' +' as 未付RMB' +',' +' case t_ch_fee.币别' +' when '+''''+'USD'+'''' +' then 0' +' when '+''''+'RMB'+''''+' then 0' +' else ROUND((t_ch_fee.金额),2)' +' end' +' as 应付其它' +',' +' case t_ch_fee.币别' +' when '+''''+'USD'+'''' +' then 0' +' when '+''''+'RMB'+''''+' then 0' +' else ROUND((t_ch_fee.结算金额),2)' +' end' +' as 已付其它' +',' +' case t_ch_fee.币别' +' when '+''''+'USD'+'''' +' then 0' +' when '+''''+'RMB'+''''+' then 0' +' else ROUND((t_ch_fee.金额-t_ch_fee.结算金额),2)' +' end' +' as 未付其它' +',t_ch_fee.结算金额 as 已付金额,(t_ch_fee.金额-t_ch_fee.结算金额) as 未付金额,' +'t_ch_fee.标准 as 标准,t_ch_fee.单价 as 单价,t_ch_fee.数量 as 数量,t_ch_fee.备注 as 费用备注,' +'v_op_bscard_all.业务编号, v_op_bscard_all.会计期间, v_op_bscard_all.主提单号,' +'v_op_bscard_all.分提单号, v_op_bscard_all.委托编号, v_op_bscard_all.装运方式,' +'v_op_bscard_all.委托单位,v_op_bscard_all.收货人,v_op_bscard_all.发货人, v_op_bscard_all.业务类型,v_op_bscard_all.业务状态, v_op_bscard_all.费用状态,v_op_bscard_all.经营单位,' +'v_op_bscard_all.航次, v_op_bscard_all.船名, v_op_bscard_all.开船日期,' +'v_op_bscard_all.装货港, v_op_bscard_all.卸货港, v_op_bscard_all.目的地, v_op_bscard_all.货物名称, ' +'v_op_bscard_all.件数, v_op_bscard_all.重量, v_op_bscard_all.尺码,' +'v_op_bscard_all.箱型1, v_op_bscard_all.箱型2, v_op_bscard_all.箱型3,' +'v_op_bscard_all.箱型4, v_op_bscard_all.箱型5, v_op_bscard_all.箱型6,' +'v_op_bscard_all.箱型7, v_op_bscard_all.箱型8, v_op_bscard_all.箱型9,' +'v_op_bscard_all.箱型10, v_op_bscard_all.其他箱型,' +'v_op_bscard_all.箱TEU, v_op_bscard_all.集装箱, v_op_bscard_all.操作员,' +'v_op_bscard_all.揽货人, v_op_bscard_all.客服员, v_op_bscard_all.航线,v_op_bscard_all.场站,' +'v_op_bscard_all.船公司, v_op_bscard_all.货代公司, v_op_bscard_all.报关行,v_op_bscard_all.报关单号,v_op_bscard_all.报检单号,v_op_bscard_all.操作部门,v_op_bscard_all.销售部门,' +'(case when round((case when v_op_bscard_all.重量/1000>v_op_bscard_all.尺码 then v_op_bscard_all.重量/1000 ' +'else v_op_bscard_all.尺码 end),4)>1 then ' +'round((case when v_op_bscard_all.重量/1000>v_op_bscard_all.尺码 then v_op_bscard_all.重量/1000 else ' +'v_op_bscard_all.尺码 end),4) else ' +'1 end) as 计费吨' +' FROM t_ch_fee inner join v_op_bscard_all on v_op_bscard_all.编号=t_ch_fee.编号 ' +str_zr +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +tempstr +str_bill+' and t_ch_fee.类型='+''''+'付'+'''' +s_private +default_sort_two(53,'v_op_bscard_all','t_ch_fee.客户名称','',''); {$IFDEF NXIANCHENG} frm_rp_no_total.p_pay_fee.Open; {$ELSE} frm_rp_no_total.p_pay_fee.ConnectionString:=constr; // showmessage(sqltext); DBQueryThread4:=TDBQueryThread.Create(frm_rp_no_total.p_pay_fee,sqltext,frm_rp_no_total.p_pay_fee1); {$ENDIF} {$IFDEF NXIANCHENG} frm_rp_no_total.p_total_client.close; frm_rp_no_total.p_total_client.Connection:=frm_main.db; frm_rp_no_total.p_total_client.DataSet:=frm_rp_no_total.p_total_client; frm_rp_no_total.p_total_client.Parameters.ParamByName('SQLStr').value:= {$ELSE} sqltext:= {$ENDIF} 'SELECT '+''''+'海运出口'+''''+' as 业务种类 ,t_ch_fee.客户名称,' +str_feesum +' FROM t_ch_fee inner join t_op_seae on t_op_seae.编号=t_ch_fee.编号 ' +str_seaezr +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_seae +s_private +' GROUP BY t_ch_fee.客户名称 ' +' union SELECT '+''''+'海运进口'+''''+' as 业务种类 ,t_ch_fee.客户名称,' +str_feesum +' FROM t_ch_fee inner join t_op_seai on t_op_seai.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_seai +s_private +' GROUP BY t_ch_fee.客户名称 ' +' union SELECT '+''''+'空运出口'+''''+' as 业务种类 ,t_ch_fee.客户名称,' +str_feesum +' FROM t_ch_fee inner join t_op_aire on t_op_aire.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_aire +s_private +' GROUP BY t_ch_fee.客户名称 ' +' union SELECT '+''''+'空运进口'+''''+' as 业务种类 ,t_ch_fee.客户名称,' +str_feesum +' FROM t_ch_fee inner join t_op_airi on t_op_airi.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_airi +s_private +' GROUP BY t_ch_fee.客户名称 ' +' union SELECT '+''''+'铁路运输'+''''+' as 业务种类 ,t_ch_fee.客户名称,' +str_feesum +' FROM t_ch_fee inner join t_op_railway on t_op_railway.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_railway +s_private +' GROUP BY t_ch_fee.客户名称 ' +' union SELECT '+''''+'监管车'+''''+' as 业务种类 ,t_ch_fee.客户名称,' +str_feesum +' FROM t_ch_fee inner join t_op_airtruck on t_op_airtruck.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_airtruck +s_private +' GROUP BY t_ch_fee.客户名称 '; {$IFDEF NXIANCHENG} frm_rp_no_total.p_total_client.Open; {$ELSE} frm_rp_no_total.p_total_client.ConnectionString:=constr; // showmessage(sqltext); DBQueryThread5:=TDBQueryThread.Create(frm_rp_no_total.p_total_client,sqltext,frm_rp_no_total.p_total_client1); {$ENDIF} {$IFDEF NXIANCHENG} frm_rp_no_total.p_total_sales.close; frm_rp_no_total.p_total_sales.Parameters.ParamByName('SQLStr').value:= {$ELSE} sqltext:= {$ENDIF} 'SELECT '+''''+'海运出口'+''''+' as 业务种类 ,t_op_seae.揽货人,' +str_feesum +' FROM t_ch_fee inner join t_op_seae on t_op_seae.编号=t_ch_fee.编号 '+ str_seaezr +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_seae +s_private +' GROUP BY t_op_seae.揽货人' +' union SELECT '+''''+'海运进口'+''''+' as 业务种类 ,t_op_seai.揽货人,' +str_feesum +' FROM t_ch_fee inner join t_op_seai on t_op_seai.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_seai +s_private +' GROUP BY t_op_seai.揽货人 ' +' union SELECT '+''''+'空运出口'+''''+' as 业务种类 ,t_op_aire.揽货人,' +str_feesum +' FROM t_ch_fee inner join t_op_aire on t_op_aire.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_aire +s_private +' GROUP BY t_op_aire.揽货人 ' +' union SELECT '+''''+'空运进口'+''''+' as 业务种类 ,t_op_airi.揽货人,' +str_feesum +' FROM t_ch_fee inner join t_op_airi on t_op_airi.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_airi+' GROUP BY t_op_airi.揽货人 ' +' union SELECT '+''''+'铁路运输'+''''+' as 业务种类 ,t_op_railway.揽货人,' +str_feesum +' FROM t_ch_fee inner join t_op_railway on t_op_railway.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_railway +s_private +' GROUP BY t_op_railway.揽货人 ' +' union SELECT '+''''+'监管车'+''''+' as 业务种类 ,t_op_airtruck.揽货人,' +str_feesum +' FROM t_ch_fee inner join t_op_airtruck on t_op_airtruck.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_airtruck +s_private +' GROUP BY t_op_airtruck.揽货人 '; {$IFDEF NXIANCHENG} frm_rp_no_total.p_total_sales.Open; {$ELSE} frm_rp_no_total.p_total_sales.ConnectionString:=constr; DBQueryThread6:=TDBQueryThread.Create(frm_rp_no_total.p_total_sales,sqltext,frm_rp_no_total.p_total_sales1); {$ENDIF} // ShowMessage(sqltext); frm_rp_no_total.p_total.close; frm_rp_no_total.p_total.Parameters.ParamByName('SQLStr').value:= //sqltext:= 'SELECT '+''''+'海运出口'+''''+' as 业务种类 ,' +str_feesum +' FROM t_ch_fee inner join t_op_seae on t_op_seae.编号=t_ch_fee.编号 '+str_seaezr +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_seae +s_private +' union SELECT '+''''+'海运进口'+''''+' as 业务种类 ,' +str_feesum +' FROM t_ch_fee inner join t_op_seai on t_op_seai.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_seai +s_private +' union SELECT '+''''+'空运出口'+''''+' as 业务种类 ,' +str_feesum +' FROM t_ch_fee inner join t_op_aire on t_op_aire.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_aire +s_private +' union SELECT '+''''+'空运进口'+''''+' as 业务种类 ,' +str_feesum +' FROM t_ch_fee inner join t_op_airi on t_op_airi.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_airi +s_private +' union SELECT '+''''+'铁路运输'+''''+' as 业务种类 ,' +str_feesum +' FROM t_ch_fee inner join t_op_railway on t_op_railway.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_railway +s_private +' union SELECT '+''''+'监管车'+''''+' as 业务种类 ,' +str_feesum +' FROM t_ch_fee inner join t_op_airtruck on t_op_airtruck.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_airtruck +s_private; frm_rp_no_total.p_total.Open; end else begin noDrShen; end; close; exit; end; case no_seae_query_bs of 10: begin str_bill:=frm_rp_no_seae_query.get_no_str(no_seae_query_table,'业务日期'); end; end; case no_seae_query_bs of 10: begin frm_rp_in_total.instr_type:=str_bill; end; end; close; end; procedure Tfrm_rp_no_seae_query.wwDBComboBox18KeyPress(Sender: TObject; var Key: Char); begin if key=#13 then begin key:=#0; frm_rp_no_seae_query.bsSkinButton1Click(Sender); end; end; procedure Tfrm_rp_no_seae_query.loadFindIni; var findini:tinifile ; mysec,tmpname:string; canload:boolean ; //是否记忆 i:integer ; begin mysec:=inttostr(no_seae_query_bs) ; findini:=Tinifile.Create(ExtractFilePath(application.ExeName)+'seaerpnoquery.ini'); try canload:=findini.ReadBool(mysec,mysec,false); bsSkinCheckRadioBox1.Checked:=canload ; if canload then begin with bsSkinGroupBox1 do for i:=0 to ControlCount-1 do begin tmpname:=Controls[i].Name ; if Controls[i] is TwwDBComboBox then (Controls[i] as TwwDBComboBox).Text:=findini.ReadString(mysec,TmpName,'') else if Controls[i] is TEdit then (Controls[i] as TEdit).Text:=findini.ReadString(mysec,TmpName,'') else if Controls[i] is TwwDBDateTimePicker then (Controls[i] as TwwDBDateTimePicker).Date:=strtodate(findini.ReadString(mysec,TmpName,'')) else if Controls[i] is TRxDBLookupCombo then (Controls[i] as TRxDBLookupCombo).Value:=findini.ReadString(mysec,TmpName,'') ; end ; with bsSkinGroupBox4 do for i:=0 to ControlCount-1 do begin tmpname:=Controls[i].Name ; if Controls[i] is TwwDBComboBox then (Controls[i] as TwwDBComboBox).Text:=findini.ReadString(mysec,TmpName,'') else if Controls[i] is TEdit then (Controls[i] as TEdit).Text:=findini.ReadString(mysec,TmpName,'') else if Controls[i] is TwwDBDateTimePicker then (Controls[i] as TwwDBDateTimePicker).Date:=strtodate(findini.ReadString(mysec,TmpName,'')) else if Controls[i] is TRxDBLookupCombo then (Controls[i] as TRxDBLookupCombo).Value:=findini.ReadString(mysec,TmpName,'') ; end ; with bsSkinGroupBox2 do for i:=0 to ControlCount-1 do begin tmpname:=Controls[i].Name ; if Controls[i] is TwwDBComboBox then (Controls[i] as TwwDBComboBox).Text:=findini.ReadString(mysec,TmpName,'') else if Controls[i] is TEdit then (Controls[i] as TEdit).Text:=findini.ReadString(mysec,TmpName,'') else if Controls[i] is TwwDBDateTimePicker then (Controls[i] as TwwDBDateTimePicker).Date:=strtodate(findini.ReadString(mysec,TmpName,'')) else if Controls[i] is TRxDBLookupCombo then (Controls[i] as TRxDBLookupCombo).Value:=findini.ReadString(mysec,TmpName,'') ; end ; end else begin wwDBComboBox18.text:='大于'; wwDBComboBox6.text:='小于'; wwDBComboBox11.text:='小于'; wwDBComboBox19.text:='大于'; wwDBComboBox21.text:='等于'; wwDBComboBox26.text:='等于'; wwDBComboBox24.text:='等于'; wwDBComboBox25.text:='等于'; wwDBComboBox28.text:='等于'; wwDBComboBox29.text:='等于'; wwDBComboBox14.text:='等于'; wwDBComboBox3.text:='等于'; wwDBComboBox38.text:='等于'; wwDBComboBox7.text:='模糊'; wwDBComboBox8.text:='模糊'; wwDBComboBox15.text:='模糊'; wwDBComboBox16.text:='模糊'; wwDBComboBox35.text:='模糊'; wwDBComboBox36.text:='模糊'; wwDBComboBox27.text:='模糊'; wwDBComboBox13.text:='等于'; wwDBComboBox30.text:='等于'; wwDBComboBox41.text:='等于'; wwDBComboBox42.text:='等于'; wwDBComboBox48.text:='等于'; wwDBComboBox33.text:='等于'; wwDBComboBox53.text:='等于'; wwDBComboBox45.text:='等于'; wwDBComboBox43.text:='等于'; wwDBComboBox1.text:='不等于'; wwDBComboBox4.text:='小于'; wwDBComboBox5.text:='大于'; wwDBComboBox17.text:='等于'; wwDBComboBox10.text:='等于'; wwDBComboBox22.text:='等于'; wwDBComboBox52.text:='等于'; wwDBComboBox34.text:='等于'; end ; finally findini.free; end ; end; procedure Tfrm_rp_no_seae_query.writeFindIni; var findini:tinifile ; mysec,tmpname:string; canload:boolean ; //是否记忆 i:integer ; begin canload:=bsSkinCheckRadioBox1.Checked ; mysec:=inttostr(no_seae_query_bs) ; findini:=Tinifile.Create(ExtractFilePath(application.ExeName)+'seaerpnoquery.ini'); try findini.WriteBool(mysec,mysec,canload); if canload then begin with bsSkinGroupBox1 do for i:=0 to ControlCount-1 do begin tmpname:=Controls[i].Name ; if Controls[i] is TwwDBComboBox then findini.WriteString(mysec,TmpName,(Controls[i] as TwwDBComboBox).Text) else if Controls[i] is TEdit then findini.WriteString(mysec,TmpName,(Controls[i] as TEdit).Text) else if Controls[i] is TwwDBDateTimePicker then findini.WriteString(mysec,TmpName,datetostr((Controls[i] as TwwDBDateTimePicker).Date)) else if Controls[i] is TRxDBLookupCombo then findini.writeString(mysec,TmpName,(Controls[i] as TRxDBLookupCombo).Value) ; end ; with bsSkinGroupBox4 do for i:=0 to ControlCount-1 do begin tmpname:=Controls[i].Name ; if Controls[i] is TwwDBComboBox then findini.WriteString(mysec,TmpName,(Controls[i] as TwwDBComboBox).Text) else if Controls[i] is TEdit then findini.WriteString(mysec,TmpName,(Controls[i] as TEdit).Text) else if Controls[i] is TwwDBDateTimePicker then findini.WriteString(mysec,TmpName,datetostr((Controls[i] as TwwDBDateTimePicker).Date)) else if Controls[i] is TRxDBLookupCombo then findini.writeString(mysec,TmpName,(Controls[i] as TRxDBLookupCombo).Value) ; end ; with bsSkinGroupBox2 do for i:=0 to ControlCount-1 do begin tmpname:=Controls[i].Name ; if Controls[i] is TwwDBComboBox then findini.WriteString(mysec,TmpName,(Controls[i] as TwwDBComboBox).Text) else if Controls[i] is TEdit then findini.WriteString(mysec,TmpName,(Controls[i] as TEdit).Text) else if Controls[i] is TwwDBDateTimePicker then findini.WriteString(mysec,TmpName,datetostr((Controls[i] as TwwDBDateTimePicker).Date)) else if Controls[i] is TRxDBLookupCombo then findini.writeString(mysec,TmpName,(Controls[i] as TRxDBLookupCombo).Value) ; end ; end ; finally findini.free; end ; end; procedure Tfrm_rp_no_seae_query.InitmemtableinvData; var corpsname, mblno:string; begin frm_rp_no_total.memtblDetail.EmptyTable; if not frm_rp_no_total.memtblDetail.Active then frm_rp_no_total.memtblDetail.Open; with frm_rp_no_total.ADOQueryINV do begin First; while not eof do begin corpsname:=trim(fieldByName('客户名称').asstring); mblno:=trim(fieldByName('主提单号').asstring); if frm_rp_no_total.memtblDetail.Locate('客户名称;主提单号', VarArrayOf([corpsname, mblno]), []) then begin frm_rp_no_total.memtblDetail.Edit; if trim(fieldByName('USD发票号码').asstring)<>'' then begin frm_rp_no_total.memtblDetail.FieldByName('USD发票号码').Value :=frm_rp_no_total.memtblDetail.FieldByName('USD发票号码').Value+' '+fieldByName('USD发票号码').asstring; frm_rp_no_total.memtblDetail.FieldByName('USD发票金额').Value :=frm_rp_no_total.memtblDetail.FieldByName('USD发票金额').Value+fieldByName('USD发票金额').asFloat; end; if trim(fieldByName('RMB发票号码').asstring)<>'' then begin frm_rp_no_total.memtblDetail.FieldByName('RMB发票号码').Value :=frm_rp_no_total.memtblDetail.FieldByName('RMB发票号码').Value+' '+fieldByName('RMB发票号码').asstring; frm_rp_no_total.memtblDetail.FieldByName('RMB发票金额').Value :=frm_rp_no_total.memtblDetail.FieldByName('RMB发票金额').Value+fieldByName('RMB发票金额').asFloat; frm_rp_no_total.memtblDetail.Post; end end else begin frm_rp_no_total.memtblDetail.Insert; frm_rp_no_total.memtblDetail.FieldByName('客户名称').Value:=fieldByName('客户名称').asstring; frm_rp_no_total.memtblDetail.FieldByName('主提单号').Value:=fieldByName('主提单号').asstring; frm_rp_no_total.memtblDetail.FieldByName('USD发票号码').Value:=fieldByName('USD发票号码').asstring; frm_rp_no_total.memtblDetail.FieldByName('USD发票金额').Value:=fieldByName('USD发票金额').asFloat; frm_rp_no_total.memtblDetail.FieldByName('RMB发票号码').Value:=fieldByName('RMB发票号码').asstring; frm_rp_no_total.memtblDetail.FieldByName('RMB发票金额').Value:=fieldByName('RMB发票金额').asFloat; frm_rp_no_total.memtblDetail.Post; end; next; end; end; end; procedure Tfrm_rp_no_seae_query.noDrShen; var str_bill,str_seae,str_seai,str_aire,str_airi,str_airtruck,str_railway,sqltext,constr,clientstr:widestring; sl:tstrings; DBQueryThread3,DBQueryThread4,DBQueryThread5,DBQueryThread6,DBQueryThread7:TDBQueryThread; W: DWord; H: THandle; begin str_seae:=frm_rp_no_seae_query.get_no_str('t_op_seae.','开船日期'); str_seai:=frm_rp_no_seae_query.get_no_str('t_op_seai.','进口日期'); str_aire:=frm_rp_no_seae_query.get_no_str('t_op_aire.','一程开航日期'); str_airi:=frm_rp_no_seae_query.get_no_str('t_op_airi.','进口日期'); str_airtruck:=frm_rp_no_seae_query.get_no_str('t_op_airtruck.','发车日期'); str_railway:=frm_rp_no_seae_query.get_no_str('t_op_railway.','发车日期'); str_bill:=frm_rp_no_seae_query.get_no_str('v_op_bscard_all.','开船日期'); str_seae:=query_tiaojian(1,str_seae,'t_op_seae.业务类型',wwDBComboBox43.text,wwDBComboBox44.text); str_seai:=query_tiaojian(1,str_seai,'t_op_seai.业务类型',wwDBComboBox43.text,wwDBComboBox44.text); str_aire:=query_tiaojian(1,str_aire,'t_op_aire.业务类型',wwDBComboBox43.text,wwDBComboBox44.text); str_airi:=query_tiaojian(1,str_airi,'t_op_airi.业务类型',wwDBComboBox43.text,wwDBComboBox44.text); str_railway:=query_tiaojian(1,str_railway,'t_op_railway.业务类型',wwDBComboBox43.text,wwDBComboBox44.text); str_airtruck:=query_tiaojian(1,str_airtruck,'t_op_airtruck.业务类型',wwDBComboBox43.text,wwDBComboBox44.text); str_bill:=query_tiaojian(1,str_bill,'v_op_bscard_all.业务种类',wwDBComboBox43.text,wwDBComboBox44.text); if wwDBComboBox2.Text<>'' then begin clientstr:=' left join t_crm_client on t_ch_fee.客户名称=t_crm_client.客户简称 '; end else begin clientstr:=' '; end; if no_seae_query_fee=4 then begin str_seae:=str_seae+' and isnull(DATEDIFF([day],t_op_seae.开船日期, GETDATE())-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)' +' else (case t_crm_client_sales.结费类型 when ''约定时间'' then' +' ( DATEDIFF([day],t_op_seae.开船日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期,t_op_seae.开船日期)))) else 0 end) end),DATEDIFF([day],t_op_seae.开船日期, GETDATE()))>0'; str_seai:=str_seai+' and isnull(DATEDIFF([day],t_op_seai.进口日期, GETDATE())-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)' +' else (case t_crm_client_sales.结费类型 when ''约定时间'' then' +' ( DATEDIFF([day],t_op_seai.进口日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期,t_op_seai.进口日期)))) else 0 end) end),DATEDIFF([day],t_op_seai.进口日期, GETDATE()))>0'; str_aire:=str_aire+' and isnull(DATEDIFF([day],t_op_aire.一程开航日期, GETDATE())-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)' +' else (case t_crm_client_sales.结费类型 when ''约定时间'' then' +' ( DATEDIFF([day],t_op_aire.一程开航日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期,t_op_aire.一程开航日期)))) else 0 end) end),DATEDIFF([day],t_op_aire.一程开航日期, GETDATE()))>0'; str_airi:=str_airi+' and isnull(DATEDIFF([day],t_op_airi.进口日期, GETDATE())-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)' +' else (case t_crm_client_sales.结费类型 when ''约定时间'' then' +' ( DATEDIFF([day],t_op_airi.进口日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期,t_op_airi.进口日期)))) else 0 end) end),DATEDIFF([day],t_op_airi.进口日期, GETDATE()))>0'; str_airtruck:=str_airtruck+' and isnull(DATEDIFF([day],t_op_airtruck.发车日期, GETDATE())-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)' +' else (case t_crm_client_sales.结费类型 when ''约定时间'' then' +' ( DATEDIFF([day],t_op_airtruck.发车日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期,t_op_airtruck.发车日期)))) else 0 end) end),DATEDIFF([day],t_op_airtruck.发车日期, GETDATE()))>0'; str_railway:=str_railway+' and isnull(DATEDIFF([day],t_op_railway.发车日期, GETDATE())-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)' +' else (case t_crm_client_sales.结费类型 when ''约定时间'' then' +' ( DATEDIFF([day],t_op_railway.发车日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期,t_op_railway.发车日期)))) else 0 end) end),DATEDIFF([day],t_op_railway.发车日期, GETDATE()))>0'; end; {$IFDEF NXIANCHENG} frm_rp_no_total.p_pay_bill.close; frm_rp_no_total.p_pay_bill.Connection:=frm_main.db; frm_rp_no_total.p_pay_bill1.DataSet:=frm_rp_no_total.p_pay_bill; frm_rp_no_total.p_pay_bill.Parameters.ParamByName('SQLStr').value:= {$ELSE} sqltext:= {$ENDIF} 'SELECT t_ch_fee.编号, t_ch_fee.客户名称,SUM(case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then t_ch_fee.金额 else 0 end) as 应付USD,' +'SUM(case t_ch_fee.币别 when '+''''+'USD'+''''+' then ' +' (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)' +' else 0 end) as 已付USD,SUM(case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then ' +'(case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)' +' else 0 end) as 未付USD,SUM(case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then 0 else t_ch_fee.金额*t_ch_fee.汇率' +' end) as 应付RMB,SUM(case t_ch_fee.币别' +' when '+''''+'USD'+''''+' then 0 else ' +' (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 ' +' end) as 已付RMB,SUM(case t_ch_fee.币别 when '+''''+'USD'+''''+' then 0' +' else ' +'(case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)' +' end) as 未付RMB,sum(t_ch_fee.金额*t_ch_fee.汇率) as 应付合计,' +' sum((case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率) as 已付合计,' +'sum((case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率) as 未付合计,' +'v_op_bscard_all.业务编号, v_op_bscard_all.会计期间, v_op_bscard_all.主提单号,' +'v_op_bscard_all.分提单号, v_op_bscard_all.委托编号, v_op_bscard_all.装运方式,' +'v_op_bscard_all.委托单位,v_op_bscard_all.收货人,v_op_bscard_all.发货人, v_op_bscard_all.业务类型,v_op_bscard_all.业务状态, v_op_bscard_all.费用状态,v_op_bscard_all.经营单位,' +'v_op_bscard_all.航次, v_op_bscard_all.船名, v_op_bscard_all.开船日期,' +'v_op_bscard_all.装货港, v_op_bscard_all.卸货港, v_op_bscard_all.货物名称, ' +'v_op_bscard_all.件数, v_op_bscard_all.重量, v_op_bscard_all.尺码,' +'v_op_bscard_all.箱型1, v_op_bscard_all.箱型2, v_op_bscard_all.箱型3,' +'v_op_bscard_all.箱型4, v_op_bscard_all.箱型5, v_op_bscard_all.箱型6,' +'v_op_bscard_all.箱型7, v_op_bscard_all.箱型8, v_op_bscard_all.箱型9,' +'v_op_bscard_all.箱型10,v_op_bscard_all.其他箱型,' +'v_op_bscard_all.箱TEU, v_op_bscard_all.集装箱, v_op_bscard_all.操作员,' +'v_op_bscard_all.揽货人, v_op_bscard_all.客服员, v_op_bscard_all.航线,v_op_bscard_all.场站,' +'v_op_bscard_all.船公司, v_op_bscard_all.货代公司, v_op_bscard_all.报关行,v_op_bscard_all.报关单号,v_op_bscard_all.报检单号,v_op_bscard_all.操作部门,v_op_bscard_all.销售部门,' +'(case when round((case when v_op_bscard_all.重量/1000>v_op_bscard_all.尺码 then v_op_bscard_all.重量/1000 ' +'else v_op_bscard_all.尺码 end),4)>1 then ' +'round((case when v_op_bscard_all.重量/1000>v_op_bscard_all.尺码 then v_op_bscard_all.重量/1000 else ' +'v_op_bscard_all.尺码 end),4) else ' +'1 end) as 计费吨' +' FROM t_ch_fee inner join v_op_bscard_all on v_op_bscard_all.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_bill+' and t_ch_fee.类型='+''''+'付'+'''' +s_private +' GROUP BY t_ch_fee.编号, t_ch_fee.客户名称,' +'v_op_bscard_all.业务编号, v_op_bscard_all.会计期间, v_op_bscard_all.主提单号,' +'v_op_bscard_all.分提单号, v_op_bscard_all.委托编号, v_op_bscard_all.装运方式,' +'v_op_bscard_all.委托单位,v_op_bscard_all.收货人,v_op_bscard_all.发货人, v_op_bscard_all.业务类型,v_op_bscard_all.业务状态, v_op_bscard_all.费用状态,v_op_bscard_all.经营单位,' +'v_op_bscard_all.航次, v_op_bscard_all.船名, v_op_bscard_all.开船日期,' +'v_op_bscard_all.装货港, v_op_bscard_all.卸货港, v_op_bscard_all.货物名称,' +'v_op_bscard_all.件数, v_op_bscard_all.重量, v_op_bscard_all.尺码,' +'v_op_bscard_all.箱型1, v_op_bscard_all.箱型2, v_op_bscard_all.箱型3,' +'v_op_bscard_all.箱型4, v_op_bscard_all.箱型5, v_op_bscard_all.箱型6,' +'v_op_bscard_all.箱型7, v_op_bscard_all.箱型8, v_op_bscard_all.箱型9,' +'v_op_bscard_all.箱型10, v_op_bscard_all.其他箱型,' +'v_op_bscard_all.箱TEU, v_op_bscard_all.集装箱, v_op_bscard_all.操作员,' +'v_op_bscard_all.揽货人, v_op_bscard_all.客服员, v_op_bscard_all.航线,v_op_bscard_all.场站,' +'v_op_bscard_all.船公司, v_op_bscard_all.货代公司, v_op_bscard_all.报关行,v_op_bscard_all.报关单号,v_op_bscard_all.报检单号,v_op_bscard_all.操作部门,v_op_bscard_all.销售部门,' +'(case when round((case when v_op_bscard_all.重量/1000>v_op_bscard_all.尺码 then v_op_bscard_all.重量/1000 ' +'else v_op_bscard_all.尺码 end),4)>1 then ' +'round((case when v_op_bscard_all.重量/1000>v_op_bscard_all.尺码 then v_op_bscard_all.重量/1000 else ' +'v_op_bscard_all.尺码 end),4) else ' +'1 end)' +default_sort_two(53,'v_op_bscard_all','t_ch_fee.客户名称','',''); {$IFDEF NXIANCHENG} {$ELSE} constr:=connect_string('main.ini'); frm_rp_no_total.p_pay_bill.ConnectionString:=constr; DBQueryThread3:=TDBQueryThread.Create(frm_rp_no_total.p_pay_bill,sqltext,frm_rp_no_total.p_pay_bill1); {$ENDIF} {$IFDEF NXIANCHENG} frm_rp_no_total.p_pay_fee.close; frm_rp_no_total.p_pay_fee.Connection:=frm_main.db; frm_rp_no_total.p_pay_fee.DataSet:=frm_rp_no_total.p_pay_fee; frm_rp_no_total.p_pay_fee.Parameters.ParamByName('SQLStr').value:= {$ELSE} sqltext:= {$ENDIF} 'SELECT t_ch_fee.编号, t_ch_fee.客户名称, t_ch_fee.费用名称,t_ch_fee.币别,t_ch_fee.金额 as 应付金额,' +' (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end) AS 已付金额,' +'(case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end) as 未付金额,' // +'t_ch_fee.结算金额 as 已付金额,(t_ch_fee.金额-t_ch_fee.结算金额) as 未付金额,' +'t_ch_fee.标准 as 标准,t_ch_fee.单价 as 单价,t_ch_fee.数量 as 数量,t_ch_fee.备注 as 费用备注,' +'v_op_bscard_all.业务编号, v_op_bscard_all.会计期间, v_op_bscard_all.主提单号,' +'v_op_bscard_all.分提单号, v_op_bscard_all.委托编号, v_op_bscard_all.装运方式,' +'v_op_bscard_all.委托单位,v_op_bscard_all.收货人,v_op_bscard_all.发货人, v_op_bscard_all.业务类型,v_op_bscard_all.业务状态, v_op_bscard_all.费用状态,v_op_bscard_all.经营单位,' +'v_op_bscard_all.航次, v_op_bscard_all.船名, v_op_bscard_all.开船日期,' +'v_op_bscard_all.装货港, v_op_bscard_all.卸货港, v_op_bscard_all.货物名称, ' +'v_op_bscard_all.件数, v_op_bscard_all.重量, v_op_bscard_all.尺码,' +'v_op_bscard_all.箱型1, v_op_bscard_all.箱型2, v_op_bscard_all.箱型3,' +'v_op_bscard_all.箱型4, v_op_bscard_all.箱型5, v_op_bscard_all.箱型6,' +'v_op_bscard_all.箱型7, v_op_bscard_all.箱型8, v_op_bscard_all.箱型9,' +'v_op_bscard_all.箱型10, v_op_bscard_all.其他箱型,' +'v_op_bscard_all.箱TEU, v_op_bscard_all.集装箱, v_op_bscard_all.操作员,' +'v_op_bscard_all.揽货人, v_op_bscard_all.客服员, v_op_bscard_all.航线,v_op_bscard_all.场站,' +'v_op_bscard_all.船公司, v_op_bscard_all.货代公司, v_op_bscard_all.报关行,v_op_bscard_all.报关单号,v_op_bscard_all.报检单号,v_op_bscard_all.操作部门,v_op_bscard_all.销售部门,' +'(case when round((case when v_op_bscard_all.重量/1000>v_op_bscard_all.尺码 then v_op_bscard_all.重量/1000 ' +'else v_op_bscard_all.尺码 end),4)>1 then ' +'round((case when v_op_bscard_all.重量/1000>v_op_bscard_all.尺码 then v_op_bscard_all.重量/1000 else ' +'v_op_bscard_all.尺码 end),4) else ' +'1 end) as 计费吨' +' FROM t_ch_fee inner join v_op_bscard_all on v_op_bscard_all.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_bill+' and t_ch_fee.类型='+''''+'付'+'''' +s_private +default_sort_two(53,'v_op_bscard_all','t_ch_fee.客户名称','',''); {$IFDEF NXIANCHENG} frm_rp_no_total.p_pay_fee.Open; {$ELSE} frm_rp_no_total.p_pay_fee.ConnectionString:=constr; DBQueryThread4:=TDBQueryThread.Create(frm_rp_no_total.p_pay_fee,sqltext,frm_rp_no_total.p_pay_fee1); {$ENDIF} {$IFDEF NXIANCHENG} frm_rp_no_total.p_total_client.close; frm_rp_no_total.p_total_client.Connection:=frm_main.db; frm_rp_no_total.p_total_client.DataSet:=frm_rp_no_total.p_total_client; frm_rp_no_total.p_total_client.Parameters.ParamByName('SQLStr').value:= {$ELSE} sqltext:= {$ENDIF} 'SELECT '+''''+'海运出口'+''''+' as 业务种类 ,t_ch_fee.客户名称,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 已收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 未收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)' +' else 0 end) ELSE 0 END) as 已付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)' +' else 0 end) ELSE 0 END) as 未付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB, ' // +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' end) ELSE 0 END) as 未付RMB,' // +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 ELSE 0 END) as 已付合计, ' // +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' ELSE 0 END) as 未付合计,' // +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 差额USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 差额RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*汇率 ELSE 0 END) as 差额合计' +' FROM t_ch_fee inner join t_op_seae on t_op_seae.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_seae +s_private +' GROUP BY t_ch_fee.客户名称 ' +' union SELECT '+''''+'海运进口'+''''+' as 业务种类 ,t_ch_fee.客户名称,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 已收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 未收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)' +' else 0 end) ELSE 0 END) as 已付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)' +' else 0 end) ELSE 0 END) as 未付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB, ' // +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' end) ELSE 0 END) as 未付RMB,' // +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 ELSE 0 END) as 已付合计, ' // +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' ELSE 0 END) as 未付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 差额USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 差额RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*汇率 ELSE 0 END) as 差额合计' +' FROM t_ch_fee inner join t_op_seai on t_op_seai.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_seai +s_private +' GROUP BY t_ch_fee.客户名称 ' +' union SELECT '+''''+'空运出口'+''''+' as 业务种类 ,t_ch_fee.客户名称,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 已收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 未收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)' +' else 0 end) ELSE 0 END) as 已付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)' +' else 0 end) ELSE 0 END) as 未付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB, ' // +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' end) ELSE 0 END) as 未付RMB,' // +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 ELSE 0 END) as 已付合计, ' // +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' ELSE 0 END) as 未付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 差额USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 差额RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*汇率 ELSE 0 END) as 差额合计' +' FROM t_ch_fee inner join t_op_aire on t_op_aire.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_aire +s_private +' GROUP BY t_ch_fee.客户名称 ' +' union SELECT '+''''+'空运进口'+''''+' as 业务种类 ,t_ch_fee.客户名称,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 已收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 未收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)' +' else 0 end) ELSE 0 END) as 已付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)' +' else 0 end) ELSE 0 END) as 未付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB, ' // +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' end) ELSE 0 END) as 未付RMB,' // +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 ELSE 0 END) as 已付合计, ' // +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' ELSE 0 END) as 未付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 差额USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 差额RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*汇率 ELSE 0 END) as 差额合计' +' FROM t_ch_fee inner join t_op_airi on t_op_airi.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_airi +s_private +' GROUP BY t_ch_fee.客户名称 ' +' union SELECT '+''''+'铁路运输'+''''+' as 业务种类 ,t_ch_fee.客户名称,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 已收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 未收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)' +' else 0 end) ELSE 0 END) as 已付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)' +' else 0 end) ELSE 0 END) as 未付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB, ' // +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' end) ELSE 0 END) as 未付RMB,' // +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 ELSE 0 END) as 已付合计, ' // +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' ELSE 0 END) as 未付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 差额USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 差额RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*汇率 ELSE 0 END) as 差额合计' +' FROM t_ch_fee inner join t_op_railway on t_op_railway.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_railway +s_private +' GROUP BY t_ch_fee.客户名称 ' +' union SELECT '+''''+'监管车'+''''+' as 业务种类 ,t_ch_fee.客户名称,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 已收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 未收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)' +' else 0 end) ELSE 0 END) as 已付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)' +' else 0 end) ELSE 0 END) as 未付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB, ' // +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' end) ELSE 0 END) as 未付RMB,' // +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 ELSE 0 END) as 已付合计, ' // +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' ELSE 0 END) as 未付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 差额USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 差额RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*汇率 ELSE 0 END) as 差额合计' +' FROM t_ch_fee inner join t_op_airtruck on t_op_airtruck.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_airtruck +s_private +' GROUP BY t_ch_fee.客户名称 '; {$IFDEF NXIANCHENG} frm_rp_no_total.p_total_client.Open; {$ELSE} frm_rp_no_total.p_total_client.ConnectionString:=constr; DBQueryThread5:=TDBQueryThread.Create(frm_rp_no_total.p_total_client,sqltext,frm_rp_no_total.p_total_client1); {$ENDIF} {$IFDEF NXIANCHENG} frm_rp_no_total.p_total_sales.close; frm_rp_no_total.p_total_sales.Parameters.ParamByName('SQLStr').value:= {$ELSE} sqltext:= {$ENDIF} 'SELECT '+''''+'海运出口'+''''+' as 业务种类 ,t_op_seae.揽货人,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 已收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 未收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)' +' else 0 end) ELSE 0 END) as 已付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)' +' else 0 end) ELSE 0 END) as 未付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB, ' // +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' end) ELSE 0 END) as 未付RMB,' // +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 ELSE 0 END) as 已付合计, ' // +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' ELSE 0 END) as 未付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 差额USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 差额RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*汇率 ELSE 0 END) as 差额合计' +' FROM t_ch_fee inner join t_op_seae on t_op_seae.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_seae +s_private +' GROUP BY t_op_seae.揽货人 ' +' union SELECT '+''''+'海运进口'+''''+' as 业务种类 ,t_op_seai.揽货人,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 已收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 未收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)' +' else 0 end) ELSE 0 END) as 已付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)' +' else 0 end) ELSE 0 END) as 未付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB, ' // +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' end) ELSE 0 END) as 未付RMB,' // +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 ELSE 0 END) as 已付合计, ' // +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' ELSE 0 END) as 未付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 差额USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 差额RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*汇率 ELSE 0 END) as 差额合计' +' FROM t_ch_fee inner join t_op_seai on t_op_seai.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_seai +s_private +' GROUP BY t_op_seai.揽货人 ' +' union SELECT '+''''+'空运出口'+''''+' as 业务种类 ,t_op_aire.揽货人,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 已收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 未收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)' +' else 0 end) ELSE 0 END) as 已付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)' +' else 0 end) ELSE 0 END) as 未付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB, ' // +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' end) ELSE 0 END) as 未付RMB,' // +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 ELSE 0 END) as 已付合计, ' // +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' ELSE 0 END) as 未付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 差额USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 差额RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*汇率 ELSE 0 END) as 差额合计' +' FROM t_ch_fee inner join t_op_aire on t_op_aire.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_aire +s_private +' GROUP BY t_op_aire.揽货人 ' +' union SELECT '+''''+'空运进口'+''''+' as 业务种类 ,t_op_airi.揽货人,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 已收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 未收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)' +' else 0 end) ELSE 0 END) as 已付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)' +' else 0 end) ELSE 0 END) as 未付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB, ' // +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' end) ELSE 0 END) as 未付RMB,' // +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 ELSE 0 END) as 已付合计, ' // +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' ELSE 0 END) as 未付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 差额USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 差额RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*汇率 ELSE 0 END) as 差额合计' +' FROM t_ch_fee inner join t_op_airi on t_op_airi.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_airi +s_private +' GROUP BY t_op_airi.揽货人 ' +' union SELECT '+''''+'铁路运输'+''''+' as 业务种类 ,t_op_railway.揽货人,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 已收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 未收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)' +' else 0 end) ELSE 0 END) as 已付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)' +' else 0 end) ELSE 0 END) as 未付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB, ' // +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' end) ELSE 0 END) as 未付RMB,' // +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 ELSE 0 END) as 已付合计, ' // +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' ELSE 0 END) as 未付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 差额USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 差额RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*汇率 ELSE 0 END) as 差额合计' +' FROM t_ch_fee inner join t_op_railway on t_op_railway.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_railway +s_private +' GROUP BY t_op_railway.揽货人 ' +' union SELECT '+''''+'监管车'+''''+' as 业务种类 ,t_op_airtruck.揽货人,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 已收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 未收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)' +' else 0 end) ELSE 0 END) as 已付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)' +' else 0 end) ELSE 0 END) as 未付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB, ' // +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' end) ELSE 0 END) as 未付RMB,' // +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 ELSE 0 END) as 已付合计, ' // +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' ELSE 0 END) as 未付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 差额USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 差额RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*汇率 ELSE 0 END) as 差额合计' +' FROM t_ch_fee inner join t_op_airtruck on t_op_airtruck.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_airtruck +s_private +' GROUP BY t_op_airtruck.揽货人 '; {$IFDEF NXIANCHENG} frm_rp_no_total.p_total_sales.Open; {$ELSE} frm_rp_no_total.p_total_sales.ConnectionString:=constr; DBQueryThread6:=TDBQueryThread.Create(frm_rp_no_total.p_total_sales,sqltext,frm_rp_no_total.p_total_sales1); {$ENDIF} frm_rp_no_total.p_total.close; frm_rp_no_total.p_total.Parameters.ParamByName('SQLStr').value:= // sqltext:= 'SELECT '+''''+'海运出口'+''''+' as 业务种类 ,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 已收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 未收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)' +' else 0 end) ELSE 0 END) as 已付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)' +' else 0 end) ELSE 0 END) as 未付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB, ' // +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' end) ELSE 0 END) as 未付RMB,' // +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 ELSE 0 END) as 已付合计, ' // +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' ELSE 0 END) as 未付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 差额USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 差额RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*汇率 ELSE 0 END) as 差额合计' +' FROM t_ch_fee inner join t_op_seae on t_op_seae.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_seae +s_private +' union SELECT '+''''+'海运进口'+''''+' as 业务种类 ,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 已收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 未收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)' +' else 0 end) ELSE 0 END) as 已付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)' +' else 0 end) ELSE 0 END) as 未付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB, ' // +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' end) ELSE 0 END) as 未付RMB,' // +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 ELSE 0 END) as 已付合计, ' // +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' ELSE 0 END) as 未付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 差额USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 差额RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*汇率 ELSE 0 END) as 差额合计' +' FROM t_ch_fee inner join t_op_seai on t_op_seai.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_seai +s_private +' union SELECT '+''''+'空运出口'+''''+' as 业务种类 ,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 已收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 未收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)' +' else 0 end) ELSE 0 END) as 已付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)' +' else 0 end) ELSE 0 END) as 未付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB, ' // +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' end) ELSE 0 END) as 未付RMB,' // +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 ELSE 0 END) as 已付合计, ' // +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' ELSE 0 END) as 未付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 差额USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 差额RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*汇率 ELSE 0 END) as 差额合计' +' FROM t_ch_fee inner join t_op_aire on t_op_aire.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_aire +s_private +' union SELECT '+''''+'空运进口'+''''+' as 业务种类 ,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 已收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 未收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)' +' else 0 end) ELSE 0 END) as 已付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)' +' else 0 end) ELSE 0 END) as 未付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB, ' // +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' end) ELSE 0 END) as 未付RMB,' // +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 ELSE 0 END) as 已付合计, ' // +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' ELSE 0 END) as 未付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 差额USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 差额RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*汇率 ELSE 0 END) as 差额合计' +' FROM t_ch_fee inner join t_op_airi on t_op_airi.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_airi +s_private +' union SELECT '+''''+'铁路运输'+''''+' as 业务种类 ,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 已收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 未收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)' +' else 0 end) ELSE 0 END) as 已付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)' +' else 0 end) ELSE 0 END) as 未付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB, ' // +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' end) ELSE 0 END) as 未付RMB,' // +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 ELSE 0 END) as 已付合计, ' // +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' ELSE 0 END) as 未付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 差额USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 差额RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*汇率 ELSE 0 END) as 差额合计' +' FROM t_ch_fee inner join t_op_railway on t_op_railway.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_railway +s_private +' union SELECT '+''''+'监管车'+''''+' as 业务种类 ,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 已收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 未收USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未收RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END) as 未收合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额 else 0 end) ELSE 0 END) as 应付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)' +' else 0 end) ELSE 0 END) as 已付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)' +' else 0 end) ELSE 0 END) as 未付USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else t_ch_fee.金额*t_ch_fee.汇率 end) ELSE 0 END) as 应付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB, ' // +' then 0 else t_ch_fee.结算金额*t_ch_fee.汇率 end) ELSE 0 END) as 已付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' end) ELSE 0 END) as 未付RMB,' // +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 未付RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN t_ch_fee.金额*t_ch_fee.汇率 ELSE 0 END) as 应付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 THEN t_ch_fee.结算金额 ' +'ELSE t_ch_fee.开票金额 end) else (CASE WHEN t_ch_fee.结算金额>t_ch_fee.开票金额 ' +'THEN t_ch_fee.开票金额 ELSE t_ch_fee.结算金额 end) end)*t_ch_fee.汇率 ELSE 0 END) as 已付合计, ' // +' THEN t_ch_fee.结算金额*t_ch_fee.汇率 ELSE 0 END) as 已付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' then (case when t_ch_fee.金额>0 then ' +'(CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) THEN (t_ch_fee.金额-t_ch_fee.开票金额) ' +'ELSE (t_ch_fee.金额-t_ch_fee.结算金额) end) else (CASE WHEN (t_ch_fee.金额-t_ch_fee.结算金额)>(t_ch_fee.金额-t_ch_fee.开票金额) ' +'THEN (t_ch_fee.金额-t_ch_fee.结算金额) ELSE (t_ch_fee.金额-t_ch_fee.开票金额) end) end)*t_ch_fee.汇率' +' ELSE 0 END) as 未付合计,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then t_ch_fee.金额-t_ch_fee.结算金额 else 0 end) ELSE 0 END) as 差额USD,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (case t_ch_fee.币别 when '+''''+'USD'+'''' +' then 0 else (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 end) ELSE 0 END) as 差额RMB,' +'SUM(CASE t_ch_fee.类型 WHEN '+''''+'收'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*t_ch_fee.汇率 ELSE 0 END' +'-CASE t_ch_fee.类型 WHEN '+''''+'付'+'''' +' THEN (t_ch_fee.金额-t_ch_fee.结算金额)*汇率 ELSE 0 END) as 差额合计' +' FROM t_ch_fee inner join t_op_airtruck on t_op_airtruck.编号=t_ch_fee.编号 ' +' left join t_crm_client_sales on t_ch_fee.客户名称=t_crm_client_sales.客户简称 ' +clientstr +str_airtruck +s_private ; frm_rp_no_total.p_total.Open; // frm_rp_no_total.p_total_client.Sort:='客户名称,业务种类'; // frm_rp_no_total.p_total_sales.Sort:='揽货人,业务种类'; // frm_rp_no_total.p_total.ConnectionString:=constr; // DBQueryThread7:=TDBQueryThread.Create(frm_rp_no_total.p_total,sqltext,frm_rp_no_total.p_total1); end; { TDBQueryThread } { procedure TDBQueryThread.ConnectDB; begin try if ADOConnection=nil then begin ADOConnection:=TADOConnection.Create(nil); ADOConnection.LoginPrompt:=False; ADOConnection.ConnectionString:=frm_main.db.ConnectionString; end; if ADOConnection.Connected then exit; ADOConnection.Open; except Self.Terminate; end; end; } procedure Tfrm_rp_no_seae_query.FormClose(Sender: TObject; var Action: TCloseAction); begin Action:=caFree; end; procedure Tfrm_rp_no_seae_query.bsSkinButton2Click(Sender: TObject); begin if RxDBLookupCombo14.DisplayValue='' then begin showmessage('请输入条件名称!!'); exit; end; if wwDBComboBox47.ItemIndex=-1 then begin showmessage('请输入条件关系!!'); exit; end; if wwDBComboBox50.ItemIndex=-1 then begin showmessage('请输入查询类型!!'); exit; end; if query_str_int.Visible then begin if query_str_int.text='' then begin showmessage('请输入条件值!!'); exit; end; if (t_sys_queryfields.FieldByName('类型').asstring='int') then begin try strtoint(query_str_int.text); except showmessage('条件值只能输入数字!!'); exit; end; end; end; if query_bit.Visible then begin if query_bit.ItemIndex=-1 then begin showmessage('请输入条件值!!'); exit; end; end; if query_date.Visible then begin if query_date.text='' then begin showmessage('请输入条件值!!'); exit; end; end; if t_sys_query.IsEmpty then begin t_sys_query.Insert; t_sys_query.post; end; t_sys_query_detail.Append; t_sys_query_detail['表']:=t_sys_queryfields['表']; t_sys_query_detail['字段名']:=t_sys_queryfields['字段名称']; if query_str_int.Visible then begin t_sys_query_detail['条件值']:=query_str_int.text; end; if query_bit.Visible then begin t_sys_query_detail['条件值']:=query_bit.text; end; if query_date.Visible then begin t_sys_query_detail['条件值']:=query_date.text; end; t_sys_query_detail['字段类型']:=t_sys_queryfields['类型']; t_sys_query_detail['条件关系']:=wwDBComboBox47.text; t_sys_query_detail['查询类型']:=wwDBComboBox50.text; t_sys_query_detail.post; end; procedure Tfrm_rp_no_seae_query.bsSkinButton4Click(Sender: TObject); begin if not t_sys_query_detail.IsEmpty then t_sys_query_detail.Delete; end; procedure Tfrm_rp_no_seae_query.bsSkinButton6Click(Sender: TObject); begin t_sys_query.Insert; t_sys_query.post; end; procedure Tfrm_rp_no_seae_query.bsSkinButton9Click(Sender: TObject); begin while not t_sys_query_detail.eof do begin t_sys_query_detail.Delete; end; if not t_sys_query.Eof then t_sys_query.delete; end; procedure Tfrm_rp_no_seae_query.RxDBLookupCombo14Change(Sender: TObject); begin query_str_int.text:=''; query_bit.text:=''; query_date.text:=''; if t_sys_queryfields.Locate('字段名称',RxDBLookupCombo14.DisplayValue,[])then begin wwDBComboBox50.ItemIndex:=-1; wwDBComboBox50.Items.Clear; if (t_sys_queryfields.FieldByName('类型').asstring='varchar') then begin query_str_int.Visible:=true; query_bit.Visible:=false; query_date.Visible:=false; wwDBComboBox50.Items.Add('等于'); wwDBComboBox50.Items.Add('不等于'); wwDBComboBox50.Items.Add('模糊'); wwDBComboBox50.ItemIndex:=2; end; if (t_sys_queryfields.FieldByName('类型').asstring='int') then begin query_str_int.Visible:=true; query_bit.Visible:=false; query_date.Visible:=false; wwDBComboBox50.Items.Add('等于'); wwDBComboBox50.Items.Add('不等于'); wwDBComboBox50.Items.Add('大于'); wwDBComboBox50.Items.Add('小于'); wwDBComboBox50.ItemIndex:=0; end; if (t_sys_queryfields.FieldByName('类型').asstring='bit') then begin query_str_int.Visible:=false; query_bit.Visible:=true; query_date.Visible:=false; wwDBComboBox50.Items.Add('等于'); wwDBComboBox50.Items.Add('不等于'); wwDBComboBox50.ItemIndex:=0; end; if (t_sys_queryfields.FieldByName('类型').asstring='date') then begin query_str_int.Visible:=false; query_bit.Visible:=false; query_date.Visible:=true; wwDBComboBox50.Items.Add('等于'); wwDBComboBox50.Items.Add('不等于'); wwDBComboBox50.Items.Add('大于'); wwDBComboBox50.Items.Add('小于'); wwDBComboBox50.ItemIndex:=0; end; end else begin query_str_int.Visible:=false; query_bit.Visible:=false; query_date.Visible:=false; end; end; procedure Tfrm_rp_no_seae_query.t_sys_queryAfterInsert(DataSet: TDataSet); begin t_sys_query['查询类型']:=rp_seae_query_str; t_sys_query['录入人']:=employee; t_sys_query['录入日期']:=date; end; procedure Tfrm_rp_no_seae_query.t_sys_query_detailAfterScroll( DataSet: TDataSet); begin if (t_sys_query_detail.fieldbyname('字段类型').asstring='varchar') then begin dxDBGrid1Column3.Items.Clear; dxDBGrid1Column3.Items.Add('等于'); dxDBGrid1Column3.Items.Add('不等于'); dxDBGrid1Column3.Items.Add('模糊'); dxDBGrid1Column3.Items.Add('大于'); dxDBGrid1Column3.Items.Add('小于'); end; if (t_sys_query_detail.fieldbyname('字段类型').asstring='int') then begin dxDBGrid1Column3.Items.Clear; dxDBGrid1Column3.Items.Add('等于'); dxDBGrid1Column3.Items.Add('不等于'); dxDBGrid1Column3.Items.Add('大于'); dxDBGrid1Column3.Items.Add('小于'); end; if (t_sys_query_detail.fieldbyname('字段类型').asstring='bit') then begin dxDBGrid1Column3.Items.Clear; dxDBGrid1Column3.Items.Add('等于'); dxDBGrid1Column3.Items.Add('不等于'); end; if (t_sys_query_detail.fieldbyname('字段类型').asstring='date') then begin dxDBGrid1Column3.Items.Clear; dxDBGrid1Column3.Items.Add('等于'); dxDBGrid1Column3.Items.Add('不等于'); dxDBGrid1Column3.Items.Add('大于'); dxDBGrid1Column3.Items.Add('小于'); end; end; procedure Tfrm_rp_no_seae_query.t_sys_query_detailBeforePost( DataSet: TDataSet); begin if t_sys_query_detail.fieldbyname('字段类型').asstring='int' then begin try strtoint(t_sys_query_detail.fieldbyname('条件值').asstring); except showmessage('条件值只能输入数字!!'); abort; end; end; if t_sys_query_detail.fieldbyname('字段类型').asstring='date' then begin try strtodate(t_sys_query_detail.fieldbyname('条件值').asstring); except showmessage('条件值只能输入日期!!'); abort; end; end; if t_sys_query_detail.fieldbyname('字段类型').asstring='bit' then begin if (t_sys_query_detail.fieldbyname('条件值').asstring<>'否') and(t_sys_query_detail.fieldbyname('条件值').asstring<>'是')then begin showmessage('条件值只能输入是\否!!'); abort; end; end; if (t_sys_query_detail.fieldbyname('条件关系').asstring<>'且') and(t_sys_query_detail.fieldbyname('条件关系').asstring<>'或')then begin showmessage('条件关系只能输入且\或!!'); abort; end; if (dxDBGrid1Column3.Items.IndexOf(t_sys_query_detail.fieldbyname('查询类型').asstring)=-1) and (t_sys_query_detail.state<>dsinsert) then begin showmessage('查询类型只能输入'+dxDBGrid1Column3.Items.text+'!!'); abort; end; end; end.