1 <% include("/elements/header.html", 'Batch Customer Note Import') %>
4 <FORM ACTION="process/cust_main_note-import.cgi" METHOD="POST">
7 <SCRIPT TYPE="text/javascript">
9 function clearhint_custnum() {
11 if ( this.value == 'Not found' ) {
13 this.style.color = '#000000';
18 function search_custnum() {
20 this.style.color = '#000000'
22 var custnum_obj = this;
23 var searchrow = this.getAttribute('rownum');
24 var custnum = this.value;
25 var name_obj = document.getElementById('name'+searchrow);
27 if ( custnum == 'searching...' || custnum == 'Not found' )
30 var customer_select = document.getElementById('cust_select'+searchrow);
32 if ( custnum == '' ) {
33 customer_select.selectedIndex = 0;
37 custnum_obj.value = 'searching...';
38 custnum_obj.disabled = true;
39 custnum_obj.style.backgroundColor = '#dddddd';
42 function search_custnum_update(customers) {
44 var customerArray = eval('(' + customers + ')');
46 custnum_obj.disabled = false;
47 custnum_obj.style.backgroundColor = '#ffffff';
49 if ( customerArray.length == 0 ) {
50 custnum_obj.value = 'Not found';
51 custnum_obj.style.color = '#ff0000';
52 } else if ( customerArray.length == 5 ) {
53 var name = customerArray[1];
54 opt(customer_select,custnum,name,'#000000');
55 customer_select.selectedIndex = customer_select.length - 1;
56 custnum_obj.value = custnum;
57 name_obj.value = name;
62 custnum_search( custnum, search_custnum_update );
66 function select_customer() {
68 var custnum = this.options[this.selectedIndex].value;
69 var name = this.options[this.selectedIndex].text;
71 var searchrow = this.getAttribute('rownum');
72 var custnum_obj = document.getElementById('custnum'+searchrow);
73 var name_obj = document.getElementById('name'+searchrow);
75 custnum_obj.value = custnum;
76 custnum_obj.style.color = '#000000';
78 name_obj.value = name;
82 function opt(what,value,text,color) {
83 var optionName = new Option(text, value, false, false);
84 optionName.style.color = color;
85 var length = what.length;
86 what.options[length] = optionName;
89 function previewChanged(what) {
90 var submit_obj = document.getElementById('importsubmit');
92 submit_obj.value = 'Preview note import';
94 submit_obj.value = 'Import notes';
100 <% include('/elements/xmlhttp.html',
101 'url' => $p. 'misc/xmlhttp-cust_main-search.cgi',
102 'subs' => [qw( custnum_search )],
106 % my $fh = $cgi->upload('csvfile');
107 % my $csv = new Text::CSV_XS;
108 % my $skip_fuzzies = $cgi->param('fuzzies') ? 0 : 1;
109 % my $use_agent_custid = $cgi->param('use_agent_custid') ? 1 : 0;
111 % if ( defined($fh) ) {
112 <TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
118 <TH>Note to be added</TH>
120 % my $agentnum = scalar($cgi->param('agentnum'));
123 % while ( defined($line=<$fh>) ) {
124 % $line =~ s/(\S*)\s*$/$1/;
125 % $line =~ s/^(.*)(#!).*/$1/;
127 % $csv->parse($line) or die "can't parse line: " . $csv->error_input();
129 % my @values = $csv->fields();
130 % my $last = shift @values;
131 % if ($last =~ /^\s*(\d+)\s*$/ ) {
133 % $last = shift @values;
135 % my $first = shift @values;
136 % my $note = join ' ', @values;
137 % next unless ( $last || $first || $note );
138 % my @cust_main = ();
139 % warn "searching for: $last, $first" if ($first || $last);
140 % if ($agentnum && $custnum && $use_agent_custid) {
141 % @cust_main = qsearch('cust_main', { 'agent' => $agentnum,
142 % 'agent_custid' => $custnum } );
143 % } elsif ($custnum) { # && !use_agent_custid
144 % @cust_main = qsearch('cust_main', { 'custnum' => $custnum });
146 % @cust_main = FS::cust_main::smart_search(
147 % 'search' => "$last, $first",
148 % 'no_fuzzy_on_exact' => $skip_fuzzies,
150 % if ($first || $last);
155 <INPUT TYPE="text" NAME="custnum<% $row %>" ID="custnum<% $row %>" SIZE=8 MAXLENGTH=12 VALUE="<% $cust_main[0] ? $cust_main[0]->custnum : '' %>" rownum="<% $row %>">
156 <SCRIPT TYPE="text/javascript">
157 var custnum_input<% $row %> = document.getElementById("custnum<% $row %>");
158 custnum_input<% $row %>.onfocus = clearhint_custnum;
159 custnum_input<% $row %>.onchange = search_custnum;
163 <SELECT NAME="cust_select<% $row %>" ID="cust_select<% $row %>" rownum="<% $row %>">
164 <OPTION VALUE="">---</OPTION>
166 % foreach (@cust_main) {
167 <OPTION <% $i ? '' : 'SELECTED' %> VALUE="<% $_->custnum %>"><% $_->name |h %></OPTION>
171 <SCRIPT TYPE="text/javascript">
172 var customer_select<% $row %> = document.getElementById("cust_select<% $row %>");
173 customer_select<% $row %>.onchange = select_customer;
175 <INPUT TYPE="hidden" NAME="name<% $row %>" ID="name<% $row %>" VALUE="<% $i ? $cust_main[0]->name : '' |h %>">
179 <INPUT TYPE="hidden" NAME="first<% $row %>" VALUE="<% $first |h %>">
183 <INPUT TYPE="hidden" NAME="last<% $row %>" VALUE="<% $last |h %>">
187 <INPUT TYPE="hidden" NAME="note<% $row %>" VALUE="<% $note %>">
193 <INPUT TYPE="submit" NAME="submit" ID="importsubmit" VALUE="Import notes">
194 <INPUT TYPE="checkbox" NAME="preview" onchange="previewChanged(this);">
207 unless $FS::CurrentUser::CurrentUser->access_right('Import');