Format code 3.0 preferences: DocFINReconciliation
authorMikel Irurita <mikel.irurita@openbravo.com>
Wed, 10 Aug 2011 11:04:33 +0200
changeset 13498 d952a90cd5be
parent 13497 ae573ce0f622
child 13499 51047ceddf8f
Format code 3.0 preferences: DocFINReconciliation
src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java	Wed Aug 10 02:41:13 2011 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java	Wed Aug 10 11:04:33 2011 +0200
@@ -218,11 +218,11 @@
             transaction.getGLItem() != null ? transaction.getGLItem().getId() : data[i]
                 .getField("cGlItemId"));
         FieldProviderFactory.setField(data[i], "cInvoiceId", paymentDetails.get(i)
-                .getFINPaymentScheduleDetailList().get(0).getInvoicePaymentSchedule() != null
-                && paymentDetails.get(i).getFINPaymentScheduleDetailList().get(0)
-                    .getInvoicePaymentSchedule().getInvoice() != null ? paymentDetails
-                .get(i).getFINPaymentScheduleDetailList().get(0).getInvoicePaymentSchedule()
-                .getInvoice().getId() : "");
+            .getFINPaymentScheduleDetailList().get(0).getInvoicePaymentSchedule() != null
+            && paymentDetails.get(i).getFINPaymentScheduleDetailList().get(0)
+                .getInvoicePaymentSchedule().getInvoice() != null ? paymentDetails.get(i)
+            .getFINPaymentScheduleDetailList().get(0).getInvoicePaymentSchedule().getInvoice()
+            .getId() : "");
         FieldProviderFactory.setField(data[i], "description", transaction.getDescription());
         FieldProviderFactory.setField(data[i], "cCurrencyId", transaction.getCurrency().getId());
         FieldProviderFactory.setField(data[i], "cProjectId", paymentDetails.get(i)
@@ -552,95 +552,102 @@
         fact = createFactPaymentDetails(detail, paymentDetail, as, conn, fact, Fact_Acct_Group_ID);
       }
     } else {
-      fact.createLine(line, getAccountPayment(conn, payment, as), C_Currency_ID, !payment
-          .isReceipt() ? line.getAmount() : "", payment.isReceipt() ? line.getAmount() : "",
-          Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType,  null, null, EXCHANGE_DOCTYPE_Payment, payment.getId(), conn);
+      fact.createLine(line, getAccountPayment(conn, payment, as), C_Currency_ID,
+          !payment.isReceipt() ? line.getAmount() : "",
+          payment.isReceipt() ? line.getAmount() : "", Fact_Acct_Group_ID, nextSeqNo(SeqNo),
+          DocumentType, null, null, EXCHANGE_DOCTYPE_Payment, payment.getId(), conn);
     }
-    fact.createLine(line, getAccountReconciliation(conn, payment, as), C_Currency_ID, payment
-        .isReceipt() ? line.getAmount() : "", !payment.isReceipt() ? line.getAmount() : "",
-        Fact_Acct_Group_ID, "999999", DocumentType, null, null, EXCHANGE_DOCTYPE_Transaction, transaction.getId(),conn);
+    fact.createLine(line, getAccountReconciliation(conn, payment, as), C_Currency_ID,
+        payment.isReceipt() ? line.getAmount() : "", !payment.isReceipt() ? line.getAmount() : "",
+        Fact_Acct_Group_ID, "999999", DocumentType, null, null, EXCHANGE_DOCTYPE_Transaction,
+        transaction.getId(), conn);
     if (!getDocumentPaymentConfirmation(payment)
         && !getDocumentTransactionConfirmation(transaction)) {
       // Pre-payment is consumed when Used Credit Amount not equals Zero. When consuming Credit no
       // credit is generated
       if (payment.getUsedCredit().compareTo(ZERO) != 0
           && payment.getGeneratedCredit().compareTo(ZERO) == 0) {
-        fact.createLine(line, getAccountBPartner(payment.getBusinessPartner().getId(), as, payment
-            .isReceipt(), true, conn), C_Currency_ID, (payment.isReceipt() ? payment
-            .getUsedCredit().toString() : ""), (payment.isReceipt() ? "" : payment.getUsedCredit()
-            .toString()), Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, null, null ,EXCHANGE_DOCTYPE_Invoice, line.getInvoiceId(), conn);
+        fact.createLine(
+            line,
+            getAccountBPartner(payment.getBusinessPartner().getId(), as, payment.isReceipt(), true,
+                conn), C_Currency_ID, (payment.isReceipt() ? payment.getUsedCredit().toString()
+                : ""), (payment.isReceipt() ? "" : payment.getUsedCredit().toString()),
+            Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, null, null,
+            EXCHANGE_DOCTYPE_Invoice, line.getInvoiceId(), conn);
       }
     }
-    //Create balancing
-    FIN_Reconciliation reconciliation = OBDal.getInstance().get(FIN_Reconciliation.class, Record_ID);
+    // Create balancing
+    FIN_Reconciliation reconciliation = OBDal.getInstance()
+        .get(FIN_Reconciliation.class, Record_ID);
     createFactCurrencyBalancing(as, conn, fact, Fact_Acct_Group_ID, reconciliation);
-    
+
     SeqNo = "0";
     return fact;
   }
+
   private void createFactCurrencyBalancing(AcctSchema as, ConnectionProvider conn, Fact fact,
-	      String fact_Acct_Group_ID, FIN_Reconciliation reconciliation) throws ServletException {
-	    final BigDecimal acctBalance = fact.getAcctBalance();
-	    if (BigDecimal.ZERO.compareTo(acctBalance) != 0) {
-	      // Need to add balancing entry
-	      // Balance == AcctDr - AcctCr
-	      String currencyLossDR = "0";
-	      String currencyGainCR = "0";
-	      boolean isGain = acctBalance.compareTo(BigDecimal.ZERO) > 0;
-	      if (isGain) {
-	        // debit > credit = need to credit
-	        currencyGainCR = acctBalance == null ? "" : acctBalance.toPlainString();
-	      } else {
-	        // debit < credit = need to debit
-	        currencyLossDR = acctBalance.negate() == null ? "" : acctBalance.negate().toPlainString();
-	      }
+      String fact_Acct_Group_ID, FIN_Reconciliation reconciliation) throws ServletException {
+    final BigDecimal acctBalance = fact.getAcctBalance();
+    if (BigDecimal.ZERO.compareTo(acctBalance) != 0) {
+      // Need to add balancing entry
+      // Balance == AcctDr - AcctCr
+      String currencyLossDR = "0";
+      String currencyGainCR = "0";
+      boolean isGain = acctBalance.compareTo(BigDecimal.ZERO) > 0;
+      if (isGain) {
+        // debit > credit = need to credit
+        currencyGainCR = acctBalance == null ? "" : acctBalance.toPlainString();
+      } else {
+        // debit < credit = need to debit
+        currencyLossDR = acctBalance.negate() == null ? "" : acctBalance.negate().toPlainString();
+      }
 
-	      String currencyLossGainAcctComboId = null;
-	      // Find gain / loss accounts from account
-	      for (FIN_FinancialAccountAccounting accounting : reconciliation.getAccount()
-	          .getFINFinancialAccountAcctList()) {
-	        if (accounting.getAccountingSchema().getId().equals(as.getC_AcctSchema_ID())) {
-	          AccountingCombination revaluationAcct;
-	          if (isGain) {
-	            revaluationAcct = accounting.getFINBankrevaluationgainAcct();
-	          } else {
-	            revaluationAcct = accounting.getFINBankrevaluationlossAcct();
-	          }
-	          if (revaluationAcct != null) {
-	            currencyLossGainAcctComboId = revaluationAcct.getId();
-	          }
-	          break;
-	        }
-	      }
-	      if (currencyLossGainAcctComboId == null) {
-	        // Find default gain/loss accounts from schema
-	        final OBQuery<AcctSchemaDefault> obqAcctSchemDefault = OBDal.getInstance().createQuery(
-	            AcctSchemaDefault.class, " where accountingSchema.id = '" + as.m_C_AcctSchema_ID + "'");
-	        final AcctSchemaDefault acctSchemaDefault = obqAcctSchemDefault.list().get(0);
-	        AccountingCombination defaultRevaluationAcct;
-	        if (isGain) {
-	          defaultRevaluationAcct = acctSchemaDefault.getBankRevaluationGain();
-	        } else {
-	          defaultRevaluationAcct = acctSchemaDefault.getBankRevaluationLoss();
-	        }
-	        if (currencyLossGainAcctComboId == null && defaultRevaluationAcct != null) {
-	          currencyLossGainAcctComboId = defaultRevaluationAcct.getId();
-	        }
-	      }
-	      Account accountGainLoss = Account.getAccount(conn, currencyLossGainAcctComboId);
-	      if (accountGainLoss == null) {
-	        // Fall back to currency balancing
-	        accountGainLoss = as.getCurrencyBalancing_Acct();
-	      }
+      String currencyLossGainAcctComboId = null;
+      // Find gain / loss accounts from account
+      for (FIN_FinancialAccountAccounting accounting : reconciliation.getAccount()
+          .getFINFinancialAccountAcctList()) {
+        if (accounting.getAccountingSchema().getId().equals(as.getC_AcctSchema_ID())) {
+          AccountingCombination revaluationAcct;
+          if (isGain) {
+            revaluationAcct = accounting.getFINBankrevaluationgainAcct();
+          } else {
+            revaluationAcct = accounting.getFINBankrevaluationlossAcct();
+          }
+          if (revaluationAcct != null) {
+            currencyLossGainAcctComboId = revaluationAcct.getId();
+          }
+          break;
+        }
+      }
+      if (currencyLossGainAcctComboId == null) {
+        // Find default gain/loss accounts from schema
+        final OBQuery<AcctSchemaDefault> obqAcctSchemDefault = OBDal.getInstance().createQuery(
+            AcctSchemaDefault.class, " where accountingSchema.id = '" + as.m_C_AcctSchema_ID + "'");
+        final AcctSchemaDefault acctSchemaDefault = obqAcctSchemDefault.list().get(0);
+        AccountingCombination defaultRevaluationAcct;
+        if (isGain) {
+          defaultRevaluationAcct = acctSchemaDefault.getBankRevaluationGain();
+        } else {
+          defaultRevaluationAcct = acctSchemaDefault.getBankRevaluationLoss();
+        }
+        if (currencyLossGainAcctComboId == null && defaultRevaluationAcct != null) {
+          currencyLossGainAcctComboId = defaultRevaluationAcct.getId();
+        }
+      }
+      Account accountGainLoss = Account.getAccount(conn, currencyLossGainAcctComboId);
+      if (accountGainLoss == null) {
+        // Fall back to currency balancing
+        accountGainLoss = as.getCurrencyBalancing_Acct();
+      }
 
-	      if (accountGainLoss != null) {
-	        final FactLine line = fact.createLine(null, accountGainLoss, as.getC_Currency_ID(),
-	            currencyLossDR, currencyGainCR, fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType,
-	            conn);
-	        line.setAmtSource(C_Currency_ID, "0", "0"); // Mimic normal currency balancing
-	      }
-	    }
-	  }
+      if (accountGainLoss != null) {
+        final FactLine line = fact.createLine(null, accountGainLoss, as.getC_Currency_ID(),
+            currencyLossDR, currencyGainCR, fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType,
+            conn);
+        line.setAmtSource(C_Currency_ID, "0", "0"); // Mimic normal currency balancing
+      }
+    }
+  }
 
   @Deprecated
   public Fact createFactPaymentDetails(DocLine_FINReconciliation line, AcctSchema as,
@@ -660,13 +667,13 @@
       BigDecimal bpAmount = new BigDecimal(line.getAmount());
       if (line.getWriteOffAmt() != null
           && ZERO.compareTo(new BigDecimal(line.getWriteOffAmt())) != 0) {
-      Account account = isReceipt ? getAccountWriteOffBPartner(AcctServer.ACCTTYPE_WriteOff,
-          line.m_C_BPartner_ID, as, conn) : getAccountWriteOffBPartner(
-          AcctServer.ACCTTYPE_WriteOff_Revenue, line.m_C_BPartner_ID, as, conn);
-      if (account == null) {
-        account = isReceipt ? getAccount(AcctServer.ACCTTYPE_WriteOffDefault, as, conn)
-            : getAccount(AcctServer.ACCTTYPE_WriteOffDefault_Revenue, as, conn);
-      }
+        Account account = isReceipt ? getAccountWriteOffBPartner(AcctServer.ACCTTYPE_WriteOff,
+            line.m_C_BPartner_ID, as, conn) : getAccountWriteOffBPartner(
+            AcctServer.ACCTTYPE_WriteOff_Revenue, line.m_C_BPartner_ID, as, conn);
+        if (account == null) {
+          account = isReceipt ? getAccount(AcctServer.ACCTTYPE_WriteOffDefault, as, conn)
+              : getAccount(AcctServer.ACCTTYPE_WriteOffDefault_Revenue, as, conn);
+        }
         fact.createLine(line, account, C_Currency_ID, (isReceipt ? line.getWriteOffAmt() : ""),
             (isReceipt ? "" : line.getWriteOffAmt()), Fact_Acct_Group_ID, nextSeqNo(SeqNo),
             DocumentType, conn);