unit u_rp_zj_aire; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, dxExEdtr, DB, ADODB, StdCtrls, wwdbdatetimepicker, bsSkinCtrls, dxTL, dxDBCtrl, dxDBGrid, dxCntner, ComCtrls, bsSkinTabs, ExtCtrls; type Tfrm_rp_zj_aire = class(TForm) Panel1: TPanel; bsSkinPageControl1: TbsSkinPageControl; bsSkinTabSheet1: TbsSkinTabSheet; dxDBGrid1: TdxDBGrid; dxDBGrid1Column1: TdxDBGridColumn; dxDBGrid1Column2: TdxDBGridColumn; dxDBGrid1Column3: TdxDBGridColumn; dxDBGrid1Column11: TdxDBGridColumn; dxDBGrid1Column8: TdxDBGridColumn; dxDBGrid1Column9: TdxDBGridColumn; dxDBGrid1Column4: TdxDBGridColumn; dxDBGrid1Column5: TdxDBGridColumn; dxDBGrid1Column6: TdxDBGridColumn; dxDBGrid1Column7: TdxDBGridColumn; dxDBGrid1Column10: TdxDBGridColumn; bsSkinTabSheet2: TbsSkinTabSheet; dxDBGrid2: TdxDBGrid; dxDBGridColumn1: TdxDBGridColumn; dxDBGridColumn2: TdxDBGridColumn; dxDBGridColumn3: TdxDBGridColumn; dxDBGrid2Column11: TdxDBGridColumn; dxDBGridColumn4: TdxDBGridColumn; dxDBGridColumn5: TdxDBGridColumn; dxDBGridColumn6: TdxDBGridColumn; dxDBGridColumn7: TdxDBGridColumn; dxDBGridColumn8: TdxDBGridColumn; dxDBGridColumn9: TdxDBGridColumn; dxDBGrid2Column10: TdxDBGridColumn; dxDBGrid3: TdxDBGrid; dxDBGridColumn11: TdxDBGridColumn; dxDBGridColumn12: TdxDBGridColumn; dxDBGridColumn13: TdxDBGridColumn; dxDBGridColumn14: TdxDBGridColumn; dxDBGridColumn15: TdxDBGridColumn; dxDBGridColumn16: TdxDBGridColumn; dxDBGridColumn17: TdxDBGridColumn; dxDBGridColumn18: TdxDBGridColumn; dxDBGridColumn19: TdxDBGridColumn; dxDBGridColumn20: TdxDBGridColumn; bsSkinPanel2: TbsSkinPanel; bsSkinButton10: TbsSkinButton; bsSkinButton9: TbsSkinButton; bsSkinButton5: TbsSkinButton; bsSkinCheckRadioBox2: TbsSkinCheckRadioBox; bsSkinCheckRadioBox1: TbsSkinCheckRadioBox; bsSkinPanel1: TbsSkinPanel; Label1: TLabel; Label2: TLabel; wwDBDateTimePicker1: TwwDBDateTimePicker; wwDBDateTimePicker2: TwwDBDateTimePicker; p_client: TADOStoredProc; p_client1: TDataSource; p_shen: TADOStoredProc; p_shen1: TDataSource; p_total: TADOStoredProc; p_total1: TDataSource; procedure bsSkinButton10Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure bsSkinButton5Click(Sender: TObject); procedure bsSkinButton9Click(Sender: TObject); procedure bsSkinPanel2Resize(Sender: TObject); procedure dxDBGrid1ColumnSorting(Sender: TObject; Column: TdxDBTreeListColumn; var Allow: Boolean); procedure dxDBGrid2ColumnSorting(Sender: TObject; Column: TdxDBTreeListColumn; var Allow: Boolean); private { Private declarations } public { Public declarations } end; var frm_rp_zj_aire: Tfrm_rp_zj_aire; implementation uses u_main, my_sys_function; {$R *.dfm} procedure Tfrm_rp_zj_aire.bsSkinButton10Click(Sender: TObject); var str,str_date:widestring; str_date_tongji:string; begin if bsSkinCheckRadioBox1.Checked then str_date_tongji:='会计期间' else str_date_tongji:='一程开航日期'; str:='where '+open_data('0036','t_op_aire.操作员','t_op_aire.揽货人','t_op_aire.客服员','no','no'); if wwDBDateTimePicker1.text<>''then begin str:=str+' and t_op_aire.'+str_date_tongji+'>='+''''+wwDBDateTimePicker1.text+''''; str_date:=' where t_op_aire.'+str_date_tongji+'>='+''''+wwDBDateTimePicker1.text+''''; end; if wwDBDateTimePicker2.text<>''then begin str:=str+' and t_op_aire.'+str_date_tongji+'<='+''''+wwDBDateTimePicker2.text+''''; if str_date='' then str_date:=' where t_op_aire.'+str_date_tongji+'<='+''''+wwDBDateTimePicker2.text+'''' else str_date:=str_date+' and t_op_aire.'+str_date_tongji+'<='+''''+wwDBDateTimePicker2.text+''''; end; p_client.close; p_client.Parameters.ParamByName('SQLStr').value:= 'DECLARE @all_pay numeric ' +'select @all_pay=isnull((select sum(t_op_gain.合计应付) from t_op_gain' +' where t_op_gain.编号 in (select t_op_aire.编号 from t_op_aire '+str_date+')),0) ' +'SELECT t_op_aire.委托单位,' +'sum(t_op_gain.毛利润) as 毛利润,' +'(case when isnull(sum(t_op_gain.合计应付),0)=0 then '+''''+'无法计算'+''''+' else ' +'ltrim(str(sum(t_op_gain.毛利润)/sum(t_op_gain.合计应付)*100,10,2))+'+''''+'%'+''''+' end) as 利润率, ' +'sum(t_op_gain.合计应付) as 资金占用量,' +'(case when @all_pay=0 then '+''''+'无法计算'+''''+' else ' +'(ltrim(str(sum(t_op_gain.合计应付)/@all_pay*100,10,2))+'+''''+'%'+''''+') end) as 资金占用率,isnull(sum(t_op_gain.合计应收),0) as 合计应收 ' +'INTO #bill ' +'FROM t_op_gain inner join t_op_aire on t_op_gain.编号 = t_op_aire.编号 ' +str +' group by t_op_aire.委托单位 ' +'SELECT t_op_aire.委托单位, ' +'SUM(CASE WHEN DATEDIFF([day], t_op_aire.'+str_date_tongji+', ' +'t_ch_balance.结算日期) ' +'<= 30 THEN t_ch_fee_do.原始金额 * t_ch_fee.汇率 ELSE 0 END) AS 当月回收, ' +'SUM(CASE WHEN DATEDIFF([day], t_op_aire.'+str_date_tongji+', ' +'t_ch_balance.结算日期) ' +'> 30 and DATEDIFF([day], t_op_aire.'+str_date_tongji+', ' +'t_ch_balance.结算日期)<=60 THEN t_ch_fee_do.原始金额 * t_ch_fee.汇率 ELSE 0 END) AS 二月回收, ' +'SUM(CASE WHEN DATEDIFF([day], t_op_aire.'+str_date_tongji+', ' +'t_ch_balance.结算日期) ' +'> 60 and DATEDIFF([day], t_op_aire.'+str_date_tongji+',' +'t_ch_balance.结算日期)<=90 THEN t_ch_fee_do.原始金额 * t_ch_fee.汇率 ELSE 0 END) AS 三月回收, ' +'SUM(CASE WHEN DATEDIFF([day], t_op_aire.'+str_date_tongji+', ' +'t_ch_balance.结算日期) ' +'> 90 THEN t_ch_fee_do.原始金额 * t_ch_fee.汇率 ELSE 0 END) AS 其他回收 ' +'INTO #fee ' +'FROM t_ch_fee_do inner JOIN t_op_aire on t_ch_fee_do.业务编号=t_op_aire.编号 inner JOIN ' +'t_ch_balance ON ' +'t_ch_fee_do.工作编号 = t_ch_balance.帐单编号 inner JOIN ' +'t_ch_fee ON t_ch_fee_do.CH_ID = t_ch_fee.CH_ID ' +str +' and t_ch_fee_do.类型='+''''+'3'+'''' +' group by t_op_aire.委托单位 ' +'select #bill.委托单位,#bill.毛利润,#bill.利润率,#bill.资金占用量,#bill.资金占用率, ' +'(case when #bill.合计应收=0 then '+''''+'无法计算'+'''' +' else ltrim(str(#fee.当月回收/#bill.合计应收*100,10,2))+'+''''+'%'+''''+' end) as 当月回收率,' +'(case when #bill.合计应收=0 then '+''''+'无法计算'+'''' +' else ltrim(str(#fee.二月回收/#bill.合计应收*100,10,2))+'+''''+'%'+''''+' end) as 二月回收率,' +'(case when #bill.合计应收=0 then '+''''+'无法计算'+'''' +' else ltrim(str(#fee.三月回收/#bill.合计应收*100,10,2))+'+''''+'%'+''''+' end) as 三月回收率,' +'(case when #bill.合计应收=0 then '+''''+'无法计算'+'''' +' else ltrim(str(#fee.其他回收/#bill.合计应收*100,10,2))+'+''''+'%'+''''+' end) as 其他回收率 ,' +'(case when #bill.合计应收=0 then '+''''+'无法计算'+'''' +' else ltrim(str((#fee.其他回收+#fee.当月回收+#fee.二月回收+#fee.三月回收)/#bill.合计应收*100,10,2))+' +''''+'%'+''''+' end) as 合计回收率 ,#bill.合计应收 ' +'from #bill left join #fee on #bill.委托单位=#fee.委托单位 ' +'order by #bill.委托单位 '; p_client.open; p_shen.close; p_shen.Parameters.ParamByName('SQLStr').value:= 'DECLARE @all_pay numeric ' +'select @all_pay=isnull((select sum(t_op_gain.合计应付) from t_op_gain' +' where t_op_gain.编号 in (select t_op_aire.编号 from t_op_aire '+str_date+')),0) ' +'SELECT t_op_aire.揽货人,' +'sum(t_op_gain.毛利润) as 毛利润,' +'(case when isnull(sum(t_op_gain.合计应付),0)=0 then '+''''+'无法计算'+''''+' else ' +'ltrim(str(sum(t_op_gain.毛利润)/sum(t_op_gain.合计应付)*100,10,2))+'+''''+'%'+''''+' end) as 利润率, ' +'sum(t_op_gain.合计应付) as 资金占用量,' +'(case when @all_pay=0 then '+''''+'无法计算'+''''+' else ' +'(ltrim(str(sum(t_op_gain.合计应付)/@all_pay*100,10,2))+'+''''+'%'+''''+') end) as 资金占用率,isnull(sum(t_op_gain.合计应收),0) as 合计应收 ' +'INTO #bill ' +'FROM t_op_gain inner join t_op_aire on t_op_gain.编号 = t_op_aire.编号 ' +str +' group by t_op_aire.揽货人 ' +'SELECT t_op_aire.揽货人, ' +'SUM(CASE WHEN DATEDIFF([day], t_op_aire.'+str_date_tongji+', ' +'t_ch_balance.结算日期) ' +'<= 30 THEN t_ch_fee_do.原始金额 * t_ch_fee.汇率 ELSE 0 END) AS 当月回收, ' +'SUM(CASE WHEN DATEDIFF([day], t_op_aire.'+str_date_tongji+', ' +'t_ch_balance.结算日期) ' +'> 30 and DATEDIFF([day], t_op_aire.'+str_date_tongji+', ' +'t_ch_balance.结算日期)<=60 THEN t_ch_fee_do.原始金额 * t_ch_fee.汇率 ELSE 0 END) AS 二月回收, ' +'SUM(CASE WHEN DATEDIFF([day], t_op_aire.'+str_date_tongji+', ' +'t_ch_balance.结算日期) ' +'> 60 and DATEDIFF([day], t_op_aire.'+str_date_tongji+',' +'t_ch_balance.结算日期)<=90 THEN t_ch_fee_do.原始金额 * t_ch_fee.汇率 ELSE 0 END) AS 三月回收, ' +'SUM(CASE WHEN DATEDIFF([day], t_op_aire.'+str_date_tongji+', ' +'t_ch_balance.结算日期) ' +'> 90 THEN t_ch_fee_do.原始金额 * t_ch_fee.汇率 ELSE 0 END) AS 其他回收 ' +'INTO #fee ' +'FROM t_ch_fee_do inner JOIN t_op_aire on t_ch_fee_do.业务编号=t_op_aire.编号 inner JOIN ' +'t_ch_balance ON ' +'t_ch_fee_do.工作编号 = t_ch_balance.帐单编号 inner JOIN ' +'t_ch_fee ON t_ch_fee_do.CH_ID = t_ch_fee.CH_ID ' +str +' and t_ch_fee_do.类型='+''''+'3'+'''' +' group by t_op_aire.揽货人 ' +'select #bill.揽货人,#bill.毛利润,#bill.利润率,#bill.资金占用量,#bill.资金占用率, ' +'(case when #bill.合计应收=0 then '+''''+'无法计算'+'''' +' else ltrim(str(#fee.当月回收/#bill.合计应收*100,10,2))+'+''''+'%'+''''+' end) as 当月回收率,' +'(case when #bill.合计应收=0 then '+''''+'无法计算'+'''' +' else ltrim(str(#fee.二月回收/#bill.合计应收*100,10,2))+'+''''+'%'+''''+' end) as 二月回收率,' +'(case when #bill.合计应收=0 then '+''''+'无法计算'+'''' +' else ltrim(str(#fee.三月回收/#bill.合计应收*100,10,2))+'+''''+'%'+''''+' end) as 三月回收率,' +'(case when #bill.合计应收=0 then '+''''+'无法计算'+'''' +' else ltrim(str(#fee.其他回收/#bill.合计应收*100,10,2))+'+''''+'%'+''''+' end) as 其他回收率,' +'(case when #bill.合计应收=0 then '+''''+'无法计算'+'''' +' else ltrim(str((#fee.其他回收+#fee.当月回收+#fee.二月回收+#fee.三月回收)/#bill.合计应收*100,10,2))+' +''''+'%'+''''+' end) as 合计回收率 ,#bill.合计应收 ' +'from #bill left join #fee on #bill.揽货人=#fee.揽货人 ' +'order by #bill.揽货人 '; p_shen.open; p_total.close; p_total.Parameters.ParamByName('SQLStr').value:= 'DECLARE @all_pay numeric ' +'select @all_pay=isnull((select sum(t_op_gain.合计应付) from t_op_gain' +' where t_op_gain.编号 in (select t_op_aire.编号 from t_op_aire '+str_date+')),0) ' +'SELECT ' +'sum(t_op_gain.毛利润) as 毛利润,' +'(case when isnull(sum(t_op_gain.合计应付),0)=0 then '+''''+'无法计算'+''''+' else ' +'ltrim(str(sum(t_op_gain.毛利润)/sum(t_op_gain.合计应付)*100,10,2))+'+''''+'%'+''''+' end) as 利润率, ' +'sum(t_op_gain.合计应付) as 资金占用量,' +'(case when @all_pay=0 then '+''''+'无法计算'+''''+' else ' +'(ltrim(str(sum(t_op_gain.合计应付)/@all_pay*100,10,2))+'+''''+'%'+''''+') end) as 资金占用率,isnull(sum(t_op_gain.合计应收),0) as 合计应收 ' +'INTO #bill ' +'FROM t_op_gain inner join t_op_aire on t_op_gain.编号 = t_op_aire.编号 ' +str +' SELECT ' +'SUM(CASE WHEN DATEDIFF([day], t_op_aire.'+str_date_tongji+', ' +'t_ch_balance.结算日期) ' +'<= 30 THEN t_ch_fee_do.原始金额 * t_ch_fee.汇率 ELSE 0 END) AS 当月回收, ' +'SUM(CASE WHEN DATEDIFF([day], t_op_aire.'+str_date_tongji+', ' +'t_ch_balance.结算日期) ' +'> 30 and DATEDIFF([day], t_op_aire.'+str_date_tongji+', ' +'t_ch_balance.结算日期)<=60 THEN t_ch_fee_do.原始金额 * t_ch_fee.汇率 ELSE 0 END) AS 二月回收, ' +'SUM(CASE WHEN DATEDIFF([day], t_op_aire.'+str_date_tongji+', ' +'t_ch_balance.结算日期) ' +'> 60 and DATEDIFF([day], t_op_aire.'+str_date_tongji+',' +'t_ch_balance.结算日期)<=90 THEN t_ch_fee_do.原始金额 * t_ch_fee.汇率 ELSE 0 END) AS 三月回收, ' +'SUM(CASE WHEN DATEDIFF([day], t_op_aire.'+str_date_tongji+', ' +'t_ch_balance.结算日期) ' +'> 90 THEN t_ch_fee_do.原始金额 * t_ch_fee.汇率 ELSE 0 END) AS 其他回收 ' +'INTO #fee ' +'FROM t_ch_fee_do inner JOIN t_op_aire on t_ch_fee_do.业务编号=t_op_aire.编号 inner JOIN ' +'t_ch_balance ON ' +'t_ch_fee_do.工作编号 = t_ch_balance.帐单编号 inner JOIN ' +'t_ch_fee ON t_ch_fee_do.CH_ID = t_ch_fee.CH_ID ' +str +' and t_ch_fee_do.类型='+''''+'3'+'''' +' select #bill.毛利润,#bill.利润率,#bill.资金占用量,#bill.资金占用率, ' +'(case when #bill.合计应收=0 then '+''''+'无法计算'+'''' +' else ltrim(str(#fee.当月回收/#bill.合计应收*100,10,2))+'+''''+'%'+''''+' end) as 当月回收率,' +'(case when #bill.合计应收=0 then '+''''+'无法计算'+'''' +' else ltrim(str(#fee.二月回收/#bill.合计应收*100,10,2))+'+''''+'%'+''''+' end) as 二月回收率,' +'(case when #bill.合计应收=0 then '+''''+'无法计算'+'''' +' else ltrim(str(#fee.三月回收/#bill.合计应收*100,10,2))+'+''''+'%'+''''+' end) as 三月回收率,' +'(case when #bill.合计应收=0 then '+''''+'无法计算'+'''' +' else ltrim(str(#fee.其他回收/#bill.合计应收*100,10,2))+'+''''+'%'+''''+' end) as 其他回收率,' +'(case when #bill.合计应收=0 then '+''''+'无法计算'+'''' +' else ltrim(str((#fee.其他回收+#fee.当月回收+#fee.二月回收+#fee.三月回收)/#bill.合计应收*100,10,2))+' +''''+'%'+''''+' end) as 合计回收率 ,#bill.合计应收 ' +'from #bill CROSS JOIN #fee '; p_total.open; end; procedure Tfrm_rp_zj_aire.FormClose(Sender: TObject; var Action: TCloseAction); begin frm_rp_zj_aire.Hide; frm_rp_zj_aire.ManualFloat(frm_rp_zj_aire.BoundsRect ); frm_main.freeTabs('frm_rp_zj_aire'); action:=cafree; frm_rp_zj_aire:=nil; end; procedure Tfrm_rp_zj_aire.bsSkinButton5Click(Sender: TObject); begin close; end; procedure Tfrm_rp_zj_aire.bsSkinButton9Click(Sender: TObject); begin sys_print('空运出口资金分析',2,nil,nil,nil,nil,p_client1,p_shen1,nil,nil,nil,nil,nil); end; procedure Tfrm_rp_zj_aire.bsSkinPanel2Resize(Sender: TObject); var i:integer; begin i:=round((bsSkinPanel2.Width-bsSkinPanel1.Width)/5); bsSkinCheckRadioBox2.Width:=i; bsSkinCheckRadioBox1.Width:=i; bsSkinButton10.Width:=i; bsSkinButton9.Width:=i; bsSkinButton5.Width:=i; end; procedure Tfrm_rp_zj_aire.dxDBGrid1ColumnSorting(Sender: TObject; Column: TdxDBTreeListColumn; var Allow: Boolean); begin Column_sort_pro(Column,p_client,'委托单位'); end; procedure Tfrm_rp_zj_aire.dxDBGrid2ColumnSorting(Sender: TObject; Column: TdxDBTreeListColumn; var Allow: Boolean); begin Column_sort_pro(Column,p_shen,'揽货人'); end; end.