Commit 8ee1c7f9 authored by Frank Bergmann's avatar Frank Bergmann

- removed unused timesheet2-invoices/invoices/index function

parent 3e4fc812
<?xml version="1.0"?>
<!DOCTYPE queryset PUBLIC "-//OpenACS//DTD XQL 1.0//EN" "/usr/share/emacs/DTDs/xql.dtd">
<!-- packages/intranet-timesheet2-invoices/www/invoices/index-postgresql.xql -->
<!-- @author (nsadmin@barna.competitiveness.com) -->
<!-- @creation-date 2004-09-21 -->
<!-- @arch-tag df8e9b42-1ce7-4989-8d65-efe8dc6f99cb -->
<!-- @cvs-id $Id$ -->
<!-- ToDo: Implement pagination -->
<queryset>
<rdbms>
<type>postgresql</type>
<version>7.2</version>
</rdbms>
<fullquery name="invoices_info_query">
<querytext>
select
i.*,
(to_date(to_char(i.invoice_date,'YYYY-MM-DD'),'YYYY-MM-DD') + i.payment_days) as due_date_calculated,
ii.invoice_amount,
to_char(ii.invoice_amount,:cur_format) as invoice_amount_formatted,
ii.invoice_currency,
pa.payment_amount,
pa.payment_currency,
u.email as company_contact_email,
u.first_names||' '||u.last_name as company_contact_name,
c.group_name as company_name,
c.short_name as company_short_name,
im_category_from_id(i.cost_status_id) as cost_status,
sysdate - (to_date(to_char(i.invoice_date, 'YYYY-MM-DD'),'YYYY-MM-DD') + i.payment_days) as overdue
from
im_invoices_active i
LEFT JOIN
users u ON i.company_contact_id=u.user_id
LEFT JOIN
user_groups c ON i.company_id=c.group_id
LEFT JOIN
(select
invoice_id,
sum(item_units * price_per_unit) as invoice_amount,
max(currency) as invoice_currency
from im_invoice_items
group by invoice_id
) ii USING (invoice_id)
(select
sum(amount) as payment_amount,
max(currency) as payment_currency,
invoice_id
from im_payments
group by invoice_id
) pa USING (invoice_id)
where
1=1
$where_clause
$order_by_clause
</querytext>
</fullquery>
</queryset>
<!-- packages/intranet-timesheet2-invoices/www/invoices/index.adp -->
<!-- @author Juanjo Ruiz (juanjoruizx@yahoo.es) -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<master src="../../../intranet-core/www/master">
<property name="title">@page_title@</property>
<property name="context">@context_bar@</property>
<property name="main_navbar_label">finance</property>
@page_body;noquote@
\ No newline at end of file
# /packages/intranet-timesheet2-invoices/www/index.tcl
#
# Copyright (C) 2003-2004 Project/Open
#
# All rights reserved. Please check
# http://www.project-open.com/license/ for details.
# ---------------------------------------------------------------
# 1. Page Contract
# ---------------------------------------------------------------
ad_page_contract {
List all invoices together with their payments
@param order_by invoice display order
@param include_subinvoices_p whether to include sub invoices
@param status_id criteria for invoice status
@param type_id criteria for cost_type_id
@param letter criteria for im_first_letter_default_to_a(ug.group_name)
@param start_idx the starting index for query
@param how_many how many rows to return
@author frank.bergmann@project-open.com
} {
{ order_by "Invoice #" }
{ status_id:integer 0 }
{ type_id:integer 0 }
{ company_id:integer 0 }
{ letter:trim "" }
{ start_idx:integer 0 }
{ how_many "" }
{ view_name "invoice_list" }
}
# ---------------------------------------------------------------
# Invoice List Page
#
# This is List-Page with some special functions. It consists of the sections:
# 1. Page Contract:
# Receive the filter values defined as parameters to this page.
# 2. Defaults & Security:
# Initialize variables, set default values for filters
# (categories) and limit filter values for unprivileged users
# 3. Define Table Columns:
# Define the table columns that the user can see.
# Again, restrictions may apply for unprivileged users,
# for example hiding company names to freelancers.
# 4. Define Filter Categories:
# Extract from the database the filter categories that
# are available for a specific user.
# For example "potential", "invoiced" and "partially paid"
# invoices are not available for unprivileged users.
# 5. Generate SQL Query
# Compose the SQL query based on filter criteria.
# All possible columns are selected from the DB, leaving
# the selection of the visible columns to the table columns,
# defined in section 3.
# 6. Format Filter
# 7. Format the List Table Header
# 8. Format Result Data
# 9. Format Table Continuation
# 10. Join Everything Together
# ---------------------------------------------------------------
# 2. Defaults & Security
# ---------------------------------------------------------------
# User id already verified by filters
set user_id [ad_maybe_redirect_for_registration]
set current_user_id $user_id
set today [lindex [split [ns_localsqltimestamp] " "] 0]
set page_title "Invoices"
set context_bar [im_context_bar $page_title]
set page_focus "im_header_form.keywords"
set return_url [im_url_with_query]
# Needed for im_view_columns, defined in intranet-views.tcl
set amp "&"
set cur_format "99,999.99"
if {![im_permission $user_id view_finance]} {
ad_return_complaint "[_ intranet-timesheet2-invoices.lt_Insufficient_Privileg]" "
<li>[_ intranet-timesheet2-invoices.lt_You_dont_have_suffici]"
}
if {$status_id == 0} {
set status_id [im_cost_status_created]
}
if { [empty_string_p $how_many] || $how_many < 1 } {
set how_many [ad_parameter -package_id [im_package_core_id] NumberResultsPerPage "" 50]
}
set end_idx [expr $start_idx + $how_many - 1]
# ---------------------------------------------------------------
# 3. Defined Table Fields
# ---------------------------------------------------------------
# Define the column headers and column contents that
# we want to show:
#
set view_id [db_string get_view_id "select view_id from im_views where view_name=:view_name"]
set column_headers [list]
set column_vars [list]
set column_sql "
select
column_name,
column_render_tcl,
visible_for
from
im_view_columns
where
view_id=:view_id
and group_id is null
order by
sort_order"
db_foreach column_list_sql $column_sql {
if {[eval $visible_for]} {
lappend column_headers "$column_name"
lappend column_vars "$column_render_tcl"
}
}
# ---------------------------------------------------------------
# 4. Define Filter Categories
# ---------------------------------------------------------------
# status_types will be a list of pairs of (cost_status_id, cost_status)
set status_types [im_memoize_list select_cost_status_types \
"select cost_status_id, cost_status
from im_cost_status
order by lower(cost_status)"]
# No "All" status, because we _really_ don't want to show the
# "In Process" invoices left over from the creation process.
#
#set status_types [linsert $status_types 0 0 All]
# ---------------------------------------------------------------
# 5. Generate SQL Query
# ---------------------------------------------------------------
set criteria [list]
if { ![empty_string_p $status_id] && $status_id > 0 } {
lappend criteria "i.cost_status_id=:status_id"
}
if { ![empty_string_p $type_id] && $type_id != 0 } {
lappend criteria "i.cost_type_id=:type_id"
}
if { ![empty_string_p $company_id] && $company_id != 0 } {
lappend criteria "i.company_id=:company_id"
}
if { ![empty_string_p $letter] && [string compare $letter "ALL"] != 0 && [string compare $letter "SCROLL"] != 0 } {
lappend criteria "im_first_letter_default_to_a(ug.group_name)=:letter"
}
set order_by_clause ""
switch $order_by {
"Invoice #" { set order_by_clause "order by invoice_nr" }
"Preview" { set order_by_clause "order by invoice_nr" }
"Client" { set order_by_clause "order by company_name" }
"Due Date" { set order_by_clause "order by (i.invoice_date+i.payment_days)" }
"Amount" { set order_by_clause "order by ii.invoice_amount" }
"Paid" { set order_by_clause "order by pa.payment_amount" }
"Status" { set order_by_clause "order by cost_status_id" }
}
set where_clause [join $criteria " and\n "]
if { ![empty_string_p $where_clause] } {
set where_clause " and $where_clause"
}
set sql "
select
i.*,
(to_date(to_char(i.invoice_date,'YYYY-MM-DD'),'YYYY-MM-DD') + i.payment_days) as due_date_calculated,
ii.invoice_amount,
to_char(ii.invoice_amount,:cur_format) as invoice_amount_formatted,
ii.invoice_currency,
pa.payment_amount,
pa.payment_currency,
u.email as company_contact_email,
u.first_names||' '||u.last_name as company_contact_name,
c.group_name as company_name,
c.short_name as company_short_name,
im_category_from_id(i.cost_status_id) as cost_status,
sysdate - (to_date(to_char(i.invoice_date, 'YYYY-MM-DD'),'YYYY-MM-DD') + i.payment_days) as overdue
from
im_invoices_active i,
users u,
user_groups c,
(select
invoice_id,
sum(item_units * price_per_unit) as invoice_amount,
max(currency) as invoice_currency
from im_invoice_items
group by invoice_id
) ii,
(select
sum(amount) as payment_amount,
max(currency) as payment_currency,
invoice_id
from im_payments
group by invoice_id
) pa
where
i.company_contact_id=u.user_id(+)
and i.invoice_id=ii.invoice_id(+)
and i.invoice_id=pa.invoice_id(+)
and i.company_id=c.group_id(+)
$where_clause
$order_by_clause
"
# ---------------------------------------------------------------
# 5a. Limit the SQL query to MAX rows and provide << and >>
# ---------------------------------------------------------------
# Limit the search results to N data sets only
# to be able to manage large sites
#
if {[string compare $letter "ALL"]} {
# Set these limits to negative values to deactivate them
set total_in_limited -1
set how_many -1
set selection "$sql"
} else {
set limited_query [im_select_row_range $sql $start_idx $end_idx]
# We can't get around counting in advance if we want to be able to
# sort inside the table on the page for only those users in the
# query results
set total_in_limited [db_string invoices_total_in_limited "
select count(*)
from im_invoices p, user_groups ug
where p.group_id=ug.group_id $where_clause"]
set selection "select z.* from ($limited_query) z $order_by_clause"
}
# ---------------------------------------------------------------
# 6. Format the Filter
# ---------------------------------------------------------------
# Note that we use a nested table because im_slider might
# return a table with a form in it (if there are too many
# options
set filter_html "
<table>
<tr>
<td>
<form method=get action='/intranet/invoicing/index'>
[export_form_vars start_idx order_by how_many view_name include_subinvoices_p letter]
<table border=0 cellpadding=0 cellspacing=0>
<tr>
<td colspan='2' class=rowtitle align=center>
[_ intranet-timesheet2-invoices.Filter_Invoices]
</td>
</tr>
<tr>
<td valign=top>[_ intranet-timesheet2-invoices.Invoice_Status]:</td>
<td valign=top>
[im_select status_id $status_types ""]
<input type=submit value=\"[_ intranet-timesheet2-invoices.Go]\" name=submit>
</td>
</tr>
</table>
</form>
</td>
<td>
<table><tr>
<td>
<blockquote>
&nbsp;
<blockquote>
</td>
</tr></table>
</td>
</tr></table>
"
# ---------------------------------------------------------------
# 7. Format the List Table Header
# ---------------------------------------------------------------
# Set up colspan to be the number of headers + 1 for the # column
set colspan [expr [llength $column_headers] + 1]
set table_header_html ""
#<tr>
# <td align=center valign=top colspan=$colspan><font size=-1>
# [im_groups_alpha_bar [im_invoice_group_id] $letter "start_idx"]</font>
# </td>
#</tr>"
# Format the header names with links that modify the
# sort order of the SQL query.
#
set url "index?"
set query_string [export_ns_set_vars url [list order_by]]
if { ![empty_string_p $query_string] } {
append url "$query_string&"
}
append table_header_html "<tr>\n"
foreach col $column_headers {
set col_txt [lang::util::suggest_key $col]
if { [string compare $order_by $col] == 0 } {
append table_header_html " <td class=rowtitle>[_ intranet-timesheet2-invoices.$col_txt]</td>\n"
} else {
append table_header_html " <td class=rowtitle><a href=\"${url}order_by=[ns_urlencode $col]\">[_ intranet-timesheet2-invoices.$col_txt]</a></td>\n"
}
}
append table_header_html "</tr>\n"
# ---------------------------------------------------------------
# 8. Format the Result Data
# ---------------------------------------------------------------
set table_body_html ""
set bgcolor(0) " class=roweven "
set bgcolor(1) " class=rowodd "
set ctr 0
set idx $start_idx
db_foreach invoices_info_query $selection {
set url [im_maybe_prepend_http $url]
if { [empty_string_p $url] } {
set url_string "&nbsp;"
} else {
set url_string "<a href=\"$url\">$url</a>"
}
# Append together a line of data based on the "column_vars" parameter list
append table_body_html "<tr$bgcolor([expr $ctr % 2])>\n"
foreach column_var $column_vars {
append table_body_html "\t<td valign=top>"
set cmd "append table_body_html $column_var"
eval $cmd
append table_body_html "</td>\n"
}
append table_body_html "</tr>\n"
incr ctr
if { $how_many > 0 && $ctr >= $how_many } {
break
}
incr idx
}
# Show a reasonable message when there are no result rows:
if { [empty_string_p $table_body_html] } {
set table_body_html "
<tr><td colspan=$colspan><ul><li><b>
[_ intranet-timesheet2-invoices.lt_There_are_currently_n]
</b></ul></td></tr>"
}
if { $ctr == $how_many && $end_idx < $total_in_limited } {
# This means that there are rows that we decided not to return
# Include a link to go to the next page
set next_start_idx [expr $end_idx + 1]
set next_page_url "index?start_idx=$next_start_idx&[export_ns_set_vars url [list start_idx]]"
} else {
set next_page_url ""
}
if { $start_idx > 0 } {
# This means we didn't start with the first row - there is
# at least 1 previous row. add a previous page link
set previous_start_idx [expr $start_idx - $how_many]
if { $previous_start_idx < 0 } { set previous_start_idx 0 }
set previous_page_url "index?start_idx=$previous_start_idx&[export_ns_set_vars url [list start_idx]]"
} else {
set previous_page_url ""
}
# ---------------------------------------------------------------
# 9. Format Table Continuation
# ---------------------------------------------------------------
# Check if there are rows that we decided not to return
# => include a link to go to the next page
#
if {$ctr==$how_many && $total_in_limited > 0 && $end_idx < $total_in_limited} {
set next_start_idx [expr $end_idx + 1]
set next_page "<a href=index?start_idx=$next_start_idx&[export_ns_set_vars url [list start_idx]]>[_ intranet-timesheet2-invoices.Next_Page]</a>"
} else {
set next_page ""
}
# Check if this is the continuation of a table (we didn't start with the
# first row - there is at least 1 previous row.
# => add a previous page link
#
if { $start_idx > 0 } {
set previous_start_idx [expr $start_idx - $how_many]
if { $previous_start_idx < 0 } { set previous_start_idx 0 }
set previous_page "<a href=index?start_idx=$previous_start_idx&[export_ns_set_vars url [list start_idx]]>[_ intranet-timesheet2-invoices.Previous_Page]</a>"
} else {
set previous_page ""
}
set table_continuation_html "
<tr>
<td align=center colspan=$colspan>
[im_maybe_insert_link $previous_page $next_page]
</td>
</tr>"
set button_html "
<tr>
<td colspan=[expr $colspan - 3]></td>
<td align=center>
<input type=submit name=submit value='[_ intranet-timesheet2-invoices.Save]'>
</td>
<td align=center>
<input type=submit name=submit value='[_ intranet-timesheet2-invoices.Del]'>
</td>
</tr>"
# ---------------------------------------------------------------
# 10. Join all parts together
# ---------------------------------------------------------------
set page_body "
$filter_html
[im_invoice_navbar $letter "/intranet/invoicing/index" $next_page_url $previous_page_url [list status_id type_id company_id start_idx order_by how_many view_name letter]]
<form action=invoice-action method=POST>
[export_form_vars company_id invoice_id return_url]
<table width=100% cellpadding=2 cellspacing=2 border=0>
$table_header_html
$table_body_html
$table_continuation_html
$button_html
</table>
</form>
"
db_release_unused_handles
ad_return_template
\ No newline at end of file
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