Commit 2808f704 authored by Frank Bergmann's avatar Frank Bergmann
parents ecf94ac4 6a1a038d
......@@ -39,7 +39,6 @@ ad_proc -public im_timesheet_invoice_permissions {
set admin_p 0
im_cost_permissions $current_user_id $invoice_id view_p read_p write_p admin_p
}
......@@ -66,14 +65,14 @@ ad_proc im_timesheet_price_component { user_id 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>[lang::message::lookup "" intranet-timesheet2-invoices.Project "Project"]</td>
<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>
<td class=rowtitle><input type='checkbox' name='_dummy' id='pricelist-bulkaction-control' title='Check/uncheck all rows'></td>
</tr>"
set price_sql "
......@@ -85,6 +84,7 @@ ad_proc im_timesheet_price_component { user_id company_id return_url} {
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_name,
p.project_nr
from
im_timesheet_prices tp
......@@ -94,9 +94,11 @@ ad_proc im_timesheet_price_component { user_id company_id return_url} {
tp.company_id = :company_id
order by
tp.currency,
tp.uom_id,
tp.material_id,
tp.task_type_id desc
p.project_name,
coalesce(tp.uom_id, 0),
coalesce(tp.task_type_id, 0) desc,
coalesce(tp.material_id, 0),
coalesce(tp.valid_from, '2000-01-01'::date)
"
set price_rows_html ""
......@@ -112,14 +114,14 @@ ad_proc im_timesheet_price_component { user_id company_id return_url} {
append price_rows_html "
<tr $bgcolor([expr {$ctr % 2}]) nobreak>
<td><a href='$url'>$uom</a></td>
<td>$project_name</td>
<td>$uom</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>
<td><a href='$url'>[format $price_format $price] $currency</a></td>
<td><input type=checkbox name=price_id.$price_id id=price_id.$price_id></td>
</tr>"
incr ctr
set old_currency $currency
......@@ -142,6 +144,14 @@ ad_proc im_timesheet_price_component { user_id company_id return_url} {
</tr>
</table>
</form>
<ul>
<li>[_ intranet-core.Note]:
[lang::message::lookup "" intranet-timesheet2-invoices.From_and_Through_overlap_bla "
From and Through dates are time points at 0:00 midnight of their specific date,<br>
so sequential prices should have first.valid_through = second.valid_from."]
</ul>
<h4>[_ intranet-core.Admin]</h4>
<ul>
<li>
<a href=/intranet-timesheet2-invoices/price-lists/[export_vars -base upload-prices {company_id return_url}]>
......@@ -150,7 +160,17 @@ ad_proc im_timesheet_price_component { user_id company_id return_url} {
<li>
[_ intranet-timesheet2-invoices.lt_Check_this_sample_pra]
[_ intranet-timesheet2-invoices.lt_It_contains_some_comm]
</ul>\n"
</ul>
<script type='text/javascript' nonce='[im_csp_nonce]'>
var e = document.getElementById('pricelist-bulkaction-control');
if (e !== null) {
e.addEventListener('click', function (event) {
acs_ListCheckAll('price_id', this.checked);
}, false);
}
</script>
"
return $price_list_html
}
......@@ -403,13 +423,10 @@ ad_proc im_timesheet_invoicing_project_hierarchy {
# ------------------------------------------------------
# Promote invoice to timesheet invoice
# ------------------------------------------------------
ad_proc -public im_timesheet_invoice_promote_invoice {
-invoice_id:required
} {
......
......@@ -287,7 +287,7 @@ if {$aggregate_tasks_p} {
sum(t.units_in_interval) as interval_sum,
sum(t.unbilled_units) as unbilled_sum,
parent.project_id as project_id,
'' as outline_nr,
''::varchar as outline_nr,
parent.project_id as task_id,
im_material_name_from_id(t.task_material_id) || ' - ' || im_category_from_id(t.task_type_id) as task_name,
t.task_type_id,
......
<!-- packages/intranet-timesheet2-invoices/www/invoices/new-2.adp -->
<!-- @author Juanjo Ruiz (juanjoruizx@yahoo.es) -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<master src="../../../intranet-core/www/master">
<master>
<property name="doc(title)">@page_title;literal@</property>
<property name="context">@context_bar;literal@</property>
<property name="main_navbar_label">finance</property>
@page_body;noquote@
\ No newline at end of file
@page_body;noquote@
......@@ -16,18 +16,21 @@ ad_page_contract {
}
set current_user_id [auth::require_login]
set page_title "<#_ Upload New File/URL#>"
set page_body "<PRE>\n<A HREF=$return_url><#_ Return to Company Page#></A>\n"
set context_bar [im_context_bar [list "/intranet/cusomers/" "<#_ Clients#>"] "<#_ Upload CSV#>"]
set page_title [lang::message::lookup "" intranet-timesheet2-invoices.Upload_File "Upload File"]
set page_body "<pre>\n<a HREF=$return_url>[lang::message::lookup "" intranet-timesheet2-invoices.Return_to_company_page "Return to company page"]</a>\n"
set context_bar [im_context_bar [list \
"/intranet/customers/" \
[lang::message::lookup "" intranet-timesheet2-invoices.Customers Customers] \
[lang::message::lookup "" intranet-timesheet2-invoices.Upload_CSV "Upload CSV"]]]
# Get the file from the user.
# number_of_bytes is the upper-limit
set max_n_bytes [im_parameter -package_id [im_package_filestorage_id] MaxNumberOfBytes "" 0]
set tmp_filename [ns_queryget upload_file.tmpfile]
im_security_alert_check_tmpnam -location "upload-prices-2.tcl" -value $tmp_filename
if { $max_n_bytes && ([file size $tmp_filename] > $max_n_bytes) } {
ad_return_complaint 1 "<#_ Your file is larger than the maximum permissible upload size#>: [util_commify_number $max_n_bytes] bytes"
return
if {$max_n_bytes && ([file size $tmp_filename] > $max_n_bytes)} {
ad_return_complaint 1 "[lang::message::lookup "" intranet-timesheet2-invoices.File_too_large "Your file is larger than the maximum permissible upload size"]: [util_commify_number $max_n_bytes] bytes"
ad_script_abort
}
# strip off the C:\directories... crud and just get the file name
......@@ -37,16 +40,16 @@ if {![regexp {([^//\\]+)$} $upload_file match company_filename]} {
}
if {[regexp {\.\.} $company_filename]} {
set error "<#_ Filename contains forbidden characters#>"
ad_returnredirect [export_vars -base /error.tcl {error}]
set error [lang::message::lookup "" intranet-timesheet2-invoices.Filename_contains_forbidden_characters "Filename contains forbidden characters"]
ad_return_complaint 1 $error
ad_script_abort
}
if {![file readable $tmp_filename]} {
set err_msg "<#_ Unable to read the file '%tmp_filename%'.#>
<#_ Please check the file permissions or price your system administrator.#>"
append page_body "\n$err_msg\n"
ad_return_template
return
if {[file readable $tmp_filename]} {
set err_msg "[lang::message::lookup "" intranet-timesheet2-invoices.Unable_to_read_file "Unable to read the file '%tmp_filename%'."]<br>
[lang::message::lookup "" intranet-timesheet2-invoices.Please_check_permisions "Please check the file permissions or contact your system administrator."]"
ad_return_complaint 1 $err_msg
ad_script_abort
}
set csv_files_content [im_exec cat $tmp_filename]
......@@ -60,7 +63,6 @@ set header [string trim [lindex $csv_files 0]]
set header_csv_fields [split $header ";"]
set header_len [llength $header_csv_fields]
append page_body "Title-Length=$header_len\n"
append page_body "\n\n"
db_dml delete_old_prices "delete from im_timesheet_prices where company_id=:company_id"
......@@ -68,8 +70,7 @@ db_dml delete_old_prices "delete from im_timesheet_prices where company_id=:comp
for {set i 1} {$i < $csv_files_len} {incr i} {
set csv_line [string trim [lindex $csv_files $i]]
set csv_fields [split $csv_line ";"]
append page_body "<#_ Line #%i%#>: $csv_line\n"
append page_body "[lang::message::lookup "" intranet-core.Line Line] $i: $csv_line\n"
# Skip empty lines or line starting with "#"
if {"" eq [string trim $csv_line]} { continue }
......@@ -110,14 +111,15 @@ for {set i 1} {$i < $csv_files_len} {incr i} {
set errmsg ""
if {$uom ne ""} {
set uom_id [db_string get_uom_id "select category_id from im_categories where category_type='Intranet UoM' and category=:uom" -default 0]
set uom_id [db_string get_uom_id "select category_id from im_categories where category_type = 'Intranet UoM' and lower(trim(category)) = lower(trim(:uom))" -default 0]
if {$uom_id == 0} { append errmsg "<li>Didn't find UoM '$uom'\n" }
}
if {$company ne ""} {
set price_company_id [db_string get_company_id "select company_id from im_companies where company_path = :company" -default 0]
if {$price_company_id == 0} { append errmsg "<li>Didn't find Company '$company'\n" }
if {$price_company_id != $company_id} { append errmsg "<li>Uploading prices for the wrong company ('$price_company_id' instead of '$company_id')" }
set price_company_id [db_string get_company_id "select company_id from im_companies where lower(trim(company_path)) = lower(trim(:company))" -default 0]
if {$price_company_id == 0} { append errmsg "<li>Didn't find Company '$company'\n" }
if {"company_path" eq $company} { append errmsg "<li>Please replace example 'company_path' with the company path of the real company\n" }
if {$price_company_id != $company_id} { append errmsg "<li>Uploading prices for the wrong company ('$price_company_id' instead of '$company_id')\n" }
}
if {$task_type ne ""} {
......@@ -130,20 +132,14 @@ for {set i 1} {$i < $csv_files_len} {incr i} {
if {"" == $material_id} {
set material_id [db_string matid "select material_id from im_materials where lower(trim(material_nr)) = lower(trim(:material))" -default ""]
}
if {"" == $material_id} { append errmsg "<li>Didn't find material='$material' neither in name nor number of any material\n" }
}
# It doesn't matter whether prices are given in European "," or American "." decimals
regsub {,} $price {.} price
# append page_body "\n"
# append page_body "uom_id=$uom_id\n"
# append page_body "price_company_id=$price_company_id\n"
# append page_body "task_type_id=$task_type_id\n"
# append page_body "material_id=$material_id\n"
# append page_body "valid_from=$valid_from\n"
# append page_body "valid_through=$valid_through\n"
# append page_body "price=$price\n"
# append page_body "currency=$currency\n"
# append page_body "[lang::message::lookup "" intranet-core.Line Line] $i: uom_id=$uom_id, price_company_id=$price_company_id, task_type_id=$task_type_id, material_id=$material_id, valid_from=$valid_from, valid_through=$valid_through, price=$price, currency=$currency\n"
set insert_price_sql "INSERT INTO im_timesheet_prices (
price_id, uom_id, company_id, task_type_id, material_id,
......@@ -154,16 +150,18 @@ for {set i 1} {$i < $csv_files_len} {incr i} {
)"
if {$errmsg eq ""} {
# Execute the insert only if there were no errors
if { [catch {
db_dml insert_price $insert_price_sql
} err_msg] } {
append page_body \n<font color=red>$err_msg</font>\n";
append page_body "\n<font color=red>$err_msg</font>\n";
}
} else {
# Otherwise show the list of (conversion) errors
append page_body "<font color=red>$errmsg</font>"
}
}
append page_body "\n<A HREF=$return_url><#_ Return to Project Page#></A>\n"
append page_body "\n<a HREF=$return_url>[lang::message::lookup "" intranet-timesheet2-invoices.Return_to_company_page "Return to company page"]</a>\n"
ad_return_template
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