unit u_rp_no_selfno; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, bsSkinCtrls, ExtCtrls, ComCtrls, bsSkinTabs, DB, ADODB,DateUtils, dxExEdtr, dxDBTLCl, dxGrClms, dxDBGrid, dxTL, dxDBCtrl, dxCntner, kbmMemTable, kbmMemBinaryStreamFormat, Menus, StdCtrls, wwdbdatetimepicker; type Tfrm_rp_no_selfno = class(TForm) Panel1: TPanel; bsSkinPanel2: TbsSkinPanel; bsSkinButton10: TbsSkinButton; bsSkinButton9: TbsSkinButton; bsSkinButton1: TbsSkinButton; bsSkinButton5: TbsSkinButton; p_total_client1: TDataSource; p_total_client: TADOStoredProc; p_total_sales: TADOStoredProc; p_total_sales1: TDataSource; SaveDialog: TSaveDialog; bsSkinPageControl4: TbsSkinPageControl; bsSkinTabSheet1: TbsSkinTabSheet; bsSkinTabSheet3: TbsSkinTabSheet; dxDBGrid1: TdxDBGrid; dxDBGridMaskColumn95: TdxDBGridMaskColumn; dxDBGridColumn19: TdxDBGridColumn; dxDBGridColumn22: TdxDBGridColumn; dxDBGridColumn25: TdxDBGridColumn; dxDBGrid3: TdxDBGrid; dxDBGrid3Column22: TdxDBGridColumn; dxDBGridColumn59: TdxDBGridColumn; dxDBGridColumn60: TdxDBGridColumn; dxDBGridColumn61: TdxDBGridColumn; dxDBGridColumn62: TdxDBGridColumn; dxDBGridColumn63: TdxDBGridColumn; dxDBGridColumn64: TdxDBGridColumn; dxDBGridColumn65: TdxDBGridColumn; dxDBGridColumn66: TdxDBGridColumn; dxDBGridColumn67: TdxDBGridColumn; dxDBGridColumn68: TdxDBGridColumn; dxDBGridColumn69: TdxDBGridColumn; dxDBGridColumn70: TdxDBGridColumn; dxDBGridColumn71: TdxDBGridColumn; dxDBGridColumn72: TdxDBGridColumn; dxDBGridColumn73: TdxDBGridColumn; dxDBGridColumn74: TdxDBGridColumn; dxDBGridColumn75: TdxDBGridColumn; dxDBGridColumn76: TdxDBGridColumn; dxDBGridColumn77: TdxDBGridColumn; dxDBGridColumn78: TdxDBGridColumn; dxDBGridColumn79: TdxDBGridColumn; bsSkinTabSheet4: TbsSkinTabSheet; p_accept_bill: TADOStoredProc; p_accept_bill1: TDataSource; dxDBGrid5: TdxDBGrid; dxDBGrid1Column1: TdxDBGridMaskColumn; dxDBGrid1Column54: TdxDBGridMaskColumn; dxDBGrid1Column11: TdxDBGridMaskColumn; dxDBGrid1Column13: TdxDBGridMaskColumn; dxDBGrid1Column15: TdxDBGridMaskColumn; dxDBGrid1Column65: TdxDBGridColumn; dxDBGrid1Column66: TdxDBGridColumn; dxDBGrid1USD: TdxDBGridColumn; dxDBGrid1Column3: TdxDBGridColumn; dxDBGrid1Column4: TdxDBGridColumn; dxDBGrid1RMB: TdxDBGridColumn; dxDBGrid1Column6: TdxDBGridColumn; dxDBGrid1Column7: TdxDBGridColumn; dxDBGrid1Column8: TdxDBGridColumn; dxDBGrid1Column9: TdxDBGridColumn; dxDBGrid1Column10: TdxDBGridColumn; dxDBGrid1Column12: TdxDBGridDateColumn; dxDBGrid1Column63: TdxDBGridColumn; dxDBGrid1Column14: TdxDBGridMaskColumn; dxDBGrid1Column16: TdxDBGridMaskColumn; dxDBGrid1Column18: TdxDBGridMaskColumn; dxDBGrid1Column19: TdxDBGridMaskColumn; dxDBGrid1Column21: TdxDBGridMaskColumn; dxDBGrid1Column20: TdxDBGridMaskColumn; dxDBGrid1Column22: TdxDBGridDateColumn; dxDBGridMaskColumn1: TdxDBGridMaskColumn; dxDBGrid1Column24: TdxDBGridMaskColumn; dxDBGrid1Column25: TdxDBGridMaskColumn; dxDBGrid1Column26: TdxDBGridMaskColumn; dxDBGrid1Column27: TdxDBGridMaskColumn; dxDBGrid1Column28: TdxDBGridColumn; dxDBGrid1Column29: TdxDBGridColumn; dxDBGrid11: TdxDBGridMaskColumn; dxDBGrid12: TdxDBGridMaskColumn; dxDBGrid13: TdxDBGridMaskColumn; dxDBGrid14: TdxDBGridMaskColumn; dxDBGrid15: TdxDBGridMaskColumn; dxDBGrid16: TdxDBGridMaskColumn; dxDBGrid17: TdxDBGridMaskColumn; dxDBGrid18: TdxDBGridMaskColumn; dxDBGrid19: TdxDBGridMaskColumn; dxDBGrid110: TdxDBGridMaskColumn; dxDBGrid1Column50: TdxDBGridMaskColumn; dxDBGrid1TEU: TdxDBGridMaskColumn; dxDBGrid1Column52: TdxDBGridMaskColumn; dxDBGrid1Column53: TdxDBGridMaskColumn; dxDBGrid1Column55: TdxDBGridMaskColumn; dxDBGrid1Column56: TdxDBGridMaskColumn; dxDBGrid1Column57: TdxDBGridMaskColumn; dxDBGrid1Column58: TdxDBGridMaskColumn; dxDBGrid1Column59: TdxDBGridMaskColumn; dxDBGrid1Column60: TdxDBGridMaskColumn; dxDBGrid1Column61: TdxDBGridColumn; dxDBGrid1Column62: TdxDBGridColumn; dxDBGrid1Column68: TdxDBGridColumn; dxDBGrid1Column69: TdxDBGridColumn; dxDBGrid5Column59: TdxDBGridColumn; kbmBinaryStreamFormat1: TkbmBinaryStreamFormat; kbmThreadDataSet1: TkbmThreadDataSet; memtblrpt_total: TkbmMemTable; bsSkinButton13: TbsSkinButton; PopupMenu1: TPopupMenu; bsSkinPanel1: TbsSkinPanel; N1: TMenuItem; N2: TMenuItem; N1101: TMenuItem; Label10: TLabel; wwDBDateTimePicker1: TwwDBDateTimePicker; wwDBDateTimePicker2: TwwDBDateTimePicker; Label5: TLabel; wwDBDateTimePicker3: TwwDBDateTimePicker; Label1: TLabel; wwDBDateTimePicker4: TwwDBDateTimePicker; Label2: TLabel; bsSkinButton15: TbsSkinButton; memtblrpt_total1: TDataSource; dxDBGrid5Column58: TdxDBGridColumn; bsSkinCheckRadioBox1: TbsSkinCheckRadioBox; dxDBGrid5Column60: TdxDBGridColumn; dxDBGrid5Column61: TdxDBGridColumn; dxDBGrid5Column62: TdxDBGridColumn; dxDBGrid5Column63: TdxDBGridColumn; dxDBGrid5Column64: TdxDBGridColumn; memtblDetail: TkbmMemTable; memtblDetailField: TStringField; StringField1: TStringField; memtblDetailField2: TIntegerField; memtblDetailUSD3: TFloatField; memtblDetailRMB3: TFloatField; memtblDetailField3: TFloatField; dxDBGrid1Column5: TdxDBGridColumn; dxDBGrid1Column17: TdxDBGridColumn; procedure bsSkinButton5Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure Panel1Resize(Sender: TObject); procedure bsSkinButton10Click(Sender: TObject); procedure bsSkinButton1Click(Sender: TObject); procedure bsSkinButton9Click(Sender: TObject); procedure dxDBGrid1ColumnSorting(Sender: TObject; Column: TdxDBTreeListColumn; var Allow: Boolean); procedure dxDBGrid2ColumnSorting(Sender: TObject; Column: TdxDBTreeListColumn; var Allow: Boolean); procedure dxDBGrid3ColumnSorting(Sender: TObject; Column: TdxDBTreeListColumn; var Allow: Boolean); procedure dxDBGrid5DblClick(Sender: TObject); procedure dxDBGrid6DblClick(Sender: TObject); procedure dxDBGrid7DblClick(Sender: TObject); procedure dxDBGrid8DblClick(Sender: TObject); procedure bsSkinButton13Click(Sender: TObject); procedure bsSkinButton15Click(Sender: TObject); procedure dxDBGrid1Column65CustomDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxDBTreeListColumn; const AText: String; AFont: TFont; var AColor: TColor; ASelected, AFocused: Boolean; var ADone: Boolean); private procedure do_1(str_bill:widestring); procedure GetNoFee; { Private declarations } public { Public declarations } end; var frm_rp_no_selfno: Tfrm_rp_no_selfno; implementation uses u_main, u_rp_no_seae_query,my_sys_function, u_rp_total_query, u_rp_no_total, u_sys_progress; {$R *.dfm} procedure Tfrm_rp_no_selfno.do_1(str_bill:widestring); begin p_accept_bill.close; p_accept_bill.Parameters.ParamByName('SQLStr').value:= 'SELECT t_ch_fee.编号, 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 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 (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 差额合计,' +'v_op_bscard.业务编号,v_op_bscard.业务类型, v_op_bscard.会计期间, v_op_bscard.主提单号,' +'v_op_bscard.分提单号, v_op_bscard.委托编号,' +'v_op_bscard.委托单位,' +'v_op_bscard.航次, v_op_bscard.船名, v_op_bscard.开船日期,' +'v_op_bscard.装货港, v_op_bscard.卸货港,' +'v_op_bscard.件数, v_op_bscard.重量, v_op_bscard.尺码,' +'v_op_bscard.箱型1, v_op_bscard.箱型2, v_op_bscard.箱型3,' +'v_op_bscard.箱型4, v_op_bscard.箱型5, v_op_bscard.箱型6,' +'v_op_bscard.箱型7, v_op_bscard.箱型8, v_op_bscard.箱型9,' +'v_op_bscard.箱型10, v_op_bscard.其他箱型,' +'v_op_bscard.箱TEU, v_op_bscard.操作员,' +'v_op_bscard.揽货人, v_op_bscard.客服员,' +'v_op_bscard.船公司, v_op_bscard.货代公司, v_op_bscard.报关行,' +'(case when round((case when v_op_bscard.重量/1000>v_op_bscard.尺码 then v_op_bscard.重量/1000 ' +'else v_op_bscard.尺码 end),4)>1 then ' +'round((case when v_op_bscard.重量/1000>v_op_bscard.尺码 then v_op_bscard.重量/1000 else ' +'v_op_bscard.尺码 end),4) else ' +'1 end) as 计费吨,DATEDIFF([day],v_op_bscard.会计期间, GETDATE()) AS 会计天数,' +' DATEDIFF([day],t_ch_fee.应结日期, GETDATE()) AS 超期天数,' +' DATEDIFF([day],t_ch_fee.应结日期, GETDATE()) AS 超期月数,' +'isnull(t_crm_client.结费期限,0) as 结费期限,' +'t_ch_fee.应结日期' +' FROM t_ch_fee inner join v_op_bscard on v_op_bscard.编号=t_ch_fee.编号 left join t_crm_client ' +' on t_ch_fee.客户名称=t_crm_client.客户简称 ' +str_bill +' GROUP BY t_ch_fee.编号, t_ch_fee.客户名称,' +'v_op_bscard.业务编号, v_op_bscard.业务类型,v_op_bscard.会计期间, v_op_bscard.主提单号,' +'v_op_bscard.分提单号, v_op_bscard.委托编号, ' +'v_op_bscard.委托单位, ' +'v_op_bscard.航次, v_op_bscard.船名, v_op_bscard.开船日期,' +'v_op_bscard.装货港, v_op_bscard.卸货港, ' +'v_op_bscard.件数, v_op_bscard.重量, v_op_bscard.尺码,' +'v_op_bscard.箱型1, v_op_bscard.箱型2, v_op_bscard.箱型3,' +'v_op_bscard.箱型4, v_op_bscard.箱型5, v_op_bscard.箱型6,' +'v_op_bscard.箱型7, v_op_bscard.箱型8, v_op_bscard.箱型9,' +'v_op_bscard.箱型10,v_op_bscard.其他箱型,' +'v_op_bscard.箱TEU, v_op_bscard.操作员,' +'v_op_bscard.揽货人, v_op_bscard.客服员, ' +'v_op_bscard.船公司, v_op_bscard.货代公司, v_op_bscard.报关行,' +'(case when round((case when v_op_bscard.重量/1000>v_op_bscard.尺码 then v_op_bscard.重量/1000 ' +'else v_op_bscard.尺码 end),4)>1 then ' +'round((case when v_op_bscard.重量/1000>v_op_bscard.尺码 then v_op_bscard.重量/1000 else ' +'v_op_bscard.尺码 end),4) else ' +'1 end),DATEDIFF([day],v_op_bscard.会计期间, GETDATE()),' +' DATEDIFF([day],v_op_bscard.开船日期, GETDATE()),' +' DATEDIFF([day],v_op_bscard.开船日期, GETDATE()),' +'isnull(t_crm_client.结费期限,0),' +'t_ch_fee.应结日期 ' +'order by v_op_bscard.业务类型,v_op_bscard.开船日期, v_op_bscard.船名, v_op_bscard.航次, v_op_bscard.主提单号 '; p_accept_bill.Open; { p_total_client.close; p_total_client.Parameters.ParamByName('SQLStr').value:= 'SELECT t_ch_fee.客户名称,v_op_bscard.业务类型,' +'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 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.金额-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 v_op_bscard on v_op_bscard.编号=t_ch_fee.编号 ' +str_bill+' GROUP BY t_ch_fee.客户名称,v_op_bscard.业务类型 order by t_ch_fee.客户名称,v_op_bscard.业务类型'; p_total_client.Open; p_total_sales.close; p_total_sales.Parameters.ParamByName('SQLStr').value:= 'SELECT v_op_bscard.揽货人,v_op_bscard.业务类型,' +'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 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.金额-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 v_op_bscard on v_op_bscard.编号=t_ch_fee.编号 ' +str_bill+' GROUP BY v_op_bscard.揽货人,v_op_bscard.业务类型 order by v_op_bscard.揽货人,v_op_bscard.业务类型'; p_total_sales.Open; p_total.close; p_total.Parameters.ParamByName('SQLStr').value:= '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 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.金额-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 v_op_bscard on v_op_bscard.编号=t_ch_fee.编号 ' +str_bill; p_total.Open; } end; procedure Tfrm_rp_no_selfno.bsSkinButton5Click(Sender: TObject); begin close; end; procedure Tfrm_rp_no_selfno.FormClose(Sender: TObject; var Action: TCloseAction); begin frm_rp_no_selfno.Hide; frm_rp_no_selfno.ManualFloat(frm_rp_no_selfno.BoundsRect ); frm_main.freeTabs('frm_rp_no_selfno'); action:=cafree; frm_rp_no_selfno:=nil; end; procedure Tfrm_rp_no_selfno.Panel1Resize(Sender: TObject); var i:integer; begin i:=round(bsSkinPanel2.Width/7); bsSkinCheckRadioBox1.Width:=i; bsSkinButton10.Width:=i; bsSkinButton9.Width:=i; bsSkinButton1.Width:=i; end; procedure Tfrm_rp_no_selfno.bsSkinButton10Click(Sender: TObject); begin try frm_rp_total_query:=tfrm_rp_total_query.Create (self); rp_seae_query_num:=1; if bsSkinCheckRadioBox1.Checked then rp_seae_query_type:=1; rp_seae_query_limited:='0033'; rp_seae_query_str:='业务综合欠费'; frm_rp_total_query.ShowModal; finally frm_rp_total_query.Free; end; GetNoFee; end; procedure Tfrm_rp_no_selfno.bsSkinButton1Click(Sender: TObject); begin with SaveDialog do begin DefaultExt :='xls'; Filter := '(*.xls)|*.xls'; if Execute then begin if bsSkinTabSheet1.Showing then dxDBGrid1.SaveToXLS(FileName,true) else if bsSkinTabSheet3.Showing then dxDBGrid3.SaveToXLS(FileName,true) else if bsSkinTabSheet4.Showing then dxDBGrid5.SaveToXLS(FileName,true) { else if bsSkinTabSheet5.Showing then dxDBGrid6.SaveToXLS(FileName,true) else if bsSkinTabSheet6.Showing then dxDBGrid7.SaveToXLS(FileName,true) else if bsSkinTabSheet7.Showing then dxDBGrid8.SaveToXLS(FileName,true); } end; end; end; procedure Tfrm_rp_no_selfno.bsSkinButton9Click(Sender: TObject); begin sys_print('业务综合欠费',2,nil,nil,nil,nil,p_accept_bill1,nil,nil,nil,p_total_client1,p_total_sales1,nil); end; procedure Tfrm_rp_no_selfno.dxDBGrid1ColumnSorting(Sender: TObject; Column: TdxDBTreeListColumn; var Allow: Boolean); begin Column_sort_pro(Column,p_total_client,'客户名称'); end; procedure Tfrm_rp_no_selfno.dxDBGrid2ColumnSorting(Sender: TObject; Column: TdxDBTreeListColumn; var Allow: Boolean); begin Column_sort_pro(Column,p_total_sales,'客户名称'); end; procedure Tfrm_rp_no_selfno.dxDBGrid3ColumnSorting(Sender: TObject; Column: TdxDBTreeListColumn; var Allow: Boolean); begin // Column_sort_pro(Column,p_total,'业务种类'); end; procedure Tfrm_rp_no_selfno.dxDBGrid5DblClick(Sender: TObject); begin fee_view(p_accept_bill.fieldbyname('编号').asstring); end; procedure Tfrm_rp_no_selfno.dxDBGrid6DblClick(Sender: TObject); begin // fee_view(p_accept_fee.fieldbyname('编号').asstring); end; procedure Tfrm_rp_no_selfno.dxDBGrid7DblClick(Sender: TObject); begin // fee_view(p_pay_bill.fieldbyname('编号').asstring); end; procedure Tfrm_rp_no_selfno.dxDBGrid8DblClick(Sender: TObject); begin // fee_view(p_pay_fee.fieldbyname('编号').asstring); end; procedure Tfrm_rp_no_selfno.bsSkinButton13Click(Sender: TObject); var Pnt:Tpoint; begin Pnt:=bsSkinButton13.ClientToScreen(Point(0,bsSkinButton13.Height)); PopupMenu1.Popup(Pnt.x,Pnt.y); end; procedure Tfrm_rp_no_selfno.bsSkinButton15Click(Sender: TObject); var str_bill:widestring; begin if wwDBDateTimePicker3.Text='' then begin MessageDlg('应结日期必须有值',mtWarning,[mbYes],0); exit; end; if wwDBDateTimePicker4.Text='' then begin MessageDlg('应结日期必须有值',mtWarning,[mbYes],0); exit; end; str_bill:=''; str_bill:=query_tiaojian(1,str_bill,'v_op_bscard.开船日期','大于',wwDBDateTimePicker1.text); str_bill:=query_tiaojian(1,str_bill,'v_op_bscard.开船日期','小于',wwDBDateTimePicker2.text); if trim(str_bill)='' then begin str_bill:='where '+open_data('0033','v_op_bscard.揽货人','v_op_bscard.操作员','v_op_bscard.客服员','v_op_bscard.报关操作','v_op_bscard.报检操作'); end else begin str_bill:=str_bill+' and '+open_data('0033','v_op_bscard.揽货人','v_op_bscard.操作员','v_op_bscard.客服员','v_op_bscard.报关操作','v_op_bscard.报检操作'); end; if str_bill='' then str_bill:='where t_ch_fee.金额<>t_ch_fee.结算金额 ' else str_bill:=str_bill+' and t_ch_fee.金额<>t_ch_fee.结算金额 '; str_bill:=query_tiaojian(1,str_bill,'t_ch_fee.应结日期','大于',wwDBDateTimePicker4.text); str_bill:=query_tiaojian(1,str_bill,'t_ch_fee.应结日期','小于',wwDBDateTimePicker3.text); do_1(str_bill); GetNoFee; end; procedure Tfrm_rp_no_selfno.GetNoFee; var aQuery,aQuery2:TAdoQuery; sumbal:Double; hvcg:Boolean; aYear,aMonth,aDay,bDay:word; begin if not p_accept_bill.Active then Exit; if p_accept_bill.IsEmpty then Exit; memtblrpt_total.DisableControls; memtblrpt_total.LoadFromDataSet(p_accept_bill,[mtcpostructure,mtcpoProperties,mtcpoFieldIndex]); p_accept_bill.Close; memtblrpt_total.FieldByName('超期月数').ReadOnly:=false; aQuery:=CreateAdoQuery; aQuery2:=CreateAdoQuery; try if memtblrpt_total.IsEmpty then exit; memtblrpt_total.First; with memtblrpt_total do begin while not memtblrpt_total.eof do begin if (memtblrpt_total.FieldByName('应收合计').AsFloat=0.00) or memtblrpt_total.FieldByName('应收合计').IsNull then begin memtblrpt_total.Delete; end; memtblrpt_total.Next; end; end; memtblDetail.Open; memtblDetail.First; while not memtblDetail.eof do begin memtblDetail.Delete; end; if not ASSIGNED(frm_sys_progress) then frm_sys_progress:=tfrm_sys_progress.Create(application); frm_sys_progress.Show; frm_sys_progress.bsSkinGauge1.MaxValue:=memtblrpt_total.RecordCount; frm_sys_progress.bsSkinGauge1.MinValue:=0; frm_sys_progress.bsSkinGauge1.Value:=0; frm_sys_progress.Update; memtblrpt_total.First; with memtblrpt_total do begin while not eof do begin frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; edit; memtblrpt_total.FieldByName('超期月数').AsInteger:=MonthsBetween(memtblrpt_total.FieldByName('应结日期').AsDateTime,now); post; if memtblDetail.Locate('揽货人;客户名称;超期月数',VarArrayOf([memtblrpt_total.FieldByName('揽货人').asstring,memtblrpt_total.FieldByName('客户名称').AsStRING,memtblrpt_total.FieldByName('超期月数').AsInteger]),[]) THEN begin memtblDetail.edit; memtblDetail.FieldByName('未收USD').AsFloat:=memtblDetail.FieldByName('未收USD').AsFloat+memtblrpt_total.FieldByName('未收USD').AsFloat; memtblDetail.FieldByName('未收RMB').AsFloat:=memtblDetail.FieldByName('未收RMB').AsFloat+memtblrpt_total.FieldByName('未收RMB').AsFloat; memtblDetail.FieldByName('未收合计').AsFloat:=memtblDetail.FieldByName('未收合计').AsFloat+memtblrpt_total.FieldByName('未收合计').AsFloat; memtblDetail.Post; end else begin memtblDetail.Insert; memtblDetail.FieldByName('揽货人').AsString:=memtblrpt_total.FieldByName('揽货人').AsString; memtblDetail.FieldByName('客户名称').AsString:=memtblrpt_total.FieldByName('客户名称').AsString; memtblDetail.FieldByName('超期月数').AsInteger:=memtblrpt_total.FieldByName('超期月数').AsInteger; memtblDetail.FieldByName('未收USD').AsFloat:=memtblDetail.FieldByName('未收USD').AsFloat+memtblrpt_total.FieldByName('未收USD').AsFloat; memtblDetail.FieldByName('未收RMB').AsFloat:=memtblDetail.FieldByName('未收RMB').AsFloat+memtblrpt_total.FieldByName('未收RMB').AsFloat; memtblDetail.FieldByName('未收合计').AsFloat:=memtblDetail.FieldByName('未收合计').AsFloat+memtblrpt_total.FieldByName('未收合计').AsFloat; memtblDetail.Post; end; next; end; end; { memtblrpt_total.Filtered:=False; if wwDBDateTimePicker4.Text<>'' then memtblrpt_total.Filter:='应结日期>='''+wwDBDateTimePicker4.Text+''' and 应结日期<='''+wwDBDateTimePicker3.Text+'''' else memtblrpt_total.Filter:='应结日期<='''+wwDBDateTimePicker3.Text+''''; memtblrpt_total.Filtered:=True; } memtblrpt_total.SortOn('揽货人;应结日期;客户名称',[]); memtblDetail.SortOn('揽货人;超期月数;客户名称',[mtcoDescending]); finally freeAndNil(aQuery); freeAndNil(aQuery2); freeAndNil(frm_sys_progress); memtblrpt_total.EnableControls; end; end; procedure Tfrm_rp_no_selfno.dxDBGrid1Column65CustomDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxDBTreeListColumn; const AText: String; AFont: TFont; var AColor: TColor; ASelected, AFocused: Boolean; var ADone: Boolean); var aday:Integer; begin aday:=StrToIntDef(ANode.Strings[dxDBGrid1Column66.Index],0); if aDay>180 then AFont.Color:=clBtnFace; end; end.