Commit 1a87c2c0 authored by cosine's avatar cosine

- Modifying timesheet prices:

  - Added project_id, from and through fields
  - Making prices editable
  - Improved permissions
parent 22d4b831
......@@ -271,6 +271,9 @@ create table im_timesheet_prices (
material_id integer
constraint im_timesheet_prices_material_fk
references im_materials,
project_id integer
constraint im_timesheet_prices_project_fk
references im_projects,
valid_from timestamptz,
valid_through timestamptz,
-- make sure the end date is after start date
......
<?xml version="1.0"?>
<!DOCTYPE queryset PUBLIC "-//OpenACS//DTD XQL 1.0//EN" "/usr/share/emacs/DTDs/xql.dtd">
<!-- packages/intranet-timesheet2-invoices/tcl/intranet-timesheet2-invoices-procs-postgresql.xql -->
<!-- @author (frank.bergmann@project-open.com) -->
<!-- @creation-date 2004-09-21 -->
<!-- @arch-tag ebd131d9-8c90-4c9b-a02c-8058aac72256 -->
<!-- @cvs-id $Id$ -->
<queryset>
<rdbms>
<type>postgresql</type>
<version>7.2</version>
</rdbms>
<fullquery name="im_timesheet_price_component.prices">
<querytext>
select
p.*,
c.company_path as company_short_name,
im_category_from_id(uom_id) as uom,
im_category_from_id(task_type_id) as task_type,
im_material_nr_from_id(material_id) as material
from
im_timesheet_prices p
LEFT JOIN
im_companies c USING (company_id)
where
p.company_id=:company_id
order by
currency,
uom_id,
task_type_id desc
</querytext>
</fullquery>
</queryset>
......@@ -51,10 +51,7 @@ ad_proc im_timesheet_price_component { user_id company_id return_url} {
Returns a formatted HTML table representing the
prices for the current company
} {
if {![im_permission $user_id view_costs]} {
return ""
}
if {![im_permission $user_id view_costs]} { return "" }
set bgcolor(0) " class=roweven "
set bgcolor(1) " class=rowodd "
......@@ -64,35 +61,42 @@ ad_proc im_timesheet_price_component { user_id company_id return_url} {
set colspan 7
set price_list_html "
<form action=/intranet-timesheet2-invoices/price-lists/price-action method=POST>
[export_vars -form {company_id return_url}]
[export_vars -form {company_id return_url}]
<table border=0>
<tr><td colspan=$colspan class=rowtitle align=center>[_ intranet-timesheet2-invoices.Price_List]</td></tr>
<tr class=rowtitle>
<td class=rowtitle>[_ intranet-timesheet2-invoices.UoM]</td>
<td class=rowtitle>[_ intranet-timesheet2-invoices.Task_Type]</td>
<td class=rowtitle>[_ intranet-timesheet2-invoices.Material]</td>
<td class=rowtitle>[lang::message::lookup "" intranet-timesheet2-invoices.Project "Project"]</td>
<td class=rowtitle>[lang::message::lookup "" intranet-timesheet2-invoices.From "From"]</td>
<td class=rowtitle>[lang::message::lookup "" intranet-timesheet2-invoices.Through "Through"]</td>
<td class=rowtitle>[_ intranet-timesheet2-invoices.Rate]</td>
<td class=rowtitle>[im_gif -translate_p 1 del "Delete"]</td>
</tr>"
set price_sql "
select
p.*,
c.company_path as company_short_name,
im_category_from_id(uom_id) as uom,
im_category_from_id(task_type_id) as task_type,
im_material_nr_id(material_id) as material
from
im_timesheet_prices p,
im_companies c
where
p.company_id=:company_id
and p.company_id=c.company_id(+)
order by
currency,
uom_id,
task_type_id desc
"
select
tp.*,
c.company_path as company_short_name,
im_category_from_id(tp.uom_id) as uom,
im_category_from_id(tp.task_type_id) as task_type,
to_char(tp.valid_from, 'YYYY-MM-DD') as valid_from,
to_char(tp.valid_through, 'YYYY-MM-DD') as valid_through,
im_material_nr_from_id(tp.material_id) as material,
p.project_nr
from
im_timesheet_prices tp
LEFT OUTER JOIN im_companies c ON (tp.company_id = c.company_id)
LEFT OUTER JOIN im_projects p ON (tp.project_id = p.project_id)
where
tp.company_id = :company_id
order by
tp.currency,
tp.uom_id,
tp.material_id,
tp.task_type_id desc
"
set price_rows_html ""
set ctr 1
......@@ -103,11 +107,16 @@ order by
append price_rows_html "<tr><td colspan=$colspan>&nbsp;</td></tr>\n"
}
set url [export_vars -base "/intranet-timesheet2-invoices/price-lists/new" {price_id}]
append price_rows_html "
<tr $bgcolor([expr {$ctr % 2}]) nobreak>
<td>$uom</td>
<td><a href='$url'>$uom</a></td>
<td>$task_type</td>
<td>$material</td>
<td>$project_nr</td>
<td>$valid_from</td>
<td>$valid_through</td>
<td>[format $price_format $price] $currency</td>
<td><input type=checkbox name=price_id.$price_id></td>
</tr>"
......
......@@ -11,7 +11,7 @@ ad_page_contract {
@author frank.bergmann@project-open.com
} {
price_id:integer,optional
company_id:integer
company_id:integer,optional
{return_url "/intranet/companies/"}
{ currency "" }
edit_p:optional
......@@ -28,37 +28,51 @@ set action_url "new"
set focus "price.var_name"
set page_title "[_ intranet-timesheet2-invoices.New_Price]"
set context [im_context_bar $page_title]
set user_id [auth::require_login]
if {"" == $currency} { set currency [im_parameter -package_id [im_package_cost_id] "DefaultCurrency" "" "EUR"] }
# In general we need financial permissions to read, modify or create prices.
if {![im_permission $user_id add_finance]} {
ad_return_complaint 1 "[_ intranet-timesheet2-invoices.lt_You_have_insufficient_1]"
ad_script_abort
}
# Check permissions. "See details" is an additional check for
# critical information
# Get the company_id if the price_id exists
if {[info exists price_id]} {
db_1row price_info "
select company_id
from im_timesheet_prices
where price_id = :price_id
"
}
# We always need a company to determine permissions on prices
# For display/edit of existing prices, we got the company from the price_id above.
# For new prices, the user needs to specify the company_id in the URL parameters.
if {![info exists company_id]} {
ad_return_complaint 1 "You need to specify 'company_id'"
ad_script_abort
}
# Check if the user is allowed to create a new price
im_company_permissions $user_id $company_id view read write admin
if {!$write || ![im_permission $user_id add_finance]} {
ad_return_complaint 1 "[_ intranet-timesheet2-invoices.lt_You_have_insufficient_1]"
return
ad_script_abort
}
if {"" == $currency} {
set currency [im_parameter -package_id [im_package_cost_id] "DefaultCurrency" "" "EUR"]
}
# ------------------------------------------------------------------
# Build the form
# ------------------------------------------------------------------
set uom_options [im_cost_uom_options]
set task_type_options [db_list_of_lists uom_options "
select category, category_id
from im_categories
where category_type = 'Intranet Project Type'
"]
set task_type_options [db_list_of_lists uom "select category, category_id from im_categories where category_type = 'Intranet Project Type'"]
set task_type_options [linsert $task_type_options 0 [list "" ""]]
set material_options [im_material_options -include_empty 1]
set include_empty 0
set currency_options [im_currency_options $include_empty]
set project_options [im_project_options -include_empty 1]
set currency_options [im_currency_options 0]
ad_form \
-name price \
......@@ -72,43 +86,41 @@ ad_form \
{uom_id:text(select) {label "[_ intranet-timesheet2-invoices.Unit_of_Measure]"} {options $uom_options} }
{task_type_id:text(im_category_tree),optional {label "[_ intranet-timesheet2-invoices.Task_Type]"} {custom {category_type "Intranet Project Type" translate_p 1 include_empty_p 1}} }
{material_id:text(select),optional {label "[_ intranet-timesheet2-invoices.Material]"} {options $material_options} }
{amount:text(text) {label "[_ intranet-timesheet2-invoices.Amount]"} {html {size 10}}}
{project_id:text(select),optional {label "[_ intranet-core.Project]"} {options $project_options} }
{valid_from:date(date),optional {label "[_ intranet-timesheet2.Start_Date]"} {after_html {<input type="button" style="height:23px; width:23px; background: url('/resources/acs-templating/calendar.gif');" onclick ="return showCalendarWithDateWidget('start_date', 'y-m-d');" >}} }
{valid_through:date(date),optional {label "[_ intranet-timesheet2.End_Date]"} {after_html {<input type="button" style="height:23px; width:23px; background: url('/resources/acs-templating/calendar.gif');" onclick ="return showCalendarWithDateWidget('end_date', 'y-m-d');" >}} }
{price:text(text) {label "[_ intranet-timesheet2-invoices.Price]"} {html {size 10}}}
{currency:text(select) {label "[_ intranet-timesheet2-invoices.Currency]"} {options $currency_options} }
}
ad_form -extend -name price -on_request {
# Populate elements from local variables
} -select_query {
select p.*
from im_timesheet_prices p
where p.price_id = :price_id
} -new_data {
db_dml price_insert "
insert into im_timesheet_prices (
price_id,
uom_id,
company_id,
task_type_id,
material_id,
currency,
price
) values (
:price_id,
:uom_id,
:company_id,
:task_type_id,
:material_id,
:currency,
:amount
)"
insert into im_timesheet_prices (
price_id,
uom_id,
company_id,
task_type_id,
material_id,
currency,
price
) values (
:price_id,
:uom_id,
:company_id,
:task_type_id,
:material_id,
:currency,
:price
)
"
} -edit_data {
db_dml price_update "
update im_prices set
package_name = :package_name,
......@@ -116,17 +128,12 @@ insert into im_timesheet_prices (
name = :name,
url = :url,
sort_order = :sort_order,
parent_price_id = :parent_price_id
parent_price_id = :parent_price_id
where
price_id = :price_id
"
"
} -on_submit {
ns_log Notice "new1: on_submit"
} -after_submit {
ad_returnredirect $return_url
ad_script_abort
}
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