1 <% include("/elements/header.html", "Batch Customer Note Import $op") %>
3 The following items <% $op eq 'Preview' ? 'would not be' : 'were not' %> imported. (See below for imported items)
5 % foreach my $row (@uninserted) {
6 % $csv->combine( (map{ $row->{$_} } qw(last first note) ),
7 % $row->{error} ? ('#!', $row->{error}) : (),
13 The following items <% $op eq 'Preview' ? 'would be' : 'were' %> imported. (See above for unimported items)
16 % foreach my $row (@inserted) {
17 % $csv->combine( (map{ $row->{$_} } qw(custnum last first note) ),
18 % ('#!', $row->{name}),
27 unless $FS::CurrentUser::CurrentUser->access_right('Import');
29 $FS::cust_main::import=1; # the customer records are already in the database
31 my $otaker = $FS::CurrentUser::CurrentUser->username;
32 my $csv = new Text::CSV_XS;
34 my $param = $cgi->Vars;
36 my $op = $param->{preview} ? "Preview" : "Results";
40 for ( my $row = 0; exists($param->{"custnum$row"}); $row++ ) {
41 if ( $param->{"custnum$row"} ) {
43 if ( $param->{use_comments} ) { # why? notes are sexier
44 my $cust_main = qsearchs('cust_main',
45 { 'custnum' => $param->{"custnum$row"} }
49 ? $cust_main->comments($cust_main->comments. " ". $param->{"note$row"})
50 : $cust_main->comments($param->{"note$row"});
51 $error = $cust_main->replace;
53 $error = "Can't find customer " . $param->{"custnum$row"};
56 my $cust_main_note = new FS::cust_main_note {
57 'custnum' => $param->{"custnum$row"},
60 'comments' => $param->{"note$row"},
62 $error = $cust_main_note->insert unless ($op eq "Preview");
64 my $result = { 'custnum' => $param->{"custnum$row"},
65 'last' => $param->{"last$row"},
66 'first' => $param->{"first$row"},
67 'note' => $param->{"note$row"},
68 'name' => $param->{"name$row"},
72 push @uninserted, $result;
74 push @inserted, $result;
77 push @uninserted, { 'custnum' => '',
78 'last' => $param->{"last$row"},
79 'first' => $param->{"first$row"},
80 'note' => $param->{"note$row"},