Attached Files | multicurrencyMiguelAngel.diff [^] (7,550 bytes) 2011-03-17 17:15 [Show Content] [Hide Content]diff -r 8b9a7f487985 src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java Thu Mar 17 11:29:33 2011 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java Thu Mar 17 17:17:10 2011 +0100
@@ -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 ? ""
@@ -405,6 +428,50 @@
return account;
}
+ public String convertAmount(String Amount, boolean isReceipt, String DateAcct,
+ String conversionDate, String C_Currency_ID_From, String C_Currency_ID, 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))
+ return Amount;
+ else
+ MultiCurrency = true;
+ String Amt = getConvertedAmt(Amount, C_Currency_ID_From, C_Currency_ID, 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, DateAcct, "",
+ 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 + " convDate:"
+ + conversionDate + " DateAcct:" + DateAcct);
+ 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, "", AmtDiff.abs().toString(), Fact_Acct_Group_ID, nextSeqNo(SeqNo),
+ DocumentType, conn);
+ } else {
+ fact.createLine(line, getAccount(AcctServer.ACCTTYPE_ConvertChargeDefaultAmt, as, conn),
+ C_Currency_ID, AmtDiff.abs().toString(), "", Fact_Acct_Group_ID, nextSeqNo(SeqNo),
+ DocumentType, conn);
+ }
+
+ return Amt;
+ }
+
public String getSeqNo() {
return SeqNo;
}
diff -r 8b9a7f487985 src/org/openbravo/erpCommon/ad_forms/DocLine_FINPayment.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocLine_FINPayment.java Thu Mar 17 11:29:33 2011 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/DocLine_FINPayment.java Thu Mar 17 17:17:10 2011 +0100
@@ -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);
@@ -29,6 +31,24 @@
String isReceipt = "";
String C_GLItem_ID = "";
String isPrepayment = "";
+ Invoice invoice = null;
+ Order order = null;
+
+ public Invoice getInvoice() {
+ return invoice;
+ }
+
+ public void setInvoice(Invoice invoice) {
+ this.invoice = invoice;
+ }
+
+ public Order getOrder() {
+ return order;
+ }
+
+ public void setOrder(Order order) {
+ this.order = order;
+ }
/**
* @param isReceipt
|