Commit 6fc551d5 authored by cosine's avatar cosine

- Creating a new absence:

  - Now calculating the duration days of the absence taking into account
    user for whom the absence is created
  - Calculate duration calculation: All arguments are now checked.
parent f45f1c28
......@@ -15,10 +15,25 @@ ad_page_contract {
} {
start_date
end_date
{ user_id:integer "" }
}
# Check that Start & End-Date have correct format
if {"" != $start_date && ![regexp {^[0-9][0-9][0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]$} $start_date]} {
doc_return 200 "text/html" "invalid"
ad_script_abort
}
if {"" != $end_date && ![regexp {^[0-9][0-9][0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]$} $end_date]} {
doc_return 200 "text/html" "invalid"
ad_script_abort
}
set current_user_id [auth::require_login]
set work_days [db_string days_in_period "select sum(unnest) / 100.0 from unnest(im_resource_mgmt_work_days(:current_user_id, :start_date::date, :end_date::date))"]
if {"" eq $user_id || 0 eq $user_id} { set user_id $current_user_id }
set work_days [db_string days_in_period "select sum(unnest) / 100.0 from unnest(im_resource_mgmt_work_days(:user_id, :start_date::date, :end_date::date))"]
if {"" eq $work_days} { set work_days "invalid" }
ns_log Notice "absence-duration.tcl: start=$start_date, end=$end_date -> $work_days"
......@@ -46,3 +61,4 @@ if {[regexp {^(.*)\.0$} $work_units match rounded_work_units]} {
doc_return 200 "text/html" "$work_units $work_units_uom_l10n"
......@@ -56,6 +56,8 @@ function calculateAbsenceDuration() {
var end_year = document.getElementById("end_date.year").value;
var end_date = end_year + '-' + end_month + '-' + end_day;
var owner_id = document.getElementById("absence:absence_owner_id:0").value;
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (debug) console.log('absences/new: readyState='+xmlHttp.readyState+', status='+xmlHttp.status+', responseText='+xmlHttp.responseText);
......@@ -70,7 +72,7 @@ function calculateAbsenceDuration() {
alert('Error processing server response from /intranet-timesheet2/absences/absence-duration:\n\n '+error);
}
}
xmlHttp.open("GET","/intranet-timesheet2/absences/absence-duration?start_date="+start_date+"&end_date="+end_date);
xmlHttp.open("GET","/intranet-timesheet2/absences/absence-duration?user_id="+owner_id+"&start_date="+start_date+"&end_date="+end_date);
xmlHttp.send(null);
if (debug) console.log('absences/new: Calculating absence duration: 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