diff options
author | ivan <ivan> | 2008-01-04 02:42:07 +0000 |
---|---|---|
committer | ivan <ivan> | 2008-01-04 02:42:07 +0000 |
commit | 1f0e0fb65fdd32d57a3134c018d5a1dc0f09e249 (patch) | |
tree | 0698a46e75923894d6fa6f0682203e01bb5acfe0 /httemplate/edit | |
parent | 3b720b3194fb140737a87830b32b2e8d616215f4 (diff) |
new tax rate editor
Diffstat (limited to 'httemplate/edit')
-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/edit/process/elements/process.html | 82 |
5 files changed, 238 insertions, 146 deletions
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/edit/process/elements/process.html b/httemplate/edit/process/elements/process.html index 19d3fbef1..a671ca118 100644 --- a/httemplate/edit/process/elements/process.html +++ b/httemplate/edit/process/elements/process.html @@ -17,9 +17,11 @@ Example: # optional ### - 'viewall_dir' => '', #'search' or 'browse', defaults to 'search' + 'viewall_dir' => '', #'search' or 'browse', defaults to 'search' OR - 'redirect' => 'view/table.cgi?', # value of primary key is appended + 'redirect' => 'view/table.cgi?', # value of primary key is appended + OR + 'popup_reload' => 'Momentary success message', #will reload parent window 'error_redirect' => popurl(2).'edit/table.cgi?', #query string appended @@ -60,6 +62,54 @@ Example: ) </%doc> +%if ( $error ) { +% +% my $edit_ext = $opt{'edit_ext'} || 'html'; +% my $url = $opt{'error_redirect'} || popurl(2)."$table.$edit_ext"; +% if ( length($cgi->query_string) > 1920 ) { #stupid IE 2083 URL limit +% +% my $session = int(rand(4294967296)); #XXX +% my $pref = new FS::access_user_pref({ +% 'usernum' => $FS::CurrentUser::CurrentUser->usernum, +% 'prefname' => "redirect$session", +% 'prefvalue' => $cgi->query_string, +% 'expiration' => time + 3600, #1h? 1m? +% }); +% my $pref_error = $pref->insert; +% if ( $pref_error ) { +% die "FATAL: couldn't even set redirect cookie: $pref_error". +% " attempting to set redirect$session to ". $cgi->query_string."\n"; +% } +% +<% $cgi->redirect("$url?redirect=$session") %> +% +% } else { +% +<% $cgi->redirect("$url?". $cgi->query_string ) %> +% +% } +% +% #different ways of handling success +% +%} elsif ( $opt{'popup_reload'} ) { + + <% include('/elements/header-popup.html', $opt{'popup_reload'} ) %> + + <SCRIPT TYPE="text/javascript"> + window.top.location.reload(); + </SCRIPT> + + </BODY> + </HTML> + +%} elsif ( $opt{'redirect'} ) { +% +<% $cgi->redirect( $opt{'redirect'}. $pkeyvalue ) %> +% +%} else { +% +<% $cgi->redirect( popurl(3). ($opt{viewall_dir}||'search'). "/$table.html" ) %> +%} <%once> my $me = 'process.html:'; @@ -162,7 +212,6 @@ if ( !$error && $opt{'process_m2name'} ) { ); } -# XXX print?!?! if ( $error ) { $cgi->param('error', $error); @@ -171,33 +220,6 @@ if ( $error ) { $cgi->param($field, '') } } - my $edit_ext = $opt{'edit_ext'} || 'html'; - my $url = $opt{'error_redirect'} || popurl(2)."$table.$edit_ext"; - if ( length($cgi->query_string) > 1920 ) { #stupid IE 2083 URL limit - - my $session = int(rand(4294967296)); #XXX - my $pref = new FS::access_user_pref({ - 'usernum' => $FS::CurrentUser::CurrentUser->usernum, - 'prefname' => "redirect$session", - 'prefvalue' => $cgi->query_string, - 'expiration' => time + 3600, #1h? 1m? - }); - my $pref_error = $pref->insert; - if ( $pref_error ) { - die "FATAL: couldn't even set redirect cookie: $pref_error". - " attempting to set redirect$session to ". $cgi->query_string."\n"; - } - print $cgi->redirect("$url?redirect=$session"); - } else { - print $cgi->redirect("$url?". $cgi->query_string ); - } -} elsif ( $opt{'redirect'} ) { - print $cgi->redirect( $opt{'redirect'}. $pkeyvalue ); -} else { - print $cgi->redirect( popurl(3). - ( $opt{'viewall_dir'} || 'search' ). - "/$table.html" - ); } </%init> |