-
Notifications
You must be signed in to change notification settings - Fork 0
/
_Employees.al
125 lines (118 loc) · 4.34 KB
/
_Employees.al
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
pageextension 50107 EmployeeCardExt extends "Employee Card"
{
layout
{
modify("No.")
{
trigger OnAfterValidate()
begin
Message('Please set the Resource No. field to the relevant resource, and set Dimension Codes for Department (Code Mandatory) and Resource (Same Code).');
end;
}
modify("E-Mail")
{ ShowMandatory = true; }
modify("Mobile Phone No.")
{ ShowMandatory = true; }
addafter("Search Name")
{
field("Employee Notes"; Rec."Employee Notes")
{
MultiLine = true;
ApplicationArea = All;
}
}
modify("Phone No.")
{ CaptionML = ENG = 'Home Phone No.'; }
modify("Phone No.2")
{ Visible = false; CaptionML = ENG = 'Home Phone No.'; }
addafter("Grounds for Term. Code")
{
field("Employment Duration"; EmploymentDuration)
{
ApplicationArea = All;
Visible = true;
Caption = 'Employment Duration';
}
}
}
actions
{
addlast("E&mployee")
{
action(ResourceLink)
{
ApplicationArea = All;
Image = Resource;
Caption = 'Resource Card';
RunObject = page "Resource Card";
RunPageLink = "No." = field("Resource No.");
Description = 'Go to the Resource Card';
ToolTip = 'Opens the resource card for this employee';
Visible = true;
Enabled = true;
// Promoted = true;
// PromotedCategory = Process;
}
}
addlast(Category_Process)
{
actionref(Dimensions_Promoted2; Dimensions)
{ }
actionref(ResourceLink_Promoted; ResourceLink)
{ }
actionref(Absenses_Promoted; "A&bsences")
{ }
}
}
var
EmploymentDuration: Text;
trigger OnAfterGetRecord()
begin
if Rec."Inactive Date" = 0D then
EmploymentDuration := CalculateTimeBetweenTwoDate(Rec."Employment Date", Today)
else
EmploymentDuration := CalculateTimeBetweenTwoDate(Rec."Employment Date", Rec."Inactive Date")
end;
// local procedure CalculateTimeBetweenTwoDate(StartDate: Date; EndDate: Date): Text
// var
// NoOfYears: Integer;
// NoOfMonths: Integer;
// NoOfDays: Integer;
// begin
// //if Rec."Termination Date" <> 0D then EndDate := Today;
// NoOfYears := DATE2DMY(EndDate, 3) - DATE2DMY(StartDate, 3);
// NoOfMonths := DATE2DMY(EndDate, 2) - DATE2DMY(StartDate, 2);
// NoOfDays := DATE2DMY(EndDate, 1) - DATE2DMY(StartDate, 1);
// exit(format(NoOfYears+(NoOfMonths/12)+(NoOfDays/365)) + 'Y ');
// //exit((12 * NoOfYears) + NoOfMonths + (NoOfDays / 30));
// // exit(format(12 * NoOfYears) + ' years ' + format(NoOfMonths) + ' months ' + format(NoOfDays) + ' days');
// end;
local procedure CalculateTimeBetweenTwoDate(StartDate: Date; EndDate: Date): Text
var
NoOfYears: Integer;
NoOfMonths: Integer;
NoOfDays: Integer;
DaysInMonth: Integer;
begin
if EndDate < StartDate then exit;
// Calculate years difference
NoOfYears := DATE2DMY(EndDate, 3) - DATE2DMY(StartDate, 3);
// Calculate months difference
NoOfMonths := DATE2DMY(EndDate, 2) - DATE2DMY(StartDate, 2);
// Calculate days difference
NoOfDays := DATE2DMY(EndDate, 1) - DATE2DMY(StartDate, 1);
// Adjust for negative days
if NoOfDays < 0 then begin
// Get the number of days in the previous month
DaysInMonth := CALCDATE('<+1M>', DMY2DATE(1, DATE2DMY(EndDate, 2) - 1, DATE2DMY(EndDate, 3))) - DMY2DATE(1, DATE2DMY(EndDate, 2) - 1, DATE2DMY(EndDate, 3));
NoOfDays := NoOfDays + DaysInMonth;
NoOfMonths := NoOfMonths - 1;
end;
// Adjust for negative months
if NoOfMonths < 0 then begin
NoOfMonths := NoOfMonths + 12;
NoOfYears := NoOfYears - 1;
end;
exit(Format(NoOfYears) + ' years, ' + Format(NoOfMonths) + ' months, ' + Format(NoOfDays) + ' days');
end;
}