From: ivan Date: Sat, 21 Sep 2002 11:17:39 +0000 (+0000) Subject: all taxes now have names. closes: Bug#15 X-Git-Tag: freeside_1_5_0pre1~223 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=8965012fa53fd05d851d2f5abed4e056ab758797 all taxes now have names. closes: Bug#15 --- diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 258b32e15..f0667258c 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -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 diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm index 72f9ce4a9..5a1dcd2aa 100644 --- a/FS/FS/cust_bill_pkg.pm +++ b/FS/FS/cust_bill_pkg.pm @@ -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. 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 diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 84fd3d150..2701ac35d 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -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; } diff --git a/FS/FS/cust_main_county.pm b/FS/FS/cust_main_county.pm index e41564d21..d8796e451 100644 --- a/FS/FS/cust_main_county.pm +++ b/FS/FS/cust_main_county.pm @@ -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') ; } diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index e8bb7ec62..f6a543fc8 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -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' => [], diff --git a/README.1.5.0pre1 b/README.1.5.0pre1 index ff3e5a6cc..57fc36af6 100644 --- a/README.1.5.0pre1 +++ b/README.1.5.0pre1 @@ -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 diff --git a/bin/create-history-tables b/bin/create-history-tables index d37d682d8..33eb0e5a3 100755 --- a/bin/create-history-tables +++ b/bin/create-history-tables @@ -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) ) { diff --git a/httemplate/browse/cust_main_county.cgi b/httemplate/browse/cust_main_county.cgi index 991606087..c2473c4c8 100755 --- a/httemplate/browse/cust_main_county.cgi +++ b/httemplate/browse/cust_main_county.cgi @@ -21,7 +21,8 @@ print '

'. &table(). <Country State County - Taxclass + Taxclass
(per-package classification) + Tax name
(printed on invoices) Tax Exempt
per
month @@ -111,6 +112,14 @@ END } print ""; + print "{taxname} ) { + print ' BGCOLOR="#ffffff">'. $hashref->{taxname}; + } else { + print ' BGCOLOR="#cccccc">Tax'; + } + print ""; + print "$hashref->{tax}%". '$'. sprintf("%.2f", $hashref->{exempt_amount} || 0). ''. diff --git a/httemplate/docs/schema.dia b/httemplate/docs/schema.dia index c0842a602..746561550 100644 Binary files a/httemplate/docs/schema.dia and b/httemplate/docs/schema.dia differ diff --git a/httemplate/docs/schema.html b/httemplate/docs/schema.html index 54adec3a7..c518d4a4d 100644 --- a/httemplate/docs/schema.html +++ b/httemplate/docs/schema.html @@ -57,6 +57,7 @@
  • recur - recurring fee
  • sdate - starting date
  • edate - ending date +
  • itemdesc - Line item description (currently used only when pkgnum is 0)
  • cust_credit - Credits. The equivalent of a negative cust_bill record.
      @@ -133,6 +134,7 @@
    • tax - % rate
    • taxclass
    • exempt_amount +
    • taxname - if defined, printed on invoices instead of "Tax"
  • cust_tax_exempt - Tax exemption record
      diff --git a/httemplate/edit/cust_main_county.cgi b/httemplate/edit/cust_main_county.cgi index 7ef37a48d..f3d28825a 100755 --- a/httemplate/edit/cust_main_county.cgi +++ b/httemplate/edit/cust_main_county.cgi @@ -15,7 +15,8 @@ print qq!
      (ALL)' , ""; + print qq!!; print qq!%!; print qq!\$$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 );