Commit b09d4614 authored by Frank Bergmann's avatar Frank Bergmann

- Timesheet2 Workflow:

  Added feature to send our reminder emails to users with unsubmitted
  hours
parent 37fb75eb
......@@ -28,6 +28,11 @@
<parameter scope="instance" datatype="string" min_n_values="1" max_n_values="1" name="DefaultWorkflowKey" default="" description="Workflow-Key of the default Time Sheet Approval Workflow, for example 'timesheet_approval_wf'. Default is empty for no workflow."/>
<parameter scope="instance" datatype="string" min_n_values="1" max_n_values="1" name="ConfirmationPeriod" default="monthly" description="Show button to confirm hours on monthly or weekly basis. Value range: 'monthly' or 'weekly'"/>
<parameter scope="instance" datatype="number" min_n_values="1" max_n_values="1" name="ShowCommentsInPanel" default="0" description="Show comments made during the approval process. (Requires pg/sql function to be set in WF writing comments to table 'im_timesheet_conf_object')"/>
<parameter scope="instance" datatype="number" min_n_values="1" max_n_values="1" name="UnsubmittedHoursUserNotificationInterval" default="0" description="Should we send users with unconfirmed hours a reminder? Default is '0' in order to disable this feature. '86400' (the number of seconds per day) would remind users once per day, while '604800' would send our remindes once per week."/>
<parameter scope="instance" datatype="string" min_n_values="1" max_n_values="1" name="UnsubmittedHoursUserNotificationLimitToUserID" default="624" description="Should we limit the UnsubmittedHours user notification to some test/debugging users before starting to use this feature in production? This parameter accepts a space separated list of user_ids. Set this list to the empty string in order to enable production use. Default is '624' which is the ID of the 'System Administrator' account in most ]po[ systems."/>
</parameters>
</version>
</package>
ad_library {
Initialization for intranet-timesheet2-workflow module
@author Frank Bergmann (frank.bergmann@project-open.com)
@creation-date 16 January, 2014
@cvs-id $Id$
}
# Check for users with unsubmitted hours and send out notification emails
set interval [parameter::get_from_package_key -package_key intranet-timesheet2-workflow -parameter "UnsubmittedHoursUserNotificationInterval" -default 0]
if {0 != $interval} {
ad_schedule_proc -thread t $interval im_timesheet2_workflow_unsubmitted_hours_user_notification_sweeper
}
......@@ -362,3 +362,110 @@ ad_proc eval_wf_start_date {
return [dt_ansi_to_julian_single_arg "$date_part_year-$date_part_month-01"]
}
}
ad_proc im_timesheet2_workflow_unsubmitted_hours_user_notification_sweeper {
{-start_date ""}
{-debug_p 0}
} {
Sweeper process (executed by "cron" type of function, so it doesn't
have access to ad_form and other functions) that checks if users
have logged hours that are not yet submitted to a timesheet workflow.
} {
ns_log Notice "im_timesheet2_workflow_unsubmitted_hours_user_notification_sweeper: Starting"
set system_url [ad_parameter -package_id [ad_acs_kernel_id] SystemURL "" ""]
set system_owner [ad_parameter -package_id [ad_acs_kernel_id] SystemOwner "" [ad_system_owner]]
set start_date_sql ""
if {"" != $start_date} {
set start_date_sql "and h.day >= :start_date::date"
}
set limit_to_user_ids [parameter::get_from_package_key -package_key intranet-timesheet2-workflow -parameter "UnsubmittedHoursUserNotificationLimitToUserID" -default "624"]
set user_id_sql ""
if {"" != $limit_to_user_ids} {
set user_id_sql "and h.user_id in ([join $limit_to_user_ids ","])"
}
# Store all unconfirmed hours into some hash array.
set hour_sql "
select h.*,
p.email,
pe.first_names,
to_char(h.day, 'YYYY-MM-01') as hour_month
from im_hours h,
parties p,
persons pe
where h.user_id = p.party_id and
h.user_id = pe.person_id and
h.conf_object_id is null
$start_date_sql
$user_id_sql
order by
h.user_id, h.day
"
db_foreach hour_sql $hour_sql {
# Sum up unconfirmed hours per month
set key "$user_id-$hour_month"
set h 0
if {[info exists user_hour_month_hash($key)]} { set h $user_hour_month_hash($key) }
set h [expr $h + $hours]
set user_hour_month_hash($key) $h
# Sum up unconfirmed hours total
set key "$user_id"
set h 0
if {[info exists user_hour_hash($key)]} { set h $user_hour_hash($key) }
set h [expr $h + $hours]
set user_hour_hash($key) $h
# Store auxillary variables in their hashes
set user_email_hash($user_id) $email
set user_first_names_hash($user_id) $first_names
}
set user_hour_month_hash_keys [lsort [array names user_hour_month_hash]]
# Send out notification emails
foreach u [array names user_email_hash] {
set email $user_email_hash($u)
set first_names $user_first_names_hash($u)
set num_hours $user_hour_hash($u)
# Build a list of links for submitting hours
set link_list ""
foreach key $user_hour_month_hash_keys {
set user_hour_month_hash_uid [lindex [split $key "-"] 0]
set user_hour_month_hash_date [join [lrange [split $key "-"] 1 end] "-"]
# ad_return_complaint 1 "key=$key - $user_hour_month_hash_uid - $user_hour_month_hash_date"
if {$user_hour_month_hash_uid == $u} {
append link_list " [export_vars -base "$system_url/intranet-timesheet2/hours/index" {{date $user_hour_month_hash_date}}]\n"
}
}
set locale [lang::user::locale -user_id $u]
set subject [lang::message::lookup $locale intranet-timesheet2-workflow.Notification_Subject "Notification: Unsubmitted Hours"]
set message [lang::message::lookup $locale intranet-timesheet2-workflow.Notification_Subject \
"Dear %first_names%,\n\nThere are %num_hours% unsubmitted hours in your time sheet.\nPlease visit the following links and submit your hours.\n\n%link_list%\n\nThis message has been sent out automatically by \]project-open\[.
"]
if {$debug_p} {
ad_return_complaint 1 "<pre>email=$email<br>system_owner=$system_owner<br>subject=$subject<br>message=$message<br>"
} else {
if [catch {
ns_sendmail $email $system_owner $subject $message
} errmsg] {
ns_log Error "im_timesheet2_workflow_unsubmitted_hours_user_notification_sweeper: Error sending to \"$email\": $errmsg"
} else {
ns_log Notice "im_timesheet2_workflow_unsubmitted_hours_user_notification_sweeper: Sent mail to $email\n"
}
}
}
ns_log Notice "im_timesheet2_workflow_unsubmitted_hours_user_notification_sweeper: Finished"
}
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