details:   https://code.openbravo.com/erp/devel/pi/rev/3ac8149413e1
changeset: 13677:3ac8149413e1
user:      Gorka Ion Damián <gorkaion.damian <at> openbravo.com>
date:      Wed Sep 07 18:20:50 2011 +0200
summary:   Fixed issue 18452.Properly manage partially invoiced orders.

diffstat:

 
modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml
 |  40 +++++----
 1 files changed, 23 insertions(+), 17 deletions(-)

diffs (89 lines):

diff -r 802072f308d0 -r 3ac8149413e1 
modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml
--- 
a/modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml
     Wed Sep 07 17:28:54 2011 +0200
+++ 
b/modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml
     Wed Sep 07 18:20:50 2011 +0200
@@ -175,7 +175,6 @@
       v_invoicedamount NUMBER;
       v_notassignedamount NUMBER;
       v_assignedamount NUMBER;
-      v_pendingAmountFromOrder NUMBER:=0;
       v_scheduledetailamount NUMBER;
       v_oldorder VARCHAR2(32) := '-1';
       v_payment_schedule_invoice VARCHAR2(32);
@@ -185,6 +184,7 @@
       v_ConsumedGranTotal NUMBER:= 0;
       v_paymentCount NUMBER:= 0;
       v_negativePS NUMBER:= 1;
+      v_psdbreakbypartialpayment BOOLEAN:=TRUE;
 
       CURSOR cur_order_schdet (invoice_id VARCHAR) IS
       SELECT DISTINCT c_orderline.c_order_id AS order_id, 
fin_payment_scheduledetail.amount + 
COALESCE(fin_payment_scheduledetail.writeoffamt,0) AS amount,
@@ -383,27 +383,31 @@
             END IF;
             IF (NOT next_order) THEN
               v_differenceamount := 0;
-              --1st condition: split order's payment schedule detail in case 
that not all the amount has been invoiced.
-              --2nd condition: invoiced amount is higher than the scheduled 
amount, calculate the difference and split
-              --the payment schedule detail of the order.
-              IF ((v_notassignedamount * v_negativeps <= v_scheduledamount * 
v_negativePS)) THEN
-                v_differenceamount := COALESCE(v_scheduledetailamount,0) - 
COALESCE(v_notassignedamount,0);
-              ELSIF ((v_scheduledamount * v_negativeps < v_notassignedamount * 
v_negativePS)) THEN
-                v_differenceamount := COALESCE(v_scheduledetailamount,0) - 
COALESCE(v_scheduledamount,0);
-              END IF;
 
-              -- The order is completely invoiced and it is the last payment 
schedule. All the pending amount of the
-              -- order has to be assigned to this invoice, a regulation psd 
only related to this invoice will be 
-              -- generated later to match the difference.
+              --1st condition: The order is completely invoiced and it is the 
last payment schedule. All the pending amount of the
+              --               order has to be assigned to this invoice, a 
regulation psd only related to this invoice will be 
+              --               generated later to match the difference.
+              --2st condition: invoiced amount is higher than the scheduled 
amount, calculate the difference and split
+              --               the payment schedule detail of the order.
+              --3rd condition: split order's payment schedule detail in case 
that not all the amount has been invoiced.
+              --               In this case difference amount would not be 
zero.
               IF(v_Count = 0 AND v_paymentcount = 0) THEN
                 v_differenceamount:= 0;
+              ELSIF (v_notassignedamount * v_negativePS > v_scheduledamount * 
v_negativeps ) THEN
+                v_differenceamount := COALESCE(v_scheduledetailamount,0) - 
COALESCE(v_scheduledamount,0);
+                IF (v_paymentcount > 0) THEN
+                  v_psdbreakbypartialpayment := true;
+                ELSE
+                  v_psdbreakbypartialpayment := false;
+                END IF;
+              ELSE
+                v_differenceamount := COALESCE(v_scheduledetailamount,0) - 
COALESCE(v_notassignedamount,0);
+                v_psdbreakbypartialpayment := false;
               END IF;
 
               --When difference amount is not 0 the payment schedule detail of 
the order has to be split. The difference
               --amount is the amount of the new psd that is not related to any 
invoice.
               IF (v_differenceamount <> 0) THEN
-                -- continue with the same payment schedule detail
-                fetch_next_order_item := false;
                 v_new_scheduledetailid := get_uuid();
                 INSERT INTO fin_payment_scheduledetail
                 (
@@ -431,9 +435,12 @@
                 WHERE fin_payment_scheduledetail_id = v_scheduledetailid;
 
                 v_scheduledetailamount := v_scheduledetailamount - 
v_differenceamount;
+              END IF;
 
+              IF (v_differenceamount = 0 OR (v_count <> 0 AND NOT 
v_psdbreakbypartialpayment)) THEN
+                fetch_next_order_item := true;
               ELSE
-                fetch_next_order_item := true;
+                fetch_next_order_item := false;
               END IF;
 
               -- link current current payment schedule detail to the invoice
@@ -481,9 +488,8 @@
               null,
               v_payment_schedule_invoice,
               null,
-              v_scheduledamount - v_pendingAmountFromOrder
+              v_scheduledamount
             );
-            v_pendingAmountFromOrder:=0;
           END IF;
         END LOOP;
 

------------------------------------------------------------------------------
Using storage to extend the benefits of virtualization and iSCSI
Virtualization increases hardware utilization and delivers a new level of
agility. Learn what those decisions are and how to modernize your storage 
and backup environments for virtualization.
http://www.accelacomm.com/jaw/sfnl/114/51434361/
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to