[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[5180] branches/1.3
- Subject: SF.net SVN: ledger-smb:[5180] branches/1.3
- From: ..hidden..
- Date: Sat, 10 Nov 2012 10:10:46 +0000
Revision: 5180
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=5180&view=rev
Author: einhverfr
Date: 2012-11-10 10:10:45 +0000 (Sat, 10 Nov 2012)
Log Message:
-----------
Fixed credit usage calculations
Modified Paths:
--------------
branches/1.3/Changelog
branches/1.3/LedgerSMB/AA.pm
Modified: branches/1.3/Changelog
===================================================================
--- branches/1.3/Changelog 2012-11-09 13:48:04 UTC (rev 5179)
+++ branches/1.3/Changelog 2012-11-10 10:10:45 UTC (rev 5180)
@@ -15,6 +15,7 @@
* Removed unused Subcontractor GIFI field (Chris T, h/t Erik H)
* Changed upgrade screen to pull AR/AP numbers (Erik H)
* Rebuild modules after upgrade, ensuring upgrade to latest version (Chris T)
+* Fixed credit limit usage calculations (Chris T, h/t Erik H)
Berend T is Berend Tober
Chris T is Chris Travers
Modified: branches/1.3/LedgerSMB/AA.pm
===================================================================
--- branches/1.3/LedgerSMB/AA.pm 2012-11-09 13:48:04 UTC (rev 5179)
+++ branches/1.3/LedgerSMB/AA.pm 2012-11-10 10:10:45 UTC (rev 5180)
@@ -1349,41 +1349,26 @@
$form->{creditremaining} = $form->{creditlimit};
$query = qq|
- SELECT SUM(amount - paid)
+ SELECT sum(used) FROM (
+ SELECT SUM((amount - paid) * coalesce(e.$buysell, 1)) as used
FROM $arap
- WHERE id = ?|;
+ LEFT JOIN exchangerate e ON $arap.transdate = e.transdate
+ WHERE entity_credit_account = ?
+ UNION
+ SELECT sum(o.amount * coalesce(e.$buysell, 1)) as used
+ FROM oe o
+ LEFT JOIN exchangerate e ON o.transdate = e.transdate
+ WHERE not closed and oe_class_id in (1, 2)
+ and entity_credit_account = ?) s|;
$sth = $dbh->prepare($query);
- $sth->execute( $form->{"$form->{vc}_id"} )
+ $sth->execute( $form->{"$form->{vc}_id"}, $form->{"$form->{vc}_id"})
|| $form->dberror($query);
my ($credit_rem) = $sth->fetchrow_array;
( $form->{creditremaining} ) -= Math::BigFloat->new($credit_rem);
$sth->finish;
- if ( $form->{vc} ne "customer" ) {
- $form->{vc} = 'vendor';
- }
- $query = qq|
- SELECT o.amount, (SELECT e.$buysell FROM exchangerate e
- WHERE e.curr = o.curr
- AND e.transdate = o.transdate)
- FROM oe o
- WHERE o.entity_id = ?
- AND o.quotation = '0' AND o.closed = '0'|;
-
- $sth = $dbh->prepare($query);
- $sth->execute( $form->{"$form->{vc}_id"} ) || $form->dberror($query);
-
- while ( my @ref = $sth->fetchrow_array ) {
- $form->db_parse_numeric(sth => $sth, arrayref => ..hidden..);
- my ($amount, $exch) = @ref;
- $exch = 1 unless $exch;
- $form->{creditremaining} -= $amount * $exch;
- }
-
- $sth->finish;
-
# get shipto if we did not converted an order or invoice
if ( !$form->{shipto} ) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.