Commit 64175c19 authored by Frank Bergmann's avatar Frank Bergmann

Fixed price upload and added feature for bulk delete, cosine #5668

parent fe13f735
...@@ -72,7 +72,7 @@ ad_proc im_timesheet_price_component { user_id company_id return_url} { ...@@ -72,7 +72,7 @@ ad_proc im_timesheet_price_component { user_id company_id return_url} {
<td class=rowtitle>[lang::message::lookup "" intranet-timesheet2-invoices.From "From"]</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>[lang::message::lookup "" intranet-timesheet2-invoices.Through "Through"]</td>
<td class=rowtitle>[_ intranet-timesheet2-invoices.Rate]</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>" </tr>"
set price_sql " set price_sql "
...@@ -118,7 +118,7 @@ ad_proc im_timesheet_price_component { user_id company_id return_url} { ...@@ -118,7 +118,7 @@ ad_proc im_timesheet_price_component { user_id company_id return_url} {
<td>$valid_from</td> <td>$valid_from</td>
<td>$valid_through</td> <td>$valid_through</td>
<td>[format $price_format $price] $currency</td> <td>[format $price_format $price] $currency</td>
<td><input type=checkbox name=price_id.$price_id></td> <td><input type=checkbox name=price_id.$price_id id=price_id.$price_id></td>
</tr>" </tr>"
incr ctr incr ctr
set old_currency $currency set old_currency $currency
...@@ -141,6 +141,14 @@ ad_proc im_timesheet_price_component { user_id company_id return_url} { ...@@ -141,6 +141,14 @@ ad_proc im_timesheet_price_component { user_id company_id return_url} {
</tr> </tr>
</table> </table>
</form> </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.Through = second.From."]
</ul>
<h4>[_ intranet-core.Admin]</h4>
<ul> <ul>
<li> <li>
<a href=/intranet-timesheet2-invoices/price-lists/[export_vars -base upload-prices {company_id return_url}]> <a href=/intranet-timesheet2-invoices/price-lists/[export_vars -base upload-prices {company_id return_url}]>
...@@ -149,7 +157,17 @@ ad_proc im_timesheet_price_component { user_id company_id return_url} { ...@@ -149,7 +157,17 @@ ad_proc im_timesheet_price_component { user_id company_id return_url} {
<li> <li>
[_ intranet-timesheet2-invoices.lt_Check_this_sample_pra] [_ intranet-timesheet2-invoices.lt_Check_this_sample_pra]
[_ intranet-timesheet2-invoices.lt_It_contains_some_comm] [_ 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 return $price_list_html
} }
......
<!-- packages/intranet-timesheet2-invoices/www/invoices/new-2.adp --> <!-- packages/intranet-timesheet2-invoices/www/invoices/new-2.adp -->
<!-- @author Juanjo Ruiz (juanjoruizx@yahoo.es) --> <!-- @author Juanjo Ruiz (juanjoruizx@yahoo.es) -->
<master>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<master src="../../../intranet-core/www/master">
<property name="doc(title)">@page_title;literal@</property> <property name="doc(title)">@page_title;literal@</property>
<property name="context">@context_bar;literal@</property> <property name="context">@context_bar;literal@</property>
<property name="main_navbar_label">finance</property> <property name="main_navbar_label">finance</property>
@page_body;noquote@ @page_body;noquote@
\ No newline at end of file
...@@ -16,18 +16,21 @@ ad_page_contract { ...@@ -16,18 +16,21 @@ ad_page_contract {
} }
set current_user_id [auth::require_login] set current_user_id [auth::require_login]
set page_title "<#_ Upload New File/URL#>" set page_title [lang::message::lookup "" intranet-timesheet2-invoices.Upload_File "Upload File"]
set page_body "<PRE>\n<A HREF=$return_url><#_ Return to Company Page#></A>\n" 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/cusomers/" "<#_ Clients#>"] "<#_ Upload CSV#>"] 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. # Get the file from the user.
# number_of_bytes is the upper-limit # number_of_bytes is the upper-limit
set max_n_bytes [im_parameter -package_id [im_package_filestorage_id] MaxNumberOfBytes "" 0] set max_n_bytes [im_parameter -package_id [im_package_filestorage_id] MaxNumberOfBytes "" 0]
set tmp_filename [ns_queryget upload_file.tmpfile] set tmp_filename [ns_queryget upload_file.tmpfile]
im_security_alert_check_tmpnam -location "upload-prices-2.tcl" -value $tmp_filename im_security_alert_check_tmpnam -location "upload-prices-2.tcl" -value $tmp_filename
if { $max_n_bytes && ([file size $tmp_filename] > $max_n_bytes) } { 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" 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"
return ad_script_abort
} }
# strip off the C:\directories... crud and just get the file name # strip off the C:\directories... crud and just get the file name
...@@ -37,16 +40,16 @@ if {![regexp {([^//\\]+)$} $upload_file match company_filename]} { ...@@ -37,16 +40,16 @@ if {![regexp {([^//\\]+)$} $upload_file match company_filename]} {
} }
if {[regexp {\.\.} $company_filename]} { if {[regexp {\.\.} $company_filename]} {
set error "<#_ Filename contains forbidden characters#>" set error [lang::message::lookup "" intranet-timesheet2-invoices.Filename_contains_forbidden_characters "Filename contains forbidden characters"]
ad_returnredirect [export_vars -base /error.tcl {error}] ad_return_complaint 1 $error
ad_script_abort
} }
if {![file readable $tmp_filename]} { if {[file readable $tmp_filename]} {
set err_msg "<#_ Unable to read the file '%tmp_filename%'.#> set err_msg "[lang::message::lookup "" intranet-timesheet2-invoices.Unable_to_read_file "Unable to read the file '%tmp_filename%'."]<br>
<#_ Please check the file permissions or price your system administrator.#>" [lang::message::lookup "" intranet-timesheet2-invoices.Please_check_permisions "Please check the file permissions or contact your system administrator."]"
append page_body "\n$err_msg\n" ad_return_complaint 1 $err_msg
ad_return_template ad_script_abort
return
} }
set csv_files_content [im_exec cat $tmp_filename] set csv_files_content [im_exec cat $tmp_filename]
...@@ -60,7 +63,6 @@ set header [string trim [lindex $csv_files 0]] ...@@ -60,7 +63,6 @@ set header [string trim [lindex $csv_files 0]]
set header_csv_fields [split $header ";"] set header_csv_fields [split $header ";"]
set header_len [llength $header_csv_fields] set header_len [llength $header_csv_fields]
append page_body "Title-Length=$header_len\n"
append page_body "\n\n" append page_body "\n\n"
db_dml delete_old_prices "delete from im_timesheet_prices where company_id=:company_id" 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 ...@@ -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} { for {set i 1} {$i < $csv_files_len} {incr i} {
set csv_line [string trim [lindex $csv_files $i]] set csv_line [string trim [lindex $csv_files $i]]
set csv_fields [split $csv_line ";"] set csv_fields [split $csv_line ";"]
append page_body "[lang::message::lookup "" intranet-core.Line Line] $i: $csv_line\n"
append page_body "<#_ Line #%i%#>: $csv_line\n"
# Skip empty lines or line starting with "#" # Skip empty lines or line starting with "#"
if {"" eq [string trim $csv_line]} { continue } if {"" eq [string trim $csv_line]} { continue }
...@@ -110,14 +111,15 @@ for {set i 1} {$i < $csv_files_len} {incr i} { ...@@ -110,14 +111,15 @@ for {set i 1} {$i < $csv_files_len} {incr i} {
set errmsg "" set errmsg ""
if {$uom ne ""} { 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 {$uom_id == 0} { append errmsg "<li>Didn't find UoM '$uom'\n" }
} }
if {$company ne ""} { if {$company ne ""} {
set price_company_id [db_string get_company_id "select company_id from im_companies where company_path = :company" -default 0] 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 {$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')" } 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 ""} { if {$task_type ne ""} {
...@@ -130,20 +132,14 @@ for {set i 1} {$i < $csv_files_len} {incr i} { ...@@ -130,20 +132,14 @@ for {set i 1} {$i < $csv_files_len} {incr i} {
if {"" == $material_id} { if {"" == $material_id} {
set material_id [db_string matid "select material_id from im_materials where lower(trim(material_nr)) = lower(trim(:material))" -default ""] 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 # It doesn't matter whether prices are given in European "," or American "." decimals
regsub {,} $price {.} price regsub {,} $price {.} price
# append page_body "\n"
# append page_body "uom_id=$uom_id\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"
# 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"
set insert_price_sql "INSERT INTO im_timesheet_prices ( set insert_price_sql "INSERT INTO im_timesheet_prices (
price_id, uom_id, company_id, task_type_id, material_id, 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} { ...@@ -154,16 +150,18 @@ for {set i 1} {$i < $csv_files_len} {incr i} {
)" )"
if {$errmsg eq ""} { if {$errmsg eq ""} {
# Execute the insert only if there were no errors
if { [catch { if { [catch {
db_dml insert_price $insert_price_sql db_dml insert_price $insert_price_sql
} err_msg] } { } 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 { } else {
# Otherwise show the list of (conversion) errors
append page_body "<font color=red>$errmsg</font>" 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 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