[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[6823] trunk



Revision: 6823
          http://sourceforge.net/p/ledger-smb/code/6823
Author:   einhverfr
Date:     2014-02-10 09:13:57 +0000 (Mon, 10 Feb 2014)
Log Message:
-----------
overpayment reversal fixes, closing 1023

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Payment.pm
    trunk/LedgerSMB/Scripts/reports.pm
    trunk/sql/modules/Payment.sql

Modified: trunk/LedgerSMB/DBObject/Payment.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Payment.pm	2014-02-10 08:52:19 UTC (rev 6822)
+++ trunk/LedgerSMB/DBObject/Payment.pm	2014-02-10 09:13:57 UTC (rev 6823)
@@ -816,7 +816,7 @@
 
 sub overpayment_reverse {
     my ($self, $args) = @_;
-    __PACKAGE__->call_procedure(procname => 'payment__reverse_overpayment',
+    __PACKAGE__->call_procedure(procname => 'overpayment__reverse',
                                      args => [$args->{id},
                                               $args->{post_date},
                                               $args->{batch_id},

Modified: trunk/LedgerSMB/Scripts/reports.pm
===================================================================
--- trunk/LedgerSMB/Scripts/reports.pm	2014-02-10 08:52:19 UTC (rev 6822)
+++ trunk/LedgerSMB/Scripts/reports.pm	2014-02-10 09:13:57 UTC (rev 6823)
@@ -200,7 +200,8 @@
         next unless $request->{"select_$rc"};
         my $args = {id => $request->{"select_$rc"}};
         $args->{$_} = $request->{$_} for qw(post_date batch_id account_class
-                                            exchangerate, curr);
+                                            exchangerate, currency);
+        $args->{curr} = $args->{currency};
         LedgerSMB::DBObject::Payment->overpayment_reverse($args);
     }
     $request->{report_name} = 'overpayments';

Modified: trunk/sql/modules/Payment.sql
===================================================================
--- trunk/sql/modules/Payment.sql	2014-02-10 08:52:19 UTC (rev 6822)
+++ trunk/sql/modules/Payment.sql	2014-02-10 09:13:57 UTC (rev 6823)
@@ -1566,12 +1566,16 @@
 
 INSERT INTO gl (transdate, reference, description, approved)
 SELECT transdate, reference || '-reversal', 'reversal of ' || description, '0'
-  FROM gl WHERE id = in_id;
+  FROM gl WHERE id = (select gl_id from payment where id = in_id);
 
-t_id := curval('id');
+IF NOT FOUND THEN
+   RETURN FALSE;
+END IF;
 
+t_id := currval('id');
+
 INSERT INTO voucher (batch_id, trans_id, batch_class)
-VALUES (in_batch_id, t_id, CASE WHEN in_account_class == 1 THEN 4 ELSE 7 END);
+VALUES (in_batch_id, t_id, CASE WHEN in_account_class = 1 THEN 4 ELSE 7 END);
 
 INSERT INTO acc_trans (transdate, trans_id, chart_id, amount)
 SELECT in_transdate, t_id, chart_id, amount * -1
@@ -1579,25 +1583,22 @@
  WHERE trans_id = in_id;
 
 -- reverse overpayment usage
-SELECT payment__reverse(ac.source, ac.transdate, eca.id, accno,
+PERFORM payment__reverse(ac.source, ac.transdate, eca.id, at.accno,
         in_transdate, eca.entity_class, in_batch_id, null, 
-        in_exchangerate, in_currency)
+        in_exchangerate, in_curr)
   FROM acc_trans ac
-  JOIN account a ON ac.chart_id = a.id
-  JOIN account_link al ON a.id = al.account_id AND description like 'A%paid'
+  JOIN account at ON ac.chart_id = at.id
+  JOIN account_link al ON at.id = al.account_id AND al.description like 'A%paid'
   JOIN (select id, entity_credit_account FROM ar UNION
         select id, entity_credit_account from ap) a ON a.id = ac.trans_id
   JOIN entity_credit_account eca ON a.entity_credit_account = eca.id
-  JOIN payment_links pl ON pl.entry_id = a.entry_id
-  JOIN overpayment op ON op.id = pl.payment_id
-  JOIN payment p ON p.id = o.payment_id
+  JOIN payment_links pl ON pl.entry_id = ac.entry_id
+  JOIN overpayments op ON op.payment_id = pl.payment_id
+  JOIN payment p ON p.id = op.payment_id
  WHERE p.gl_id = in_id
 GROUP BY ac.source, ac.transdate, eca.id, eca.entity_class,
-         a.accno, al.description;
+         at.accno, al.description;
 
-UPDATE overpayment set available = 0 
- WHERE payment_id = (select id from payment where gl_id = in_id);
-
 RETURN TRUE;
 END;
 $$;

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk
_______________________________________________
Ledger-smb-commits mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-commits