Commit bc44aabb authored by cosine's avatar cosine

- Finished 'vacation balance' update process:

  - Vacation Balance Portlet:
    Now showing a warning message and a link in any vacation balance
    portlet when it's necessary to update users.
  - Vacation Balance Report:
    Only offers to update the balance for those users with an outdated
    balance.
  - Added lengthy help text
  - Improved clarity of header0
parent 3c5306ff
<if @view_absences_p@ or @view_absences_all_p@>
<!-- Show a message if there are old vacation balances in the system -->
<if @vacation_balance_update_msg@ not nil>
@vacation_balance_update_msg;noquote@
</if>
<table>
<!--
<tr class=rowtitle>
......@@ -33,7 +39,6 @@
</table>
<br>
<h2><%=[lang::message::lookup "" intranet-timesheet2.Absences_This_Year "Current Year"]%></h2>
<listtemplate name="vacation_balance"></listtemplate>
<br>
......
......@@ -63,7 +63,7 @@ db_0or1row user_info "
# ------------------------------------------------------------------
#
# Calculate the number of vacation days for current year
# ------------------------------------------------------------------
list::create \
......@@ -109,9 +109,8 @@ set vacation_sql "
a.owner_id = :user_id_from_search and
a.start_date <= :end_of_year and
a.end_date >= :start_of_year and
a.absence_type_id in (select * from im_sub_categories(5000)) and
a.absence_status_id <> 16006 and
a.absence_status_id <> 16002
a.absence_type_id in (select * from im_sub_categories([im_user_absence_type_vacation])) and
a.absence_status_id not in ([im_user_absence_status_deleted], [im_user_absence_status_rejected])
order by
a.start_date
"
......@@ -171,7 +170,6 @@ set start_of_next_year "[expr {$current_year + 1}]-01-01"
set end_of_next_year "[expr {$current_year + 1}]-12-31"
set vacation_days_next_year_sql "
select
a.*,
substring(a.description from 1 for 40) as description_pretty,
......@@ -185,9 +183,8 @@ set vacation_days_next_year_sql "
a.owner_id = :user_id_from_search and
a.start_date <= :end_of_next_year and
a.end_date >= :start_of_next_year and
a.absence_type_id = 5000 and
a.absence_status_id <> 16006 and
a.absence_status_id <> 16002
a.absence_type_id in (select * from im_sub_categories([im_user_absence_type_vacation])) and
a.absence_status_id not in ([im_user_absence_status_deleted], [im_user_absence_status_rejected])
order by
a.start_date
"
......@@ -198,3 +195,104 @@ db_multirow -extend { absence_url absence_type } vacation_multirow_next_year vac
set duration_days [format "%.2f" $duration_days]
}
# ------------------------------------------------------------------
# Calculate the number of vacation days for past year
# ------------------------------------------------------------------
list::create \
-name vacation_days_past_year \
-multirow vacation_multirow_past_year \
-key absence_id \
-checkbox_name checkbox \
-selected_format "normal" \
-class "list" \
-main_class "list" \
-sub_class "narrow" \
-actions {
} -elements {
absence_name {
label "[lang::message::lookup {} intranet-timesheet2.Name Name]"
link_url_eval $absence_url
}
absence_type {
label "[lang::message::lookup {} intranet-timesheet2.Type Type]"
}
start_date_pretty {
label "[lang::message::lookup {} intranet-timesheet2.Start_Date Start]"
}
end_date_pretty {
label "[lang::message::lookup {} intranet-timesheet2.End_Date End]"
}
duration_days {
label "[lang::message::lookup {} intranet-timesheet2.Vacation_Days_Taken {Vacation Days Taken}]"
}
}
set start_of_past_year "[expr $current_year - 1]-01-01"
set end_of_past_year "[expr $current_year - 1]-12-31"
set vacation_days_past_year_sql "
select
a.*,
substring(a.description from 1 for 40) as description_pretty,
substring(a.contact_info from 1 for 40) as contact_info_pretty,
to_char(a.start_date, :date_format) as start_date_pretty,
to_char(a.end_date, :date_format) as end_date_pretty,
im_name_from_user_id(a.owner_id) as owner_name
from
im_user_absences a
where
a.owner_id = :user_id_from_search and
a.start_date <= :end_of_past_year and
a.end_date >= :start_of_past_year and
a.absence_type_id in (select * from im_sub_categories([im_user_absence_type_vacation])) and
a.absence_status_id not in ([im_user_absence_status_deleted], [im_user_absence_status_rejected])
order by
a.start_date
"
db_multirow -extend { absence_url absence_type } vacation_multirow_past_year vacation_days_past_year $vacation_days_past_year_sql {
set absence_url [export_vars -base "$absence_base_url/new" {{form_mode display} absence_id}]
set absence_type [im_category_from_id $absence_type_id]
set duration_days [format "%.2f" $duration_days]
}
# ------------------------------------------------------------------
# Check if there are outdated vacation balances in the system
# ------------------------------------------------------------------
set vacation_balance_update_msg ""
set num_vacation_balance_outdated [db_string vacation_balance_outdated "
select count(*)
from cc_users u,
im_employees e
where u.user_id = e.employee_id and
now()::date - vacation_balance_year >= 365 and
u.member_state = 'approved'
and e.employee_id in (
select member_id from group_distinct_member_map
where group_id in (select group_id from groups where group_name = 'Employees')
)
"]
if {$num_vacation_balance_outdated > 0} {
set vacation_balance_update_url [export_vars -base "/intranet-timesheet2/absences/vacation-balance-report.tcl" {return_url}]
set vacation_balance_update_msg "
<h3>Outdated 'Vacation Balances'</h3>
There are $num_vacation_balance_outdated users in the system with an outdated 'vacation balance'.<br>
Please <a href=$vacation_balance_update_url>click here</a> for a guided process to update the vacation balance.<br>
<br>&nbsp;<br>
"
}
# Only show to HR and admins
if {![im_permission $current_user_id "view_hr"]} { set vacation_balance_update_msg "" }
......@@ -29,12 +29,27 @@ foreach uid [array names vacation_balance] {
set new_vacation_balance $vacation_balance($uid)
set new_vacation_balance_year $vacation_balance_year($uid)
# Write Audit Trail before update, just in case
im_audit -object_id $uid -action before_update
# Backup the old value, just in case...
db_dml backup_old_balance "
update im_employees set
vacation_balance_backup_previous_year = vacation_balance
where employee_id = :uid
"
# Update the value and the date of the value
db_dml update_balance "
update im_employees set
vacation_balance = :new_vacation_balance,
vacation_balance_year = :new_vacation_balance_year::date
where employee_id = :uid
"
# Write Audit Trail after the update
im_audit -object_id $uid -action after_update
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment