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 (i think this can
44 # come out now? UI doesn't let you set it
45 my $cust_main = qsearchs('cust_main',
46 { 'custnum' => $param->{"custnum$row"} }
50 ? $cust_main->comments($cust_main->comments. " ". $param->{"note$row"})
51 : $cust_main->comments($param->{"note$row"});
52 $error = $cust_main->replace;
54 $error = "Can't find customer " . $param->{"custnum$row"};
58 my $comments = $param->{"note$row"};
60 if ( $comments =~ /^\s*(\d+)\s*\|\s*(.+)$/ ) {
65 my $cust_main_note = new FS::cust_main_note {
66 'custnum' => $param->{"custnum$row"},
69 'comments' => $comments,
70 'classnum' => $classnum,
72 $error = $cust_main_note->insert unless ($op eq "Preview");
74 my $result = { 'custnum' => $param->{"custnum$row"},
75 'last' => $param->{"last$row"},
76 'first' => $param->{"first$row"},
77 'note' => $param->{"note$row"},
78 'name' => $param->{"name$row"},
82 push @uninserted, $result;
84 push @inserted, $result;
87 push @uninserted, { 'custnum' => '',
88 'last' => $param->{"last$row"},
89 'first' => $param->{"first$row"},
90 'note' => $param->{"note$row"},