- my $total_credit = 0;
- my @cust_credit = $sales->cust_credit( $beginning, $ending );
- $total_credit += $_->amount foreach @cust_credit;
+ #my $total_credit = 0;
+ #my @cust_credit = $sales->cust_credit( $beginning, $ending );
+ #$total_credit += $_->amount foreach @cust_credit;
+
+ my $search = $sales->cust_credit_search( $beginning, $ending );
+
+ my $sql =
+ "SELECT SUM(cust_credit.amount) FROM cust_credit ". #$search->{table}
+ $search->{addl_from}. ' '.
+ ' WHERE commission_salesnum = ? '. #$search->{hashref}
+ $search->{extra_sql};
+
+ my $total = FS::Record->scalar_sql($sql, $sales->salesnum);