all taxes now have names. closes: Bug#15
authorivan <ivan>
Sat, 21 Sep 2002 11:17:39 +0000 (11:17 +0000)
committerivan <ivan>
Sat, 21 Sep 2002 11:17:39 +0000 (11:17 +0000)
12 files changed:
FS/FS/cust_bill.pm
FS/FS/cust_bill_pkg.pm
FS/FS/cust_main.pm
FS/FS/cust_main_county.pm
FS/bin/freeside-setup
README.1.5.0pre1
bin/create-history-tables
httemplate/browse/cust_main_county.cgi
httemplate/docs/schema.dia
httemplate/docs/schema.html
httemplate/edit/cust_main_county.cgi
httemplate/edit/process/cust_main_county.cgi

index 258b32e..f066725 100644 (file)
@@ -510,10 +510,13 @@ sub send_csv {
         time2str("%x", $cust_bill_pkg->edate),
       );
 
-    } else { #pkgnum Tax
+    } else { #pkgnum tax
       next unless $cust_bill_pkg->setup != 0;
+      my $itemdesc = defined $cust_bill_pkg->dbdef_table->column('itemdesc')
+                       ? ( $cust_bill_pkg->itemdesc || 'Tax' )
+                       : 'Tax';
       ($pkg, $setup, $recur, $sdate, $edate) =
-        ( 'Tax', sprintf("%10.2f",$cust_bill_pkg->setup), '', '', '' );
+        ( $itemdesc, sprintf("%10.2f",$cust_bill_pkg->setup), '', '', '' );
     }
 
     $csv->combine(
@@ -858,7 +861,9 @@ sub print_text {
   }
 
   #new charges
-  foreach ( $self->cust_bill_pkg ) {
+  foreach ( ( grep {   $_->pkgnum } $self->cust_bill_pkg ),  #packages first
+            ( grep { ! $_->pkgnum } $self->cust_bill_pkg ),  #then taxes
+  ) {
 
     if ( $_->pkgnum ) {
 
@@ -882,8 +887,11 @@ sub print_text {
           map { [ "  ". $_->[0]. ": ". $_->[1], '' ] } $cust_pkg->labels;
       }
 
-    } else { #pkgnum Tax
-      push @buf,["Tax", $money_char. sprintf("%10.2f",$_->setup) ] 
+    } else { #pkgnum tax
+      my $itemdesc = defined $_->dbdef_table->column('itemdesc')
+                     ? ( $_->itemdesc || 'Tax' )
+                     : 'Tax';
+      push @buf,[$itemdesc, $money_char. sprintf("%10.2f",$_->setup) ] 
         if $_->setup != 0;
     }
   }
@@ -1031,7 +1039,7 @@ sub print_text {
 
 =head1 VERSION
 
-$Id: cust_bill.pm,v 1.45 2002-09-17 10:21:47 ivan Exp $
+$Id: cust_bill.pm,v 1.46 2002-09-21 11:17:39 ivan Exp $
 
 =head1 BUGS
 
index 72f9ce4..5a1dcd2 100644 (file)
@@ -47,6 +47,8 @@ supported:
 
 =item edate - ending date of recurring fee
 
+=item itemdesc - Line item description (currentlty used only when pkgnum is 0)
+
 =back
 
 sdate and edate are specified as UNIX timestamps; see L<perlfunc/"time">.  Also
@@ -111,6 +113,7 @@ sub check {
       || $self->ut_money('recur')
       || $self->ut_numbern('sdate')
       || $self->ut_numbern('edate')
+      || $self->ut_textn('itemdesc')
   ;
   return $error if $error;
 
@@ -140,7 +143,7 @@ sub cust_pkg {
 
 =head1 VERSION
 
-$Id: cust_bill_pkg.pm,v 1.3 2002-04-06 22:32:43 ivan Exp $
+$Id: cust_bill_pkg.pm,v 1.4 2002-09-21 11:17:39 ivan Exp $
 
 =head1 BUGS
 
index 84fd3d1..2701ac3 100644 (file)
@@ -904,10 +904,12 @@ sub bill {
   my( $total_setup, $total_recur ) = ( 0, 0 );
   #my( $taxable_setup, $taxable_recur ) = ( 0, 0 );
   my @cust_bill_pkg = ();
-  my $tax = 0;##
+  #my $tax = 0;##
   #my $taxable_charged = 0;##
   #my $charged = 0;##
 
+  my %tax;
+
   foreach my $cust_pkg (
     qsearch('cust_pkg', { 'custnum' => $self->custnum } )
   ) {
@@ -1101,7 +1103,10 @@ sub bill {
           } #if $cust_main_county->exempt_amount
 
           $taxable_charged = sprintf( "%.2f", $taxable_charged);
-          $tax += $taxable_charged * $cust_main_county->tax / 100
+
+          #$tax += $taxable_charged * $cust_main_county->tax / 100
+          $tax{ $cust_main_county->taxname || 'Tax' } +=
+            $taxable_charged * $cust_main_county->tax / 100
 
         } #unless $self->tax =~ /Y/i
           #       || $self->payby eq 'COMP'
@@ -1134,16 +1139,17 @@ sub bill {
 #      $taxable_charged * ( $cust_main_county->getfield('tax') / 100 )
 #    );
 
-  $tax = sprintf("%.2f", $tax);
-  if ( $tax > 0 ) {
+  foreach my $taxname ( grep { $tax{$_} > 0 } keys %tax ) {
+    my $tax = sprintf("%.2f", $tax{$taxname} );
     $charged = sprintf( "%.2f", $charged+$tax );
 
     my $cust_bill_pkg = new FS::cust_bill_pkg ({
-      'pkgnum' => 0,
-      'setup'  => $tax,
-      'recur'  => 0,
-      'sdate'  => '',
-      'edate'  => '',
+      'pkgnum'   => 0,
+      'setup'    => $tax,
+      'recur'    => 0,
+      'sdate'    => '',
+      'edate'    => '',
+      'itemdesc' => $taxname,
     });
     push @cust_bill_pkg, $cust_bill_pkg;
   }
index e41564d..d8796e4 100644 (file)
@@ -61,6 +61,8 @@ currently supported:
 
 =item exempt_amount
 
+=item taxname - if defined, printed on invoices instead of "Tax"
+
 =back
 
 =head1 METHODS
@@ -110,6 +112,7 @@ sub check {
     || $self->ut_float('tax')
     || $self->ut_textn('taxclass') # ...
     || $self->ut_money('exempt_amount')
+    || $self->ut_textn('taxname')
   ;
 
 }
index e8bb7ec..f6a543f 100755 (executable)
@@ -189,7 +189,23 @@ foreach my $table ( grep { ! /^h_/ } $dbdef->tables ) {
                        'default' => '',
                        'local'   => '',
                      } ),
-                     map { $tableobj->column($_) } $tableobj->columns
+                     map {
+                       my $column = $tableobj->column($_);
+
+                       #clone so as to not disturb the original
+                       $column = DBIx::DBSchema::Column->new( {
+                         map { $_ => $column->$_() }
+                           qw( name type null length default local )
+                       } );
+
+                       $column->type('int')
+                         if $column->type eq 'serial';
+                       #$column->default('')
+                       #  if $column->default =~ /^nextval\(/i;
+                       #( my $local = $column->local ) =~ s/AUTO_INCREMENT//i;
+                       #$column->local($local);
+                       $column;
+                     } $tableobj->columns
                    ],
   } );
   $dbdef->addtable($h_tableobj);
@@ -397,9 +413,10 @@ sub tables_hash_hack {
         'recur',   @money_type,
         'sdate',   @date_type,
         'edate',   @date_type,
+        'itemdesc', 'varchar', 'NULL', $char_d,
       ],
       'primary_key' => '',
-      'unique' => [ ['pkgnum', 'invnum'] ],
+      'unique' => [],
       'index' => [ ['invnum'] ],
     },
 
@@ -504,6 +521,7 @@ sub tables_hash_hack {
         'taxclass',   'varchar', 'NULL', $char_d,
         'exempt_amount', @money_type,
         'tax',      'real',  '',    '', #tax %
+        'taxname',  'varchar',  'NULL',    $char_d,
       ],
       'primary_key' => 'taxnum',
       'unique' => [],
index ff3e5a6..57fc36a 100644 (file)
@@ -4,6 +4,9 @@ schema changes:
   *** get svc_broadband changes from pc-intouch
   *** otaker changes s/8/32 all otkaer fields
   *** optional: sequence changes
+  *** add column cust_main_county.taxname
+  *** add column cust_bill_pkg.itemdesc
+  *** drop index cust_bill_pkg1
 
 install DBIx::DBSchema 0.21
 install NetAddr::IP
index d37d682..33eb0e5 100755 (executable)
@@ -2,7 +2,7 @@
 
 use strict;
 use DBI;
-use DBIx::DBSchema 0.20;
+use DBIx::DBSchema 0.21;
 use DBIx::DBSchema::Table;
 use DBIx::DBSchema::Column;
 use DBIx::DBSchema::ColGroup::Unique;
@@ -64,7 +64,16 @@ foreach my $table ( @tables ) {
                        'default' => '',
                        'local'   => '',
                      } ),
-                     map { $tableobj->column($_) } $tableobj->columns
+                     map {
+                       my $column = $tableobj->column($_);
+                       $column->type('int')
+                         if $column->type eq 'serial';
+                       $column->default('')
+                         if $column->default =~ /^nextval\(/i;
+                       ( my $local = $column->local ) =~ s/AUTO_INCREMENT//i;
+                       $column->local($local);
+                       $column;
+                     } $tableobj->columns
                    ],
   } );
   foreach my $statement ( $h_tableobj->sql_create_table($dbh) ) {
index 9916060..c2473c4 100755 (executable)
@@ -21,7 +21,8 @@ print '<BR><BR>'. &table(). <<END;
         <TH><FONT SIZE=-1>Country</FONT></TH>
         <TH><FONT SIZE=-1>State</FONT></TH>
         <TH>County</TH>
-        <TH>Taxclass</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>Exempt<BR>per<BR>month</TH>
       </TR>
@@ -111,6 +112,14 @@ END
   }
   print "</TD>";
 
+  print "<TD";
+  if ( $hashref->{taxname} ) {
+    print ' BGCOLOR="#ffffff">'. $hashref->{taxname};
+  } else {
+    print ' BGCOLOR="#cccccc">Tax';
+  }
+  print "</TD>";
+
   print "<TD BGCOLOR=\"#ffffff\">$hashref->{tax}%</TD>".
         '<TD BGCOLOR="#ffffff">$'.
           sprintf("%.2f", $hashref->{exempt_amount} || 0). '</TD>'.
index c0842a6..7465615 100644 (file)
Binary files a/httemplate/docs/schema.dia and b/httemplate/docs/schema.dia differ
index 54adec3..c518d4a 100644 (file)
@@ -57,6 +57,7 @@
         <li>recur - recurring fee
         <li>sdate - starting date
         <li>edate - ending date
+        <li>itemdesc - Line item description (currently used only when pkgnum is 0)
       </ul>
     <li><a name="cust_credit" href="man/FS/cust_credit.html">cust_credit</a> - Credits.  The equivalent of a negative <a href="#cust_bill">cust_bill</a> record.
       <ul>
         <li>tax - % rate
         <li>taxclass
         <li>exempt_amount
+        <li>taxname - if defined, printed on invoices instead of "Tax"
       </ul>
     <li><a name="cust_tax_exempt" href="man/FS/cust_tax_exempt.html">cust_tax_exempt</a> - Tax exemption record
       <ul>
index 7ef37a4..f3d2882 100755 (executable)
@@ -15,7 +15,8 @@ print qq!<FORM ACTION="!, popurl(1),
         <TH><FONT SIZE=-1>Country</FONT></TH>
         <TH><FONT SIZE=-1>State</FONT></TH>
         <TH><FONT SIZE=-1>County</FONT></TH>
-        <TH><FONT SIZE=-1>Taxclass</FONT></TH>
+        <TH><FONT SIZE=-1>Taxclass</FONT><BR><FONT SIZE=-2>(per-package classification)</FONT></TH>
+        <TH><FONT SIZE=-1>Tax name</FONT><BR><FONT SIZE=-2>(printed on invoices)</FONT></TH>
         <TH><FONT SIZE=-1>Tax</FONT></TH>
         <TH><FONT SIZE=-1>Exempt<BR>per<BR>month</TH>
       </TR>
@@ -46,6 +47,8 @@ END
       : ' BGCOLOR="#cccccc">(ALL)'
     , "</TD>";
 
+  print qq!<TD><INPUT TYPE="text" NAME="taxname!, $hashref->{taxnum},
+        qq!" VALUE="!, $hashref->{taxname}, qq!"></TD>!;
   print qq!<TD><INPUT TYPE="text" NAME="tax!, $hashref->{taxnum},
         qq!" VALUE="!, $hashref->{tax}, qq!" SIZE=6 MAXLENGTH=6>%</TD>!;
   print qq!<TD>\$<INPUT TYPE="text" NAME="exempt_amount!, $hashref->{taxnum},
index 990a239..6d80ad5 100755 (executable)
@@ -2,17 +2,18 @@
 
 foreach ( grep { /^tax\d+$/ } $cgi->param ) {
   /^tax(\d+)$/ or die "Illegal form $_!";
-  my($taxnum)=$1;
-  my($old)=qsearchs('cust_main_county',{'taxnum'=>$taxnum})
+  my $taxnum = $1;
+  my $old = qsearchs('cust_main_county', { 'taxnum' => $taxnum })
     or die "Couldn't find taxnum $taxnum!";
-  my $exempt_amount = $cgi->param("exempt_amount$taxnum");
-  next unless $old->tax ne $cgi->param("tax$taxnum")
-              || $old->exempt_amount ne $exempt_amount;
+  next unless    $old->tax           != $cgi->param("tax$taxnum")
+              || $old->exempt_amount != $cgi->param("exempt_amount$taxnum")
+              || $old->taxname       ne $cgi->param("taxname$taxnum");
   my %hash = $old->hash;
   $hash{tax} = $cgi->param("tax$taxnum");
-  $hash{exempt_amount} = $exempt_amount;
-  my($new)=new FS::cust_main_county \%hash;
-  my($error)=$new->replace($old);
+  $hash{exempt_amount} = $cgi->param("exempt_amount$taxnum");
+  $hash{taxname} = $cgi->param("taxname$taxnum");
+  my $new = new FS::cust_main_county \%hash;
+  my $error = $new->replace($old);
   if ( $error ) {
     $cgi->param('error', $error);
     print $cgi->redirect(popurl(2). "cust_main_county.cgi?". $cgi->query_string );