unit u_rp_sales_profitLcx; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, RxLookup, bsSkinCtrls, StdCtrls, wwdbdatetimepicker, XPMenu, dxExEdtr, dxDBTLCl, dxGrClms, dxDBCtrl, dxDBGrid, dxTL, dxCntner, DB, ADODB, Menus, kbmMemTable,DateUtils; type Tfrm_rp_sales_profitLcx = class(TForm) bsSkinPanel1: TbsSkinPanel; Label10: TLabel; Label5: TLabel; Label8: TLabel; Label11: TLabel; Label16: TLabel; Label1: TLabel; Label2: TLabel; wwDBDateTimePicker3: TwwDBDateTimePicker; bsSkinButton10: TbsSkinButton; bsSkinButton9: TbsSkinButton; bsSkinButton5: TbsSkinButton; wwDBDateTimePicker1: TwwDBDateTimePicker; wwDBDateTimePicker2: TwwDBDateTimePicker; wwDBDateTimePicker4: TwwDBDateTimePicker; RxDBLookupCombo6: TRxDBLookupCombo; RxDBLookupCombo1: TRxDBLookupCombo; RxDBLookupCombo2: TRxDBLookupCombo; bsSkinButton6: TbsSkinButton; XPMenu1: TXPMenu; dxDBGrid1: TdxDBGrid; Label3: TLabel; cmbbYwlb: TComboBox; tv_bscard_all: TADOQuery; tv_bscard_all1: TDataSource; dxDBGrid1Column1: TdxDBGridMaskColumn; dxDBGrid1Column3: TdxDBGridMaskColumn; dxDBGrid1Column4: TdxDBGridMaskColumn; dxDBGrid1Column5: TdxDBGridMaskColumn; dxDBGrid1Column6: TdxDBGridDateColumn; dxDBGrid1Column7: TdxDBGridMaskColumn; dxDBGrid1Column8: TdxDBGridMaskColumn; dxDBGrid1Column9: TdxDBGridMaskColumn; dxDBGrid1Column10: TdxDBGridMaskColumn; dxDBGrid1Column11: TdxDBGridMaskColumn; dxDBGrid1Column12: TdxDBGridMaskColumn; dxDBGrid1Column13: TdxDBGridMaskColumn; dxDBGrid1Column14: TdxDBGridDateColumn; dxDBGrid1Column15: TdxDBGridMaskColumn; dxDBGrid1Column16: TdxDBGridMaskColumn; dxDBGrid1Column17: TdxDBGridMaskColumn; dxDBGrid1Column18: TdxDBGridMaskColumn; dxDBGrid1Column20: TdxDBGridMaskColumn; dxDBGrid1Column21: TdxDBGridDateColumn; dxDBGrid1Column22: TdxDBGridMaskColumn; dxDBGrid1Column23: TdxDBGridMaskColumn; dxDBGrid1Column24: TdxDBGridMaskColumn; dxDBGrid1Column25: TdxDBGridMaskColumn; dxDBGrid1Column31: TdxDBGridMaskColumn; dxDBGrid1Column32: TdxDBGridMaskColumn; dxDBGrid1Column40: TdxDBGridMaskColumn; dxDBGrid1Column41: TdxDBGridMaskColumn; dxDBGrid1Column68: TdxDBGridMaskColumn; dxDBGrid1Column83: TdxDBGridMaskColumn; PopupMenu2: TPopupMenu; N10: TMenuItem; MenuItem1: TMenuItem; N14: TMenuItem; N13: TMenuItem; N12: TMenuItem; N15: TMenuItem; N16: TMenuItem; dxDBGrid1Column94: TdxDBGridColumn; dxDBGrid1Column19: TdxDBGridColumn; dxDBGrid1USD: TdxDBGridColumn; dxDBGrid1Column71: TdxDBGridColumn; dxDBGrid1Column72: TdxDBGridColumn; dxDBGrid1Column73: TdxDBGridColumn; dxDBGrid1Column74: TdxDBGridColumn; dxDBGrid1RMB: TdxDBGridColumn; dxDBGrid1Column76: TdxDBGridColumn; dxDBGrid1Column77: TdxDBGridColumn; dxDBGrid1Column78: TdxDBGridColumn; dxDBGrid1Column79: TdxDBGridColumn; dxDBGrid1Column80: TdxDBGridColumn; dxDBGrid1Column81: TdxDBGridColumn; dxDBGrid1Column82: TdxDBGridColumn; dxDBGrid1Column84: TdxDBGridColumn; dxDBGrid1Column85: TdxDBGridColumn; memTblCustDetail: TkbmMemTable; dsrTblCustDetal: TDataSource; memTblCustDetailField2: TStringField; memTblCustDetailField3: TStringField; memTblCustDetailField4: TStringField; memTblCustDetailField5: TStringField; memTblCustDetailField6: TStringField; memTblCustDetailField9: TStringField; memTblCustDetailField8: TIntegerField; memTblCustDetailField10: TStringField; memTblCustDetailField11: TStringField; memTblCustDetailField12: TStringField; memTblCustDetailField13: TStringField; memTblCustDetailField14: TStringField; memTblCustDetailField16: TStringField; memTblCustDetailField17: TStringField; memTblCustDetailField18: TIntegerField; memTblCustDetailField19: TStringField; memTblCustDetailField20: TFloatField; memTblCustDetailField21: TStringField; memTblCustDetailField23: TStringField; memTblCustDetailField24: TStringField; memTblCustDetailField25: TStringField; memTblCustDetailField26: TStringField; memTblCustDetailField27: TStringField; memTblCustDetailField28: TStringField; memTblCustDetailField29: TStringField; memTblCustDetailField30: TStringField; memTblCustDetailField31: TStringField; memTblCustDetailUSD: TFloatField; memTblCustDetailUSD2: TFloatField; memTblCustDetailUSD3: TFloatField; memTblCustDetailUSD4: TFloatField; memTblCustDetailUSD5: TFloatField; memTblCustDetailRMB: TFloatField; memTblCustDetailRMB2: TFloatField; memTblCustDetailRMB3: TFloatField; memTblCustDetailRMB4: TFloatField; memTblCustDetailRMB5: TFloatField; memTblCustDetailField32: TFloatField; memTblCustDetailField33: TFloatField; memTblCustDetailField34: TFloatField; memTblCustDetailField35: TFloatField; memTblCustDetailField36: TFloatField; memTblCustDetailField37: TStringField; memTblCustDetailField38: TFloatField; memTblCustDetailField: TDateTimeField; memTblCustDetailField7: TDateTimeField; memTblCustDetailField15: TDateTimeField; dxDBGrid1Column47: TdxDBGridColumn; bsSkinCheckRadioBox1: TbsSkinCheckRadioBox; bsSkinCheckRadioBox2: TbsSkinCheckRadioBox; memTblCustDetailField22: TStringField; dxDBGrid1Column48: TdxDBGridColumn; bsSkinCheckRadioBox3: TbsSkinCheckRadioBox; memTblCustDetailField39: TDateTimeField; Label4: TLabel; wwDBDateTimePicker5: TwwDBDateTimePicker; Label6: TLabel; wwDBDateTimePicker6: TwwDBDateTimePicker; dxDBGrid1Column49: TdxDBGridColumn; RxDBLookupCombo15: TRxDBLookupCombo; RxDBLookupCombo12: TRxDBLookupCombo; Label23: TLabel; Label40: TLabel; Label21: TLabel; RxDBLookupCombo20: TRxDBLookupCombo; bsSkinButton1: TbsSkinButton; bsSkinButton2: TbsSkinButton; bsSkinButton3: TbsSkinButton; dxDBGrid1Column50: TdxDBGridCheckColumn; memTblCustDetailFEE2: TIntegerField; memTblCustDetailField40: TStringField; dxDBGrid1Column51: TdxDBGridColumn; procedure bsSkinButton5Click(Sender: TObject); procedure bsSkinButton10Click(Sender: TObject); procedure bsSkinButton6Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure N10Click(Sender: TObject); procedure N14Click(Sender: TObject); procedure N12Click(Sender: TObject); procedure N16Click(Sender: TObject); procedure bsSkinButton9Click(Sender: TObject); procedure FormShow(Sender: TObject); procedure bsSkinButton1Click(Sender: TObject); procedure dxDBGrid1DblClick(Sender: TObject); procedure bsSkinButton2Click(Sender: TObject); procedure bsSkinButton3Click(Sender: TObject); procedure dxDBGrid1CustomDraw(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 function getlx(etd:TDate;bsno,saleid:string):double; { Private declarations } public { Public declarations } procedure UpdateBsProfit(bstype,bsno:String;fee:integer); end; var frm_rp_sales_profitLcx: Tfrm_rp_sales_profitLcx; implementation {$R *.dfm} uses u_main, my_sys_function, u_rp_totaljs_query; procedure Tfrm_rp_sales_profitLcx.UpdateBsProfit(bstype,bsno:String;fee:integer); var aQuery:TADOQuery; tblname:string; begin tblname:=''; if bstype='海运出口' then tblname:='t_op_seae' else if bstype='海运进口' then tblname:='t_op_seai' else if bstype='空运出口' then tblname:='t_op_Aire' else if bstype='空运进口' then tblname:='t_op_Airi'; if tblname='' then exit; aQuery:=CreateAdoQuery; with aQuery do try Close;SQL.Clear; SQL.Add('update '+tblname +' set Fee2=:fee'); SQL.Add('where 编号=:bsno'); Parameters.ParamByName('bsno').Value:=bsno; Parameters.ParamByName('fee').Value:=fee; Execsql; finally FreeAndNil(aQuery); end; end; function Tfrm_rp_sales_profitLcx.getlx(etd:TDate;bsno,saleid:string):double; var aQuery,aQuery2:TAdoQuery; d:integer; lx:real; begin aQuery:=CreateAdoQuery; aQuery2:=CreateAdoQuery; result:=0; try with aQuery do begin close;sql.clear; sql.Add('select * from t_crm_saleslxSet where 方案名称=(select 提成方案 from t_sys_employee where 姓名='''+saleid+''') order by 开始天数'); open; if IsEmpty then begin result:=0; exit; end else begin aQuery2.close;aQuery2.sql.clear; aQuery2.sql.Add('select sum(原始金额*汇率) as 金额,结算日期 from v_fee_do_detail where 类型=''收'' and 编号='''+bsno+''''); aQuery2.sql.Add('group by 结算日期'); aQuery2.Open; aQuery2.First; while not aQuery2.Eof do begin if aQuery2.FieldByName('结算日期').AsDateTime>etd then begin d:=abs(daysbetween(etd,aQuery2.FieldByName('结算日期').AsDateTime)); first; lx:=0.00; while not eof do begin if (d>=fieldbyname('开始天数').asinteger) and (d<=fieldbyname('结束天数').asinteger) then begin lx:=fieldbyname('扣息百分比').asfloat; result:=result+(aQuery2.fieldbyname('金额').asfloat*lx/100*(d-fieldbyname('开始天数').asinteger)); end else begin if d>fieldbyname('结束天数').asinteger then begin lx:=fieldbyname('扣息百分比').asfloat; result:=result+(aQuery2.fieldbyname('金额').asfloat*lx/100*(fieldbyname('结束天数').asinteger-fieldbyname('开始天数').asinteger)); end; end; next; end; end; aQuery2.Next; end; end; end; finally FreeAndNil(aQuery); FreeAndNil(aQuery2); end; end; procedure Tfrm_rp_sales_profitLcx.bsSkinButton5Click(Sender: TObject); begin close ; end; procedure Tfrm_rp_sales_profitLcx.bsSkinButton10Click(Sender: TObject); begin if bsSkinCheckRadioBox2.Checked then begin if (wwDBDateTimePicker5.text='')or (wwDBDateTimePicker5.text='') then begin MessageDlg('到付统计的开船日期为必填!',mtWarning,[mbok],0); end; end; with tv_bscard_all,sql do begin close ; clear ; add('SELECT V_op_bscard.*, v_fee_do_max.结算日期 FROM V_op_bscard '); add('left join v_fee_do_max on v_fee_do_max.编号=V_op_bscard.编号 '); add('where 1=1'); if bsSkinCheckRadioBox1.Checked then begin add(' and (v_op_bscard.合计应收=v_op_bscard.合计已收) and (v_op_bscard.合计应收<>0)'); end; case cmbbYwlb.ItemIndex of 1:add('and (V_op_bscard.业务类型 ='+'''海运出口'''+')'); 2:add('and (V_op_bscard.业务类型 ='+'''海运进口'''+')'); 3:add('and (V_op_bscard.业务类型 ='+'''空运出口'''+')'); 4:add('and (V_op_bscard.业务类型 ='+'''空运进口'''+')'); end ; if wwDBDateTimePicker1.text<>''then begin add(' and v_fee_do_max.结算日期 >='+''''+wwDBDateTimePicker1.text+''''); end ; if wwDBDateTimePicker2.text<>''then begin add(' and v_fee_do_max.结算日期 <='+''''+wwDBDateTimePicker2.text+' 23:59:59 '''); end ; if wwDBDateTimePicker3.text<>''then add(' and V_op_bscard.开船日期>='+''''+wwDBDateTimePicker3.text+''''); if wwDBDateTimePicker4.text<>''then add(' and V_op_bscard.开船日期<='+''''+wwDBDateTimePicker4.text+''''); if RxDBLookupCombo6.DisplayValue<>''then add(' and V_op_bscard.操作员='+''''+RxDBLookupCombo6.DisplayValue+''''); if RxDBLookupCombo1.DisplayValue<>''then add(' and V_op_bscard.揽货人='+''''+RxDBLookupCombo1.DisplayValue+''''); if RxDBLookupCombo2.DisplayValue<>''then add(' and V_op_bscard.录入人='+''''+RxDBLookupCombo2.DisplayValue+''''); if RxDBLookupCombo12.DisplayValue<>''then add(' and V_op_bscard.销售部门='+''''+RxDBLookupCombo12.DisplayValue+''''); if RxDBLookupCombo15.DisplayValue<>''then add(' and V_op_bscard.分部名称='+''''+RxDBLookupCombo15.DisplayValue+''''); if RxDBLookupCombo20.DisplayValue<>''then add(' and V_op_bscard.航线='+''''+RxDBLookupCombo20.DisplayValues[1]+''''); add(' and '+open_data('0021','v_op_bscard.揽货人','no','no','no','no')); if bsSkinCheckRadioBox2.Checked then begin add('union SELECT V_op_bscard.*, v_fee_do_max.结算日期 FROM V_op_bscard '); add('left join v_fee_do_max on v_fee_do_max.编号=V_op_bscard.编号 '); add('where 1=1'); add(' and v_op_bscard.合计应收=0 '); if wwDBDateTimePicker5.text<>''then begin add(' and v_op_bscard.开船日期 >='+''''+wwDBDateTimePicker5.text+''''); end; if wwDBDateTimePicker6.text<>''then begin add(' and v_op_bscard.开船日期 <='+''''+wwDBDateTimePicker6.text+''''); end; // add(')'); if RxDBLookupCombo6.DisplayValue<>''then add(' and V_op_bscard.操作员='+''''+RxDBLookupCombo6.DisplayValue+''''); if RxDBLookupCombo1.DisplayValue<>''then add(' and V_op_bscard.揽货人='+''''+RxDBLookupCombo1.DisplayValue+''''); if RxDBLookupCombo2.DisplayValue<>''then add(' and V_op_bscard.录入人='+''''+RxDBLookupCombo2.DisplayValue+''''); if RxDBLookupCombo20.DisplayValue<>''then add(' and V_op_bscard.航线='+''''+RxDBLookupCombo20.DisplayValues[1]+''''); case cmbbYwlb.ItemIndex of 1:add('and (V_op_bscard.业务类型 ='+'''海运出口'''+')'); 2:add('and (V_op_bscard.业务类型 ='+'''海运进口'''+')'); 3:add('and (V_op_bscard.业务类型 ='+'''空运出口'''+')'); 4:add('and (V_op_bscard.业务类型 ='+'''空运进口'''+')'); end ; if RxDBLookupCombo12.DisplayValue<>''then add(' and V_op_bscard.销售部门='+''''+RxDBLookupCombo12.DisplayValue+''''); if RxDBLookupCombo15.DisplayValue<>''then add(' and V_op_bscard.分部名称='+''''+RxDBLookupCombo15.DisplayValue+''''); add(' and '+open_data('0021','v_op_bscard.揽货人','no','no','no','no')); end; open ; memTblCustDetail.LoadFromDataSet(tv_bscard_all,[]); if bsSkinCheckRadioBox3.Checked then begin with memTblCustDetail do begin First; while not eof do begin if Fieldbyname('合计应收').Asfloat<>0 then begin edit; fieldbyname('扣利息').AsFloat:=getlx(fieldbyname('开船日期').AsDateTime,fieldbyname('编号').asstring,fieldbyname('揽货人').asstring); post; end; Next; end; end; end; end ; end; procedure Tfrm_rp_sales_profitLcx.bsSkinButton6Click(Sender: TObject); begin wwDBDateTimePicker1.Clear; wwDBDateTimePicker2.Clear; wwDBDateTimePicker3.Clear; wwDBDateTimePicker4.Clear; RxDBLookupCombo6.ClearValue; RxDBLookupCombo1.ClearValue; RxDBLookupCombo2.ClearValue; cmbbYwlb.ItemIndex:=-1 ; end; procedure Tfrm_rp_sales_profitLcx.FormClose(Sender: TObject; var Action: TCloseAction); begin savereggrid(dxdbgrid1,caption); frm_rp_sales_profitLcx.Hide; frm_rp_sales_profitLcx.ManualFloat(frm_rp_sales_profitLcx.BoundsRect ); frm_main.freeTabs('frm_rp_sales_profitLcx'); action:=cafree; frm_rp_sales_profitLcx:=nil; end; procedure Tfrm_rp_sales_profitLcx.N10Click(Sender: TObject); begin update_grid_view_no(dxdbgrid1); end; procedure Tfrm_rp_sales_profitLcx.N14Click(Sender: TObject); begin update_grid_view_all(dxdbgrid1); end; procedure Tfrm_rp_sales_profitLcx.N12Click(Sender: TObject); begin update_grid(dxdbgrid1,111); end; procedure Tfrm_rp_sales_profitLcx.N16Click(Sender: TObject); begin grid_save_xls(dxdbgrid1); end; procedure Tfrm_rp_sales_profitLcx.bsSkinButton9Click(Sender: TObject); begin sys_print('结算提成统计',2,nil,nil,nil,nil,dsrTblCustDetal,nil,nil,nil,nil,nil,nil); end; procedure Tfrm_rp_sales_profitLcx.FormShow(Sender: TObject); begin loadreggrid(dxdbgrid1,true,caption); end; procedure Tfrm_rp_sales_profitLcx.bsSkinButton1Click(Sender: TObject); begin try frm_rp_totaljs_query:=tfrm_rp_totaljs_query.Create (self); rp_totaljs_query_limited:='0021'; rp_totaljs_query_str:='业务员结算提成'; frm_rp_totaljs_query.ShowModal; finally FreeAndNil(frm_rp_totaljs_query); end; if tv_bscard_all.Recordset.RecordCount<>0 then begin memTblCustDetail.LoadFromDataSet(tv_bscard_all,[]); if bsSkinCheckRadioBox3.Checked then begin with memTblCustDetail do begin First; while not eof do begin if Fieldbyname('合计应收').Asfloat<>0 then begin edit; fieldbyname('扣利息').AsFloat:=getlx(fieldbyname('开船日期').AsDateTime,fieldbyname('编号').asstring,fieldbyname('揽货人').asstring); post; end; Next; end; end; end; end; end; procedure Tfrm_rp_sales_profitLcx.dxDBGrid1DblClick(Sender: TObject); begin fee_view(memTblCustDetail.fieldbyname('编号').asstring); end; procedure Tfrm_rp_sales_profitLcx.bsSkinButton2Click(Sender: TObject); var i:integer; begin if not if_open('405') then begin showmessage('你没有此模块的操作权限!,请联系系统管理员,权限设置路径:操作管理--->销售管理--->发放提成'); exit; end; if dxDBGrid1.SelectedCount>=1 then begin for i:=0 to dxDBGrid1.SelectedCount-1 do begin memTblCustDetail.GotoBookmark(pointer(dxDBGrid1.selectedrows[i])); UpdateBsProfit(memTblCustDetail.fieldbyname('业务类型').asstring,memTblCustDetail.fieldbyname('编号').asstring,1); memTblCustDetail.Edit; memTblCustDetail.fieldbyname('FEE2').AsString:='1'; memTblCustDetail.Post; end; end; end; procedure Tfrm_rp_sales_profitLcx.bsSkinButton3Click(Sender: TObject); var i:integer; begin if not if_open('406') then begin showmessage('你没有此模块的操作权限!,请联系系统管理员,权限设置路径操作管理--->销售管理--->取消提成'); exit; end; if dxDBGrid1.SelectedCount>=1 then begin for i:=0 to dxDBGrid1.SelectedCount-1 do begin memTblCustDetail.GotoBookmark(pointer(dxDBGrid1.selectedrows[i])); UpdateBsProfit(memTblCustDetail.fieldbyname('业务类型').asstring,memTblCustDetail.fieldbyname('编号').asstring,0); memTblCustDetail.Edit; memTblCustDetail.fieldbyname('FEE2').AsString:='0'; memTblCustDetail.Post; end; end; end; procedure Tfrm_rp_sales_profitLcx.dxDBGrid1CustomDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxDBTreeListColumn; const AText: String; AFont: TFont; var AColor: TColor; ASelected, AFocused: Boolean; var ADone: Boolean); begin if uppercase(ANode.Strings[dxDBGrid1Column50.Index])='1' then begin AColor:=clRed; exit; end; end; end.