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.

398 lines
12 KiB
Plaintext

11 months ago
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 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> from t_sys_department ');
SQL.Add('order by <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
Open;first;
CheckListBox1.Clear;
while not eof do
begin
CheckListBox1.Items.Add(trim(FieldByName('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>').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.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
betd:=beginEtd;
eetd:=EndEtd;
aQuery:=CreateAdoQuery;
with aQuery do
try
Close;SQL.Clear;
str:='select s.<2E><><EFBFBD><EFBFBD>,s.<2E><><EFBFBD><EFBFBD>Ա,s.<2E><><EFBFBD><EFBFBD><E1B5A5>,s.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
str:=Str+' '+',sum(case when (fee.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=''<27><><EFBFBD>˷<EFBFBD>'') or (fee.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=''THC<48><43>'') or (fee.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=''<27><><EFBFBD>ɷ<EFBFBD>'') then fee.<2E><><EFBFBD><EFBFBD> else 0 end) <20><><EFBFBD>˷<EFBFBD>';
str:=Str+' '+',sum(case when (fee.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=''<27>ϳ<EFBFBD><CFB3><EFBFBD>'') or (fee.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=''½<>˷<EFBFBD>'') then fee.<2E><><EFBFBD><EFBFBD> else 0 end) <20>ϳ<EFBFBD><CFB3><EFBFBD>';
str:=Str+' '+',sum(case when fee.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=''<27><><EFBFBD>ط<EFBFBD>'' then fee.<2E><><EFBFBD><EFBFBD> else 0 end) <20><><EFBFBD>ط<EFBFBD>';
str:=Str+' '+',sum(case when fee.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=''<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'' then fee.<2E><><EFBFBD><EFBFBD> else 0 end) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
str:=Str+' '+',sum(case when fee.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=''<27><EFBFBD><E0BBA4>'' then fee.<2E><><EFBFBD><EFBFBD> else 0 end) <20><EFBFBD><E0BBA4>';
str:=Str+' '+',sum(case when fee.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=''<27>յ<EFBFBD><D5B5><EFBFBD>'' then fee.<2E><><EFBFBD><EFBFBD> else 0 end) <20>յ<EFBFBD><D5B5><EFBFBD>';
str:=Str+' '+',ctn.TEU';
str:=Str+' '+',ass.<2E>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>';
str:=Str+' '+'from t_op_seae s ';
str:=Str+' '+'left join (select <20><><EFBFBD><EFBFBD>,sum(TEU) TEU from t_op_ctn group by <20><><EFBFBD><EFBFBD>) ctn on s.<2E><><EFBFBD><EFBFBD>=ctn.<2E><><EFBFBD><EFBFBD>';
str:=Str+' '+'left join t_ch_fee fee on fee.<2E><><EFBFBD><EFBFBD>=s.<2E><><EFBFBD><EFBFBD> and fee.<2E><><EFBFBD><EFBFBD>=''<27><>''';
str:=Str+' '+'left join (select <20><><EFBFBD><EFBFBD>,count(*) <20>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD> from t_op_seae_assistant group by <20><><EFBFBD><EFBFBD> ) as ass on s.<2E><><EFBFBD><EFBFBD>=ass.<2E><><EFBFBD><EFBFBD>';
str:=Str+' '+'where 1=1 and s.ҵ<><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>=''<27><>ͨ<EFBFBD><CDA8>'' and ';
str:=Str+' '+bdatestr+'>='+''''+DateToStr(betd)+'''';
str:=Str+' and '+bdatestr+'<='+''''+DateToStr(eetd)+'''';
if RxDBLookupCombo3.DisplayValue<>'' then
str:=Str+' and s.<2E><><EFBFBD><EFBFBD>Ա='+''''+RxDBLookupCombo3.DisplayValue+'''';
if depts<>'' then
str:=Str+' and s.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> in ('+depts+')';
str:=str+' and '+open_data('0001','s.¼<><C2BC><EFBFBD><EFBFBD>',
's.<2E><><EFBFBD><EFBFBD>Ա','s.<2E>ͷ<EFBFBD>Ա','no','no','no');
SQL.Add(str);
SQL.Add(' group by s.<2E><><EFBFBD><EFBFBD>,s.<2E><><EFBFBD><EFBFBD>Ա,s.<2E><><EFBFBD><EFBFBD><E1B5A5>,s.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,ass.<2E>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>,ctn.TEU');
SQL.Add(' order by s.<2E><><EFBFBD><EFBFBD>Ա,s.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
// showmessage(SQL.Text);
Open;First;
while not eof do
begin
kbmqc.insert;
kbmqc.FieldByName('OrdNo').AsInteger:=OrdNo;
kbmqc.FieldByName('<27><><EFBFBD><EFBFBD>Ա').AsString:=FieldByName('<27><><EFBFBD><EFBFBD>Ա').AsString;
kbmqc.FieldByName('<27><><EFBFBD><EFBFBD><E1B5A5>').AsString:=FieldByName('<27><><EFBFBD><EFBFBD><E1B5A5>').AsString;
kbmqc.FieldByName('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>').AsString:=FieldByName('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>').AsString;
kbmqc.FieldByName('<27><><EFBFBD>˷<EFBFBD>').AsBoolean:=FieldByName('<27><><EFBFBD>˷<EFBFBD>').AsFloat<>0;
kbmqc.FieldByName('<27>ϳ<EFBFBD><CFB3><EFBFBD>').AsBoolean:=FieldByName('<27>ϳ<EFBFBD><CFB3><EFBFBD>').AsFloat<>0;
kbmqc.FieldByName('<27><><EFBFBD>ط<EFBFBD>').AsBoolean:=FieldByName('<27><><EFBFBD>ط<EFBFBD>').AsFloat<>0;
kbmqc.FieldByName('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>').AsBoolean:=FieldByName('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>').AsFloat<>0;
kbmqc.FieldByName('<27><EFBFBD><E0BBA4>').AsBoolean:=FieldByName('<27><EFBFBD><E0BBA4>').AsFloat<>0;
kbmqc.FieldByName('<27>յ<EFBFBD><D5B5><EFBFBD>').AsBoolean:=FieldByName('<27>յ<EFBFBD><D5B5><EFBFBD>').AsFloat<>0;
kbmqc.FieldByName('TEU').AsFloat:=FieldByName('TEU').AsFloat;
kbmqc.FieldByName('<27>ֵ<EFBFBD>').AsBoolean:=FieldByName('<27>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>').AsFloat<>0;
kbmqc.FieldByName('<27><><EFBFBD><EFBFBD>').AsString:=FormatDateTime('YYMM',Eetd);
kbmqc.FieldByName('<27><><EFBFBD><EFBFBD>').AsString:=FieldByName('<27><><EFBFBD><EFBFBD>').AsString;
rate:=0;
if kbmqc.FieldByName('<27><><EFBFBD>˷<EFBFBD>').AsBoolean then
begin
rate:=1;
if kbmqc.FieldByName('TEU').AsFloat>10 then
rate:=rate+0.5;
if kbmqc.FieldByName('<27>ֵ<EFBFBD>').AsBoolean then
rate:=rate+0.7;
if kbmqc.FieldByName('<27><EFBFBD><E0BBA4>').AsBoolean then
rate:=rate+0.5;
if kbmqc.FieldByName('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>').AsBoolean then
rate:=rate+0.2;
{
if kbmqc.FieldByName('<27>ϳ<EFBFBD><CFB3><EFBFBD>').AsBoolean then
rate:=rate+0.2;
if kbmqc.FieldByName('<27><><EFBFBD>ط<EFBFBD>').AsBoolean then
rate:=rate+0.2;
}
end
else
begin
if (kbmqc.FieldByName('<27><><EFBFBD>ط<EFBFBD>').AsBoolean) and kbmqc.FieldByName('<27>ϳ<EFBFBD><CFB3><EFBFBD>').AsBoolean then
rate:=0.5
else
if kbmqc.FieldByName('<27><><EFBFBD>ط<EFBFBD>').AsBoolean then
rate:=0.2
else
if kbmqc.FieldByName('<27>ϳ<EFBFBD><CFB3><EFBFBD>').AsBoolean then
rate:=0.2;
if kbmqc.FieldByName('<27>յ<EFBFBD><D5B5><EFBFBD>').AsBoolean then
rate:=rate+0.2;
if kbmqc.FieldByName('TEU').AsFloat>10 then
rate:=rate+0.5;
end;
kbmqc.FieldByName('<27>ϼ<EFBFBD>').AsFloat:=rate;
kbmqc.Post;
if kbmtc.Locate('<27><><EFBFBD><EFBFBD>;<3B><><EFBFBD><EFBFBD>Ա',varArrayof([kbmqc.FieldByName('<27><><EFBFBD><EFBFBD>').AsString,kbmqc.FieldByName('<27><><EFBFBD><EFBFBD>Ա').AsString]),[]) then
begin
kbmtc.Edit;
kbmtc.FieldByName('Ʊ<><C6B1>').AsFloat:=kbmtc.FieldByName('Ʊ<><C6B1>').AsFloat+rate;
kbmtc.Post;
end
else
begin
kbmtc.insert;
kbmtc.FieldByName('OrdNo').AsInteger:=OrdNo;
kbmtc.FieldByName('<27><><EFBFBD><EFBFBD>Ա').AsString:=FieldByName('<27><><EFBFBD><EFBFBD>Ա').AsString;
kbmtc.FieldByName('<27><><EFBFBD><EFBFBD>').AsString:=FormatDateTime('YYMM',eetd);
kbmtc.FieldByName('Ʊ<><C6B1>').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('<27><><EFBFBD>˲<EFBFBD><CBB2><EFBFBD>',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('<27><><EFBFBD><EFBFBD>').asstring);
end;
procedure Tfrm_rp_op_profit.N1Click(Sender: TObject);
begin
grid_save_xls(dxdbgrid8);
end;
end.