X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=httemplate%2Felements%2Fcustomer-table.html;h=ed2513d613c9859ad951dc9c0399a061006a5982;hb=3995bf01d2f4bd9c10eb0b209579efd803ccaf89;hp=c3a5df937542132045db9f7bf39f2ee29878d3b8;hpb=99a7600cf4b5986b6f2be8ee1ad871ca77799c6b;p=freeside.git diff --git a/httemplate/elements/customer-table.html b/httemplate/elements/customer-table.html index c3a5df937..ed2513d61 100644 --- a/httemplate/elements/customer-table.html +++ b/httemplate/elements/customer-table.html @@ -67,7 +67,45 @@ Example: this.value = ''; } - + + function update_customer(searchrow, customerArray) { + + var custnum_obj = document.getElementById('custnum'+searchrow); + var customer = document.getElementById('customer'+searchrow); + var customer_select = document.getElementById('cust_select'+searchrow); + + custnum_obj.disabled = false; + custnum_obj.style.backgroundColor = '#ffffff'; + customer.disabled = false; + customer.style.backgroundColor = '#ffffff'; + + if ( customerArray.length == 0 ) { + + custnum_obj.value = 'Not found'; + customer.value = 'Not found'; + custnum_obj.style.color = '#ff0000'; + customer.style.color = '#ff0000'; + + customer.style.display = ''; + customer_select.style.display = 'none'; + return false; + + } else if ( customerArray.length == 5 ) { + + custnum_obj.value = customerArray[0]; + custnum_obj.style.color = '#000000'; + customer.value = customerArray[1]; + + update_balance_text(searchrow, customerArray[2]); + update_status_text( searchrow, customerArray[3]); + update_status_color(searchrow, '#'+customerArray[4]); + + customer.style.display = ''; + customer_select.style.display = 'none'; + return true; + } + } + function <% $opt{prefix} %>search_invnum() { this.style.color = '#000000' @@ -99,51 +137,25 @@ Example: customer_select.style.display = 'none'; var custnum_obj = document.getElementById('custnum'+searchrow); - var balance = document.getElementById('balance'+searchrow); - balance.value = ''; + update_balance_text(searchrow, ''); + update_status_text(searchrow, ''); + update_status_color(searchrow, '#000000'); function search_invnum_update(customers) { var customerArray = eval('(' + customers + ')'); - - custnum_obj.disabled = false; - custnum_obj.style.backgroundColor = '#ffffff'; - customer.disabled = false; - customer.style.backgroundColor = '#ffffff'; - - if ( customerArray.length == 0 ) { - - custnum_obj.value = 'Not found'; - customer.value = 'Not found'; - custnum_obj.style.color = '#ff0000'; - customer.style.color = '#ff0000'; - - customer.style.display = ''; - customer_select.style.display = 'none'; - - } else if ( customerArray.length == 3 ) { - - custnum_obj.value = customerArray[0]; - custnum_obj.style.color = '#000000'; - customer.value = customerArray[1]; - balance.value = customerArray[2]; - - customer.style.display = ''; - customer_select.style.display = 'none'; + update_customer(searchrow, customerArray); % if ( $opt{invnum_update_callback} ) { <% $opt{invnum_update_callback} %>(searchrow, '<% $opt{prefix} %>') % } - } - } invnum_search( invnum, search_invnum_update ); } - function <% $opt{prefix} %>search_custnum() { this.style.color = '#000000' @@ -163,46 +175,68 @@ Example: if ( ( <% $opt{prefix} %>rownum - searchrow ) == 1 ) { <% $opt{prefix} %>addRow(); } - var customer = document.getElementById('customer'+searchrow); - customer.value = 'searching...'; - customer.disabled = true; - customer.style.color = '#000000'; - customer.style.backgroundColor = '#dddddd'; + + var customer_obj = document.getElementById('customer'+searchrow); + customer_obj.value = 'searching...'; + customer_obj.disabled = true; + customer_obj.style.color = '#000000'; + customer_obj.style.backgroundColor = '#dddddd'; var customer_select = document.getElementById('cust_select'+searchrow); - customer.style.display = ''; + customer_obj.style.display = ''; customer_select.style.display = 'none'; var invnum = document.getElementById('invnum'+searchrow); invnum.value = ''; - - var balance = document.getElementById('balance'+searchrow); - balance.value = ''; - function search_custnum_update(name) { + update_balance_text(searchrow, ''); + update_status_text( searchrow, ''); + update_status_color(searchrow, '#000000'); - var name = eval('(' + name + ')' ); + function search_custnum_update(customers) { - customer.disabled = false; - customer.style.backgroundColor = '#ffffff'; + var customerArrayArray = eval('(' + customers + ')') || []; + + if ( customerArrayArray.length == 0 ) { + + update_customer(searchrow, []); - if ( name.length > 0 ) { - customer.value = name; - customer.setAttribute('magic', 'nosearch'); + } else if ( customerArrayArray.length == 1 ) { + + update_customer(searchrow, customerArrayArray[0]); % if ( $opt{custnum_update_callback} ) { - <% $opt{custnum_update_callback} %>(searchrow, '<% $opt{prefix} %>') + <% $opt{custnum_update_callback} %>(searchrow, '<% $opt{prefix} %>') % } + } else { - customer.value = 'Not found'; - customer.style.color = '#ff0000'; + + custnum_obj.value = 'Multiple'; // or something custnum_obj.style.color = '#ff0000'; + //blank the current list + customer_select.options.length = 0; + + opt(customer_select, '', 'Multiple customers match "' + custnum + '" - select one', '#ff0000'); + //add the multiple customers + for ( var s = 0; s < customerArrayArray.length; s++ ) { + opt(customer_select, + JSON.stringify(customerArrayArray[s]), + customerArrayArray[s][1], + '#000000'); + } + + opt(customer_select, 'cancel', '(Edit search string)', '#000000'); + + customer_obj.style.display = 'none'; + + customer_select.style.display = ''; + } } - custnum_search( custnum, search_custnum_update ); + custnum_search(custnum, search_custnum_update ); } @@ -235,34 +269,20 @@ Example: var customer_select = document.getElementById('cust_select'+searchrow); - var balance = document.getElementById('balance'+searchrow); - balance.value = ''; - function search_customer_update(customers) { - var customerArray = eval('(' + customers + ')'); + var customerArrayArray = eval('(' + customers + ')') || [ [] ]; custnum_obj.disabled = false; custnum_obj.style.backgroundColor = '#ffffff'; - if ( customerArray.length == 0 ) { - - custnum_obj.value = 'Not found'; - custnum_obj.style.color = '#ff0000'; - customer_obj.style.color = '#ff0000'; - - customer_obj.style.display = ''; - customer_select.style.display = 'none'; - - } else if ( customerArray.length == 1 ) { + if ( customerArrayArray.length == 0 ) { - custnum_obj.value = customerArray[0][0]; - customer_obj.value = customerArray[0][1]; - balance.value = customerArray[0][2]; + update_customer(searchrow, []); - customer_obj.style.display = ''; - customer_select.style.display = 'none'; + } else if ( customerArrayArray.length == 1 ) { + update_customer(searchrow, customerArrayArray[0]); % if ( $opt{custnum_update_callback} ) { <% $opt{custnum_update_callback} %>(searchrow, '<% $opt{prefix} %>') % } @@ -273,14 +293,16 @@ Example: custnum_obj.style.color = '#ff0000'; //blank the current list - for ( var i = customer_select.length; i >= 0; i-- ) - customer_select.options[i] = null; + customer_select.options.length = 0; opt(customer_select, '', 'Multiple customers match "' + customer + '" - select one', '#ff0000'); - //add the multiple customers - for ( var s = 0; s < customerArray.length; s++ ) - opt(customer_select, customerArray[s][0], customerArray[s][1], '#000000'); + for ( var s = 0; s < customerArrayArray.length; s++ ) { + opt(customer_select, + JSON.stringify(customerArrayArray[s]), + customerArrayArray[s][1], + '#000000'); + } opt(customer_select, 'cancel', '(Edit search string)', '#000000'); @@ -298,16 +320,18 @@ Example: function select_customer() { - var custnum = this.options[this.selectedIndex].value; + var custnum_balance_status = this.options[this.selectedIndex].value; var customer = this.options[this.selectedIndex].text; var searchrow = this.getAttribute('rownum'); var custnum_obj = document.getElementById('custnum'+searchrow); var customer_obj = document.getElementById('customer'+searchrow); + var balance_obj = document.getElementById('balance'+searchrow); + var status_obj = document.getElementById('status'+searchrow); - if ( custnum == '' ) { + if ( custnum_balance_status == '' ) { - } else if ( custnum == 'cancel' ) { + } else if ( custnum_balance_status == 'cancel' ) { custnum_obj.value = ''; custnum_obj.style.color = '#000000'; @@ -317,15 +341,8 @@ Example: customer_obj.focus(); } else { - - custnum_obj.value = custnum; - custnum_obj.style.color = '#000000'; - - customer_obj.value = customer; - customer_obj.style.color = '#000000'; - - this.style.display = 'none'; - customer_obj.style.display = ''; + + update_customer(searchrow, JSON.parse(custnum_balance_status)); % if ( $opt{custnum_update_callback} ) { <% $opt{custnum_update_callback} %>(searchrow, '<% $opt{prefix} %>') @@ -342,6 +359,23 @@ Example: what.options[length] = optionName; } + function update_status_text(rownum, newval) { + document.getElementById('status'+rownum).value = newval; + document.getElementById('status'+rownum+'_text').innerHTML = newval; + } + + function update_status_color(rownum, newval) { + document.getElementById('statuscolor'+rownum).value = newval; + document.getElementById('status'+rownum+'_text').style.color = newval; + } + + function update_balance_text(rownum, newval) { + document.getElementById('balance'+rownum).value = newval; + document.getElementById('balance'+rownum+'_text').innerHTML = newval; + } + + + @@ -349,11 +383,12 @@ Example: + + % foreach my $header ( @{$opt{header}} ) { % } - % my $row = 0; % for ( $row = 0; exists($param->{"custnum$row"}); $row++ ) { @@ -392,6 +427,28 @@ Example: custnum_input<% $row %>.onchange = <% $opt{prefix} %>search_custnum; + + + + % my $col = 0; % foreach my $field ( @{$opt{fields}} ) { % my $value; @@ -447,22 +519,11 @@ Example: % $col++; % } - % } - @@ -566,6 +627,31 @@ Example: custnum_cell.appendChild(custnum_input); row.appendChild(custnum_cell); + + var status_cell = document.createElement('TD'); + status_cell.style.textAlign = 'center'; + + var status_span = document.createElement('SPAN'); + status_span.setAttribute('id', 'status'+<% $opt{prefix} %>rownum+'_text'); + status_span.style.fontWeight = 'bold'; + status_span.setAttribute('rownum', <% $opt{prefix} %>rownum); + status_cell.appendChild(status_span); + + var status_input = document.createElement('INPUT'); + status_input.setAttribute('type', 'hidden'); + status_input.setAttribute('name', 'status'+<% $opt{prefix} %>rownum); + status_input.setAttribute('id', 'status'+<% $opt{prefix} %>rownum); + status_input.setAttribute('rownum', <% $opt{prefix} %>rownum); + status_cell.appendChild(status_input); + + var statuscolor_input = document.createElement('INPUT'); + statuscolor_input.setAttribute('type', 'hidden'); + statuscolor_input.setAttribute('name', 'statuscolor'+<% $opt{prefix} %>rownum); + statuscolor_input.setAttribute('id', 'statuscolor'+<% $opt{prefix} %>rownum); + statuscolor_input.setAttribute('rownum', <% $opt{prefix} %>rownum); + status_cell.appendChild(statuscolor_input); + + row.appendChild(status_cell); var customer_cell = document.createElement('TD'); @@ -590,6 +676,29 @@ Example: customer_cell.appendChild(customer_select); row.appendChild(customer_cell); + + var balance_cell = document.createElement('TD'); + + balance_cell.style.textAlign = 'right'; + balance_cell.appendChild(document.createTextNode('<%$money_char%>')); + + var balance_span = document.createElement('SPAN'); + balance_span.setAttribute('id', 'balance'+<% $opt{prefix} %>rownum+'_text'); + balance_span.setAttribute('rownum', <% $opt{prefix} %>rownum); + balance_cell.appendChild(balance_span); + + balance_cell.appendChild( + document.createTextNode(String.fromCharCode(160)) //  + ); + + var balance_input = document.createElement('INPUT'); + balance_input.setAttribute('type', 'hidden'); + balance_input.setAttribute('name', 'balance'+<% $opt{prefix} %>rownum); + balance_input.setAttribute('id', 'balance'+<% $opt{prefix} %>rownum); + balance_input.setAttribute('rownum', <% $opt{prefix} %>rownum); + balance_cell.appendChild(balance_input); + + row.appendChild(balance_cell); % my $col = 0; % foreach my $field ( @{$opt{fields}} ) { @@ -608,9 +717,10 @@ Example: my_cell.appendChild(my_text); % } +% my $name = (ref($field) eq 'CODE') ? "column${col}_" : $field; var my_input = document.createElement('INPUT'); - my_input.setAttribute('name', '<% $field %>'+<% $opt{prefix} %>rownum); - my_input.setAttribute('id', '<% $field %>'+<% $opt{prefix} %>rownum); + my_input.setAttribute('name', '<% $name %>'+<% $opt{prefix} %>rownum); + my_input.setAttribute('id', '<% $name %>'+<% $opt{prefix} %>rownum); my_input.style.textAlign = '<% $align{ $opt{align}->[$col] || 'l' } %>'; my_input.setAttribute('size', <% $sizes->[$col] || 10 %>); % if ($types->[$col] eq 'immutable') { @@ -627,21 +737,6 @@ Example: % $col++; % } - var balance_cell = document.createElement('TD'); - - var balance_input = document.createElement('INPUT'); - balance_input.setAttribute('name', 'balance'+<% $opt{prefix} %>rownum); - balance_input.setAttribute('id', 'balance'+<% $opt{prefix} %>rownum); - balance_input.style.textAlign = 'right'; - balance_input.setAttribute('size', 8); - balance_input.setAttribute('maxlength', 12); - balance_input.setAttribute('rownum', <% $opt{prefix} %>rownum); - balance_input.disabled = true; - balance_input.style.backgroundColor = '#dddddd'; - balance_cell.appendChild(balance_input); - - row.appendChild(balance_cell); - //update the total # of rows display if ( <% $opt{prefix} %>rownum == 1 ) { <% $opt{prefix} %>total_el.innerHTML = @@ -667,11 +762,12 @@ Example: <%init> my(%opt) = @_; +my $conf = new FS::Conf; $opt{prefix} = '' unless defined $opt{prefix}; $opt{prefix} .= '_' if $opt{prefix}; -my $types = $opt{'types'} ? [ @{$opt{'types'}} ] : []; +my $types = $opt{'type'} ? [ @{$opt{'type'}} ] : []; my $sizes = $opt{'size'} ? [ @{$opt{'size'}} ] : []; my $param = $opt{param}; @@ -687,4 +783,5 @@ my %align = ( 'c' => 'center', ); +my $money_char = $conf->config('money_char') || '$';
Inv # Cust #Status CustomerBalance<% $header %>Balance
+ " + + ><% $param->{"status$row"} %> + " + rownum = "<% $row %>" + > + " + rownum = "<% $row %>" + > + " rownum="<% $row %>"> @@ -409,6 +466,21 @@ Example: + <% $money_char %> + <% $param->{"balance$row"} %> +   + " + rownum = "<% $row %>" + > + - " - rownum = "<% $row %>" - > -
+ Total <% $row ? $row-1 : 0 %> <% PL($opt{name_singular} || 'customer', ( $row ? $row-1 : 0 ) ) %>