diff options
| -rwxr-xr-x | httemplate/browse/cust_main_county.cgi | 383 | ||||
| -rwxr-xr-x | httemplate/edit/cust_main_county-expand.cgi | 122 | ||||
| -rw-r--r-- | httemplate/edit/cust_main_county.html | 62 | ||||
| -rwxr-xr-x | httemplate/edit/process/cust_main_county-expand.cgi | 112 | ||||
| -rw-r--r-- | httemplate/edit/process/cust_main_county.html | 6 | ||||
| -rw-r--r-- | httemplate/search/elements/search.html | 112 | 
6 files changed, 496 insertions, 301 deletions
diff --git a/httemplate/browse/cust_main_county.cgi b/httemplate/browse/cust_main_county.cgi index 3bbbb4b47..3e67b1122 100755 --- a/httemplate/browse/cust_main_county.cgi +++ b/httemplate/browse/cust_main_county.cgi @@ -1,170 +1,225 @@ -<% include('/elements/header.html', "Tax Rate Listing", menubar( -  'Edit tax rates' => $p. "edit/cust_main_county.cgi", -)) %> - -    Click on <u>expand country</u> to specify a country's tax rates by state. -    <BR>Click on <u>expand state</u> to specify a state's tax rates by county. -% -%my $conf = new FS::Conf; -%my $enable_taxclasses = $conf->exists('enable_taxclasses'); -% -%if ( $enable_taxclasses ) {  - - -  <BR>Click on <u>expand taxclasses</u> to specify tax classes -% }  - - -<BR><BR> -<% table() %> - -  <TR> -    <TH><FONT SIZE=-1>Country</FONT></TH> -    <TH><FONT SIZE=-1>State</FONT></TH> -    <TH>County</TH> -    <TH>Taxclass<BR><FONT SIZE=-1>(per-package classification)</FONT></TH> -    <TH>Tax name<BR><FONT SIZE=-1>(printed on invoices)</FONT></TH> -    <TH><FONT SIZE=-1>Tax</FONT></TH> -    <TH><FONT SIZE=-1>Exemption</TH> -  </TR> -% -%my @regions = sort {    $a->country  cmp $b->country -%                     or $a->state    cmp $b->state -%                     or $a->county   cmp $b->county -%                     or $a->taxclass cmp $b->taxclass -%                   } qsearch('cust_main_county',{}); -% -%my $sup=0; -%#foreach $cust_main_county ( @regions ) { -%for ( my $i=0; $i<@regions; $i++ ) {  -%  my $cust_main_county = $regions[$i]; -%  my $hashref = $cust_main_county->hashref; -% -%   - -      <TR> -        <TD BGCOLOR="#ffffff"><% $hashref->{country} %></TD> -% -% -%  my $j; -%  if ( $sup ) { -%    $sup--; -%  } else { +<% include( 'elements/browse.html', +     'title'          => 'Tax Rates', +     'name_singular'  => 'tax rate', +     'html_init'      => $html_init, +     'html_posttotal' => $html_posttotal, +     'query'          => { +                           'table'    => 'cust_main_county', +                           'hashref'  => $hashref, +                           'order_by' => +                             'ORDER BY country, state, county, taxclass', +                         }, +     'count_query'    => $count_query, +     'header'         => \@header, +     'header2'        => \@header2, +     'fields'         => \@fields, +     'align'          => $align, +     'color'          => \@color, +     'cell_style'     => \@cell_style, +     'links'          => \@links, +     'link_onclicks'  => \@link_onclicks, +  ) +%>  % -%    #lookahead -%    for ( $j=1; $i+$j<@regions; $j++ ) { -%      last if $hashref->{country} ne $regions[$i+$j]->country -%           || $hashref->{state} ne $regions[$i+$j]->state -%           || $hashref->{tax} != $regions[$i+$j]->tax -%           || $hashref->{exempt_amount} != $regions[$i+$j]->exempt_amount -%           || $hashref->{setuptax} ne $regions[$i+$j]->setuptax -%           || $hashref->{recurtax} ne $regions[$i+$j]->recurtax; -%    } +% #         <FONT SIZE=-1><A HREF="<% $p %>edit/process/cust_main_county-collapse.cgi?<% $hashref->{taxnum} %>">collapse state</A></FONT> +% # % }   % -%    my $newsup=0; -%    if ( $j>1 && $i+$j+1 < @regions -%         && ( $hashref->{state} ne $regions[$i+$j+1]->state  -%              || $hashref->{country} ne $regions[$i+$j+1]->country -%              ) -%         && ( ! $i -%              || $hashref->{state} ne $regions[$i-1]->state  -%              || $hashref->{country} ne $regions[$i-1]->country -%              ) -%       ) { -%       $sup = $j-1; -%    } else { -%      $j = 1; -%    } -% -%     - - -    <TD ROWSPAN=<% $j %><% -      $hashref->{state} -        ? ' BGCOLOR="#ffffff">'. $hashref->{state} -        : qq! BGCOLOR="#cccccc">(ALL) <FONT SIZE=-1>!. -          qq!<A HREF="${p}edit/cust_main_county-expand.cgi?!. $hashref->{taxnum}. -          qq!">expand country</A></FONT>! -      %> -% if ( $j>1 ) {  - -        <FONT SIZE=-1><A HREF="<% $p %>edit/process/cust_main_county-collapse.cgi?<% $hashref->{taxnum} %>">collapse state</A></FONT> -% }  - - -    </TD> -% }  -% #  $sup=$newsup;  - - -    <TD -% if ( $hashref->{county} ) { -%             - BGCOLOR="#ffffff"><% $hashref->{county} %> -% } else { -%             - BGCOLOR="#cccccc">(ALL) -% if ( $hashref->{state} ) {  - -                 <FONT SIZE=-1><A HREF="<% $p %>edit/cust_main_county-expand.cgi?<% $hashref->{taxnum} %>">expand state</A></FONT> -% }  -% }  - -    </TD> - -    <TD -% if ( $hashref->{taxclass} ) { -%             - BGCOLOR="#ffffff"><% $hashref->{taxclass} %> -% } else { -%             - BGCOLOR="#cccccc">(ALL) -% if ( $enable_taxclasses ) {  - -                 <FONT SIZE=-1><A HREF="<% $p %>edit/cust_main_county-expand.cgi?taxclass<% $hashref->{taxnum} %>">expand taxclasses</A></FONT> -% }  -% }  - -    </TD> - -    <TD -% if ( $hashref->{taxname} ) { -%             - BGCOLOR="#ffffff"><% $hashref->{taxname} %> -% } else { -%             - BGCOLOR="#cccccc">Tax -% }  - -    </TD> - -    <TD BGCOLOR="#ffffff"><% $hashref->{tax} %>%</TD> - -    <TD BGCOLOR="#ffffff"> -% if ( $hashref->{exempt_amount} > 0 ) {  - -        $<% sprintf("%.2f", $hashref->{exempt_amount} ) %> per month<BR> -% }  -% if ( $hashref->{setuptax} =~ /^Y$/i ) {  - -        Setup fee<BR> -% }  -% if ( $hashref->{recurtax} =~ /^Y$/i ) {  - -        Recurring fee<BR> -% }  - - -    </TD> - -  </TR> -% }  - - -</TABLE> - -<% include('/elements/footer.html') %> +<%once> + +my $conf = new FS::Conf; +my $money_char = $conf->config('money_char') || '$'; + +my @manual_countries = ( 'US', 'CA', 'AU', 'NZ', 'GB' ); #some manual ordering +my @all_countries = ( @manual_countries,  +                      grep { my $c = $_; ! grep { $c eq $_ } @manual_countries } +                      map { $_->country }  +                          qsearch({ +                                    'select'    => 'country', +                                    'table'     => 'cust_main_county', +                                    'hashref'   => {}, +                                    'extra_sql' => 'GROUP BY country', +                                 }) +                    ); + +my $exempt_sub = sub { +  my $cust_main_county = shift; + +  my @exempt = (); +  push @exempt, +       sprintf("$money_char%.2f per month", $cust_main_county->exempt_amount ) +    if $cust_main_county->exempt_amount > 0; + +  push @exempt, 'Setup fee' +    if $cust_main_county->setuptax =~ /^Y$/i; + +  push @exempt, 'Recurring fee' +    if $cust_main_county->recurtax =~ /^Y$/i; + +  [ map [ {'data'=>$_} ], @exempt ]; +}; + +my $oldrow; +my $cell_style; +my $cell_style_sub = sub { +  my $row = shift; +  if ( $oldrow ne $row ) { +    if ( $oldrow ) { +      if ( $oldrow->country ne $row->country ) { +        $cell_style = 'border-top:1px solid #000000'; +      } elsif ( $oldrow->state ne $row->state ) { +        $cell_style = 'border-top:1px solid #cccccc'; #default? +      } elsif ( $oldrow->state eq $row->state ) { +        #$cell_style = 'border-top:dashed 1px dark gray'; +        $cell_style = 'border-top:1px dashed #cccccc'; +      } +    } +    $oldrow = $row; +  } +  return $cell_style; +}; + +#my $edit_link = [ "${p}edit/cust_main_county.html", 'taxnum' ]; +my $edit_link = [ 'javascript:void(0);', sub { ''; } ]; + +my $edit_onclick = sub { +  my $row = shift; +  my $taxnum = $row->taxnum; +  my $color = '#333399'; +  qq!overlib( OLiframeContent('${p}edit/cust_main_county.html?$taxnum', 540, 420, 'edit_cust_main_county_popup' ), CAPTION, 'Edit tax rate', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK, BGCOLOR, '$color', CGCOLOR, '$color' ); return false;!; +}; + +sub expand_link { +  my( $row, $desc, %opt ) = @_; +  my $taxnum = $row->taxnum; +  $taxnum = "taxclass$taxnum" if $opt{'taxclass'}; +  my $color = '#333399'; +  qq!<FONT SIZE="-1"><A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}edit/cust_main_county-expand.cgi?$taxnum', 540, 420, 'edit_cust_main_county_popup' ), CAPTION, '$desc', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK, BGCOLOR, '$color', CGCOLOR, '$color' ); return false;">!; +} + +</%once>  <%init> +  die "access denied"    unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +#my $conf = new FS::Conf; +#my $money_char = $conf->config('money_char') || '$'; +my $enable_taxclasses = $conf->exists('enable_taxclasses'); + +my $html_init = +  "Click on <u>add states</u> to specify a country's tax rates by state or province. +   <BR>Click on <u>add counties</u> to specify a state's tax rates by county."; +$html_init .= "<BR>Click on <u>add taxclasses</u> to specify tax classes." +  if $enable_taxclasses; +$html_init .= '<BR><BR>'; + +$html_init .= qq( +  <SCRIPT TYPE="text/javascript" SRC="${fsurl}elements/overlibmws.js"></SCRIPT> +  <SCRIPT TYPE="text/javascript" SRC="${fsurl}elements/overlibmws_iframe.js"></SCRIPT> +  <SCRIPT TYPE="text/javascript" SRC="${fsurl}elements/overlibmws_draggable.js"></SCRIPT> +  <SCRIPT TYPE="text/javascript" SRC="${fsurl}elements/iframecontentmws.js"></SCRIPT> +); + +my $filter_country = ''; +if ( $cgi->param('filter_country') =~ /^(\w\w)$/ ) { +  $filter_country = $1; +} +$cgi->delete('filter_country'); +$cgi->param('dummy', 1); + +my $country_filter_change = +  "window.location = '". +  $cgi->self_url. ";filter_country=' + this.options[this.selectedIndex].value;"; + +my $html_posttotal = +  '(show country: '. +  qq(<SELECT NAME="filter_country" onChange="$country_filter_change">). +  qq(<OPTION VALUE="">(all)\n). +  join("\n", map qq[<OPTION VALUE="$_"]. +                   ( $_ eq $filter_country ? 'SELECTED' : '' ). +                   '>'. code2country($_). " ($_)", +                 @all_countries +      ). +  '</SELECT>)'; + +my $hashref = {}; +my $count_query = 'SELECT COUNT(*) FROM cust_main_county'; +if ( $filter_country ) { +  $hashref->{'country'} = $filter_country; +  $count_query .= " WHERE country = '$filter_country'"; +} + +$cell_style = ''; + +my @header        = ( 'Country', 'State/Province', 'County',); +my @header2       = ( '', '', '', ); +my @links         = ( '', '', '', ); +my @link_onclicks = ( '', '', '', ); +my $align = 'lll'; + +my @fields = ( +  sub { my $country = shift->country; +        code2country($country). " ($country)"; +      }, +  sub { state_label($_[0]->state, $_[0]->country). +        ( $_[0]->state +            ? '' +            : ' '. expand_link($_[0], 'Add States'). +                       'add states</A></FONT>' +        ) +      }, +  sub { $_[0]->county || '(all) '. +                         expand_link($_[0], 'Add Counties'). +                         'add counties</A></FONT>' +      }, +); + +my @color = ( +  '000000', +  sub { shift->state  ? '000000' : '999999' }, +  sub { shift->county ? '000000' : '999999' }, +); + +if ( $conf->exists('enable_taxclasses') ) { +  push @header,  'Tax class'; +  push @header2, '(per-package classification)'; +  push @fields,  sub { $_[0]->taxclass || '(all) '. +                         expand_link($_[0], 'Add Taxclasses', 'taxclass'=>1). +                         'add taxclasses</A></FONT>' +                     }; +  push @color,   sub { shift->taxclass ? '000000' : '999999' }; +  push @links,   ''; +  push @link_onclicks, ''; +  $align .= 'l'; +} + +push @header, 'Tax name', +              'Rate', #'Tax', +              'Exemptions', +              ; + +push @header2, '(printed on invoices)', +               '', +               '', +               ; + +push @fields,  +  sub { shift->taxname || 'Tax' }, +  sub { shift->tax. '% <FONT SIZE="-1">(edit)</FONT>' }, +  $exempt_sub, +; + +push @color, +  sub { shift->taxname ? '000000' : '666666' }, +  sub { shift->tax     ? '000000' : '666666' }, +  '000000', +; + +$align .= 'lrl'; + +my @cell_style = map $cell_style_sub, (1..scalar(@header)); + +push @links,         '', $edit_link,    ''; +push @link_onclicks, '', $edit_onclick, ''; +  </%init> diff --git a/httemplate/edit/cust_main_county-expand.cgi b/httemplate/edit/cust_main_county-expand.cgi index f56d31941..abf8e27f2 100755 --- a/httemplate/edit/cust_main_county-expand.cgi +++ b/httemplate/edit/cust_main_county-expand.cgi @@ -1,59 +1,65 @@ -<!-- mason kludge --> -% -% -%my($taxnum, $delim, $expansion, $taxclass ); -%my($query) = $cgi->keywords; -%if ( $cgi->param('error') ) { -%  $taxnum = $cgi->param('taxnum'); -%  $delim = $cgi->param('delim'); -%  $expansion = $cgi->param('expansion'); -%  $taxclass = $cgi->param('taxclass'); -%} else { -%  $query =~ /^(taxclass)?(\d+)$/ -%    or die "Illegal taxnum (query $query)"; -%  $taxclass = $1 ? 'taxclass' : ''; -%  $taxnum = $2; -%  $delim = 'n'; -%  $expansion = ''; -%} -% -%my $cust_main_county = qsearchs('cust_main_county',{'taxnum'=>$taxnum}) -%  or die "cust_main_county.taxnum $taxnum not found"; -%if ( $taxclass ) { -%  die "Can't expand entry!" if $cust_main_county->getfield('taxclass'); -%} else { -%  die "Can't expand entry!" if $cust_main_county->getfield('county'); -%} -% -%my $p1 = popurl(1); -%print header("Tax Rate (expand)", menubar( -%  'Main Menu' => popurl(2), -%)); -% -%print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'), -%      "</FONT>" -%  if $cgi->param('error'); -% -%print <<END; -%    <FORM ACTION="${p1}process/cust_main_county-expand.cgi" METHOD=POST> -%      <INPUT TYPE="hidden" NAME="taxnum" VALUE="$taxnum"> -%      <INPUT TYPE="hidden" NAME="taxclass" VALUE="$taxclass"> -%      Separate by -%END -%print '<INPUT TYPE="radio" NAME="delim" VALUE="n"'; -%print ' CHECKED' if $delim eq 'n'; -%print '>line (broken on some browsers) or', -%      '<INPUT TYPE="radio" NAME="delim" VALUE="s"'; -%print ' CHECKED' if $delim eq 's'; -%print '>whitespace.'; -%print <<END; -%      <BR><INPUT TYPE="submit" VALUE="Submit"> -%      <BR><TEXTAREA NAME="expansion" ROWS=100>$expansion</TEXTAREA> -%    </FORM> -%    </CENTER> -%  </BODY> -%</HTML> -%END -% -% +<% include('/elements/header-popup.html', "Enter $title") %> +<% include('/elements/error.html') %> + +<FORM ACTION="<% $p1 %>process/cust_main_county-expand.cgi" METHOD=POST> + +<INPUT TYPE="hidden" NAME="taxnum" VALUE="<% $taxnum %>"> +<INPUT TYPE="hidden" NAME="taxclass" VALUE="<% $taxclass |h %>"> + +<TEXTAREA NAME="expansion" COLS="50" ROWS="16"><% $expansion |h %></TEXTAREA> + +<BR> +<INPUT TYPE="submit" VALUE="Add <% $title %>"> + +</FORM> +</BODY> +</HTML> + +<%init> + +my($taxnum, $expansion, $taxclass); +my($query) = $cgi->keywords; +if ( $cgi->param('error') ) { +  $taxnum = $cgi->param('taxnum'); +  $expansion = $cgi->param('expansion'); +  $taxclass = $cgi->param('taxclass'); +} else { +  $query =~ /^(taxclass)?(\d+)$/ +    or die "Illegal taxnum (query $query)"; +  $taxclass = $1 ? 'taxclass' : ''; +  $taxnum = $2; +  $expansion = ''; +} + +my $cust_main_county = qsearchs('cust_main_county',{'taxnum'=>$taxnum}) +  or die "cust_main_county.taxnum $taxnum not found"; + +my $title; +if ( $taxclass ) { +  die "Can't expand entry!" if $cust_main_county->taxclass; + +  $title = 'Tax Classes'; + +  # prepopuplate with other tax classes... which should really have a primary +  #  key of their own... also this could be more efficient in the error case... +  my $sth = dbh->prepare("SELECT DISTINCT taxclass FROM cust_main_county") +    or die dbh->errstr; +  $sth->execute or die $sth->errstr; +  my %taxclasses = map { $_->[0] => 1 } @{$sth->fetchall_arrayref}; +  $expansion ||= join("\n", grep $_, keys %taxclasses ); +   +} else { +  die "Can't expand entry!" if $cust_main_county->county; + +  if ( $cust_main_county->state ) { +    $title = 'Counties'; +  } else { +    $title = 'States/Provinces'; +  } + +} + +my $p1 = popurl(1); + +</%init> diff --git a/httemplate/edit/cust_main_county.html b/httemplate/edit/cust_main_county.html new file mode 100644 index 000000000..510839d71 --- /dev/null +++ b/httemplate/edit/cust_main_county.html @@ -0,0 +1,62 @@ +<% include('elements/edit.html', +     'popup'  => 1, +     'name'   => 'Tax rate', #Edit tax rate +     'table'  => 'cust_main_county', +     'labels' => { 'taxnum'   => 'Tax', +                   'country'  => 'Country', +                   'state'    => 'State', +                   'county'   => 'County', +                   'taxclass' => 'Tax class', +                   'taxname'  => 'Tax name', +                   'tax'      => 'Tax rate', +                   'setuptax' => 'This tax not applicable to setup fees', +                   'recurtax' => 'This tax not applicable to recurring fees', +                   'exempt_amount' => 'Monthly exemption per customer ($25 "Texas tax")', +                 }, +     'fields' => \@fields, +   ) +%> +<%once> + +my $conf = new FS::Conf; + +</%once> + +<%init> + +die "access denied" +  unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my $taxnum; +if ( $cgi->param('error') ) { +  $cgi->param('taxnum') =~ /^(\d+)$/ or die 'error, but no taxnum'; +  $taxnum = $1; +} else { +  my($query) = $cgi->keywords; +  $query =~ /^(\d+)$/ or die 'no taxnum'; +  $taxnum = $1; +} + +my $cust_main_county = qsearchs('cust_main_county', { 'taxnum' => $taxnum }) +  or die "unknown taxnum $1"; + +my @fields = ( +  { field=>'country',  type=>'fixed-country', }, +  { field=>'state',    type=>'fixed-state', }, +  { field=>'county',   type=>'fixed', }, +); + +push @fields, { field=>'taxclass', type=>'fixed', } +  if $conf->exists('enable_taxclasses'); + +push @fields, +  'taxname', +  { field=>'tax',      type=>'percentage', }, + +  { type=>'tablebreak-tr-title', value=>'Exemptions' }, +  { field=>'setuptax', type=>'checkbox', value=>'Y', }, +  { field=>'recurtax', type=>'checkbox', value=>'Y', }, +  { field=>'exempt_amount', type=>'money', }, +; + +</%init> diff --git a/httemplate/edit/process/cust_main_county-expand.cgi b/httemplate/edit/process/cust_main_county-expand.cgi index e550e8b4a..4e04f37fc 100755 --- a/httemplate/edit/process/cust_main_county-expand.cgi +++ b/httemplate/edit/process/cust_main_county-expand.cgi @@ -1,59 +1,55 @@ -% -% -%$cgi->param('taxnum') =~ /^(\d+)$/ or die "Illegal taxnum!"; -%my $taxnum = $1; -%my $cust_main_county = qsearchs('cust_main_county',{'taxnum'=>$taxnum}) -%  or die ("Unknown taxnum!"); -% -%my @expansion; -%if ( $cgi->param('delim') eq 'n' ) { -%  @expansion=split(/\n/,$cgi->param('expansion')); -%} elsif ( $cgi->param('delim') eq 's' ) { -%  @expansion=split(' ',$cgi->param('expansion')); -%} else { -%  die "Illegal delim!"; -%} -% -%@expansion=map { -%  unless ( /^\s*([\w\- ]+)\s*$/ ) { -%    $cgi->param('error', "Illegal item in expansion"); -%    print $cgi->redirect(popurl(2). "cust_main_county-expand.cgi?". $cgi->query_string ); -%    myexit(); -%  } -%  $1; -%} @expansion; -% -%foreach ( @expansion) { -%  my(%hash)=$cust_main_county->hash; -%  my($new)=new FS::cust_main_county \%hash; -%  $new->setfield('taxnum',''); -%  if ( $cgi->param('taxclass') ) { -%    $new->setfield('taxclass', $_); -%  } elsif ( ! $cust_main_county->state ) { -%    $new->setfield('state',$_); -%  } else { -%    $new->setfield('county',$_); -%  } -%  #if (datasrc =~ m/Pg/) -%  #{ -%  #    $new->setfield('tax',0.0); -%  #} -%  my($error)=$new->insert; -%  die $error if $error; -%} -% -%unless ( qsearch( 'cust_main', { -%                                 'state'  => $cust_main_county->state, -%                                 'county' => $cust_main_county->county, -%                                 'country' =>  $cust_main_county->country, -%                               } ) -%         || ! @expansion -%) { -%  my($error)=($cust_main_county->delete); -%  die $error if $error; -%} -% -%print $cgi->redirect(popurl(3). "browse/cust_main_county.cgi"); -% -% +<% include('/elements/header-popup.html', 'Addition successful' ) %> +<SCRIPT TYPE="text/javascript"> +  window.top.location.reload(); +</SCRIPT> + +</BODY> +</HTML> +<%init> + +$cgi->param('taxnum') =~ /^(\d+)$/ or die "Illegal taxnum!"; +my $taxnum = $1; +my $cust_main_county = qsearchs('cust_main_county',{'taxnum'=>$taxnum}) +  or die ("Unknown taxnum!"); + +my @expansion = split /[\n\r]{1,2}/, $cgi->param('expansion'); +#warn scalar(@expansion); +#warn "$_: $expansion[$_]\n" foreach (0..$#expansion); + +@expansion=map { +  unless ( /^\s*([\w\- ]+)\s*$/ ) { +    $cgi->param('error', "Illegal item in expansion: $_"); +    print $cgi->redirect(popurl(2). "cust_main_county-expand.cgi?". $cgi->query_string ); +    myexit(); +  } +  $1; +} @expansion; + +foreach ( @expansion) { +  my(%hash)=$cust_main_county->hash; +  my($new)=new FS::cust_main_county \%hash; +  $new->setfield('taxnum',''); +  if ( $cgi->param('taxclass') ) { +    $new->setfield('taxclass', $_); +  } elsif ( ! $cust_main_county->state ) { +    $new->setfield('state',$_); +  } else { +    $new->setfield('county',$_); +  } +  my $error = $new->insert; +  die $error if $error; +} + +unless ( qsearch( 'cust_main', { +                                 'state'  => $cust_main_county->state, +                                 'county' => $cust_main_county->county, +                                 'country' =>  $cust_main_county->country, +                               } ) +         || ! @expansion +) { +  my $error = $cust_main_county->delete; +  die $error if $error; +} + +</%init> diff --git a/httemplate/edit/process/cust_main_county.html b/httemplate/edit/process/cust_main_county.html new file mode 100644 index 000000000..3d9d20b85 --- /dev/null +++ b/httemplate/edit/process/cust_main_county.html @@ -0,0 +1,6 @@ +<% include( 'elements/process.html', +              'table' => 'cust_main_county', +              'popup_reload' => 'Tax changed', #a popup "parent reload" for now +              #someday change the individual element and go away instead +          ) +%> diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html index 919125ece..c9d09746d 100644 --- a/httemplate/search/elements/search.html +++ b/httemplate/search/elements/search.html @@ -51,7 +51,20 @@ Example:      #listref of column labels, <TH>      #required unless 'query' is an SQL query string      # (if not specified the database column names will be used) -    'header'      => [ '#', 'Item' ], +    'header'      => [ '#', +                       'Item', +                       { 'label' => 'Another Item', +                          +                       }, +                     ], + +    #second (smaller) header line, currently only for HTML +    'header2      => [ '#', +                       'Item', +                       { 'label' => 'Another Item', +                          +                       }, +                     ],      'disable_download' => '', # set true to hide the CSV/Excel download links      'disable_nonefound' => '', # set true to disable the "No matching Xs found" @@ -80,19 +93,27 @@ Example:      #listref of column footers      'footer'      => [], -    #listref - each item is the empty string, or a listref of ... -    'links'       => -    +    #listref - each item is the empty string, +    #          or a listref of link and method name to append, +    #          or a listref of link and coderef to run and append +    #          or a coderef that returns such a listref +    'links'       => [],` + +    #listref - each item is the empty string, +    #          or a string onClick handler for the corresponding link +    #          or a coderef that returns string onClick handler +    'link_onclicks' => [], + +    #one letter for each column, left/right/center/none +    # or pass a listref with full values: [ 'left', 'right', 'center', '' ] +    'align'       => 'lrc.', -    'align'       => 'lrc.', #one letter for each column, left/right/center/none -                             # can also pass a listref with full values: -                             # [ 'left', 'right', 'center', '' ] -    -    #listrefs... +    #listrefs of ( scalars or coderefs )      #currently only HTML, maybe eventually Excel too      'color'       => [],      'size'        => [], -    'style'       => [], +    'style'       => [], #<B> or <I>, etc. +    'cell_style'  => [], #STYLE= attribute of TR, very HTML-specific...      #redirect if there's only one item...      # listref of URL base and column name (or method) @@ -375,11 +396,42 @@ Example:                <% include('/elements/table-grid.html') %>                  <TR> -%                 foreach my $header ( @$header ) {  -                    <TH CLASS="grid" BGCOLOR="#cccccc"><% $header %></TH> +%                 my $h2 = 0; +%                 foreach my $header ( @{ $opt{header} } ) {  +%                   my $label = ref($header) ? $header->{label} : $header; +%                   my $rowspan = 1; +%                   my $style = ''; +%                   if ( $opt{header2} ) { +%                     if ( !length($opt{header2}->[$h2]) ) { +%                       $rowspan = 2; +%                       splice @{ $opt{header2} }, $h2, 1; +%                     } else { +%                       $h2++; +%                       $style = 'STYLE="border-bottom: none"' +%                     } +%                   } +                    <TH CLASS   = "grid" +                        BGCOLOR = "#cccccc" +                        ROWSPAN = "<% $rowspan %>" +                        <% $style %> + +                    > +                      <% $label %> +                    </TH>  %                 }                   </TR> +%               if ( $opt{header2} ) { +                  <TR> +%                   foreach my $header ( @{ $opt{header2} } ) {  +%                     my $label = ref($header) ? $header->{label} : $header; +                      <TH CLASS="grid" BGCOLOR="#cccccc"> +                        <FONT SIZE="-1"><% $label %></FONT> +                      </TH> +%                   }  +                  </TR> +%               } +  %               my $bgcolor1 = '#eeeeee';  %               my $bgcolor2 = '#ffffff';  %               my $bgcolor; @@ -396,11 +448,13 @@ Example:  %                   if ( $opt{'fields'} ) {  % -%                     my $links  = $opt{'links'} ? [ @{$opt{'links'}} ] : ''; -%                     my $aligns = $opt{'align'} ? [ @{$opt{'align'}} ] : ''; -%                     my $colors = $opt{'color'} ? [ @{$opt{'color'}} ] : []; -%                     my $sizes  = $opt{'size'}  ? [ @{$opt{'size'}}  ] : []; -%                     my $styles = $opt{'style'} ? [ @{$opt{'style'}} ] : []; +%                     my $links    = $opt{'links'} ? [ @{$opt{'links'}} ] : ''; +%                     my $onclicks = $opt{'link_onclicks'} ? [ @{$opt{'link_onclicks'}} ] : []; +%                     my $aligns   = $opt{'align'} ? [ @{$opt{'align'}} ] : ''; +%                     my $colors   = $opt{'color'} ? [ @{$opt{'color'}} ] : []; +%                     my $sizes    = $opt{'size'}  ? [ @{$opt{'size'}}  ] : []; +%                     my $styles   = $opt{'style'} ? [ @{$opt{'style'}} ] : []; +%                     my $cstyles  = $opt{'cell_style'} ? [ @{$opt{'cell_style'}} ] : [];  %  %                     foreach my $field (  % @@ -483,7 +537,14 @@ Example:  %                       my $a = '';  %                       if ( $links ) {  %                         my $link = shift @$links; -%                         $link = &{$link}($row) if ref($link) eq 'CODE'; +%                         $link = &{$link}($row) +%                           if ref($link) eq 'CODE'; +% +%                         my $onclick = shift @$onclicks; +%                         $onclick = &{$onclick}($row) +%                           if ref($onclick) eq 'CODE'; +%                         $onclick = qq( onClick="$onclick") if $onclick; +%  %                         if ( $link ) {  %                           my( $url, $method ) = @{$link};  %                           if ( ref($method) eq 'CODE' ) { @@ -491,7 +552,7 @@ Example:  %                           } else {  %                             $a = $url. $row->$method();  %                           } -%                           $a = qq(<A HREF="$a">); +%                           $a = qq(<A HREF="$a"$onclick>);  %                         }  %                       }  % @@ -514,8 +575,13 @@ Example:  %                         $s = join( '', map "<$_>", split('', $style) );  %                         $es = join( '', map "</$_>", split('', $style) );  %                       } +% +%                       my $cstyle = shift @$cstyles; +%                       $cstyle = &{$cstyle}($row) if ref($cstyle) eq 'CODE'; +%                       $cstyle = qq(STYLE="$cstyle") +%                         if $cstyle; -                        <TD CLASS="<% $class %>" BGCOLOR="<% $bgcolor %>"<% $align %>><% $font %><% $a %><% $s %><% $field %><% $es %><% $a ? '</A>' : '' %><% $font ? '</FONT>' : '' %></TD> +                        <TD CLASS="<% $class %>" BGCOLOR="<% $bgcolor %>" <% $align %> <% $cstyle %>><% $font %><% $a %><% $s %><% $field %><% $es %><% $a ? '</A>' : '' %><% $font ? '</FONT>' : '' %></TD>  %                     }   % @@ -620,6 +686,8 @@ if ( $opt{'agent_virt'} ) {      splice @{ $opt{'color'}  }, $pos, 0, '';      splice @{ $opt{'links'}  }, $pos, 0, '' #[ 'agent link?', 'agentnum' ]        if $opt{'links'}; +    splice @{ $opt{'link_onclicks'}  }, $pos, 0, '' +      if $opt{'link_onclicks'};    } @@ -655,6 +723,8 @@ if ( $opt{'disableable'} ) {        sub { shift->disabled ? 'FF0000'   : '00CC00'; };      splice @{ $opt{'links'}  }, $pos, 0, ''        if $opt{'links'}; +    splice @{ $opt{'link_onlicks'}  }, $pos, 0, '' +      if $opt{'link_onlicks'};    }    #add show/hide disabled links @@ -722,7 +792,7 @@ unless ( $type =~ /^(csv|\w*\.xls)$/ ) {  # run the query -my $header = $opt{header}; +my $header = [ map { ref($_) ? $_->{'label'} : $_ } @{$opt{header}} ];  my $rows;  if ( ref($opt{query}) ) {  | 
