unit u_rp_sales_profit; 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,inifiles; type Tfrm_rp_sales_profit = class(TForm) Panel1: TPanel; bsSkinPageControl1: TbsSkinPageControl; bsSkinTabSheet1: TbsSkinTabSheet; bsSkinTabSheet4: TbsSkinTabSheet; bsSkinTabSheet6: TbsSkinTabSheet; bsSkinPageControl2: TbsSkinPageControl; bsSkinTabSheet11: TbsSkinTabSheet; bsSkinTabSheet13: TbsSkinTabSheet; dxDBGrid1: TdxDBGrid; dxDBGrid1Column5: TdxDBGridMaskColumn; dxDBGrid1Column3: TdxDBGridMaskColumn; dxDBGrid1Column4: TdxDBGridMaskColumn; dxDBGrid1Column6: TdxDBGridDateColumn; dxDBGrid1Column7: TdxDBGridMaskColumn; dxDBGrid1Column8: TdxDBGridMaskColumn; dxDBGrid1Column9: TdxDBGridMaskColumn; dxDBGrid1Column10: TdxDBGridMaskColumn; dxDBGrid1Column11: TdxDBGridMaskColumn; dxDBGrid1Column24: TdxDBGridMaskColumn; dxDBGrid1Column25: TdxDBGridMaskColumn; dxDBGrid1Column26: TdxDBGridDateColumn; dxDBGrid1Column31: TdxDBGridMaskColumn; dxDBGrid1Column54: TdxDBGridMaskColumn; dxDBGrid1Column55: TdxDBGridMaskColumn; dxDBGrid1Column56: TdxDBGridColumn; dxDBGrid1Column57: TdxDBGridColumn; dxDBGrid11: TdxDBGridMaskColumn; dxDBGrid12: TdxDBGridMaskColumn; dxDBGrid13: TdxDBGridMaskColumn; dxDBGrid14: TdxDBGridMaskColumn; dxDBGrid15: TdxDBGridMaskColumn; dxDBGrid16: TdxDBGridMaskColumn; dxDBGrid17: TdxDBGridMaskColumn; dxDBGrid18: TdxDBGridMaskColumn; dxDBGrid19: TdxDBGridMaskColumn; dxDBGrid110: TdxDBGridMaskColumn; dxDBGrid1Column80: TdxDBGridMaskColumn; dxDBGrid1TEU: TdxDBGridMaskColumn; dxDBGrid1Column82: TdxDBGridMaskColumn; dxDBGrid1Column83: TdxDBGridMaskColumn; dxDBGrid1Column84: TdxDBGridDateColumn; dxDBGrid1Column89: TdxDBGridMaskColumn; dxDBGrid1Column90: TdxDBGridMaskColumn; dxDBGrid1Column92: TdxDBGridMaskColumn; dxDBGrid1Column85: TdxDBGridMaskColumn; dxDBGrid1Column87: TdxDBGridMaskColumn; dxDBGrid1Column86: TdxDBGridMaskColumn; dxDBGrid1USD: TdxDBGridColumn; dxDBGrid1RMB: TdxDBGridColumn; dxDBGrid1Column102: TdxDBGridColumn; dxDBGrid1Column105: TdxDBGridColumn; dxDBGrid1Column108: TdxDBGridColumn; dxDBGrid1Column111: TdxDBGridColumn; dxDBGrid1Column114: TdxDBGridColumn; dxDBGrid1Column115: TdxDBGridColumn; dxDBGrid1Column116: TdxDBGridColumn; dxDBGrid1Column117: TdxDBGridMaskColumn; dxDBGrid7: TdxDBGrid; dxDBGridMaskColumn93: TdxDBGridMaskColumn; dxDBGrid1Column68: TdxDBGridColumn; dxDBGrid1Column69: TdxDBGridColumn; PopupMenu2: TPopupMenu; N10: TMenuItem; N11: TMenuItem; N14: TMenuItem; N13: TMenuItem; N12: TMenuItem; N15: TMenuItem; N16: TMenuItem; XPMenu2: TXPMenu; bsSkinPanel1: TbsSkinPanel; dxDBGrid3: TdxDBGrid; dxDBGridMaskColumn39: TdxDBGridMaskColumn; dxDBGridMaskColumn42: TdxDBGridMaskColumn; dxDBGridMaskColumn47: TdxDBGridMaskColumn; dxDBGridDateColumn7: TdxDBGridDateColumn; dxDBGridMaskColumn75: TdxDBGridMaskColumn; t_salepriftset: TADOQuery; ds1: TDataSource; kbmThreadDataSet1: TkbmThreadDataSet; kbmBinaryStreamFormat1: TkbmBinaryStreamFormat; memtblrpt_total: TkbmMemTable; kbmMemTable1: TkbmMemTable; kbmMemTable2: TkbmMemTable; P_SUM: TkbmMemTable; DataSource1: TDataSource; DataSource2: TDataSource; DataSource3: TDataSource; DataSource4: TDataSource; dxDBGrid1Column51: TdxDBGridColumn; dxDBGrid1Column52: TdxDBGridColumn; dxDBGrid1Column53: TdxDBGridColumn; dxDBGrid1Column58: TdxDBGridColumn; dxDBGrid1Column59: TdxDBGridColumn; dxDBGrid1Column60: TdxDBGridColumn; dxDBGrid1Column61: TdxDBGridColumn; dxDBGrid3Column57: TdxDBGridColumn; dxDBGrid7Column12: TdxDBGridColumn; dxDBGrid7Column13: TdxDBGridColumn; dxDBGrid7Column14: TdxDBGridColumn; dxDBGrid7Column15: TdxDBGridColumn; dxDBGrid7Column16: TdxDBGridColumn; dxDBGrid7Column17: TdxDBGridColumn; dxDBGrid7Column18: TdxDBGridColumn; dxDBGrid7Column19: TdxDBGridColumn; dxDBGrid7Column20: TdxDBGridColumn; dxDBGrid1Column62: TdxDBGridColumn; dxDBGrid9: TdxDBGrid; dxDBGridMaskColumn77: TdxDBGridMaskColumn; dxDBGridColumn27: TdxDBGridColumn; dxDBGridColumn28: TdxDBGridColumn; dxDBGridColumn29: TdxDBGridColumn; dxDBGridColumn30: TdxDBGridColumn; dxDBGridColumn31: TdxDBGridColumn; dxDBGridColumn32: TdxDBGridColumn; dxDBGridColumn33: TdxDBGridColumn; dxDBGridColumn34: TdxDBGridColumn; dxDBGridColumn35: TdxDBGridColumn; dxDBGridColumn36: TdxDBGridColumn; dxDBGridColumn37: TdxDBGridColumn; dxDBGridColumn38: TdxDBGridColumn; dxDBGridColumn39: TdxDBGridColumn; dxDBGridColumn40: TdxDBGridColumn; dxDBGridColumn41: TdxDBGridColumn; dxDBGridColumn42: TdxDBGridColumn; dxDBGridColumn43: TdxDBGridColumn; dxDBGridColumn44: TdxDBGridColumn; dxDBGridColumn45: TdxDBGridColumn; dxDBGridColumn56: TdxDBGridColumn; bskntbsht1: TbsSkinTabSheet; dxDBGrid4: TdxDBGrid; dxDBGridMaskColumn78: TdxDBGridMaskColumn; dxDBGridMaskColumn79: TdxDBGridMaskColumn; dxDBGridMaskColumn80: TdxDBGridMaskColumn; dxDBGridDateColumn11: TdxDBGridDateColumn; dxDBGridMaskColumn81: TdxDBGridMaskColumn; dxDBGridMaskColumn82: TdxDBGridMaskColumn; dxDBGridMaskColumn83: TdxDBGridMaskColumn; dxDBGridMaskColumn84: TdxDBGridMaskColumn; dxDBGridMaskColumn85: TdxDBGridMaskColumn; dxDBGridMaskColumn86: TdxDBGridMaskColumn; dxDBGridMaskColumn87: TdxDBGridMaskColumn; dxDBGridDateColumn12: TdxDBGridDateColumn; dxDBGridDateColumn13: TdxDBGridDateColumn; dxDBGridDateColumn14: TdxDBGridDateColumn; dxDBGridMaskColumn88: TdxDBGridMaskColumn; dxDBGridMaskColumn89: TdxDBGridMaskColumn; dxDBGridMaskColumn90: TdxDBGridMaskColumn; dxDBGridMaskColumn91: TdxDBGridMaskColumn; dxDBGridMaskColumn92: TdxDBGridMaskColumn; dxDBGridMaskColumn94: TdxDBGridMaskColumn; dxDBGridColumn57: TdxDBGridColumn; dxDBGridColumn58: TdxDBGridColumn; dxDBGridMaskColumn95: TdxDBGridMaskColumn; dxDBGridMaskColumn96: TdxDBGridMaskColumn; dxDBGridMaskColumn97: TdxDBGridMaskColumn; dxDBGridMaskColumn98: TdxDBGridMaskColumn; dxDBGridMaskColumn99: TdxDBGridMaskColumn; dxDBGridMaskColumn100: TdxDBGridMaskColumn; dxDBGridMaskColumn101: TdxDBGridMaskColumn; dxDBGridMaskColumn102: TdxDBGridMaskColumn; dxDBGridMaskColumn103: TdxDBGridMaskColumn; dxDBGridMaskColumn104: TdxDBGridMaskColumn; dxDBGridMaskColumn105: TdxDBGridMaskColumn; dxDBGridMaskColumn106: TdxDBGridMaskColumn; dxDBGridMaskColumn107: TdxDBGridMaskColumn; dxDBGridMaskColumn108: TdxDBGridMaskColumn; dxDBGridDateColumn15: TdxDBGridDateColumn; dxDBGridMaskColumn109: TdxDBGridMaskColumn; dxDBGridMaskColumn110: TdxDBGridMaskColumn; dxDBGridMaskColumn111: TdxDBGridMaskColumn; dxDBGridMaskColumn112: TdxDBGridMaskColumn; dxDBGridMaskColumn113: TdxDBGridMaskColumn; dxDBGridMaskColumn114: TdxDBGridMaskColumn; dxDBGridMaskColumn115: TdxDBGridMaskColumn; dxDBGridColumn59: TdxDBGridColumn; dxDBGridColumn60: TdxDBGridColumn; dxDBGridColumn61: TdxDBGridColumn; dxDBGridColumn62: TdxDBGridColumn; dxDBGridColumn63: TdxDBGridColumn; dxDBGridColumn64: TdxDBGridColumn; dxDBGridColumn65: TdxDBGridColumn; dxDBGridColumn66: TdxDBGridColumn; dxDBGridColumn67: TdxDBGridColumn; dxDBGridMaskColumn116: TdxDBGridMaskColumn; dxDBGridColumn68: TdxDBGridColumn; dxDBGridColumn69: TdxDBGridColumn; dxDBGridColumn70: TdxDBGridColumn; dxDBGridColumn71: TdxDBGridColumn; kbmMemTable4: TkbmMemTable; DataSource5: TDataSource; dxDBGrid7Column22: TdxDBGridColumn; P_SUMField: TStringField; P_SUMField2: TFloatField; P_SUMField3: TFloatField; P_SUMField4: TFloatField; P_SUMField5: TFloatField; P_SUMField6: TFloatField; P_SUMField7: TFloatField; P_SUMField8: TFloatField; P_SUMField9: TFloatField; P_SUMField10: TFloatField; P_SUMField11: TFloatField; P_SUMField12: TFloatField; P_SUMField13: TFloatField; P_SUMField14: TFloatField; P_SUMField15: TFloatField; P_SUMField16: TFloatField; bskntbsht2: TbsSkinTabSheet; bsSkinPageControl3: TbsSkinPageControl; bskntbshtpg1: TbsSkinTabSheet; bskntbsht3: TbsSkinTabSheet; dxDBGrid2: TdxDBGrid; dxDBGridMaskColumn32: TdxDBGridMaskColumn; dxDBGridMaskColumn33: TdxDBGridMaskColumn; dxDBGridMaskColumn34: TdxDBGridMaskColumn; dxDBGridMaskColumn35: TdxDBGridMaskColumn; dxDBGridMaskColumn36: TdxDBGridMaskColumn; dxDBGridMaskColumn37: TdxDBGridMaskColumn; dxDBGridColumn10: TdxDBGridColumn; dxDBGridColumn11: TdxDBGridColumn; dxDBGridColumn47: TdxDBGridColumn; memtblDetail: TkbmMemTable; StringField1: TStringField; FloatField1: TFloatField; FloatField2: TFloatField; FloatField3: TFloatField; FloatField4: TFloatField; FloatField5: TFloatField; FloatField7: TFloatField; FloatField8: TFloatField; FloatField15: TFloatField; memtblDetailField: TStringField; memtblDetailField2: TDateTimeField; memtblDetailField3: TStringField; memtblDetailField4: TStringField; memtblDetailField5: TDateTimeField; memtblDetailField6: TStringField; memtblDetailField7: TFloatField; memtblLX: TkbmMemTable; StringField2: TStringField; StringField3: TStringField; DateTimeField1: TDateTimeField; DateTimeField2: TDateTimeField; StringField6: TStringField; FloatField10: TFloatField; FloatField11: TFloatField; FloatField19: TFloatField; memtblLXField: TIntegerField; memtblLXField2: TFloatField; memtblDetailField8: TStringField; memtblDetailField9: TStringField; memtblLXField3: TStringField; memtblLXField4: TStringField; DataSource6: TDataSource; DataSource7: TDataSource; dxDBGrid2Column11: TdxDBGridColumn; dxDBGrid2Column12: TdxDBGridColumn; dxDBGrid2Column13: TdxDBGridColumn; dxDBGrid2Column14: TdxDBGridColumn; dxDBGrid2Column15: TdxDBGridColumn; dxDBGrid2Column16: TdxDBGridColumn; dxDBGrid2Column17: TdxDBGridColumn; dxDBGrid5: TdxDBGrid; dxDBGridMaskColumn1: TdxDBGridMaskColumn; dxDBGridMaskColumn2: TdxDBGridMaskColumn; dxDBGridMaskColumn3: TdxDBGridMaskColumn; dxDBGridColumn1: TdxDBGridColumn; dxDBGridColumn2: TdxDBGridColumn; dxDBGridColumn3: TdxDBGridColumn; dxDBGridColumn5: TdxDBGridColumn; dxDBGridColumn6: TdxDBGridColumn; dxDBGridColumn8: TdxDBGridColumn; memtblDetailField10: TStringField; memtblDetailField11: TStringField; memtblDetailField12: TDateTimeField; memtblDetailField13: TDateTimeField; memtblLXField5: TFloatField; P_SUMField17: TFloatField; dxDBGrid2Column18: TdxDBGridColumn; dxDBGrid2Column19: TdxDBGridColumn; P_SUMField18: TFloatField; dxDBGrid7Column21: TdxDBGridColumn; dxDBGrid3Column7: TdxDBGridColumn; dxDBGrid3Column8: TdxDBGridColumn; dxDBGrid3Column9: TdxDBGridColumn; dxDBGrid3Column10: TdxDBGridColumn; dxDBGrid3Column11: TdxDBGridColumn; dxDBGrid3Column12: TdxDBGridColumn; dxDBGrid3Column13: TdxDBGridColumn; dxDBGrid3Column14: TdxDBGridColumn; dxDBGrid3Column15: TdxDBGridColumn; kbmMemTable2Field: TStringField; kbmMemTable2Field2: TStringField; kbmMemTable2Field3: TStringField; kbmMemTable2Field4: TDateField; kbmMemTable2Field5: TStringField; kbmMemTable2USD: TFloatField; kbmMemTable2RMB: TFloatField; kbmMemTable2Field6: TFloatField; kbmMemTable2USD2: TFloatField; kbmMemTable2RMB2: TFloatField; kbmMemTable2Field7: TFloatField; kbmMemTable2USD3: TFloatField; kbmMemTable2RMB3: TFloatField; kbmMemTable2Field8: TFloatField; kbmMemTable2Field9: TFloatField; kbmMemTable2Field10: TStringField; kbmMemTable2USD4: TFloatField; kbmMemTable2RMB4: TFloatField; kbmMemTable2Field11: TFloatField; dxDBGrid3Column16: TdxDBGridColumn; dxDBGrid3Column17: TdxDBGridColumn; dxDBGrid3Column18: TdxDBGridColumn; memtblDetailField14: TFloatField; memtblDetailField15: TFloatField; memtblDetailField16: TFloatField; memtblDetailField17: TFloatField; Saleprofitsum: TADOQuery; dxDBGrid2Column20: TdxDBGridColumn; dxDBGrid2Column21: TdxDBGridColumn; dxDBGrid2Column22: TdxDBGridColumn; dxDBGrid2Column23: TdxDBGridColumn; bsSkinRadioGroup1: TbsSkinRadioGroup; memtblDetailField18: TDateField; dxDBGrid2Column24: TdxDBGridColumn; dxDBGrid2Column25: TdxDBGridColumn; memtblDetailField19: TStringField; memtblDetailField20: TStringField; dxDBGrid2Column26: TdxDBGridColumn; memtblDetailField21: TIntegerField; dxDBGrid2Column27: TdxDBGridColumn; dxDBGrid2Column28: TdxDBGridColumn; dxDBGrid2Column29: TdxDBGridColumn; memtblDetailRMB: TFloatField; memtblDetailUSD: TFloatField; memtblDetailField22: TFloatField; dxDBGrid2Column30: TdxDBGridColumn; kbmMemTable3: TkbmMemTable; kbmMemTable3Field: TStringField; kbmMemTable3Field2: TFloatField; memtblDetailField23: TStringField; dxDBGrid2Column31: TdxDBGridColumn; memtblDetailField24: TStringField; dxDBGrid2Column32: TdxDBGridColumn; dxDBGrid2Column33: TdxDBGridCheckColumn; memtblDetailField25: TIntegerField; memtblDetailField26: TStringField; dxDBGrid2Column34: TdxDBGridColumn; bsSkinButton1: TbsSkinButton; bsSkinButton2: TbsSkinButton; bsSkinButton10: TbsSkinButton; bsSkinButton9: TbsSkinButton; bsSkinButton5: TbsSkinButton; bsSkinCheckRadioBox1: TbsSkinCheckRadioBox; bsSkinLabel1: TbsSkinLabel; bsSkinEdit1: TbsSkinEdit; Label4: TLabel; bsSkinComboBox2: TbsSkinComboBox; Label14: TLabel; Label22: TLabel; RxDBLookupCombo3: TRxDBLookupCombo; RxDBLookupCombo10: TRxDBLookupCombo; Label3: TLabel; wwDBComboBox1: TwwDBComboBox; bsSkinComboBox1: TbsSkinComboBox; Label1: TLabel; Label2: TLabel; wwDBComboBox20: TwwDBComboBox; RxDBLookupCombo2: TRxDBLookupCombo; Label9: TLabel; memtblDetailField27: TStringField; dxDBGrid2Column35: TdxDBGridColumn; bsSkinCheckRadioBox2: TbsSkinCheckRadioBox; bsSkinTabSheet5: TbsSkinTabSheet; dxDBGrid6: TdxDBGrid; kbmtc: TkbmMemTable; kbmtc1: TDataSource; kbmqc: TkbmMemTable; kbmqc1: TDataSource; kbmtcField: TStringField; kbmtcField2: TFloatField; kbmtcField3: TFloatField; kbmqcField: TStringField; kbmqcField2: TStringField; kbmqcField3: TStringField; kbmqcField4: TStringField; kbmqcField5: TDateField; kbmqcField6: TDateField; kbmqcField7: TFloatField; kbmqcField8: TFloatField; dxDBGrid8: TdxDBGrid; dxDBGridColumn4: TdxDBGridColumn; dxDBGridColumn7: TdxDBGridColumn; dxDBGridColumn9: TdxDBGridColumn; dxDBGrid6Column1: TdxDBGridColumn; dxDBGrid6Column2: TdxDBGridColumn; dxDBGrid6Column3: TdxDBGridColumn; dxDBGrid6Column4: TdxDBGridColumn; kbmqcField9: TStringField; dxDBGrid6Column5: TdxDBGridColumn; dxDBGrid6Column6: TdxDBGridColumn; dxDBGrid6Column7: TdxDBGridColumn; dxDBGrid6Column8: TdxDBGridColumn; kbmqcField10: TIntegerField; dxDBGrid6Column9: TdxDBGridColumn; kbmqcField11: TIntegerField; dxDBGrid6Column10: TdxDBGridColumn; kbmqcField12: TFloatField; dxDBGrid6Column11: TdxDBGridColumn; kbmtcUSD: TFloatField; kbmtcRMB: TFloatField; kbmtcField4: TFloatField; kbmtcField5: TStringField; dxDBGrid8Column4: TdxDBGridColumn; dxDBGrid8Column5: TdxDBGridColumn; dxDBGrid8Column6: TdxDBGridColumn; dxDBGrid8Column7: TdxDBGridColumn; kbmtcField6: TFloatField; dxDBGrid8Column8: TdxDBGridColumn; kbmqcField13: TStringField; dxDBGrid6Column12: TdxDBGridColumn; kbmqcUSD: TFloatField; kbmqcRMB: TFloatField; PopupMenu1: TPopupMenu; MenuItem7: TMenuItem; bsSkinPanel2: TbsSkinPanel; wwDBDateTimePicker1: TwwDBDateTimePicker; wwDBDateTimePicker2: TwwDBDateTimePicker; Label5: TLabel; Label6: TLabel; kbmqcField14: TDateField; kbmqcRMB2: TFloatField; kbmqcUSD2: TFloatField; kbmqcField15: TFloatField; dxDBGrid6Column15: TdxDBGridColumn; dxDBGrid6Column16: TdxDBGridColumn; dxDBGrid6Column17: TdxDBGridColumn; dxDBGrid6Column18: TdxDBGridColumn; bsSkinButton3: TbsSkinButton; kbmqcField16: TStringField; dxDBGrid6Column19: TdxDBGridColumn; N1: TMenuItem; Label7: TLabel; Edit1: TEdit; Label8: TLabel; tex: TbsSkinButton; Edit2: TEdit; 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 N12Click(Sender: TObject); procedure N16Click(Sender: TObject); procedure bsSkinButton10Click(Sender: TObject); procedure dxDBGrid2DblClick(Sender: TObject); procedure bsSkinButton1Click(Sender: TObject); procedure bsSkinButton2Click(Sender: TObject); procedure dxDBGrid2CustomDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxDBTreeListColumn; const AText: String; AFont: TFont; var AColor: TColor; ASelected, AFocused: Boolean; var ADone: Boolean); procedure MenuItem7Click(Sender: TObject); procedure bsSkinButton3Click(Sender: TObject); procedure texClick(Sender: TObject); private function GetSALEprofit(SALE:string;aMonth:Integer;profit:Double;tuo:boolean):Double; procedure GetProfit; procedure GetProfitall; procedure Getlx; procedure Getcq; procedure GetProfitSum; procedure GetProfitSumall; procedure GetProfittcLx; function GetBetwMonth(aBe,aEe:TDate):Integer; function issameMonth(aBe,aEe:TDate):Boolean; { Private declarations } public bdatestr:String; { Public declarations } procedure UpdateBsProfit(bstype,bsno:String;fee:integer); function CalcProftAmttc(ProftAmt:Double;Employee:string):Double; function getzq(cust: string;aDate:TDateTime):TDateTime; function CalcProftAmtqx(ProftAmt:Double;Employee:string):Double; function getzqtype(cust: string;aDate:TDateTime):string; end; var frm_rp_sales_profit: Tfrm_rp_sales_profit; rp_rp_total_open:boolean; implementation uses u_main, my_sys_function, u_rp_query, u_sys_progress, u_data_share; {$R *.dfm} function Tfrm_rp_sales_profit.getzqtype(cust: string;aDate:TDateTime):string; var aQuery:TAdoQuery; begin result:='现结买单'; aQuery:=CreateAdoQuery; try with aQuery do begin close;sql.Clear; sql.Add('select 客户简称,结费类型,结费期限,类型模式,结费日期,结费金额'); sql.Add('from t_crm_client_sales'); sql.Add('where 客户简称='''+cust+''''); sql.Add('and 开始日期<=:Date1 and 结束日期>=:date2'); Parameters.ParamByName('Date1').Value:=aDate; Parameters.ParamByName('Date2').Value:=aDate; open;First; if IsEmpty then begin end else begin result:=Trim(fieldbyname('结费类型').asString); end; end; finally FreeAndNil(aQuery); end; end; function Tfrm_rp_sales_profit.getzq(cust: string;aDate:TDateTime):TDateTime; var aQuery:TAdoQuery; begin result:=0; aQuery:=CreateAdoQuery; try with aQuery do begin close;sql.Clear; sql.Add('select 客户简称,结费类型,结费期限,类型模式,结费日期,结费金额'); sql.Add('from t_crm_client_sales'); sql.Add('where 客户简称='''+cust+''''); sql.Add('and 开始日期<=:Date1 and 结束日期>=:date2'); Parameters.ParamByName('Date1').Value:=aDate; Parameters.ParamByName('Date2').Value:=aDate; open;First; if IsEmpty then begin result:=aDate; end else begin if Trim(fieldbyname('结费类型').asString)='现结买单' then result:=aDate else if Trim(fieldbyname('结费类型').asString)='约定天数' then result:=aDate+fieldbyname('结费期限').AsFloat else if Trim(fieldbyname('结费类型').asString)='约定时间' then begin if DaysInMonth(IncMonth(aDate,fieldbyname('类型模式').Asinteger))>fieldbyname('结费日期').Asinteger then begin result:=EncodeDate(Yearof(IncMonth(aDate,fieldbyname('类型模式').Asinteger)),Monthof(IncMonth(aDate,fieldbyname('类型模式').Asinteger)),fieldbyname('结费日期').Asinteger); end else begin result:=EncodeDate(Yearof(IncMonth(aDate,fieldbyname('类型模式').Asinteger)),Monthof(IncMonth(aDate,fieldbyname('类型模式').Asinteger)),DaysInMonth(IncMonth(aDate,fieldbyname('类型模式').Asinteger))); end; end; end; end; finally FreeAndNil(aQuery); end; end; function Tfrm_rp_sales_profit.CalcProftAmttc(ProftAmt:Double;Employee:string):Double; var aAdoQueryProfitPlan,aAdoQueryProfitPlanItem:TAdoQuery; PlanName:string; begin result:=0; PlanName:=''; aAdoQueryProfitPlan:=CreateAdoQuery; aAdoQueryProfitPlanItem:=CreateAdoQuery; with aAdoQueryProfitPlan do begin Close;SQL.Clear; SQL.Add('select 提成方案 from t_sys_employee'); SQL.Add('Where 姓名=:Employee'); Parameters.ParamByName('Employee').Value:=Employee; Open; PlanName:=FieldByName('提成方案').AsString; end; if PlanName='' then Exit; with aAdoQueryProfitPlanItem do try Close;SQL.Clear; SQL.Add(' select distinct 利润起,利润止,本月结提成比例 from t_crm_salesproftSet'); SQL.Add('where 方案名称=:PlanName'); SQL.Add('Order by 利润起 '); Parameters.ParamByName('PlanName').Value:=trim(PlanName); Open;First; while not eof do begin if ProftAmt>=FieldByName('利润止').AsFloat then begin result:=result+(FieldByName('利润止').AsFloat-FieldByName('利润起').AsFloat)*FieldByName('本月结提成比例').AsFloat/100; end else begin if (ProftAmt>FieldByName('利润起').AsFloat) and (ProftAmt<=FieldByName('利润止').AsFloat) then begin result:=result+(ProftAmt-FieldByName('利润起').AsFloat)*FieldByName('本月结提成比例').AsFloat/100; end end; Next; end; finally Free; aAdoQueryProfitPlan.Free; end; end; function Tfrm_rp_sales_profit.CalcProftAmtqx(ProftAmt:Double;Employee:string):Double; var aAdoQueryProfitPlan,aAdoQueryProfitPlanItem:TAdoQuery; PlanName:string; begin result:=0; PlanName:=''; aAdoQueryProfitPlan:=CreateAdoQuery; aAdoQueryProfitPlanItem:=CreateAdoQuery; with aAdoQueryProfitPlan do begin Close;SQL.Clear; SQL.Add('select 提成方案 from t_sys_employee'); SQL.Add('Where 姓名=:Employee'); Parameters.ParamByName('Employee').Value:=Employee; Open; PlanName:=FieldByName('提成方案').AsString; end; if PlanName='' then Exit; with aAdoQueryProfitPlanItem do try Close;SQL.Clear; SQL.Add(' select distinct 开始天数,结束天数,扣息百分比 from t_crm_saleslxSet'); SQL.Add('where 方案名称=:PlanName'); SQL.Add('Order by 开始天数 '); Parameters.ParamByName('PlanName').Value:=trim(PlanName); Open;First; while not eof do begin if ProftAmt>0 then if (ProftAmt>FieldByName('开始天数').AsFloat) and (ProftAmt<=FieldByName('结束天数').AsFloat) then begin result:=FieldByName('扣息百分比').AsFloat; end; Next; end; finally Free; aAdoQueryProfitPlan.Free; end; end; procedure Tfrm_rp_sales_profit.GetProfittcLx; var betd,eetd:TDate; aquery,bquery:TADOQuery; str:String; begin if bsSkinRadioGroup1.ItemIndex=1 then bdatestr:='会计期间' else bdatestr:='开船日期'; kbmtc.EmptyTable; kbmtc.Open; betd:=EncodeDate(StrToInt(wwDBComboBox20.Text), StrToInt(wwDBComboBox1.Text), 1); eetd:=EncodeDate(StrToInt(wwDBComboBox20.Text), StrToInt(wwDBComboBox1.Text), MonthDays[isLeapYear(StrToInt(wwDBComboBox20.Text)),StrToInt(wwDBComboBox1.Text)]); aQuery:=CreateAdoQuery; bQuery:=CreateAdoQuery; with aQuery do try Close;SQL.Clear; if bsSkinCheckRadioBox1.Checked then //利润RMB,利润USD str:='select 揽货人,sum(毛利润) as 毛利润,sum(利润RMB) as 利润RMB,sum(利润USD) as 利润USD from v_op_bscard where 合计应收=合计已收 and ' else str:='select 揽货人,sum(毛利润) as 毛利润,sum(利润RMB) as 利润RMB,sum(利润USD) as 利润USD from v_op_bscard where 1=1 and '; str:=Str+' '+bdatestr+'>='+''''+DateToStr(betd)+''''; str:=Str+' and '+bdatestr+'<='+''''+DateToStr(eetd)+''''; 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+''''; case bsSkinComboBox1.itemindex of 1: str:=Str+' and (fee2=0 or fee2 is null) '; 2: str:=Str+' and (fee2=1) '; end; case bsSkinComboBox2.itemindex of 1: str:=Str+' and 费用状态=''录入状态'''; 2: str:=Str+' and 费用状态=''费用封帐'''; end; SQL.Add(str); SQL.Add(' group by 揽货人 order by 揽货人'); Open;First; while not eof do begin kbmtc.insert; kbmtc.FieldByName('揽货人').AsString:=FieldByName('揽货人').AsString; kbmtc.FieldByName('利润RMB').AsFloat:=FieldByName('利润RMB').AsFloat; kbmtc.FieldByName('利润USD').AsFloat:=FieldByName('利润USD').AsFloat; kbmtc.FieldByName('毛利润').AsFloat:=FieldByName('毛利润').AsFloat; kbmtc.FieldByName('汇率').AsFloat:=getUsdExRate(DateToStr(betd),'USD'); kbmtc.FieldByName('年月').AsString:=FormatDateTime('YYMM',betd); kbmtc.FieldByName('应提成').AsString:=FormatFloat('0.00;-0.00;',CalcProftAmttc(FieldByName('毛利润').AsFloat,FieldByName('揽货人').AsString)); kbmtc.Post; Next; end; /// { Close;SQL.Clear; str:='select 编号,揽货人,主提单号,委托编号,委托单位,开船日期,(应收RMB-已收RMB) 未收RMB,(应收USD- 已收USD) 未收USD,(合计应收- 合计已收) 未收合计,应收RMB,应收USD,合计应收 应收合计 from v_op_bscard where 1=1 and '; str:=Str+' '+bdatestr+'>='+''''+DateToStr(wwDBDateTimePicker1.Date)+''''; str:=Str+' and '+bdatestr+'<='+''''+DateToStr(wwDBDateTimePicker2.Date)+''''; 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+''''; case bsSkinComboBox1.itemindex of 1: str:=Str+' and (fee2=0 or fee2 is null) '; 2: str:=Str+' and (fee2=1) '; end; case bsSkinComboBox2.itemindex of 1: str:=Str+' and 费用状态=''录入状态'''; 2: str:=Str+' and 费用状态=''费用封帐'''; end; SQL.Add(str); SQL.Add(' and 委托单位 in (select 客户简称 from t_crm_client_sales)'); SQL.Add(' order by 揽货人'); Open;First; kbmqc.EmptyTable; kbmqc.Open; while not eof do begin kbmqc.insert; kbmqc.FieldByName('编号').AsString:=FieldByName('编号').AsString; kbmqc.FieldByName('揽货人').AsString:=FieldByName('揽货人').AsString; kbmqc.FieldByName('主提单号').AsString:=FieldByName('主提单号').AsString; kbmqc.FieldByName('委托编号').AsString:=FieldByName('委托编号').AsString; kbmqc.FieldByName('客户名称').AsString:=FieldByName('委托单位').AsString; kbmqc.FieldByName('开船日期').AsDateTime:=FieldByName('开船日期').AsDateTime; kbmqc.FieldByName('未收RMB').AsFloat:=FieldByName('未收RMB').AsFloat; kbmqc.FieldByName('未收USD').AsFloat:=FieldByName('未收USD').AsFloat; kbmqc.FieldByName('未收合计').AsFloat:=FieldByName('未收合计').AsFloat; kbmqc.FieldByName('应收RMB').AsFloat:=FieldByName('应收RMB').AsFloat; kbmqc.FieldByName('应收USD').AsFloat:=FieldByName('应收USD').AsFloat; kbmqc.FieldByName('应收合计').AsFloat:=FieldByName('应收合计').AsFloat; kbmqc.FieldByName('应结日期').AsDateTime:=getzq(kbmqc.FieldByName('客户名称').AsString,kbmqc.FieldByName('开船日期').AsDateTime); bQuery.Close; bQuery.SQL.Clear; bQuery.SQL.Add('select top 1 结算日期 from v_fee_do_jie where 业务编号='''+kbmqc.FieldByName('编号').AsString+''' order by 结算日期 DESC '); bQuery.Open; if not bQuery.IsEmpty then begin kbmqc.FieldByName('结算日期').VALUE:=bQuery.FieldByName('结算日期').AsDateTime; end; kbmqc.FieldByName('结费类型').AsString:=getzqtype(kbmqc.FieldByName('客户名称').AsString,kbmqc.FieldByName('开船日期').AsDateTime); kbmqc.FieldByName('宽限天数').AsInteger:=StrToInt(bsSkinEdit1.text); if (DaysBetween(Date,kbmqc.FieldByName('应结日期').AsDateTime)-kbmqc.FieldByName('宽限天数').AsInteger)>0 then begin if not kbmqc.FieldByName('结算日期').IsNull then begin if kbmqc.FieldByName('结算日期').AsDateTime>kbmqc.FieldByName('应结日期').AsDateTime then kbmqc.FieldByName('扣息天数').AsInteger:=DaysBetween(kbmqc.FieldByName('结算日期').AsDateTime,kbmqc.FieldByName('应结日期').AsDateTime)-kbmqc.FieldByName('宽限天数').AsInteger else kbmqc.FieldByName('扣息天数').AsInteger:=0; kbmqc.FieldByName('扣息百分比').AsFloat:=CalcProftAmtqx(kbmqc.FieldByName('扣息天数').AsFloat,kbmqc.FieldByName('揽货人').AsString); if trim(kbmqc.FieldByName('结费类型').AsString)<>'现结买单' then kbmqc.FieldByName('利息').AsString:=FormatFloat('0.00;-0.00;0',kbmqc.FieldByName('扣息百分比').AsFloat/100*kbmqc.FieldByName('应收合计').AsFloat*kbmqc.FieldByName('扣息天数').AsInteger); end else begin if Date>kbmqc.FieldByName('应结日期').AsDateTime then kbmqc.FieldByName('扣息天数').AsInteger:=DaysBetween(Date,kbmqc.FieldByName('应结日期').AsDateTime)-kbmqc.FieldByName('宽限天数').AsInteger else kbmqc.FieldByName('扣息天数').AsInteger:=0; kbmqc.FieldByName('扣息百分比').AsFloat:=CalcProftAmtqx(kbmqc.FieldByName('扣息天数').AsFloat,kbmqc.FieldByName('揽货人').AsString); if trim(kbmqc.FieldByName('结费类型').AsString)<>'现结买单' then kbmqc.FieldByName('利息').AsString:=FormatFloat('0.00;-0.00;0',kbmqc.FieldByName('扣息百分比').AsFloat/100*kbmqc.FieldByName('应收合计').AsFloat*kbmqc.FieldByName('扣息天数').AsInteger); end; if kbmtc.Locate('揽货人',Trim(kbmqc.FieldByName('揽货人').AsString),[]) then begin kbmtc.Edit; kbmtc.FieldByName('扣息').AsFloat:=kbmtc.FieldByName('扣息').AsFloat+kbmqc.FieldByName('利息').AsFloat; kbmtc.Post; end; try kbmqc.Post; except on e:Exception do begin ShowMessage(e.Message); end; end; end; Next; end; } finally FreeAndNil(aquery); end; end; procedure Tfrm_rp_sales_profit.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; procedure Tfrm_rp_sales_profit.bsSkinButton5Click(Sender: TObject); begin close; end; function Tfrm_rp_sales_profit.GetSALEprofit(SALE:string;aMonth:Integer;profit:Double;tuo:boolean):Double; var aQuery:TADOQuery; BL:Double; begin BL:=0.00; if profit=0 then begin result:=0.0; exit; end; aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select * from t_crm_salesproftSet where 结费月份='+inttostr(aMonth)+' and 方案名称=(select 提成方案 from t_sys_employee where 姓名='''+SALE+''') Order by 利润起 ASC'); Open; first; while not eof do begin if (Profit>FieldByName('利润起').AsFloat) and (Profit<=FieldByName('利润止').AsFloat) then begin if tuo then begin BL:=FieldByName('本月结提成比例').AsFloat; end else begin if aMonth<>0 then BL:=FieldByName('拖至本月结提成比例').AsFloat else BL:=FieldByName('本月结提成比例').AsFloat; end; end; Next; end; Result:=BL; end; finally FreeAndNil(aQuery); end; end; procedure Tfrm_rp_sales_profit.FormClose(Sender: TObject; var Action: TCloseAction); var inifile1:Tinifile; begin savereggrid(dxdbgrid1,caption+'1'); savereggrid(dxdbgrid2,caption+'2'); savereggrid(dxdbgrid3,caption+'3'); savereggrid(dxdbgrid9,caption+'9'); savereggrid(dxdbgrid6,caption+'6'); frm_rp_sales_profit.Hide; frm_rp_sales_profit.ManualFloat(frm_rp_sales_profit.BoundsRect ); frm_main.freeTabs('frm_rp_sales_profit'); action:=cafree; frm_rp_sales_profit:=nil; inifile1:=Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini'); inifile1.WriteString('TC','DAYS',bsSkinEdit1.text); inifile1.free; end; procedure Tfrm_rp_sales_profit.FormShow(Sender: TObject); var bYear,bMonth,bDate:Word; inifile1:Tinifile; begin DecodeDate(incmonth(Now,-5),bYear,bMonth,bDate); wwDBComboBox20.Text:=IntToStr(bYear); wwDBComboBox20.Text:=IntToStr(YearOf(date)); wwDBComboBox1.Text:=IntToStr(bMonth); loadreggrid(dxdbgrid1,true,caption+'1'); loadreggrid(dxdbgrid2,true,caption+'2'); loadreggrid(dxdbgrid3,false,caption+'3'); loadreggrid(dxdbgrid4,false,caption+'4'); loadreggrid(dxdbgrid9,false,caption+'9'); loadreggrid(dxdbgrid6,false,caption+'6'); wwDBDateTimePicker1.Date:=Date; wwDBDateTimePicker2.Date:=Date; inifile1:=Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini'); bsSkinEdit1.text:=inifile1.Readstring('TC','DAYS','0'); inifile1.free; end; procedure Tfrm_rp_sales_profit.bsSkinButton9Click(Sender: TObject); begin sys_print('业务综合统计',2,nil,nil,nil,DataSource4,DataSource6,DataSource7,DataSource3,kbmtc1,kbmqc1,nil,nil); end; procedure Tfrm_rp_sales_profit.N10Click(Sender: TObject); begin if bsSkinTabSheet1.Showing then begin if bskntbsht2.Showing then begin if bskntbshtpg1.Showing then begin update_grid_view_no(dxdbgrid2); exit; end; if bskntbsht3.Showing then begin update_grid_view_no(dxdbgrid5); exit; end; end; if bsSkinTabSheet11.Showing then begin update_grid_view_no(dxdbgrid1); exit; end; if bskntbsht1.Showing then begin update_grid_view_no(dxdbgrid4); exit; end; if bsSkinTabSheet13.Showing then begin update_grid_view_no(dxdbgrid3); exit; end; end else begin if bsSkinTabSheet4.Showing then begin update_grid_view_no(dxdbgrid7); exit; end; end; end; procedure Tfrm_rp_sales_profit.N14Click(Sender: TObject); begin if bsSkinTabSheet1.Showing then begin if bskntbsht2.Showing then begin if bskntbshtpg1.Showing then begin update_grid_view_all(dxdbgrid2); exit; end; if bskntbsht3.Showing then begin update_grid_view_all(dxdbgrid5); exit; end; end; if bsSkinTabSheet11.Showing then begin update_grid_view_all(dxdbgrid1); exit; end; if bskntbsht1.Showing then begin update_grid_view_all(dxdbgrid4); exit; end; if bsSkinTabSheet13.Showing then begin update_grid_view_all(dxdbgrid3); exit; end; end else begin if bsSkinTabSheet4.Showing then begin update_grid_view_all(dxdbgrid7); exit; end; end; end; procedure Tfrm_rp_sales_profit.N12Click(Sender: TObject); begin { if bsSkinTabSheet1.Showing then begin if bsSkinTabSheet11.Showing then begin update_grid(dxdbgrid1,108); exit; end; if bsSkinTabSheet12.Showing then begin update_grid(dxdbgrid2,109); exit; end; if bsSkinTabSheet13.Showing then begin update_grid(dxdbgrid3,110); exit; end; if bskntbsht1.Showing then begin update_grid(dxdbgrid4,111); exit; end; end; if bsSkinTabSheet4.Showing then begin update_grid(dxdbgrid7,112); exit; end; if bsSkinTabSheet6.Showing then begin update_grid(dxdbgrid9,95); exit; end; } end; procedure Tfrm_rp_sales_profit.N16Click(Sender: TObject); begin if bsSkinTabSheet1.Showing then begin if bskntbsht2.Showing then begin if bskntbshtpg1.Showing then begin grid_save_xls(dxdbgrid2); exit; end; if bskntbsht3.Showing then begin grid_save_xls(dxdbgrid5); exit; end; end; if bsSkinTabSheet11.Showing then begin grid_save_xls(dxdbgrid1); exit; end; if bskntbsht1.Showing then begin grid_save_xls(dxdbgrid4); exit; end; if bsSkinTabSheet13.Showing then begin grid_save_xls(dxdbgrid3); exit; end; end else begin if bsSkinTabSheet4.Showing then begin grid_save_xls(dxdbgrid7); exit; end; end; { if bsSkinTabSheet1.Showing then begin if bsSkinTabSheet11.Showing then begin grid_save_xls(dxdbgrid1); exit; end; if bsSkinTabSheet12.Showing then begin grid_save_xls(dxdbgrid2); exit; end; if bsSkinTabSheet13.Showing then begin grid_save_xls(dxdbgrid3); exit; end; if bskntbsht1.Showing then begin grid_save_xls(dxdbgrid4); exit; end; end; if bsSkinTabSheet4.Showing then begin grid_save_xls(dxdbgrid7); exit; end; if bsSkinTabSheet6.Showing then begin grid_save_xls(dxdbgrid9); exit; end; } end; procedure Tfrm_rp_sales_profit.bsSkinButton10Click(Sender: TObject); var betd,eetd:TDate; aquery:TADOQuery; str:String; begin if bsSkinCheckRadioBox2.Checked then begin GetProfittcLx; end else begin if bsSkinRadioGroup1.ItemIndex=1 then bdatestr:='会计期间' else bdatestr:='开船日期'; //showmessage('1'); memtblrpt_total.EmptyTable; kbmMemTable2.EmptyTable; kbmMemTable1.EmptyTable; kbmMemTable4.EmptyTable; memtblDetail.EmptyTable; memtblLX.EmptyTable; P_SUM.EmptyTable; //showmessage('2'); betd:=EncodeDate(StrToInt(wwDBComboBox20.Text), StrToInt(wwDBComboBox1.Text), 1); eetd:=EncodeDate(StrToInt(wwDBComboBox20.Text), StrToInt(wwDBComboBox1.Text), MonthDays[isLeapYear(StrToInt(wwDBComboBox20.Text)),StrToInt(wwDBComboBox1.Text)]); aQuery:=CreateAdoQuery; try Saleprofitsum.Close; Saleprofitsum.sql.clear; Saleprofitsum.SQL.Add('select 揽货人,sum(毛利润) as 毛利润 from v_op_bscard where '+bdatestr+'>='''+DateToStr(betd)+''' and '+bdatestr+'<='''+DateToStr(eetd)+''' group by 揽货人 order by 揽货人'); // showmessage(Saleprofitsum.SQL.text); Saleprofitsum.Open; // showmessage('30'); with aQuery do begin Close;SQL.Clear; if bsSkinCheckRadioBox1.Checked then str:='select * from v_op_bscard_MAX where 合计应收=合计已收 and ' else str:='select * from v_op_bscard where 1=1 and '; str:=Str+' '+bdatestr+'>='+''''+DateToStr(betd)+''''; str:=Str+' and '+bdatestr+'<='+''''+DateToStr(eetd)+''''; 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+''''; case bsSkinComboBox1.itemindex of 1: str:=Str+' and (fee2=0 or fee2 is null) '; 2: str:=Str+' and (fee2=1) '; end; case bsSkinComboBox2.itemindex of 1: str:=Str+' and 费用状态=''录入状态'''; 2: str:=Str+' and 费用状态=''费用封帐'''; end; str:=Str+' and 委托单位 not in (select 客户简称 from t_crm_client_sales where 是否特批客户=1) '; SQL.Add(str); try // showmessage('31'); Open; // showmessage('32'); memtblrpt_total.LoadFromDataSet(aQuery,[mtcpostructure,mtcpoProperties,mtcpoFieldIndex]); except on e:exception do begin SHOWMESSAGE(E.Message); end; end; //showmessage('3'); Close;SQL.Clear; str:='select *,毛利润*0.05 as 提成 from v_op_bscard where 1=1 and '; str:=Str+' '+bdatestr+'>='+''''+DateToStr(betd)+''''; str:=Str+' and '+bdatestr+'<='+''''+DateToStr(eetd)+''''; 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+''''; str:=Str+' and 委托单位 in (select 客户简称 from t_crm_client_sales where 是否特批客户=1) '; SQL.Add(str); try Open; kbmMemTable4.LoadFromDataSet(aQuery,[mtcpostructure,mtcpoProperties,mtcpoFieldIndex]); except on e:exception do begin SHOWMESSAGE(E.Message); end; end; //showmessage('4'); Close;SQL.Clear; str:='select v.主提单号,sum(fee.金额) 金额 from v_op_bscard_MAX v'; str:=Str+' Left join t_ch_fee fee on v.编号=fee.编号 and fee.类型=''付'' '; str:=Str+' where fee.客户名称 in (''安捷车队'',''华运易通'',''大亚报关0000'',''外运车队'') '; str:=Str+' and v.合计应收=v.合计已收 and '; // str:=Str+' and v.合计应收=v.合计已收 and v.业务种类=''普通货'' and '; str:=Str+' '+bdatestr+'>='+''''+DateToStr(betd)+''''; str:=Str+' and '+bdatestr+'<='+''''+DateToStr(eetd)+''''; if RxDBLookupCombo3.DisplayValue<>'' then str:=Str+' and v.揽货人='+''''+RxDBLookupCombo3.DisplayValue+''''; if RxDBLookupCombo2.DisplayValue<>'' then str:=Str+' and v.委托单位='+''''+RxDBLookupCombo2.DisplayValues[1]+''''; if RxDBLookupCombo10.DisplayValue<>'' then str:=Str+' and v.销售部门='+''''+RxDBLookupCombo10.DisplayValue+''''; str:=Str+' Group by v.主提单号'; SQL.Add(str); try Open; kbmMemTable3.EmptyTable; kbmMemTable3.LoadFromDataSet(aQuery,[mtcpostructure,mtcpoProperties,mtcpoFieldIndex]); except on e:exception do begin SHOWMESSAGE(E.Message); end; end; end; //showmessage('5'); if bsSkinCheckRadioBox1.Checked then begin GetProfit; try Getlx; Getcq; GetProfitSum; except on e:exception do begin SHOWMESSAGE(E.Message); end; end; end else begin GetProfitall; Getlx; try Getcq; except on e:exception do begin SHOWMESSAGE(E.Message); end; end; GetProfitSumall; end; finally FreeAndNil(aquery); end; end; end; procedure Tfrm_rp_sales_profit.GetProfit; var aQuery,aQuery3:TADOQuery; aStlDate:TDate; bYear,bMonth,bDate,eYear,eMonth,eDate:Word; btMonth,l,d:Integer; LXBL:Double; function getstlDate(aetd:TDateTime;Cust,SaleID:String):TDate; var aQuery2:TADOQuery; aYear,aMonth,aDay,bDay:word; aStlDate:TDateTime; bMonth:Integer; begin aQuery2:=CreateAdoQuery; aStlDate:=aetd; result:=aStlDate; try with aQuery2 do begin Close;SQL.Clear; SQL.Add('Select * from t_crm_client_sales where 状态=''审核'' and 开始日期<='''+FormatDateTime('YYYY-MM-DD',aetd)+''' and 结束日期>='''+FormatDateTime('YYYY-MM-DD',aetd)+''' and 客户简称='''+Cust+''''); // SQL.Add('Select * from t_crm_client_sales where 状态=''审核'' and 开始日期<='''+FormatDateTime('YYYY-MM-DD',aetd)+''' and 结束日期>='''+FormatDateTime('YYYY-MM-DD',aetd)+''' and 客户简称='''+Cust+''' and 揽货人='''+SaleID+''''); Open; if IsEmpty then begin Result:=aetd; memtblDetail.FieldByName('原定帐期').AsString:='当月结算'; Exit; end; if FieldByName('结费类型').AsString='现结买单' then begin Result:=aetd; memtblDetail.FieldByName('原定帐期').AsString:='当月结算'; end else if FieldByName('结费类型').AsString='约定天数' then begin result:=aStlDate+fieldByName('结费期限').AsInteger; bMonth:=GetBetwMonth(aetd,result); if bMonth=0 then memtblDetail.FieldByName('原定帐期').AsString:='当月结算' else if bMonth=1 then memtblDetail.FieldByName('原定帐期').AsString:='次月结算' else if bMonth=2 then memtblDetail.FieldByName('原定帐期').AsString:='三月结算' else if bMonth=3 then memtblDetail.FieldByName('原定帐期').AsString:='四月结算'; 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)); if StrToIntDef(FieldByName('类型模式').AsString,0)=0 then memtblDetail.FieldByName('原定帐期').AsString:='当月结算' else if StrToIntDef(FieldByName('类型模式').AsString,0)=1 then memtblDetail.FieldByName('原定帐期').AsString:='次月结算' else if StrToIntDef(FieldByName('类型模式').AsString,0)=2 then memtblDetail.FieldByName('原定帐期').AsString:='三月结算' else if StrToIntDef(FieldByName('类型模式').AsString,0)=3 then memtblDetail.FieldByName('原定帐期').AsString:='四月结算'; 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; if StrToIntDef(FieldByName('类型模式').AsString,0)=0 then memtblDetail.FieldByName('原定帐期').AsString:='当月结算' else if StrToIntDef(FieldByName('类型模式').AsString,0)=1 then memtblDetail.FieldByName('原定帐期').AsString:='次月结算' else if StrToIntDef(FieldByName('类型模式').AsString,0)=2 then memtblDetail.FieldByName('原定帐期').AsString:='三月结算' else if StrToIntDef(FieldByName('类型模式').AsString,0)=3 then memtblDetail.FieldByName('原定帐期').AsString:='四月结算'; end else begin Result:=aetd; memtblDetail.FieldByName('原定帐期').AsString:='当月结算'; end; end; finally FreeAndNil(aQuery2); end; end; begin if not P_SUM.Active then P_SUM.Open; if not t_salepriftset.Active then t_salepriftset.Open; if not memtblLX.Active then memtblLX.Open; if NOT memtblDetail.Active then memtblDetail.Open; if memtblrpt_total.RecordCount=0 then exit; l:=memtblrpt_total.RecordCount+kbmMemTable4.RecordCount; if l=0 then l:=100; 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:=l; frm_sys_progress.bsSkinGauge1.MinValue:=0; frm_sys_progress.bsSkinGauge1.Value:=0; frm_sys_progress.Update; { memtblDetail.Open; if not memtblDetail.IsEmpty then begin memtblDetail.First; while not memtblDetail.Eof do begin memtblDetail.Delete; end; end; P_SUM.Open; if not P_SUM.IsEmpty then begin P_SUM.First; while not P_SUM.Eof do begin P_SUM.Delete; end; end; } memtblrpt_total.First; while not memtblrpt_total.eof do begin { DecodeDate(memtblrpt_total.FieldByName('结算日期').AsDateTime,bYear,bMonth,bDate); DecodeDate(memtblrpt_total.FieldByName('开船日期').AsDateTime,eYear,eMonth,eDate); if bYear=eYear then btMonth:=bMonth-eMonth else begin btMonth:=bMonth+(12-eMonth); end; if btMonth>3 then begin if not memtblLX.Active then memtblLX.Open; memtblLX.insert; memtblLX.FieldByName('编号').asstring:=memtblrpt_total.FieldByName('编号').asstring; memtblLX.FieldByName('业务编号').asstring:=memtblrpt_total.FieldByName('业务编号').asstring; memtblLX.FieldByName('主提单号').asstring:=memtblrpt_total.FieldByName('主提单号').asstring; memtblLX.FieldByName('揽货人').asstring:=memtblrpt_total.FieldByName('揽货人').asstring; memtblLX.FieldByName('客户名称').asstring:=memtblrpt_total.FieldByName('委托单位').asstring; memtblLX.FieldByName('开船日期').value:=memtblrpt_total.FieldByName('开船日期').value; memtblLX.FieldByName('未收USD').AsFloat:=memtblrpt_total.FieldByName('应收USD').AsFloat; memtblLX.FieldByName('未收RMB').AsFloat:=memtblrpt_total.FieldByName('应收RMB').AsFloat; memtblLX.FieldByName('未收合计').AsFloat:=memtblrpt_total.FieldByName('合计应收').AsFloat; memtblLX.FieldByName('扣息开始日期').value:=IncMonth(memtblrpt_total.FieldByName('开船日期').value,4); memtblLX.FieldByName('扣息月数').AsInteger:=btMonth; if t_salepriftset.Locate('姓名',Trim(memtblrpt_total.FieldByName('揽货人').asstring),[]) then LXBL:=t_salepriftset.FieldByName('利息').AsFloat else LXBL:=0; memtblLX.FieldByName('扣息比率').AsFloat:=LXBL; memtblLX.FieldByName('扣息金额').AsFloat:=(memtblrpt_total.FieldByName('合计应收').AsFloat)*LXBL/100; memtblLX.post; end; } aQuery3.Close;aQuery3.SQL.Clear; aQuery3.SQL.Add('select * from t_crm_salesproftt where 方案名称 in (select 提成方案 from t_sys_employee where 姓名='''+memtblrpt_total.fieldbyname('揽货人').asstring+''')'); aQuery3.open; if aQuery3.FieldByName('允许误差天数').IsNull then d:=0 else d:=aQuery3.FieldByName('允许误差天数').AsInteger; if not P_SUM.Locate('揽货人',memtblrpt_total.fieldbyname('揽货人').asstring,[])then begin P_SUM.insert; P_SUM['揽货人']:=memtblrpt_total.fieldbyname('揽货人').asstring; P_SUM['当月结算']:=0; P_SUM['次月结算']:=0; P_SUM['拖至次月']:=0.0; P_SUM['三月结算']:=0.0; P_SUM['拖至三月']:=0; P_SUM['四月结算']:=0; P_SUM['拖至四月']:=0; P_SUM['扣利息']:=0.00; P_SUM['扣利润']:=0.00; P_SUM['特殊客户']:=0.00; P_SUM['已扣利润']:=0.00; P_SUM['毛利润']:=0.00; P_SUM['应提成']:=0.00; P_SUM['合计提成']:=0.00; end else begin P_SUM.edit; end; 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('FEE2').AsString; memtblDetail.FieldByName('费用状态').AsString:=memtblrpt_total.FieldByName('费用状态').AsString; aQuery.Close; aQuery.SQL.Clear; aQuery.SQL.Add('select top 1 * from v_fee_do_jie where 业务编号='''+memtblDetail.FieldByName('编号').AsString+''' order by 结算日期 DESC '); aQuery.Open; if not aQuery.IsEmpty then begin memtblDetail.FieldByName('工作编号').AsString:=aQuery.fieldByName('工作编号').AsString; memtblDetail.FieldByName('收款金额').AsString:=aQuery.fieldByName('币别').AsString+Floattostr(aQuery.fieldByName('结算金额').AsFloat); memtblDetail.FieldByName('结算日期').Value:=aQuery.FieldByName('结算日期').Value; memtblDetail.FieldByName('到帐日期').Value:=aQuery.FieldByName('结算日期').Value; end else begin memtblDetail.FieldByName('工作编号').AsString:=''; memtblDetail.FieldByName('收款金额').AsString:=''; end; 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('利润RMB').Value:=memtblrpt_total.FieldByName('利润RMB').Value; memtblDetail.FieldByName('利润USD').Value:=memtblrpt_total.FieldByName('利润USD').Value; P_SUM['毛利润']:=P_SUM['毛利润']+memtblrpt_total.FieldByName('毛利润').AsFloat; memtblDetail.FieldByName('死帐扣款').AsFloat:=0; memtblDetail.FieldByName('剩余毛利').AsFloat:=0; memtblDetail.FieldByName('原提成比率').AsFloat:=0; memtblDetail.FieldByName('应提成金额').AsFloat:=0; memtblDetail.FieldByName('实际提成金额').AsFloat:=0; memtblDetail.FieldByName('提成差额').AsFloat:=0; bdatestr:='开船日期'; // bdatestr aStlDate:=getstlDate(memtblrpt_total.FieldByName(bdatestr).AsDateTime,memtblrpt_total.FieldByName('委托单位').AsString,memtblrpt_total.FieldByName('揽货人').AsString); memtblDetail.FieldByName('应结算日期').AsDateTime:=aStlDate; if memtblDetail.FieldByName('结算日期').IsNull then begin aStlDate:=getstlDate(memtblrpt_total.FieldByName(bdatestr).AsDateTime,memtblrpt_total.FieldByName('委托单位').AsString,memtblrpt_total.FieldByName('揽货人').AsString); memtblDetail.FieldByName('应结算日期').AsDateTime:=aStlDate; end else if memtblDetail.FieldByName('结算日期').AsDateTime=memtblDetail.FieldByName('结算日期').AsDateTime then begin if memtblDetail.FieldByName('结算日期').AsDateTime>memtblrpt_total.FieldByName(bdatestr).AsDateTime then begin DecodeDate(memtblDetail.FieldByName('结算日期').AsDateTime,bYear,bMonth,bDate); DecodeDate(memtblrpt_total.FieldByName(bdatestr).AsDateTime,eYear,eMonth,eDate); if bYear=eYear then btMonth:=bMonth-eMonth else begin btMonth:=bMonth+(12-eMonth); end; case btMonth of 0: begin memtblDetail.FieldByName('结算帐期').AsString:='本月结算'; memtblDetail.FieldByName('实际提成比率').AsFloat:=0; P_SUM['当月结算']:=P_SUM['当月结算']+memtblrpt_total.FieldByName('毛利润').AsFloat; end; 1: begin memtblDetail.FieldByName('结算帐期').AsString:='次月结算'; memtblDetail.FieldByName('实际提成比率').AsFloat:=0; P_SUM['次月结算']:=P_SUM['次月结算']+memtblrpt_total.FieldByName('毛利润').AsFloat; end; 2: begin memtblDetail.FieldByName('结算帐期').AsString:='三月结算'; memtblDetail.FieldByName('实际提成比率').AsFloat:=0; P_SUM['三月结算']:=P_SUM['三月结算']+memtblrpt_total.FieldByName('毛利润').AsFloat; end; 3: begin memtblDetail.FieldByName('结算帐期').AsString:='四月结算'; memtblDetail.FieldByName('实际提成比率').AsFloat:=0; P_SUM['四月结算']:=P_SUM['四月结算']+memtblrpt_total.FieldByName('毛利润').AsFloat; end; else begin memtblDetail.FieldByName('结算帐期').AsString:='超过四月'; memtblDetail.FieldByName('实际提成比率').AsFloat:=0; end; end; end else begin memtblDetail.FieldByName('结算帐期').AsString:='本月结算'; P_SUM['当月结算']:=P_SUM['当月结算']+memtblrpt_total.FieldByName('毛利润').AsFloat; end; end else begin DecodeDate(memtblDetail.FieldByName('结算日期').AsDateTime,bYear,bMonth,bDate); DecodeDate(aStlDate,eYear,eMonth,eDate); if bMonth=eMonth then begin if memtblDetail.FieldByName('结算日期').AsDateTime>memtblrpt_total.FieldByName(bdatestr).AsDateTime then begin DecodeDate(memtblDetail.FieldByName('结算日期').AsDateTime,bYear,bMonth,bDate); DecodeDate(memtblrpt_total.FieldByName(bdatestr).AsDateTime,eYear,eMonth,eDate); if bYear=eYear then btMonth:=bMonth-eMonth else begin btMonth:=bMonth+(12-eMonth); end; case btMonth of 0: begin memtblDetail.FieldByName('结算帐期').AsString:='当月结算'; memtblDetail.FieldByName('实际提成比率').AsFloat:=0; P_SUM['当月结算']:=P_SUM['当月结算']+memtblrpt_total.FieldByName('毛利润').AsFloat; end; 1: begin memtblDetail.FieldByName('结算帐期').AsString:='次月结算'; memtblDetail.FieldByName('实际提成比率').AsFloat:=0; P_SUM['次月结算']:=P_SUM['次月结算']+memtblrpt_total.FieldByName('毛利润').AsFloat; end; 2: begin memtblDetail.FieldByName('结算帐期').AsString:='三月结算'; memtblDetail.FieldByName('实际提成比率').AsFloat:=0; P_SUM['三月结算']:=P_SUM['三月结算']+memtblrpt_total.FieldByName('毛利润').AsFloat; end; 3: begin memtblDetail.FieldByName('结算帐期').AsString:='四月结算'; memtblDetail.FieldByName('实际提成比率').AsFloat:=0; P_SUM['四月结算']:=P_SUM['四月结算']+memtblrpt_total.FieldByName('毛利润').AsFloat; end; else begin memtblDetail.FieldByName('结算帐期').AsString:='超过四月'; memtblDetail.FieldByName('实际提成比率').AsFloat:=0; end; end; end else begin memtblDetail.FieldByName('结算帐期').AsString:='当月结算'; P_SUM['当月结算']:=P_SUM['当月结算']+memtblrpt_total.FieldByName('毛利润').AsFloat; end; end else begin if memtblDetail.FieldByName('结算日期').AsDateTime>memtblrpt_total.FieldByName(bdatestr).AsDateTime then begin DecodeDate(memtblDetail.FieldByName('结算日期').AsDateTime,bYear,bMonth,bDate); DecodeDate(memtblrpt_total.FieldByName(bdatestr).AsDateTime,eYear,eMonth,eDate); if bYear=eYear then btMonth:=bMonth-eMonth else begin btMonth:=bMonth+(12-eMonth); end; case btMonth of 0: begin memtblDetail.FieldByName('结算帐期').AsString:='当月结算'; memtblDetail.FieldByName('实际提成比率').AsFloat:=0; P_SUM['当月结算']:=P_SUM['当月结算']+memtblrpt_total.FieldByName('毛利润').AsFloat; end; 1: begin memtblDetail.FieldByName('结算帐期').AsString:='拖至次月'; memtblDetail.FieldByName('实际提成比率').AsFloat:=0; P_SUM['拖至次月']:=P_SUM['拖至次月']+memtblrpt_total.FieldByName('毛利润').AsFloat; end; 2: begin memtblDetail.FieldByName('结算帐期').AsString:='拖至三月'; memtblDetail.FieldByName('实际提成比率').AsFloat:=0; P_SUM['拖至三月']:=P_SUM['拖至三月']+memtblrpt_total.FieldByName('毛利润').AsFloat; end; 3: begin memtblDetail.FieldByName('结算帐期').AsString:='拖至四月'; memtblDetail.FieldByName('实际提成比率').AsFloat:=0; P_SUM['拖至四月']:=P_SUM['拖至四月']+memtblrpt_total.FieldByName('毛利润').AsFloat; end; else begin memtblDetail.FieldByName('结算帐期').AsString:='超过四月'; memtblDetail.FieldByName('实际提成比率').AsFloat:=0; end; end; end else begin memtblDetail.FieldByName('结算帐期').AsString:='当月结算'; P_SUM['当月结算']:=P_SUM['当月结算']+memtblrpt_total.FieldByName('毛利润').AsFloat; end; end; end; end; with aQuery do try Close; SQL.Clear; SQL.Add('select * from t_op_fee'); SQL.Add('where ACCYEAR=:ACCYEAR and ACCMONTH=:ACCMONTH'); SQL.Add('and 相关人员=:Empl'); Parameters.ParamByName('ACCYEAR').Value:=wwDBComboBox20.Text; Parameters.ParamByName('ACCMONTH').Value:=wwDBComboBox1.Text; Parameters.ParamByName('Empl').Value:=RxDBLookupCombo3.DisplayValue; Open;First; while not eof do begin memtblDetail.Insert; memtblDetail.FieldByName('编号').AsString:=FieldByName('相关号码').AsString; memtblDetail.FieldByName('业务编号').AsString:=FieldByName('相关号码').AsString; memtblDetail.FieldByName('主提单号').AsString:=FieldByName('相关号码').AsString; memtblDetail.FieldByName('揽货人').AsString:=RxDBLookupCombo3.DisplayValue; memtblDetail.FieldByName('工作编号').AsString:=''; memtblDetail.FieldByName('收款金额').AsString:=''; memtblDetail.FieldByName('结算日期').Value:=null; memtblDetail.FieldByName('到帐日期').Value:=null; memtblDetail.FieldByName('客户名称').AsString:=FieldByName('相关客户').AsString; memtblDetail.FieldByName('开船日期').Value:=FieldByName('发生期间').Value; memtblDetail.FieldByName('会计期间').Value:=FieldByName('发生期间').Value; memtblDetail.FieldByName('毛利润').Value:=-FieldByName('金额').Value; memtblDetail.FieldByName('死帐扣款').AsFloat:=0; memtblDetail.FieldByName('剩余毛利').AsFloat:=0; memtblDetail.FieldByName('原提成比率').AsFloat:=0; memtblDetail.FieldByName('应提成金额').AsFloat:=0; memtblDetail.FieldByName('实际提成金额').AsFloat:=0; memtblDetail.FieldByName('提成差额').AsFloat:=0; memtblDetail.FieldByName('应结算日期').AsDateTime:=aStlDate; memtblDetail.FieldByName('结算帐期').AsString:=''; memtblDetail.FieldByName('实际提成比率').AsFloat:=0; memtblDetail.Post; Next; end; finally end; if (trim(memtblDetail.FieldByName('业务种类').AsString)='普通货') and (kbmMemTable3.Locate('主提单号',Trim(memtblDetail.FieldByName('主提单号').asstring),[])) then memtblDetail.FieldByName('虚拟成本').Value:=kbmMemTable3.FieldByName('金额').value; if (memtblDetail.FieldByName('毛利润').Value<=0) or (memtblDetail.FieldByName('原定帐期').AsString='当月结算') or (memtblDetail.FieldByName('业务种类').AsString='更改单')then memtblDetail.FieldByName('超期天数').value:=0 else memtblDetail.FieldByName('超期天数').value :=daysbetween(memtblDetail.FieldByName('结算日期').AsDateTime,memtblDetail.FieldByName('应结算日期').AsDateTime)-strtoInt(bsSkinEdit1.Text); memtblDetail.Post; P_SUM.post; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; memtblrpt_total.Next; end; if not kbmMemTable4.IsEmpty then begin kbmMemTable4.First; while not kbmMemTable4.Eof do begin memtblDetail.Insert; memtblDetail.FieldByName('编号').AsString:=kbmMemTable4.FieldByName('编号').AsString; memtblDetail.FieldByName('业务编号').AsString:=kbmMemTable4.FieldByName('业务编号').AsString; memtblDetail.FieldByName('主提单号').AsString:=kbmMemTable4.FieldByName('主提单号').AsString; memtblDetail.FieldByName('揽货人').AsString:=kbmMemTable4.FieldByName('揽货人').AsString; memtblDetail.FieldByName('工作编号').AsString:=''; memtblDetail.FieldByName('收款金额').AsString:=''; memtblDetail.FieldByName('结算日期').Value:=null; memtblDetail.FieldByName('到帐日期').Value:=null; memtblDetail.FieldByName('客户名称').AsString:=kbmMemTable4.FieldByName('委托单位').AsString; memtblDetail.FieldByName('开船日期').Value:=kbmMemTable4.FieldByName('开船日期').Value; memtblDetail.FieldByName('会计期间').Value:=kbmMemTable4.FieldByName('会计期间').Value; memtblDetail.FieldByName('毛利润').Value:=kbmMemTable4.FieldByName('毛利润').Value; memtblDetail.FieldByName('死帐扣款').AsFloat:=0; memtblDetail.FieldByName('剩余毛利').AsFloat:=kbmMemTable4.FieldByName('毛利润').Value; memtblDetail.FieldByName('原提成比率').AsFloat:=5; memtblDetail.FieldByName('应提成金额').AsFloat:=kbmMemTable4.FieldByName('提成').AsFloat; memtblDetail.FieldByName('实际提成金额').AsFloat:=kbmMemTable4.FieldByName('提成').AsFloat; memtblDetail.FieldByName('提成差额').AsFloat:=0; aStlDate:=getstlDate(kbmMemTable4.FieldByName(bdatestr).AsDateTime,kbmMemTable4.FieldByName('委托单位').AsString,kbmMemTable4.FieldByName('揽货人').AsString); memtblDetail.FieldByName('应结算日期').AsDateTime:=aStlDate; memtblDetail.FieldByName('结算帐期').AsString:='特殊客户'; memtblDetail.FieldByName('实际提成比率').AsFloat:=5; memtblDetail.Post; kbmMemTable4.Next; end; 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; procedure Tfrm_rp_sales_profit.GetProfitall; var aQuery,aQuery3:TADOQuery; aStlDate,aSBDATE:TDate; bYear,bMonth,bDate,eYear,eMonth,eDate:Word; btMonth,l,d:Integer; LXBL,YB,SB:Double; function getstlDate(aetd:TDateTime;Cust,SaleID:String):TDate; var aQuery2:TADOQuery; aYear,aMonth,aDay,bDay:word; aStlDate:TDateTime; bMonth:Integer; begin aQuery2:=CreateAdoQuery; aStlDate:=aetd; result:=aStlDate; try with aQuery2 do begin Close;SQL.Clear; SQL.Add('Select * from t_crm_client_sales where 状态=''审核'' and 开始日期<='''+FormatDateTime('YYYY-MM-DD',aetd)+''' and 结束日期>='''+FormatDateTime('YYYY-MM-DD',aetd)+''' and 客户简称='''+Cust+''''); // SQL.Add('Select * from t_crm_client_sales where 状态=''审核'' and 开始日期<='''+FormatDateTime('YYYY-MM-DD',aetd)+''' and 结束日期>='''+FormatDateTime('YYYY-MM-DD',aetd)+''' and 客户简称='''+Cust+''' and 揽货人='''+SaleID+''''); Open; if IsEmpty then begin Result:=aetd; memtblDetail.FieldByName('原定帐期').AsString:='当月结算'; Exit; end; if FieldByName('结费类型').AsString='现结买单' then begin Result:=aetd; memtblDetail.FieldByName('原定帐期').AsString:='当月结算'; end else if FieldByName('结费类型').AsString='约定天数' then begin result:=aStlDate+fieldByName('结费期限').AsInteger; bMonth:=GetBetwMonth(aetd,result); if bMonth=0 then memtblDetail.FieldByName('原定帐期').AsString:='当月结算' else if bMonth=1 then memtblDetail.FieldByName('原定帐期').AsString:='次月结算' else if bMonth=2 then memtblDetail.FieldByName('原定帐期').AsString:='三月结算' else if bMonth=3 then memtblDetail.FieldByName('原定帐期').AsString:='四月结算'; 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)); if StrToIntDef(FieldByName('类型模式').AsString,0)=0 then memtblDetail.FieldByName('原定帐期').AsString:='当月结算' else if StrToIntDef(FieldByName('类型模式').AsString,0)=1 then memtblDetail.FieldByName('原定帐期').AsString:='次月结算' else if StrToIntDef(FieldByName('类型模式').AsString,0)=2 then memtblDetail.FieldByName('原定帐期').AsString:='三月结算' else if StrToIntDef(FieldByName('类型模式').AsString,0)=3 then memtblDetail.FieldByName('原定帐期').AsString:='四月结算'; 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; if StrToIntDef(FieldByName('类型模式').AsString,0)=0 then memtblDetail.FieldByName('原定帐期').AsString:='当月结算' else if StrToIntDef(FieldByName('类型模式').AsString,0)=1 then memtblDetail.FieldByName('原定帐期').AsString:='次月结算' else if StrToIntDef(FieldByName('类型模式').AsString,0)=2 then memtblDetail.FieldByName('原定帐期').AsString:='三月结算' else if StrToIntDef(FieldByName('类型模式').AsString,0)=3 then memtblDetail.FieldByName('原定帐期').AsString:='四月结算'; end else begin Result:=aetd; memtblDetail.FieldByName('原定帐期').AsString:='当月结算'; end; end; finally FreeAndNil(aQuery2); end; end; begin if not P_SUM.Active then P_SUM.Open; if not t_salepriftset.Active then t_salepriftset.Open; if not memtblLX.Active then memtblLX.Open; if NOT memtblDetail.Active then memtblDetail.Open; if memtblrpt_total.RecordCount=0 then exit; l:=memtblrpt_total.RecordCount+kbmMemTable4.RecordCount; if l=0 then l:=100; 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:=l; frm_sys_progress.bsSkinGauge1.MinValue:=0; frm_sys_progress.bsSkinGauge1.Value:=0; frm_sys_progress.Update; { memtblDetail.Open; if not memtblDetail.IsEmpty then begin memtblDetail.First; while not memtblDetail.Eof do begin memtblDetail.Delete; end; end; P_SUM.Open; if not P_SUM.IsEmpty then begin P_SUM.First; while not P_SUM.Eof do begin P_SUM.Delete; end; end; } memtblrpt_total.First; while not memtblrpt_total.eof do begin aQuery3.Close;aQuery3.SQL.Clear; aQuery3.SQL.Add('select * from t_crm_salesproftt where 方案名称 in (select 提成方案 from t_sys_employee where 姓名='''+memtblrpt_total.fieldbyname('揽货人').asstring+''')'); aQuery3.open; if aQuery3.FieldByName('允许误差天数').IsNull then d:=0 else d:=aQuery3.FieldByName('允许误差天数').AsInteger; if not P_SUM.Locate('揽货人',memtblrpt_total.fieldbyname('揽货人').asstring,[])then begin P_SUM.insert; P_SUM['揽货人']:=memtblrpt_total.fieldbyname('揽货人').asstring; P_SUM['当月结算']:=0; P_SUM['次月结算']:=0; P_SUM['拖至次月']:=0.0; P_SUM['三月结算']:=0.0; P_SUM['拖至三月']:=0; P_SUM['四月结算']:=0; P_SUM['拖至四月']:=0; P_SUM['扣利息']:=0.00; P_SUM['扣利润']:=0.00; P_SUM['特殊客户']:=0.00; P_SUM['已扣利润']:=0.00; P_SUM['毛利润']:=0.00; P_SUM['应提成']:=0.00; P_SUM['合计提成']:=0.00; end else begin P_SUM.edit; end; 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('FEE2').AsString; memtblDetail.FieldByName('费用状态').AsString:=memtblrpt_total.FieldByName('费用状态').AsString; memtblDetail.FieldByName('利润率').AsString:=memtblrpt_total.FieldByName('利润率').AsString; aStlDate:=getstlDate(memtblrpt_total.FieldByName('开船日期').AsDateTime,memtblrpt_total.FieldByName('委托单位').AsString,memtblrpt_total.FieldByName('揽货人').AsString); memtblDetail.FieldByName('应结算日期').AsDateTime:=aStlDate; 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('利润RMB').Value:=memtblrpt_total.FieldByName('利润RMB').Value; memtblDetail.FieldByName('利润USD').Value:=memtblrpt_total.FieldByName('利润USD').Value; if (trim(memtblDetail.FieldByName('业务种类').AsString)='普通货') and (kbmMemTable3.Locate('主提单号',Trim(memtblDetail.FieldByName('主提单号').asstring),[])) then memtblDetail.FieldByName('虚拟成本').Value:=kbmMemTable3.FieldByName('金额').value; if (memtblDetail.FieldByName('毛利润').Value<=0) or (memtblDetail.FieldByName('原定帐期').AsString='当月结算') or (memtblDetail.FieldByName('业务种类').AsString='更改单')then memtblDetail.FieldByName('超期天数').value:=0 else memtblDetail.FieldByName('超期天数').value :=daysbetween(memtblDetail.FieldByName('结算日期').AsDateTime,memtblDetail.FieldByName('应结算日期').AsDateTime)-strtoInt(bsSkinEdit1.Text); Saleprofitsum.Locate('揽货人',memtblrpt_total.FieldByName('揽货人').AsString,[]); //根据收费来计算提成 aQuery.Close; aQuery.SQL.Clear; aQuery.SQL.Add('select 结算日期,sum(原始金额*汇率) as 结算金额 from v_fee_do where 业务编号='''+memtblDetail.FieldByName('编号').AsString+''' and 收付类型=''收'' and 类型=''3'' group by 结算日期 order by 结算日期 '); aQuery.Open; if not aQuery.IsEmpty then begin aQuery.first; while not aQuery.Eof do begin if (memtblrpt_total.FieldByName('合计应收').AsFloat=0) or (memtblDetail.FieldByName('毛利润').AsFloat=0) then begin memtblDetail.FieldByName('工作编号').AsString:=''; memtblDetail.FieldByName('收款金额').AsString:=''; memtblDetail.FieldByName('死帐扣款').AsFloat:=0; memtblDetail.FieldByName('剩余毛利').AsFloat:=0; memtblDetail.FieldByName('原提成比率').AsFloat:=0; memtblDetail.FieldByName('应提成金额').AsFloat:=0; memtblDetail.FieldByName('实际提成金额').AsFloat:=0; memtblDetail.FieldByName('提成差额').AsFloat:=0; end else begin aQuery3.Close;aQuery3.SQL.Clear; aQuery3.SQL.Add('select * from t_crm_salesproftt where 方案名称 in (select 提成方案 from t_sys_employee where 姓名='''+memtblDetail.FieldByName('揽货人').AsString+''')'); aQuery3.open; if aQuery3.FieldByName('允许误差天数').IsNull then d:=0 else d:=aQuery3.FieldByName('允许误差天数').AsInteger; if (d<>0) and (aQuery.FieldByName('结算日期').AsDateTimememtblDetail.FieldByName('应结算日期').AsDateTime then aSBDATE:=aQuery.FieldByName('结算日期').AsDatetime else aSBDATE:=memtblDetail.FieldByName('应结算日期').AsDatetime; SB:=GetSALEprofit(memtblDetail.FieldByName('揽货人').AsString,GetBetwMonth(memtblDetail.FieldByName('开船日期').AsDateTime,aSBDATE),Saleprofitsum.FieldByName('毛利润').AsFloat,issameMonth(memtblDetail.FieldByName('应结算日期').AsDateTime,aQuery.FieldByName('结算日期').AsDateTime)); end; // ShowMessage(IntToStr(GetBetwMonth(memtblDetail.FieldByName(bdatestr).AsDateTime,aSBDATE))+floattostr(SB)); case GetBetwMonth(memtblDetail.FieldByName(bdatestr).AsDateTime,aSBDATE) of 0:begin memtblDetail.FieldByName('一月结算').AsFloat:=memtblDetail.FieldByName('一月结算').AsFloat+aQuery.fieldbyname('结算金额').AsFloat; memtbldetail.FieldByName('实际提成金额').AsFloat:=memtbldetail.FieldByName('实际提成金额').AsFloat+(memtblDetail.FieldByName('毛利润').AsFloat*(aQuery.fieldbyname('结算金额').AsFloat/memtblrpt_total.FieldByName('合计应收').AsFloat)*SB/100) end; 1:begin memtblDetail.FieldByName('二月结算').AsFloat:=memtblDetail.FieldByName('二月结算').AsFloat+aQuery.fieldbyname('结算金额').AsFloat; memtbldetail.FieldByName('实际提成金额').AsFloat:=memtbldetail.FieldByName('实际提成金额').AsFloat+(memtblDetail.FieldByName('毛利润').AsFloat*(aQuery.fieldbyname('结算金额').AsFloat/memtblrpt_total.FieldByName('合计应收').AsFloat)*SB/100) end; 2:begin memtblDetail.FieldByName('三月结算').AsFloat:=memtblDetail.FieldByName('三月结算').AsFloat+aQuery.fieldbyname('结算金额').AsFloat; memtbldetail.FieldByName('实际提成金额').AsFloat:=memtbldetail.FieldByName('实际提成金额').AsFloat+(memtblDetail.FieldByName('毛利润').AsFloat*(aQuery.fieldbyname('结算金额').AsFloat/memtblrpt_total.FieldByName('合计应收').AsFloat)*SB/100) end; 3: begin memtblDetail.FieldByName('四月结算').AsFloat:=memtblDetail.FieldByName('四月结算').AsFloat+aQuery.fieldbyname('结算金额').AsFloat; memtbldetail.FieldByName('实际提成金额').AsFloat:=memtbldetail.FieldByName('实际提成金额').AsFloat+(memtblDetail.FieldByName('毛利润').AsFloat*(aQuery.fieldbyname('结算金额').AsFloat/memtblrpt_total.FieldByName('合计应收').AsFloat)*SB/100) end; end; memtblDetail.FieldByName('工作编号').AsString:=''; memtblDetail.FieldByName('收款金额').AsString:=''; end; aQuery.Next; end; end else begin //showmessage(memtblDetail.FieldByName('业务种类').AsString+' '+memtblDetail.FieldByName('毛利润').AsString); if trim(memtblDetail.FieldByName('业务种类').AsString)='更改单' then begin YB:=GetSALEprofit(memtblDetail.FieldByName('揽货人').AsString,0,Saleprofitsum.FieldByName('毛利润').AsFloat,true); SB:=GetSALEprofit(memtblDetail.FieldByName('揽货人').AsString,0,Saleprofitsum.FieldByName('毛利润').AsFloat,true); //YB:=1; //SB:=1; // showmessage(memtblDetail.FieldByName('毛利润').AsString); memtbldetail.FieldByName('实际提成金额').AsFloat:=memtbldetail.FieldByName('实际提成金额').AsFloat+(memtblDetail.FieldByName('毛利润').AsFloat*SB/100); // showmessage(memtblDetail.FieldByName('实际提成金额').AsString); memtblDetail.FieldByName('工作编号').AsString:=''; memtblDetail.FieldByName('收款金额').AsString:=''; memtblDetail.FieldByName('死帐扣款').AsFloat:=0; memtblDetail.FieldByName('剩余毛利').AsFloat:=0; memtblDetail.FieldByName('原提成比率').AsFloat:=0; memtblDetail.FieldByName('应提成金额').AsFloat:=0; memtblDetail.FieldByName('提成差额').AsFloat:=0; end else begin memtblDetail.FieldByName('工作编号').AsString:=''; memtblDetail.FieldByName('收款金额').AsString:=''; memtblDetail.FieldByName('死帐扣款').AsFloat:=0; memtblDetail.FieldByName('剩余毛利').AsFloat:=0; memtblDetail.FieldByName('原提成比率').AsFloat:=0; memtblDetail.FieldByName('应提成金额').AsFloat:=0; memtblDetail.FieldByName('实际提成金额').AsFloat:=0; memtblDetail.FieldByName('提成差额').AsFloat:=0; end; end; P_SUM['应提成']:=P_SUM['应提成']+memtblDetail.FieldByName('实际提成金额').AsFloat; P_SUM['毛利润']:=P_SUM['毛利润']+memtblrpt_total.FieldByName('毛利润').AsFloat; memtblDetail.Post; P_SUM.post; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; memtblrpt_total.Next; end; with aQuery do try Close; SQL.Clear; SQL.Add('select * from t_op_fee'); SQL.Add('where ACCYEAR=:ACCYEAR and ACCMONTH=:ACCMONTH'); SQL.Add('and 相关人员=:Empl'); Parameters.ParamByName('ACCYEAR').Value:=wwDBComboBox20.Text; Parameters.ParamByName('ACCMONTH').Value:=wwDBComboBox1.Text; Parameters.ParamByName('Empl').Value:=RxDBLookupCombo3.DisplayValue; Open;First; while not eof do begin memtblDetail.Insert; memtblDetail.FieldByName('编号').AsString:=FieldByName('相关号码').AsString; memtblDetail.FieldByName('业务编号').AsString:=FieldByName('相关号码').AsString; memtblDetail.FieldByName('主提单号').AsString:=FieldByName('相关号码').AsString; memtblDetail.FieldByName('揽货人').AsString:=RxDBLookupCombo3.DisplayValue; memtblDetail.FieldByName('工作编号').AsString:=''; memtblDetail.FieldByName('收款金额').AsString:=''; memtblDetail.FieldByName('结算日期').Value:=null; memtblDetail.FieldByName('到帐日期').Value:=null; memtblDetail.FieldByName('客户名称').AsString:=FieldByName('相关客户').AsString; memtblDetail.FieldByName('开船日期').Value:=FieldByName('发生期间').Value; memtblDetail.FieldByName('会计期间').Value:=FieldByName('发生期间').Value; memtblDetail.FieldByName('毛利润').Value:=-FieldByName('金额').Value; memtblDetail.FieldByName('死帐扣款').AsFloat:=0; memtblDetail.FieldByName('剩余毛利').AsFloat:=0; memtblDetail.FieldByName('原提成比率').AsFloat:=5; memtblDetail.FieldByName('应提成金额').AsFloat:=0; memtblDetail.FieldByName('实际提成金额').AsFloat:=0; memtblDetail.FieldByName('提成差额').AsFloat:=0; memtblDetail.FieldByName('应结算日期').AsDateTime:=aStlDate; memtblDetail.FieldByName('结算帐期').AsString:=''; memtblDetail.FieldByName('实际提成比率').AsFloat:=0; memtblDetail.Post; Next; end; finally end; if not kbmMemTable4.IsEmpty then begin kbmMemTable4.First; while not kbmMemTable4.Eof do begin if not P_SUM.Locate('揽货人',memtblrpt_total.fieldbyname('揽货人').asstring,[])then begin P_SUM.insert; P_SUM['揽货人']:=memtblrpt_total.fieldbyname('揽货人').asstring; P_SUM['当月结算']:=0; P_SUM['次月结算']:=0; P_SUM['拖至次月']:=0.0; P_SUM['三月结算']:=0.0; P_SUM['拖至三月']:=0; P_SUM['四月结算']:=0; P_SUM['拖至四月']:=0; P_SUM['扣利息']:=0.00; P_SUM['扣利润']:=0.00; P_SUM['特殊客户']:=0.00; P_SUM['已扣利润']:=0.00; P_SUM['毛利润']:=0.00; P_SUM['应提成']:=0.00; P_SUM['合计提成']:=0.00; end else begin P_SUM.edit; end; memtblDetail.Insert; memtblDetail.FieldByName('编号').AsString:=kbmMemTable4.FieldByName('编号').AsString; memtblDetail.FieldByName('业务编号').AsString:=kbmMemTable4.FieldByName('业务编号').AsString; memtblDetail.FieldByName('主提单号').AsString:=kbmMemTable4.FieldByName('主提单号').AsString; memtblDetail.FieldByName('揽货人').AsString:=kbmMemTable4.FieldByName('揽货人').AsString; memtblDetail.FieldByName('工作编号').AsString:=''; memtblDetail.FieldByName('收款金额').AsString:=''; memtblDetail.FieldByName('结算日期').Value:=null; memtblDetail.FieldByName('到帐日期').Value:=null; memtblDetail.FieldByName('客户名称').AsString:=kbmMemTable4.FieldByName('委托单位').AsString; memtblDetail.FieldByName('开船日期').Value:=kbmMemTable4.FieldByName('开船日期').Value; memtblDetail.FieldByName('会计期间').Value:=kbmMemTable4.FieldByName('会计期间').Value; memtblDetail.FieldByName('毛利润').Value:=kbmMemTable4.FieldByName('毛利润').Value; memtblDetail.FieldByName('死帐扣款').AsFloat:=0; memtblDetail.FieldByName('剩余毛利').AsFloat:=kbmMemTable4.FieldByName('毛利润').Value; memtblDetail.FieldByName('原提成比率').AsFloat:=5; memtblDetail.FieldByName('应提成金额').AsFloat:=kbmMemTable4.FieldByName('提成').AsFloat; memtblDetail.FieldByName('实际提成金额').AsFloat:=kbmMemTable4.FieldByName('提成').AsFloat; memtblDetail.FieldByName('提成差额').AsFloat:=0; aStlDate:=getstlDate(kbmMemTable4.FieldByName(bdatestr).AsDateTime,kbmMemTable4.FieldByName('委托单位').AsString,kbmMemTable4.FieldByName('揽货人').AsString); memtblDetail.FieldByName('应结算日期').AsDateTime:=aStlDate; memtblDetail.FieldByName('结算帐期').AsString:='特殊客户'; memtblDetail.FieldByName('实际提成比率').AsFloat:=5; P_SUM['应提成']:=P_SUM['应提成']+memtblDetail.FieldByName('实际提成金额').AsFloat; P_SUM['毛利润']:=P_SUM['毛利润']+kbmMemTable4.FieldByName('毛利润').AsFloat; memtblDetail.Post; P_SUM.post; kbmMemTable4.Next; end; 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; procedure Tfrm_rp_sales_profit.GetProfitSum; var aK,YB,SB:Double; aSBDATE:TDate; aQuery3:TAdoQuery; d:integer; begin if not memtblrpt_total.Active then exit; 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:=memtblLX.RecordCount+kbmMemTable4.RecordCount+memtblDetail.RecordCount*2; // frm_sys_progress.bsSkinGauge1.MaxValue:=kbmMemTable2.RecordCount+kbmMemTable4.RecordCount+memtblDetail.RecordCount*2; frm_sys_progress.bsSkinGauge1.MinValue:=0; frm_sys_progress.bsSkinGauge1.Value:=0; frm_sys_progress.Update; P_SUM.Open; if not memtblLX.IsEmpty then begin memtblLX.First; while not memtblLX.Eof do begin if not P_SUM.Locate('揽货人',memtblLX.fieldbyname('揽货人').asstring,[])then begin P_SUM.insert; P_SUM['揽货人']:=memtblLX.fieldbyname('揽货人').asstring; P_SUM['扣利息']:=memtblLX.fieldbyname('扣息金额').asfloat; P_SUM['当月结算']:=0.00; P_SUM['次月结算']:=0.00; P_SUM['拖至次月']:=0.00; P_SUM['三月结算']:=0.00; P_SUM['拖至三月']:=0.00; P_SUM['四月结算']:=0.00; P_SUM['拖至四月']:=0.00; P_SUM['扣利润']:=0; P_SUM['已扣利润']:=0; P_SUM['特殊客户']:=0; P_SUM['应提成']:=0.00; P_SUM['合计提成']:=-memtblLX.fieldbyname('扣息金额').asfloat; P_SUM.post; end else begin P_SUM.Edit; P_SUM['揽货人']:=memtblLX.fieldbyname('揽货人').asstring; P_SUM['扣利息']:=P_SUM['扣利息']+memtblLX.fieldbyname('扣息金额').asfloat; P_SUM.post; end; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; memtblLX.Next; end; end; if kbmMemTable2.Active then if not kbmMemTable2.IsEmpty then begin kbmMemTable2.First; while not kbmMemTable2.Eof do begin if not P_SUM.Locate('揽货人',kbmMemTable2.fieldbyname('揽货人').asstring,[])then begin P_SUM.insert; P_SUM['揽货人']:=kbmMemTable2.fieldbyname('揽货人').asstring; P_SUM['扣利润']:=kbmMemTable2.fieldbyname('扣除利润').asfloat; P_SUM['已扣利润']:=0; P_SUM['扣利息']:=0.00; P_SUM['当月结算']:=0.00; P_SUM['次月结算']:=0.00; P_SUM['拖至次月']:=0.00; P_SUM['三月结算']:=0.00; P_SUM['拖至三月']:=0.00; P_SUM['四月结算']:=0.00; P_SUM['拖至四月']:=0.00; P_SUM['应提成']:=0.00; P_SUM['合计提成']:=0; P_SUM.post; end else begin P_SUM.Edit; P_SUM['揽货人']:=kbmMemTable2.fieldbyname('揽货人').asstring; P_SUM['扣利润']:=P_SUM['扣利润']+kbmMemTable2.fieldbyname('扣除利润').asfloat; P_SUM.post; end; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; kbmMemTable2.Next; end; end; if not kbmMemTable4.IsEmpty then begin kbmMemTable4.First; while not kbmMemTable4.Eof do begin if not P_SUM.Locate('揽货人',kbmMemTable4.fieldbyname('揽货人').asstring,[])then begin P_SUM.insert; P_SUM['揽货人']:=kbmMemTable4.fieldbyname('揽货人').asstring; P_SUM['特殊客户']:=kbmMemTable4.fieldbyname('提成').asfloat; P_SUM['已扣利润']:=0; P_SUM['扣利润']:=0.00; P_SUM['扣利息']:=0.00; P_SUM['当月结算']:=0.00; P_SUM['次月结算']:=0.00; P_SUM['拖至次月']:=0.00; P_SUM['三月结算']:=0.00; P_SUM['拖至三月']:=0.00; P_SUM['四月结算']:=0.00; P_SUM['拖至四月']:=0.00; P_SUM['应提成']:=0.00; P_SUM['合计提成']:=kbmMemTable4.fieldbyname('提成').asfloat; P_SUM.post; end else begin P_SUM.Edit; P_SUM['揽货人']:=kbmMemTable4.fieldbyname('揽货人').asstring; P_SUM['特殊客户']:=P_SUM['特殊客户']+kbmMemTable4.fieldbyname('提成').asfloat; P_SUM.post; end; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; kbmMemTable4.Next; end; end; if not memtblDetail.IsEmpty then begin memtblDetail.SortOn('结算日期',[]); memtblDetail.Last; while not memtblDetail.Bof do begin if P_SUM.Locate('揽货人',memtblDetail.FieldByName('揽货人').AsString,[]) then begin memtblDetail.Edit; P_SUM.Edit; { if (P_SUM.FieldByName('扣利润').AsFloat>P_SUM.FieldByName('已扣利润').AsFloat) AND (P_SUM.FieldByName('扣利润').AsFloat<>0) then begin aK:=P_SUM.FieldByName('扣利润').AsFloat-P_SUM.FieldByName('已扣利润').AsFloat; if aK>memtblDetail.FieldByName('毛利润').AsFloat then begin P_SUM.FieldByName('已扣利润').AsFloat:=P_SUM.FieldByName('已扣利润').AsFloat+memtblDetail.FieldByName('毛利润').AsFloat; memtblDetail.FieldByName('死帐扣款').AsFloat:=memtblDetail.FieldByName('毛利润').AsFloat; memtblDetail.FieldByName('剩余毛利').AsFloat:=0; end else begin memtblDetail.FieldByName('死帐扣款').AsFloat:=aK; memtblDetail.FieldByName('剩余毛利').AsFloat:=memtblDetail.FieldByName('毛利润').AsFloat-aK; P_SUM.FieldByName('已扣利润').AsFloat:=P_SUM.FieldByName('已扣利润').AsFloat+aK; end; end else begin } memtblDetail.FieldByName('剩余毛利').AsFloat:=memtblDetail.FieldByName('毛利润').AsFloat; // end; if memtblDetail.FieldByName('结算帐期').AsString<>'特殊客户' then begin aQuery3.Close;aQuery3.SQL.Clear; aQuery3.SQL.Add('select * from t_crm_salesproftt where 方案名称 in (select 提成方案 from t_sys_employee where 姓名='''+memtblDetail.FieldByName('揽货人').AsString+''')'); aQuery3.open; if aQuery3.FieldByName('允许误差天数').IsNull then d:=0 else d:=aQuery3.FieldByName('允许误差天数').AsInteger; if (d<>0) and (memtblDetail.FieldByName('结算日期').AsDateTimememtblDetail.FieldByName('应结算日期').AsDateTime then aSBDATE:=memtblDetail.FieldByName('结算日期').AsDatetime else aSBDATE:=memtblDetail.FieldByName('应结算日期').AsDatetime; SB:=GetSALEprofit(memtblDetail.FieldByName('揽货人').AsString,0,P_SUM.FieldByName('毛利润').AsFloat,true); memtblDetail.FieldByName('实际提成比率').AsFloat:=SB; memtblDetail.FieldByName('原提成比率').AsFloat:=YB; end else begin YB:=GetSALEprofit(memtblDetail.FieldByName('揽货人').AsString,GetBetwMonth(memtblDetail.FieldByName(bdatestr).AsDateTime,memtblDetail.FieldByName('应结算日期').AsDateTime),P_SUM.FieldByName('毛利润').AsFloat,False); if memtblDetail.FieldByName('结算日期').AsDateTime>memtblDetail.FieldByName('应结算日期').AsDateTime then aSBDATE:=memtblDetail.FieldByName('结算日期').AsDatetime else aSBDATE:=memtblDetail.FieldByName('应结算日期').AsDatetime; SB:=GetSALEprofit(memtblDetail.FieldByName('揽货人').AsString,GetBetwMonth(memtblDetail.FieldByName(bdatestr).AsDateTime,aSBDATE),P_SUM.FieldByName('毛利润').AsFloat,issameMonth(memtblDetail.FieldByName('应结算日期').AsDateTime,memtblDetail.FieldByName('结算日期').AsDateTime)); memtblDetail.FieldByName('实际提成比率').AsFloat:=SB; memtblDetail.FieldByName('原提成比率').AsFloat:=YB; end; end; memtblDetail.FieldByName('应提成金额').AsFloat:=memtblDetail.FieldByName('毛利润').AsFloat*memtblDetail.FieldByName('原提成比率').AsFloat/100; memtblDetail.FieldByName('实际提成金额').AsFloat:=memtblDetail.FieldByName('剩余毛利').AsFloat*memtblDetail.FieldByName('实际提成比率').AsFloat/100; memtblDetail.FieldByName('提成差额').AsFloat:=memtblDetail.FieldByName('应提成金额').AsFloat-memtblDetail.FieldByName('实际提成金额').AsFloat; P_SUM['应提成']:=P_SUM['应提成']+memtblDetail.FieldByName('实际提成金额').AsFloat; P_SUM.Post; memtblDetail.Post; end; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; memtblDetail.Prior; end; memtblDetail.SortOn('揽货人;结算日期;工作编号',[]); end; p_sum.First; while not p_sum.eof do begin P_SUM.edit; P_SUM['合计提成']:=P_SUM['应提成']+P_SUM['特殊客户']-P_SUM['扣利息']; P_SUM.post; P_SUM.Next; end; finally FreeAndNil(aQuery3); frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.MaxValue; frm_sys_progress.free; frm_sys_progress:=nil; end; end; procedure Tfrm_rp_sales_profit.GetProfitSumall; var aK,YB,SB:Double; aSBDATE:TDate; aQuery3:TAdoQuery; d:integer; begin if not memtblrpt_total.Active then exit; 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:=memtblLX.RecordCount+kbmMemTable4.RecordCount+memtblDetail.RecordCount*2; // frm_sys_progress.bsSkinGauge1.MaxValue:=kbmMemTable2.RecordCount+kbmMemTable4.RecordCount+memtblDetail.RecordCount*2; frm_sys_progress.bsSkinGauge1.MinValue:=0; frm_sys_progress.bsSkinGauge1.Value:=0; frm_sys_progress.Update; P_SUM.Open; if not memtblLX.IsEmpty then begin memtblLX.First; while not memtblLX.Eof do begin if not P_SUM.Locate('揽货人',memtblLX.fieldbyname('揽货人').asstring,[])then begin P_SUM.insert; P_SUM['揽货人']:=memtblLX.fieldbyname('揽货人').asstring; P_SUM['扣利息']:=memtblLX.fieldbyname('扣息金额').asfloat; P_SUM['当月结算']:=0.00; P_SUM['次月结算']:=0.00; P_SUM['拖至次月']:=0.00; P_SUM['三月结算']:=0.00; P_SUM['拖至三月']:=0.00; P_SUM['四月结算']:=0.00; P_SUM['拖至四月']:=0.00; P_SUM['扣利润']:=0; P_SUM['已扣利润']:=0; P_SUM['特殊客户']:=0; P_SUM['应提成']:=0.00; P_SUM['合计提成']:=-memtblLX.fieldbyname('扣息金额').asfloat; P_SUM.post; end else begin P_SUM.Edit; P_SUM['揽货人']:=memtblLX.fieldbyname('揽货人').asstring; P_SUM['扣利息']:=P_SUM['扣利息']+memtblLX.fieldbyname('扣息金额').asfloat; P_SUM.post; end; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; memtblLX.Next; end; end; if kbmMemTable2.Active then if not kbmMemTable2.IsEmpty then begin kbmMemTable2.First; while not kbmMemTable2.Eof do begin if not P_SUM.Locate('揽货人',kbmMemTable2.fieldbyname('揽货人').asstring,[])then begin P_SUM.insert; P_SUM['揽货人']:=kbmMemTable2.fieldbyname('揽货人').asstring; P_SUM['扣利润']:=kbmMemTable2.fieldbyname('扣除利润').asfloat; P_SUM['已扣利润']:=0; P_SUM['扣利息']:=0.00; P_SUM['当月结算']:=0.00; P_SUM['次月结算']:=0.00; P_SUM['拖至次月']:=0.00; P_SUM['三月结算']:=0.00; P_SUM['拖至三月']:=0.00; P_SUM['四月结算']:=0.00; P_SUM['拖至四月']:=0.00; P_SUM['应提成']:=0.00; P_SUM['合计提成']:=0; P_SUM.post; end else begin P_SUM.Edit; P_SUM['揽货人']:=kbmMemTable2.fieldbyname('揽货人').asstring; P_SUM['扣利润']:=P_SUM['扣利润']+kbmMemTable2.fieldbyname('扣除利润').asfloat; P_SUM.post; end; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; kbmMemTable2.Next; end; end; if not kbmMemTable4.IsEmpty then begin kbmMemTable4.First; while not kbmMemTable4.Eof do begin if not P_SUM.Locate('揽货人',kbmMemTable4.fieldbyname('揽货人').asstring,[])then begin P_SUM.insert; P_SUM['揽货人']:=kbmMemTable4.fieldbyname('揽货人').asstring; P_SUM['特殊客户']:=kbmMemTable4.fieldbyname('提成').asfloat; P_SUM['已扣利润']:=0; P_SUM['扣利润']:=0.00; P_SUM['扣利息']:=0.00; P_SUM['当月结算']:=0.00; P_SUM['次月结算']:=0.00; P_SUM['拖至次月']:=0.00; P_SUM['三月结算']:=0.00; P_SUM['拖至三月']:=0.00; P_SUM['四月结算']:=0.00; P_SUM['拖至四月']:=0.00; P_SUM['应提成']:=0.00; P_SUM['合计提成']:=kbmMemTable4.fieldbyname('提成').asfloat; P_SUM.post; end else begin P_SUM.Edit; P_SUM['揽货人']:=kbmMemTable4.fieldbyname('揽货人').asstring; P_SUM['特殊客户']:=P_SUM['特殊客户']+kbmMemTable4.fieldbyname('提成').asfloat; P_SUM.post; end; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; kbmMemTable4.Next; end; end; { if not memtblDetail.IsEmpty then begin memtblDetail.SortOn('结算日期',[]); memtblDetail.Last; while not memtblDetail.Bof do begin if P_SUM.Locate('揽货人',memtblDetail.FieldByName('揽货人').AsString,[]) then begin memtblDetail.Edit; P_SUM.Edit; memtblDetail.FieldByName('剩余毛利').AsFloat:=memtblDetail.FieldByName('毛利润').AsFloat; if memtblDetail.FieldByName('结算帐期').AsString<>'特殊客户' then begin aQuery3.Close;aQuery3.SQL.Clear; aQuery3.SQL.Add('select * from t_crm_salesproftt where 方案名称 in (select 提成方案 from t_sys_employee where 姓名='''+memtblDetail.FieldByName('揽货人').AsString+''')'); aQuery3.open; if aQuery3.FieldByName('允许误差天数').IsNull then d:=0 else d:=aQuery3.FieldByName('允许误差天数').AsInteger; if (d<>0) and (memtblDetail.FieldByName('结算日期').AsDateTimememtblDetail.FieldByName('应结算日期').AsDateTime then aSBDATE:=memtblDetail.FieldByName('结算日期').AsDatetime else aSBDATE:=memtblDetail.FieldByName('应结算日期').AsDatetime; SB:=GetSALEprofit(memtblDetail.FieldByName('揽货人').AsString,0,P_SUM.FieldByName('毛利润').AsFloat,true); memtblDetail.FieldByName('实际提成比率').AsFloat:=SB; memtblDetail.FieldByName('原提成比率').AsFloat:=YB; end else begin YB:=GetSALEprofit(memtblDetail.FieldByName('揽货人').AsString,GetBetwMonth(memtblDetail.FieldByName('开船日期').AsDateTime,memtblDetail.FieldByName('应结算日期').AsDateTime),P_SUM.FieldByName('毛利润').AsFloat,False); if memtblDetail.FieldByName('结算日期').AsDateTime>memtblDetail.FieldByName('应结算日期').AsDateTime then aSBDATE:=memtblDetail.FieldByName('结算日期').AsDatetime else aSBDATE:=memtblDetail.FieldByName('应结算日期').AsDatetime; SB:=GetSALEprofit(memtblDetail.FieldByName('揽货人').AsString,GetBetwMonth(memtblDetail.FieldByName('开船日期').AsDateTime,aSBDATE),P_SUM.FieldByName('毛利润').AsFloat,issameMonth(memtblDetail.FieldByName('应结算日期').AsDateTime,memtblDetail.FieldByName('结算日期').AsDateTime)); memtblDetail.FieldByName('实际提成比率').AsFloat:=SB; memtblDetail.FieldByName('原提成比率').AsFloat:=YB; end; end; memtblDetail.FieldByName('应提成金额').AsFloat:=memtblDetail.FieldByName('毛利润').AsFloat*memtblDetail.FieldByName('原提成比率').AsFloat/100; memtblDetail.FieldByName('实际提成金额').AsFloat:=memtblDetail.FieldByName('剩余毛利').AsFloat*memtblDetail.FieldByName('实际提成比率').AsFloat/100; memtblDetail.FieldByName('提成差额').AsFloat:=memtblDetail.FieldByName('应提成金额').AsFloat-memtblDetail.FieldByName('实际提成金额').AsFloat; P_SUM['应提成']:=P_SUM['应提成']+memtblDetail.FieldByName('实际提成金额').AsFloat; P_SUM.Post; memtblDetail.Post; end; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; memtblDetail.Prior; end; memtblDetail.SortOn('揽货人;结算日期;工作编号',[]); end; } p_sum.First; while not p_sum.eof do begin P_SUM.edit; P_SUM['合计提成']:=P_SUM['应提成']+P_SUM['特殊客户']-P_SUM['扣利息']; P_SUM.post; P_SUM.Next; end; finally FreeAndNil(aQuery3); frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.MaxValue; frm_sys_progress.free; frm_sys_progress:=nil; end; end; procedure Tfrm_rp_sales_profit.Getlx; var aQuery:TADOQuery; aQuery2:TADOQuery; Str:String; betd,eetd:TDate; LXBL:Double; function GetHistryno(nodate:Tdate;bsno:String):double; var aQuery2:TADOQuery; begin aQuery2:=CreateAdoQuery; try with aQuery2 do begin Close;SQL.Clear; SQL.Add('select sum(CASE 类型 when ''收'' then 原始金额*汇率 else 0 end) as 未收合计 '); SQL.Add(' from v_fee_do_detail where 编号='''+bsno+''' and 结算日期<'''+DateToStr(nodate)+''''); SQL.Add(' Group by 编号'); OPEN; if IsEmpty then result:=0.00 else Result:=fieldbyName('未收合计').AsFloat; end; finally FreeAndNil(aQuery2); end; end; begin betd:=EncodeDate(StrToInt(wwDBComboBox20.Text), StrToInt(wwDBComboBox1.Text), 1); eetd:=EncodeDate(StrToInt(wwDBComboBox20.Text), StrToInt(wwDBComboBox1.Text), MonthDays[isLeapYear(StrToInt(wwDBComboBox20.Text)),StrToInt(wwDBComboBox1.Text)]); if not t_salepriftset.Active then t_salepriftset.Open; if not memtblLX.Active then memtblLX.Open; aQuery:=CreateAdoQuery; aQuery2:=CreateAdoQuery; if not ASSIGNED(frm_sys_progress) then frm_sys_progress:=tfrm_sys_progress.Create(application); try aQuery2.close;aQuery2.SQL.Clear; aQuery2.SQL.Add('select * from t_crm_salesproftt where (利息计算始月<> 0) AND (利息计算至月<> 0) and 方案名称 in (select distinct 方案名称 from t_sys_employee where 1=1 '); if RxDBLookupCombo3.DisplayValue<>'' then aQuery2.SQL.Add(' and 姓名='''+RxDBLookupCombo3.DisplayValue+''''); aQuery2.SQL.Add(')'); aQuery2.Open; aQuery2.First; while not aQuery2.Eof do begin with aQuery do begin Close;SQL.Clear; str:='select *,(合计应收-合计已收)*0.01 as 扣除利息 from v_op_bscard where 合计已收<>合计应收 and '; str:=Str+' '+bdatestr+'<'+''''+DateToStr(incmonth(betd,-(aQuery2.fieldbyname('利息计算始月').AsInteger-1)))+''''; str:=Str+' and '+bdatestr+'>='+''''+DateToStr(incmonth(betd,-(aQuery2.fieldbyname('利息计算至月').AsInteger-1)))+''''; str:=str+' and 揽货人 in (select 姓名 from t_sys_employee where 提成方案='''+aQuery2.fieldbyname('方案名称').asstring+''')'; 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+''''; str:=Str+' and 委托单位 not in (select 客户简称 from t_crm_client_sales where 是否特批客户=1) '; SQL.Add(str); Open; if not IsEmpty then begin frm_sys_progress.Show; frm_sys_progress.bsSkinGauge1.MaxValue:=RecordCount; frm_sys_progress.bsSkinGauge1.MinValue:=0; frm_sys_progress.bsSkinGauge1.Value:=0; frm_sys_progress.Update; first; while not eof do begin memtblLX.insert; memtblLX.FieldByName('编号').asstring:=FieldByName('编号').asstring; memtblLX.FieldByName('业务编号').asstring:=FieldByName('业务编号').asstring; memtblLX.FieldByName('主提单号').asstring:=FieldByName('主提单号').asstring; memtblLX.FieldByName('揽货人').asstring:=FieldByName('揽货人').asstring; memtblLX.FieldByName('客户名称').asstring:=FieldByName('委托单位').asstring; memtblLX.FieldByName('开船日期').value:=FieldByName('开船日期').value; memtblLX.FieldByName('未收USD').AsFloat:=FieldByName('应收USD').AsFloat-FieldByName('已收USD').AsFloat; memtblLX.FieldByName('未收RMB').AsFloat:=FieldByName('应收RMB').AsFloat-FieldByName('已收RMB').AsFloat; memtblLX.FieldByName('未收合计').AsFloat:=FieldByName('合计应收').AsFloat-GetHistryno(eetd+1,FieldByName('编号').asstring); memtblLX.FieldByName('扣息开始日期').value:=IncMonth(FieldByName('开船日期').value,3); memtblLX.FieldByName('扣息月数').AsInteger:=1; if t_salepriftset.Locate('姓名',Trim(FieldByName('揽货人').asstring),[]) then LXBL:=t_salepriftset.FieldByName('利息').AsFloat else LXBL:=0; memtblLX.FieldByName('扣息比率').AsFloat:=LXBL; memtblLX.FieldByName('扣息金额').AsFloat:=(memtblLX.FieldByName('未收合计').AsFloat)*LXBL/100; memtblLX.post; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; Next; end; end; Close;SQL.Clear; str:='select * from v_op_bscard_MAX where 合计应收=合计已收 and '; str:=Str+' '+bdatestr+'<'+''''+DateToStr(incmonth(betd,-(aQuery2.fieldbyname('利息计算始月').AsInteger-1)))+''''; str:=Str+' and '+bdatestr+'>='+''''+DateToStr(incmonth(betd,-(aQuery2.fieldbyname('利息计算至月').AsInteger-1)))+''''; str:=Str+' and 结算日期>='+''''+DateToStr(betd)+''''; str:=str+' and 揽货人 in (select 姓名 from t_sys_employee where 提成方案='''+aQuery2.fieldbyname('方案名称').asstring+''')'; if not bsSkinCheckRadioBox1.Checked then str:=Str+' and 开船日期>='+'''2008-01-01'''; 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+''''; str:=Str+' and 委托单位 not in (select 客户简称 from t_crm_client_sales where 是否特批客户=1) '; SQL.Add(str); Open; if not IsEmpty then begin first; while not eof do begin memtblLX.insert; memtblLX.FieldByName('编号').asstring:=FieldByName('编号').asstring; memtblLX.FieldByName('业务编号').asstring:=FieldByName('业务编号').asstring; memtblLX.FieldByName('主提单号').asstring:=FieldByName('主提单号').asstring; memtblLX.FieldByName('揽货人').asstring:=FieldByName('揽货人').asstring; memtblLX.FieldByName('客户名称').asstring:=FieldByName('委托单位').asstring; memtblLX.FieldByName('开船日期').value:=FieldByName('开船日期').value; memtblLX.FieldByName('未收USD').AsFloat:=FieldByName('应收USD').AsFloat-FieldByName('已收USD').AsFloat; memtblLX.FieldByName('未收RMB').AsFloat:=FieldByName('应收RMB').AsFloat-FieldByName('已收RMB').AsFloat; memtblLX.FieldByName('未收合计').AsFloat:=FieldByName('合计应收').AsFloat-GetHistryno(eetd+1,FieldByName('编号').asstring); memtblLX.FieldByName('扣息开始日期').value:=IncMonth(FieldByName('开船日期').value,3); memtblLX.FieldByName('扣息月数').AsInteger:=1; if t_salepriftset.Locate('姓名',Trim(FieldByName('揽货人').asstring),[]) then LXBL:=t_salepriftset.FieldByName('利息').AsFloat else LXBL:=0; memtblLX.FieldByName('扣息比率').AsFloat:=LXBL; memtblLX.FieldByName('扣息金额').AsFloat:=(memtblLX.FieldByName('未收合计').AsFloat)*LXBL/100; memtblLX.post; Next; end; end; end; aQuery2.Next; end; memtblLX.first; while not memtblLX.Eof do begin if memtblLX.FieldByName('扣息金额').AsFloat=0 then memtblLX.Delete else memtblLX.Next; end; memtblLX.SortOn('客户名称;揽货人;开船日期',[]); finally frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.MaxValue; frm_sys_progress.free; frm_sys_progress:=nil; FreeAndNil(aQuery); FreeAndNil(aQuery2); end; end; function Tfrm_rp_sales_profit.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.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; procedure Tfrm_rp_sales_profit.Getcq; var aQuery:TADOQuery; aQuery2:TADOQuery; Str:String; betd,eetd:TDate; LXBL:Double; function GetHistryno(nodate:Tdate;bsno:String):double; var aQuery2:TADOQuery; begin aQuery2:=CreateAdoQuery; try with aQuery2 do begin Close;SQL.Clear; SQL.Add('select sum(CASE 类型 when ''收'' then 原始金额*汇率 else 0 end) as 未收合计 '); SQL.Add(' from v_fee_do_detail where 编号='''+bsno+''' and 结算日期<'''+DateToStr(nodate)+''''); SQL.Add(' Group by 编号'); OPEN; if IsEmpty then result:=0.00 else Result:=fieldbyName('未收合计').AsFloat; end; finally FreeAndNil(aQuery2); end; end; function GetHistryUSDno(nodate:Tdate;bsno:String):double; var aQuery2:TADOQuery; begin aQuery2:=CreateAdoQuery; try with aQuery2 do begin Close;SQL.Clear; SQL.Add('select sum(CASE 类型 when ''收'' then 原始金额 else 0 end) as 未收合计 '); SQL.Add(' from v_fee_do_detail where 原始币别=''USD'' and 编号='''+bsno+''' and 结算日期<'''+DateToStr(nodate)+''''); SQL.Add(' Group by 编号'); OPEN; if IsEmpty then result:=0.00 else Result:=fieldbyName('未收合计').AsFloat; end; finally FreeAndNil(aQuery2); end; end; function GetHistryRMBno(nodate:Tdate;bsno:String):double; var aQuery2:TADOQuery; begin aQuery2:=CreateAdoQuery; try with aQuery2 do begin Close;SQL.Clear; SQL.Add('select sum(CASE 类型 when ''收'' then 原始金额*汇率 else 0 end) as 未收合计 '); SQL.Add(' from v_fee_do_detail where 原始币别<>''USD'' and 编号='''+bsno+''' and 结算日期<'''+DateToStr(nodate)+''''); SQL.Add(' Group by 编号'); OPEN; if IsEmpty then result:=0.00 else Result:=fieldbyName('未收合计').AsFloat; end; finally FreeAndNil(aQuery2); end; end; begin betd:=EncodeDate(StrToInt(wwDBComboBox20.Text), StrToInt(wwDBComboBox1.Text), 1); eetd:=EncodeDate(StrToInt(wwDBComboBox20.Text), StrToInt(wwDBComboBox1.Text), MonthDays[isLeapYear(StrToInt(wwDBComboBox20.Text)),StrToInt(wwDBComboBox1.Text)]); if not kbmMemTable2.Active then kbmMemTable2.Open; aQuery:=CreateAdoQuery; aQuery2:=CreateAdoQuery; if not ASSIGNED(frm_sys_progress) then frm_sys_progress:=tfrm_sys_progress.Create(application); try aQuery2.close;aQuery2.SQL.Clear; aQuery2.SQL.Add('select * from t_crm_salesproftt where (死帐计算月份<> 0) and 方案名称 in (select distinct 方案名称 from t_sys_employee where 1=1 '); if RxDBLookupCombo3.DisplayValue<>'' then aQuery2.SQL.Add(' and 姓名='''+RxDBLookupCombo3.DisplayValue+''''); aQuery2.SQL.Add(')'); aQuery2.Open; aQuery2.First; while not aQuery2.Eof do begin with aQuery do begin Close;SQL.Clear; str:='select *,合计应收-合计已收 as 扣除利润 from v_op_bscard where 合计已收<>合计应收 and '; str:=Str+' '+bdatestr+'<'+''''+DateToStr(incmonth(betd,-(aQuery2.fieldbyname('死帐计算月份').AsInteger-1)))+''''; str:=Str+' and '+bdatestr+'>='+''''+DateToStr(incmonth(betd,-aQuery2.fieldbyname('死帐计算月份').AsInteger))+''''; str:=str+' and 揽货人 in (select 姓名 from t_sys_employee where 提成方案='''+aQuery2.fieldbyname('方案名称').asstring+''')'; 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+''''; str:=Str+' and 委托单位 not in (select 客户简称 from t_crm_client_sales where 是否特批客户=1) '; SQL.Add(str); Open; if not IsEmpty then begin frm_sys_progress.Show; frm_sys_progress.bsSkinGauge1.MaxValue:=RecordCount; frm_sys_progress.bsSkinGauge1.MinValue:=0; frm_sys_progress.bsSkinGauge1.Value:=0; frm_sys_progress.Update; first; while not eof do begin kbmMemTable2.insert; kbmMemTable2.FieldByName('编号').asstring:=FieldByName('编号').asstring; kbmMemTable2.FieldByName('业务编号').asstring:=FieldByName('业务编号').asstring; kbmMemTable2.FieldByName('主提单号').asstring:=FieldByName('主提单号').asstring; kbmMemTable2.FieldByName('揽货人').asstring:=FieldByName('揽货人').asstring; kbmMemTable2.FieldByName('委托单位').asstring:=FieldByName('委托单位').asstring; kbmMemTable2.FieldByName('开船日期').value:=FieldByName('开船日期').value; kbmMemTable2.FieldByName('应收USD').AsFloat:=FieldByName('应收USD').AsFloat; kbmMemTable2.FieldByName('应收RMB').AsFloat:=FieldByName('应收RMB').AsFloat; kbmMemTable2.FieldByName('合计应收').AsFloat:=FieldByName('合计应收').AsFloat; kbmMemTable2.FieldByName('已收USD').AsFloat:=GetHistryusdno(eetd+1,FieldByName('编号').asstring); kbmMemTable2.FieldByName('已收RMB').AsFloat:=GetHistryRMBno(eetd+1,FieldByName('编号').asstring); kbmMemTable2.FieldByName('合计已收').AsFloat:=GetHistryno(eetd+1,FieldByName('编号').asstring); kbmMemTable2.FieldByName('未收USD').AsFloat:=kbmMemTable2.FieldByName('应收USD').AsFloat-kbmMemTable2.FieldByName('已收USD').AsFloat; kbmMemTable2.FieldByName('未收RMB').AsFloat:=kbmMemTable2.FieldByName('应收RMB').AsFloat-kbmMemTable2.FieldByName('已收RMB').AsFloat; kbmMemTable2.FieldByName('合计未收').AsFloat:=FieldByName('合计应收').AsFloat-kbmMemTable2.FieldByName('合计已收').AsFloat; kbmMemTable2.FieldByName('利润USD').AsFloat:=FieldByName('利润USD').AsFloat; kbmMemTable2.FieldByName('利润RMB').AsFloat:=FieldByName('利润RMB').AsFloat; kbmMemTable2.FieldByName('毛利润').AsFloat:=FieldByName('毛利润').AsFloat; kbmMemTable2.FieldByName('扣除利润').AsFloat:=kbmMemTable2.FieldByName('合计未收').AsFloat; kbmMemTable2.post; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; Next; end; end; Close;SQL.Clear; str:='select * from v_op_bscard_MAX where 合计应收=合计已收 and '; str:=Str+' '+bdatestr+'<'+''''+DateToStr(incmonth(betd,-(aQuery2.fieldbyname('死帐计算月份').AsInteger-1)))+''''; str:=Str+' and '+bdatestr+'>='+''''+DateToStr(incmonth(betd,-aQuery2.fieldbyname('死帐计算月份').AsInteger))+''''; str:=Str+' and 结算日期>='+''''+DateToStr(betd)+''''; str:=str+' and 揽货人 in (select 姓名 from t_sys_employee where 提成方案='''+aQuery2.fieldbyname('方案名称').asstring+''')'; if not bsSkinCheckRadioBox1.Checked then str:=Str+' and 开船日期>='+'''2008-01-01'''; 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+''''; str:=Str+' and 委托单位 not in (select 客户简称 from t_crm_client_sales where 是否特批客户=1) '; SQL.Add(str); // SHOWMESSAGE(str); Open; if not IsEmpty then begin first; while not eof do begin kbmMemTable2.insert; kbmMemTable2.FieldByName('编号').asstring:=FieldByName('编号').asstring; kbmMemTable2.FieldByName('业务编号').asstring:=FieldByName('业务编号').asstring; kbmMemTable2.FieldByName('主提单号').asstring:=FieldByName('主提单号').asstring; kbmMemTable2.FieldByName('揽货人').asstring:=FieldByName('揽货人').asstring; kbmMemTable2.FieldByName('委托单位').asstring:=FieldByName('委托单位').asstring; kbmMemTable2.FieldByName('开船日期').value:=FieldByName('开船日期').value; kbmMemTable2.FieldByName('应收USD').AsFloat:=FieldByName('应收USD').AsFloat; kbmMemTable2.FieldByName('应收RMB').AsFloat:=FieldByName('应收RMB').AsFloat; kbmMemTable2.FieldByName('合计应收').AsFloat:=FieldByName('合计应收').AsFloat; kbmMemTable2.FieldByName('已收USD').AsFloat:=GetHistryusdno(eetd+1,FieldByName('编号').asstring); kbmMemTable2.FieldByName('已收RMB').AsFloat:=GetHistryRMBno(eetd+1,FieldByName('编号').asstring); kbmMemTable2.FieldByName('合计已收').AsFloat:=GetHistryno(eetd+1,FieldByName('编号').asstring); kbmMemTable2.FieldByName('未收USD').AsFloat:=kbmMemTable2.FieldByName('应收USD').AsFloat-kbmMemTable2.FieldByName('已收USD').AsFloat; kbmMemTable2.FieldByName('未收RMB').AsFloat:=kbmMemTable2.FieldByName('应收RMB').AsFloat-kbmMemTable2.FieldByName('已收RMB').AsFloat; kbmMemTable2.FieldByName('合计未收').AsFloat:=kbmMemTable2.FieldByName('合计应收').AsFloat-kbmMemTable2.FieldByName('合计已收').AsFloat; kbmMemTable2.FieldByName('利润USD').AsFloat:=FieldByName('利润USD').AsFloat; kbmMemTable2.FieldByName('利润RMB').AsFloat:=FieldByName('利润RMB').AsFloat; kbmMemTable2.FieldByName('毛利润').AsFloat:=FieldByName('毛利润').AsFloat; kbmMemTable2.FieldByName('扣除利润').AsFloat:=kbmMemTable2.FieldByName('合计未收').AsFloat; kbmMemTable2.post; Next; end; end; end; aQuery2.next; end; kbmMemTable2.SortOn('委托单位;揽货人;开船日期',[]); finally frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.MaxValue; frm_sys_progress.free; frm_sys_progress:=nil; FreeAndNil(aQuery); end; end; procedure Tfrm_rp_sales_profit.dxDBGrid2DblClick(Sender: TObject); begin fee_view(memtblDetail.fieldbyname('编号').asstring); end; procedure Tfrm_rp_sales_profit.bsSkinButton1Click(Sender: TObject); var i:integer; begin if not if_open('405') then begin showmessage('你没有此模块的操作权限!,请联系系统管理员,权限设置路径:操作管理--->销售管理--->发放提成'); exit; end; try memtblDetail.DisableControls; for i:=0 to dxDBGrid2.SelectedCount-1 do begin memtblDetail.GotoBookmark(pointer(dxDBGrid2.selectedrows[i])); UpdateBsProfit(memtblDetail.fieldbyname('业务类型').asstring,memtblDetail.fieldbyname('编号').asstring,1); memtblDetail.Edit; memtblDetail.fieldbyname('提成结算').AsString:='1'; memtblDetail.Post; end; finally memtblDetail.EnableControls; end; end; procedure Tfrm_rp_sales_profit.bsSkinButton2Click(Sender: TObject); var i:integer; begin if not if_open('406') then begin showmessage('你没有此模块的操作权限!,请联系系统管理员,权限设置路径:操作管理--->销售管理--->取消提成'); exit; end; try memtblDetail.DisableControls; for i:=0 to dxDBGrid2.SelectedCount-1 do begin memtblDetail.GotoBookmark(pointer(dxDBGrid2.selectedrows[i])); UpdateBsProfit(memtblDetail.fieldbyname('业务类型').asstring,memtblDetail.fieldbyname('编号').asstring,0); memtblDetail.Edit; memtblDetail.fieldbyname('提成结算').AsString:='0'; memtblDetail.Post; end; finally memtblDetail.EnableControls; end; end; procedure Tfrm_rp_sales_profit.dxDBGrid2CustomDraw(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[dxDBGrid2Column33.Index])='1' then begin // AFont.Style:=AFont.Style+[fsStrikeOut]; AColor:=clRed; exit; end; end; procedure Tfrm_rp_sales_profit.MenuItem7Click(Sender: TObject); begin grid_save_xls(dxdbgrid6); end; procedure Tfrm_rp_sales_profit.bsSkinButton3Click(Sender: TObject); var betd,eetd:TDate; aquery,bquery:TADOQuery; str:String; begin aQuery:=CreateAdoQuery; bQuery:=CreateAdoQuery; with aQuery do try Close;SQL.Clear; str:='select 编号,揽货人,业务类型,主提单号,发票号,委托编号,委托单位,开船日期,(应收RMB-已收RMB) 未收RMB,(应收USD- 已收USD) 未收USD,(合计应收- 合计已收) 未收合计,应收RMB,应收USD,合计应收 应收合计 from v_op_bscard where 1=1 and '; str:=Str+' '+bdatestr+'>='+''''+DateToStr(wwDBDateTimePicker1.Date)+''''; str:=Str+' and '+bdatestr+'<='+''''+DateToStr(wwDBDateTimePicker2.Date)+''''; if RxDBLookupCombo3.DisplayValue<>'' then str:=Str+' and 揽货人='+''''+RxDBLookupCombo3.DisplayValue+''''; if Edit1.text<>'' then str:=Str+' and 发票号='+''''+Edit1.text+''''; if RxDBLookupCombo2.DisplayValue<>'' then str:=Str+' and 委托单位='+''''+RxDBLookupCombo2.DisplayValues[1]+''''; if RxDBLookupCombo10.DisplayValue<>'' then str:=Str+' and 销售部门='+''''+RxDBLookupCombo10.DisplayValue+''''; case bsSkinComboBox1.itemindex of 1: str:=Str+' and (fee2=0 or fee2 is null) '; 2: str:=Str+' and (fee2=1) '; end; case bsSkinComboBox2.itemindex of 1: str:=Str+' and 费用状态=''录入状态'''; 2: str:=Str+' and 费用状态=''费用封帐'''; end; SQL.Add(str); SQL.Add(' and 委托单位 in (select 客户简称 from t_crm_client_sales)'); SQL.Add(' order by 揽货人'); Open;First; kbmqc.EmptyTable; kbmqc.Open; while not eof do begin kbmqc.insert; kbmqc.FieldByName('编号').AsString:=FieldByName('编号').AsString; kbmqc.FieldByName('揽货人').AsString:=FieldByName('揽货人').AsString; kbmqc.FieldByName('扣息月').AsString:=FieldByName('发票号').AsString; kbmqc.FieldByName('主提单号').AsString:=FieldByName('主提单号').AsString; kbmqc.FieldByName('委托编号').AsString:=FieldByName('委托编号').AsString; kbmqc.FieldByName('客户名称').AsString:=FieldByName('委托单位').AsString; kbmqc.FieldByName('开船日期').AsDateTime:=FieldByName('开船日期').AsDateTime; kbmqc.FieldByName('未收RMB').AsFloat:=FieldByName('未收RMB').AsFloat; kbmqc.FieldByName('未收USD').AsFloat:=FieldByName('未收USD').AsFloat; kbmqc.FieldByName('未收合计').AsFloat:=FieldByName('未收合计').AsFloat; kbmqc.FieldByName('应收RMB').AsFloat:=FieldByName('应收RMB').AsFloat; kbmqc.FieldByName('应收USD').AsFloat:=FieldByName('应收USD').AsFloat; kbmqc.FieldByName('应收合计').AsFloat:=FieldByName('应收合计').AsFloat; kbmqc.FieldByName('应结日期').AsDateTime:=getzq(kbmqc.FieldByName('客户名称').AsString,kbmqc.FieldByName('开船日期').AsDateTime); bQuery.Close; bQuery.SQL.Clear; bQuery.SQL.Add('select top 1 结算日期 from v_fee_do_jie where 业务编号='''+kbmqc.FieldByName('编号').AsString+''' order by 结算日期 DESC '); bQuery.Open; if not bQuery.IsEmpty then begin kbmqc.FieldByName('结算日期').VALUE:=bQuery.FieldByName('结算日期').AsDateTime; end; kbmqc.FieldByName('结费类型').AsString:=getzqtype(kbmqc.FieldByName('客户名称').AsString,kbmqc.FieldByName('开船日期').AsDateTime); kbmqc.FieldByName('宽限天数').AsInteger:=StrToInt(bsSkinEdit1.text); if (DaysBetween(Date,kbmqc.FieldByName('应结日期').AsDateTime)-kbmqc.FieldByName('宽限天数').AsInteger)>0 then begin if not kbmqc.FieldByName('结算日期').IsNull then begin if kbmqc.FieldByName('结算日期').AsDateTime>kbmqc.FieldByName('应结日期').AsDateTime then kbmqc.FieldByName('扣息天数').AsInteger:=DaysBetween(kbmqc.FieldByName('结算日期').AsDateTime,kbmqc.FieldByName('应结日期').AsDateTime)-kbmqc.FieldByName('宽限天数').AsInteger else kbmqc.FieldByName('扣息天数').AsInteger:=0; kbmqc.FieldByName('扣息百分比').AsFloat:=CalcProftAmtqx(kbmqc.FieldByName('扣息天数').AsFloat,kbmqc.FieldByName('揽货人').AsString); if trim(kbmqc.FieldByName('结费类型').AsString)<>'现结买单' then kbmqc.FieldByName('利息').AsString:=FormatFloat('0.00;-0.00;0',kbmqc.FieldByName('扣息百分比').AsFloat/100*kbmqc.FieldByName('应收合计').AsFloat*kbmqc.FieldByName('扣息天数').AsInteger); end else begin if Date>kbmqc.FieldByName('应结日期').AsDateTime then kbmqc.FieldByName('扣息天数').AsInteger:=DaysBetween(Date,kbmqc.FieldByName('应结日期').AsDateTime)-kbmqc.FieldByName('宽限天数').AsInteger else kbmqc.FieldByName('扣息天数').AsInteger:=0; kbmqc.FieldByName('扣息百分比').AsFloat:=CalcProftAmtqx(kbmqc.FieldByName('扣息天数').AsFloat,kbmqc.FieldByName('揽货人').AsString); if trim(kbmqc.FieldByName('结费类型').AsString)<>'现结买单' then kbmqc.FieldByName('利息').AsString:=FormatFloat('0.00;-0.00;0',kbmqc.FieldByName('扣息百分比').AsFloat/100*kbmqc.FieldByName('应收合计').AsFloat*kbmqc.FieldByName('扣息天数').AsInteger); end; { if kbmtc.Locate('揽货人',Trim(kbmqc.FieldByName('揽货人').AsString),[]) then begin kbmtc.Edit; kbmtc.FieldByName('扣息').AsFloat:=kbmtc.FieldByName('扣息').AsFloat+kbmqc.FieldByName('利息').AsFloat; kbmtc.Post; end; } try kbmqc.Post; except on e:Exception do begin ShowMessage(e.Message); end; end; end; Next; end; finally FreeAndNil(aquery); end; end; procedure Tfrm_rp_sales_profit.texClick(Sender: TObject); var i:integer; begin if Edit2.text='' then begin ShowMessage('请输入月份'); Exit; end; if dxDBGrid6.SelectedCount<1 then begin showmessage('请选择要打印的业务帐单!!'); exit; end; try kbmqc.DisableControls; for i:=0 to dxDBGrid6.SelectedCount-1 do begin kbmqc.GotoBookmark(pointer(dxDBGrid6.selectedrows[i])); end; finally kbmqc.EnableControls; end; end; end.