X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_fee.pm;h=954f70b34e8c5fd3a6f5f2e756cee181a5b531f2;hb=74f252e841ae742b7defe1042e8e9d3d7c513867;hp=fe632504058bc7497a5a3f9de19189ece7eeec4d;hpb=e1c6b4af716fecad943bf282b50c0d459b986720;p=freeside.git diff --git a/FS/FS/part_fee.pm b/FS/FS/part_fee.pm index fe6325040..954f70b34 100644 --- a/FS/FS/part_fee.pm +++ b/FS/FS/part_fee.pm @@ -2,14 +2,15 @@ package FS::part_fee; use strict; use base qw( FS::o2m_Common FS::Record ); -use vars qw( $DEBUG ); use FS::Record qw( qsearch qsearchs ); use FS::pkg_class; +use FS::cust_bill_pkg_display; use FS::part_pkg_taxproduct; use FS::agent; use FS::part_fee_usage; -$DEBUG = 0; +our $DEBUG = 0; +our $default_class; =head1 NAME @@ -53,6 +54,9 @@ the invoice =item disabled - 'Y' if the fee is disabled =item classnum - the L that the fee belongs to, for reporting +and placement on multisection invoices. Unlike packages, fees I be +assigned to a class; they will default to class named "Fees", which belongs +to the same invoice section that normally contains taxes. =item taxable - 'Y' if this fee should be considered a taxable sale. Currently, taxable fees will be treated like they exist at the customer's @@ -133,6 +137,13 @@ sub check { $self->set('amount', 0) unless $self->amount; $self->set('percent', 0) unless $self->percent; + $default_class ||= qsearchs('pkg_class', { classname => 'Fees' }) + or die "default package fee class not found; run freeside-upgrade to continue.\n"; + + if (!$self->get('classnum')) { + $self->set('classnum', $default_class->classnum); + } + my $error = $self->ut_numbern('feepart') || $self->ut_textn('comment') @@ -269,6 +280,8 @@ sub lineitem { ' FROM cust_bill_pkg WHERE billpkgnum = ?'; @item_base = map { FS::Record->scalar_sql($sql, $_->billpkgnum) } @items; + + $amount += $total_base * $self->percent / 100; } } else { # the fee applies to _this_ invoice. It has no payments or credits, so @@ -279,6 +292,8 @@ sub lineitem { $total_base = $cust_bill->charged; @item_base = map { $_->setup + $_->recur } @items; + + $amount += $total_base * $self->percent / 100; } } @@ -375,11 +390,19 @@ sub lineitem { # set the amount that we'll charge $cust_bill_pkg->set( $self->setuprecur, $amount ); + # create display record + my $categoryname = ''; if ( $self->classnum ) { my $pkg_category = $self->pkg_class->pkg_category; - $cust_bill_pkg->set('section' => $pkg_category->categoryname) - if $pkg_category; + $categoryname = $pkg_category->categoryname if $pkg_category; } + my $displaytype = ($self->setuprecur eq 'setup') ? 'S' : 'R'; + my $display = FS::cust_bill_pkg_display->new({ + type => $displaytype, + section => $categoryname, + # post_total? summary? who the hell knows? + }); + $cust_bill_pkg->set('display', [ $display ]); # if this is a percentage fee and has line item fractions, # adjust them to be proportional and to add up correctly. @@ -484,6 +507,19 @@ sub tax_rates { return @taxes; } +=item categoryname + +Returns the package category name, or the empty string if there is no package +category. + +=cut + +sub categoryname { + my $self = shift; + my $pkg_class = $self->pkg_class; + $pkg_class ? $pkg_class->categoryname : ''; +} + sub part_pkg_taxoverride {} # we don't do overrides here sub has_taxproduct {