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.

1055 lines
34 KiB
Plaintext

unit u_rp_sales_profit_two;
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
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_two = class(TForm)
kbmThreadDataSet1: TkbmThreadDataSet;
Panel2: TPanel;
Label2: TLabel;
Label3: TLabel;
Label1: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
bsSkinEdit1: TbsSkinEdit;
wwDBComboBox1: TwwDBComboBox;
wwDBComboBox20: TwwDBComboBox;
wwDBComboBox2: TwwDBComboBox;
bsSkinButton10: TbsSkinButton;
CheckListBox1: TCheckListBox;
bsSkinButton9: TbsSkinButton;
bsSkinButton5: TbsSkinButton;
dxDBGrid8: TdxDBGrid;
dxDBGrid8Column7: TdxDBGridColumn;
dxDBGridColumn4: TdxDBGridColumn;
dxDBGrid8Column6: TdxDBGridColumn;
dxDBGrid8Column4: TdxDBGridColumn;
dxDBGrid8Column5: TdxDBGridColumn;
dxDBGridColumn7: TdxDBGridColumn;
dxDBGridColumn9: TdxDBGridColumn;
dxDBGrid8Column8: TdxDBGridColumn;
bsSkinPanel2: TbsSkinPanel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
wwDBDateTimePicker1: TwwDBDateTimePicker;
wwDBDateTimePicker2: TwwDBDateTimePicker;
bsSkinButton3: TbsSkinButton;
Edit1: TEdit;
tex: TbsSkinButton;
Edit2: TEdit;
dxDBGrid6: TdxDBGrid;
dxDBGrid6Column19: TdxDBGridColumn;
dxDBGrid6Column1: TdxDBGridColumn;
dxDBGrid6Column2: TdxDBGridColumn;
dxDBGrid6Column3: TdxDBGridColumn;
dxDBGrid6Column4: TdxDBGridColumn;
dxDBGrid6Column5: TdxDBGridColumn;
dxDBGrid6Column6: TdxDBGridColumn;
dxDBGrid6Column7: TdxDBGridColumn;
dxDBGrid6Column10: TdxDBGridColumn;
dxDBGrid6Column8: TdxDBGridColumn;
dxDBGrid6Column11: TdxDBGridColumn;
dxDBGrid6Column12: TdxDBGridColumn;
dxDBGrid6Column17: TdxDBGridColumn;
dxDBGrid6Column18: TdxDBGridColumn;
kbmqc: TkbmMemTable;
kbmqcField4: TStringField;
kbmqcField: TStringField;
kbmqcField2: TStringField;
kbmqcField3: TStringField;
kbmqcField5: TDateField;
kbmqcField6: TDateField;
kbmqcField7: TFloatField;
kbmqcField8: TFloatField;
kbmqcField9: TStringField;
kbmqcField11: TIntegerField;
kbmqcField10: TIntegerField;
kbmqcField12: TFloatField;
kbmqcField13: TStringField;
kbmqcUSD: TFloatField;
kbmqcRMB: TFloatField;
kbmqcField14: TDateField;
kbmqcRMB2: TFloatField;
kbmqcUSD2: TFloatField;
kbmqcField15: TFloatField;
kbmqcField16: TStringField;
kbmqc1: TDataSource;
kbmtc: TkbmMemTable;
kbmtcField: TStringField;
kbmtcField2: TFloatField;
kbmtcField3: TFloatField;
kbmtcUSD: TFloatField;
kbmtcRMB: TFloatField;
kbmtcField4: TFloatField;
kbmtcField5: TStringField;
kbmtcField6: TFloatField;
kbmtc1: TDataSource;
RxDBLookupCombo3: TRxDBLookupCombo;
kbmtcField7: TFloatField;
dxDBGrid8Column9: TdxDBGridColumn;
kbmqcField17: TStringField;
ComboBox1: TComboBox;
Label11: TLabel;
PopupMenu1: TPopupMenu;
MenuItem7: TMenuItem;
kbmtcOrdno: TIntegerField;
PopupMenu2: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
kbmtcField8: TStringField;
dxDBGrid8Column10: TdxDBGridColumn;
kbmtcField9: TFloatField;
dxDBGrid8Column11: TdxDBGridColumn;
dxDBGrid8Column12: TdxDBGridColumn;
kbmtcField10: TFloatField;
Label12: TLabel;
ComboBox2: TComboBox;
Label13: TLabel;
ComboBox3: TComboBox;
procedure bsSkinButton5Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure bsSkinButton10Click(Sender: TObject);
procedure bsSkinButton3Click(Sender: TObject);
procedure texClick(Sender: TObject);
procedure bsSkinButton9Click(Sender: TObject);
procedure MenuItem7Click(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure dxDBGrid6CustomDraw(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 dxDBGrid8CustomDraw(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 kbmtcBeforePost(DataSet: TDataSet);
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_sales_profit_two: Tfrm_rp_sales_profit_two;
FmDate,ToDate:String;
sqlstr:WideString;
implementation
uses u_main, my_sys_function,u_sys_progress;
{$R *.dfm}
procedure Tfrm_rp_sales_profit_two.bsSkinButton5Click(Sender: TObject);
begin
close;
end;
procedure Tfrm_rp_sales_profit_two.FormClose(Sender: TObject;
var Action: TCloseAction);
var inifile1:Tinifile;
begin
savereggrid(dxdbgrid6,caption+'6');
savereggrid(dxdbgrid8,caption+'8');
frm_rp_sales_profit_two.Hide;
frm_rp_sales_profit_two.ManualFloat(frm_rp_sales_profit_two.BoundsRect );
frm_main.freeTabs('frm_rp_sales_profit_two');
action:=cafree;
frm_rp_sales_profit_two:=nil;
inifile1:=Tinifile.Create(ExtractFilePath(application.ExeName)+'main.ini');
inifile1.WriteString('TC','DAYS',bsSkinEdit1.text);
inifile1.free;
end;
procedure Tfrm_rp_sales_profit_two.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);
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');
bsSkinEdit1.text:=inifile1.Readstring('TC','DAYS','0');
inifile1.free;
end;
function Tfrm_rp_sales_profit_two.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;
procedure Tfrm_rp_sales_profit_two.GetProfittcLx(depts:string;beginEtd,EndEtd:TDateTime);
var
betd,eetd:TDate;
aquery,bquery:TADOQuery;
str,bdatestr:String;
begin
bdatestr:='开船日期';
betd:=beginEtd;
eetd:=EndEtd;
aQuery:=CreateAdoQuery;
bQuery:=CreateAdoQuery;
with bQuery do
begin
Close;SQL.Clear;
SQL.Add('select distinct Fee2 from v_op_bscard');
SQL.Add('where 开船日期 between :beginEtd and :EndEtd');
SQL.Add(' and 揽货人=:揽货人');
end;
with aQuery do
try
Close;SQL.Clear;
str:='select 揽货人,sum(合计应收- 合计已收) 未收合计,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 if_open('405') then
else
begin
str:=Str+' and 揽货人='+''''+employee+'''';
end;
if depts<>'' then
str:=Str+' and 销售部门 in ('+depts+')';
SQL.Add(str);
SQL.Add(' group by 揽货人');
{
case ComboBox3.itemindex of
0:;
1:begin
SQL.Add(' having (sum(合计应收- 合计已收)=0) or (sum(合计应收- 合计已收) is null)');
end;
2:begin
SQL.Add(' having sum(合计应收- 合计已收)<>0');
end;
end;
}
SQL.Add(' order by 揽货人');
Open;First;
while not eof do
begin
case ComboBox3.itemindex of
0:
begin
kbmtc.insert;
kbmtc.FieldByName('OrdNo').AsInteger:=OrdNo;
bQuery.Close;
bQuery.Parameters.ParamByName('beginEtd').Value:=betd;
bQuery.Parameters.ParamByName('EndEtd').Value:=eetd;
bQuery.Parameters.ParamByName('揽货人').Value:=FieldByName('揽货人').AsString;
bQuery.Open;bQuery.first;
if bQuery.RecordCount>1 then
kbmtc.FieldByName('是否发放').AsString:='否'
else
if bQuery.RecordCount=1 then
begin
if bQuery.FieldByName('Fee2').AsInteger=1 then
kbmtc.FieldByName('是否发放').AsString:='是'
else kbmtc.FieldByName('是否发放').AsString:='否';
end
else kbmtc.FieldByName('是否发放').AsString:='否';
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:=FieldByName('未收合计').AsFloat;
kbmtc.FieldByName('汇率').AsFloat:=getUsdExRate(DateToStr(betd),'USD');
kbmtc.FieldByName('年月').AsString:=FormatDateTime('YYMM',betd);
kbmtc.FieldByName('应提成').AsString:=FormatFloat('0;-0;0',CalcProftAmttc(FieldByName('毛利润').AsFloat,FieldByName('揽货人').AsString));
kbmtc.FieldByName('税金').AsString:=FormatFloat('0;-0;0',kbmtc.FieldByName('应提成').AsFloat*0.08);
case ComboBox2.itemindex of
0:
begin
kbmtc.Post;
end;
1:
begin
if kbmtc.FieldByName('是否发放').AsString='否' then
kbmtc.Post
else
kbmtc.Delete;
end;
2:
begin
if kbmtc.FieldByName('是否发放').AsString='是' then
kbmtc.Post
else
kbmtc.Delete;
end;
end;
end;
1:begin
if FieldByName('未收合计').AsFloat=0 then
begin
kbmtc.insert;
kbmtc.FieldByName('OrdNo').AsInteger:=OrdNo;
bQuery.Close;
bQuery.Parameters.ParamByName('beginEtd').Value:=betd;
bQuery.Parameters.ParamByName('EndEtd').Value:=eetd;
bQuery.Parameters.ParamByName('揽货人').Value:=FieldByName('揽货人').AsString;
bQuery.Open;bQuery.first;
if bQuery.RecordCount>1 then
kbmtc.FieldByName('是否发放').AsString:='否'
else
if bQuery.RecordCount=1 then
begin
if bQuery.FieldByName('Fee2').AsInteger=1 then
kbmtc.FieldByName('是否发放').AsString:='是'
else kbmtc.FieldByName('是否发放').AsString:='否';
end
else kbmtc.FieldByName('是否发放').AsString:='否';
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:=FieldByName('未收合计').AsFloat;
kbmtc.FieldByName('汇率').AsFloat:=getUsdExRate(DateToStr(betd),'USD');
kbmtc.FieldByName('年月').AsString:=FormatDateTime('YYMM',betd);
kbmtc.FieldByName('应提成').AsString:=FormatFloat('0;-0;0',CalcProftAmttc(FieldByName('毛利润').AsFloat,FieldByName('揽货人').AsString));
kbmtc.FieldByName('税金').AsString:=FormatFloat('0;-0;0',kbmtc.FieldByName('应提成').AsFloat*0.08);
case ComboBox2.itemindex of
0:
begin
kbmtc.Post;
end;
1:
begin
if kbmtc.FieldByName('是否发放').AsString='否' then
kbmtc.Post
else
kbmtc.Delete;
end;
2:
begin
if kbmtc.FieldByName('是否发放').AsString='是' then
kbmtc.Post
else
kbmtc.Delete;
end;
end;
end;
end;
2:begin
if FieldByName('未收合计').AsFloat<>0 then
begin
kbmtc.insert;
kbmtc.FieldByName('OrdNo').AsInteger:=OrdNo;
bQuery.Close;
bQuery.Parameters.ParamByName('beginEtd').Value:=betd;
bQuery.Parameters.ParamByName('EndEtd').Value:=eetd;
bQuery.Parameters.ParamByName('揽货人').Value:=FieldByName('揽货人').AsString;
bQuery.Open;bQuery.first;
if bQuery.RecordCount>1 then
kbmtc.FieldByName('是否发放').AsString:='否'
else
if bQuery.RecordCount=1 then
begin
if bQuery.FieldByName('Fee2').AsInteger=1 then
kbmtc.FieldByName('是否发放').AsString:='是'
else kbmtc.FieldByName('是否发放').AsString:='否';
end
else kbmtc.FieldByName('是否发放').AsString:='否';
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:=FieldByName('未收合计').AsFloat;
kbmtc.FieldByName('汇率').AsFloat:=getUsdExRate(DateToStr(betd),'USD');
kbmtc.FieldByName('年月').AsString:=FormatDateTime('YYMM',betd);
kbmtc.FieldByName('应提成').AsString:=FormatFloat('0;-0;0',CalcProftAmttc(FieldByName('毛利润').AsFloat,FieldByName('揽货人').AsString));
kbmtc.FieldByName('税金').AsString:=FormatFloat('0;-0;0',kbmtc.FieldByName('应提成').AsFloat*0.08);
case ComboBox2.itemindex of
0:
begin
kbmtc.Post;
end;
1:
begin
if kbmtc.FieldByName('是否发放').AsString='否' then
kbmtc.Post
else
kbmtc.Delete;
end;
2:
begin
if kbmtc.FieldByName('是否发放').AsString='是' then
kbmtc.Post
else
kbmtc.Delete;
end;
end;
end;
end;
end;
OrdNo:=OrdNo+1;
Next;
end;
finally
FreeAndNil(aquery);
FreeAndNil(bquery);
end;
end;
procedure Tfrm_rp_sales_profit_two.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;
kbmtc.EmptyTable;
kbmtc.Open;
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_sales_profit_two.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_two.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_two.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_two.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_two.UpdateBsProfitLc(bstype,bsno,LcYYMM:String);
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 发票号=:发票号');
SQL.Add('where 编号=:bsno');
Parameters.ParamByName('bsno').Value:=bsno;
Parameters.ParamByName('发票号').Value:=LcYYMM;
Execsql;
finally
FreeAndNil(aQuery);
end;
end;
procedure Tfrm_rp_sales_profit_two.bsSkinButton3Click(Sender: TObject);
var
betd,eetd:TDate;
aquery,bquery:TADOQuery;
str,bdatestr:String;
begin
if Trim(Edit1.Text)<>'' then
begin
ComboBox1.ItemIndex:=2;
end;
if not kbmtc.IsEmpty then
with kbmtc do
begin
First;
while not Eof do
begin
kbmtc.Edit;
kbmtc.FieldByName('扣息').AsFloat:=0;
kbmtc.FieldByName('实发提成').AsFloat:=0;
kbmtc.Post;
Next;
end;
end;
bdatestr:='开船日期';
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 ';
if (wwDBDateTimePicker1.text<>'') and (wwDBDateTimePicker2.text<>'') then
begin
str:=Str+' '+bdatestr+'>='+''''+DateToStr(wwDBDateTimePicker1.Date)+'''';
str:=Str+' and '+bdatestr+'<='+''''+DateToStr(wwDBDateTimePicker2.Date)+'''';
end
else
begin
str:=Str+' 1=1';
end;
{
if Edit1.text<>'' then
str:=Str+' and 发票号='+''''+Edit1.text+'''';
}
if if_open('405') then
begin
end
else
begin
str:=Str+' and 揽货人='+''''+employee+'''';
end;
SQL.Add(str);
SQL.Add(' and 委托单位 in (select 客户简称 from t_crm_client_sales where 结费类型<>''现结买单'')');
case ComboBox1.ItemIndex of
0:begin //全部
end;
1:begin //未结算
SQL.Add(' and (发票号 is Null or 发票号='''')');
end;
2:begin //已结算
if trim(Edit1.text)<>'' then
SQL.Add(' and 发票号='+''''+Edit1.text+'''')
else
SQL.Add(' and (not 发票号 is Null and 发票号<>'''')');
end;
3:begin //未收款
SQL.Add(' and (合计应收-合计已收)<>0');
end;
end;
SQL.Add(' order by 揽货人');
Open;First;
//ShowMessage(SQL.Text);
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('客户名称').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('利息').AsFloat:=0;
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;
end;
if (Trim(kbmqc.FieldByName('扣息月').AsString)<>'') and (kbmqc.FieldByName('利息').AsFloat>0) then
if not kbmtc.IsEmpty then
if kbmtc.Locate('揽货人;年月',vararrayof([Trim(kbmqc.FieldByName('揽货人').AsString),Trim(kbmqc.FieldByName('扣息月').AsString)]),[]) then
begin
kbmtc.Edit;
kbmtc.FieldByName('扣息').AsFloat:=kbmtc.FieldByName('扣息').AsFloat+StrToFloat(FormatFloat('0;-0;0',kbmqc.FieldByName('利息').AsFloat));
kbmtc.Post;
end;
if kbmqc.FieldByName('利息').AsFloat>0 then
kbmqc.Post
else
kbmqc.Delete;
Next;
end;
finally
FreeAndNil(aquery);
end;
end;
procedure Tfrm_rp_sales_profit_two.texClick(Sender: TObject);
var i:integer;
begin
if Edit2.text='' then
begin
if not if_open('406') then
begin
showmessage('你没有此模块的操作权限!,请联系系统管理员,权限设置路径:操作管理--->销售管理--->取消提成');
exit;
end;
if MessageDlg('输入月份(YYMM)为空要取消结算吗? 是否继续?',mtWarning,[mbyes,mbno],0)<>mryes then
Exit;
end
else
begin
if not if_open('405') then
begin
showmessage('你没有此模块的操作权限!,请联系系统管理员,权限设置路径:操作管理--->销售管理--->发放提成');
exit;
end;
if MessageDlg('确实要将扣息结算结算到'+Edit2.text+'吗? 是否继续?',mtWarning,[mbyes,mbno],0)<>mryes then
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]));
kbmqc.Edit;
kbmqc.FieldByName('扣息月').AsString:=Edit2.text;
kbmqc.Post;
UpdateBsProfitLc(kbmqc.fieldbyname('业务类型').asstring,kbmqc.fieldbyname('编号').asstring,Edit2.text);
end;
finally
kbmqc.EnableControls;
end;
end;
procedure Tfrm_rp_sales_profit_two.bsSkinButton9Click(Sender: TObject);
begin
sys_print('业务综合统计',2,nil,nil,nil,nil,nil,nil,nil,kbmtc1,kbmqc1,nil,nil);
end;
procedure Tfrm_rp_sales_profit_two.MenuItem7Click(Sender: TObject);
begin
grid_save_xls(dxdbgrid6);
end;
procedure Tfrm_rp_sales_profit_two.N1Click(Sender: TObject);
var aquery:TADOQuery;
begin
if not if_open('405') then
begin
showmessage('你没有此模块的操作权限!,请联系系统管理员,权限设置路径:操作管理--->销售管理--->发放提成');
exit;
end;
if MessageDlg('确实要结算 '+kbmtc.FieldByName('揽货人').AsString+' '+kbmtc.FieldByName('年月').AsString+'吗? 是否继续?',mtWarning,[mbyes,mbno],0)<>mryes then
Exit;
aQuery:=CreateAdoQuery;
with aQuery do
try
close;SQL.Clear;
SQL.Add('select * from v_op_bscard');
SQL.Add('where substring(CONVERT(varchar(100), 开船日期, 112),3,4)='''+kbmtc.FieldByName('年月').AsString+'''');
SQL.Add('and 揽货人='''+kbmtc.FieldByName('揽货人').AsString+'''');
open;First;
while not eof do
begin
UpdateBsProfit(fieldbyname('业务类型').asstring,fieldbyname('编号').asstring,1);
Next;
end;
kbmtc.Edit;
kbmtc.FieldByName('是否发放').AsString:='是';
kbmtc.Post;
finally
Free;
end;
//
end;
procedure Tfrm_rp_sales_profit_two.N3Click(Sender: TObject);
var aquery:TADOQuery;
begin
if not if_open('406') then
begin
showmessage('你没有此模块的操作权限!,请联系系统管理员,权限设置路径:操作管理--->销售管理--->取消提成');
exit;
end;
if MessageDlg('确实要取消结算 '+kbmtc.FieldByName('揽货人').AsString+' '+kbmtc.FieldByName('年月').AsString+'吗? 是否继续?',mtWarning,[mbyes,mbno],0)<>mryes then
Exit;
aQuery:=CreateAdoQuery;
with aQuery do
try
close;SQL.Clear;
SQL.Add('select * from v_op_bscard');
SQL.Add('where substring(CONVERT(varchar(100), 开船日期, 112),3,4)='''+kbmtc.FieldByName('年月').AsString+'''');
SQL.Add('and 揽货人='''+kbmtc.FieldByName('揽货人').AsString+'''');
open;First;
while not eof do
begin
UpdateBsProfit(fieldbyname('业务类型').asstring,fieldbyname('编号').asstring,0);
Next;
end;
kbmtc.Edit;
kbmtc.FieldByName('是否发放').AsString:='否';
kbmtc.Post;
finally
Free;
end;
end;
procedure Tfrm_rp_sales_profit_two.dxDBGrid6CustomDraw(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[dxDBGrid6Column19.Index])<>'' then
begin
// AFont.Style:=AFont.Style+[fsStrikeOut];
AColor:=$00E3C784;
exit;
end;
end;
procedure Tfrm_rp_sales_profit_two.dxDBGrid8CustomDraw(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[dxDBGrid8Column10.Index])='是' then
begin
// AFont.Style:=AFont.Style+[fsStrikeOut];
AColor:=$00E3C784;
exit;
end;
end;
procedure Tfrm_rp_sales_profit_two.kbmtcBeforePost(DataSet: TDataSet);
begin
kbmtc.FieldByName('实发提成').AsFloat:=StrToFloat(FormatFloat('0;-0;0',kbmtc.FieldByName('应提成').AsFloat-kbmtc.FieldByName('税金').AsFloat-kbmtc.FieldByName('扣息').AsFloat));
end;
end.