unit u_rp_sales_profit_lx; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, dxExEdtr, RxMemDS, DB, ADODB, Menus, XPMenu, bsSkinCtrls, dxDBGrid, dxDBTLCl, dxGrClms, dxTL, dxDBCtrl, dxCntner, ComCtrls,DateUtils, bsSkinTabs, ExtCtrls, StdCtrls, Mask, wwdbedit, Wwdotdot, Wwdbcomb, kbmMemTable, kbmMemBinaryStreamFormat, wwdbdatetimepicker, RxLookup, bsSkinBoxCtrls, Grids, DBGrids; type Tfrm_rp_sales_profit_lx = class(TForm) Panel1: TPanel; bsSkinPageControl1: TbsSkinPageControl; PopupMenu2: TPopupMenu; N10: TMenuItem; N11: TMenuItem; N14: TMenuItem; N13: TMenuItem; N12: TMenuItem; N15: TMenuItem; N16: TMenuItem; XPMenu2: TXPMenu; bsSkinPanel1: TbsSkinPanel; bsSkinPanel3: TbsSkinPanel; kbmThreadDataSet1: TkbmThreadDataSet; kbmBinaryStreamFormat1: TkbmBinaryStreamFormat; memtblrpt_total: TkbmMemTable; RxDBLookupCombo3: TRxDBLookupCombo; Label14: TLabel; P_SUM: TkbmMemTable; DataSource1: TDataSource; P_SUM1: TDataSource; P_SUMField: TStringField; P_SUMField14: TFloatField; pnl1: TPanel; bsSkinButton10: TbsSkinButton; bsSkinButton9: TbsSkinButton; bsSkinButton5: TbsSkinButton; RxDBLookupCombo2: TRxDBLookupCombo; Label9: TLabel; Label22: TLabel; RxDBLookupCombo10: TRxDBLookupCombo; memtblDetail: TkbmMemTable; StringField1: TStringField; FloatField5: TFloatField; FloatField7: TFloatField; memtblDetailField: TStringField; memtblDetailField5: TDateTimeField; memtblDetailField6: TStringField; memtblDetailField8: TStringField; memtblDetailField9: TStringField; memtblDetail1: TDataSource; memtblDetailField11: TStringField; memtblDetailField12: TDateTimeField; memtblDetailField13: TDateTimeField; memtblDetailField18: TDateField; Label1: TLabel; bsSkinGroupBox1: TbsSkinGroupBox; Edit1: TEdit; Label4: TLabel; wwDBDateTimePicker1: TwwDBDateTimePicker; wwDBDateTimePicker2: TwwDBDateTimePicker; bsSkinMemo1: TbsSkinMemo; Label2: TLabel; Label3: TLabel; Label5: TLabel; wwDBDateTimePicker3: TwwDBDateTimePicker; Label6: TLabel; wwDBDateTimePicker4: TwwDBDateTimePicker; Label7: TLabel; wwDBDateTimePicker5: TwwDBDateTimePicker; Label8: TLabel; wwDBDateTimePicker6: TwwDBDateTimePicker; memtblDetailField2: TStringField; memtblDetailField3: TStringField; memtblDetailField4: TStringField; memtblDetailField7: TStringField; memtblDetailField10: TStringField; memtblDetailField14: TStringField; memtblDetailField15: TStringField; memtblDetailField16: TStringField; memtblDetailField17: TIntegerField; memtblDetailField19: TFloatField; bsSkinTabSheet1: TbsSkinTabSheet; bsSkinTabSheet2: TbsSkinTabSheet; dxDBGrid2: TdxDBGrid; dxDBGridMaskColumn32: TdxDBGridMaskColumn; dxDBGrid2Column19: TdxDBGridColumn; dxDBGrid2Column18: TdxDBGridColumn; dxDBGridMaskColumn36: TdxDBGridMaskColumn; dxDBGrid2Column24: TdxDBGridColumn; dxDBGrid2Column11: TdxDBGridColumn; dxDBGrid2Column12: TdxDBGridColumn; dxDBGrid2Column15: TdxDBGridColumn; dxDBGrid2Column16: TdxDBGridColumn; dxDBGrid2Column13: TdxDBGridColumn; dxDBGrid2Column14: TdxDBGridColumn; dxDBGrid2Column17: TdxDBGridColumn; dxDBGrid2Column20: TdxDBGridColumn; dxDBGrid2Column21: TdxDBGridColumn; dxDBGrid2Column22: TdxDBGridColumn; dxDBGrid2Column23: TdxDBGridColumn; dxDBGrid2Column25: TdxDBGridColumn; dxDBGrid2Column26: TdxDBGridColumn; dxDBGrid2Column27: TdxDBGridColumn; dxDBGrid1: TdxDBGrid; dxDBGrid1Column1: TdxDBGridColumn; dxDBGrid1Column2: TdxDBGridColumn; Label39: TLabel; wwDBComboBox44: TwwDBComboBox; procedure bsSkinButton5Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormShow(Sender: TObject); procedure bsSkinButton9Click(Sender: TObject); procedure N10Click(Sender: TObject); procedure N14Click(Sender: TObject); procedure N16Click(Sender: TObject); procedure bsSkinButton10Click(Sender: TObject); private procedure Getlx; function GetBetwMonth(aBe,aEe:TDate):Integer; function issameMonth(aBe,aEe:TDate):Boolean; { Private declarations } public bdatestr:String; { Public declarations } end; var frm_rp_sales_profit_lx: Tfrm_rp_sales_profit_lx; rp_rp_total_open:boolean; implementation uses u_main, my_sys_function, u_sys_progress,u_data_share; {$R *.dfm} procedure Tfrm_rp_sales_profit_lx.bsSkinButton5Click(Sender: TObject); begin close; end; procedure Tfrm_rp_sales_profit_lx.FormClose(Sender: TObject; var Action: TCloseAction); begin savereggrid(dxdbgrid2,caption+'2'); frm_rp_sales_profit_lx.Hide; frm_rp_sales_profit_lx.ManualFloat(frm_rp_sales_profit_lx.BoundsRect ); frm_main.freeTabs('frm_rp_sales_profit_lx'); action:=cafree; frm_rp_sales_profit_lx:=nil; end; procedure Tfrm_rp_sales_profit_lx.FormShow(Sender: TObject); begin loadreggrid(dxdbgrid2,true,caption+'2'); end; procedure Tfrm_rp_sales_profit_lx.bsSkinButton9Click(Sender: TObject); begin sys_print('业务利息计算',2,nil,nil,nil,nil,memtblDetail1,P_SUM1,nil,nil,nil,nil,nil); end; procedure Tfrm_rp_sales_profit_lx.N10Click(Sender: TObject); begin update_grid_view_no(dxdbgrid2); end; procedure Tfrm_rp_sales_profit_lx.N14Click(Sender: TObject); begin update_grid_view_all(dxdbgrid2); end; procedure Tfrm_rp_sales_profit_lx.N16Click(Sender: TObject); begin grid_save_xls(dxdbgrid2); end; procedure Tfrm_rp_sales_profit_lx.bsSkinButton10Click(Sender: TObject); var aquery:TADOQuery; str:String; begin memtblrpt_total.EmptyTable; memtblDetail.EmptyTable; P_SUM.EmptyTable; aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; str:=' where 类型=''收'' '; if wwDBDateTimePicker1.Text<>'' then str:=Str+' and 开船日期>='+''''+wwDBDateTimePicker1.text+''''; if wwDBDateTimePicker2.Text<>'' then str:=Str+' and 开船日期<='+''''+wwDBDateTimePicker2.text+''''; if wwDBDateTimePicker3.Text<>'' then str:=Str+' and 会计期间>='+''''+wwDBDateTimePicker3.text+''''; if wwDBDateTimePicker4.Text<>'' then str:=Str+' and 会计期间<='+''''+wwDBDateTimePicker4.text+''''; if wwDBDateTimePicker5.Text<>'' then str:=Str+' and 结算日期>='+''''+wwDBDateTimePicker5.text+''''; if wwDBDateTimePicker6.Text<>'' then str:=Str+' and 结算日期<='+''''+wwDBDateTimePicker6.text+''''; if RxDBLookupCombo3.DisplayValue<>'' then str:=Str+' and 揽货人='+''''+RxDBLookupCombo3.DisplayValue+''''; if RxDBLookupCombo2.DisplayValue<>'' then str:=Str+' and 委托单位='+''''+RxDBLookupCombo2.DisplayValues[1]+''''; if RxDBLookupCombo10.DisplayValue<>'' then str:=Str+' and 销售部门='+''''+RxDBLookupCombo10.DisplayValue+''''; if wwDBComboBox44.Text='帐期客户' then str:=str+' and 客户名称 in (select 客户简称 from t_crm_client_sales where 结费类型 in (''约定时间'',''约定天数'')) ' else str:=str+' and 客户名称 not in (select 客户简称 from t_crm_client_sales where 结费类型 in (''约定时间'',''约定天数'')) '; Str:='select 编号,业务状态,费用状态,客户名称,业务编号,会计期间,主提单号,分提单号,委托编号,装运方式,委托单位,'+ '船名,航次,开船日期,装货港,卸货港,件数,重量,尺码,集装箱,录入人, 录入日期,'+ '操作员,揽货人,客服员,航线,船公司,货代公司,报关行,工作编号 as 帐单编号,结算日期,结算人,结算方式,相关号码,银行,'+ ' SUM(case 原始币别 when ''USD'' then 原始金额 else 0 end) as 美元金额,SUM(case 原始币别 when ''USD'' then 0 else 原始金额 end) as 人民币金额 '+ 'from v_fee_do_bscard_detail '+str+ 'Group by 编号,业务状态,费用状态,客户名称,业务编号,会计期间,主提单号,分提单号,委托编号,装运方式,委托单位,'+ '船名,航次,开船日期,装货港,卸货港,件数,重量,尺码,集装箱,录入人, 录入日期, '+ '操作员,揽货人,客服员,航线,船公司,货代公司,报关行,工作编号,结算日期,结算人,结算方式,相关号码,银行 '+ 'order by 编号 desc'; SQL.Add(str); Open; memtblrpt_total.LoadFromDataSet(aQuery,[mtcpostructure,mtcpoProperties,mtcpoFieldIndex]); Getlx; end; finally FreeAndNil(aquery); end; end; procedure Tfrm_rp_sales_profit_lx.Getlx; var aQuery,aQuery3:TADOQuery; aStlDate:TDate; function getstlDate(aetd:TDateTime;Cust,SaleID:String):TDate; var aQuery2:TADOQuery; aYear,aMonth,aDay,bDay:word; aStlDate:TDateTime; begin aQuery2:=CreateAdoQuery; aStlDate:=aetd; result:=aStlDate; try with aQuery2 do begin Close;SQL.Clear; SQL.Add('Select * from t_crm_client_sales where 开始日期<='''+FormatDateTime('YYYY-MM-DD',aetd)+''' and 结束日期>='''+FormatDateTime('YYYY-MM-DD',aetd)+''' and 客户简称='''+Cust+''''); Open; if IsEmpty then begin Result:=aetd; Exit; end; if FieldByName('结费类型').AsString='现结买单' then begin Result:=aetd; end else if FieldByName('结费类型').AsString='约定天数' then begin result:=aStlDate+fieldByName('结费期限').AsInteger; end else if FieldByName('结费类型').AsString='约定时间' then begin if FieldByName('日期模式').AsString='固定' then begin DecodeDate(IncMonth(aStlDate,StrToIntDef(FieldByName('类型模式').AsString,0)),aYear,aMonth,aDay); bDay:=DaysInMonth(EncodeDate(aYear,aMonth,1)); if fieldByName('结费日期').AsInteger>bDay then result:=EncodeDate(aYear,aMonth,bDay) else result:=EncodeDate(aYear,aMonth,fieldByName('结费日期').AsInteger); end else result:=IncMonth(aStlDate,StrToIntDef(FieldByName('类型模式').AsString,0)); end else if FieldByName('结费类型').AsString='分阶段付费' then begin DecodeDate(IncMonth(aStlDate,StrToIntDef(FieldByName('类型模式').AsString,0)),aYear,aMonth,aDay); if aDay>fieldByName('结束日期').AsInteger then begin bDay:=DaysInMonth(EncodeDate(aYear,aMonth,1)); if fieldByName('结费日期2').AsInteger>bDay then result:=EncodeDate(aYear,aMonth,bDay) else result:=EncodeDate(aYear,aMonth,fieldByName('结费日期2').AsInteger); end else begin bDay:=DaysInMonth(EncodeDate(aYear,aMonth,1)); if fieldByName('结费日期').AsInteger>bDay then result:=EncodeDate(aYear,aMonth,bDay) else result:=EncodeDate(aYear,aMonth,fieldByName('结费日期').AsInteger); result:=EncodeDate(aYear,aMonth,fieldByName('结费日期').AsInteger); end; end else begin Result:=aetd; end; end; finally FreeAndNil(aQuery2); end; end; begin if NOT memtblDetail.Active then memtblDetail.Open; if NOT p_sum.Active then p_sum.Open; if memtblrpt_total.RecordCount=0 then exit; aQuery:=CreateAdoQuery; aQuery3:=CreateAdoQuery; try if not ASSIGNED(frm_sys_progress) then frm_sys_progress:=tfrm_sys_progress.Create(application); frm_sys_progress.Show; frm_sys_progress.bsSkinGauge1.MaxValue:=memtblrpt_total.RecordCount; frm_sys_progress.bsSkinGauge1.MinValue:=0; frm_sys_progress.bsSkinGauge1.Value:=0; frm_sys_progress.Update; memtblrpt_total.First; while not memtblrpt_total.eof do begin aStlDate:=getstlDate(memtblrpt_total.FieldByName('开船日期').AsDateTime,memtblrpt_total.FieldByName('委托单位').AsString,memtblrpt_total.FieldByName('揽货人').AsString); if memtblrpt_total.FieldByName('结算日期').AsDateTime>aStlDate then begin memtblDetail.Insert; memtblDetail.FieldByName('编号').AsString:=memtblrpt_total.FieldByName('编号').AsString; memtblDetail.FieldByName('业务编号').AsString:=memtblrpt_total.FieldByName('业务编号').AsString; memtblDetail.FieldByName('主提单号').AsString:=memtblrpt_total.FieldByName('主提单号').AsString; memtblDetail.FieldByName('揽货人').AsString:=memtblrpt_total.FieldByName('揽货人').AsString; memtblDetail.FieldByName('客户名称').AsString:=memtblrpt_total.FieldByName('客户名称').AsString; memtblDetail.FieldByName('船公司').AsString:=memtblrpt_total.FieldByName('船公司').AsString; memtblDetail.FieldByName('货代公司').AsString:=memtblrpt_total.FieldByName('货代公司').AsString; memtblDetail.FieldByName('报关行').AsString:=memtblrpt_total.FieldByName('报关行').AsString; memtblDetail.FieldByName('委托编号').AsString:=memtblrpt_total.FieldByName('委托编号').AsString; memtblDetail.FieldByName('航线').AsString:=memtblrpt_total.FieldByName('航线').AsString; memtblDetail.FieldByName('卸货港').AsString:=memtblrpt_total.FieldByName('卸货港').AsString; memtblDetail.FieldByName('开船日期').Value:=memtblrpt_total.FieldByName('开船日期').Value; memtblDetail.FieldByName('会计期间').Value:=memtblrpt_total.FieldByName('会计期间').Value; memtblDetail.FieldByName('结算日期').Value:=memtblrpt_total.FieldByName('结算日期').Value; memtblDetail.FieldByName('美元金额').Value:=memtblrpt_total.FieldByName('美元金额').Value; memtblDetail.FieldByName('人民币金额').Value:=memtblrpt_total.FieldByName('人民币金额').Value; memtblDetail.FieldByName('应结算日期').AsDateTime:=aStlDate; memtblDetail.FieldByName('超期天数').Asinteger:=DaysBetween(memtblrpt_total.FieldByName('结算日期').asDatetime,aStlDate); memtblDetail.FieldByName('利息金额').Value:=(memtblrpt_total.FieldByName('人民币金额').asfloat+memtblrpt_total.FieldByName('美元金额').Value*(GetUsdExrate(memtblrpt_total.FieldByName('开船日期').asstring)))*strtofloat(Edit1.text)/100*memtblDetail.FieldByName('超期天数').Asinteger; if p_sum.Locate('揽货人',memtblrpt_total.FieldByName('揽货人').AsString,[]) then begin P_sum.Edit; P_sum.fieldbyname('扣利息').AsFloat:=P_sum.fieldbyname('扣利息').AsFloat+memtblDetail.FieldByName('利息金额').Value; P_sum.post; end else begin P_sum.insert; p_sum.FieldByName('揽货人').AsString:=memtblrpt_total.FieldByName('揽货人').AsString; P_sum.fieldbyname('扣利息').AsFloat:=P_sum.fieldbyname('扣利息').AsFloat+memtblDetail.FieldByName('利息金额').Value; P_sum.post; end; memtblDetail.post; end; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; memtblrpt_total.Next; end; finally frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.MaxValue; frm_sys_progress.free; frm_sys_progress:=nil; FreeAndNil(aQuery); FreeAndNil(aQuery3); end; end; function Tfrm_rp_sales_profit_lx.GetBetwMonth(aBe, aEe: TDate): Integer; var bYear,bMonth,bDate,eYear,eMonth,eDate:Word; begin DecodeDate(aBe,bYear,bMonth,bDate); DecodeDate(aEe,eYear,eMonth,eDate); if bYear=eYear then Result:=Abs(bMonth-eMonth) else begin if bYear>eYear then begin Result:=bMonth+(12-eMonth); end else begin Result:=eMonth+(12-bMonth); end; end; end; function Tfrm_rp_sales_profit_lx.issameMonth(aBe, aEe: TDate): Boolean; var bYear,bMonth,bDate,eYear,eMonth,eDate:Word; begin DecodeDate(aBe,bYear,bMonth,bDate); DecodeDate(aEe,eYear,eMonth,eDate); if (eMonth=bMonth) or (aBe>aEe) then Result:=True else result:=false; end; end.