details: /erp/devel/pi/rev/26ee9d288ed9
changeset: 11519:26ee9d288ed9
user: Eduardo Argal Guibert <eduardo.argal <at> openbravo.com>
date: Wed Apr 06 12:12:29 2011 +0200
summary: fixes bug 0016177, adds message per accounting when table is
disabled in accounting schema/s, changed chech in accounting of payments
diffstat:
src-db/database/sourcedata/AD_MESSAGE.xml | 11 +
src/org/openbravo/erpCommon/ad_forms/AcctServer.java | 52 ++++-
src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java | 101 +++++++++-
src/org/openbravo/erpCommon/ad_forms/DocLine_FINPayment.java | 20 ++
src/org/openbravo/erpCommon/ad_forms/FactLine.java | 2 +-
5 files changed, 162 insertions(+), 24 deletions(-)
diffs (truncated from 337 to 300 lines):
diff -r 433ad8e1d1cf -r 26ee9d288ed9 src-db/database/sourcedata/AD_MESSAGE.xml
--- a/src-db/database/sourcedata/AD_MESSAGE.xml Wed Apr 06 11:48:50 2011 +0200
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml Wed Apr 06 12:12:29 2011 +0200
@@ -34435,6 +34435,17 @@
<!--FF8080812EDE8228012EE3857935003C-->
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
<!--FF8080812EDE8228012EE3857935003C--></AD_MESSAGE>
+<!--FF8080812EFD7CD9012EFD9B49970172--><AD_MESSAGE>
+<!--FF8080812EFD7CD9012EFD9B49970172-->
<AD_MESSAGE_ID><![CDATA[FF8080812EFD7CD9012EFD9B49970172]]></AD_MESSAGE_ID>
+<!--FF8080812EFD7CD9012EFD9B49970172-->
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8080812EFD7CD9012EFD9B49970172--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8080812EFD7CD9012EFD9B49970172--> <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8080812EFD7CD9012EFD9B49970172-->
<VALUE><![CDATA[TableDisabled]]></VALUE>
+<!--FF8080812EFD7CD9012EFD9B49970172--> <MSGTEXT><![CDATA[Document will not
be posted as related table is not active for any of the accounting schemas.
Please first activate related table @Table@ in the accounting
schema/s]]></MSGTEXT>
+<!--FF8080812EFD7CD9012EFD9B49970172--> <MSGTYPE><![CDATA[W]]></MSGTYPE>
+<!--FF8080812EFD7CD9012EFD9B49970172-->
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--FF8080812EFD7CD9012EFD9B49970172--></AD_MESSAGE>
+
<!--FF8081812EDCCB27012EDCD3F897000A--><AD_MESSAGE>
<!--FF8081812EDCCB27012EDCD3F897000A-->
<AD_MESSAGE_ID><![CDATA[FF8081812EDCCB27012EDCD3F897000A]]></AD_MESSAGE_ID>
<!--FF8081812EDCCB27012EDCD3F897000A-->
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff -r 433ad8e1d1cf -r 26ee9d288ed9
src/org/openbravo/erpCommon/ad_forms/AcctServer.java
--- a/src/org/openbravo/erpCommon/ad_forms/AcctServer.java Wed Apr 06
11:48:50 2011 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/AcctServer.java Wed Apr 06
12:12:29 2011 +0200
@@ -21,7 +21,9 @@
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Vector;
import javax.servlet.ServletException;
@@ -32,6 +34,7 @@
import org.openbravo.dal.core.OBContext;
import org.openbravo.dal.service.OBCriteria;
import org.openbravo.dal.service.OBDal;
+import org.openbravo.dal.service.OBDao;
import org.openbravo.dal.service.OBQuery;
import org.openbravo.data.FieldProvider;
import org.openbravo.database.ConnectionProvider;
@@ -40,9 +43,11 @@
import org.openbravo.erpCommon.utility.SequenceIdData;
import org.openbravo.erpCommon.utility.Utility;
import org.openbravo.exception.NoConnectionAvailableException;
+import org.openbravo.model.ad.datamodel.Table;
import org.openbravo.model.common.businesspartner.CustomerAccounts;
import org.openbravo.model.common.businesspartner.VendorAccounts;
import
org.openbravo.model.financialmgmt.accounting.FIN_FinancialAccountAccounting;
+import org.openbravo.model.financialmgmt.accounting.coa.AcctSchemaTable;
import org.openbravo.model.financialmgmt.gl.GLItem;
import org.openbravo.model.financialmgmt.gl.GLItemAccounts;
import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
@@ -147,6 +152,8 @@
/** Document Status */
public static final String STATUS_DocumentDisabled = "D";
/** Document Status */
+ public static final String STATUS_TableDisabled = "T";
+ /** Document Status */
public static final String STATUS_BackgroundDisabled = "d";
OBError messageResult = null;
@@ -638,7 +645,25 @@
// log4j.debug("AcctServer - Post - Antes de new Fact - C_CURRENCY_ID = "
// + C_Currency_ID);
m_fact = new Fact[m_as.length];
-
+ // AcctSchema Table check
+ boolean isTableActive = false;
+ for (AcctSchema as : m_as) {
+ AcctSchemaTable table = (AcctSchemaTable) OBDao.getFilteredCriteria(
+ AcctSchemaTable.class,
+ Expression.eq(AcctSchemaTable.PROPERTY_ACCOUNTINGSCHEMA,
OBDal.getInstance().get(
+
org.openbravo.model.financialmgmt.accounting.coa.AcctSchema.class,
+ as.getC_AcctSchema_ID())),
+ Expression.eq(AcctSchemaTable.PROPERTY_TABLE,
OBDal.getInstance().get(Table.class,
+ AD_Table_ID))).uniqueResult();
+ if (table != null) {
+ isTableActive = true;
+ break;
+ }
+ }
+ if (!isTableActive) {
+ setMessageResult(conn, vars, STATUS_TableDisabled, "Warning");
+ return false;
+ }
// for all Accounting Schema
boolean OK = true;
if (log4j.isDebugEnabled())
@@ -1731,6 +1756,7 @@
if (strStatus == null || strStatus.equals(""))
strStatus = getStatus();
String strMessage = "";
+ Map<String, String> parameters = new HashMap<String, String>();
if (messageResult == null)
messageResult = new OBError();
if (strMessageType == null || strMessageType.equals(""))
@@ -1750,21 +1776,27 @@
} else if (strStatus.equals(STATUS_BackgroundDisabled)) {
strMessage = "@BackgroundDisabled@";
messageResult.setType("Warning");
- } else if (strStatus.equals(STATUS_InvalidAccount))
+ } else if (strStatus.equals(STATUS_InvalidAccount)) {
strMessage = "@InvalidAccount@";
- else if (strStatus.equals(STATUS_PeriodClosed))
- strMessage = "@PeriodNotAvailable@";
- else if (strStatus.equals(STATUS_NotConvertible))
+ } else if (strStatus.equals(STATUS_PeriodClosed)) {
+ strMessage = "@PeriodClosed@";
+ } else if (strStatus.equals(STATUS_NotConvertible)) {
strMessage = "@NotConvertible@";
- else if (strStatus.equals(STATUS_NotBalanced))
+ } else if (strStatus.equals(STATUS_NotBalanced)) {
strMessage = "@NotBalanced@";
- else if (strStatus.equals(STATUS_NotPosted))
+ } else if (strStatus.equals(STATUS_NotPosted)) {
strMessage = "@NotPosted@";
- else if (strStatus.equals(STATUS_PostPrepared))
+ } else if (strStatus.equals(STATUS_PostPrepared)) {
strMessage = "@PostPrepared@";
- else if (strStatus.equals(STATUS_Posted))
+ } else if (strStatus.equals(STATUS_Posted)) {
strMessage = "@Posted@";
- messageResult.setMessage(Utility.parseTranslation(conn, vars,
vars.getLanguage(), strMessage));
+ } else if (strStatus.equals(STATUS_TableDisabled)) {
+ strMessage = "@TableDisabled@";
+ parameters.put("Table", tableName);
+ messageResult.setType("Warning");
+ }
+ messageResult.setMessage(Utility.parseTranslation(conn, vars, parameters,
vars.getLanguage(),
+ Utility.parseTranslation(conn, vars, vars.getLanguage(), strMessage)));
}
public OBError getMessageResult() {
diff -r 433ad8e1d1cf -r 26ee9d288ed9
src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java Wed Apr 06
11:48:50 2011 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java Wed Apr 06
12:12:29 2011 +0200
@@ -39,6 +39,7 @@
import org.openbravo.erpCommon.utility.FieldProviderFactory;
import org.openbravo.erpCommon.utility.SequenceIdData;
import org.openbravo.model.common.enterprise.AcctSchemaTableDocType;
+import org.openbravo.model.common.invoice.Invoice;
import
org.openbravo.model.financialmgmt.accounting.FIN_FinancialAccountAccounting;
import org.openbravo.model.financialmgmt.accounting.coa.AcctSchemaTable;
import org.openbravo.model.financialmgmt.gl.GLItem;
@@ -49,7 +50,6 @@
import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
public class DocFINPayment extends AcctServer {
-
private static final long serialVersionUID = 1L;
static Logger log4j = Logger.getLogger(DocFINPayment.class);
@@ -125,13 +125,24 @@
if (data[i] == null)
continue;
String Line_ID = data[i].getField("FIN_Payment_Detail_ID");
- DocLine_FINPayment docLine = new DocLine_FINPayment(DocumentType,
Record_ID, Line_ID);
- docLine.loadAttributes(data[i], this);
- docLine.setAmount(data[i].getField("Amount"));
- docLine.setIsPrepayment(data[i].getField("isprepayment"));
- docLine.setWriteOffAmt(data[i].getField("WriteOffAmt"));
- docLine.setC_GLItem_ID(data[i].getField("C_GLItem_ID"));
- list.add(docLine);
+ OBContext.setAdminMode();
+ try {
+ FIN_PaymentDetail detail =
OBDal.getInstance().get(FIN_PaymentDetail.class, Line_ID);
+ DocLine_FINPayment docLine = new DocLine_FINPayment(DocumentType,
Record_ID, Line_ID);
+ docLine.loadAttributes(data[i], this);
+ docLine.setAmount(data[i].getField("Amount"));
+ docLine.setIsPrepayment(data[i].getField("isprepayment"));
+ docLine.setWriteOffAmt(data[i].getField("WriteOffAmt"));
+ docLine.setC_GLItem_ID(data[i].getField("C_GLItem_ID"));
+ docLine
+ .setInvoice(detail.getFINPaymentScheduleDetailList() != null
+ &&
detail.getFINPaymentScheduleDetailList().get(0).getInvoicePaymentSchedule() !=
null ? detail
+
.getFINPaymentScheduleDetailList().get(0).getInvoicePaymentSchedule().getInvoice()
+ : null);
+ list.add(docLine);
+ } finally {
+ OBContext.restorePreviousMode();
+ }
}
// Return Array
DocLine_FINPayment[] dl = new DocLine_FINPayment[list.size()];
@@ -201,13 +212,25 @@
bpAmount = new BigDecimal(bpAmount).add(new
BigDecimal(line.WriteOffAmt)).toString();
}
if ("".equals(line.getC_GLItem_ID())) {
+ String bpAmountConverted = bpAmount;
+ Invoice invoice = line.getInvoice();
+ String strcCurrencyId = C_Currency_ID;
+ if (invoice != null && !C_Currency_ID.equals(as.m_C_Currency_ID)) {
+ String dateFormat =
OBPropertiesProvider.getInstance().getOpenbravoProperties()
+ .getProperty("dateFormat.java");
+ SimpleDateFormat outputFormat = new SimpleDateFormat(dateFormat);
+ bpAmountConverted = convertAmount(bpAmount, isReceipt, DateAcct,
outputFormat
+ .format(invoice.getAccountingDate()), C_Currency_ID,
as.m_C_Currency_ID, line, as,
+ fact, Fact_Acct_Group_ID, conn);
+ strcCurrencyId = as.m_C_Currency_ID;
+ }
fact
.createLine(line,
getAccountBPartner((line.m_C_BPartner_ID == null ||
line.m_C_BPartner_ID
.equals("")) ? this.C_BPartner_ID :
line.m_C_BPartner_ID, as, isReceipt,
- isPrepayment, conn), C_Currency_ID, (isReceipt ? "" :
bpAmount),
- (isReceipt ? bpAmount : ""), Fact_Acct_Group_ID,
nextSeqNo(SeqNo), DocumentType,
- conn);
+ isPrepayment, conn), strcCurrencyId, (isReceipt ? "" :
bpAmountConverted),
+ (isReceipt ? bpAmountConverted : ""), Fact_Acct_Group_ID,
nextSeqNo(SeqNo),
+ DocumentType, conn);
} else {
fact.createLine(line,
getAccountGLItem(OBDal.getInstance().get(GLItem.class,
line.getC_GLItem_ID()), as, isReceipt, conn), C_Currency_ID,
(isReceipt ? ""
@@ -271,11 +294,19 @@
public boolean getDocumentConfirmation(ConnectionProvider conn, String
strRecordId) {
// Checks if this step is configured to generate accounting for the
selected financial account
boolean confirmation = false;
- final String AWAITING_EXECUTION = "RPAE";
+ final String PAYMENT_RECEIVED = "RPR";
+ final String PAYMENT_MADE = "PPM";
+ final String DEPOSITED_NOT_CLEARED = "RDNC";
+ final String WITHDRAWN_NOT_CLEARED = "PWNC";
+ final String PAYMENT_CLEARED = "RPPC";
OBContext.setAdminMode();
try {
FIN_Payment payment = OBDal.getInstance().get(FIN_Payment.class,
strRecordId);
- if (!payment.getStatus().equals(AWAITING_EXECUTION)) {
+ // Posting can just happen if payment is in the right status
+ if (payment.getStatus().equals(PAYMENT_RECEIVED) ||
payment.getStatus().equals(PAYMENT_MADE)
+ || payment.getStatus().equals(DEPOSITED_NOT_CLEARED)
+ || payment.getStatus().equals(WITHDRAWN_NOT_CLEARED)
+ || payment.getStatus().equals(PAYMENT_CLEARED)) {
OBCriteria<FinAccPaymentMethod> obCriteria =
OBDal.getInstance().createCriteria(
FinAccPaymentMethod.class);
obCriteria.add(Expression.eq(FinAccPaymentMethod.PROPERTY_ACCOUNT,
payment.getAccount()));
@@ -405,6 +436,50 @@
return account;
}
+ public String convertAmount(String Amount, boolean isReceipt, String
mDateAcct,
+ String conversionDate, String C_Currency_ID_From, String
C_Currency_ID_To, DocLine line,
+ AcctSchema as, Fact fact, String Fact_Acct_Group_ID, ConnectionProvider
conn)
+ throws ServletException {
+ if (Amount == null || Amount.equals(""))
+ return "0";
+ if (C_Currency_ID_From.equals(C_Currency_ID_To))
+ return Amount;
+ else
+ MultiCurrency = true;
+ String Amt = getConvertedAmt(Amount, C_Currency_ID_From, C_Currency_ID_To,
conversionDate, "",
+ AD_Client_ID, AD_Org_ID, conn);
+ if (log4j.isDebugEnabled())
+ log4j.debug("Amt:" + Amt);
+
+ String AmtTo = getConvertedAmt(Amount, C_Currency_ID_From,
C_Currency_ID_To, mDateAcct, "",
+ AD_Client_ID, AD_Org_ID, conn);
+ if (log4j.isDebugEnabled())
+ log4j.debug("AmtTo:" + AmtTo);
+
+ BigDecimal AmtDiff = (new BigDecimal(AmtTo)).subtract(new BigDecimal(Amt));
+ if (log4j.isDebugEnabled())
+ log4j.debug("AmtDiff:" + AmtDiff);
+
+ if (log4j.isDebugEnabled()) {
+ log4j.debug("curr from:" + C_Currency_ID_From + " Curr to:" +
C_Currency_ID_To + " convDate:"
+ + conversionDate + " DateAcct:" + mDateAcct);
+ log4j.debug("Amt:" + Amt + " AmtTo:" + AmtTo + " Diff:" +
AmtDiff.toString());
+ }
+
+ if ((isReceipt && AmtDiff.compareTo(new BigDecimal("0.00")) == 1)
+ || (!isReceipt && AmtDiff.compareTo(new BigDecimal("0.00")) == -1)) {
+ fact.createLine(line,
getAccount(AcctServer.ACCTTYPE_ConvertGainDefaultAmt, as, conn),
+ C_Currency_ID_To, "", AmtDiff.abs().toString(), Fact_Acct_Group_ID,
nextSeqNo(SeqNo),
+ DocumentType, conn);
+ } else {
+ fact.createLine(line,
getAccount(AcctServer.ACCTTYPE_ConvertChargeDefaultAmt, as, conn),
+ C_Currency_ID_To, AmtDiff.abs().toString(), "", Fact_Acct_Group_ID,
nextSeqNo(SeqNo),
+ DocumentType, conn);
+ }
+
+ return Amt;
+ }
+
public String getSeqNo() {
return SeqNo;
}
diff -r 433ad8e1d1cf -r 26ee9d288ed9
src/org/openbravo/erpCommon/ad_forms/DocLine_FINPayment.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocLine_FINPayment.java Wed Apr
06 11:48:50 2011 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocLine_FINPayment.java Wed Apr
06 12:12:29 2011 +0200
@@ -19,6 +19,8 @@
package org.openbravo.erpCommon.ad_forms;
import org.apache.log4j.Logger;
+import org.openbravo.model.common.invoice.Invoice;
+import org.openbravo.model.common.order.Order;
public class DocLine_FINPayment extends DocLine {
private static final Logger log4j =
Logger.getLogger(DocLine_FINPayment.class);
------------------------------------------------------------------------------
Xperia(TM) PLAY
It's a major breakthrough. An authentic gaming
smartphone on the nation's most reliable network.
And it wants your games.
http://p.sf.net/sfu/verizon-sfdev
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits