X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main.pm;h=e696e1bc9bf5bd2feeabb057fa573ad61ac0222b;hb=4d9f43b90460175581aaa976e9b9937f20ccc434;hp=1766b45427323632b603676c27b320a1e9ba79c3;hpb=4a525836ffb9fa8a941c11247637543d931733b8;p=freeside.git diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 1766b4542..e696e1bc9 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -1819,17 +1819,13 @@ sub all_pkgs { my $self = shift; my $extra_qsearch = ref($_[0]) ? shift : {}; - return $self->num_pkgs unless wantarray; #XXX doesn't work w/$extra_qsearch + return $self->num_pkgs unless wantarray || keys(%$extra_qsearch); my @cust_pkg = (); if ( $self->{'_pkgnum'} ) { @cust_pkg = values %{ $self->{'_pkgnum'}->cache }; } else { - @cust_pkg = qsearch({ - %$extra_qsearch, - 'table' => 'cust_pkg', - 'hashref' => { 'custnum' => $self->custnum }, - }); + @cust_pkg = $self->_cust_pkg($extra_qsearch); } sort sort_packages @cust_pkg; @@ -1883,12 +1879,9 @@ sub ncancelled_pkgs { $self->custnum. "\n" if $DEBUG > 1; - @cust_pkg = qsearch({ - %$extra_qsearch, - 'table' => 'cust_pkg', - 'hashref' => { 'custnum' => $self->custnum }, - 'extra_sql' => ' AND ( cancel IS NULL OR cancel = 0 ) ', - }); + $extra_qsearch->{'extra_sql'} .= ' AND ( cancel IS NULL OR cancel = 0 ) '; + + @cust_pkg = $self->_cust_pkg($extra_qsearch); } @@ -1896,6 +1889,27 @@ sub ncancelled_pkgs { } +sub _cust_pkg { + my $self = shift; + my $extra_qsearch = ref($_[0]) ? shift : {}; + + $extra_qsearch->{'select'} ||= '*'; + $extra_qsearch->{'select'} .= + ',( SELECT COUNT(*) FROM cust_svc WHERE cust_pkg.pkgnum = cust_svc.pkgnum ) + AS _num_cust_svc'; + + map { + $_->{'_num_cust_svc'} = $_->get('_num_cust_svc'); + $_; + } + qsearch({ + %$extra_qsearch, + 'table' => 'cust_pkg', + 'hashref' => { 'custnum' => $self->custnum }, + }); + +} + # This should be generalized to use config options to determine order. sub sort_packages { @@ -1905,11 +1919,13 @@ sub sort_packages { #shouldn't get here... return 0; } else { + my $a_num_cust_svc = $a->num_cust_svc; + my $b_num_cust_svc = $b->num_cust_svc; + return 0 if !$a_num_cust_svc && !$b_num_cust_svc; + return -1 if $a_num_cust_svc && !$b_num_cust_svc; + return 1 if !$a_num_cust_svc && $b_num_cust_svc; my @a_cust_svc = $a->cust_svc; my @b_cust_svc = $b->cust_svc; - return 0 if !scalar(@a_cust_svc) && !scalar(@b_cust_svc); - return -1 if scalar(@a_cust_svc) && !scalar(@b_cust_svc); - return 1 if !scalar(@a_cust_svc) && scalar(@b_cust_svc); $a_cust_svc[0]->svc_x->label cmp $b_cust_svc[0]->svc_x->label; } @@ -2517,20 +2533,20 @@ sub bill { my $tax_object = shift @{ $totlisthash{$tax} }; warn "found previously found taxed tax ". $tax_object->taxname. "\n" if $DEBUG > 2; - my $listref_or_error = + my $hashref_or_error = $tax_object->taxline( $totlisthash{$tax}, 'custnum' => $self->custnum, 'invoice_time' => $invoice_time ); - unless (ref($listref_or_error)) { + unless (ref($hashref_or_error)) { $dbh->rollback if $oldAutoCommit; - return $listref_or_error; + return $hashref_or_error; } - warn "adding taxed tax amount ". $listref_or_error->[1]. + warn "adding taxed tax amount ". $hashref_or_error->{'amount'}. " as ". $tax_object->taxname. "\n" if $DEBUG; - $tax{ $tax } += $listref_or_error->[1]; + $tax{ $tax } += $hashref_or_error->{'amount'}; } #consolidate and create tax line items @@ -2923,7 +2939,7 @@ sub _handle_taxes { foreach my $tax ( @taxes ) { - my $taxname = ref( $tax ). ' taxnum'. $tax->taxnum; + my $taxname = ref( $tax ). ' '. $tax->taxnum; # $taxname .= ' pkgnum'. $cust_pkg->pkgnum. # ' locationnum'. $cust_pkg->locationnum # if $conf->exists('tax-pkg_address') && $cust_pkg->locationnum;