Commit fa14ed5b authored by Frank Bergmann's avatar Frank Bergmann

- Added code to check absences for Timesheet2

parent 03631a5a
......@@ -70,6 +70,7 @@ ad_proc -public im_timesheet_home_component {user_id} {
set num_hours [hours_sum_for_user $user_id "" $num_days]
} err_msg] } {
set num_hours 0
ad_return_complaint 1 "<pre>$err_msg</pre>"
}
if { $num_hours < $expected_hours && $add_hours } {
......@@ -250,10 +251,15 @@ where
}
ad_proc hours_sum_for_user { user_id { project_id "" } { number_days "" } } {
ad_proc hours_sum_for_user { user_id { project_id "" } { number_days "7" } } {
Returns the total number of hours the specified user logged for
whatever else is included in the arg list
whatever else is included in the arg list.
Also counts absences with 8 hours.
} {
set hours_per_absence [parameter::get -package_id [im_package_timesheet2_id] -parameter "TimesheetHoursPerAbsence" -default 8]
# --------------------------------------------------------
# Count the number of hours in the last days.
set criteria [list "user_id=:user_id"]
if { ![empty_string_p $project_id] } {
......@@ -263,11 +269,31 @@ ad_proc hours_sum_for_user { user_id { project_id "" } { number_days "" } } {
lappend criteria "day >= to_date(to_char(sysdate,'yyyymmdd'),'yyyymmdd') - $number_days"
}
set where_clause [join $criteria "\n and "]
set num [db_string hours_sum \
"select sum(hours) from im_hours, dual where $where_clause"]
set num_hours [db_string hours_sum "
select sum(hours)
from im_hours, dual
where $where_clause
" -default 0]
if {"" == $num_hours} { set num 0}
if {"" == $num} { set num 0}
return $num
# --------------------------------------------------------
# Count the absences in the last days
set num_absences [db_string absences_sum "
select
count(*)
from
im_user_absences a,
im_day_enumerator(now()::date - '7'::integer, now()::date) d
where
owner_id = :user_id
and a.start_date <= d.d
and a.end_date >= d.d
" -default 0]
# ad_return_complaint 1 [expr $num_hours + $num_absences * $hours_per_absence]
return [expr $num_hours + $num_absences * $hours_per_absence]
}
ad_proc hours_sum { project_id {number_days ""} } {
......
......@@ -38,6 +38,13 @@
<a href=@different_date_url;noquote@>
#intranet-timesheet2.lt_Log_hours_for_a_diffe#
</a>
<li>
<a href=@absences_url;noquote@>
@absences_link_text@
</a>
<% if {[im_permission $user_id view_projects_all]} { %>
<li>
<a href=@different_project_url;noquote@>
......
......@@ -51,6 +51,11 @@ set different_date_url "index?[export_ns_set_vars url [list julian_date]]"
# "Log hours for a different project"
set different_project_url "other-projects?[export_url_vars julian_date]"
# Log Absences
set absences_url [export_vars -base "/intranet-timesheet2/absences/new" {return_url}]
set absences_link_text [lang::message::lookup "" intranet-timesheet2.Log_Absences "Log Absences"]
db_1row user_name_and_date "
select
im_name_from_user_id(user_id) as user_name,
......@@ -62,6 +67,67 @@ set page_title "[_ intranet-timesheet2.lt_Hours_for_pretty_date]"
set context_bar [im_context_bar [list index "[_ intranet-timesheet2.Hours]"] "[_ intranet-timesheet2.Add_hours]"]
# ---------------------------------------------------------
# Check for registered hours
# ---------------------------------------------------------
# These are the hours and notes captured from the intranet-timesheet2-task-popup
# modules, if it's there. The module allows the user to capture notes during the
# day on what task she is working.
array set popup_hours [list]
array set popup_notes [list]
set timesheet_popup_installed_p [db_table_exists im_timesheet_popups]
if {$timesheet_popup_installed_p} {
set timesheet_popup_sql "
select
p.log_time,
round(to_char(min(q.log_time) - p.log_time, 'HH24')::integer
+ to_char(min(q.log_time) - p.log_time, 'MI')::integer / 60.0
+ to_char(min(q.log_time) - p.log_time, 'SS')::integer / 3600.0
, 3) as log_hours,
p.task_id,
p.note
from
im_timesheet_popups p,
im_timesheet_popups q
where
1=1
and p.log_time::date = now()::date
and q.log_time::date = now()::date
and q.log_time > p.log_time
and p.user_id = :user_id
and q.user_id = :user_id
group by
p.log_time,
p.task_id,
p.note
order by
p.log_time
"
db_foreach timesheet_popup $timesheet_popup_sql {
set p_hours ""
if {[info exists popup_hours($task_id)]} { set p_hours $popup_hours($task_id) }
set p_notes ""
if {[info exists popup_notes($task_id)]} { set p_notes $popup_notes($task_id) }
append p_hours "[expr $log_hours+0]<br>"
if {"" != [string trim $note] && ![string equal "Timesheet" [string tolower $note]]} {
append p_notes "$note<br>"
}
set popup_hours($task_id) $p_hours
set popup_notes($task_id) $p_notes
}
}
# ad_return_complaint 1 [array get popup_hours]
# ---------------------------------------------------------
# Build the SQL Subquery, determining the (parent)
# projects to be displayed
......@@ -219,6 +285,15 @@ db_foreach $statement_name $sql {
set level [expr $level-1]
}
# These are the hours and notes captured from the intranet-timesheet2-task-popup
# modules, if it's there. The module allows the user to capture notes during the
# day on what task she is working.
set p_hours ""
set p_notes ""
if {[info exists popup_hours($task_id)]} { set p_hours $popup_hours($task_id) }
if {[info exists popup_notes($task_id)]} { set p_notes $popup_notes($task_id) }
# Insert intermediate header for every new project
if {$old_project_id != $project_id} {
......@@ -255,9 +330,7 @@ db_foreach $statement_name $sql {
<td>
<INPUT NAME=notes.$ctr size=60 value=\"[ns_quotehtml [value_if_exists note]]\">
</td>
</tr>
"
</tr>\n"
} else {
append results "
<td></td>
......@@ -290,9 +363,11 @@ db_foreach $statement_name $sql {
<td>$material_name</td>
<td>
<INPUT NAME=hours.$ctr size=5 MAXLENGTH=5 value=\"$hours\">
$p_hours
</td>
<td>
<INPUT NAME=notes.$ctr size=60 value=\"[ns_quotehtml [value_if_exists note]]\">
$p_notes
</td>
</tr>
"
......@@ -312,3 +387,5 @@ if { [empty_string_p $results] } {
}
set export_form_vars [export_form_vars julian_date return_url]
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