Commit f9bd93f1 authored by stage's avatar stage
parents a7ef47ed 6cb381bc
# Temporary files
*.log
*.orig
*~
.\#*
.~*
\#*\#
# Helpers
emacs.bash
......@@ -134,7 +134,9 @@
<msg key="go">los</msg>
<msg key="Grand_Total">Gesamtsumme</msg>
<msg key="H">H</msg>
<msg key="h">h</msg>
<msg key="here">hier</msg>
<msg key="Hour_abbrev">h</msg>
<msg key="Hour_logging__Casex">Erfasste Stunden</msg>
<msg key="Hours">Stunden</msg>
<msg key="hours">Stunden</msg>
......@@ -166,7 +168,9 @@
<msg key="Log_Absences">Abwesenheiten melden</msg>
<msg key="Log_Absences_for_user_name">Abwesenheiten erfassen fr %user_name%</msg>
<msg key="log_dedication">Stunden erfassen</msg>
<msg key="Log_for_the_week">Fr die Woche loggen</msg>
<msg key="Log_Hours">Stunden erfassen</msg>
<msg key="Log_hours">Stunden loggen</msg>
<msg key="log_hours">Stunden fr den Tag erfassen</msg>
<msg key="Log_hours_for_the_week">Stunden fr die Woche erfassen</msg>
<msg key="Log_hours_for_user">Stunden fr Benutzer erfassen</msg>
......@@ -270,6 +274,7 @@
<msg key="Mine">Meine</msg>
<msg key="Monday">Montag</msg>
<msg key="Month">Monat</msg>
<msg key="Month_total">Monat gesamt</msg>
<msg key="More_currencies">Weitere Whrungen</msg>
<msg key="N">N</msg>
<msg key="Name">Name</msg>
......@@ -325,9 +330,12 @@
<msg key="Project">Projekt</msg>
<msg key="Project_br_Name">Projekt-&lt;br&gt;Name</msg>
<msg key="Project_History">Projekthistorie</msg>
<msg key="Project_month">Projekte Monat</msg>
<msg key="Project_name">Aufgabenname</msg>
<msg key="Project_Summaries">Projektzusammenfassung</msg>
<msg key="Project_units">Projekteinheiten</msg>
<msg key="Project_week">Projekte Woche</msg>
<msg key="Projects">Projekte</msg>
<msg key="Providers">Lieferanten</msg>
<msg key="Q">Q</msg>
<msg key="R">R</msg>
......
......@@ -137,7 +137,9 @@
<msg key="go">go</msg>
<msg key="Grand_Total">Grand Total</msg>
<msg key="H">H</msg>
<msg key="h">h</msg>
<msg key="here">here</msg>
<msg key="Hour_abbrev">h</msg>
<msg key="Hour_logging__Casex">Hour logging &amp; Casex</msg>
<msg key="Hours">Hours</msg>
<msg key="hours">hours</msg>
......@@ -169,7 +171,9 @@
<msg key="Log_Absences">Log Absences</msg>
<msg key="Log_Absences_for_user_name">Log absences for %user_name%</msg>
<msg key="log_dedication">log dedication</msg>
<msg key="Log_for_the_week">Log for the week</msg>
<msg key="Log_Hours">Log Hours</msg>
<msg key="Log_hours">Log hours</msg>
<msg key="log_hours">log hours</msg>
<msg key="Log_hours_for_the_week">Log hours for the week</msg>
<msg key="Log_hours_for_user">Log for:</msg>
......@@ -282,6 +286,7 @@ of those units were billed hourly, for a total amount of</msg>
<msg key="Mine">Mine</msg>
<msg key="Monday">Monday</msg>
<msg key="Month">Month</msg>
<msg key="Month_total">Month total</msg>
<msg key="More_currencies">More currencies</msg>
<msg key="N">N</msg>
<msg key="Name">Name</msg>
......@@ -337,9 +342,12 @@ of those units were billed hourly, for a total amount of</msg>
<msg key="Project">Project</msg>
<msg key="Project_br_Name">Project&lt;br&gt;Name</msg>
<msg key="Project_History">Project History</msg>
<msg key="Project_month">Projects month</msg>
<msg key="Project_name">Project name</msg>
<msg key="Project_Summaries">Project Summaries</msg>
<msg key="Project_units">Project units</msg>
<msg key="Project_week">Projects week</msg>
<msg key="Projects">Projects</msg>
<msg key="Providers">Providers</msg>
<msg key="Q">Q</msg>
<msg key="R">R</msg>
......
......@@ -288,12 +288,17 @@ ad_proc -public im_timesheet_home_component {user_id} {
set expected_hours [parameter::get -package_id [im_package_timesheet2_id] -parameter "TimesheetRedirectNumHoursInDays" -default 32]
set available_perc [util_memoize [list db_string percent_available "select availability from im_employees where employee_id = $user_id" -default 100] 60]
if {"" == $available_perc} { set available_perc 100 }
set expected_hours [expr {$expected_hours * $available_perc / 100}]
set expected_hours [expr $expected_hours * $available_perc / 100]
set hours_html ""
set log_them_now_link "<a href=/intranet-timesheet2/hours/index>"
set num_hours [im_timesheet_hours_sum -user_id $user_id -number_days $num_days]
set absences_hours [im_timesheet_absences_sum -user_id $user_id -number_days $num_days]
set absence_hours [im_timesheet_absences_sum -user_id $user_id -number_days $num_days]
set absences_hours_message ""
if {$absence_hours > 0} {
set absences_hours_message [lang::message::lookup "" intranet-timesheet2.and_absence_hours "and %absence_hours% hours of absences"]
}
if {$num_hours == 0} {
set message "<b>[_ intranet-timesheet2.lt_You_havent_logged_you]</a></b>\n"
......@@ -301,20 +306,15 @@ ad_proc -public im_timesheet_home_component {user_id} {
set message "[_ intranet-timesheet2.lt_You_logged_num_hours_]"
}
set absences_hours_message ""
if { [expr {$num_hours + $absences_hours}] < $expected_hours && $add_hours } {
if {[expr $num_hours + $absence_hours] < $expected_hours && $add_hours} {
if {$absences_hours > 0} {
set absences_hours_message [lang::message::lookup "" \
intranet-timesheet2.and_absences_hours \
"and %absences_hours% hours of absences"]
}
set default_message "
You have only logged %num_hours% hours %absences_hours_message%
in the last %num_days% days out of %expected_hours% expected hours.
You have only logged $num_hours hours of project work $absences_hours_message
in the last $num_days days out of $expected_hours expected hours.
"
set message "<b>[lang::message::lookup "" intranet-timesheet2.You_need_to_log_hours $default_message]</b>"
# Only redirect if it's not the admin...
if {$redirect_p && !$admin_p} {
set header [lang::message::lookup "" intranet-timesheet2.Please_Log_Your_Hours "Please Log Your Hours"]
ad_returnredirect [export_vars -base "/intranet-timesheet2/hours/index" {header message}]
......
......@@ -15,7 +15,7 @@
ad_page_contract {
Calendar format display of user's hours with links
Calendar format display of user's hours with links
to log more hours, if the user is looking at him/
herself
......@@ -25,7 +25,7 @@ ad_page_contract {
@param user_id the user for whom we're viewing hours. Defaults to currently logged in user.
@param project_id The user group for which we're viewing hours. Defaults to all groups.
@param return_url Return URL
@author Michael Bryzek (mbryzek@arsdigita.com)
@author Frank Bergmann (frank.bergmann@project-open.com)
@author Klaus Hofeditz (klaus.hofeditz@project-open.com)
......@@ -41,7 +41,7 @@ ad_page_contract {
}
# Decision FB on 160624: Disregard for now:
# Clean up data in case WF cases have been OCdeleted in WF Admin Panel.
# Clean up data in case WF cases have been deleted in WF Admin Panel.
# conf_object will not be removed and hours are shown as 'to be confirmed'.
# db_dml sql "update im_hours set conf_object_id = null where conf_object_id not in (select object_id from wf_cases)"
# db_dml sql "delete from im_timesheet_conf_objects where conf_id not in (select object_id from wf_cases)"
......@@ -55,9 +55,13 @@ set add_hours_all_p [im_permission $current_user_id "add_hours_all"]
set add_hours_direct_reports_p [im_permission $current_user_id "add_hours_direct_reports"]
set base_url_confirm_wf "/intranet-timesheet2-workflow/conf-objects/new-timesheet-workflow"
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-timesheet2.Hour_abbrev "h"]
switch $user_id_from_search {
"" - all - mine - direct_reports - employees - customers - providers {
set user_id_from_search $current_user_id
"" - all - mine - direct_reports - employees - customers - providers {
set user_id_from_search $current_user_id
}
default {
# Is the user allowed to log hours for another user?
......@@ -66,11 +70,11 @@ switch $user_id_from_search {
set reportees [im_user_direct_reports_ids -user_id $current_user_id]
if {[lsearch $reportees $user_id_from_search] < 0} {
# User not in reportees - reset to current user
set user_id_from_search $current_user_id
set user_id_from_search $current_user_id
}
} else {
# The user has no permission to log hours for others
set user_id_from_search $current_user_id
set user_id_from_search $current_user_id
}
}
}
......@@ -98,29 +102,28 @@ set fill_up_first_last_row_p [parameter::get -package_id [apm_package_id_from_ke
set start_day [parameter::get -package_id [apm_package_id_from_key intranet-timesheet2] -parameter "WeekStartDay" -default 0]
set show_link_log_hours_for_week_p [parameter::get -package_id [apm_package_id_from_key intranet-timesheet2] -parameter "ShowLinkToWeeklyTimesheetP" -default 0]
set hours_base_url [parameter::get -package_id [apm_package_id_from_key intranet-timesheet2] -parameter "HourURL" -default "/intranet-timesheet2/hours"]
set attendance_management_installed_p [im_table_exists im_attendance_intervals]
set header_days_of_week "";
# Patch: http://sourceforge.net/projects/project-open/forums/forum/295937/topic/3324310
for { set i $start_day } { $i < 7 } { incr i } {
if { $i ==0 } { append header_days_of_week "[_ intranet-timesheet2.Sunday] " }
if { $i ==1 } { append header_days_of_week "[_ intranet-timesheet2.Monday] " }
if { $i ==2 } { append header_days_of_week "[_ intranet-timesheet2.Tuesday] " }
if { $i ==3 } { append header_days_of_week "[_ intranet-timesheet2.Wednesday] " }
if { $i ==4 } { append header_days_of_week "[_ intranet-timesheet2.Thursday] " }
if { $i ==5 } { append header_days_of_week "[_ intranet-timesheet2.Friday] " }
if { $i ==6 } { append header_days_of_week "[_ intranet-timesheet2.Saturday] " }
for {set i $start_day} {$i < 7} {incr i} {
if {$i == 0} { append header_days_of_week "[_ intranet-timesheet2.Sunday] " }
if {$i == 1} { append header_days_of_week "[_ intranet-timesheet2.Monday] " }
if {$i == 2} { append header_days_of_week "[_ intranet-timesheet2.Tuesday] " }
if {$i == 3} { append header_days_of_week "[_ intranet-timesheet2.Wednesday] " }
if {$i == 4} { append header_days_of_week "[_ intranet-timesheet2.Thursday] " }
if {$i == 5} { append header_days_of_week "[_ intranet-timesheet2.Friday] " }
if {$i == 6} { append header_days_of_week "[_ intranet-timesheet2.Saturday] " }
}
for { set i 0 } { $i < $start_day } { incr i } {
if { $i ==0 } { append header_days_of_week "[_ intranet-timesheet2.Sunday] " }
if { $i ==1 } { append header_days_of_week "[_ intranet-timesheet2.Monday] " }
if { $i ==2 } { append header_days_of_week "[_ intranet-timesheet2.Tuesday] " }
if { $i ==3 } { append header_days_of_week "[_ intranet-timesheet2.Wednesday] " }
if { $i ==4 } { append header_days_of_week "[_ intranet-timesheet2.Thursday] " }
if { $i ==5 } { append header_days_of_week "[_ intranet-timesheet2.Friday] " }
if { $i ==6 } { append header_days_of_week "[_ intranet-timesheet2.Saturday] " }
for {set i 0} {$i < $start_day} {incr i} {
if {$i == 0} { append header_days_of_week "[_ intranet-timesheet2.Sunday] " }
if {$i == 1} { append header_days_of_week "[_ intranet-timesheet2.Monday] " }
if {$i == 2} { append header_days_of_week "[_ intranet-timesheet2.Tuesday] " }
if {$i == 3} { append header_days_of_week "[_ intranet-timesheet2.Wednesday] " }
if {$i == 4} { append header_days_of_week "[_ intranet-timesheet2.Thursday] " }
if {$i == 5} { append header_days_of_week "[_ intranet-timesheet2.Friday] " }
if {$i == 6} { append header_days_of_week "[_ intranet-timesheet2.Saturday] " }
}
set weekly_logging_days [parameter::get_from_package_key -package_key intranet-timesheet2 -parameter TimesheetWeeklyLoggingDays -default "0 1 2 3 4 5 6"]
......@@ -128,20 +131,21 @@ set weekly_logging_days [parameter::get_from_package_key -package_key intranet-t
# ---------------------------------
# Date Logic: We are working with "YYYY-MM-DD" dates in this page.
if {"" == $date } {
if {"" == $date} {
if {"" != $julian_date} {
set date [db_string julian_date_select "select to_char( to_date(:julian_date,'J'), 'YYYY-MM-DD') from dual"]
set date [db_string julian_date_select "select to_char(to_date(:julian_date,'J'), 'YYYY-MM-DD') from dual"]
} else {
set date [db_string ansi_date_select "select to_char( sysdate, 'YYYY-MM-DD') from dual"]
set date [db_string ansi_date_select "select to_char(sysdate, 'YYYY-MM-DD') from dual"]
}
}
set julian_date [db_string conv "select to_char(:date::date, 'J')"]
# Set last day of month:
# Set last day of month:
set last_day_of_month_ansi [db_string get_last_day_month "select date_trunc('month',add_months(:date,1))::date - 1" -default 0]
set first_day_of_month_ansi [db_string get_first_day_month "select date_trunc('month', '$date'::DATE)::date" -default 0]
set first_day_of_month_julian [db_string fdom_julian "select to_char(:first_day_of_month_ansi::date, 'J')"]
set today_ansi [db_string today "select now()::date"]
set project_id_for_default [lindex $project_id 0]
set show_left_functional_menu_p [parameter::get_from_package_key -package_key "intranet-core" -parameter "ShowLeftFunctionalMenupP" -default 0]
......@@ -160,12 +164,15 @@ set menu_links_html [im_menu_ul_list -no_uls 1 "timesheet_hours_new_admin" $bind
# Enable the functionality to confirm timesheet hours?
set confirm_timesheet_hours_p 0
if { "" != [parameter::get -package_id [apm_package_id_from_key intranet-timesheet2-workflow] -parameter "DefaultWorkflowKey" -default ""] } {
if {"" != [parameter::get -package_id [apm_package_id_from_key intranet-timesheet2-workflow] -parameter "DefaultWorkflowKey" -default ""]} {
set confirm_timesheet_hours_p 1
}
if {![im_column_exists im_hours conf_object_id]} { set confirm_timesheet_hours_p 0 }
# Rounding by two digits
set rounding_factor 100.0
# ---------------------------------------------------------------
# Render the Calendar widget
......@@ -175,24 +182,111 @@ set calendar_details [ns_set create calendar_details]
# figure out the first and last julian days in the month
# This call defines a whole set of variables in our environment
calendar_get_info_from_db $date
# ---------------------------------------------------------------
# Attendance Management
# ---------------------------------------------------------------
if {$attendance_management_installed_p} {
set attendance_sql "
select ai.*,
to_char(ai.attendance_start, 'YYYY-MM-DD') as attendance_start_date,
to_char(ai.attendance_start, 'J') as attendance_start_julian,
im_category_from_id(ai.attendance_type_id) as type,
round((extract(epoch from attendance_end - attendance_start) / 3600)::numeric, 2) as duration_hours,
coalesce(EXTRACT(EPOCH FROM ai.attendance_end - ai.attendance_start) / 3600, 0) as attendance_duration_hours,
(select sum(hours) from im_hours h where h.user_id = :user_id_from_search and h.day::date = ai.attendance_start::date) as ts_sum_per_user_day
from im_attendance_intervals ai
where ai.attendance_user_id = :user_id_from_search and
ai.attendance_start::date >= to_date(:first_julian_date, 'J') and
ai.attendance_end is not null and -- discard elements in process of completing
ai.attendance_end::date <= to_date(:last_julian_date, 'J')
order by
ai.attendance_start
"
set attendance_work 0.0
set attendance_break 0.0
db_foreach attendances $attendance_sql {
# -----------------------------------------------------------
# Sum up all attendances for all days of that month and store into att_work_hash and att_break_hash
set att_type [string tolower $type]
switch $attendance_type_id {
92100 {
# Work Attendance
set v 0.0
if {[info exists att_work_hash($attendance_start_julian)]} { set v $att_work_hash($attendance_start_julian)}
set v [expr $v + $duration_hours]
set att_work_hash($attendance_start_julian) $v
set attendance_work [expr $attendance_work + $duration_hours;]
}
92110 {
# Break
set v 0.0
if {[info exists att_break_hash($attendance_start_julian)]} { set v $att_break_hash($attendance_start_julian)}
set v [expr $v + $duration_hours]
set att_break_hash($attendance_start_julian) $v
set attendance_break [expr $attendance_break + $duration_hours;]
}
}
# -----------------------------------------------------------
# Check for consistence: Create a list of atts for each $key order by attendance_start
# Aggregate attendance data per day and user
# cell_hash: Temporary hash with the ordered list of attendances per day
# error_hash: List of all errors in atts per day
set key "$attendance_start_julian"
set v [list]
if {[info exists cell_hash($key)]} { set v $cell_hash($key) }
# Write attendance data into hash-list
set list [list]
set vars {attendance_id attendance_type_id attendance_start_date attendance_start attendance_end attendance_duration_hours ts_sum_per_user_day}
foreach var $vars { lappend list $var [set $var] }
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}]
}
# ad_return_complaint 1 "<pre>[join [array get cell_hash] "\n"]\n\n\n[array get error_hash]</pre>"
# --------------------------------------------------------------
# Grab all the hours from im_hours
set sql "
select to_char(day, 'J') as julian_date,
select to_char(day, 'J') as julian_date,
sum(hours) as hours
from im_hours
where user_id = :user_id_from_search
and day between to_date(:first_julian_date, 'J') and to_date(:last_julian_date, 'J')
and day between to_date(:first_julian_date, 'J') and to_date(:last_julian_date, 'J')
$project_restriction
group by
group by
to_char(day, 'J')
"
db_foreach hours_logged $sql {
set users_hours($julian_date) $hours
}
db_foreach hours_logged $sql { set users_hours($julian_date) $hours }
# --------------------------------------------------------------
# Render the calendar
......@@ -200,54 +294,61 @@ db_foreach hours_logged $sql {
set hours_for_this_week 0.0
set hours_for_this_month 0.0
set unconfirmed_hours_for_this_week 0.0
set unconfirmed_hours_for_this_month 0.0
set absence_list [absence_list_for_user_and_time_period $user_id_from_search $first_julian_date $last_julian_date]
set absence_index 0
set curr_absence ""
# Column counter runs from 1 to 7
# Column counter runs from 1 to 7
set column_ctr 1
# Counter for weekday -> need to correspond with weekly_logging_days
if { 1 == $start_day } {
# Week starts with Monday
set week_day 1
if {1 == $start_day} {
# Week starts with Monday
set week_day 1
} else {
# Week starts with Sunday
set week_day 0
# Week starts with Sunday
set week_day 0
}
# Helper to determine location of last WF confirm button -> last day shown or last day of month
# Helper to determine location of last WF confirm button -> last day shown or last day of month
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 } {
set current_date_ansi [dt_julian_to_ansi $current_date]
for {set current_date $first_julian_date} {$current_date <= $last_julian_date} {incr current_date} {
# -------------------------------------------------------------------------
# Setup base variables
set current_date_ansi [dt_julian_to_ansi $current_date]
# Unconfirmed hours in workflow
if {![info exists unconfirmed_hours($current_date)]} { set unconfirmed_hours($current_date) "" }
if {"" == $unconfirmed_hours($current_date)} { set unconfirmed_hours($current_date) 0 }
if { $confirm_timesheet_hours_p } {
if {$confirm_timesheet_hours_p} {
set no_ts_approval_wf_sql "
select count(*)
from im_hours
where conf_object_id is not null
and day::text like '%[string range $current_date_ansi 0 9]%'
select count(*)
from im_hours
where conf_object_id is not null
and day::text like '%[string range $current_date_ansi 0 9]%'
and user_id = :current_user_id
"
set no_ts_approval_wf [db_string workflow_started_p $no_ts_approval_wf_sql -default "0"]
if {$confirm_timesheet_hours_p && ("monthly" in $confirmation_period || "weekly" in $confirmation_period) && 0 != $no_ts_approval_wf } {
if {$confirm_timesheet_hours_p && ("monthly" in $confirmation_period || "weekly" in $confirmation_period) && 0 != $no_ts_approval_wf} {
# ns_log Notice "TS: Entry blocked: Date: $current_date_ansi; Number: $no_ts_approval_wf; $no_ts_approval_wf_sql"
set timesheet_entry_blocked_p 1
set timesheet_entry_blocked_p 1
}
}
# -------------------------------------------------------------------------
# User's hours for the day
set hours ""
if { [info exists users_hours($current_date)] && $users_hours($current_date) ne "" } {
set hours "$users_hours($current_date) [lang::message::lookup "" intranet-timesheet2.hours "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.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
......@@ -255,48 +356,43 @@ for { set current_date $first_julian_date} { $current_date <= $last_julian_date
if {$current_date >= $first_day_of_month_julian} {
set hours_for_this_month [expr {$hours_for_this_month + $users_hours($current_date)}]
}
} else {
if { $timesheet_entry_blocked_p } {
set hours "<span class='log_hours'>[lang::message::lookup "" intranet-timesheet2.Nolog_Workflow_In_Progress "0 hours"]</span>"
if {$timesheet_entry_blocked_p} {
# Fraber 2023-12-12: I'm quite sure that is unreachable code, because there are no hours for that day.
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'>[_ intranet-timesheet2.log_hours]</span>"
if {[string first $week_day $weekly_logging_days] != -1} {
set hours "<span><nobr>[lang::message::lookup "" intranet-timesheet2.Projects "Projects"]: [lang::message::lookup "" intranet-timesheet2.Log_hours "Log hours"]</nobr></span>"
}
}
}
if {![info exists unconfirmed_hours($current_date)]} { set unconfirmed_hours($current_date) "" }
if {"" == $unconfirmed_hours($current_date)} { set unconfirmed_hours($current_date) 0 }
# Sum up unconfirmed_hours - KH: 160624: This might be broken and it seems that vars are not being used.
set unconfirmed_hours_for_this_week [expr {$unconfirmed_hours_for_this_week + $unconfirmed_hours($current_date)}]
set unconfirmed_hours_for_this_month [expr {$unconfirmed_hours_for_this_month + $unconfirmed_hours($current_date)}]
# User's Absences for the day
set curr_absence [lindex $absence_list $absence_index]
if {"" != $curr_absence} { set curr_absence "<br>$curr_absence" }
set hours_url [export_vars -base "$hours_base_url/new" {user_id_from_search {julian_date $current_date} show_week_p return_url project_id project_id}]
if { [string first $week_day $weekly_logging_days] != -1 } {
if {[string first $week_day $weekly_logging_days] != -1} {
set hours "<a href=$hours_url>$hours</a>"
} else {
set hours "$hours"
}
if {$column_ctr == 1 && $show_link_log_hours_for_week_p } {
if {$column_ctr == 1 && $show_link_log_hours_for_week_p} {
set log_hours_for_the_week_html "<br>
<nobr>
<a href=[export_vars -base "$hours_base_url/new" {user_id_from_search {julian_date $current_date} {show_week_p 1} return_url}]
><span class='log_hours'>[lang::message::lookup "" intranet-timesheet2.Log_hours_for_the_week "Log hours for the week"]</span></a>
><span class='log_hours'>[lang::message::lookup "" intranet-timesheet2.Projects "Projects"]:
[lang::message::lookup "" intranet-timesheet2.Log_for_the_week "Log for the week"]</span></a></nobr>
"
} else {
set log_hours_for_the_week_html ""
}
if { [info exists users_hours($current_date)] } {
if { [info exists unconfirmed_hours($current_date)] && $confirm_timesheet_hours_p } {
set no_unconfirmed_hours [get_unconfirmed_hours_for_period $user_id_from_search $current_date $current_date]
if {[info exists users_hours($current_date)]} {
if {[info exists unconfirmed_hours($current_date)] && $confirm_timesheet_hours_p} {
set no_unconfirmed_hours [get_unconfirmed_hours_for_period $user_id_from_search $current_date $current_date]
if {0 == $no_unconfirmed_hours || "" == $no_unconfirmed_hours} {
set wf_actice_case_sql "
select count(*)
......@@ -307,16 +403,16 @@ for { set current_date $first_julian_date} { $current_date <= $last_julian_date
h.user_id = :user_id_from_search
"
set no_wf_cases [db_string no_wf_cases $wf_actice_case_sql]
if { $no_wf_cases > 0 } {
if {$no_wf_cases > 0} {
set html "<span id='hours_confirmed_yellow'>$hours</span>$curr_absence$log_hours_for_the_week_html"
} else {
set html "<span id='hours_confirmed_green'>$hours</span>$curr_absence$log_hours_for_the_week_html"
}
} else {
set html "${hours}${curr_absence}<br>"
set html "${hours}${curr_absence}<br>"
if {$confirm_timesheet_hours_p} {
append html "[lang::message::lookup "" intranet-timesheet2.ToConfirm "To confirm"]:&nbsp;"
append html "<span id='hours_confirmed_red'>${no_unconfirmed_hours}&nbsp;[_ intranet-timesheet2.hours]</span>"
append html "<nobr>[lang::message::lookup "" intranet-timesheet2.ToConfirm "To confirm"]:&nbsp;"
append html "<span id='hours_confirmed_red'>${no_unconfirmed_hours}&nbsp;[_ intranet-timesheet2.hours]</span></nobr>"
}
append html "$log_hours_for_the_week_html"
}
......@@ -326,72 +422,146 @@ for { set current_date $first_julian_date} { $current_date <= $last_julian_date
} else {
set html "${hours}${curr_absence}$log_hours_for_the_week_html"
}
# -------------------------------------------------------------------------
# Show monthly total
if {$current_date_ansi == $last_day_of_month_ansi} {
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} {
# Calculate the actual work/break time
set work 0
if {[info exists att_work_hash($current_date)]} {
set work [expr round($rounding_factor * $att_work_hash($current_date)) / $rounding_factor]
}
set break ""
if {[info exists att_break_hash($current_date)]} {
set break [expr round($rounding_factor * $att_break_hash($current_date)) / $rounding_factor]
}
# Hours to be expected for today
set expected_hours [im_attendance_daily_attendance_hours -user_id $current_user_id -date $current_date_ansi]
if {$current_date_ansi < $first_day_of_month_ansi} { set expected_hours 0.0 }
if {$current_date_ansi > $last_day_of_month_ansi} { set expected_hours 0.0 }
if {$current_date_ansi > $today_ansi} { set expected_hours 0.0 }
# 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]
ns_log Notice "intranet-timesheet2/hours/index: date=$current_date_ansi, expected=$expected_hours, xxx"
# -------------------------------------------------------------------------
# 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($rounding_factor * $attendance_work) / $rounding_factor]${hour_l10n}, expected $monthly_expected_total${hour_l10n}</font>"
}
# -------------------------------------------------------------------------
# Call consistency checker
set v [list]
if {[info exists cell_hash($current_date)]} { set v $cell_hash($current_date) }
ns_log Notice "timesheet2/index: Before im_attendance_check_consistency: $v"
set attendance_errors [im_attendance_check_consistency -user_id $user_id_from_search -date $current_date_ansi -attendance_hashs $v]
set color_html ""
set color_html_end ""
# Write out lines for work and break
set line_items [list]
if {"" ne $work} {
# 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}}]
set work_formatted [format "%.2f" $work]
lappend line_items "<nobr><a href=$attendance_portlet_julian_url target=_>$color_html $work_l10n: ${work_formatted}${hour_l10n}$color_html_end</a></nobr>"
}
if {"" ne $break} {
set break_formatted [format "%.2f" $break]
lappend line_items "<nobr>$break_l10n: ${break_formatted}${hour_l10n}</nobr>"
}
# ds_comment "$column_ctr, current_date_ansi: $current_date_ansi, last_day_of_month_ansi: $last_day_of_month_ansi, show_last_confirm_button_p: $show_last_confirm_button_p"
if {[llength $attendance_errors] > 0} {
lappend line_items "<font color=red><ul><li>[join $attendance_errors "</li>\n<li>"]</ul></font></div"
}
if {[llength $line_items] > 0} {
append html "<br>[join $line_items ",<br> "]"
}
}
# -------------------------------------------------------------------------
# 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 {($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 }
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 {$confirmation_period eq "weekly" && $confirm_timesheet_hours_p} {}
if {$confirm_timesheet_hours_p} {
if { !$fill_up_first_last_row_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 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}]
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>
"
}
# -------------------------------------------------------------------------
# Monthly hour approval request
if { $current_date_ansi == $last_day_of_month_ansi && ("monthly" in $confirmation_period) } {
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]
set end_date_month_julian [dt_ansi_to_julian_single_arg $last_day_of_month_ansi]
set conf_url [export_vars -base $base_url_confirm_wf { {user_id $user_id_from_search} {start_date_julian $start_date_month_julian } {end_date_julian $end_date_month_julian} return_url } ]
set conf_url [export_vars -base $base_url_confirm_wf {{user_id $user_id_from_search} {start_date_julian $start_date_month_julian} {end_date_julian $end_date_month_julian} return_url} ]
set button_txt [lang::message::lookup "" intranet-timesheet2.Confirm_monthly_hours "Confirm hours for this month"]
append html "<p>&nbsp;</p><a href='$conf_url' class=button>$button_txt</a>"
}
}
ns_set put $calendar_details $current_date "$html<br>&nbsp;"
# we keep track of the day of the week we are on
incr column_ctr
incr week_day
incr week_day
if { $column_ctr > 7 } {
if {$column_ctr > 7} {
set column_ctr 1
set hours_for_this_week 0.0
set unconfirmed_hours_for_this_week 0.0
}
# Weekday needs to be in range [0..6]
if { $week_day > 6 } {
set week_day 0
if {$week_day > 6} {
set week_day 0
}
set curr_absence ""
......@@ -400,14 +570,14 @@ for { set current_date $first_julian_date} { $current_date <= $last_julian_date
}
set prev_month_template "
<font color=white>&lt;</font>
<font color=white>&lt;</font>
<a href=\"[export_vars -base index {user_id_from_search}]&date=\$ansi_date\">
<font color=white>\[_ intranet-timesheet2.$prev_month_name] </font>
</a>"
set next_month_template "
<a href=\"[export_vars -base index {user_id_from_search}]&date=\$ansi_date\">
<font color=white>\[_ intranet-timesheet2.$next_month_name]</font>
</a>
</a>
<font color=white>&gt;</font>"
set day_bgcolor "#efefef"
......@@ -461,7 +631,7 @@ set left_navbar_html "
</div>
<form action='$hours_base_url/index' method=GET>
[export_vars -form {show_week_p}]
[export_vars -form {show_week_p}]
<table border=0 cellpadding=1 cellspacing=1>
<tr>
<td>[lang::message::lookup "" intranet-core.Date "Date"]</td>
......@@ -544,4 +714,3 @@ if {"" ne $admin_html} {
</div><ul>$admin_html</ul></div>
"
}
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