[freeside-commits] freeside/FS/FS cust_bill_pkg.pm, 1.13, 1.14 part_pkg.pm, 1.70, 1.71 tax_rate.pm, 1.3, 1.4
Jeff Finucane,420,,
jeff at wavetail.420.am
Wed May 14 11:07:25 PDT 2008
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv21487/FS/FS
Modified Files:
cust_bill_pkg.pm part_pkg.pm tax_rate.pm
Log Message:
correct tax selection and *actually* handle fee based taxes
Index: part_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg.pm,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- part_pkg.pm 13 May 2008 21:20:08 -0000 1.70
+++ part_pkg.pm 14 May 2008 18:07:22 -0000 1.71
@@ -416,6 +416,11 @@
|| $self->ut_enum('disabled', [ '', 'Y' ] )
|| $self->ut_floatn('pay_weight')
|| $self->ut_floatn('credit_weight')
+ || $self->ut_numbern('taxproductnum')
+ || $self->ut_foreign_keyn('taxproductnum',
+ 'part_pkg_taxproduct',
+ 'taxproductnum'
+ )
|| $self->ut_agentnum_acl('agentnum', 'Edit global package definitions')
|| $self->SUPER::check
;
@@ -808,25 +813,57 @@
=cut
+sub _expand_cch_taxproductnum {
+ my $self = shift;
+ my $part_pkg_taxproduct =
+ qsearchs( 'part_pkg_taxproduct',
+ { 'taxproductnum' => $self->taxproductnum }
+ );
+ my ($a,$b,$c,$d) = ( $part_pkg_taxproduct
+ ? ( split ':', $part_pkg_taxproduct->taxproduct )
+ : ()
+ );
+ my $extra_sql = "AND ( taxproduct = '$a:$b:$c:$d'
+ OR taxproduct = '$a:$b:$c:'
+ OR taxproduct = '$a:$b:".":$d'
+ OR taxproduct = '$a:$b:".":' )";
+ map { $_->taxproductnum } qsearch( { 'table' => 'part_pkg_taxproduct',
+ 'hashref' => { 'data_vendor'=>'cch' },
+ 'extra_sql' => $extra_sql,
+ } );
+
+}
+
sub part_pkg_taxrate {
my $self = shift;
my ($data_vendor, $geocode) = @_;
my $dbh = dbh;
+ my $extra_sql = 'WHERE part_pkg_taxproduct.data_vendor = '.
+ dbh->quote($data_vendor);
+
# CCH oddness in m2m
- my $extra_sql = 'AND ('.
+ $extra_sql .= ' AND ('.
join(' OR ', map{ 'geocode = '. $dbh->quote(substr($geocode, 0, $_)) }
qw(10 5 2)
).
')';
- my $order_by = 'ORDER BY taxclassnum, length(geocode) desc';
- my $select = 'DISTINCT ON(taxclassnum) *';
+ # much more CCH oddness in m2m -- this is kludgy
+ $extra_sql .= ' AND ('.
+ join(' OR ', map{ "taxproductnum = $_" } $self->_expand_cch_taxproductnum).
+ ')';
+
+ my $addl_from = 'LEFT JOIN part_pkg_taxproduct USING ( taxproductnum )';
+ my $order_by = 'ORDER BY taxclassnum, length(geocode) desc, length(taxproduct) desc';
+ my $select = 'DISTINCT ON(taxclassnum) *, taxproduct';
+ # should qsearch preface columns with the table to facilitate joins?
qsearch( { 'table' => 'part_pkg_taxrate',
- 'select' => 'distinct on(taxclassnum) *',
- 'hashref' => { 'data_vendor' => $data_vendor,
- 'taxproductnum' => $self->taxproductnum,
+ 'select' => $select,
+ 'hashref' => { # 'data_vendor' => $data_vendor,
+ # 'taxproductnum' => $self->taxproductnum,
},
+ 'addl_from' => $addl_from,
'extra_sql' => $extra_sql,
'order_by' => $order_by,
} );
@@ -891,6 +928,7 @@
sub calc_remain { 0; }
sub calc_cancel { 0; }
+sub calc_units { 0; }
=back
@@ -1059,6 +1097,8 @@
plandata should go
+part_pkg_taxrate is Pg specific
+
=head1 SEE ALSO
L<FS::Record>, L<FS::cust_pkg>, L<FS::type_pkgs>, L<FS::pkg_svc>, L<Safe>.
Index: cust_bill_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_bill_pkg.pm,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- cust_bill_pkg.pm 17 Apr 2008 01:39:53 -0000 1.13
+++ cust_bill_pkg.pm 14 May 2008 18:07:22 -0000 1.14
@@ -309,6 +309,18 @@
);
}
+=item units
+
+Returns the number of billing units (for tax purposes) represented by this,
+line item.
+
+=cut
+
+sub units {
+ my $self = shift;
+ $self->part_pkg->calc_units($self->cust_pkg);
+}
+
=back
=head1 BUGS
Index: tax_rate.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/tax_rate.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- tax_rate.pm 15 Apr 2008 20:47:59 -0000 1.3
+++ tax_rate.pm 14 May 2008 18:07:22 -0000 1.4
@@ -349,6 +349,10 @@
my $self = shift;
my @cust_bill_pkg = @_;
+ warn "calculating taxes for ". $self->taxnum. " on ".
+ join (",", map { $_->pkgnum } @cust_bill_pkg)
+ if $DEBUG;
+
if ($self->passflag eq 'N') {
return "fatal: can't (yet) handle taxes not passed to the customer";
}
@@ -386,7 +390,16 @@
my $taxable_units = 0;
unless ($self->recurtax =~ /^Y$/i) {
- $taxable_units += $_->units foreach @cust_bill_pkg;
+ if ($self->unittype == 0) {
+ $taxable_units += $_->units foreach @cust_bill_pkg;
+ }elsif ($self->unittype == 1) {
+ return qq!fatal: can't (yet) handle fee with minute unit type!;
+ }elsif ($self->unittype == 2) {
+ $taxable_units = 1;
+ }else {
+ return qq!fatal: can't (yet) handle unknown unit type in tax!.
+ $self->taxnum;
+ }
}
#
@@ -399,6 +412,9 @@
$amount += $taxable_charged * $self->tax;
$amount += $taxable_units * $self->fee;
+ warn "calculated taxes as [ $name, $amount ]\n"
+ if $DEBUG;
+
return [$name, $amount];
}
More information about the freeside-commits
mailing list