X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_bill_pkg.pm;h=f94bf9b19321ff9f03770d3e26e95679e2b937f7;hb=c3d33450dd1d457bc8b8c008fe17ffc9128201b1;hp=716c0983e93b2d36033040434bf636080f8b4281;hpb=a14db43cc4ec18badd0aff4fbc3e6738f4f63f6c;p=freeside.git diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm index 716c0983e..f94bf9b19 100644 --- a/FS/FS/cust_bill_pkg.pm +++ b/FS/FS/cust_bill_pkg.pm @@ -434,7 +434,13 @@ sub check { || $self->ut_snumber('pkgnum') || $self->ut_number('invnum') || $self->ut_money('setup') + || $self->ut_moneyn('unitsetup') + || $self->ut_currencyn('setup_billed_currency') + || $self->ut_moneyn('setup_billed_amount') || $self->ut_money('recur') + || $self->ut_moneyn('unitrecur') + || $self->ut_currencyn('recur_billed_currency') + || $self->ut_moneyn('recur_billed_amount') || $self->ut_numbern('sdate') || $self->ut_numbern('edate') || $self->ut_textn('itemdesc') @@ -949,8 +955,8 @@ Returns an SQL expression for the sum of payments applied to this item. sub paid_sql { my ($class, $start, $end, %opt) = @_; - my $s = $start ? "AND cust_bill_pay._date <= $start" : ''; - my $e = $end ? "AND cust_bill_pay._date > $end" : ''; + my $s = $start ? "AND cust_pay._date <= $start" : ''; + my $e = $end ? "AND cust_pay._date > $end" : ''; my $setuprecur = $opt{setuprecur} =~ /^s/ ? 'setup' : $opt{setuprecur} =~ /^r/ ? 'recur' : @@ -959,6 +965,7 @@ sub paid_sql { my $paid = "( SELECT COALESCE(SUM(cust_bill_pay_pkg.amount),0) FROM cust_bill_pay_pkg JOIN cust_bill_pay USING (billpaynum) + JOIN cust_pay USING (paynum) WHERE cust_bill_pay_pkg.billpkgnum = cust_bill_pkg.billpkgnum $s $e $setuprecur )"; @@ -977,8 +984,8 @@ sub paid_sql { sub credited_sql { my ($class, $start, $end, %opt) = @_; - my $s = $start ? "AND cust_credit_bill._date <= $start" : ''; - my $e = $end ? "AND cust_credit_bill._date > $end" : ''; + my $s = $start ? "AND cust_credit._date <= $start" : ''; + my $e = $end ? "AND cust_credit._date > $end" : ''; my $setuprecur = $opt{setuprecur} =~ /^s/ ? 'setup' : $opt{setuprecur} =~ /^r/ ? 'recur' : @@ -987,6 +994,7 @@ sub credited_sql { my $credited = "( SELECT COALESCE(SUM(cust_credit_bill_pkg.amount),0) FROM cust_credit_bill_pkg JOIN cust_credit_bill USING (creditbillnum) + JOIN cust_credit USING (crednum) WHERE cust_credit_bill_pkg.billpkgnum = cust_bill_pkg.billpkgnum $s $e $setuprecur )"; @@ -1104,16 +1112,12 @@ sub upgrade_tax_location { delete @hash{qw(censustract censusyear latitude longitude coord_auto)}; $hash{custnum} = $h_cust_main->custnum; - my $tax_loc = qsearchs('cust_location', \%hash) # unlikely - || FS::cust_location->new({ %hash }); - if ( !$tax_loc->locationnum ) { - $tax_loc->disabled('Y'); - my $error = $tax_loc->insert; - if ( $error ) { - warn "couldn't create historical location record for cust#". - $h_cust_main->custnum.": $error\n"; - next INVOICE; - } + my $tax_loc = FS::cust_location->new(\%hash); + my $error = $tax_loc->find_or_insert || $tax_loc->disable_if_unused; + if ( $error ) { + warn "couldn't create historical location record for cust#". + $h_cust_main->custnum.": $error\n"; + next INVOICE; } my $exempt_cust = 1 if $h_cust_main->tax;