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"
set cost_id [db_string costs_id_exist "select cost_id from im_costs where cost_type_id = [im_cost_type_timesheet] and project_id = :on_what_id and effective_date = to_date(:julian_date, 'J') and cause_object_id = :user_id" -default 0]
}
set cost_id [db_string costs_id_exist "
select
cost_id
from
im_costs
where
cost_type_id = [im_cost_type_timesheet]
and project_id = :project_id
and effective_date = to_date(:julian_date, 'J')
and cause_object_id = :user_id
" -default 0]
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 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 = :on_what_id" -default 0]
set customer_id [db_string customer_id "select company_id from im_projects where project_id = :project_id" -default 0]
# Update costs table
if {[db_table_exists im_costs]}{
# Update costs table
if {[db_table_exists im_costs]}{
db_dml cost_update "
update im_costs set
cost_name = :cost_name,
project_id = :on_what_id,
project_id = :project_id,
customer_id = :customer_id,
effective_date = to_date(:julian_date, 'J'),
amount = :billing_rate * cast(:hours_worked as numeric),