unit u_rp_op_profit; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, bsSkinCtrls, ExtCtrls, ComCtrls, bsSkinTabs, DB, ADODB,DateUtils, dxExEdtr, dxDBTLCl, dxGrClms, dxDBGrid, dxTL, dxDBCtrl, dxCntner, kbmMemTable, kbmMemBinaryStreamFormat, Menus, StdCtrls, wwdbdatetimepicker, Grids, DBGridEh, Mask, wwdbedit, Wwdotdot, Wwdbcomb, RxLookup, DBGrids, bsSkinBoxCtrls, DBCtrlsEh,inifiles, CheckLst; type Tfrm_rp_op_profit = class(TForm) kbmThreadDataSet1: TkbmThreadDataSet; Panel2: TPanel; Label2: TLabel; Label3: TLabel; Label1: TLabel; Label4: TLabel; Label6: TLabel; wwDBComboBox1: TwwDBComboBox; wwDBComboBox20: TwwDBComboBox; wwDBComboBox2: TwwDBComboBox; bsSkinButton10: TbsSkinButton; CheckListBox1: TCheckListBox; bsSkinButton9: TbsSkinButton; bsSkinButton5: TbsSkinButton; dxDBGrid8: TdxDBGrid; dxDBGrid8Column7: TdxDBGridColumn; dxDBGridColumn4: TdxDBGridColumn; dxDBGridColumn7: TdxDBGridColumn; dxDBGrid6: TdxDBGrid; kbmqc: TkbmMemTable; kbmqcField2: TStringField; kbmqc1: TDataSource; kbmtc: TkbmMemTable; kbmtcField: TStringField; kbmtcField2: TFloatField; kbmtc1: TDataSource; RxDBLookupCombo3: TRxDBLookupCombo; PopupMenu1: TPopupMenu; MenuItem7: TMenuItem; kbmtcOrdno: TIntegerField; PopupMenu2: TPopupMenu; N1: TMenuItem; kbmqcField: TStringField; kbmqcOrdno: TIntegerField; kbmqcField3: TStringField; kbmqcField4: TStringField; kbmqcTEU: TFloatField; kbmqcBooleanField: TBooleanField; kbmqcBooleanField2: TBooleanField; kbmqcField5: TBooleanField; kbmqcField6: TBooleanField; kbmqcField7: TBooleanField; kbmqcBooleanField3: TBooleanField; dxDBGrid6Column1: TdxDBGridColumn; dxDBGrid6Column2: TdxDBGridColumn; dxDBGrid6Column3: TdxDBGridColumn; dxDBGrid6Column4: TdxDBGridColumn; dxDBGrid6Column6: TdxDBGridCheckColumn; dxDBGrid6Column7: TdxDBGridCheckColumn; dxDBGrid6Column8: TdxDBGridCheckColumn; dxDBGrid6Column9: TdxDBGridCheckColumn; dxDBGrid6Column10: TdxDBGridCheckColumn; dxDBGrid6Column11: TdxDBGridCheckColumn; dxDBGrid6Column5: TdxDBGridColumn; dxDBGrid6Column12: TdxDBGridColumn; kbmqcField8: TFloatField; dxDBGrid6Column13: TdxDBGridColumn; kbmqcField9: TStringField; kbmtcField3: TStringField; Label5: TLabel; wwDBDateTimePicker1: TwwDBDateTimePicker; Label7: TLabel; wwDBDateTimePicker2: TwwDBDateTimePicker; kbmqcField10: TBooleanField; dxDBGrid6Column14: TdxDBGridCheckColumn; procedure bsSkinButton5Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormShow(Sender: TObject); procedure bsSkinButton10Click(Sender: TObject); procedure bsSkinButton9Click(Sender: TObject); procedure MenuItem7Click(Sender: TObject); procedure dxDBGrid6DblClick(Sender: TObject); procedure N1Click(Sender: TObject); private { Private declarations } public { Public declarations } ordno:Integer; procedure GetProfittcLx(depts:string;beginEtd,EndEtd:TDateTime); function CalcProftAmttc(ProftAmt:Double;Employee:string):Double; function getzq(cust: string;aDate:TDateTime):TDateTime; function getzqtype(cust: string;aDate:TDateTime):string; function CalcProftAmtqx(ProftAmt:Double;Employee:string):Double; procedure UpdateBsProfit(bstype,bsno:String;fee:integer); procedure UpdateBsProfitLc(bstype,bsno,LcYYMM:String); end; var frm_rp_op_profit: Tfrm_rp_op_profit; FmDate,ToDate:String; sqlstr:WideString; implementation uses u_main, my_sys_function,u_sys_progress; {$R *.dfm} procedure Tfrm_rp_op_profit.bsSkinButton5Click(Sender: TObject); begin close; end; procedure Tfrm_rp_op_profit.FormClose(Sender: TObject; var Action: TCloseAction); var inifile1:Tinifile; begin savereggrid(dxdbgrid6,caption+'6'); savereggrid(dxdbgrid8,caption+'8'); frm_rp_op_profit.Hide; frm_rp_op_profit.ManualFloat(frm_rp_op_profit.BoundsRect ); frm_main.freeTabs('frm_rp_op_profit'); action:=cafree; frm_rp_op_profit:=nil; inifile1:=Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini'); inifile1.free; end; procedure Tfrm_rp_op_profit.FormShow(Sender: TObject); var bYear,bMonth,bDate:Word; inifile1:Tinifile; aAdoQuery:TAdoQuery; begin loadreggrid(dxdbgrid6,false,caption+'6'); loadreggrid(dxdbgrid8,false,caption+'8'); DecodeDate(incmonth(Now),bYear,bMonth,bDate); wwDBComboBox20.Text:=IntToStr(bYear); wwDBComboBox20.Text:=IntToStr(YearOf(date)); wwDBComboBox1.Text:=IntToStr(bMonth); wwDBComboBox2.Text:=IntToStr(bMonth); wwDBDateTimePicker1.date:=Date; wwDBDateTimePicker2.date:=Date; aAdoQuery:=CreateAdoQuery; with aAdoQuery do try Close;SQL.Clear; SQL.Add('select 部门名称 from t_sys_department '); SQL.Add('order by 部门名称'); Open;first; CheckListBox1.Clear; while not eof do begin CheckListBox1.Items.Add(trim(FieldByName('部门名称').AsString)); next; end; finally aAdoQuery.Free; end; inifile1:=Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini'); inifile1.free; end; function Tfrm_rp_op_profit.CalcProftAmttc(ProftAmt:Double;Employee:string):Double; begin end; procedure Tfrm_rp_op_profit.GetProfittcLx(depts:string;beginEtd,EndEtd:TDateTime); var betd,eetd:TDate; aquery:TADOQuery; str,bdatestr:String; rate:double; begin bdatestr:='s.开船日期'; betd:=beginEtd; eetd:=EndEtd; aQuery:=CreateAdoQuery; with aQuery do try Close;SQL.Clear; str:='select s.编号,s.操作员,s.主提单号,s.开船日期'; str:=Str+' '+',sum(case when (fee.费用名称=''海运费'') or (fee.费用名称=''THC费'') or (fee.费用名称=''包干费'') then fee.金额 else 0 end) 海运费'; str:=Str+' '+',sum(case when (fee.费用名称=''拖车费'') or (fee.费用名称=''陆运费'') then fee.金额 else 0 end) 拖车费'; str:=Str+' '+',sum(case when fee.费用名称=''报关费'' then fee.金额 else 0 end) 报关费'; str:=Str+' '+',sum(case when fee.费用名称=''制冷费'' then fee.金额 else 0 end) 制冷费'; str:=Str+' '+',sum(case when fee.费用名称=''监护费'' then fee.金额 else 0 end) 监护费'; str:=Str+' '+',sum(case when fee.费用名称=''舱单费'' then fee.金额 else 0 end) 舱单费'; str:=Str+' '+',ctn.TEU'; str:=Str+' '+',ass.分单数量'; str:=Str+' '+'from t_op_seae s '; str:=Str+' '+'left join (select 编号,sum(TEU) TEU from t_op_ctn group by 编号) ctn on s.编号=ctn.编号'; str:=Str+' '+'left join t_ch_fee fee on fee.编号=s.编号 and fee.类型=''收'''; str:=Str+' '+'left join (select 编号,count(*) 分单数量 from t_op_seae_assistant group by 编号 ) as ass on s.编号=ass.编号'; str:=Str+' '+'where 1=1 and s.业务类型=''普通货'' and '; str:=Str+' '+bdatestr+'>='+''''+DateToStr(betd)+''''; str:=Str+' and '+bdatestr+'<='+''''+DateToStr(eetd)+''''; if RxDBLookupCombo3.DisplayValue<>'' then str:=Str+' and s.操作员='+''''+RxDBLookupCombo3.DisplayValue+''''; if depts<>'' then str:=Str+' and s.操作部门 in ('+depts+')'; str:=str+' and '+open_data('0001','s.录入人', 's.操作员','s.客服员','no','no','no'); SQL.Add(str); SQL.Add(' group by s.编号,s.操作员,s.主提单号,s.开船日期,ass.分单数量,ctn.TEU'); SQL.Add(' order by s.操作员,s.开船日期'); // showmessage(SQL.Text); Open;First; while not eof do begin kbmqc.insert; kbmqc.FieldByName('OrdNo').AsInteger:=OrdNo; kbmqc.FieldByName('操作员').AsString:=FieldByName('操作员').AsString; kbmqc.FieldByName('主提单号').AsString:=FieldByName('主提单号').AsString; kbmqc.FieldByName('开船日期').AsString:=FieldByName('开船日期').AsString; kbmqc.FieldByName('海运费').AsBoolean:=FieldByName('海运费').AsFloat<>0; kbmqc.FieldByName('拖车费').AsBoolean:=FieldByName('拖车费').AsFloat<>0; kbmqc.FieldByName('报关费').AsBoolean:=FieldByName('报关费').AsFloat<>0; kbmqc.FieldByName('制冷费').AsBoolean:=FieldByName('制冷费').AsFloat<>0; kbmqc.FieldByName('监护费').AsBoolean:=FieldByName('监护费').AsFloat<>0; kbmqc.FieldByName('舱单费').AsBoolean:=FieldByName('舱单费').AsFloat<>0; kbmqc.FieldByName('TEU').AsFloat:=FieldByName('TEU').AsFloat; kbmqc.FieldByName('分单').AsBoolean:=FieldByName('分单数量').AsFloat<>0; kbmqc.FieldByName('年月').AsString:=FormatDateTime('YYMM',Eetd); kbmqc.FieldByName('编号').AsString:=FieldByName('编号').AsString; rate:=0; if kbmqc.FieldByName('海运费').AsBoolean then begin rate:=1; if kbmqc.FieldByName('TEU').AsFloat>10 then rate:=rate+0.5; if kbmqc.FieldByName('分单').AsBoolean then rate:=rate+0.7; if kbmqc.FieldByName('监护费').AsBoolean then rate:=rate+0.5; if kbmqc.FieldByName('制冷费').AsBoolean then rate:=rate+0.2; { if kbmqc.FieldByName('拖车费').AsBoolean then rate:=rate+0.2; if kbmqc.FieldByName('报关费').AsBoolean then rate:=rate+0.2; } end else begin if (kbmqc.FieldByName('报关费').AsBoolean) and kbmqc.FieldByName('拖车费').AsBoolean then rate:=0.5 else if kbmqc.FieldByName('报关费').AsBoolean then rate:=0.2 else if kbmqc.FieldByName('拖车费').AsBoolean then rate:=0.2; if kbmqc.FieldByName('舱单费').AsBoolean then rate:=rate+0.2; if kbmqc.FieldByName('TEU').AsFloat>10 then rate:=rate+0.5; end; kbmqc.FieldByName('合计').AsFloat:=rate; kbmqc.Post; if kbmtc.Locate('年月;操作员',varArrayof([kbmqc.FieldByName('年月').AsString,kbmqc.FieldByName('操作员').AsString]),[]) then begin kbmtc.Edit; kbmtc.FieldByName('票数').AsFloat:=kbmtc.FieldByName('票数').AsFloat+rate; kbmtc.Post; end else begin kbmtc.insert; kbmtc.FieldByName('OrdNo').AsInteger:=OrdNo; kbmtc.FieldByName('操作员').AsString:=FieldByName('操作员').AsString; kbmtc.FieldByName('年月').AsString:=FormatDateTime('YYMM',eetd); kbmtc.FieldByName('票数').AsFloat:=rate; kbmtc.Post; end; OrdNo:=OrdNo+1; Next; end; finally FreeAndNil(aquery); end; end; procedure Tfrm_rp_op_profit.bsSkinButton10Click(Sender: TObject); var i,j :integer; depts:string; betd,eetd:TDate; begin ordno:=1; for i:=0 to CheckListBox1.Items.Count-1 do begin if CheckListBox1.Checked[i] then if depts='' then depts:=''''+CheckListBox1.Items[i]+'''' else depts:=depts+','+''''+CheckListBox1.Items[i]+''''; end; kbmqc.EmptyTable; kbmqc.Open; kbmtc.EmptyTable; kbmtc.Open; betd:=wwDBDateTimePicker1.date; eetd:=wwDBDateTimePicker2.date; GetProfittcLx(depts,betd,eetd); { for j:=StrToInt(wwDBComboBox1.Text) to StrToInt(wwDBComboBox2.Text) do begin betd:=EncodeDate(StrToInt(wwDBComboBox20.Text), j, 1); eetd:=EncodeDate(StrToInt(wwDBComboBox20.Text), j, MonthDays[isLeapYear(StrToInt(wwDBComboBox20.Text)),j]); GetProfittcLx(depts,betd,eetd); end; } end; function Tfrm_rp_op_profit.getzq(cust: string;aDate:TDateTime):TDateTime; begin end; function Tfrm_rp_op_profit.getzqtype(cust: string;aDate:TDateTime):string; begin end; function Tfrm_rp_op_profit.CalcProftAmtqx(ProftAmt:Double;Employee:string):Double; begin end; procedure Tfrm_rp_op_profit.UpdateBsProfit(bstype,bsno:String;fee:integer); begin end; procedure Tfrm_rp_op_profit.UpdateBsProfitLc(bstype,bsno,LcYYMM:String); begin end; procedure Tfrm_rp_op_profit.bsSkinButton9Click(Sender: TObject); begin sys_print('考核操作',2,nil,nil,nil,nil,nil,nil,nil,kbmtc1,kbmqc1,nil,nil); end; procedure Tfrm_rp_op_profit.MenuItem7Click(Sender: TObject); begin grid_save_xls(dxdbgrid6); end; procedure Tfrm_rp_op_profit.dxDBGrid6DblClick(Sender: TObject); begin fee_view(kbmqc.fieldbyname('编号').asstring); end; procedure Tfrm_rp_op_profit.N1Click(Sender: TObject); begin grid_save_xls(dxdbgrid8); end; end.