You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1171 lines
43 KiB
Plaintext
1171 lines
43 KiB
Plaintext
unit u_rp_sales_profit_tc;
|
|
|
|
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;
|
|
|
|
type
|
|
TSalesTc = Record
|
|
bsNo //编号
|
|
,shippers //委托单位
|
|
,sales //揽货人
|
|
,mblno //主提单号
|
|
,bstype //业务种类
|
|
,FeeStaus //费用状态
|
|
,EtdYearMonth //开船月
|
|
,CorpStlType //客户结费类型
|
|
:string;
|
|
Etd //开船日期
|
|
,StlDate:TDateTime; //结算日期
|
|
AmtRmb //RMB合计
|
|
,AmtUsd // USD合计
|
|
,ProfitAmt
|
|
,TtlProfitAmt
|
|
:Double; //毛利润
|
|
ACTCQDays, //实际超期天数
|
|
CQDays, //超期天数
|
|
xyDays //超期天数
|
|
:integer;
|
|
end;
|
|
|
|
|
|
|
|
Tfrm_rp_sales_profit_tc = class(TForm)
|
|
Panel1: TPanel;
|
|
bsSkinPanel2: TbsSkinPanel;
|
|
kbmBinaryStreamFormat1: TkbmBinaryStreamFormat;
|
|
kbmThreadDataSet1: TkbmThreadDataSet;
|
|
bsSkinPageControl1: TbsSkinPageControl;
|
|
DateTimePicker1: TDateTimePicker;
|
|
Label1: TLabel;
|
|
bsSkinTabSheet2: TbsSkinTabSheet;
|
|
dxDBGrid2: TdxDBGrid;
|
|
dxDBGrid2Column1: TdxDBGridColumn;
|
|
memtblItems: TkbmMemTable;
|
|
memtblItemsField: TStringField;
|
|
memtblItemsField2: TStringField;
|
|
memtblItemsField3: TStringField;
|
|
memtblItems1: TDataSource;
|
|
dxDBGrid2Column2: TdxDBGridColumn;
|
|
dxDBGrid2Column3: TdxDBGridColumn;
|
|
memtblItemsField5: TStringField;
|
|
memtblItemsField4: TFloatField;
|
|
memtblItemsField6: TIntegerField;
|
|
memtblItemsField7: TIntegerField;
|
|
dxDBGrid2Column4: TdxDBGridColumn;
|
|
dxDBGrid2Column5: TdxDBGridColumn;
|
|
dxDBGrid2Column6: TdxDBGridColumn;
|
|
dxDBGrid2Column7: TdxDBGridColumn;
|
|
memtblItemsField8: TStringField;
|
|
bsSkinLabel1: TbsSkinLabel;
|
|
bsSkinEdit1: TbsSkinEdit;
|
|
bsSkinLabel2: TbsSkinLabel;
|
|
bsSkinEdit2: TbsSkinEdit;
|
|
memtblItemsField9: TIntegerField;
|
|
dxDBGrid2Column8: TdxDBGridColumn;
|
|
memtblItemsField10: TStringField;
|
|
dxDBGrid2Column9: TdxDBGridColumn;
|
|
dxDBGrid2Column10: TdxDBGridColumn;
|
|
memtblItemsField11: TStringField;
|
|
memtblItemsField12: TFloatField;
|
|
memtblItemsField13: TFloatField;
|
|
dxDBGrid2Column11: TdxDBGridColumn;
|
|
dxDBGrid2Column12: TdxDBGridColumn;
|
|
memtblItemsRMB: TFloatField;
|
|
memtblItemsUSD: TFloatField;
|
|
dxDBGrid2Column13: TdxDBGridColumn;
|
|
dxDBGrid2Column14: TdxDBGridColumn;
|
|
Label2: TLabel;
|
|
DBComboBoxEh1: TDBComboBoxEh;
|
|
memtblItemsField14: TFloatField;
|
|
dxDBGrid2Column15: TdxDBGridColumn;
|
|
bsSkinPanel1: TbsSkinPanel;
|
|
bsSkinButton10: TbsSkinButton;
|
|
bsSkinButton1: TbsSkinButton;
|
|
bsSkinButton2: TbsSkinButton;
|
|
bsSkinButton5: TbsSkinButton;
|
|
memtblItemsField15: TStringField;
|
|
dxDBGrid2Column16: TdxDBGridColumn;
|
|
memtblItemsField16: TStringField;
|
|
dxDBGrid2Column17: TdxDBGridColumn;
|
|
memtblItemsOrdno: TIntegerField;
|
|
dxDBGrid2Column18: TdxDBGridColumn;
|
|
memtblItemsField17: TStringField;
|
|
dxDBGrid2Column19: TdxDBGridColumn;
|
|
bsSkinCheckRadioBox1: TbsSkinCheckRadioBox;
|
|
bsSkinTabSheet3: TbsSkinTabSheet;
|
|
bsSkinTabSheet4: TbsSkinTabSheet;
|
|
bsSkinTabSheet5: TbsSkinTabSheet;
|
|
memtblItems31: TDataSource;
|
|
memtblItems3: TkbmMemTable;
|
|
StringField1: TStringField;
|
|
StringField2: TStringField;
|
|
StringField3: TStringField;
|
|
StringField4: TStringField;
|
|
FloatField1: TFloatField;
|
|
IntegerField1: TIntegerField;
|
|
IntegerField2: TIntegerField;
|
|
StringField5: TStringField;
|
|
IntegerField3: TIntegerField;
|
|
StringField6: TStringField;
|
|
StringField7: TStringField;
|
|
FloatField2: TFloatField;
|
|
FloatField3: TFloatField;
|
|
FloatField4: TFloatField;
|
|
FloatField5: TFloatField;
|
|
FloatField6: TFloatField;
|
|
StringField8: TStringField;
|
|
StringField9: TStringField;
|
|
IntegerField4: TIntegerField;
|
|
StringField10: TStringField;
|
|
memtblItems2: TkbmMemTable;
|
|
StringField11: TStringField;
|
|
StringField12: TStringField;
|
|
StringField13: TStringField;
|
|
StringField14: TStringField;
|
|
FloatField7: TFloatField;
|
|
IntegerField5: TIntegerField;
|
|
IntegerField6: TIntegerField;
|
|
StringField15: TStringField;
|
|
IntegerField7: TIntegerField;
|
|
StringField16: TStringField;
|
|
StringField17: TStringField;
|
|
FloatField8: TFloatField;
|
|
FloatField9: TFloatField;
|
|
FloatField10: TFloatField;
|
|
FloatField11: TFloatField;
|
|
FloatField12: TFloatField;
|
|
StringField18: TStringField;
|
|
StringField19: TStringField;
|
|
IntegerField8: TIntegerField;
|
|
StringField20: TStringField;
|
|
memtblItems21: TDataSource;
|
|
memtblItems111: TDataSource;
|
|
memtblItems11: TkbmMemTable;
|
|
StringField21: TStringField;
|
|
StringField22: TStringField;
|
|
StringField23: TStringField;
|
|
StringField24: TStringField;
|
|
FloatField13: TFloatField;
|
|
IntegerField9: TIntegerField;
|
|
IntegerField10: TIntegerField;
|
|
StringField25: TStringField;
|
|
IntegerField11: TIntegerField;
|
|
StringField26: TStringField;
|
|
StringField27: TStringField;
|
|
FloatField14: TFloatField;
|
|
FloatField15: TFloatField;
|
|
FloatField16: TFloatField;
|
|
FloatField17: TFloatField;
|
|
FloatField18: TFloatField;
|
|
StringField28: TStringField;
|
|
StringField29: TStringField;
|
|
IntegerField12: TIntegerField;
|
|
StringField30: TStringField;
|
|
dxDBGrid1: TdxDBGrid;
|
|
dxDBGridColumn1: TdxDBGridColumn;
|
|
dxDBGridColumn2: TdxDBGridColumn;
|
|
dxDBGridColumn3: TdxDBGridColumn;
|
|
dxDBGridColumn4: TdxDBGridColumn;
|
|
dxDBGridColumn5: TdxDBGridColumn;
|
|
dxDBGridColumn6: TdxDBGridColumn;
|
|
dxDBGridColumn7: TdxDBGridColumn;
|
|
dxDBGridColumn8: TdxDBGridColumn;
|
|
dxDBGridColumn9: TdxDBGridColumn;
|
|
dxDBGridColumn10: TdxDBGridColumn;
|
|
dxDBGridColumn11: TdxDBGridColumn;
|
|
dxDBGridColumn12: TdxDBGridColumn;
|
|
dxDBGridColumn13: TdxDBGridColumn;
|
|
dxDBGridColumn14: TdxDBGridColumn;
|
|
dxDBGridColumn15: TdxDBGridColumn;
|
|
dxDBGridColumn16: TdxDBGridColumn;
|
|
dxDBGridColumn17: TdxDBGridColumn;
|
|
dxDBGridColumn18: TdxDBGridColumn;
|
|
dxDBGridColumn19: TdxDBGridColumn;
|
|
dxDBGrid3: TdxDBGrid;
|
|
dxDBGridColumn20: TdxDBGridColumn;
|
|
dxDBGridColumn21: TdxDBGridColumn;
|
|
dxDBGridColumn22: TdxDBGridColumn;
|
|
dxDBGridColumn23: TdxDBGridColumn;
|
|
dxDBGridColumn24: TdxDBGridColumn;
|
|
dxDBGridColumn25: TdxDBGridColumn;
|
|
dxDBGridColumn26: TdxDBGridColumn;
|
|
dxDBGridColumn27: TdxDBGridColumn;
|
|
dxDBGridColumn28: TdxDBGridColumn;
|
|
dxDBGridColumn29: TdxDBGridColumn;
|
|
dxDBGridColumn30: TdxDBGridColumn;
|
|
dxDBGridColumn31: TdxDBGridColumn;
|
|
dxDBGridColumn32: TdxDBGridColumn;
|
|
dxDBGridColumn33: TdxDBGridColumn;
|
|
dxDBGridColumn34: TdxDBGridColumn;
|
|
dxDBGridColumn35: TdxDBGridColumn;
|
|
dxDBGridColumn36: TdxDBGridColumn;
|
|
dxDBGridColumn37: TdxDBGridColumn;
|
|
dxDBGridColumn38: TdxDBGridColumn;
|
|
dxDBGrid4: TdxDBGrid;
|
|
dxDBGridColumn39: TdxDBGridColumn;
|
|
dxDBGridColumn40: TdxDBGridColumn;
|
|
dxDBGridColumn41: TdxDBGridColumn;
|
|
dxDBGridColumn42: TdxDBGridColumn;
|
|
dxDBGridColumn43: TdxDBGridColumn;
|
|
dxDBGridColumn44: TdxDBGridColumn;
|
|
dxDBGridColumn45: TdxDBGridColumn;
|
|
dxDBGridColumn46: TdxDBGridColumn;
|
|
dxDBGridColumn47: TdxDBGridColumn;
|
|
dxDBGridColumn48: TdxDBGridColumn;
|
|
dxDBGridColumn49: TdxDBGridColumn;
|
|
dxDBGridColumn50: TdxDBGridColumn;
|
|
dxDBGridColumn51: TdxDBGridColumn;
|
|
dxDBGridColumn52: TdxDBGridColumn;
|
|
dxDBGridColumn53: TdxDBGridColumn;
|
|
dxDBGridColumn54: TdxDBGridColumn;
|
|
dxDBGridColumn55: TdxDBGridColumn;
|
|
dxDBGridColumn56: TdxDBGridColumn;
|
|
dxDBGridColumn57: TdxDBGridColumn;
|
|
memtblItemsField18: TStringField;
|
|
memtblItems2Field: TStringField;
|
|
memtblItems3Field: TStringField;
|
|
dxDBGrid2Column20: TdxDBGridColumn;
|
|
PopupMenu2: TPopupMenu;
|
|
N14: TMenuItem;
|
|
memtblItems11Field: TStringField;
|
|
bsSkinTabSheet6: TbsSkinTabSheet;
|
|
dxDBGrid5: TdxDBGrid;
|
|
dxDBGridColumn58: TdxDBGridColumn;
|
|
dxDBGridColumn59: TdxDBGridColumn;
|
|
dxDBGridColumn60: TdxDBGridColumn;
|
|
dxDBGridColumn61: TdxDBGridColumn;
|
|
dxDBGridColumn62: TdxDBGridColumn;
|
|
dxDBGridColumn63: TdxDBGridColumn;
|
|
dxDBGridColumn64: TdxDBGridColumn;
|
|
dxDBGridColumn65: TdxDBGridColumn;
|
|
dxDBGridColumn66: TdxDBGridColumn;
|
|
dxDBGridColumn67: TdxDBGridColumn;
|
|
dxDBGridColumn68: TdxDBGridColumn;
|
|
dxDBGridColumn69: TdxDBGridColumn;
|
|
dxDBGridColumn70: TdxDBGridColumn;
|
|
dxDBGridColumn71: TdxDBGridColumn;
|
|
dxDBGridColumn72: TdxDBGridColumn;
|
|
dxDBGridColumn73: TdxDBGridColumn;
|
|
dxDBGridColumn74: TdxDBGridColumn;
|
|
dxDBGridColumn75: TdxDBGridColumn;
|
|
dxDBGridColumn76: TdxDBGridColumn;
|
|
dxDBGridColumn77: TdxDBGridColumn;
|
|
memtblDetailTC: TkbmMemTable;
|
|
StringField31: TStringField;
|
|
StringField32: TStringField;
|
|
StringField33: TStringField;
|
|
StringField34: TStringField;
|
|
FloatField19: TFloatField;
|
|
IntegerField13: TIntegerField;
|
|
IntegerField14: TIntegerField;
|
|
StringField35: TStringField;
|
|
IntegerField15: TIntegerField;
|
|
StringField36: TStringField;
|
|
StringField37: TStringField;
|
|
FloatField20: TFloatField;
|
|
FloatField21: TFloatField;
|
|
FloatField22: TFloatField;
|
|
FloatField23: TFloatField;
|
|
FloatField24: TFloatField;
|
|
StringField38: TStringField;
|
|
StringField39: TStringField;
|
|
IntegerField16: TIntegerField;
|
|
StringField40: TStringField;
|
|
StringField41: TStringField;
|
|
memtblDetailTC1: TDataSource;
|
|
memtblDetailTCFloatField: TFloatField;
|
|
dxDBGrid5Column21: TdxDBGridColumn;
|
|
bsSkinTabSheet7: TbsSkinTabSheet;
|
|
dxDBGrid6: TdxDBGrid;
|
|
dxDBGridColumn78: TdxDBGridColumn;
|
|
dxDBGridColumn94: TdxDBGridColumn;
|
|
kbmMemTableCLF: TkbmMemTable;
|
|
kbmMemTableCLF1: TDataSource;
|
|
bsSkinButton4: TbsSkinButton;
|
|
kbmMemTableCLFField: TStringField;
|
|
kbmMemTableCLFField2: TFloatField;
|
|
procedure bsSkinButton5Click(Sender: TObject);
|
|
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
|
procedure bsSkinButton10Click(Sender: TObject);
|
|
procedure FormShow(Sender: TObject);
|
|
procedure bsSkinButton1Click(Sender: TObject);
|
|
procedure DBComboBoxEh1DropDown(Sender: TObject);
|
|
procedure bsSkinPanel1Resize(Sender: TObject);
|
|
procedure N14Click(Sender: TObject);
|
|
procedure bsSkinButton4Click(Sender: TObject);
|
|
private
|
|
NextDateBegin,NextDateEnd
|
|
,CurDateBegin,CurDateEnd
|
|
,LastDateOneBegin,LastDateOneEnd
|
|
,LastDateTwoBegin,LastDateTwoEnd:TDateTime;
|
|
procedure Creatememtbl;
|
|
function getleftstr(substr:String;leng:integer;left:boolean=true):String;
|
|
function CalcProftAmt(cqMonth:string;ProftAmt:Double;Employee:string;var planbegin,planend:Double):Double;
|
|
procedure GetBsDate(curDate:TDate);
|
|
procedure GetFeeItems(aMemtblItems:TKbmmemTable);
|
|
function GetProftAmt(Employee:string;AEtd:TDateTime):Double;
|
|
|
|
|
|
{ Private declarations }
|
|
public
|
|
{ Public declarations }
|
|
ordno_tc:Integer;
|
|
procedure IsertFeeItems(aMemtblItems:TKbmmemTable;SalesTc:TSalesTc);
|
|
|
|
end;
|
|
|
|
var
|
|
frm_rp_sales_profit_tc: Tfrm_rp_sales_profit_tc;
|
|
FmDate,ToDate:String;
|
|
sqlstr:WideString;
|
|
|
|
implementation
|
|
|
|
uses u_main, my_sys_function,u_sys_progress;
|
|
|
|
{$R *.dfm}
|
|
|
|
function Tfrm_rp_sales_profit_tc.GetProftAmt(Employee:string;AEtd:TDateTime):Double;
|
|
var aDate:String;
|
|
aDateTime,aCurDateBegin,aCurDateEnd:TDateTime;
|
|
y,m,d,hh,mm,ss,Endhh,Endmm,Endss,mmmm:Word;
|
|
aAdoQuery:TAdoQuery;
|
|
begin
|
|
Result:=0;
|
|
aDate:=FormatDateTime('YYYY-MM-DD',AEtd);
|
|
aDateTime:=StrToDateTime(aDate);
|
|
if DateTimePicker1.Date=null then
|
|
begin
|
|
MessageDlg('开船日期不能为空!',mtWarning,[mbOk],0);
|
|
exit;
|
|
end;
|
|
y:=0;
|
|
m:=0;
|
|
d:=0;
|
|
hh:=0;
|
|
mm:=0;
|
|
ss:=0;
|
|
Endhh:=23;
|
|
Endmm:=59;
|
|
Endss:=00;
|
|
mmmm:=0;
|
|
decodedate(incMonth(aDateTime,-1),y,m,d);
|
|
aCurDateBegin:=encodedatetime(y,m,26,hh,mm,ss,mmmm);
|
|
decodedate(aDateTime,y,m,d);
|
|
aCurDateEnd:=encodedatetime(y,m,25,Endhh,Endmm,Endss,mmmm);
|
|
|
|
aAdoQuery:=CreateAdoQuery;
|
|
with aAdoQuery do //一月利润
|
|
try
|
|
Close;SQL.Clear;
|
|
SQL.Add('Select 揽货人,sum(毛利润) 毛利润 From v_op_bscard');
|
|
SQL.Add('Where 开船日期 between :BeginDate and :EndDate');
|
|
SQL.Add('and 揽货人=:揽货人');
|
|
Parameters.ParamByName('揽货人').Value:=Employee;
|
|
Parameters.ParamByName('BeginDate').Value:=CurDateBegin;
|
|
Parameters.ParamByName('EndDate').Value:=CurDateEnd;
|
|
SQL.Add('Group by 揽货人');
|
|
SQL.Add('Order by 揽货人');
|
|
Open;First;
|
|
Result:=FieldByName('毛利润').AsFloat;
|
|
finally
|
|
Free;
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
procedure Tfrm_rp_sales_profit_tc.bsSkinButton5Click(Sender: TObject);
|
|
begin
|
|
close;
|
|
end;
|
|
|
|
procedure Tfrm_rp_sales_profit_tc.FormClose(Sender: TObject;
|
|
var Action: TCloseAction);
|
|
begin
|
|
savereggrid(dxdbgrid2,caption+'2');
|
|
frm_rp_sales_profit_tc.Hide;
|
|
frm_rp_sales_profit_tc.ManualFloat(frm_rp_sales_profit_tc.BoundsRect );
|
|
frm_main.freeTabs('frm_rp_sales_profit_tc');
|
|
action:=cafree;
|
|
frm_rp_sales_profit_tc:=nil;
|
|
end;
|
|
|
|
procedure Tfrm_rp_sales_profit_tc.GetBsDate(curDate:TDate);
|
|
var aDate,s:String;
|
|
aDateTime:TDateTime;
|
|
y,m,d,hh,mm,ss,Endhh,Endmm,Endss,mmmm:Word;
|
|
|
|
begin
|
|
aDate:=FormatDateTime('YYYY-MM-DD',curDate);
|
|
aDateTime:=StrToDateTime(aDate);
|
|
if DateTimePicker1.Date=null then
|
|
begin
|
|
MessageDlg('统计月不能为空!',mtWarning,[mbOk],0);
|
|
exit;
|
|
end;
|
|
|
|
|
|
y:=0;
|
|
m:=0;
|
|
d:=0;
|
|
hh:=0;
|
|
mm:=0;
|
|
ss:=0;
|
|
Endhh:=23;
|
|
Endmm:=59;
|
|
Endss:=00;
|
|
mmmm:=0;
|
|
if bsSkinCheckRadioBox1.Checked then
|
|
begin
|
|
decodedate(incMonth(aDateTime,1),y,m,d);
|
|
NextDateBegin:=encodedatetime(y,m,1,hh,mm,ss,mmmm);
|
|
NextDateEnd:=encodedatetime(y,m,DaysInAMonth(y,m),hh,mm,ss,mmmm);
|
|
|
|
decodedate(aDateTime,y,m,d);
|
|
CurDateBegin:=encodedatetime(y,m,1,hh,mm,ss,mmmm);
|
|
CurDateEnd:=encodedatetime(y,m,DaysInAMonth(y,m),Endhh,Endmm,Endss,mmmm);
|
|
|
|
decodedate(incMonth(aDateTime,-1),y,m,d);
|
|
LastDateOneBegin:=encodedatetime(y,m,1,hh,mm,ss,mmmm);
|
|
LastDateOneEnd:=encodedatetime(y,m,DaysInAMonth(y,m),Endhh,Endmm,Endss,mmmm);
|
|
|
|
decodedate(incMonth(aDateTime,-2),y,m,d);
|
|
LastDateTwoBegin:=encodedatetime(y,m,1,hh,mm,ss,mmmm);
|
|
LastDateTwoEnd:=encodedatetime(y,m,DaysInAMonth(y,m),Endhh,Endmm,Endss,mmmm);
|
|
end
|
|
else
|
|
begin
|
|
|
|
decodedate(aDateTime,y,m,d);
|
|
NextDateBegin:=EncodeDate(y,m,26);
|
|
decodedate(incMonth(aDateTime,1),y,m,d);
|
|
NextDateEnd:=EncodeDate(y,m,25);
|
|
|
|
decodedate(incMonth(aDateTime,-1),y,m,d);
|
|
CurDateBegin:=encodedatetime(y,m,26,hh,mm,ss,mmmm);
|
|
decodedate(aDateTime,y,m,d);
|
|
CurDateEnd:=encodedatetime(y,m,25,Endhh,Endmm,Endss,mmmm);
|
|
|
|
decodedate(incMonth(aDateTime,-2),y,m,d);
|
|
LastDateOneBegin:=encodedatetime(y,m,26,hh,mm,ss,mmmm);
|
|
decodedate(incMonth(aDateTime,-1),y,m,d);
|
|
LastDateOneEnd:=encodedatetime(y,m,25,Endhh,Endmm,Endss,mmmm);
|
|
|
|
decodedate(incMonth(aDateTime,-3),y,m,d);
|
|
LastDateTwoBegin:=EncodeDate(y,m,26);
|
|
decodedate(incMonth(aDateTime,-2),y,m,d);
|
|
LastDateTwoEnd:=EncodeDate(y,m,25);
|
|
end;
|
|
s:=datetostr(NextDateBegin)+#13#10+datetostr(NextDateEnd)+#13#10+datetostr(CurDateBegin)+datetostr(CurDateEnd)+#13#10;
|
|
s:=s+datetostr(LastDateOneBegin)+#13#10+datetostr(LastDateOneEnd)+#13#10+datetostr(LastDateTwoBegin)+#13#10+datetostr(LastDateTwoEnd);
|
|
// ShowMessage(s);
|
|
|
|
|
|
end;
|
|
|
|
procedure Tfrm_rp_sales_profit_tc.IsertFeeItems(aMemtblItems:TKbmmemTable;SalesTc:TSalesTc);
|
|
var
|
|
aAdoQuery :TAdoQuery;
|
|
Amt:Double;
|
|
salses:string;
|
|
ordno:Integer;
|
|
lastplanbegin,lastplanend,lasttcxs,lasttc,lastprofit,planbegin,planend:Double;
|
|
|
|
begin
|
|
try
|
|
aMemtblItems.DisableControls;
|
|
Amt:=0;
|
|
// ordno:=1;
|
|
planbegin:=0;
|
|
planend:=0;
|
|
lastplanbegin:=0;
|
|
lastplanend:=0;
|
|
lasttcxs:=0;
|
|
lasttc:=0;
|
|
aMemtblItems.IndexDefs.Clear;
|
|
aMemtblItems.AddIndex('Index1', '揽货人;开船月;结算日期', []);
|
|
aMemtblItems.IndexName := 'Index1';
|
|
ordno_tc:=ordno_tc+1;
|
|
aMemtblItems.Append;
|
|
aMemtblItems.FieldByName('ordno').AsInteger:=ordno_tc;
|
|
aMemtblItems.FieldByName('编号').Value:=SalesTc.bsNo;
|
|
aMemtblItems.FieldByName('委托单位').Value:=SalesTc.shippers;
|
|
|
|
aMemtblItems.FieldByName('揽货人').Value:=SalesTc.sales;
|
|
aMemtblItems.FieldByName('主提单号').Value:=SalesTc.mblno;
|
|
aMemtblItems.FieldByName('业务种类').Value:=SalesTc.bstype;
|
|
aMemtblItems.FieldByName('费用状态').Value:=SalesTc.FeeStaus;
|
|
aMemtblItems.FieldByName('开船日期').Value:=SalesTc.Etd;
|
|
aMemtblItems.FieldByName('结算日期').Value:=FormatDateTime('YYYY-MM-DD hh:mm:sss',SalesTc.StlDate);
|
|
aMemtblItems.FieldByName('RMB合计').Value:=SalesTc.AmtRmb;
|
|
aMemtblItems.FieldByName('USD合计').Value:=SalesTc.AmtUsd;
|
|
aMemtblItems.FieldByName('毛利润').Value:=SalesTc.ProfitAmt;
|
|
aMemtblItems.FieldByName('开船月').AsString:=FormatDateTime('YYYY-MM',SalesTc.Etd);
|
|
aMemtblItems.FieldByName('利润合计').Value:=SalesTc.TtlProfitAmt;
|
|
aMemtblItems.FieldByName('实际超期天数').AsInteger:=0;
|
|
|
|
if SalesTc.CQDays<=0 then
|
|
aMemtblItems.FieldByName('超期天数').AsInteger:=0
|
|
else
|
|
aMemtblItems.FieldByName('超期天数').AsInteger:=SalesTc.CQDays;
|
|
|
|
if (SalesTc.CorpStlType='') or (SalesTc.CorpStlType='现结买单') then
|
|
begin
|
|
if SalesTc.CQDays>=StrToInt(bsSkinEdit1.Text) then
|
|
aMemtblItems.FieldByName('实际超期天数').AsInteger:=SalesTc.CQDays-StrToInt(bsSkinEdit1.Text)
|
|
else aMemtblItems.FieldByName('实际超期天数').AsInteger;
|
|
end
|
|
else
|
|
begin
|
|
if SalesTc.CQDays>=StrToInt(bsSkinEdit2.Text) then
|
|
aMemtblItems.FieldByName('实际超期天数').AsInteger:=SalesTc.CQDays-StrToInt(bsSkinEdit2.Text)
|
|
else aMemtblItems.FieldByName('实际超期天数').AsInteger;
|
|
end;
|
|
|
|
if (aMemtblItems.FieldByName('实际超期天数').AsInteger>=0) and (memtblItems.FieldByName('实际超期天数').AsInteger<=30) then
|
|
begin
|
|
aMemtblItems.FieldByName('超期月').Value:=0;
|
|
aMemtblItems.FieldByName('提成区间').Value:=100;
|
|
end
|
|
else
|
|
if (aMemtblItems.FieldByName('实际超期天数').AsInteger>30) and (memtblItems.FieldByName('实际超期天数').AsInteger<=60) then
|
|
begin
|
|
aMemtblItems.FieldByName('超期月').Value:=1;
|
|
aMemtblItems.FieldByName('提成区间').Value:=80;
|
|
end
|
|
else
|
|
if (aMemtblItems.FieldByName('实际超期天数').AsInteger>60) and (memtblItems.FieldByName('实际超期天数').AsInteger<=90) then
|
|
begin
|
|
aMemtblItems.FieldByName('超期月').Value:=2;
|
|
aMemtblItems.FieldByName('提成区间').Value:=60;
|
|
end
|
|
else
|
|
begin
|
|
aMemtblItems.FieldByName('超期月').Value:='大于3';
|
|
aMemtblItems.FieldByName('提成区间').Value:=0;
|
|
end;
|
|
|
|
aMemtblItems.FieldByName('协议天数').AsInteger:=SalesTc.xyDays;
|
|
lasttcxs:=0;
|
|
|
|
|
|
aMemtblItems.FieldByName('提成比例').Value:=CalcProftAmt(aMemtblItems.FieldByName('超期月').AsString,aMemtblItems.FieldByName('利润合计').AsFloat,SalesTc.sales,planbegin,planend);
|
|
|
|
|
|
if aMemtblItems.FieldByName('提成比例').Value<>0 then
|
|
begin
|
|
if planbegin>(aMemtblItems.FieldByName('利润合计').Value-aMemtblItems.FieldByName('毛利润').Value) then
|
|
begin
|
|
aMemtblItems.FieldByName('提成').Value:=formatFloat('0.00;-0.00;0',aMemtblItems.FieldByName('提成比例').Value*(aMemtblItems.FieldByName('利润合计').Value-planbegin));
|
|
|
|
lastprofit:=aMemtblItems.FieldByName('利润合计').AsFloat-aMemtblItems.FieldByName('毛利润').AsFloat;
|
|
|
|
lasttcxs:=CalcProftAmt(aMemtblItems.FieldByName('超期月').AsString,lastprofit,SalesTc.sales,lastplanbegin,lastplanend);
|
|
if lasttcxs>0 then
|
|
begin
|
|
if (aMemtblItems.FieldByName('毛利润').Value-(aMemtblItems.FieldByName('利润合计').Value-planbegin))>0 then
|
|
lasttc:=lasttcxs*(aMemtblItems.FieldByName('毛利润').Value-(aMemtblItems.FieldByName('利润合计').Value-planbegin));
|
|
end;
|
|
if (lasttcxs>0) and (lasttc>0) then
|
|
begin
|
|
aMemtblItems.FieldByName('提成').Value:=aMemtblItems.FieldByName('提成').Value+strToFloat(formatFloat('0.00;-0.00;0',lasttc));
|
|
aMemtblItems.FieldByName('备注').Value:='系数:'+FloatToStr(lasttcxs)+' 提成:'+formatFloat('0.00;-0.00;0',lasttc);
|
|
end;
|
|
end
|
|
else
|
|
aMemtblItems.FieldByName('提成').Value:=formatFloat('0.00;-0.00;0',aMemtblItems.FieldByName('提成比例').Value*memtblItems.FieldByName('毛利润').Value);
|
|
|
|
end
|
|
else
|
|
begin
|
|
aMemtblItems.FieldByName('提成').Value:=0;
|
|
end;
|
|
aMemtblItems.Post;
|
|
finally
|
|
aMemtblItems.EnableControls;
|
|
aMemtblItems.Refresh;
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Tfrm_rp_sales_profit_tc.bsSkinButton10Click(Sender: TObject);
|
|
var y,m,d:Word;
|
|
ListEmpl,ListEtdYearMonth:TStringlist;
|
|
i,j:Integer;
|
|
Amt:Double;
|
|
SalesTc:TSalesTc;
|
|
begin
|
|
ordno_tc:=0;
|
|
GetBsDate(DateTimePicker1.Date);
|
|
GetFeeItems(memtblItems);
|
|
|
|
|
|
decodedate(incMonth(DateTimePicker1.Date,-1),y,m,d);
|
|
GetBsDate(encodedatetime(y,m,1,0,0,0,0));
|
|
GetFeeItems(memtblItems11);
|
|
|
|
decodedate(incMonth(DateTimePicker1.Date,-2),y,m,d);
|
|
GetBsDate(encodedatetime(y,m,1,0,0,0,0));
|
|
GetFeeItems(memtblItems2);
|
|
|
|
decodedate(incMonth(DateTimePicker1.Date,-3),y,m,d);
|
|
GetBsDate(encodedatetime(y,m,1,0,0,0,0));
|
|
GetFeeItems(memtblItems3);
|
|
|
|
//exit;
|
|
ListEmpl:=TStringlist.Create;
|
|
ListEtdYearMonth:=TStringlist.Create;
|
|
ListEmpl.Clear;
|
|
ListEtdYearMonth.Clear;
|
|
try
|
|
with memtblItems do
|
|
begin
|
|
First;
|
|
while not eof do
|
|
begin
|
|
if ListEmpl.IndexOf(FieldByName('揽货人').AsString)<0 then
|
|
ListEmpl.Add(FieldByName('揽货人').AsString);
|
|
Next;
|
|
end;
|
|
end;
|
|
|
|
memtblDetailTC.Close;
|
|
memtblDetailTC.EmptyTable;
|
|
memtblDetailTC.Open;
|
|
for i:=0 to ListEmpl.count-1 do
|
|
begin
|
|
memtblItems.Filtered:=False;
|
|
memtblItems.Filter:='揽货人='+''''+ListEmpl[i]+'''';
|
|
memtblItems.Filtered:=True;
|
|
ListEtdYearMonth.Clear;
|
|
with memtblItems do
|
|
begin
|
|
First;
|
|
while not eof do
|
|
begin
|
|
if ListEtdYearMonth.IndexOf(FieldByName('开船月').AsString)<0 then
|
|
ListEtdYearMonth.Add(FieldByName('开船月').AsString);
|
|
Next;
|
|
end;
|
|
end;
|
|
|
|
// ShowMessage(ListEtdYearMonth[j]);
|
|
for j:=0 to ListEtdYearMonth.count-1 do
|
|
begin
|
|
Amt:=0;
|
|
memtblItems11.Filtered:=False;
|
|
memtblItems11.Filter:='揽货人='+''''+ListEmpl[i]+'''';
|
|
memtblItems11.Filter:=memtblItems11.Filter+' And 开船月='+''''+ListEtdYearMonth[j]+'''';
|
|
memtblItems11.Filtered:=True;
|
|
with memtblItems11 do
|
|
begin
|
|
First;
|
|
while not eof do
|
|
begin
|
|
Amt:=Amt+s_w(2,FieldByName('毛利润').AsFloat);
|
|
Next;
|
|
end;
|
|
end;
|
|
memtblItems2.Filtered:=False;
|
|
memtblItems2.Filter:='揽货人='+''''+ListEmpl[i]+'''';
|
|
memtblItems2.Filter:=memtblItems2.Filter+' And 开船月='+''''+ListEtdYearMonth[j]+'''';
|
|
memtblItems2.Filtered:=True;
|
|
with memtblItems2 do
|
|
begin
|
|
First;
|
|
while not eof do
|
|
begin
|
|
Amt:=Amt+s_w(2,FieldByName('毛利润').AsFloat);
|
|
Next;
|
|
end;
|
|
end;
|
|
memtblItems3.Filtered:=False;
|
|
memtblItems3.Filter:='揽货人='+''''+ListEmpl[i]+'''';
|
|
memtblItems3.Filter:=memtblItems2.Filter+' And 开船月='+''''+ListEtdYearMonth[j]+'''';
|
|
memtblItems3.Filtered:=True;
|
|
with memtblItems3 do
|
|
begin
|
|
First;
|
|
while not eof do
|
|
begin
|
|
Amt:=Amt+s_w(2,FieldByName('毛利润').AsFloat);
|
|
Next;
|
|
end;
|
|
end;
|
|
memtblItems.Filtered:=False;
|
|
memtblItems.Filter:='揽货人='+''''+ListEmpl[i]+'''';
|
|
memtblItems.Filter:=memtblItems.Filter+' And 开船月='+''''+ListEtdYearMonth[j]+'''';
|
|
memtblItems.Filtered:=True;
|
|
memtblItems.IndexDefs.Clear;
|
|
memtblItems.AddIndex('Index1', '揽货人;开船月;结算日期', []);
|
|
memtblItems.IndexName := 'Index1';
|
|
|
|
|
|
decodedate(incMonth(DateTimePicker1.Date,-1),y,m,d);
|
|
if not kbmMemTableCLF.IsEmpty then
|
|
if FormatDateTime('YYYY-MM',encodedatetime(y,m,1,0,0,0,0))=ListEtdYearMonth[j] then
|
|
begin
|
|
if kbmMemTableCLF.Locate('揽货人',ListEmpl[i],[]) then
|
|
begin
|
|
Amt:=Amt-kbmMemTableCLF.FieldByName('差旅费').AsFloat;
|
|
end;
|
|
end;
|
|
|
|
with memtblItems do
|
|
begin
|
|
First;
|
|
while not eof do
|
|
begin
|
|
Amt:=Amt+s_w(2,FieldByName('毛利润').AsFloat);
|
|
|
|
SalesTc.bsNo:=FieldByName('编号').AsString;
|
|
SalesTc.shippers:=FieldByName('委托单位').AsString;
|
|
|
|
SalesTc.sales:=FieldByName('揽货人').AsString;
|
|
SalesTc.mblno:=FieldByName('主提单号').AsString;
|
|
SalesTc.bstype:=FieldByName('业务种类').AsString;
|
|
SalesTc.FeeStaus:=FieldByName('费用状态').AsString;
|
|
SalesTc.Etd:=FieldByName('开船日期').AsDateTime;
|
|
SalesTc.StlDate:=FieldByName('结算日期').AsDateTime;
|
|
SalesTc.AmtRmb:=FieldByName('RMB合计').AsFloat;
|
|
SalesTc.AmtUsd:=FieldByName('USD合计').AsFloat;
|
|
SalesTc.ProfitAmt:=FieldByName('毛利润').AsFloat;
|
|
SalesTc.EtdYearMonth:=FormatDateTime('YYYY-MM',FieldByName('开船日期').AsDateTime);
|
|
SalesTc.CQDays:=FieldByName('超期天数').AsInteger;
|
|
SalesTc.xyDays:=FieldByName('协议天数').AsInteger;
|
|
SalesTc.TtlProfitAmt:=Amt;
|
|
IsertFeeItems(memtblDetailTC,SalesTc);
|
|
Next;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
finally
|
|
ListEmpl.Free;
|
|
ListEtdYearMonth.Free;
|
|
|
|
memtblItems11.Filtered:=False;
|
|
memtblItems11.Filter:='';
|
|
memtblItems3.Filtered:=False;
|
|
memtblItems3.Filter:='';
|
|
memtblItems2.Filtered:=False;
|
|
memtblItems2.Filter:='';
|
|
memtblItems.Filtered:=False;
|
|
memtblItems.Filter:='';
|
|
|
|
|
|
end;
|
|
end;
|
|
|
|
function Tfrm_rp_sales_profit_tc.CalcProftAmt(cqMonth:string;ProftAmt:Double;Employee:string;var planbegin,planend:Double):Double;
|
|
var aAdoQueryProfitPlan,aAdoQueryProfitPlanItem:TAdoQuery;
|
|
PlanName:string;
|
|
rate1,rate2:Double;
|
|
begin
|
|
if Trim(cqMonth)='0' then
|
|
rate1:=100
|
|
else
|
|
if Trim(cqMonth)='1' then
|
|
rate1:=80
|
|
else
|
|
if Trim(cqMonth)='2' then
|
|
rate1:=60
|
|
else rate1:=0;
|
|
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;
|
|
// ShowMessage(PlanName);
|
|
if PlanName='' then Exit;
|
|
|
|
with aAdoQueryProfitPlanItem do
|
|
try
|
|
Close;SQL.Clear;
|
|
SQL.Add(' select * from t_crm_salesproftSet');
|
|
SQL.Add('where 方案名称=:PlanName');
|
|
Parameters.ParamByName('PlanName').Value:=trim(PlanName);
|
|
Open;First;
|
|
while not eof do
|
|
begin
|
|
if ProftAmt<>0 then
|
|
begin
|
|
if (ProftAmt>FieldByName('利润起').AsFloat) and (ProftAmt<=FieldByName('利润止').AsFloat) then
|
|
begin
|
|
result:=FieldByName('本月结提成比例').AsFloat/100*rate1/100;
|
|
planbegin:=FieldByName('利润起').AsFloat;
|
|
planend:=FieldByName('利润止').AsFloat;
|
|
end
|
|
else
|
|
// result:=0;
|
|
end;
|
|
Next;
|
|
end;
|
|
finally
|
|
Free;
|
|
aAdoQueryProfitPlan.Free;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure Tfrm_rp_sales_profit_tc.GetFeeItems(aMemtblItems:TKbmmemTable);
|
|
var
|
|
aAdoQuery :TAdoQuery;
|
|
Amt:Double;
|
|
salses,field_lirun:string;
|
|
ordno:Integer;
|
|
lastplanbegin,lastplanend,lasttcxs,lasttc,lastprofit,planbegin,planend:Double;
|
|
|
|
begin
|
|
field_lirun:='财务不含税毛利润 毛利润';
|
|
aMemtblItems.Close;
|
|
aMemtblItems.EmptyTable;
|
|
// memtblItems.CreateTable;
|
|
aMemtblItems.Open;
|
|
|
|
if Trim(DBComboBoxEh1.Text)='' then
|
|
begin
|
|
// showmessage('请选择揽货人');
|
|
// exit;
|
|
end;
|
|
|
|
aAdoQuery:=CreateAdoQuery;
|
|
|
|
with aAdoQuery do // 1 1
|
|
try
|
|
Close;SQL.Clear;
|
|
SQL.Add('select v_op_bscard.编号,v_op_bscard.揽货人,convert(varchar(7),v_op_bscard.开船日期,120) 开船月,v_op_bscard.业务种类,v_op_bscard.费用状态,v_op_bscard.主提单号,v_op_bscard.委托单位,v_op_bscard.开船日期,jie.结算日期,v_op_bscard.'+field_lirun+'');
|
|
SQL.Add(',v_op_bscard.应收USD,v_op_bscard.应收RMB,');
|
|
SQL.Add('DATEDIFF([day],v_op_bscard.开船日期,jie.结算日期) AS 实际天数,t_crm_client_sales.结费类型,');
|
|
SQL.Add('isnull(DATEDIFF([day],v_op_bscard.开船日期, jie.结算日期)-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)');
|
|
SQL.Add(' else (case t_crm_client_sales.结费类型 when ''约定时间'' then');
|
|
SQL.Add(' ( DATEDIFF([day],v_op_bscard.开船日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期,DATEADD(Day,-Day(v_op_bscard.开船日期)+1,v_op_bscard.开船日期))))) else 0 end) end)');
|
|
SQL.Add(',DATEDIFF([day],v_op_bscard.开船日期, jie.结算日期)) as 超期天数,');
|
|
SQL.Add('(case t_crm_client_sales.结费类型 ');
|
|
SQL.Add(' when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0) ');
|
|
SQL.Add(' when ''约定时间'' then CAST(t_crm_client_sales.类型模式 AS int)*30+isnull(t_crm_client_sales.结费日期,0) ');
|
|
SQL.Add(' else 0 ');
|
|
SQL.Add(' end) as 协议天数 ');
|
|
SQL.Add('from v_op_bscard ');
|
|
SQL.Add(' left join t_crm_client_sales on v_op_bscard.委托单位=t_crm_client_sales.客户简称 ');
|
|
SQL.Add('left join v_fee_do_max jie on v_op_bscard.编号=jie.编号');
|
|
SQL.Add('where v_op_bscard.合计应收=v_op_bscard.合计已收 and v_op_bscard.合计应收<>0');
|
|
SQL.add(' and jie.结算日期 >='+''''+datetimetostr(CurDateBegin)+'''');
|
|
SQL.add(' and jie.结算日期 <='+''''+datetimetostr(CurDateEnd)+'''');
|
|
SQL.add(' and v_op_bscard.开船日期 <'+''''+datetimetostr(CurDateBegin)+'''');// 不取当月费用
|
|
SQL.add(' and v_op_bscard.开船日期 >''2012-12-26''');// 不取当月费用
|
|
{
|
|
Parameters.ParamByName('StlBeginDate').Value:=CurDateBegin;
|
|
Parameters.ParamByName('StlEndDate').Value:=CurDateEnd;
|
|
}
|
|
SQL.Add(' union ');
|
|
SQL.Add('select v_op_bscard.编号,v_op_bscard.揽货人,convert(varchar(7),v_op_bscard.开船日期,120) 开船月,v_op_bscard.业务种类,v_op_bscard.费用状态,v_op_bscard.主提单号,v_op_bscard.委托单位,v_op_bscard.开船日期,jie.结算日期,v_op_bscard.'+field_lirun+'');
|
|
SQL.Add(',v_op_bscard.应收USD,v_op_bscard.应收RMB,');
|
|
SQL.Add('DATEDIFF([day],v_op_bscard.开船日期,jie.结算日期) AS 实际天数,t_crm_client_sales.结费类型,');
|
|
SQL.Add('isnull(DATEDIFF([day],v_op_bscard.开船日期, jie.结算日期)-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)');
|
|
SQL.Add(' else (case t_crm_client_sales.结费类型 when ''约定时间'' then');
|
|
SQL.Add(' ( DATEDIFF([day],v_op_bscard.开船日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期,DATEADD(Day,-Day(v_op_bscard.开船日期)+1,v_op_bscard.开船日期))))) else 0 end) end)');
|
|
SQL.Add(',DATEDIFF([day],v_op_bscard.开船日期, jie.结算日期)) as 超期天数,');
|
|
SQL.Add('(case t_crm_client_sales.结费类型 ');
|
|
SQL.Add(' when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0) ');
|
|
SQL.Add(' when ''约定时间'' then CAST(t_crm_client_sales.类型模式 AS int)*30+isnull(t_crm_client_sales.结费日期,0) ');
|
|
SQL.Add(' else 0 ');
|
|
SQL.Add(' end) as 协议天数 ');
|
|
SQL.Add('from v_op_bscard ');
|
|
SQL.Add(' left join t_crm_client_sales on v_op_bscard.委托单位=t_crm_client_sales.客户简称 ');
|
|
SQL.Add('left join v_fee_do_max_cr jie on v_op_bscard.编号=jie.编号');
|
|
SQL.Add('where v_op_bscard.合计应付=v_op_bscard.合计已付 and v_op_bscard.合计应收=0'); //取只有付没有收的
|
|
SQL.add(' and jie.结算日期 >='+''''+datetimetostr(CurDateBegin)+'''');
|
|
SQL.add(' and jie.结算日期 <='+''''+datetimetostr(CurDateEnd)+'''');
|
|
SQL.add(' and v_op_bscard.开船日期 <'+''''+datetimetostr(CurDateBegin)+'''');// 不取当月费用
|
|
SQL.add(' and v_op_bscard.开船日期 >''2012-12-26''');// 不取当月费用
|
|
|
|
|
|
|
|
//取上月结算 但是上月没有封帐的业务
|
|
SQL.Add(' union ');
|
|
SQL.Add('select v_op_bscard.编号,v_op_bscard.揽货人,convert(varchar(7),v_op_bscard.开船日期,120) 开船月,v_op_bscard.业务种类,v_op_bscard.费用状态,v_op_bscard.主提单号,v_op_bscard.委托单位,v_op_bscard.开船日期,jie.结算日期,v_op_bscard.'+field_lirun+'');
|
|
SQL.Add(',v_op_bscard.应收USD,v_op_bscard.应收RMB,');
|
|
SQL.Add('DATEDIFF([day],v_op_bscard.开船日期,jie.结算日期) AS 实际天数,t_crm_client_sales.结费类型,');
|
|
SQL.Add('isnull(DATEDIFF([day],v_op_bscard.开船日期, jie.结算日期)-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)');
|
|
SQL.Add(' else (case t_crm_client_sales.结费类型 when ''约定时间'' then');
|
|
SQL.Add(' ( DATEDIFF([day],v_op_bscard.开船日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期,DATEADD(Day,-Day(v_op_bscard.开船日期)+1,v_op_bscard.开船日期))))) else 0 end) end)');
|
|
SQL.Add(',DATEDIFF([day],v_op_bscard.开船日期, jie.结算日期)) as 超期天数,');
|
|
SQL.Add('(case t_crm_client_sales.结费类型 ');
|
|
SQL.Add(' when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0) ');
|
|
SQL.Add(' when ''约定时间'' then CAST(t_crm_client_sales.类型模式 AS int)*30+isnull(t_crm_client_sales.结费日期,0) ');
|
|
SQL.Add(' else 0 ');
|
|
SQL.Add(' end) as 协议天数 ');
|
|
SQL.Add('from v_op_bscard ');
|
|
SQL.Add(' left join t_crm_client_sales on v_op_bscard.委托单位=t_crm_client_sales.客户简称 ');
|
|
SQL.Add('left join v_fee_do_max jie on v_op_bscard.编号=jie.编号');
|
|
SQL.Add('where v_op_bscard.合计应收=v_op_bscard.合计已收 and v_op_bscard.合计应收<>0');
|
|
SQL.add(' and jie.结算日期 >='+''''+datetimetostr(LastDateOneBegin)+'''');
|
|
SQL.add(' and jie.结算日期 <='+''''+datetimetostr(LastDateOneEnd)+'''');
|
|
SQL.add(' and v_op_bscard.开船日期 >='+''''+datetimetostr(LastDateOneBegin)+'''');
|
|
SQL.add(' and v_op_bscard.开船日期 <='+''''+datetimetostr(LastDateOneEnd)+'''');
|
|
SQL.add(' and v_op_bscard.开船日期 >''2012-12-26''');// 不取当月费用
|
|
|
|
SQL.Add(' union ');
|
|
SQL.Add('select v_op_bscard.编号,v_op_bscard.揽货人,convert(varchar(7),v_op_bscard.开船日期,120) 开船月,v_op_bscard.业务种类,v_op_bscard.费用状态,v_op_bscard.主提单号,v_op_bscard.委托单位,v_op_bscard.开船日期,jie.结算日期,v_op_bscard.'+field_lirun+'');
|
|
SQL.Add(',v_op_bscard.应收USD,v_op_bscard.应收RMB,');
|
|
SQL.Add('DATEDIFF([day],v_op_bscard.开船日期,jie.结算日期) AS 实际天数,t_crm_client_sales.结费类型,');
|
|
SQL.Add('isnull(DATEDIFF([day],v_op_bscard.开船日期, jie.结算日期)-(case t_crm_client_sales.结费类型 when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0)');
|
|
SQL.Add(' else (case t_crm_client_sales.结费类型 when ''约定时间'' then');
|
|
SQL.Add(' ( DATEDIFF([day],v_op_bscard.开船日期,DATEADD(month, CAST(t_crm_client_sales.类型模式 AS int), DATEADD(day,t_crm_client_sales.结费日期,DATEADD(Day,-Day(v_op_bscard.开船日期)+1,v_op_bscard.开船日期))))) else 0 end) end)');
|
|
SQL.Add(',DATEDIFF([day],v_op_bscard.开船日期, jie.结算日期)) as 超期天数,');
|
|
SQL.Add('(case t_crm_client_sales.结费类型 ');
|
|
SQL.Add(' when ''约定天数'' then isnull(t_crm_client_sales.结费期限,0) ');
|
|
SQL.Add(' when ''约定时间'' then CAST(t_crm_client_sales.类型模式 AS int)*30+isnull(t_crm_client_sales.结费日期,0) ');
|
|
SQL.Add(' else 0 ');
|
|
SQL.Add(' end) as 协议天数 ');
|
|
SQL.Add('from v_op_bscard ');
|
|
SQL.Add(' left join t_crm_client_sales on v_op_bscard.委托单位=t_crm_client_sales.客户简称 ');
|
|
SQL.Add('left join v_fee_do_max_cr jie on v_op_bscard.编号=jie.编号');
|
|
SQL.Add('where v_op_bscard.合计应付=v_op_bscard.合计已付 and v_op_bscard.合计应收=0'); //取只有付没有收的
|
|
SQL.add(' and jie.结算日期 >='+''''+datetimetostr(LastDateOneBegin)+'''');
|
|
SQL.add(' and jie.结算日期 <='+''''+datetimetostr(LastDateOneEnd)+'''');
|
|
SQL.add(' and v_op_bscard.开船日期 >='+''''+datetimetostr(LastDateOneBegin)+'''');
|
|
SQL.add(' and v_op_bscard.开船日期 <='+''''+datetimetostr(LastDateOneEnd)+'''');
|
|
SQL.add(' and v_op_bscard.开船日期 >''2012-12-26''');// 不取当月费用
|
|
SQL.add('order by v_op_bscard.揽货人,convert(varchar(7),v_op_bscard.开船日期,120),jie.结算日期');
|
|
Open;First;
|
|
salses:='';
|
|
aMemtblItems.EmptyTable;
|
|
aMemtblItems.DisableControls;
|
|
Amt:=0;
|
|
ordno:=1;
|
|
planbegin:=0;
|
|
planend:=0;
|
|
lastplanbegin:=0;
|
|
lastplanend:=0;
|
|
lasttcxs:=0;
|
|
lasttc:=0;
|
|
aMemtblItems.IndexDefs.Clear;
|
|
aMemtblItems.AddIndex('Index1', '揽货人;开船月;结算日期', []);
|
|
aMemtblItems.IndexName := 'Index1';
|
|
|
|
{ aMemtblItems.AddIndex('Indexordno', 'ordno', []);
|
|
aMemtblItems.IndexName := 'Indexordno';
|
|
}
|
|
|
|
salses:=Trim(FieldByName('揽货人').AsString);
|
|
while not Eof do
|
|
begin
|
|
ordno:=ordno+1;
|
|
aMemtblItems.Append;
|
|
aMemtblItems.FieldByName('ordno').AsInteger:=ordno;
|
|
aMemtblItems.FieldByName('编号').Value:=FieldByName('编号').Value;
|
|
aMemtblItems.FieldByName('委托单位').Value:=FieldByName('委托单位').Value;
|
|
aMemtblItems.FieldByName('揽货人').Value:=FieldByName('揽货人').Value;
|
|
aMemtblItems.FieldByName('主提单号').Value:=FieldByName('主提单号').Value;
|
|
aMemtblItems.FieldByName('业务种类').Value:=FieldByName('业务种类').Value;
|
|
aMemtblItems.FieldByName('费用状态').Value:=FieldByName('费用状态').Value;
|
|
aMemtblItems.FieldByName('开船日期').Value:=FieldByName('开船日期').Value;
|
|
aMemtblItems.FieldByName('结算日期').Value:=FormatDateTime('YYYY-MM-DD hh:mm:sss',FieldByName('结算日期').AsDateTime);
|
|
aMemtblItems.FieldByName('RMB合计').Value:=FieldByName('应收RMB').Value;
|
|
aMemtblItems.FieldByName('USD合计').Value:=FieldByName('应收USD').Value;
|
|
aMemtblItems.FieldByName('毛利润').Value:=FieldByName('毛利润').Value;
|
|
|
|
aMemtblItems.FieldByName('开船月').AsString:=FormatDateTime('YYYY-MM',FieldByName('开船日期').Value);
|
|
|
|
|
|
// ShowMessage(salses+' '+Trim(FieldByName('揽货人').AsString));
|
|
if salses=Trim(FieldByName('揽货人').AsString) then
|
|
Amt:=Amt+FieldByName('毛利润').AsFloat
|
|
else Amt:=FieldByName('毛利润').AsFloat;
|
|
|
|
|
|
aMemtblItems.FieldByName('利润合计').Value:=Amt;
|
|
aMemtblItems.FieldByName('实际超期天数').AsInteger:=0;
|
|
|
|
if FieldByName('超期天数').AsInteger<=0 then
|
|
aMemtblItems.FieldByName('超期天数').AsInteger:=0
|
|
else
|
|
aMemtblItems.FieldByName('超期天数').AsInteger:=FieldByName('超期天数').AsInteger;
|
|
|
|
|
|
if (FieldByName('结费类型').AsString='') or (FieldByName('结费类型').AsString='现结买单') then
|
|
begin
|
|
if FieldByName('超期天数').AsInteger>=StrToInt(bsSkinEdit1.Text) then
|
|
aMemtblItems.FieldByName('实际超期天数').AsInteger:=FieldByName('超期天数').AsInteger-StrToInt(bsSkinEdit1.Text)
|
|
else aMemtblItems.FieldByName('实际超期天数').AsInteger;
|
|
end
|
|
else
|
|
begin
|
|
if FieldByName('超期天数').AsInteger>=StrToInt(bsSkinEdit2.Text) then
|
|
aMemtblItems.FieldByName('实际超期天数').AsInteger:=FieldByName('超期天数').AsInteger-StrToInt(bsSkinEdit2.Text)
|
|
else aMemtblItems.FieldByName('实际超期天数').AsInteger;
|
|
end;
|
|
|
|
if (aMemtblItems.FieldByName('实际超期天数').AsInteger>=0) and (memtblItems.FieldByName('实际超期天数').AsInteger<=30) then
|
|
aMemtblItems.FieldByName('超期月').Value:=0
|
|
else
|
|
if (aMemtblItems.FieldByName('实际超期天数').AsInteger>30) and (memtblItems.FieldByName('实际超期天数').AsInteger<=60) then
|
|
aMemtblItems.FieldByName('超期月').Value:=1
|
|
else
|
|
if (aMemtblItems.FieldByName('实际超期天数').AsInteger>60) and (memtblItems.FieldByName('实际超期天数').AsInteger<=90) then
|
|
aMemtblItems.FieldByName('超期月').Value:=2
|
|
else aMemtblItems.FieldByName('超期月').Value:='大于3';
|
|
|
|
aMemtblItems.FieldByName('协议天数').AsInteger:=FieldByName('协议天数').AsInteger;
|
|
lasttcxs:=0;
|
|
|
|
aMemtblItems.FieldByName('提成比例').Value:=CalcProftAmt(aMemtblItems.FieldByName('超期月').AsString,aMemtblItems.FieldByName('利润合计').AsFloat,FieldByName('揽货人').AsString,planbegin,planend);
|
|
|
|
if aMemtblItems.FieldByName('提成比例').Value<>0 then
|
|
begin
|
|
if planbegin>(aMemtblItems.FieldByName('利润合计').Value-aMemtblItems.FieldByName('毛利润').Value) then
|
|
begin
|
|
aMemtblItems.FieldByName('提成').Value:=formatFloat('0.00;-0.00;0',aMemtblItems.FieldByName('提成比例').Value*(aMemtblItems.FieldByName('利润合计').Value-planbegin));
|
|
|
|
lastprofit:=aMemtblItems.FieldByName('利润合计').AsFloat-aMemtblItems.FieldByName('毛利润').AsFloat;
|
|
|
|
lasttcxs:=CalcProftAmt(aMemtblItems.FieldByName('超期月').AsString,lastprofit,FieldByName('揽货人').AsString,lastplanbegin,lastplanend);
|
|
if lasttcxs>0 then
|
|
begin
|
|
if (aMemtblItems.FieldByName('毛利润').Value-(aMemtblItems.FieldByName('利润合计').Value-planbegin))>0 then
|
|
lasttc:=lasttcxs*(aMemtblItems.FieldByName('毛利润').Value-(aMemtblItems.FieldByName('利润合计').Value-planbegin));
|
|
end;
|
|
if (lasttcxs>0) and (lasttc>0) then
|
|
begin
|
|
aMemtblItems.FieldByName('提成').Value:=aMemtblItems.FieldByName('提成').Value+strToFloat(formatFloat('0.00;-0.00;0',lasttc));
|
|
aMemtblItems.FieldByName('备注').Value:='系数:'+FloatToStr(lasttcxs)+' 提成:'+formatFloat('0.00;-0.00;0',lasttc);
|
|
end;
|
|
end
|
|
else
|
|
aMemtblItems.FieldByName('提成').Value:=formatFloat('0.00;-0.00;0',aMemtblItems.FieldByName('提成比例').Value*memtblItems.FieldByName('毛利润').Value);
|
|
|
|
end
|
|
else
|
|
begin
|
|
aMemtblItems.FieldByName('提成').Value:=0;
|
|
end;
|
|
aMemtblItems.Post;
|
|
salses:=Trim(FieldByName('揽货人').AsString);
|
|
Next;
|
|
end;
|
|
finally
|
|
aMemtblItems.EnableControls;
|
|
aMemtblItems.Refresh;
|
|
Free;
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure Tfrm_rp_sales_profit_tc.Creatememtbl;
|
|
|
|
begin
|
|
end;
|
|
|
|
|
|
function Tfrm_rp_sales_profit_tc.getleftstr(substr: String; leng: integer;
|
|
left: boolean=true): String;
|
|
|
|
begin
|
|
end;
|
|
|
|
|
|
|
|
procedure Tfrm_rp_sales_profit_tc.FormShow(Sender: TObject);
|
|
begin
|
|
DateTimePicker1.Date:=Date;
|
|
loadreggrid(dxdbgrid2,false,caption+'2');
|
|
end;
|
|
|
|
procedure Tfrm_rp_sales_profit_tc.bsSkinButton1Click(Sender: TObject);
|
|
begin
|
|
grid_save_xls(dxdbgrid5);
|
|
end;
|
|
|
|
procedure Tfrm_rp_sales_profit_tc.DBComboBoxEh1DropDown(Sender: TObject);
|
|
var AdoQuery1:TAdoQuery;
|
|
begin
|
|
DBComboBoxEh1.items.clear;
|
|
AdoQuery1:=CreateAdoQuery;
|
|
with AdoQuery1 do
|
|
try
|
|
Close;sql.Clear;
|
|
SQL.Add('select * from t_sys_employee where 提成方案<>''''');
|
|
SQL.Add('Order by 姓名');
|
|
Open;first;
|
|
while not Eof do
|
|
begin
|
|
DBComboBoxEh1.Items.Add(AdoQuery1.fieldbyname('姓名').AsString);
|
|
Next;
|
|
end;
|
|
finally
|
|
Free;
|
|
end;
|
|
|
|
end;
|
|
|
|
procedure Tfrm_rp_sales_profit_tc.bsSkinPanel1Resize(Sender: TObject);
|
|
var
|
|
i:integer;
|
|
begin
|
|
i:=round(bsSkinPanel1.Width/4);
|
|
bsSkinButton1.Width:=i;
|
|
bsSkinButton2.Width:=i;
|
|
bsSkinButton10.Width:=i;
|
|
// bsSkinButton3.Width:=i;
|
|
// bsSkinButton13.Left:=Panel2.Width-bsSkinButton13.Width-20;
|
|
// bsSkinButton15.left:=bsSkinButton13.Left-75;
|
|
end;
|
|
|
|
procedure Tfrm_rp_sales_profit_tc.N14Click(Sender: TObject);
|
|
begin
|
|
update_grid_view_all(dxdbgrid2);
|
|
|
|
end;
|
|
|
|
procedure Tfrm_rp_sales_profit_tc.bsSkinButton4Click(Sender: TObject);
|
|
var AdoQuery1:TAdoQuery;
|
|
begin
|
|
kbmMemTableCLF.Close;
|
|
kbmMemTableCLF.EmptyTable;
|
|
kbmMemTableCLF.Open;
|
|
AdoQuery1:=CreateAdoQuery;
|
|
with AdoQuery1 do
|
|
try
|
|
Close;sql.Clear;
|
|
SQL.Add('select * from t_sys_employee where 提成方案<>''''');
|
|
SQL.Add('Order by 姓名');
|
|
Open;first;
|
|
while not Eof do
|
|
begin
|
|
kbmMemTableCLF.Append;
|
|
kbmMemTableCLF.FieldByName('揽货人').AsString:=FieldByName('姓名').AsString;
|
|
kbmMemTableCLF.FieldByName('差旅费').AsFloat:=0;
|
|
kbmMemTableCLF.Post;
|
|
Next;
|
|
end;
|
|
finally
|
|
Free;
|
|
end;
|
|
end;
|
|
|
|
end.
|