Permalink
Browse files

wrote upgrade script cnauto-core

  • Loading branch information...
2 parents 5ca3bd0 + 5c0e991 commit b520fd511638999b8865611dbb668fc72e9490a4 Iuri Sampaio committed Mar 22, 2012
@@ -1,4 +1,4 @@
--- /packages/cnauto-core/sql/postgresql/upgrade/upgrade-0.1d-0.2d.sql
+-- /packages/cnauto-core/sql/postgresql/upgrade/upgrade-0.3d-0.4d.sql
SELECT acs_log__debug ('/packages/cnauto-core/sql/postgresql/upgrade/upgrade-0.3d-0.4d.sql','');
@@ -578,3 +578,91 @@ ad_proc -public cn_core::export_csv_to_txt {
}
+
+
+
+
+ad_proc -public cn_core::import_csv_file_abeiva {
+ {-input_file}
+} {
+ Import Abeiva's spreadsheet
+
+} {
+
+ ns_log Notice "Running ad_proc export_csv_to_txt"
+ # Input File
+ set input_file [open "${input_file}" r]
+ set lines [split [read $input_file] \n]
+
+ set items [list]
+ set i 0
+ set duplicated 0
+
+ set count_towner 0
+ set count_topic 0
+
+ foreach line $lines {
+ set line [split $line ";"]
+
+ if {$line ne ""} {
+ ns_log Notice "LINE: $line"
+
+ # Date
+ set date [lindex $line 0]
+ set date [split $date /]
+ set date "[lindex $date 2]-[lindex $date 1]-[lindex $date 0]"
+
+ if {$date ne "--data"} {
+ set month [db_string select_month {
+ SELECT EXTRACT (month from timestamp :date)
+ }]
+ set year [db_string select_year {
+ SELECT EXTRACT (year from timestamp :date)
+ }]
+
+ ns_log Notice "$month $year"
+
+
+ # Chassis
+ set chassis [lindex $line 1]
+
+ set exists_p [item_exists -items $items -chassi $chassis]
+
+ #ns_log Notice "EXISTS $exists_p"
+ if {$exists_p == 1} {
+ incr duplicated
+ }
+
+ if {$exists_p == 0} {
+
+ lappend items $chassis
+
+ if {$month eq 12 && $year eq 2011} {
+ if {[regexp -all {LSY} $chassis]} {
+ incr count_topic
+ }
+ if {[regexp -all {LKH} $chassis]} {
+ incr count_towner
+ }
+
+ incr i
+ }
+ }
+ set model [lindex $line 2]
+ set description [lindex $line 3]
+ set fabricant [lindex $line 4]
+ set municipality [lindex $line 5]
+ set state [lindex $line 6]
+
+ ns_log Notice "$date | $chassis | $model | $description | $fabricant | $municipality | $state"
+
+ }
+ }
+ }
+
+ ns_log Notice "Total $i | Towners: $count_towner | Topics: $count_topic"
+
+ close $input_file
+
+ return
+}
@@ -0,0 +1,6 @@
+<master>
+ <property name="title">@title;noquote@</property>
+ <property name="title">@context;noquote@</property>
+
+<h1>@title;noquote@</h1>
+<formtemplate id="import_file"></formtemplate>
@@ -0,0 +1,24 @@
+ad_page_contract {
+ Import file from abeiva spreadsheet
+
+ @author Iuri Sampaio (iuri.sampaio@iurix.com)
+ @creation-date 2012-03-16
+} {
+ {return_url ""}
+}
+
+set title "#cnauto-core.Import_file# ABEIVA"
+set context $title
+
+
+ad_form -html { enctype multipart/form-data } -name import_file -form {
+ {input_file:file {label "#cnauto-core.Input_file#"} {html "size 30"}}
+} -on_submit {
+
+ set input_file [list [template::util::file::get_property tmp_filename $input_file]]
+ cn_core::import_csv_file_abeiva -input_file $input_file
+
+} -after_submit {
+ ad_returnredirect /cnauto-core
+ ad_script_abort
+}
@@ -17,7 +17,7 @@ ad_form -html { enctype multipart/form-data } -name export_file -form {
} -on_submit {
set input_file [list [template::util::file::get_property tmp_filename $input_file]]
- cnauto_core::export_csv_to_txt -input_file $input_file -output_file $output_file
+ cn_core::export_csv_to_txt -input_file $input_file -output_file $output_file
} -after_submit {
ad_returnredirect /cnauto-core
@@ -7,7 +7,7 @@
<ul>
<li><a href="@categories_url@">#cnauto-resources.Categories#</a></li>
-
<li><a href="@export_url@">B.A. #cnauto.Export_file#</a></li>
- <li><a href="@import_url@">Cotia #cnauto.Import_file#</a></li>
+ <li><a href="@import_cotia_url@">Cotia #cnauto.Import_file#</a></li>
+ <li><a href="@import_abeiva_url@">ABEIVA #cnauto.Import_file#</a></li>
<ul>
@@ -13,6 +13,9 @@ set context [list]
set return_url [ad_conn url]
set export_url [export_vars -base "ba-file" {return_url}]
-set import_url [export_vars -base "cotia-import-xml" {return_url}]
+
+set import_cotia_url [export_vars -base "cotia-import-xml" {return_url}]
+
+set import_abeiva_url [export_vars -base "abeiva-file" {return_url}]
set categories_url [export_vars -base "categories" {return_url}]

0 comments on commit b520fd5

Please sign in to comment.