summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authorivan <ivan>2009-06-25 01:28:53 +0000
committerivan <ivan>2009-06-25 01:28:53 +0000
commitfa19c2c557f7abd72f94357373290b99dd3297bf (patch)
treeb60036e49f1c8fe298decdc26a5baeef70d391e3 /httemplate
parent8449080168affaabc1102234502bcd4fa491d615 (diff)
tax adjustments, RT#5595
Diffstat (limited to 'httemplate')
-rw-r--r--httemplate/edit/cust_tax_adjustment.html102
-rw-r--r--httemplate/edit/process/cust_tax_adjustment.html41
-rw-r--r--httemplate/search/cust_tax_adjustment.html52
-rw-r--r--httemplate/view/cust_main/payment_history.html29
4 files changed, 221 insertions, 3 deletions
diff --git a/httemplate/edit/cust_tax_adjustment.html b/httemplate/edit/cust_tax_adjustment.html
new file mode 100644
index 000000000..9d4afbc60
--- /dev/null
+++ b/httemplate/edit/cust_tax_adjustment.html
@@ -0,0 +1,102 @@
+<% include('/elements/header-popup.html', 'Tax adjustment' ) %>
+
+<% include('/elements/error.html') %>
+
+<SCRIPT TYPE="text/javascript">
+
+function enable_tax_adjustment () {
+ if ( document.TaxAdjustmentForm.amount.value
+ && document.TaxAdjustmentForm.taxname.selectedIndex > 0 ) {
+ document.TaxAdjustmentForm.submit.disabled = false;
+ } else {
+ document.TaxAdjustmentForm.submit.disabled = true;
+ }
+}
+
+function validate_tax_adjustment () {
+ var comment = document.TaxAdjustmentForm.comment.value;
+ var comment_regex = /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/ ;
+ var amount = document.TaxAdjustmentForm.amount.value;
+ var amount_regex = /^\s*\$?\s*(\d*(\.?\d{1,2}))\s*$/ ;
+ var rval = true;
+
+ if ( ! amount_regex.test(amount) ) {
+ alert('Illegal amount - enter the amount of the tax adjustment, for example, "5" or "43" or "21.46".');
+ return false;
+ }
+ if ( ! comment_regex.test(comment) ) {
+ alert('Illegal comment - spaces, letters, numbers, and the following punctuation characters are allowed: . , ! ? @ # $ % & ( ) - + ; : ' + "'" + ' " = [ ]' );
+ return false;
+ }
+
+ return true;
+}
+
+</SCRIPT>
+
+<FORM ACTION="process/cust_tax_adjustment.html" NAME="TaxAdjustmentForm" ID="TaxAdjustmentForm" METHOD="POST" onsubmit="document.TaxAdjustmentForm.submit.disabled=true;return validate_tax_adjustment();">
+
+<INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
+
+<TABLE ID="TaxAdjustmentTable" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0 STYLE="background-color: #cccccc">
+
+<TR>
+ <TD ALIGN="right">Tax </TD>
+ <TD>
+ <SELECT NAME="taxname" ID="taxname" onChange="enable_tax_adjustment()" onKeyPress="enable_tax_adjustment()">
+ <OPTION VALUE=""></OPTION>
+% foreach my $taxname (@taxname) {
+ <OPTION VALUE="<% $taxname %>"><% $taxname %></OPTION>
+% }
+ </SELECT>
+ </TD>
+</TR>
+
+<TR>
+ <TD ALIGN="right">Amount </TD>
+ <TD>
+ $<INPUT TYPE="text" NAME="amount" SIZE=6 VALUE="<% $amount %>" onChange="enable_tax_adjustment()" onKeyPress="enable_tax_adjustment()">
+ </TD>
+</TR>
+
+<TR>
+ <TD ALIGN="right">Comment </TD>
+ <TD>
+ <INPUT TYPE="text" NAME="comment" SIZE="50" MAXLENGTH="50" VALUE="<% $comment %>" onChange="enable_tax_adjustment()" onKeyPress="enable_tax_adjustment()">
+ </TD>
+</TR>
+
+</TABLE>
+
+<BR>
+<INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="Add tax adjustment" <% $cgi->param('error') ? '' :' DISABLED' %>>
+
+</FORM>
+
+</BODY>
+</HTML>
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Add customer tax adjustment');
+
+my $sql = 'SELECT DISTINCT(taxname) FROM cust_main_county';
+my $sth = dbh->prepare($sql) or die dbh->errstr;
+$sth->execute() or die $sth->errstr;
+my @taxname = map { $_->[0] || 'Tax' } @{ $sth->fetchall_arrayref([]) };
+
+my $conf = new FS::Conf;
+
+$cgi->param('custnum') =~ /^(\d+)$/ or die 'illegal custnum';
+my $custnum = $1;
+
+my $amount = '';
+if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
+ $amount = $1;
+}
+
+$cgi->param('comment') =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/
+ or die 'illegal description';
+my $comment = $1;
+
+</%init>
diff --git a/httemplate/edit/process/cust_tax_adjustment.html b/httemplate/edit/process/cust_tax_adjustment.html
new file mode 100644
index 000000000..204b5b9f7
--- /dev/null
+++ b/httemplate/edit/process/cust_tax_adjustment.html
@@ -0,0 +1,41 @@
+% if ( $error ) {
+% $cgi->param('error', $error );
+<% $cgi->redirect($p.'cust_tax_adjustment.html?'. $cgi->query_string) %>
+% } else {
+<% header("Tax adjustment added") %>
+ <SCRIPT TYPE="text/javascript">
+ //window.top.location.reload();
+ parent.cClick();
+ </SCRIPT>
+ </BODY></HTML>
+% }
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Add customer tax adjustment');
+
+my $error = '';
+my $conf = new FS::conf;
+my $param = $cgi->Vars;
+
+$param->{"custnum"} =~ /^(\d+)$/
+ or $error .= "Illegal customer number " . $param->{"custnum"} . " ";
+my $custnum = $1;
+
+$param->{"amount"} =~ /^\s*(\d*(?:\.?\d{1,2}))\s*$/
+ or $error .= "Illegal amount " . $param->{"amount"} . " ";
+my $amount = $1;
+
+unless ( $error ) {
+
+ my $cust_tax_adjustment = new FS::cust_tax_adjustment {
+ 'custnum' => $custnum,
+ 'taxname' => $param->{'taxname'},
+ 'amount' => $amount,
+ 'comment' => $param->{'comment'},
+ };
+ $error = $cust_tax_adjustment->insert;
+
+}
+
+</%init>
diff --git a/httemplate/search/cust_tax_adjustment.html b/httemplate/search/cust_tax_adjustment.html
new file mode 100644
index 000000000..dfc638e8b
--- /dev/null
+++ b/httemplate/search/cust_tax_adjustment.html
@@ -0,0 +1,52 @@
+<% include( 'elements/search.html',
+ 'title' => $title,
+ 'name_singular' => 'tax adjustment',
+ 'query' => $query,
+ 'count_query' => $count_query,
+ 'header' => [ 'Tax', 'Amount', 'Comment', 'Invoice' ],
+ 'fields' => [ 'taxname',
+ sub { $money_char. shift->amount },
+ 'comment',
+ sub { my $l = shift->cust_bill_pkg;
+ $l ? '#'.$l->invnum : '';
+ },
+ ],
+ 'links' => [ '', '', '', $ilink ],
+ )
+%>
+
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Add customer tax adjustment');
+
+my $conf = new FS::Conf;
+my $money_char = $conf->config('money_char') || '$';
+
+my $count_query = 'SELECT COUNT(*) FROM cust_tax_adjustment';
+
+my $hashref = {};
+
+my $custnum = $cgi->param('custnum');
+my $cust_main;
+if ( $custnum ) {
+ $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
+ $hashref->{'custnum'} = $custnum;
+}
+
+my $title = 'Tax adjustments';
+$title .= ' for '. $cust_main->name if $cust_main;
+
+my $query = { 'table' => 'cust_tax_adjustment',
+ 'hashref' => $hashref,
+ };
+
+my $ilink = [ $p.'view/cust_bill.cgi?', sub { my $l = shift->cust_bill_pkg;
+ $l ? $l->invnum : 'EXCEPTION';
+ }
+ ];
+
+#XXX would be nice to list customer fields on the report too, if we ever need
+# to link to here without a custnum (i'm sure we will, eventually...)
+
+</%init>
diff --git a/httemplate/view/cust_main/payment_history.html b/httemplate/view/cust_main/payment_history.html
index f2abe0eac..1711e1449 100644
--- a/httemplate/view/cust_main/payment_history.html
+++ b/httemplate/view/cust_main/payment_history.html
@@ -127,10 +127,33 @@
%# tax exemption link
-% if ( $curuser->access_right('View customer tax exemptions') ) {
- <A HREF="<% $p %>search/cust_tax_exempt_pkg.cgi?custnum=<% $custnum %>">View tax exemptions</A>
+% my $view_exemptions = $curuser->access_right('View customer tax exemptions');
+% my $add_adjustment = ( $conf->exists('enable_tax_adjustments')
+% && $curuser->access_right('Add customer tax adjustment')
+% );
+% if ( $view_exemptions || $add_adjustment ) {
+
+% if ( $view_exemptions ) {
+ <A HREF="<% $p %>search/cust_tax_exempt_pkg.cgi?custnum=<% $custnum %>">View tax exemptions</A>
+ <% $add_adjustment ? '|' : '' %>
+% }
+
+% if ( $add_adjustment ) {
+ <% include('/elements/popup_link.html', {
+ 'action' => $p.'edit/cust_tax_adjustment.html?custnum='. $cust_main->custnum,
+ 'label' => 'Add tax adjustment',
+ 'actionlabel' => 'Add tax adjustment',
+ #'color' => '#333399',
+ #'width' => 763,
+ 'height' => 200,
+ })
+ %>
+ |
+ <A HREF="<% $p %>search/cust_tax_adjustment.html?custnum=<% $custnum %>">View tax adjustments</A>
+% }
+
<BR>
-% }
+% }
%# batched payment links