[freeside-commits] freeside/httemplate/search report_tax.cgi, 1.51, 1.52 report_tax.html, 1.13, 1.14

Ivan,,, ivan at wavetail.420.am
Mon May 25 18:35:18 PDT 2009


Update of /home/cvs/cvsroot/freeside/httemplate/search
In directory wavetail.420.am:/tmp/cvs-serv7186/httemplate/search

Modified Files:
	report_tax.cgi report_tax.html 
Log Message:
add a config option for some basic tax grouping by name, RT#5446

Index: report_tax.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/search/report_tax.html,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- report_tax.html	10 Dec 2008 21:43:43 -0000	1.13
+++ report_tax.html	26 May 2009 01:35:16 -0000	1.14
@@ -4,29 +4,49 @@
 
 <TABLE>
 
+% if ( $conf->config('tax-report_groups') ) {
+%   my @lines = $conf->config('tax-report_groups');
+    
+  <TR>
+    <TD>Tax group</TD>
+    <TD>
+      <SELECT NAME="report_group">
+
+        <OPTION VALUE="">all</OPTION>
+
+%       foreach my $line ( @lines ) {
+%         $line =~ /^\s*(.+)\s+(=|!=)\s+(.*)\s*$/ #or next;
+%           or do { warn "bad report_group line: $line\n"; next; };
+%         my($label, $op, $value) = ($1, $2, $3);
+
+          <OPTION VALUE="<% "$op $value" %>"><% $label %></OPTION>
+%       }
+
+      </SELECT>
+    </TD>
+  </TR>
+
+% }
+
  <% include( '/elements/tr-select-agent.html', 'disable_empty'=>0 ) %>
 
  <% include( '/elements/tr-input-beginning_ending.html' ) %>
-% my $conf = new FS::Conf;
-%    if ( $conf->exists('enable_taxclasses') ) {
-% 
 
+%    if ( $conf->exists('enable_taxclasses') ) {
    <TR>
      <TD ALIGN="right"><INPUT TYPE="checkbox" NAME="show_taxclasses" VALUE="1"></TD>
      <TD>Show tax classes</TD>
    </TR>
 % } 
-% my @pkg_class = qsearch('pkg_class', {});
-%    if ( @pkg_class ) {
-% 
 
+% my @pkg_class = qsearch('pkg_class', {});
+% if ( @pkg_class ) {
    <TR>
      <TD ALIGN="right"><INPUT TYPE="checkbox" NAME="show_pkgclasses" VALUE="1"></TD>
      <TD>Show package classes</TD>
    </TR>
 % } 
 
-
 </TABLE>
 
 <BR><INPUT TYPE="submit" VALUE="Get Report">
@@ -39,4 +59,6 @@
 die "access denied"
   unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
 
+my $conf = new FS::Conf;
+
 </%init>

Index: report_tax.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/search/report_tax.cgi,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- report_tax.cgi	22 Feb 2009 02:38:17 -0000	1.51
+++ report_tax.cgi	26 May 2009 01:35:16 -0000	1.52
@@ -174,7 +174,7 @@
    <<%$td%>>Total</TD>
    <<%$td%> ALIGN="right">
      <A HREF="<% $baselink %>;istax=1"
-     ><% &$money_sprintf( $tax ) %></A>
+     ><% &$money_sprintf( $tot_tax ) %></A>
    </TD>
   </TR>
 
@@ -275,8 +275,16 @@
     "WHERE 0 < ( SELECT COUNT(*) FROM cust_main WHERE $gotcust LIMIT 1 )";
 }
 
-my($total, $tot_taxable, $owed, $tax) = ( 0, 0, 0, 0 );
+#tax-report_groups filtering
+my($group_op, $group_value) = ( '', '' );
+if ( $cgi->param('report_group') =~ /^(=|!=) (.*)$/ ) {
+  ( $group_op, $group_value ) = ( $1, $2 );
+}
+my $skipping_out = $group_op ? 1 : 0; #in case there are other reasons
+
+my( $total, $tot_taxable, $tot_owed ) = ( 0, 0, 0 );
 my( $exempt_cust, $exempt_pkg, $exempt_monthly ) = ( 0, 0, 0 );
+
 my $out = 'Out of taxable region(s)';
 my %regions = ();
 
@@ -326,8 +334,8 @@
   my $t_sql =
    "SELECT SUM(cust_bill_pkg.setup+cust_bill_pkg.recur) $fromwhere AND $nottax";
   my $t = scalar_sql($r, \@param, $t_sql);
-  $total += $t;
   $regions{$label}->{'total'} += $t;
+  $total += $t unless $label eq $out && $skipping_out;
 
   #if ( $label eq $out ) {# && $t ) {
   #  warn "adding $t for ".
@@ -356,8 +364,8 @@
      $fromwhere AND $nottax AND tax = 'Y' "
   );
 
-  $exempt_cust += $x_cust;
   $regions{$label}->{'exempt_cust'} += $x_cust;
+  $exempt_cust += $x_cust unless $label eq $out && $skipping_out;
   
   ## calculate package-exemption for this region
 
@@ -384,8 +392,8 @@
        AND ( tax != 'Y' OR tax IS NULL )
     "
   );
-  $exempt_pkg += $x_pkg;
   $regions{$label}->{'exempt_pkg'} += $x_pkg;
+  $exempt_pkg += $x_pkg unless $label eq $out && $skipping_out;
 
   ## calculate monthly exemption (texas tax) for this region
 
@@ -404,16 +412,17 @@
 #    $taxable -= $x_monthly;
 #  }
 
-  $exempt_monthly += $x_monthly;
   $regions{$label}->{'exempt_monthly'} += $x_monthly;
+  $exempt_monthly += $x_monthly unless $label eq $out && $skipping_out;
 
   my $taxable = $t - $x_cust - $x_pkg - $x_monthly;
 
-  $tot_taxable += $taxable;
   $regions{$label}->{'taxable'} += $taxable;
+  $tot_taxable += $taxable unless $label eq $out && $skipping_out;
 
-  $owed += $taxable * ($r->tax/100);
-  $regions{$label}->{'owed'} += $taxable * ($r->tax/100);
+  my $owed = $taxable * ($r->tax/100);
+  $regions{$label}->{'owed'} += $owed;
+  $tot_owed += $owed unless $label eq $out && $skipping_out;
 
   if ( defined($regions{$label}->{'rate'})
        && $regions{$label}->{'rate'} != $r->tax.'%' ) {
@@ -474,6 +483,7 @@
   scalar_sql($r, \@taxparam, $sql );
 };
 
+my $tot_tax = 0;
 #foreach my $label ( keys %regions ) {
 foreach my $r ( qsearch(\%qsearch) ) {
 
@@ -486,8 +496,8 @@
 
   my $x = &{$_taxamount_sub}($r);
 
-  $tax += $x unless $cgi->param('show_taxclasses');
   $regions{$label}->{'tax'} += $x;
+  $tot_tax += $x unless $cgi->param('show_taxclasses');
 
 }
 
@@ -508,17 +518,34 @@
           );
 
     $base_regions{$base_label}->{'tax'} += $x;
-    $tax += $x;
+    $tot_tax += $x;
   }
 
 }
 
 
+my @regions = keys %regions;
+
+#tax-report_groups filtering
+if ( $group_op ) {
+  @regions = grep {
+    if ( $_ eq $out ) { #don't display "out of taxable region" in this case
+      0;
+    } elsif ( $group_op eq '=' ) {
+      $_ =~ /^$group_value \(/;
+    } elsif ( $group_op eq '!=' ) {
+      $_ !~ /^$group_value \(/;
+    } else {
+      die "guru meditation #00de: group_op $group_op\n";
+    }
+  } @regions;
+}
+
 #ordering
-my @regions =
+ at regions =
   map $regions{$_},
   sort { ( ($a eq $out) cmp ($b eq $out) ) || ($b cmp $a) }
-  keys %regions;
+  @regions;
 
 my @base_regions =
   map $base_regions{$_},
@@ -534,8 +561,8 @@
   'exempt_monthly' => $exempt_monthly,
   'taxable'        => $tot_taxable,
   'rate'           => '',
-  'owed'           => $owed,
-  'tax'            => $tax,
+  'owed'           => $tot_owed,
+  'tax'            => $tot_tax,
 };
 
 #-- 



More information about the freeside-commits mailing list