8 our @ISA = qw(Exporter);
9 our @EXPORT = qw(get_credit_remaining);
11 sub get_credit_remaining {
13 my ($type, $arap) = ref $vc eq 'SL::DB::Customer' ? ('customer', 'ar') : ('vendor', 'ap');
16 my $credit_remaining = $vc->creditlimit || 0;
19 SELECT SUM(${arap}.amount - ${arap}.paid)
23 my ($amount_unpaid) = selectfirst_array_query($::form, $vc->dbh, $query, $vc->id);
24 $credit_remaining -= $amount_unpaid;
28 (SELECT e.buy FROM exchangerate e
29 WHERE e.currency_id = o.currency_id
30 AND e.transdate = o.transdate)
32 WHERE (o.${type}_id = ?)
33 AND NOT COALESCE(o.quotation, FALSE)
34 AND NOT COALESCE(o.closed, FALSE)
38 if ($params{exclude_order_id}) {
39 $query .= qq| AND (o.id <> ?)|;
40 push @values, $params{exclude_order_id};
43 my $sth = prepare_execute_query($::form, $vc->dbh, $query, $vc->id, @values);
45 while (my ($amount, $exch) = $sth->fetchrow_array) {
46 $credit_remaining -= $amount * ($exch || 1);
50 return $credit_remaining;