Commit 82ff01ac authored by Project Open's avatar Project Open
parents 4297f093 fc0e508c
@html;noquote@
\ No newline at end of file
<if 1 eq @show_html_p@>
<table>
<tr valign=top>
<td width='70%'>
<table cellspaing=2 cellpadding=2>
<tr>
<td class=rowtitle>Name</td>
<td class=rowtitle>Amount</td>
<td class=rowtitle>Type</td>
<td class=rowtitle>Status</td>
</tr>
<tr><td colspan=99><h1>Predecessors</h1></td></tr>
@predecessor_html;noquote@
<tr><td colspan=99><h1>Successors</h1></td></tr>
@successor_html;noquote@
</table>
</td>
<td width='30%'>
<p>This portlet shows predecessors (= financial documents from which this document was created)
and successors (= financial documents created based on this one).</p>
</td>
</td>
</table>
</if>
......@@ -3,7 +3,7 @@
# Expected variables:
# invoice_id
# project_id set by portlet TCL
# Try behaving like a page if not called as a portlet (may not work yet)
if {![info exists invoice_id]} {
ad_page_contract {} {invoice_id:integer ""}
}
......@@ -20,6 +20,13 @@ if {!$read_p} {
set invoice_base_url "/intranet-invoices/view"
# Check if the calling page (invoices/view?invoice_id=123) has a locale set
set locale [uplevel 2 {if {[info exists locale]} { set locale }}]
if {"" eq $locale} {
set locale [lang::user::locale]
}
# -------------------------------------------------------------
# Main project
# -------------------------------------------------------------
......@@ -33,7 +40,6 @@ set main_project_ids [db_list pids "
p.project_id = r.object_id_one and
main_p.tree_sortkey = tree_root_key(p.tree_sortkey);
"]
lappend main_project_ids 0
# -------------------------------------------------------------
......@@ -42,7 +48,7 @@ lappend main_project_ids 0
set costs_sql "
select cost_id, item_id, cost_name, cost_nr, cost_type_id, cost_status_id, item_source_invoice_id,
cost_amount, cost_currency,
coalesce(cost_amount, 0.0) as cost_amount, cost_currency,
CASE WHEN item_source_invoice_id = cost_id THEN null ELSE item_source_invoice_id END as source_id
from (
select c.*,
......@@ -61,7 +67,7 @@ set costs_sql "
c.cost_type_id not in (3714, 3718, 3720, 3722, 3726, 3736, 73102)
UNION
select c.*,
c.amount as cost_amount,
coalesce(c.amount, 0.0) as cost_amount,
c.currency as cost_currency,
i.*,
ii.*
......@@ -91,7 +97,7 @@ db_foreach costs $costs_sql {
set name_hash($cost_id) $cost_name
set type_hash($cost_id) $cost_type_id
set status_hash($cost_id) $cost_status_id
set amount_hash($cost_id) "$cost_amount $cost_currency"
set amount_hash($cost_id) "[lc_numeric $cost_amount "%.2f" $locale] $cost_currency"
if {"" ne $source_id} {
set predecessors {}
......@@ -169,14 +175,17 @@ while {[llength $list] > 0 && $cnt < 10} {
set amount $amount_hash($id)
set type [im_category_from_id $type_hash($id)]
set status [im_category_from_id $status_hash($id)]
set link "<a href=$url>$name</a>"
} else {
set name "Unknown #$id"
set url ""
set name "Deleted #$id"
set amount ""
set type ""
set status ""
set link $name
}
append predecessor_html "<tr>
<td><a href=$url>$name</a></td>
<td>$link</td>
<td>$amount</td>
<td>$type</td>
<td>$status</td>
......@@ -251,36 +260,10 @@ while {[llength $list] > 0 && $cnt < 100} {
# -------------------------------------------------------------
#
# Output HTML
# -------------------------------------------------------------
if {"" eq $predecessor_html} { set predecessor_html "<tr><td colspan=99>No predecessors found</td></tr>" }
if {"" eq $successor_html} { set successor_html "<tr><td colspan=99>No successors found</td></tr>" }
set html "
<table><tr valign=top>
<td width='70%'>
<table cellspaing=2 cellpadding=2>
<tr>
<td class=rowtitle>Name</td>
<td class=rowtitle>Amount</td>
<td class=rowtitle>Type</td>
<td class=rowtitle>Status</td>
</tr>
<tr><td colspan=99><h1>Predecessors</h1></td></tr>
$predecessor_html
<tr><td colspan=99><h1>Successors</h1></td></tr>
$successor_html
</table>
</td>
<td width='30%'>
<p>This portlet shows predecessors (= financial documents from which this document was created)
and successors (= financial documents created based on this one).</p>
</td>
</td></table>
"
if {[expr $predecessor_num + $successor_num] < 1} { set html "" }
set show_html_p [expr ($predecessor_num + $successor_num) > 0]
-- Returns a formatted string with links to successor objects
create or replace function im_invoice_predecessor_links(integer)
returns varchar as $body$
declare
p_invoice_id alias for $1;
row RECORD;
v_result varchar;
begin
v_result := '';
FOR row IN
select distinct
c_pred.cost_id as pred_id,
c_pred.cost_name as pred_name
from im_invoice_items ii,
im_costs c_pred
where ii.invoice_id = p_invoice_id and
c_pred.cost_id = item_source_invoice_id
LOOP
IF v_result != '' THEN
v_result = v_result || ', ';
END IF;
v_result = v_result ||
'<a href=/intranet-invoices/view?invoice_id=' || row.pred_id ||
'>' || row.pred_name || '</a>';
END LOOP;
return v_result;
end; $body$ language 'plpgsql';
create or replace function im_invoice_successor_links(integer)
returns varchar as $body$
declare
p_invoice_id alias for $1;
row RECORD;
v_result varchar;
begin
v_result := '';
FOR row IN
select distinct
c_succ.cost_id as succ_id,
c_succ.cost_name as succ_name
from im_invoice_items ii,
im_costs c_succ
where ii.invoice_id = c_succ.cost_id and
ii.item_source_invoice_id = p_invoice_id
LOOP
IF v_result != '' THEN
v_result = v_result || ', ';
END IF;
v_result = v_result ||
'<a href=/intranet-invoices/view?invoice_id=' || row.succ_id ||
'>' || row.succ_name || '</a>';
END LOOP;
return v_result;
end; $body$ language 'plpgsql';
create or replace function im_invoice_successor_sum(integer)
returns numeric as $body$
declare
p_invoice_id alias for $1;
row RECORD;
v_result numeric;
begin
v_result := 0.0;
FOR row IN
select distinct
c_succ.cost_id as succ_id,
c_succ.cost_name as succ_name,
c_succ.amount
from im_invoice_items ii,
im_costs c_succ
where ii.invoice_id = c_succ.cost_id and
ii.item_source_invoice_id = p_invoice_id
LOOP
v_result = v_result + row.amount;
END LOOP;
return v_result;
end; $body$ language 'plpgsql';
select im_invoice_predecessor_links(447724);
select im_invoice_successor_links(406832);
......@@ -91,7 +91,7 @@ if {"delete" == $action} {
im_audit -object_type "im_invoice" -object_id $invoice_id -action after_update
ad_returnredirect $return_url
ad_abort_script
ad_script_abort
}
......@@ -111,7 +111,7 @@ if {"set_invoiced" == $action} {
}
ad_returnredirect $return_url
ad_abort_script
ad_script_abort
}
......
......@@ -18,6 +18,7 @@ ad_page_contract {
@cvs-id index.tcl,v 3.24.2.9 2000/09/22 01:38:44 kevin Exp
} {
{ order_by "Effective Date" }
{ filter_project_id:integer 0 }
{ cost_status_id:integer "[im_cost_status_created]" }
{ cost_type_id:integer 0 }
{ company_id:integer 0 }
......@@ -79,7 +80,7 @@ set date_format [im_l10n_sql_date_format]
set default_currency [im_parameter -package_id [im_package_cost_id] "DefaultCurrency" "" "EUR"]
set local_url "/intranet-invoices/list"
set cost_status_created [im_cost_status_created]
set cost_type [db_string get_cost_type "select category from im_categories where category_id=:cost_type_id" -default [_ intranet-invoices.Costs]]
set cost_type [db_string get_cost_type "select category from im_categories where category_id = :cost_type_id" -default [_ intranet-invoices.Costs]]
set letter [string toupper $letter]
if {![im_permission $user_id view_invoices]} {
......@@ -122,31 +123,47 @@ if {0 == $view_id} {
}
set extra_selects [list]
set extra_froms [list]
set extra_wheres [list]
set column_sql "
select column_name,
column_render_tcl,
visible_for,
order_by_clause as column_order_by_clause
from im_view_columns
where view_id = :view_id
and group_id is null
order by
sort_order"
select column_name,
column_render_tcl,
visible_for,
extra_select,
extra_from,
extra_where,
order_by_clause
from im_view_columns
where view_id = :view_id
and group_id is null
order by
sort_order
"
# Get the main view
set column_headers [list]
set column_vars [list]
set order_by_clause ""
db_foreach column_list_sql $column_sql {
set admin_html ""
if {$user_is_admin_p} {
set url [export_vars -base "/intranet/admin/views/new-column" {column_id return_url}]
set admin_html "<a href='$url'>[im_gif wrench ""]</a>"
}
if {"" == $visible_for || [eval $visible_for]} {
lappend column_headers "$column_name"
lappend column_vars "$column_render_tcl"
lappend column_headers_admin $admin_html
if {"" != $extra_select} { lappend extra_selects [eval "set a \"$extra_select\""] }
if {"" != $extra_from} { lappend extra_froms $extra_from }
if {"" != $extra_where} { lappend extra_wheres $extra_where }
if {"" != $order_by_clause && $order_by == $column_name} {
set view_order_by_clause $order_by_clause
}
}
if {$order_by eq $column_name} {
set order_by_clause $column_order_by_clause
}
}
# ---------------------------------------------------------------
......@@ -154,6 +171,17 @@ db_foreach column_list_sql $column_sql {
# ---------------------------------------------------------------
set criteria [list]
if { $filter_project_id ne "" && $filter_project_id > 0 } {
lappend criteria "ci.project_id in (
select sub_p.project_id
from im_projects main_p,
im_projects sub_p
where main_p.project_id = :filter_project_id and
sub_p.tree_sortkey between main_p.tree_sortkey and tree_right(main_p.tree_sortkey)
)"
}
if { $cost_status_id ne "" && $cost_status_id > 0 } {
lappend criteria "ci.cost_status_id in ([join [im_sub_categories $cost_status_id] ","])"
}
......@@ -176,6 +204,23 @@ if {"" != $end_date} {
set extra_select [join $extra_selects ",\n\t"]
if { $extra_select ne "" } {
set extra_select ",\n\t$extra_select"
}
set extra_from [join $extra_froms ",\n\t"]
if { $extra_from ne "" } {
set extra_from ",\n\t$extra_from"
}
set extra_where [join $extra_wheres "and\n\t"]
if { $extra_where ne "" } {
set extra_where ",\n\t$extra_where"
}
# Get the list of user's companies for which he can see invoices
set company_ids [db_list users_companies "
select
......@@ -200,6 +245,7 @@ if {![im_permission $user_id view_invoices]} {
ns_log Notice "/intranet-invoices/index: company_where=$company_where"
set counter_reset_expression ""
set order_by_clause ""
# If filter is set to Customer or Provider Doc's and no order_by is providedwe order by creation date.
# Before order_by was set to default (Document No). This way documents showed up grouped by document types.
......@@ -256,11 +302,6 @@ if { $where_clause ne "" } {
set payment_amount ""
set payment_currency ""
set extra_select ""
set extra_from ""
set extra_where ""
# -----------------------------------------------------------------
# Main SQL
# -----------------------------------------------------------------
......@@ -420,6 +461,12 @@ set filter_html "
[im_company_select -include_empty_p 1 -include_empty_name "All" company_id $company_id]
</td>
</tr>
<tr>
<td>[_ intranet-core.Project]</td>
<td>
[im_project_select -exclude_subprojects_p 1 -include_empty_p 1 filter_project_id $filter_project_id]
</td>
</tr>
<tr>
<td class=form-label>[_ intranet-core.Start_Date]</td>
<td class=form-widget>
......
......@@ -139,6 +139,7 @@ if {"" == $invoice_currency} { set invoice_currency $default_currency }
set current_user_id [auth::require_login]
set admin_p [im_user_is_admin_p $current_user_id]
set user_id $current_user_id
set write_p [im_cost_center_write_p $cost_center_id $cost_type_id $user_id]
# if !$write_p || ![im_permission $user_id add_invoices] || "" == $cost_center_id
......@@ -192,10 +193,25 @@ if {$duplicate_p} {
}
}
# ---------------------------------------------------------------
# Check if there is a single project to which this document refers.
# Check if there is a workflow ongoing
# ---------------------------------------------------------------
set wf_case_p [db_string wf_case "select count(*) from wf_cases where object_id = :invoice_id"]
if {$wf_case_p > 0 && !$admin_p} {
ad_return_complaint 1 "<b>[lang::message::lookup "" intranet-invoices.Ongoing_Workflow "Financial Document Controlled by Workflow"]:</b><br>
[lang::message::lookup "" intranet-invoices.intranet-invoices.Ongoing_Workflow_msg "
This financial document is controlled by a workflow,
so normal users are not allowed to change it anymore.<br>
Please notify your system administrator if you think this is not correct.
"]"
ad_script_abort
}
# ---------------------------------------------------------------
# Check if there is a single project to which this document refers.
# ---------------------------------------------------------------
# Look for common super-projects for multi-project documents
set select_project [im_invoices_unify_select_projects $select_project]
......
......@@ -132,16 +132,9 @@ if { "" == $project_id || ![info exists project_id] } {
}
# ---------------------------------------------------------------
# set customer_select [im_company_select customer_id $customer_id "" "CustOrIntl"]
# set provider_select [im_company_select provider_id $provider_id "" "Provider"]
# set customer_select [im_company_select -tag_attributes {onchange "ajaxFunction();" onkeyup "ajaxFunction();"} customer_id $customer_id "" "CustOrIntl"]
# set provider_select [im_company_select -tag_attributes {onchange "ajaxFunction();" onkeyup "ajaxFunction();"} provider_id $provider_id "" "Provider"]
set customer_select [im_company_select -tag_attributes {id "customer_id"} customer_id $customer_id "" "CustOrIntl"]
set provider_select [im_company_select -tag_attributes {id "provider_id"} provider_id $provider_id "" "Provider"]
# ---------------------------------------------------------------
# Determine whether it's an Invoice or a Bill
# ---------------------------------------------------------------
......
......@@ -228,9 +228,9 @@ set cost_center_installed_p [apm_package_installed_p "intranet-cost-center"]
# Is there already a workflow controlling the lifecycle of the invoice?
set wf_case_p [db_string wf_case "select count(*) from wf_cases where object_id = :invoice_id"]
set wf_transition_key [db_string wf_transition "select transition_key from wf_tasks where task_id = :task_id" -default ""]
if {"modify" eq $wf_transition_key} { set wf_case_p 0 }
if {[im_user_is_admin_p $user_id]} { set wf_case_p 0 }
if {"modify" eq $wf_transition_key} { set wf_case_p 0 }; # Transition corresponds to editing the object
if {[im_user_is_admin_p $current_user_id]} { set wf_case_p 0 }; # Admins can always override WF
if {[im_permission $current_user_id wf_reassign_tasks]} { set wf_case_p 0 }; # User can override tasks anyway...
# ---------------------------------------------------------------
......
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