set hours_worked [string trim $hours($project_id)]
set project_id $project_ids($item_nr)
set note [string trim $notes($project_id)]
set note [string trim $notes($item_nr)]
set timesheet_task_id $timesheet_task_ids($item_nr)
if {"" == $project_id || 0 == $project_id}{
if {"" == $project_id || 0 == $project_id}{
ad_return_complaint 1 "Internal Error:<br>
ad_return_complaint 1 "Internal Error:<br>
There is an empty project_id for item \#$item_nr"
There is an empty project_id for item \#$project_id"
return
return
}
}
...
@@ -101,12 +101,10 @@ foreach item_nr $item_nrs {
...
@@ -101,12 +101,10 @@ foreach item_nr $item_nrs {
if {$hours_worked == 0 }{
if {$hours_worked == 0 }{
# Delete a timesheet entry
# Delete a timesheet entry
ns_log Notice "timesheet2-tasks/new-2: Delete timesheet entry for task_id=$timesheet_task_id"
ns_log Notice "timesheet2-tasks/new-2: Delete timesheet entry for project_id=$project_id"
db_dml hours_delete "
db_dml hours_delete "
delete from im_hours
delete from im_hours
where
where project_id = :project_id
project_id = :project_id
and timesheet_task_id = :timesheet_task_id
and user_id = :user_id
and user_id = :user_id
and day = to_date(:julian_date, 'J')
and day = to_date(:julian_date, 'J')
"
"
...
@@ -124,6 +122,9 @@ foreach item_nr $item_nrs {
...
@@ -124,6 +122,9 @@ foreach item_nr $item_nrs {
# Create or update a timesheet entry
# Create or update a timesheet entry
ns_log Notice "timesheet2-tasks/new-2: Create"
ns_log Notice "timesheet2-tasks/new-2: Create"
# Replace "," by "."
if {[regexp{([0-9]+)(\,([0-9]+))?}$hours_worked]}{
if {[regexp{([0-9]+)(\,([0-9]+))?}$hours_worked]}{
regsub ","$hours_worked "." hours_worked
regsub ","$hours_worked "." hours_worked
regsub "'"$hours_worked "." hours_worked
regsub "'"$hours_worked "." hours_worked
...
@@ -132,39 +133,6 @@ foreach item_nr $item_nrs {
...
@@ -132,39 +133,6 @@ foreach item_nr $item_nrs {
regsub ","$hours_worked "." hours_worked
regsub ","$hours_worked "." hours_worked
}
}
# Check if this entry is coming from a project without a
# timesheet task already defined:
if {"" == $timesheet_task_id || 0 == $timesheet_task_id}{
set timesheet_task_id [db_string existing_default_task "
select task_id
from im_timesheet_tasks_view
where project_id = :project_id
and task_nr = 'default'
" -default 0]
}
if {"" == $timesheet_task_id || 0 == $timesheet_task_id}{
# Create a default timesheet task for this project
set task_id [im_new_object_id]
set task_nr "default"
set task_name "Default Task"
set material_id [db_string default_material "select material_id from im_materials where material_nr='default'" -default 0]
if {!$material_id}{
ad_return_complaint 1 "Configuration Error:<br>Error during the creation of a default timesheet task for project \#$project_id: We couldn't find any default material with the material_nr 'default'. <br>Please inform your system administrator or contact Project/Open."
}
set cost_center_id ""
set uom_id [im_uom_hour]
set task_type_id [im_timesheet_task_type_standard]
set task_status_id [im_timesheet_task_status_active]
set description "Default task for timesheet logging convenience - please update"
db_exec_plsql task_insert ""
set timesheet_task_id $task_id
}
# Update the hours table
# Update the hours table
#
#
db_dml hours_update "
db_dml hours_update "
...
@@ -174,7 +142,6 @@ foreach item_nr $item_nrs {
...
@@ -174,7 +142,6 @@ foreach item_nr $item_nrs {
note = :note
note = :note
where
where
project_id = :project_id
project_id = :project_id
and timesheet_task_id = :timesheet_task_id
and user_id = :user_id
and user_id = :user_id
and day = to_date(:julian_date, 'J')
and day = to_date(:julian_date, 'J')
"
"
...
@@ -183,12 +150,12 @@ foreach item_nr $item_nrs {
...
@@ -183,12 +150,12 @@ foreach item_nr $item_nrs {
if {[db_resultrows] == 0 }{
if {[db_resultrows] == 0 }{
db_dml hours_insert "
db_dml hours_insert "
insert into im_hours (
insert into im_hours (
user_id, project_id, timesheet_task_id,
user_id, project_id,
day, hours,
day, hours,
billing_rate, billing_currency,
billing_rate, billing_currency,
note
note
) values (
) values (
:user_id, :project_id, :timesheet_task_id,
:user_id, :project_id,
to_date(:julian_date,'J'), :hours_worked,
to_date(:julian_date,'J'), :hours_worked,
:billing_rate, :billing_currency,
:billing_rate, :billing_currency,
:note
:note
...
@@ -199,8 +166,11 @@ foreach item_nr $item_nrs {
...
@@ -199,8 +166,11 @@ foreach item_nr $item_nrs {
db_dml update_timesheet_task ""
db_dml update_timesheet_task ""
ns_log Notice "timesheet2-tasks/new-2: Determine the cost-item related to task"
# Update costs table
set cost_id [db_string costs_id_exist "
if {[db_table_exists im_costs]}{
ns_log Notice "timesheet2-tasks/new-2: Determine the cost-item related to task"
set cost_id [db_string costs_id_exist "
select
select
min(cost_id)
min(cost_id)
from
from
...
@@ -208,20 +178,15 @@ foreach item_nr $item_nrs {
...
@@ -208,20 +178,15 @@ foreach item_nr $item_nrs {
where
where
cost_type_id = [im_cost_type_timesheet]
cost_type_id = [im_cost_type_timesheet]
and project_id = :project_id
and project_id = :project_id
and effective_date = to_date(:julian_date, 'J')
and effective_date = to_date(:julian_date, 'J')
and cause_object_id = :timesheet_task_id
" -default ""]
" -default ""]
set day [db_string day "select to_char(to_date(:julian_date, 'J'), :timesheet_log_date_format) from dual"]
set cost_name "$day$user_name"
if {"" == $cost_id}{
set cost_id [im_cost::new -cost_name $cost_name -cost_type_id [im_cost_type_timesheet]]
}
set customer_id [db_string customer_id "select company_id from im_projects where project_id = :project_id" -default 0]
set cost_name "$today$user_name"
if {"" == $cost_id}{
set cost_id [im_cost::new -cost_name $cost_name -cost_type_id [im_cost_type_timesheet]]
}
set customer_id [db_string customer_id "select company_id from im_projects where project_id = :project_id" -default 0]