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
37583e72
Commit
37583e72
authored
Dec 28, 2020
by
Frank Bergmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- moved file to upgrade folder
parent
3ca434e0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
124 deletions
+0
-124
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
+0
-124
No files found.
sql/postgresql/upgrade/upgrade-5.0.3.0.0-5.0.3.0.1.sql
deleted
100644 → 0
View file @
3ca434e0
-- upgrade-5.0.3.0.0-5.0.3.0.1.sql
SELECT
acs_log__debug
(
'/packages/intranet-resource-management/sql/postgresql/upgrade/upgrade-5.0.3.0.0-5.0.3.0.1.sql'
,
''
);
-- Returns a real[] for each day between start and end
-- with 100 for working days and 0 for weekend + bank holidays
create
or
replace
function
im_resource_mgmt_work_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
v_work_days
=
im_resource_mgmt_weekend
(
p_user_id
,
p_start_date
,
p_end_date
);
-- Apply "Bank Holiday" 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
-- Take into
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(%,%,%): Bank Holiday %', 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
<
0
.
0
THEN
v
:
=
0
.
0
;
END
IF
;
v_work_days
[
v_date
-
p_start_date
]
:
=
v
;
v_date
:
=
v_date
+
1
;
END
LOOP
;
END
LOOP
;
return
v_work_days
;
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_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