details: https://code.openbravo.com/erp/devel/pi/rev/d952a90cd5be changeset: 13490:d952a90cd5be user: Mikel Irurita <mikel.irurita <at> openbravo.com> date: Wed Aug 10 11:04:33 2011 +0200 summary: Format code 3.0 preferences: DocFINReconciliation
details: https://code.openbravo.com/erp/devel/pi/rev/51047ceddf8f changeset: 13491:51047ceddf8f user: Mikel Irurita <mikel.irurita <at> openbravo.com> date: Wed Aug 10 11:29:52 2011 +0200 summary: Fixes issue 18238: Posting reconciliation does not take in account trx acc dimensions diffstat: src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java | 188 +++++---- 1 files changed, 99 insertions(+), 89 deletions(-) diffs (242 lines): diff -r ae573ce0f622 -r 51047ceddf8f 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:29:52 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) @@ -341,10 +341,8 @@ .toString()); FieldProviderFactory.setField(data[0], "description", transaction.getDescription()); FieldProviderFactory.setField(data[0], "cCurrencyId", transaction.getCurrency().getId()); - FieldProviderFactory - .setField(data[0], "cBpartnerId", (transaction.getFinPayment() == null || transaction - .getFinPayment().getBusinessPartner() == null) ? "" : transaction.getFinPayment() - .getBusinessPartner().getId()); + FieldProviderFactory.setField(data[0], "cBpartnerId", + transaction.getBusinessPartner() != null ? transaction.getBusinessPartner().getId() : ""); String dateFormat = OBPropertiesProvider.getInstance().getOpenbravoProperties() .getProperty("dateFormat.java"); SimpleDateFormat outputFormat = new SimpleDateFormat(dateFormat); @@ -357,6 +355,11 @@ if (transaction.getSalesCampaign() != null) FieldProviderFactory.setField(data[0], "cCampaignId", transaction.getSalesCampaign() .getId()); + if (transaction.getProduct() != null) + FieldProviderFactory.setField(data[0], "mProductId", transaction.getProduct().getId()); + if (transaction.getSalesRegion() != null) + FieldProviderFactory.setField(data[0], "cSalesregionId", transaction.getSalesRegion() + .getId()); FieldProviderFactory.setField(data[0], "lineno", transaction.getLineNo().toString()); } finally { OBContext.restorePreviousMode(); @@ -552,95 +555,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 +670,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); ------------------------------------------------------------------------------ uberSVN's rich system and user administration capabilities and model configuration take the hassle out of deploying and managing Subversion and the tools developers use with it. Learn more about uberSVN and get a free download at: http://p.sf.net/sfu/wandisco-dev2dev _______________________________________________ Openbravo-commits mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openbravo-commits
