X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_bill_pkg.pm;h=f94bf9b19321ff9f03770d3e26e95679e2b937f7;hb=4109791a9b80df968edaf2e71da8ebcfb8882be3;hp=572fe79739aa13e4141c3217203c906b8f122aeb;hpb=3d0a1bb06b895c5be6e3f0517d355442a6b1e125;p=freeside.git diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm index 572fe7973..f94bf9b19 100644 --- a/FS/FS/cust_bill_pkg.pm +++ b/FS/FS/cust_bill_pkg.pm @@ -955,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' : @@ -965,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 )"; @@ -983,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' : @@ -993,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 )";