From: jeff Date: Tue, 20 Mar 2007 17:03:43 +0000 (+0000) Subject: ticket 1418, a tool for customer note importation X-Git-Tag: TRIXBOX_2_6~586 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=587f0384fb03179f6b504daeada93e193d2ea27f ticket 1418, a tool for customer note importation --- diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 9c4b8bed7..f6270e1d4 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -4115,7 +4115,8 @@ sub fuzzy_search { Accepts the following options: I, the string to search for. The string will be searched for as a customer number, phone number, name or company name, as an exact, or, in some cases, a substring or fuzzy match (see the source code -for the exact heuristics used). +for the exact heuristics used); I, causes smart_search to +skip fuzzy matching when an exact match is found. Any additional options are treated as an additional qualifier on the search (i.e. I). @@ -4132,6 +4133,7 @@ sub smart_search { my @cust_main = (); + my $skip_fuzzy = delete $options{'no_fuzzy_on_exact'}; my $search = delete $options{'search'}; ( my $alphanum_search = $search ) =~ s/\W//g; @@ -4269,7 +4271,7 @@ sub smart_search { #always do substring & fuzzy, #getting complains searches are not returning enough - #unless ( @cust_main ) { #no exact match, trying substring/fuzzy + unless ( @cust_main && $skip_fuzzy ) { #no exact match, trying substring/fuzzy #still some false laziness w/ search/cust_main.cgi @@ -4330,7 +4332,7 @@ sub smart_search { FS::cust_main->fuzzy_search( { $field => $value }, @fuzopts ); } - #} + } #eliminate duplicates my %saw = (); diff --git a/httemplate/misc/cust_main_note-import.cgi b/httemplate/misc/cust_main_note-import.cgi new file mode 100644 index 000000000..07b922f6c --- /dev/null +++ b/httemplate/misc/cust_main_note-import.cgi @@ -0,0 +1,200 @@ +<% include("/elements/header.html", 'Batch Customer Note Import') %> +% + +
+ + + + +<% include('/elements/xmlhttp.html', + 'url' => $p. 'misc/xmlhttp-cust_main-search.cgi', + 'subs' => [qw( custnum_search )], + ) +%> + +% my $fh = $cgi->upload('csvfile'); +% my $csv = new Text::CSV_XS; +% my $skip_fuzzies = $cgi->param('fuzzies') ? 0 : 1; +% +% if ( defined($fh) ) { + + + + + + + + +% my $agentnum => scalar($cgi->param('agentnum')), +% my $line; +% my $row = 0; +% while ( defined($line=<$fh>) ) { +% chomp $line; +% $line =~ s/^(.*)(#!).*/$1/; +% +% $csv->parse($line) or die "can't parse line: " . $csv->error_input(); +% my $custnum = 0; +% my @values = $csv->fields(); +% my $last = shift @values; +% if ($last =~ /^\s*(\d+)\s*$/ ) { +% $custnum = $1; +% $last = shift @values; +% } +% my $first = shift @values; +% my $note = join ' ', @values; +% next unless ( $last || $first || $note ); +% my @cust_main = (); +% warn "searching for: $last, $first" if ($first || $last); +% if ($custnum) { +% @cust_main = qsearch('cust_main', { 'custnum' => $custnum }); +% } else { +% @cust_main = FS::cust_main::smart_search( +% 'search' => "$last, $first", +% 'no_fuzzy_on_exact' => $skip_fuzzies, +% ) +% if ($first || $last); +% } +% + + + + + + + +% $row++; +% } +
Cust #CustomerLastFirstNote to be added
+ + + + + + + + <% $first %> + + + <% $last %> + + + <% $note %> + +
+ + + Preview mode +% } else { + No file supplied +% } + +
+ + diff --git a/httemplate/misc/cust_main_note-import.html b/httemplate/misc/cust_main_note-import.html new file mode 100644 index 000000000..67f49f326 --- /dev/null +++ b/httemplate/misc/cust_main_note-import.html @@ -0,0 +1,32 @@ +<% include("/elements/header.html",'Batch Customer Note Import') %> + +
+ +Import a CSV file containing customer notes records. +

+ +File format is CSV, with the following field order: [custnum], last, first, notefield1, notefield2, notefield3... +
+The optional custnum field is identified by being numeric. +Anything after the character sequence #! is ignored. +

+ +<% &ntable("#cccccc") %> + + + CSV filename + + + + Include additional possibilites when exact match is found + + + + +

+ + +
+ +<% include('/elements/footer.html') %> + diff --git a/httemplate/misc/process/cust_main_note-import.cgi b/httemplate/misc/process/cust_main_note-import.cgi new file mode 100644 index 000000000..af06ae95e --- /dev/null +++ b/httemplate/misc/process/cust_main_note-import.cgi @@ -0,0 +1,66 @@ +<% include("/elements/header.html", "Batch Customer Note Import $op") %> + +The following items <% $op eq 'Preview' ? 'would not be' : 'were not' %> imported. (See below for imported items) +
+%  foreach my $row (@uninserted) {
+%    $csv->combine( (map{ $row->{$_} } qw(last first note) ),
+%                   $row->{error} ? ('#!', $row->{error}) : (),
+%                 );
+<% $csv->string %>
+%  }
+
+ +The following items <% $op eq 'Preview' ? 'would be' : 'were' %> imported. (See above for unimported items) + +
+%  foreach my $row (@inserted) {
+%    $csv->combine( (map{ $row->{$_} } qw(custnum last first note) ),
+%                   ('#!', $row->{name}),
+%                 );
+<% $csv->string %>
+%  }
+
+ +<%init> +my $date = time; +my $otaker = $FS::CurrentUser::CurrentUser->username; +my $csv = new Text::CSV_XS; + +my $param = $cgi->Vars; + +my $op = $param->{preview} ? "Preview" : "Results"; + +my @inserted = (); +my @uninserted = (); +for ( my $row = 0; exists($param->{"custnum$row"}); $row++ ) { + if ( $param->{"custnum$row"} ) { + my $cust_main_note = new FS::cust_main_note { + 'custnum' => $param->{"custnum$row"}, + '_date' => $date, + 'otaker' => $otaker, + 'comments' => $param->{"note$row"}, + }; + my $error = ''; + $error = $cust_main_note->insert unless ($op eq "Preview"); + my $result = { 'custnum' => $param->{"custnum$row"}, + 'last' => $param->{"last$row"}, + 'first' => $param->{"first$row"}, + 'note' => $param->{"note$row"}, + 'name' => $param->{"name$row"}, + 'error' => $error, + }; + if ($error) { + push @uninserted, $result; + }else{ + push @inserted, $result; + } + }else{ + push @uninserted, { 'custnum' => '', + 'last' => $param->{"last$row"}, + 'first' => $param->{"first$row"}, + 'note' => $param->{"note$row"}, + 'error' => '', + }; + } +} +