[Doubtful Debt] Fixes payment processing and reactivation + trigger.
authorEduardo Argal Guibert <eduardo.argal@openbravo.com>
Fri, 11 Jan 2013 10:07:44 +0100
changeset 19565 2ffacd79bc39
parent 19564 0e5eed990909
child 19566 0192e05b4f00
[Doubtful Debt] Fixes payment processing and reactivation + trigger.
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.java
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java
src-db/database/model/triggers/FIN_DOUBTFUL_DEBT_RUN_CHK_TRG.xml
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.java	Thu Jan 10 17:47:11 2013 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.java	Fri Jan 11 10:07:44 2013 +0100
@@ -321,6 +321,8 @@
               // update existing PD with difference
               outStandingPSDs.get(0).setAmount(
                   outStandingPSDs.get(0).getAmount().add(psd.getAmount()));
+              outStandingPSDs.get(0).setDebtAmount(
+                  outStandingPSDs.get(0).getDebtAmount().add(psd.getDebtAmount()));
               OBDal.getInstance().save(outStandingPSDs.get(0));
             }
             toRemovePDs.add(pd.getId());
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java	Thu Jan 10 17:47:11 2013 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java	Fri Jan 11 10:07:44 2013 +0100
@@ -70,8 +70,6 @@
     try {
       // retrieve custom params
       final String strAction = (String) bundle.getParams().get("action");
-      // This parameter is used inside this class
-      String isReversedPayment = (String) bundle.getParams().get("isReversedPayment");
       // retrieve standard params
       final String recordID = (String) bundle.getParams().get("Fin_Payment_ID");
       final FIN_Payment payment = dao.getObject(FIN_Payment.class, recordID);
@@ -634,6 +632,7 @@
                 // Restore write off
                 List<FIN_PaymentScheduleDetail> outstandingPDSs = FIN_AddPayment
                     .getOutstandingPSDs(paymentScheduleDetail);
+                BigDecimal outstandingDebtAmount = BigDecimal.ZERO;
                 if (outstandingPDSs.size() > 0) {
                   outstandingPDSs.get(0).setAmount(
                       outstandingPDSs.get(0).getAmount().add(psdWriteoffAmount));
@@ -642,12 +641,16 @@
                   FIN_PaymentScheduleDetail outstandingPSD = (FIN_PaymentScheduleDetail) DalUtil
                       .copy(paymentScheduleDetail, false);
                   outstandingPSD.setAmount(psdWriteoffAmount);
+                  outstandingDebtAmount = paymentScheduleDetail.getDebtAmount().subtract(
+                      paymentScheduleDetail.getAmount());
+                  outstandingPSD.setDebtAmount(outstandingDebtAmount);
                   outstandingPSD.setWriteoffAmount(BigDecimal.ZERO);
                   outstandingPSD.setPaymentDetails(null);
                   OBDal.getInstance().save(outstandingPSD);
                 }
                 paymentScheduleDetail.setWriteoffAmount(BigDecimal.ZERO);
-                paymentScheduleDetail.setDebtAmount(BigDecimal.ZERO);
+                paymentScheduleDetail.setDebtAmount(paymentScheduleDetail.getDebtAmount().subtract(
+                    outstandingDebtAmount));
                 paymentScheduleDetail.getPaymentDetails().setWriteoffAmount(BigDecimal.ZERO);
                 OBDal.getInstance().save(paymentScheduleDetail.getPaymentDetails());
                 OBDal.getInstance().save(paymentScheduleDetail);
--- a/src-db/database/model/triggers/FIN_DOUBTFUL_DEBT_RUN_CHK_TRG.xml	Thu Jan 10 17:47:11 2013 +0100
+++ b/src-db/database/model/triggers/FIN_DOUBTFUL_DEBT_RUN_CHK_TRG.xml	Fri Jan 11 10:07:44 2013 +0100
@@ -19,6 +19,8 @@
     ************************************************************************/
 
   v_DateNull DATE := TO_DATE('01-01-1900', 'DD-MM-YYYY');
+  V_Processed FIN_Doubtful_Debt.Processed%TYPE;
+
 
      
 BEGIN
@@ -36,17 +38,24 @@
     OR(COALESCE(:old.RUNDATE, v_DateNull) <> COALESCE(:new.RUNDATE, v_DateNull))
     OR(COALESCE(:old.AD_ORG_ID, '0') <> COALESCE(:new.AD_ORG_ID, '0'))
     OR(COALESCE(:old.AD_CLIENT_ID, '0') <> COALESCE(:new.AD_CLIENT_ID, '0')))) THEN
-      RAISE_APPLICATION_ERROR(-20000, '@20501@') ;
+      RAISE_APPLICATION_ERROR(-20000, '@20507@') ;
     END IF;
   END IF;
   IF(DELETING) THEN
     IF(:old.Processed='Y') THEN
       RAISE_APPLICATION_ERROR(-20000, '@20501@') ;
     END IF;
+    SELECT COALESCE(MAX(PROCESSED), 'N')
+    	INTO V_PROCESSED
+		FROM FIN_DOUBTFUL_DEBT 
+		WHERE fin_doubtful_debt_run_id = :old.fin_doubtful_debt_run_id;
+		IF(V_PROCESSED = 'Y') THEN
+			RAISE_APPLICATION_ERROR(-20000, '@20503@') ;
+		END IF;
   END IF;
   IF(INSERTING) THEN
     IF(:NEW.Processed='Y') THEN
-      RAISE_APPLICATION_ERROR(-20000, '@20501@') ;
+      RAISE_APPLICATION_ERROR(-20000, '@20509@') ;
     END IF;
   END IF;
 END FIN_DOUBTFUL_DEBT_RUN_CHK_TRG