Commit b8c44cf5 authored by Frank Bergmann's avatar Frank Bergmann

Implemented warnings for attendance management

parent b712aecb
......@@ -57,7 +57,7 @@ set base_url_confirm_wf "/intranet-timesheet2-workflow/conf-objects/new-timeshee
set work_l10n [lang::message::lookup "" intranet-attendance-management.Work "Work"]
set break_l10n [lang::message::lookup "" intranet-attendance-management.Break "Break"]
set hour_l10n [lang::message::lookup "" intranet-core.Hour_abbrev "h"]
set hour_l10n [lang::message::lookup "" intranet-timesheet2.Hour_abbrev "h"]
switch $user_id_from_search {
"" - all - mine - direct_reports - employees - customers - providers {
......@@ -249,6 +249,22 @@ if {$attendance_management_installed_p} {
lappend v $list
set cell_hash($key) $v
}
# -----------------------------------------------------------
# Calculate link to Attendance management widget
if {[catch {
db_1row portlet_props "
select plugin_id, page_url
from im_component_plugins
where plugin_name = 'Attendance Management' and
package_name = 'intranet-attendance-management'
"
} err_msg]} {
ad_return_complaint 1 "<b>Error locating the attendance portlet</b>:
There is no portlet named 'Attendance Management' of package 'intranet-attendance-management'.<br>"
}
set attendance_portlet_url [export_vars -base $page_url {{view_name "component"} plugin_id}]
}
......@@ -294,6 +310,10 @@ if {1 == $start_day} {
set show_last_confirm_button_p 1
set timesheet_entry_blocked_p 0
set monthly_work_total 0.0
set monthly_break_total 0.0
set monthly_expected_total 0.0
# And now fill in information for every day of the month
for {set current_date $first_julian_date} {$current_date <= $last_julian_date} {incr current_date} {
......@@ -324,7 +344,7 @@ for {set current_date $first_julian_date} {$current_date <= $last_julian_date} {
# User's hours for the day
set hours ""
if {[info exists users_hours($current_date)] && $users_hours($current_date) ne ""} {
set hours "[lang::message::lookup "" intranet-timesheet2.Projects "Projects"]: $users_hours($current_date)[lang::message::lookup "" intranet-timesheet2.h "h"]"
set hours "[lang::message::lookup "" intranet-timesheet2.Projects "Projects"]: $users_hours($current_date)[lang::message::lookup "" intranet-timesheet2.Hour_abbrev "h"]"
set hours_for_this_week [expr {$hours_for_this_week + $users_hours($current_date)}]
# Sum today's hours to total month, if the month has actually started
......@@ -338,7 +358,7 @@ for {set current_date $first_julian_date} {$current_date <= $last_julian_date} {
set hours "<span class='log_hours'>[lang::message::lookup "" intranet-timesheet2.Nolog_Workflow_In_Progress "0 hours"] xxx </span>"
} else {
if {[string first $week_day $weekly_logging_days] != -1} {
set hours "<span class='log_hours'><nobr>[lang::message::lookup "" intranet-timesheet2.Projects "Projects"]: [lang::message::lookup "" intranet-timesheet2.Log_hours "Log hours"]</nobr></span>"
set hours "<span><nobr>[lang::message::lookup "" intranet-timesheet2.Projects "Projects"]: [lang::message::lookup "" intranet-timesheet2.Log_hours "Log hours"]</nobr></span>"
}
}
}
......@@ -399,65 +419,21 @@ for {set current_date $first_julian_date} {$current_date <= $last_julian_date} {
set html "${hours}${curr_absence}$log_hours_for_the_week_html"
}
# -------------------------------------------------------------------------
# Weekly total
if {($column_ctr == 7 || 0 && $current_date_ansi == $last_day_of_month_ansi) && $show_last_confirm_button_p} {
append html "<br>
<a href=[export_vars -base "week" {{julian_date $current_date} user_id_from_search}]
>[_ intranet-timesheet2.Week_total_1] [format "%.2f" [expr {double(round(100*$hours_for_this_week))/100}]]</a>
"
if {$current_date_ansi == $last_day_of_month_ansi} { set show_last_confirm_button_p 0 }
# Include link for weekly TS confirmation
# Monthly confirmation_period not supported yet, always assume weekly
# if {$confirmation_period eq "weekly" && $confirm_timesheet_hours_p} {}
if {$confirm_timesheet_hours_p} {
if {!$fill_up_first_last_row_p} {
set start_date_julian_wf [eval_wf_start_date $current_date $column_ctr]
set end_date_julian_wf $current_date
} else {
set start_date_julian_wf [expr {$current_date - 6}]
set end_date_julian_wf $current_date
}
set no_unconfirmed_hours [get_unconfirmed_hours_for_period $user_id_from_search $start_date_julian_wf $end_date_julian_wf]
if {$confirm_timesheet_hours_p && (0 < $no_unconfirmed_hours || "" != $no_unconfirmed_hours) && ("weekly" in $confirmation_period)} {
set conf_url [export_vars -base $base_url_confirm_wf {{user_id $user_id_from_search} {start_date_julian $start_date_julian_wf} {end_date_julian $end_date_julian_wf} return_url}]
set button_txt [lang::message::lookup "" intranet-timesheet2.Confirm_weekly_hours "Confirm hours for this week"]
append html "<p>&nbsp;</p><a href='$conf_url' class=button>$button_txt</a>"
}
}
}
# -------------------------------------------------------------------------
# Show monthly total
if {$current_date_ansi == $last_day_of_month_ansi} {
append html "<br>
<a href=[export_vars -base "month" {{julian_date $current_date} user_id_from_search}]
>[lang::message::lookup "" intranet-timesheet2.Month_total "Month total:"] [format "%.2f" [expr {double(round(100*$hours_for_this_month))/100}]]</a>
"
set monthly_total_url [export_vars -base "month" {{julian_date $current_date} user_id_from_search}]
set monthly_total_l10n [lang::message::lookup "" intranet-timesheet2.Project_month "Projects month"]
set monthly_total_pretty [format "%.2f" [expr round(100.0 * $hours_for_this_month)/100.0]]
append html "<br><a href=$monthly_total_url>$monthly_total_l10n: $monthly_total_pretty</a>"
}
# -------------------------------------------------------------------------
# Attendance Management
if {$attendance_management_installed_p} {
# Get the URL and the ID of the portlet in order to show a direct link
if {[catch {
db_1row portlet_props "
select plugin_id, page_url
from im_component_plugins
where plugin_name = 'Attendance Management' and
package_name = 'intranet-attendance-management'
"
} err_msg]} {
ad_return_complaint 1 "<b>Error locating the attendance portlet</b>:
There is no portlet named 'Attendance Management' of package 'intranet-attendance-management'.<br>"
}
set work_url [export_vars -base $page_url {{view_name "component"} plugin_id {julian $current_date}}]
# Calculate the actual work/break time
set work 0
if {[info exists att_work_hash($current_date)]} {
......@@ -467,10 +443,28 @@ for {set current_date $first_julian_date} {$current_date <= $last_julian_date} {
if {[info exists att_break_hash($current_date)]} {
set break [expr round(10.0 * $att_break_hash($current_date)) / 10.0]
}
# Hours to be expected for today
set expected_hours [im_attendance_daily_attendance_hours -user_id $current_user_id -date $current_date_ansi]
# Calculate the monthly sum of all three types of hours
set monthly_work_total [expr $monthly_work_total + $work]
if {"" ne $break} { set monthly_break_total [expr $monthly_break_total + $break] }
set monthly_expected_total [expr $monthly_expected_total + $expected_hours]
# -------------------------------------------------------------------------
# Comparison at the end of the month
if {$current_date_ansi == $last_day_of_month_ansi} {
if {$attendance_work < $monthly_expected_total} {
set font_html "color=red"
} else {
set font_html ""
}
append html "<br><font $font_html>Month work total: [expr round(10.0 * $attendance_work) / 10.0]${hour_l10n}, expected $monthly_expected_total${hour_l10n}</font>"
}
# Calculate color coding
# -------------------------------------------------------------------------
# Call consistency checker
set v [list]
......@@ -484,7 +478,9 @@ for {set current_date $first_julian_date} {$current_date <= $last_julian_date} {
# Write out lines for work and break
set line_items [list]
if {"" ne $work} {
lappend line_items "<nobr><a href=$work_url target=_>$color_html $work_l10n: ${work}${hour_l10n}$color_html_end</a></nobr>"
# Get the URL of a portlet with right julian date to enter attendances
set attendance_portlet_julian_url [export_vars -base $attendance_portlet_url {{julian $current_date}}]
lappend line_items "<nobr><a href=$attendance_portlet_julian_url target=_>$color_html $work_l10n: ${work}${hour_l10n}$color_html_end</a></nobr>"
}
if {"" ne $break} {
lappend line_items "<nobr>$break_l10n: ${break}${hour_l10n}</nobr>"
......@@ -498,13 +494,40 @@ for {set current_date $first_julian_date} {$current_date <= $last_julian_date} {
append html "<br>[join $line_items ",<br> "]"
}
# Comparison at the end of the month
if {$current_date_ansi == $last_day_of_month_ansi} {
append html "<br>Month work total: [expr round(10.0 * $attendance_work) / 10.0]${hour_l10n}"
}
}
# -------------------------------------------------------------------------
# Weekly total
if {($column_ctr == 7 || 0 && $current_date_ansi == $last_day_of_month_ansi) && $show_last_confirm_button_p} {
set weekly_total_url [export_vars -base "week" {{julian_date $current_date} user_id_from_search}]
set weekly_total_l10n [lang::message::lookup "" intranet-timesheet2.Project_week "Projects week"]
set weekly_total_pretty [format "%.2f" [expr round(100.0 * $hours_for_this_week)/100.0]]
append html "<br><a href=$weekly_total_url>$weekly_total_l10n: $weekly_total_pretty</a>"
if {$current_date_ansi == $last_day_of_month_ansi} { set show_last_confirm_button_p 0 }
# Include link for weekly TS confirmation
# Monthly confirmation_period not supported yet, always assume weekly
# if {$confirmation_period eq "weekly" && $confirm_timesheet_hours_p} {}
if {$confirm_timesheet_hours_p} {
if {!$fill_up_first_last_row_p} {
set start_date_julian_wf [eval_wf_start_date $current_date $column_ctr]
set end_date_julian_wf $current_date
} else {
set start_date_julian_wf [expr {$current_date - 6}]
set end_date_julian_wf $current_date
}
set no_unconfirmed_hours [get_unconfirmed_hours_for_period $user_id_from_search $start_date_julian_wf $end_date_julian_wf]
if {$confirm_timesheet_hours_p && (0 < $no_unconfirmed_hours || "" != $no_unconfirmed_hours) && ("weekly" in $confirmation_period)} {
set conf_url [export_vars -base $base_url_confirm_wf {{user_id $user_id_from_search} {start_date_julian $start_date_julian_wf} {end_date_julian $end_date_julian_wf} return_url}]
set button_txt [lang::message::lookup "" intranet-timesheet2.Confirm_weekly_hours "Confirm hours for this week"]
append html "<p>&nbsp;</p><a href='$conf_url' class=button>$button_txt</a>"
}
}
}
# -------------------------------------------------------------------------
# Monthly hour approval request
if {$current_date_ansi == $last_day_of_month_ansi && ("monthly" in $confirmation_period)} {
set start_date_month_julian [dt_ansi_to_julian_single_arg $first_day_of_month_ansi]
......
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