Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
intranet-resource-management
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
project-open
intranet-resource-management
Commits
66352319
Commit
66352319
authored
Jan 17, 2020
by
cosine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- WIP - trying to add "collisions" to cosine resource-management report
parent
b3a2b77a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
0 deletions
+72
-0
intranet-resource-management-create.sql
sql/postgresql/intranet-resource-management-create.sql
+1
-0
upgrade-5.0.3.0.0-5.0.3.0.1.sql
sql/postgresql/upgrade/upgrade-5.0.3.0.0-5.0.3.0.1.sql
+71
-0
No files found.
sql/postgresql/intranet-resource-management-create.sql
View file @
66352319
...
...
@@ -369,6 +369,7 @@ BEGIN
v_date
:
=
row
.
start_date
;
WHILE
(
v_date
<=
row
.
end_date
)
LOOP
v
:
=
v_work_days
[
v_date
-
p_start_date
];
IF
v
is
NULL
THEN
exit
;
END
IF
;
v
:
=
v
-
v_perc
;
if
v
<
0
.
0
THEN
v
:
=
0
.
0
;
END
IF
;
v_work_days
[
v_date
-
p_start_date
]
:
=
v
;
...
...
sql/postgresql/upgrade/upgrade-5.0.3.0.0-5.0.3.0.1.sql
View file @
66352319
...
...
@@ -42,6 +42,7 @@ BEGIN
v_date
:
=
row
.
start_date
;
WHILE
(
v_date
<=
row
.
end_date
)
LOOP
v
:
=
v_work_days
[
v_date
-
p_start_date
];
IF
v
is
null
THEN
exit
;
END
IF
;
v
:
=
v
-
v_perc
;
if
v
<
0
.
0
THEN
v
:
=
0
.
0
;
END
IF
;
v_work_days
[
v_date
-
p_start_date
]
:
=
v
;
...
...
@@ -54,3 +55,73 @@ END;$body$ language 'plpgsql';
-- select im_resource_mgmt_work_days(624, '2019-12-23', '2019-12-30');
-- select im_resource_mgmt_work_days(463, '2018-12-01'::date, '2019-01-01');
-- Returns a real[] for each day between start and end
-- with 100 for a full absence (vacation, bank holiday, ...any)
create
or
replace
function
im_resource_mgmt_absence_days
(
integer
,
date
,
date
)
returns
float
[]
as
$
body
$
DECLARE
p_user_id
alias
for
$
1
;
p_start_date
alias
for
$
2
;
p_end_date
alias
for
$
3
;
v_weekday
integer
;
v_date
date
;
v_work_days
float
[];
v_date_difference
integer
;
v_perc
float
;
v
float
;
row
record
;
BEGIN
-- Initiate the result array with zeros
v_date
:
=
p_start_date
;
WHILE
(
v_date
<=
p_end_date
)
LOOP
v_work_days
[
v_date
-
p_start_date
]
:
=
0
;
v_date
:
=
v_date
+
1
;
END
LOOP
;
-- Apply absences
FOR
row
IN
select
a
.
*
from
im_user_absences
a
where
(
a
.
owner_id
=
p_user_id
OR
a
.
group_id
=
p_user_id
OR
a
.
group_id
in
(
select
group_id
from
group_distinct_member_map
where
member_id
=
p_user_id
))
and
a
.
end_date
::
date
>=
p_start_date
and
a
.
start_date
::
date
<=
p_end_date
and
-- a.absence_type_id in (select * from im_sub_categories(5005)) and -- only bank holidays
a
.
absence_status_id
not
in
(
select
*
from
im_sub_categories
(
16002
)
union
select
*
from
im_sub_categories
(
16006
))
-- exclude deleted and rejected
LOOP
v_date_difference
=
1
+
row
.
end_date
::
date
-
row
.
start_date
::
date
;
v_perc
=
100
.
0
*
row
.
duration_days
/
v_date_difference
;
RAISE
NOTICE
'im_resource_mgmt_work_days(%,%,%): Absence %'
,
p_user_id
,
p_start_date
,
p_end_date
,
row
.
absence_name
;
v_date
:
=
row
.
start_date
;
WHILE
(
v_date
<=
row
.
end_date
)
LOOP
v
:
=
v_work_days
[
v_date
-
p_start_date
];
IF
v
is
null
THEN
exit
;
END
IF
;
v
:
=
v
+
v_perc
;
if
v
>
100
.
0
THEN
v
:
=
100
.
0
;
END
IF
;
v_work_days
[
v_date
-
p_start_date
]
:
=
v
;
v_date
:
=
v_date
+
1
;
END
LOOP
;
END
LOOP
;
-- Set weekends to zero
WHILE
(
v_date
<=
p_end_date
)
LOOP
v_weekday
:
=
to_char
(
v_date
,
'D'
);
IF
v_weekday
=
1
OR
v_weekday
=
7
THEN
v_work_days
[
v_date
-
p_start_date
]
:
=
0
;
END
IF
;
v_date
:
=
v_date
+
1
;
END
LOOP
;
return
v_work_days
;
END
;
$
body
$
language
'plpgsql'
;
select
im_resource_mgmt_work_days
(
55815
,
'2020-01-01'
,
'2020-01-31'
);
select
im_resource_mgmt_work_days_cosine
(
55815
,
'2020-01-01'
,
'2020-01-31'
);
select
im_resource_mgmt_absence_days
(
55815
,
'2020-01-01'
,
'2020-01-31'
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment