Commit 98a845e5 authored by Frank Bergmann's avatar Frank Bergmann

- Started migrating reported_units_chache from

  im_timesheet_tasks to im_projects.reported_hours_cache
parent 8bb8d8bd
...@@ -50,6 +50,13 @@ create index im_hours_day_idx on im_hours(day); ...@@ -50,6 +50,13 @@ create index im_hours_day_idx on im_hours(day);
-- Add the sum of timesheet hours cached here for reporting
-- to the im_projects table
--
alter table im_projects add reported_hours_cache float;
------------------------------------------------------ ------------------------------------------------------
-- Permissions and Privileges -- Permissions and Privileges
-- --
...@@ -79,6 +86,86 @@ select im_priv_create('view_hours_all', 'Sales'); ...@@ -79,6 +86,86 @@ select im_priv_create('view_hours_all', 'Sales');
select im_priv_create('view_hours_all', 'Senior Managers'); select im_priv_create('view_hours_all', 'Senior Managers');
create or replace function inline_0 ()
returns integer as '
declare
-- Menu IDs
v_menu integer; v_parent_menu integer;
-- Groups
v_employees integer; v_accounting integer;
v_senman integer; v_customers integer;
v_freelancers integer; v_proman integer;
v_admins integer;
BEGIN
select group_id into v_admins from groups where group_name = ''P/O Admins'';
select group_id into v_senman from groups where group_name = ''Senior Managers'';
select group_id into v_proman from groups where group_name = ''Project Managers'';
select group_id into v_accounting from groups where group_name = ''Accounting'';
select group_id into v_employees from groups where group_name = ''Employees'';
select group_id into v_customers from groups where group_name = ''Customers'';
select group_id into v_freelancers from groups where group_name = ''Freelancers'';
select menu_id into v_parent_menu
from im_menus where label=''main'';
v_menu := im_menu__new (
null, -- p_menu_id
''acs_object'', -- object_type
now(), -- creation_date
null, -- creation_user
null, -- creation_ip
null, -- context_id
''intranet-timesheet2'', -- package_name
''timesheet2_timesheet'', -- label
''Timesheet'', -- name
''/intranet-timesheet2/hours/index'', -- url
73, -- sort_order
v_parent_menu, -- parent_menu_id
null -- p_visible_tcl
);
PERFORM acs_permission__grant_permission(v_menu, v_admins, ''read'');
PERFORM acs_permission__grant_permission(v_menu, v_senman, ''read'');
PERFORM acs_permission__grant_permission(v_menu, v_proman, ''read'');
PERFORM acs_permission__grant_permission(v_menu, v_accounting, ''read'');
PERFORM acs_permission__grant_permission(v_menu, v_employees, ''read'');
PERFORM acs_permission__grant_permission(v_menu, v_customers, ''read'');
PERFORM acs_permission__grant_permission(v_menu, v_freelancers, ''read'');
v_menu := im_menu__new (
null, -- p_menu_id
''acs_object'', -- object_type
now(), -- creation_date
null, -- creation_user
null, -- creation_ip
null, -- context_id
''intranet-timesheet2'', -- package_name
''timesheet2_absences'', -- label
''Absences'', -- name
''/intranet-timesheet2/hours/index'', -- url
74, -- sort_order
v_parent_menu, -- parent_menu_id
null -- p_visible_tcl
);
PERFORM acs_permission__grant_permission(v_menu, v_admins, ''read'');
PERFORM acs_permission__grant_permission(v_menu, v_senman, ''read'');
PERFORM acs_permission__grant_permission(v_menu, v_proman, ''read'');
PERFORM acs_permission__grant_permission(v_menu, v_accounting, ''read'');
PERFORM acs_permission__grant_permission(v_menu, v_employees, ''read'');
PERFORM acs_permission__grant_permission(v_menu, v_customers, ''read'');
PERFORM acs_permission__grant_permission(v_menu, v_freelancers, ''read'');
return 0;
end;' language 'plpgsql';
select inline_0 ();
drop function inline_0 ();
select im_component_plugin__new ( select im_component_plugin__new (
null, -- plugin_id null, -- plugin_id
'acs_object', -- object_type 'acs_object', -- object_type
...@@ -87,13 +174,13 @@ select im_component_plugin__new ( ...@@ -87,13 +174,13 @@ select im_component_plugin__new (
null, -- creattion_ip null, -- creattion_ip
null, -- context_id null, -- context_id
'Project Timesheet Component', -- plugin_name 'Project Timesheet Component', -- plugin_name
'intranet-timesheet', -- package_name 'intranet-timesheet', -- package_name
'right', -- location 'right', -- location
'/intranet/projects/view', -- page_url '/intranet/projects/view', -- page_url
null, -- view_name null, -- view_name
50, -- sort_order 50, -- sort_order
'im_timesheet_project_component $user_id $project_id ', 'im_timesheet_project_component $user_id $project_id ',
'_ intranet-timesheet2.Timesheet' '_ intranet-timesheet2.Timesheet'
); );
...@@ -105,15 +192,15 @@ select im_component_plugin__new ( ...@@ -105,15 +192,15 @@ select im_component_plugin__new (
null, -- creattion_ip null, -- creattion_ip
null, -- context_id null, -- context_id
'Home Timesheet Component', -- plugin_name 'Home Timesheet Component', -- plugin_name
'intranet-timesheet', -- package_name 'intranet-timesheet', -- package_name
'right', -- location 'right', -- location
'/intranet/index', -- page_url '/intranet/index', -- page_url
null, -- view_name null, -- view_name
80, -- sort_order 80, -- sort_order
'im_timesheet_home_component $user_id', 'im_timesheet_home_component $user_id',
'intranet-timesheet2.Timesheet' 'intranet-timesheet2.Timesheet'
); );
\i intranet-absences-create.sql \i intranet-absences-create.sql
\i ../common/intranet-timesheet-common.sql \i ../common/intranet-timesheet-common.sql
......
...@@ -14,64 +14,6 @@ $ --> ...@@ -14,64 +14,6 @@ $ -->
<version>7.2</version> <version>7.2</version>
</rdbms> </rdbms>
<fullquery name="task_insert">
<querytext>
BEGIN
PERFORM im_timesheet_task__new (
:task_id, -- p_task_id
'im_timesheet_task', -- object_type
now(), -- creation_date
null, -- creation_user
null, -- creation_ip
null, -- context_id
:task_nr,
:task_name,
:project_id,
:material_id,
:cost_center_id,
:uom_id,
:task_type_id,
:task_status_id,
:description
);
return 0;
END;
</querytext>
</fullquery>
<fullquery name="task_delete">
<querytext>
BEGIN
PERFORM im_task__delete (:task_id);
return 0;
END;
</querytext>
</fullquery>
<fullquery name="task_update">
<querytext>
update im_timesheet_tasks set
task_name = :task_name,
task_nr = :task_nr,
project_id = :project_id,
material_id = :material_id,
cost_center_id = :cost_center_id,
task_type_id = :task_type_id,
task_status_id = :task_status_id,
uom_id = :uom_id,
planned_units = :planned_units,
billable_units = :billable_units,
description = :description
where
task_id = :task_id;
</querytext>
</fullquery>
<fullquery name="delete_timesheet_costs"> <fullquery name="delete_timesheet_costs">
<querytext> <querytext>
...@@ -84,7 +26,6 @@ $ --> ...@@ -84,7 +26,6 @@ $ -->
where cost_type_id = [im_cost_type_timesheet] where 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
loop loop
PERFORM im_cost__delete(row.cost_id); PERFORM im_cost__delete(row.cost_id);
end loop; end loop;
......
...@@ -16,15 +16,13 @@ ...@@ -16,15 +16,13 @@
ad_page_contract { ad_page_contract {
Writes hours to db. Writes hours to db.
@param hours @param hours
@param julian_date @param julian_date
@author dvr@arsdigita.com @author dvr@arsdigita.com
@author mbryzek@arsdigita.com @author mbryzek@arsdigita.com
@author frank.bergmann@project-open.com @author frank.bergmann@project-open.com
} { } {
project_ids:array,integer
timesheet_task_ids:array,integer
hours:array hours:array
notes:array,html notes:array,html
julian_date julian_date
...@@ -49,6 +47,10 @@ set item_nrs [array names hours] ...@@ -49,6 +47,10 @@ set item_nrs [array names hours]
ns_log Notice "timesheet2-tasks/new-2: items_nrs=$item_nrs" ns_log Notice "timesheet2-tasks/new-2: items_nrs=$item_nrs"
set today [db_string day "
select to_char(to_date(:julian_date, 'J'), :timesheet_log_date_format)
from dual
"]
# ---------------------------------------------------------- # ----------------------------------------------------------
# Determine Billing Rate # Determine Billing Rate
...@@ -76,19 +78,17 @@ if {"" == $billing_currency} { ...@@ -76,19 +78,17 @@ if {"" == $billing_currency} {
# Update items # Update items
# ---------------------------------------------------------- # ----------------------------------------------------------
foreach item_nr $item_nrs { foreach project_id $item_nrs {
ns_log Notice "timesheet2-tasks/new-2: item_nr=$item_nr" ns_log Notice "timesheet2-tasks/new-2: project_id=$project_id"
# Extract the parameters from the arrays # Extract the parameters from the arrays
set hours_worked [string trim $hours($item_nr)] 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]
# Update costs table
if {[db_table_exists im_costs]} {
db_dml cost_update " db_dml cost_update "
update im_costs set update im_costs set
cost_name = :cost_name, cost_name = :cost_name,
...@@ -233,7 +198,6 @@ foreach item_nr $item_nrs { ...@@ -233,7 +198,6 @@ foreach item_nr $item_nrs {
payment_days = 0, payment_days = 0,
vat = 0, vat = 0,
tax = 0, tax = 0,
cause_object_id = :timesheet_task_id,
description = :note description = :note
where where
cost_id = :cost_id cost_id = :cost_id
......
...@@ -281,9 +281,6 @@ db_foreach $statement_name $sql { ...@@ -281,9 +281,6 @@ db_foreach $statement_name $sql {
set level [expr $level-1] set level [expr $level-1]
} }
# Highlight main projects
if {0 == $subproject_level} { set project_name "<b>$project_name</b>" }
# These are the hours and notes captured from the intranet-timesheet2-task-popup # 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 # modules, if it's there. The module allows the user to capture notes during the
# day on what task she is working. # day on what task she is working.
...@@ -293,62 +290,29 @@ db_foreach $statement_name $sql { ...@@ -293,62 +290,29 @@ db_foreach $statement_name $sql {
if {[info exists popup_notes($project_id)]} { set p_notes $popup_notes($project_id) } if {[info exists popup_notes($project_id)]} { set p_notes $popup_notes($project_id) }
# Insert intermediate header for every parent_project # Insert intermediate header for every top-project
if {$old_project_id != $top_project_id} { if {0 == $subproject_level} {
set project_name "<b>$project_name</b>"
# Add an empty line after every main project # Add an empty line after every main project
if {"" == $parent_project_id} { if {"" == $parent_project_id} {
append results "<tr class=rowplain><td colspan=99>&nbsp;</td></tr>\n" append results "<tr class=rowplain><td colspan=99>&nbsp;</td></tr>\n"
} }
# Add a line for a project. This is useful if there are
# no timesheet_tasks yet for this project, because we
# always want to allow employees to log their ours in
# order not to give them excuses.
#
append resultssss "
<tr $bgcolor([expr $ctr % 2])>
<td>
<nobr>
$indent i
<A href=/intranet/projects/view?project_id=$project_id>
<B>$project_name</B>
</A>
</nobr>
<input type=hidden name=\"project_ids.$ctr\" value=\"$project_id\">
<input type=hidden name=\"timesheet_task_ids.$ctr\" value=\"\$task_id\">
</td>
<td></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
"
set old_project_id $top_project_id
incr ctr
} }
# Don't show the empty tasks that are produced with each project # Allow hour logging
# due to the "left outer join" SQL query set project_url [export_vars -base "/intranet/projects/view?" {project_id return_url}]
append results " append results "
<tr $bgcolor([expr $ctr % 2])> <tr $bgcolor([expr $ctr % 2])>
<td> <td>
<nobr> <nobr>$indent <A href=\"$project_url\">$project_name</A></nobr>
$indent
<A href=/intranet-timesheet2-tasks/new?[export_url_vars task_id project_id return_url]>
$project_name
</A>
</nobr>
<input type=hidden name=\"project_ids.$ctr\" value=\"$project_id\">
<input type=hidden name=\"timesheet_task_ids.$ctr\" value=\"$project_id\">
</td> </td>
<td> <td>
<INPUT NAME=hours.$ctr size=5 MAXLENGTH=5 value=\"$hours\"> <INPUT NAME=hours.$project_id size=5 MAXLENGTH=5 value=\"$hours\">
$p_hours $p_hours
</td> </td>
<td> <td>
<INPUT NAME=notes.$ctr size=60 value=\"[ns_quotehtml [value_if_exists note]]\"> <INPUT NAME=notes.$project_id size=60 value=\"[ns_quotehtml [value_if_exists note]]\">
$p_notes $p_notes
</td> </td>
</tr> </tr>
...@@ -368,4 +332,3 @@ if { [empty_string_p results] } { ...@@ -368,4 +332,3 @@ if { [empty_string_p results] } {
set export_form_vars [export_form_vars julian_date return_url] 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