unit u_seai_sf_xsf; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, dxExEdtr, dxDBGrid, dxDBTLCl, dxGrClms, dxTL, dxDBCtrl, dxCntner, DB, ADODB, StdCtrls, Mask, bsSkinBoxCtrls, bsSkinCtrls, kbmMemTable,DateUtils, RxLookup; type Tfrm_seai_sf_xsf = class(TForm) t_op_ctn: TADOQuery; t_op_ctn1: TDataSource; dxDBGrid1: TdxDBGrid; dxDBGrid1Column1: TdxDBGridMaskColumn; dxDBGrid1Column2: TdxDBGridColumn; dxDBGrid1Column3: TdxDBGridColumn; bsSkinPanel1: TbsSkinPanel; bsSkinButton1: TbsSkinButton; kmltbl: TkbmMemTable; kmltblField: TStringField; kmltblField2: TStringField; kmltblField3: TStringField; kmltblField4: TIntegerField; kmltblField5: TFloatField; dxDBGrid1Column4: TdxDBGridColumn; dxDBGrid1Column5: TdxDBGridColumn; dxDBGrid1Column6: TdxDBGridColumn; kmltblField7: TStringField; dxDBGrid1Column7: TdxDBGridColumn; kmltblField8: TIntegerField; dxDBGrid1Column8: TdxDBGridColumn; bsSkinButton2: TbsSkinButton; Label131: TLabel; Edit2: TEdit; Label213: TLabel; RxDBLookupCombo57: TRxDBLookupCombo; Label12: TLabel; RxDBLookupCombo1: TRxDBLookupCombo; dxDBGrid1Column10: TdxDBGridColumn; dxDBGrid1Column11: TdxDBGridColumn; kmltblField10: TIntegerField; kmltblField6: TStringField; kmltblField9: TStringField; procedure FormShow(Sender: TObject); procedure bsSkinButton1Click(Sender: TObject); procedure bsSkinButton2Click(Sender: TObject); private { Private declarations } public { Public declarations } function GetCQFEE(bsNo,Carrer:string;CQDay,Days,FreeDays:Integer):Double; end; var frm_seai_sf_xsf: Tfrm_seai_sf_xsf; implementation uses my_sys_function; {$R *.dfm} function Tfrm_seai_sf_xsf.GetCQFEE(bsNo,Carrer:string;CQDay,Days,FreeDays:Integer):Double; var aAdoQuery,bAdoQuery:TAdoQuery; begin result:=0; aAdoQuery:=CreateAdoQuery; bAdoQuery:=CreateAdoQuery; with bAdoQuery do begin Close;SQL.Clear; SQL.Add('select *'); SQL.Add('from t_ctn_cqfee'); SQL.Add('where 客户简称=:客户简称 and 表现形式=:表现形式'); end; with aAdoQuery do try Close;SQL.Clear; SQL.Add('select *'); SQL.Add('from t_op_ctn'); SQL.Add('where 编号=:编号'); Parameters.ParamByName('编号').Value:=bsNo; Open;First; while not Eof do begin bAdoQuery.Close; bAdoQuery.Parameters.ParamByName('客户简称').Value:=Carrer; bAdoQuery.Parameters.ParamByName('表现形式').Value:=FieldByName('表现形式').Value; bAdoQuery.Open; if bAdoQuery.FieldByName('免箱使期').asFloat=0 then begin if CQDay<=bAdoQuery.FieldByName('区间1').AsInteger then begin result:=result+CQDay*bAdoQuery.FieldByName('箱使费1').asFloat; end else if (CQDay>bAdoQuery.FieldByName('区间1').AsInteger) and (CQDay<=bAdoQuery.FieldByName('区间2').AsInteger) then begin result:=result+CQDay*bAdoQuery.FieldByName('箱使费2').asFloat; end else if (CQDay>bAdoQuery.FieldByName('区间2').AsInteger) and (CQDay<=bAdoQuery.FieldByName('区间3').AsInteger) then begin result:=result+CQDay*bAdoQuery.FieldByName('箱使费3').asFloat; end else if (CQDay>bAdoQuery.FieldByName('区间3').AsInteger) and (CQDay<=bAdoQuery.FieldByName('区间4').AsInteger) then begin result:=result+CQDay*bAdoQuery.FieldByName('箱使费4').asFloat; end else if (CQDay>bAdoQuery.FieldByName('区间4').AsInteger) and (CQDay<=bAdoQuery.FieldByName('区间5').AsInteger) then begin result:=result+CQDay*bAdoQuery.FieldByName('箱使费5').asFloat; end else if CQDay>bAdoQuery.FieldByName('区间5').AsInteger then begin result:=result+CQDay*bAdoQuery.FieldByName('箱使费5').asFloat; end; end else //区间计算 begin if (Days>bAdoQuery.FieldByName('区间5').AsInteger) then begin if FreeDaysbAdoQuery.FieldByName('区间4').AsInteger) and (Days<=bAdoQuery.FieldByName('区间5').AsInteger) then begin if (FreeDays>bAdoQuery.FieldByName('区间4').AsInteger) and (FreeDays<=bAdoQuery.FieldByName('区间5').AsInteger) then begin if FreeDaysbAdoQuery.FieldByName('区间3').AsInteger) and (FreeDays<=bAdoQuery.FieldByName('区间4').AsInteger) then begin result:=result+(Days-bAdoQuery.FieldByName('区间4').AsInteger)*bAdoQuery.FieldByName('箱使费5').asFloat; if FreeDaysbAdoQuery.FieldByName('区间2').AsInteger) and (FreeDays<=bAdoQuery.FieldByName('区间3').AsInteger) then begin result:=result+(Days-bAdoQuery.FieldByName('区间4').AsInteger)*bAdoQuery.FieldByName('箱使费5').asFloat; result:=result+(bAdoQuery.FieldByName('区间4').AsInteger-bAdoQuery.FieldByName('区间3').AsInteger)*bAdoQuery.FieldByName('箱使费4').asFloat; if FreeDaysbAdoQuery.FieldByName('区间1').AsInteger) and (FreeDays<=bAdoQuery.FieldByName('区间2').AsInteger) then begin result:=result+(Days-bAdoQuery.FieldByName('区间4').AsInteger)*bAdoQuery.FieldByName('箱使费5').asFloat; result:=result+(bAdoQuery.FieldByName('区间4').AsInteger-bAdoQuery.FieldByName('区间3').AsInteger)*bAdoQuery.FieldByName('箱使费4').asFloat; result:=result+(bAdoQuery.FieldByName('区间3').AsInteger-bAdoQuery.FieldByName('区间2').AsInteger)*bAdoQuery.FieldByName('箱使费3').asFloat; if FreeDaysbAdoQuery.FieldByName('区间3').AsInteger) and (Days<=bAdoQuery.FieldByName('区间4').AsInteger) then begin if (FreeDays>bAdoQuery.FieldByName('区间3').AsInteger) and (FreeDays<=bAdoQuery.FieldByName('区间4').AsInteger) then begin if FreeDaysbAdoQuery.FieldByName('区间2').AsInteger) and (FreeDays<=bAdoQuery.FieldByName('区间3').AsInteger) then begin result:=result+(Days-bAdoQuery.FieldByName('区间3').AsInteger)*bAdoQuery.FieldByName('箱使费4').asFloat; if FreeDaysbAdoQuery.FieldByName('区间1').AsInteger) and (FreeDays<=bAdoQuery.FieldByName('区间2').AsInteger) then begin result:=result+(Days-bAdoQuery.FieldByName('区间3').AsInteger)*bAdoQuery.FieldByName('箱使费4').asFloat; result:=result+(bAdoQuery.FieldByName('区间3').AsInteger-bAdoQuery.FieldByName('区间2').AsInteger)*bAdoQuery.FieldByName('箱使费3').asFloat; if FreeDaysbAdoQuery.FieldByName('区间2').AsInteger) and (Days<=bAdoQuery.FieldByName('区间3').AsInteger) then begin if (FreeDays>bAdoQuery.FieldByName('区间2').AsInteger) and (FreeDays<=bAdoQuery.FieldByName('区间3').AsInteger) then begin if FreeDaysbAdoQuery.FieldByName('区间1').AsInteger) and (FreeDays<=bAdoQuery.FieldByName('区间2').AsInteger) then begin result:=result+(Days-bAdoQuery.FieldByName('区间2').AsInteger)*bAdoQuery.FieldByName('箱使费3').asFloat; if FreeDaysbAdoQuery.FieldByName('区间1').AsInteger) and (Days<=bAdoQuery.FieldByName('区间2').AsInteger) then begin if FreeDays=t_op_seai.免费箱使天数 and t_op_seai.放货日期 is null'); if Trim(RxDBLookupCombo57.DisplayValues[1])<>'' then begin SQL.Add('and t_op_seai.委托单位=:委托单位'); Parameters.ParamByName('委托单位').Value:=Trim(RxDBLookupCombo57.DisplayValues[1]); end; if Trim(RxDBLookupCombo1.DisplayValues[1])<>'' then begin SQL.Add('and t_op_seai.船公司=:船公司'); Parameters.ParamByName('船公司').Value:=Trim(RxDBLookupCombo1.DisplayValues[1]); end; if Trim(Edit2.Text)<>'' then begin SQL.Add('and t_op_seai.主提单号 like '+''''+'%'+Edit2.text+'%'+''''); end; Open;First; while not Eof do begin kmltbl.Insert; kmltbl.FieldByName('委托单位').Value:=FieldByName('委托单位').Value; kmltbl.FieldByName('主提单号').Value:=FieldByName('主提单号').Value; kmltbl.FieldByName('操作员').Value:=FieldByName('操作员').Value; kmltbl.FieldByName('船公司').Value:=FieldByName('船公司').Value; kmltbl.FieldByName('进口日期').Value:=FormatDateTime('YYYY-MM-DD',FieldByName('进厂日期').Value); kmltbl.FieldByName('返箱日期').Value:=FieldByName('放货日期').Value; kmltbl.FieldByName('免费箱使天数').Value:=FieldByName('免费箱使天数').Value; if FieldByName('放货日期').IsNull then begin kmltbl.FieldByName('超期天数').Value:=daysBetween(Date,FieldByName('进厂日期').Value)-FieldByName('免费箱使天数').AsInteger; days:=daysBetween(Date,FieldByName('进厂日期').Value); end else begin kmltbl.FieldByName('超期天数').Value:=daysBetween(FieldByName('放货日期').AsDateTime,FieldByName('进厂日期').Value)-FieldByName('免费箱使天数').AsInteger; days:=daysBetween(FieldByName('放货日期').AsDateTime,FieldByName('进厂日期').Value); end; if days>FieldByName('免费箱使天数').AsInteger then kmltbl.FieldByName('超期金额').Value:=GetCQFEE(FieldByName('编号').AsString,FieldByName('船公司').AsString,kmltbl.FieldByName('超期天数').AsInteger,days,FieldByName('免费箱使天数').Asinteger) else kmltbl.FieldByName('超期金额').Value:=0; kmltbl.FieldByName('实际使箱天数').Value:=days; kmltbl.Post; Next; end; end; end; procedure Tfrm_seai_sf_xsf.bsSkinButton2Click(Sender: TObject); var days:integer; begin kmltbl.EmptyTable; kmltbl.Open; with t_op_ctn do begin Close;SQL.Clear; SQL.Add('select t_op_seai.编号,t_op_seai.委托单位,t_op_seai.主提单号,t_op_seai.操作员,t_op_seai.船公司,t_op_seai.免费箱使天数,t_op_seai.进厂日期,t_op_seai.进口日期,t_op_seai.放货日期'); SQL.Add('from t_op_seai'); SQL.Add('where t_op_seai.装运方式=''三废'' and not 进厂日期 is null '); Open;First; while not Eof do begin kmltbl.Insert; kmltbl.FieldByName('委托单位').Value:=FieldByName('委托单位').AsString; kmltbl.FieldByName('主提单号').Value:=FieldByName('主提单号').AsString; kmltbl.FieldByName('操作员').Value:=FieldByName('操作员').AsString; kmltbl.FieldByName('船公司').Value:=FieldByName('船公司').AsString; kmltbl.FieldByName('进口日期').Value:=FormatDateTime('YYYY-MM-DD',FieldByName('进厂日期').Value); kmltbl.FieldByName('免费箱使天数').Value:=FieldByName('免费箱使天数').Value; if FieldByName('放货日期').IsNull then begin kmltbl.FieldByName('超期天数').AsInteger:=daysBetween(Date,FieldByName('进厂日期').Value)-FieldByName('免费箱使天数').AsInteger; days:=daysBetween(Date,FieldByName('进口日期').Value); end else begin kmltbl.FieldByName('超期天数').AsInteger:=daysBetween(FieldByName('放货日期').AsDateTime,FieldByName('进厂日期').Value)-FieldByName('免费箱使天数').AsInteger; days:=daysBetween(Date,FieldByName('放货日期').Value); end; if days>FieldByName('免费箱使天数').AsInteger then kmltbl.FieldByName('超期金额').value:=GetCQFEE(FieldByName('编号').AsString,FieldByName('船公司').AsString,kmltbl.FieldByName('超期天数').AsInteger,days,FieldByName('免费箱使天数').Asinteger) else kmltbl.FieldByName('超期金额').AsInteger:=0; kmltbl.FieldByName('实际使箱天数').AsInteger:=days; kmltbl.Post; Next; end; end; end; end.