X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_bill.pm;h=127053013abc8db1b69e4c403551524412a8a850;hb=7b125e587a4d1ee0aca692e23ea7897f671855ae;hp=f10a5d0c42226818e45a8c35dc735be9cc353536;hpb=08b36523ebbf6e2995878f26bfac988f32f7a218;p=freeside.git diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index f10a5d0c4..127053013 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -4341,8 +4341,7 @@ Returns an SQL fragment to retreive the amount owed (charged minus credited and =cut sub owed_sql { - my $class = shift; - my ($start, $end) = @_; + my ($class, $start, $end) = @_; 'charged - '. $class->paid_sql($start, $end). ' - '. $class->credited_sql($start, $end); @@ -4355,8 +4354,7 @@ Returns an SQL fragment to retreive the net amount (charged minus credited). =cut sub net_sql { - my $class = shift; - my ($start, $end) = @_; + my ($class, $start, $end) = @_; 'charged - '. $class->credited_sql($start, $end); } @@ -4369,7 +4367,9 @@ Returns an SQL fragment to retreive the amount paid against this invoice. sub paid_sql { my ($class, $start, $end) = @_; $start &&= "AND cust_bill_pay._date <= $start"; - $end &&= "AND cust_bill_pay._date > $end"; + $end &&= "AND cust_bill_pay._date > $end"; + $start = '' unless defined($start); + $end = '' unless defined($end); "( SELECT COALESCE(SUM(amount),0) FROM cust_bill_pay WHERE cust_bill.invnum = cust_bill_pay.invnum $start $end )"; } @@ -4381,9 +4381,11 @@ Returns an SQL fragment to retreive the amount credited against this invoice. =cut sub credited_sql { - my ($class, $start, $end) = shift; + my ($class, $start, $end) = @_; $start &&= "AND cust_credit_bill._date <= $start"; - $end &&= "AND cust_credit_bill._date > $end"; + $end &&= "AND cust_credit_bill._date > $end"; + $start = '' unless defined($start); + $end = '' unless defined($end); "( SELECT COALESCE(SUM(amount),0) FROM cust_credit_bill WHERE cust_bill.invnum = cust_credit_bill.invnum $start $end )"; }