X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main.pm;h=5d6826f485e6b14c003ccb15ce0e4391e149469d;hb=1c2b820bd8d41fb9620e81faf617adffe85dbd33;hp=700e15a794387ee51d3f1ee3f024ebb93f806c36;hpb=2cb70470a8e5c3287146008e4ce2c4eb9f242373;p=freeside.git diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 700e15a79..5d6826f48 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -45,6 +45,7 @@ use FS::cust_refund; use FS::part_referral; use FS::cust_main_county; use FS::cust_location; +use FS::cust_class; use FS::cust_main_exemption; use FS::cust_tax_adjustment; use FS::tax_rate; @@ -1537,6 +1538,7 @@ sub check { || $self->ut_number('agentnum') || $self->ut_textn('agent_custid') || $self->ut_number('refnum') + || $self->ut_foreign_keyn('classnum', 'cust_class', 'classnum') || $self->ut_textn('custbatch') || $self->ut_name('last') || $self->ut_name('first') @@ -2305,6 +2307,53 @@ sub agent { qsearchs( 'agent', { 'agentnum' => $self->agentnum } ); } +=item cust_class + +Returns the customer class, as an FS::cust_class object, or the empty string +if there is no customer class. + +=cut + +sub cust_class { + my $self = shift; + if ( $self->classnum ) { + qsearchs('cust_class', { 'classnum' => $self->classnum } ); + } else { + return ''; + } +} + +=item categoryname + +Returns the customer category name, or the empty string if there is no customer +category. + +=cut + +sub categoryname { + my $self = shift; + my $cust_class = $self->cust_class; + $cust_class + ? $cust_class->categoryname + : ''; +} + +=item classname + +Returns the customer class name, or the empty string if there is no customer +class. + +=cut + +sub classname { + my $self = shift; + my $cust_class = $self->cust_class; + $cust_class + ? $cust_class->classname + : ''; +} + + =item bill_and_collect Cancels and suspends any packages due, generates bills, applies payments and @@ -3175,15 +3224,24 @@ sub _handle_taxes { $taxhash{'taxclass'} = $part_pkg->taxclass; - my @taxes = qsearch( 'cust_main_county', \%taxhash ); - + my @taxes = (); my %taxhash_elim = %taxhash; + my @elim = qw( city county state ); + do { - my @elim = qw( taxclass city county state ); - while ( !scalar(@taxes) && scalar(@elim) ) { - $taxhash_elim{ shift(@elim) } = ''; + #first try a match with taxclass @taxes = qsearch( 'cust_main_county', \%taxhash_elim ); - } + + if ( !scalar(@taxes) && $taxhash_elim{'taxclass'} ) { + #then try a match without taxclass + my %no_taxclass = %taxhash_elim; + $no_taxclass{ 'taxclass' } = ''; + @taxes = qsearch( 'cust_main_county', \%no_taxclass ); + } + + $taxhash_elim{ shift(@elim) } = ''; + + } while ( !scalar(@taxes) && scalar(@elim) ); @taxes = grep { ! $_->taxname or ! $self->tax_exemption($_->taxname) } @taxes @@ -8201,6 +8259,10 @@ listref of start date, end date listref +=item paydate_year + +=item paydate_month + =item current_balance listref (list returned by FS::UI::Web::parse_lt_gt($cgi, 'current_balance')) @@ -8279,6 +8341,21 @@ sub search_sql { } ### + # classnum + ### + + my @classnum = grep /^(\d*)$/, @{ $params->{'classnum'} }; + if ( @classnum ) { + push @where, '( '. join(' OR ', map { + $_ ? "cust_main.classnum = $_" + : "cust_main.classnum IS NULL" + } + @classnum + ). + ' )'; + } + + ### # payby ### @@ -8287,6 +8364,23 @@ sub search_sql { push @where, '( '. join(' OR ', map "cust_main.payby = '$_'", @payby). ' )'; } + ### + # paydate_year / paydate_month + ### + + if ( $params->{'paydate_year'} =~ /^(\d{4})$/ ) { + my $year = $1; + $params->{'paydate_month'} =~ /^(\d\d?)$/ + or die "paydate_year without paydate_month?"; + my $month = $1; + + push @where, + 'paydate IS NOT NULL', + "paydate != ''", + "CAST(paydate AS timestamp) < CAST('$year-$month-01' AS timestamp )" +; + } + ## # amounts ##