Author: hansbak
Date: Wed Dec 24 22:26:14 2008 New Revision: 729396 URL: http://svn.apache.org/viewvc?rev=729396&view=rev Log: OFBIZ-2097: show organizationPartyId in header(can be set in preferences), rewrote financial history to show currencies, invoice/p[aymentworker now can show in actual and organizationparty currency Added: ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/UnAppliedInvoicesForParty.groovy (with props) ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/UnAppliedPaymentsForParty.groovy (with props) Modified: ofbiz/trunk/applications/accounting/config/AccountingUiLabels.xml ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/EditInvoice.groovy ofbiz/trunk/applications/accounting/webapp/accounting/invoice/InvoiceForms.xml ofbiz/trunk/applications/accounting/webapp/accounting/payment/PaymentForms.xml ofbiz/trunk/applications/accounting/widget/InvoiceScreens.xml ofbiz/trunk/applications/accounting/widget/Menus.xml ofbiz/trunk/applications/party/entitydef/entitymodel.xml ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/PartyFinancialHistory.groovy ofbiz/trunk/applications/party/webapp/partymgr/party/PartyForms.xml ofbiz/trunk/applications/party/widget/partymgr/PartyScreens.xml ofbiz/trunk/applications/party/widget/partymgr/ProfileScreens.xml ofbiz/trunk/framework/common/config/CommonUiLabels.xml ofbiz/trunk/framework/common/webcommon/includes/header.ftl ofbiz/trunk/framework/common/widget/CommonScreens.xml Modified: ofbiz/trunk/applications/accounting/config/AccountingUiLabels.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/config/AccountingUiLabels.xml?rev=729396&r1=729395&r2=729396&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/config/AccountingUiLabels.xml (original) +++ ofbiz/trunk/applications/accounting/config/AccountingUiLabels.xml Wed Dec 24 22:26:14 2008 @@ -3777,12 +3777,8 @@ <value xml:lang="th">PDF</value> <value xml:lang="zh">PDF</value> </property> - <property key="AccountingInvoicePDFOtherCur"> - <value xml:lang="en">PDF other Currency</value> - <value xml:lang="fr">PDF en autre devise</value> - <value xml:lang="it">PDF Altra Valuta</value> - <value xml:lang="nl">PDF andere valuta</value> - <value xml:lang="th">PDF สà¸à¸¸à¸¥à¹à¸à¸´à¸à¸à¸·à¹à¸ à¹</value> + <property key="AccountingInvoicePDFDefaultCur"> + <value xml:lang="en">PDF default Currency</value> </property> <property key="AccountingInvoicePaid"> <value xml:lang="ar">٠سدد</value> @@ -3855,6 +3851,9 @@ <value xml:lang="th">à¹à¸à¸à¸³à¸à¸±à¸à¸à¸²à¸£à¸à¸²à¸¢</value> <value xml:lang="zh">éå®å票</value> </property> + <property key="InvoicesApplPayments"> + <value xml:lang="en">Payments applied to Invoices</value> + </property> <property key="AccountingInvoiceStatus"> <value xml:lang="ar">اÙÙضعÙات</value> <value xml:lang="en">Status</value> Modified: ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml?rev=729396&r1=729395&r2=729396&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml (original) +++ ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml Wed Dec 24 22:26:14 2008 @@ -1418,6 +1418,45 @@ </relation> </entity> + <view-entity entity-name="InvoiceAndApplAndPayment" package-name="org.ofbiz.accounting.invoice" title="Invoice and related applications and payments"> + <member-entity entity-alias="INV" entity-name="Invoice"/> + <member-entity entity-alias="PAP" entity-name="PaymentApplication"/> + <member-entity entity-alias="PAM" entity-name="Payment"/> + <alias-all entity-alias="INV"/> + <alias-all entity-alias="PAP"> + <exclude field="billingAccountId"/> + </alias-all> + <alias-all entity-alias="PAM" prefix="pm"/> + <view-link entity-alias="INV" rel-entity-alias="PAP"> + <key-map field-name="invoiceId"/> + </view-link> + <view-link entity-alias="PAP" rel-entity-alias="PAM"> + <key-map field-name="paymentId"/> + </view-link> + </view-entity> + + <view-entity entity-name="InvoiceAndType" package-name="org.ofbiz.accounting.invoice"> + <member-entity entity-alias="INV" entity-name="Invoice"/> + <member-entity entity-alias="IVT" entity-name="InvoiceType"/> + <alias-all entity-alias="INV"/> + <alias-all entity-alias="IVT"> + <exclude field="invoiceTypeId"/> + </alias-all> + <view-link entity-alias="INV" rel-entity-alias="IVT"> + <key-map field-name="invoiceTypeId"/> + </view-link> + <relation type="many" rel-entity-name="InvoiceItem"> + <key-map field-name="invoiceId"/> + </relation> + <relation type="many" rel-entity-name="PaymentApplication"> + <key-map field-name="invoiceId"/> + </relation> + <relation type="many" rel-entity-name="AcctgTrans"> + <key-map field-name="invoiceId"/> + </relation> + </view-entity> + + <!-- ========================================================= --> <!-- org.ofbiz.accounting.ledger --> <!-- ========================================================= --> @@ -2531,6 +2570,26 @@ <key-map field-name="overrideGlAccountId" rel-field-name="glAccountId"/> </relation> </entity> + <view-entity entity-name="PaymentAndType" + package-name="org.ofbiz.accounting.payment" + never-cache="true" + title="Payment and Payment type View Entity"> + <member-entity entity-alias="PY" entity-name="Payment"/> + <member-entity entity-alias="TY" entity-name="PaymentType"/> + <alias-all entity-alias="PY"/> + <alias-all entity-alias="TY"> + <exclude field="paymentTypeId"/> + </alias-all> + <view-link entity-alias="PY" rel-entity-alias="TY"> + <key-map field-name="paymentTypeId"/> + </view-link> + <relation type="many" fk-name="PAYTYPE_PAY" rel-entity-name="PaymentApplication"> + <key-map field-name="paymentId"/> + </relation> + <relation type="many" fk-name="PAYTYPE_TOPAY" title="to" rel-entity-name="PaymentApplication"> + <key-map field-name="paymentId" rel-field-name="toPaymentId"/> + </relation> + </view-entity> <view-entity entity-name="PaymentAndApplication" package-name="org.ofbiz.accounting.payment" never-cache="true" Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java?rev=729396&r1=729395&r2=729396&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java (original) +++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java Wed Dec 24 22:26:14 2008 @@ -19,6 +19,7 @@ package org.ofbiz.accounting.invoice; import java.math.BigDecimal; +import java.math.MathContext; import java.sql.Timestamp; import java.util.Iterator; import java.util.List; @@ -29,6 +30,7 @@ import org.ofbiz.base.util.UtilDateTime; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilNumber; +import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.GenericDelegator; import org.ofbiz.entity.GenericEntityException; @@ -37,6 +39,7 @@ import org.ofbiz.entity.condition.EntityConditionList; import org.ofbiz.entity.condition.EntityOperator; import org.ofbiz.entity.util.EntityUtil; +import org.ofbiz.service.LocalDispatcher; /** * InvoiceWorker - Worker methods of invoices @@ -60,6 +63,10 @@ } public static BigDecimal getInvoiceTotalBd(GenericDelegator delegator, String invoiceId) { + return getInvoiceTotalBd(delegator, invoiceId, true); + } + + public static BigDecimal getInvoiceTotalBd(GenericDelegator delegator, String invoiceId, Boolean actualCurrency) { if (delegator == null) { throw new IllegalArgumentException("Null delegator is not allowed in this method"); } @@ -75,7 +82,7 @@ throw new IllegalArgumentException("The invoiceId passed does not match an existing invoice"); } - return getInvoiceTotalBd(invoice); + return getInvoiceTotalBd(invoice, actualCurrency); } /** Method to get the taxable invoice item types as a List of invoiceItemTypeIds. These are identified in Enumeration with enumTypeId TAXABLE_INV_ITM_TY. */ @@ -127,10 +134,10 @@ } public static double getInvoiceNoTaxTotal(GenericValue invoice) { - return getInvoiceTotalBd(invoice).doubleValue() - getInvoiceTaxTotal(invoice); + return getInvoiceTotalBd(invoice, true).doubleValue() - getInvoiceTaxTotal(invoice); } public static BigDecimal getInvoiceNoTaxTotalBd(GenericValue invoice) { - return getInvoiceTotalBd(invoice).subtract(getInvoiceTaxTotalBd(invoice)); + return getInvoiceTotalBd(invoice, true).subtract(getInvoiceTaxTotalBd(invoice)); } /** @@ -139,10 +146,14 @@ * @return the invoice total as double */ public static double getInvoiceTotal(GenericValue invoice) { - return getInvoiceTotalBd(invoice).doubleValue(); + return getInvoiceTotalBd(invoice, true).doubleValue(); } public static BigDecimal getInvoiceTotalBd(GenericValue invoice) { + return getInvoiceTotalBd(invoice, true); + } + + public static BigDecimal getInvoiceTotalBd(GenericValue invoice, Boolean actualCurrency) { BigDecimal invoiceTotal = ZERO; BigDecimal invoiceTaxTotal = ZERO; List invoiceItems = null; @@ -168,6 +179,10 @@ } } } + invoiceTotal = invoiceTotal.add(invoiceTaxTotal).setScale(decimals, rounding); + if (UtilValidate.isNotEmpty(invoiceTotal) && !actualCurrency) { + invoiceTotal = invoiceTotal.multiply(getInvoiceCurrencyConversionRate(invoice)).setScale(decimals,rounding); + } return invoiceTotal.add(invoiceTaxTotal).setScale(decimals, rounding); } @@ -365,11 +380,17 @@ * @param invoice GenericValue object of the Invoice * @return the invoice total as double */ + public static BigDecimal getInvoiceNotApplied(GenericDelegator delegator, String invoiceId, Boolean actualCurrency) { + return InvoiceWorker.getInvoiceTotalBd(delegator, invoiceId, actualCurrency).subtract(getInvoiceAppliedBd(delegator, invoiceId, UtilDateTime.nowTimestamp(), actualCurrency)); + } public static BigDecimal getInvoiceNotApplied(GenericDelegator delegator, String invoiceId) { return InvoiceWorker.getInvoiceTotalBd(delegator, invoiceId).subtract(getInvoiceAppliedBd(delegator, invoiceId)); } public static BigDecimal getInvoiceNotApplied(GenericValue invoice) { - return InvoiceWorker.getInvoiceTotalBd(invoice).subtract(getInvoiceAppliedBd(invoice)); + return InvoiceWorker.getInvoiceTotalBd(invoice, true).subtract(getInvoiceAppliedBd(invoice)); + } + public static BigDecimal getInvoiceNotApplied(GenericValue invoice, Boolean actualCurrency) { + return InvoiceWorker.getInvoiceTotalBd(invoice, actualCurrency).subtract(getInvoiceAppliedBd(invoice, actualCurrency)); } /** * Returns amount not applied (ie, still outstanding) of an invoice at an asOfDate, based on Payment.effectiveDate <= asOfDateTime @@ -379,7 +400,7 @@ * @return */ public static BigDecimal getInvoiceNotApplied(GenericValue invoice, Timestamp asOfDateTime) { - return InvoiceWorker.getInvoiceTotalBd(invoice).subtract(getInvoiceAppliedBd(invoice, asOfDateTime)); + return InvoiceWorker.getInvoiceTotalBd(invoice, true).subtract(getInvoiceAppliedBd(invoice, asOfDateTime)); } @@ -393,7 +414,7 @@ } public static BigDecimal getInvoiceAppliedBd(GenericDelegator delegator, String invoiceId) { - return getInvoiceAppliedBd(delegator, invoiceId, UtilDateTime.nowTimestamp()); + return getInvoiceAppliedBd(delegator, invoiceId, UtilDateTime.nowTimestamp(), true); } /** @@ -404,7 +425,7 @@ * @param asOfDateTime - a Timestamp * @return */ - public static BigDecimal getInvoiceAppliedBd(GenericDelegator delegator, String invoiceId, Timestamp asOfDateTime) { + public static BigDecimal getInvoiceAppliedBd(GenericDelegator delegator, String invoiceId, Timestamp asOfDateTime, Boolean actualCurrency) { if (delegator == null) { throw new IllegalArgumentException("Null delegator is not allowed in this method"); } @@ -433,6 +454,9 @@ invoiceApplied = invoiceApplied.add(paymentApplication.getBigDecimal("amountApplied")).setScale(decimals,rounding); } } + if (UtilValidate.isNotEmpty(invoiceApplied) && !actualCurrency) { + invoiceApplied = invoiceApplied.multiply(getInvoiceCurrencyConversionRate(delegator, invoiceId)).setScale(decimals,rounding); + } return invoiceApplied; } /** @@ -451,8 +475,11 @@ * @param invoiceItemSeqId * @return */ + public static BigDecimal getInvoiceAppliedBd(GenericValue invoice, Boolean actualCurrency) { + return getInvoiceAppliedBd(invoice.getDelegator(), invoice.getString("invoiceId"), UtilDateTime.nowTimestamp(), actualCurrency); + } public static BigDecimal getInvoiceAppliedBd(GenericValue invoice, Timestamp asOfDateTime) { - return getInvoiceAppliedBd(invoice.getDelegator(), invoice.getString("invoiceId"), asOfDateTime); + return getInvoiceAppliedBd(invoice.getDelegator(), invoice.getString("invoiceId"), asOfDateTime, true); } public static BigDecimal getInvoiceAppliedBd(GenericValue invoice) { return getInvoiceAppliedBd(invoice, UtilDateTime.nowTimestamp()); @@ -519,6 +546,82 @@ } return invoiceItemApplied; } - + public static BigDecimal getInvoiceCurrencyConversionRate(GenericValue invoice) { + BigDecimal conversionRate = null; + GenericDelegator delegator = invoice.getDelegator(); + String otherCurrencyUomId = null; + // find the organization party currencyUomId which different from the invoice currency + try { + GenericValue party = delegator.findByPrimaryKey("PartyAcctgPreference", UtilMisc.toMap("partyId", invoice.getString("partyIdFrom"))); + if (UtilValidate.isEmpty(party) || party.getString("baseCurrencyUomId").equals(invoice.getString("currencyUomId"))) { + party = delegator.findByPrimaryKey("PartyAccntgPreferences", UtilMisc.toMap("partyId", invoice.getString("partyId"))); + } + if (party.getString("baseCurrencyUomId").equals(invoice.getString("currencyUomId"))) { + return BigDecimal.ONE; // organization party has the same currency so conversion not required. + } else { + otherCurrencyUomId = new String(invoice.getString("currencyUomId")); + } + } catch (GenericEntityException e) { + Debug.logError(e, "Trouble getting database records....", module); + } + + try { + // check if the invoice is posted and get the conversion from there + List acctgTransEntries = invoice.getRelated("AcctgTrans"); + if (UtilValidate.isNotEmpty(acctgTransEntries)) { + GenericValue acctgTransEntry = ((GenericValue) acctgTransEntries.get(0)).getRelated("AcctgTransEntry").get(0); + conversionRate = acctgTransEntry.getBigDecimal("amount").divide(acctgTransEntry.getBigDecimal("origAmount"), new MathContext(100)).setScale(decimals,rounding); + } + // check if a payment is applied and use the currency conversion from there + if (UtilValidate.isEmpty(conversionRate)) { + List paymentAppls = invoice.getRelated("PaymentApplication"); + Iterator ii = paymentAppls.iterator(); + while (ii.hasNext()) { + GenericValue paymentAppl = (GenericValue) ii.next(); + GenericValue payment = paymentAppl.getRelatedOne("Payment"); + if (UtilValidate.isNotEmpty(payment.getBigDecimal("actualCurrencyAmount"))) { + if (UtilValidate.isEmpty(conversionRate)) { + conversionRate = payment.getBigDecimal("amount").divide(payment.getBigDecimal("actualCurrencyAmount"),new MathContext(100)).setScale(decimals,rounding); + } else { + conversionRate = conversionRate.add(payment.getBigDecimal("amount").divide(payment.getBigDecimal("actualCurrencyAmount"),new MathContext(100))).divide(new BigDecimal("2"),new MathContext(100)).setScale(decimals,rounding); + } + } + } + } + // use the dated conversion entity + if (UtilValidate.isEmpty(conversionRate)) { + List rates = EntityUtil.filterByDate(delegator.findByAnd("UomConversionDated", UtilMisc.toMap("uomIdTo", invoice.getString("currencyUomId"), "uomId", otherCurrencyUomId)), invoice.getTimestamp("invoiceDate")); + if (UtilValidate.isNotEmpty(rates)) { + conversionRate = (BigDecimal.ONE).divide(((GenericValue) rates.get(0)).getBigDecimal("conversionFactor"), new MathContext(100)).setScale(decimals,rounding); + } else { + Debug.logError("Could not find conversionrate for invoice: " + invoice.getString("invoiceId"), module); + return new BigDecimal("1"); + } + } + + } catch (GenericEntityException e) { + Debug.logError(e, "Trouble getting database records....", module); + } + return(conversionRate); + } + + public static BigDecimal getInvoiceCurrencyConversionRate(GenericDelegator delegator, String invoiceId) { + if (delegator == null) { + throw new IllegalArgumentException("Null delegator is not allowed in this method"); + } + + GenericValue invoice = null; + try { + invoice = delegator.findByPrimaryKey("Invoice", UtilMisc.toMap("invoiceId", invoiceId)); + } catch (GenericEntityException e) { + Debug.logError(e, "Problem getting Invoice", module); + } + + if (invoice == null) { + throw new IllegalArgumentException("The invoiceId passed does not match an existing invoice"); + } + + return getInvoiceCurrencyConversionRate(invoice); + } } Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java?rev=729396&r1=729395&r2=729396&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java (original) +++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java Wed Dec 24 22:26:14 2008 @@ -54,18 +54,18 @@ private static int rounding = UtilNumber.getBigDecimalRoundingMode("invoice.rounding"); /** @deprecated */ - public static void getPartyPaymentMethodValueMaps(PageContext pageContext, String partyId, boolean showOld, String paymentMethodValueMapsAttr) { + public static void getPartyPaymentMethodValueMaps(PageContext pageContext, String partyId, Boolean showOld, String paymentMethodValueMapsAttr) { GenericDelegator delegator = (GenericDelegator) pageContext.getRequest().getAttribute("delegator"); List paymentMethodValueMaps = getPartyPaymentMethodValueMaps(delegator, partyId, showOld); pageContext.setAttribute(paymentMethodValueMapsAttr, paymentMethodValueMaps); } - // to be able to use in minilanguage where boolean cannot be used + // to be able to use in minilanguage where Boolean cannot be used public static List getPartyPaymentMethodValueMaps(GenericDelegator delegator, String partyId) { return(getPartyPaymentMethodValueMaps(delegator, partyId, false)); } - public static List getPartyPaymentMethodValueMaps(GenericDelegator delegator, String partyId, boolean showOld) { + public static List getPartyPaymentMethodValueMaps(GenericDelegator delegator, String partyId, Boolean showOld) { List paymentMethodValueMaps = new LinkedList(); try { List paymentMethods = delegator.findByAnd("PaymentMethod", UtilMisc.toMap("partyId", partyId)); @@ -118,7 +118,7 @@ GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); Map results = new HashMap(); - boolean tryEntity = true; + Boolean tryEntity = true; if (request.getAttribute("_ERROR_MESSAGE_") != null) tryEntity = false; String donePage = request.getParameter("DONE_PAGE"); @@ -236,10 +236,10 @@ * @return the applied total as double */ public static double getPaymentApplied(GenericDelegator delegator, String paymentId) { - return getPaymentAppliedBd(delegator, paymentId).doubleValue(); + return getPaymentAppliedBd(delegator, paymentId, false).doubleValue(); } - public static BigDecimal getPaymentAppliedBd(GenericDelegator delegator, String paymentId) { + public static BigDecimal getPaymentAppliedBd(GenericDelegator delegator, String paymentId, Boolean actual) { if (delegator == null) { throw new IllegalArgumentException("Null delegator is not allowed in this method"); } @@ -255,7 +255,7 @@ throw new IllegalArgumentException("The paymentId passed does not match an existing payment"); } - return getPaymentAppliedBd(payment); + return getPaymentAppliedBd(payment, actual); } /** * Method to return the amount applied converted to the currency of payment @@ -307,7 +307,7 @@ * @param false for currency of the payment, true for the actual currency * @return the applied total as BigDecimal in the currency of the payment */ - public static BigDecimal getPaymentAppliedBd(GenericValue payment, boolean actual) { + public static BigDecimal getPaymentAppliedBd(GenericValue payment, Boolean actual) { BigDecimal paymentApplied = BigDecimal.ZERO; List paymentApplications = null; try { @@ -344,11 +344,21 @@ public static BigDecimal getPaymentNotAppliedBd(GenericValue payment) { return payment.getBigDecimal("amount").subtract(getPaymentAppliedBd(payment)).setScale(decimals,rounding); } + public static BigDecimal getPaymentNotAppliedBd(GenericValue payment, Boolean actual) { + if (actual && UtilValidate.isNotEmpty(payment.getBigDecimal("actualCurrencyAmount"))) { + return payment.getBigDecimal("actualCurrencyAmount").subtract(getPaymentAppliedBd(payment, actual)).setScale(decimals,rounding); + } + return payment.getBigDecimal("amount").subtract(getPaymentAppliedBd(payment)).setScale(decimals,rounding); + } public static double getPaymentNotApplied(GenericDelegator delegator, String paymentId) { - return getPaymentNotAppliedBd(delegator,paymentId).doubleValue(); + return getPaymentNotAppliedBd(delegator,paymentId, false).doubleValue(); + } + + public static BigDecimal getPaymentNotApplied(GenericDelegator delegator, String paymentId, Boolean actual) { + return getPaymentNotAppliedBd(delegator,paymentId, actual); } - public static BigDecimal getPaymentNotAppliedBd(GenericDelegator delegator, String paymentId) { + public static BigDecimal getPaymentNotAppliedBd(GenericDelegator delegator, String paymentId, Boolean actual) { if (delegator == null) { throw new IllegalArgumentException("Null delegator is not allowed in this method"); } @@ -363,6 +373,6 @@ if (payment == null) { throw new IllegalArgumentException("The paymentId passed does not match an existing payment"); } - return payment.getBigDecimal("amount").subtract(getPaymentAppliedBd(delegator,paymentId)).setScale(decimals,rounding); + return payment.getBigDecimal("amount").subtract(getPaymentAppliedBd(delegator,paymentId, actual)).setScale(decimals,rounding); } } Modified: ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/EditInvoice.groovy URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/EditInvoice.groovy?rev=729396&r1=729395&r2=729396&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/EditInvoice.groovy (original) +++ ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/EditInvoice.groovy Wed Dec 24 22:26:14 2008 @@ -35,60 +35,20 @@ invoice = delegator.findByPrimaryKey("Invoice", [invoiceId : invoiceId]); context.invoice = invoice; -other = parameters.other; // allow the display of the invoice in the currency of the other party. sales: partyId, purch: partyIdFrom using the convertUom service. -conversionRate = null; +currency = parameters.currency; // allow the display of the invoice in the original currency, the default is to display the invoice in the default currency +BigDecimal conversionRate = new BigDecimal("1"); ZERO = BigDecimal.ZERO; decimals = UtilNumber.getBigDecimalScale("invoice.decimals"); rounding = UtilNumber.getBigDecimalRoundingMode("invoice.rounding"); -if ("Y".equalsIgnoreCase(other)) { - if (invoice.currencyUomId.equals(invoice.getRelatedOne("Party").preferredCurrencyUomId)) { - otherCurrency = invoice.getRelatedOne("FromParty").preferredCurrencyUomId; - } else { - otherCurrency = invoice.getRelatedOne("Party").preferredCurrencyUomId; - } - result = null; - if (otherCurrency && invoice.currencyUomId && !otherCurrency.equals(invoice.currencyUomId)) { - invoice.currencyUomId = otherCurrency; - // check if the transaction is created, take the conversion from there - acctgTransEntries = invoice.getRelated("AcctgTrans"); - if (acctgTransEntries) { - acctgTransEntry = acctgTransEntries[0].getRelated("AcctgTransEntry")[0]; - conversionRate = acctgTransEntry.getBigDecimal("amount").divided(acctgTransEntry.getBigDecimal("origAmount"), new MathContext(100)); - } - // check if a payment is applied and use the currency conversion from there - if (!conversionRate) { - paymentAppls = invoice.getRelated("PaymentApplication"); - paymentAppls.each { paymentAppl -> - payment = paymentAppl.getRelatedOne("Payment"); - if (!conversionRate) { - conversionRate = payment.getBigDecimal("amount").divide(payment.getBigDecimal("actualCurrencyAmount"),new MathContext(100)); - } else { - conversionRate = conversionRate.add(payment.getBigDecimal("amount").divide(payment.getBigDecimal("actualCurrencyAmount"),new MathContext(100))).divide(new BigDecimal("2"),new MathContext(100)); - } - } - } - if (!conversionRate) { - result = dispatcher.runSync("convertUom", [uomId : invoice.currencyUomId, - uomIdTo : otherCurrency, - originalValue : new Double("1.00"), - asOfDate : invoice.invoiceDate]); - - if (result.convertedValue != null) { - conversionRate = new BigDecimal(result.convertedValue.doubleValue()); - invoice.invoiceMessage = invoice.get("invoiceMessage") ? - invoice.invoiceMessage.concat(" Converted from " + invoice.currencyUomId + " Rate: " + conversionRate.setScale(6, rounding).toString()) : - "Converted from " + invoice.currencyUomId + " Rate: " + conversionRate.setScale(6, rounding).toString(); - } - } - } -} - -if (!conversionRate) { - conversionRate = 1; -} if (invoice) { - invoiceItems = invoice.getRelatedOrderBy("InvoiceItem", ["invoiceItemSeqId"]); + if (currency && !invoice.getString("currencyUomId").equals(currency)) { + conversionRate = InvoiceWorker.getInvoiceCurrencyConversionRate(invoice); + invoice.currencyUomId = currency; + invoice.invoiceMessage = " converted from original with a rate of: " + conversionRate.setScale(8, rounding); + } + + invoiceItems = invoice.getRelatedOrderBy("InvoiceItem", ["invoiceItemSeqId"]); invoiceItemsConv = FastList.newInstance(); invoiceItems.each { invoiceItem -> invoiceItem.amount = new Double((invoiceItem.getBigDecimal("amount").multiply(conversionRate).setScale(decimals, rounding)).doubleValue()); Modified: ofbiz/trunk/applications/accounting/webapp/accounting/invoice/InvoiceForms.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/webapp/accounting/invoice/InvoiceForms.xml?rev=729396&r1=729395&r2=729396&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/webapp/accounting/invoice/InvoiceForms.xml (original) +++ ofbiz/trunk/applications/accounting/webapp/accounting/invoice/InvoiceForms.xml Wed Dec 24 22:26:14 2008 @@ -76,8 +76,12 @@ <field name="invoiceDate"><display/></field> <field name="statusId"><display-entity entity-name="StatusItem" description="${description}"/></field> <field name="description"><display/></field> - <field name="partyIdFrom"><display description="${partyNameResultFrom.fullName} [${partyIdFrom}]"/></field> - <field name="partyIdTo" parameter-name="partyId"><display description="${partyNameResultTo.fullName} [${partyId}]"/></field> + <field name="partyIdFrom"> + <hyperlink target="/partymgr/control/PartyFinancialHistory?partyId=${partyIdFrom}" target-type="inter-app" description="${partyNameResultFrom.fullName} [${partyIdFrom}]"/> + </field> + <field name="partyIdTo" parameter-name="partyId"> + <hyperlink target="/partymgr/control/PartyFinancialHistory?partyId=${partyId}" target-type="inter-app" description="${partyNameResultTo.fullName} [${partyId}]"/> + </field> <field name="invoiceDate"><display description="${date:dateStr(invoiceDate)}"/></field> <field name="total" widget-area-style="align-text"><display type="currency" currency="${currencyUomId}"/></field> <field name="amountToApply" widget-area-style="align-text"><display type="currency" currency="${currencyUomId}"/></field> Modified: ofbiz/trunk/applications/accounting/webapp/accounting/payment/PaymentForms.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/webapp/accounting/payment/PaymentForms.xml?rev=729396&r1=729395&r2=729396&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/webapp/accounting/payment/PaymentForms.xml (original) +++ ofbiz/trunk/applications/accounting/webapp/accounting/payment/PaymentForms.xml Wed Dec 24 22:26:14 2008 @@ -83,6 +83,15 @@ <form name="NewPaymentOut" type="single" target="createPayment" default-map-name="payment" header-row-style="header-row" default-table-style="basic-table"> + <actions> + <entity-condition entity-name="PaymentType" list-name="paymentTypes"> + <condition-list combine="or"> + <condition-expr field-name="parentTypeId" operator="equals" value="DISBURSEMENT"/> + <condition-expr field-name="parentTypeId" operator="equals" value="TAX_PAYMENT"/> + </condition-list> + <order-by field-name="description"/> + </entity-condition> + </actions> <field name="statusId"><hidden value="PMNT_NOT_PAID"/></field> <field position="1" name="organizationPartyId" parameter-name="partyIdFrom"> <drop-down allow-empty="false"> @@ -95,9 +104,7 @@ <field name="partyIdTo" position="2"><lookup target-form-name="LookupPartyName"/></field> <field position="1" name="paymentTypeId"> <drop-down allow-empty="false"> - <entity-options description="${description}" entity-name="PaymentType"> - <entity-order-by field-name="description"/> - </entity-options> + <list-options list-name="paymentTypes" key-name="paymentTypeId" description="${description}"/> </drop-down> </field> <field position="2" name="paymentMethodTypeId"> @@ -135,6 +142,7 @@ <field position="1" name="paymentTypeId"> <drop-down allow-empty="false"> <entity-options description="${description}" entity-name="PaymentType"> + <entity-constraint field-name="parentTypeId" value="RECEIPT"/> <entity-order-by field-name="description"/> </entity-options> </drop-down> Modified: ofbiz/trunk/applications/accounting/widget/InvoiceScreens.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/widget/InvoiceScreens.xml?rev=729396&r1=729395&r2=729396&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/widget/InvoiceScreens.xml (original) +++ ofbiz/trunk/applications/accounting/widget/InvoiceScreens.xml Wed Dec 24 22:26:14 2008 @@ -444,20 +444,6 @@ <container style="screenlet"> <container style="screenlet-title-bar"> <container style="h3"> - <label text="${uiLabelMap.AccountingAssignPaymentToInvoice}"/> - </container> - </container> - <container style="screenlet-body"> - <section> - <widgets> - <include-form name="AddPayment" location="component://accounting/webapp/accounting/invoice/InvoiceForms.xml"/> - </widgets> - </section> - </container> - </container> - <container style="screenlet"> - <container style="screenlet-title-bar"> - <container style="h3"> <label text="${uiLabelMap.AccountingInvoiceItems}"/> </container> </container> Modified: ofbiz/trunk/applications/accounting/widget/Menus.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/widget/Menus.xml?rev=729396&r1=729395&r2=729396&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/widget/Menus.xml (original) +++ ofbiz/trunk/applications/accounting/widget/Menus.xml Wed Dec 24 22:26:14 2008 @@ -108,7 +108,6 @@ </menu-item> </menu> <menu name="InvoiceSubTabBar" menu-container-style="button-bar button-style-2" default-selected-style="selected"> - <menu-item name="createNew" title="${uiLabelMap.CommonCreateNew}" > <link target="newInvoice"/> </menu-item> @@ -120,15 +119,18 @@ </menu-item> <menu-item name="pdf" title="${uiLabelMap.AccountingInvoicePDF}"> <condition> - <not><if-empty field-name="invoice.invoiceId"/></not> + <not><if-empty field-name="invoice.invoiceId"/></not> </condition> <link target="invoice.pdf?invoiceId=${invoice.invoiceId}" target-window="_BLANK"/> </menu-item> - <menu-item name="pdfOtherCur" title="${uiLabelMap.AccountingInvoicePDFOtherCur}"> + <menu-item name="pdfDfltCur" title="${uiLabelMap.AccountingInvoicePDFDefaultCur}(${defaultOrganizationPartyCurrencyUomId})"> <condition> - <not><if-empty field-name="invoice.invoiceId"/></not> + <and> + <not><if-empty field-name="invoice.invoiceId"/></not> + <if-compare-field field-name="invoice.currencyUomId" operator="not-equals" to-field-name="defaultOrganizationPartyCurrencyUomId"/> + </and> </condition> - <link target="invoice.pdf?invoiceId=${invoice.invoiceId}&other=Y" target-window="_BLANK"/> + <link target="invoice.pdf?invoiceId=${invoice.invoiceId}&currency=${defaultOrganizationPartyCurrencyUomId}" target-window="_BLANK"/> </menu-item> <menu-item name="statusToApproved" title="${uiLabelMap.AccountingInvoiceStatusToApproved}"> <condition> @@ -437,13 +439,13 @@ <condition> <if-service-permission service-name="acctgPrefPermissionCheck" main-action="UPDATE"/> </condition> - <link target="AdminMain?organizationPartyId=${organizationPartyId}"/> + <link target="AdminMain?organizationPartyId=${defaultOrganizationPartyId}"/> </menu-item> <menu-item name="PartyAccounts" title="${uiLabelMap.AccountingAccounting}"> <condition> <if-service-permission service-name="basicGeneralLedgerPermissionCheck" main-action="VIEW"/> </condition> - <link target="PartyAccountsSummary?organizationPartyId=${organizationPartyId}"/> + <link target="PartyAccountsSummary?organizationPartyId=${defaultOrganizationPartyId}"/> </menu-item> </menu> <menu name="OrganizationAccountingTabBar" extends="CommonTabBarMenu" extends-resource="component://common/widget/CommonMenus.xml" Modified: ofbiz/trunk/applications/party/entitydef/entitymodel.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/party/entitydef/entitymodel.xml?rev=729396&r1=729395&r2=729396&view=diff ============================================================================== --- ofbiz/trunk/applications/party/entitydef/entitymodel.xml (original) +++ ofbiz/trunk/applications/party/entitydef/entitymodel.xml Wed Dec 24 22:26:14 2008 @@ -2627,19 +2627,15 @@ <key-map field-name="partyId"/> </relation> </extend-entity> - <view-entity entity-name="PartyAcctgAndName" + <view-entity entity-name="PartyAcctgPrefAndGroup" package-name="org.ofbiz.party.party" - title="PartyAcctgPreference and PartyNameView Entity"> + title="PartyAcctgPreference and PartyGroup Entity"> <member-entity entity-alias="PTYACCPREF" entity-name="PartyAcctgPreference"/> - <member-entity entity-alias="PTYNVIEW" entity-name="PartyNameView"/> + <member-entity entity-alias="PTYGROUP" entity-name="PartyGroup"/> <alias entity-alias="PTYACCPREF" name="partyId" /> - <alias entity-alias="PTYNVIEW" name="firstName"/> - <alias entity-alias="PTYNVIEW" name="middleName"/> - <alias entity-alias="PTYNVIEW" name="lastName"/> - <alias entity-alias="PTYNVIEW" name="groupName"/> - <alias entity-alias="PTYNVIEW" name="partyTypeId"/> - <alias entity-alias="PTYNVIEW" name="description"/> - <view-link entity-alias="PTYACCPREF" rel-entity-alias="PTYNVIEW"> + <alias entity-alias="PTYACCPREF" name="baseCurrencyUomId" /> + <alias entity-alias="PTYGROUP" name="groupName"/> + <view-link entity-alias="PTYACCPREF" rel-entity-alias="PTYGROUP"> <key-map field-name="partyId"/> </view-link> </view-entity> Modified: ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/PartyFinancialHistory.groovy URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/PartyFinancialHistory.groovy?rev=729396&r1=729395&r2=729396&view=diff ============================================================================== --- ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/PartyFinancialHistory.groovy (original) +++ ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/PartyFinancialHistory.groovy Wed Dec 24 22:26:14 2008 @@ -16,278 +16,116 @@ * specific language governing permissions and limitations * under the License. */ -import java.util.*; -import java.math.*; -import java.sql.Timestamp; -import org.ofbiz.base.util.*; import org.ofbiz.entity.*; -import org.ofbiz.securityext.login.*; +import org.ofbiz.base.util.*; import org.ofbiz.common.*; import org.ofbiz.webapp.control.*; import org.ofbiz.accounting.invoice.*; import org.ofbiz.accounting.payment.*; - -delegator = parameters.delegator; -partyId = parameters.partyId; -List historyList = new LinkedList(); - -//get payment totals -BigDecimal totalPaymentsIn = new BigDecimal("0.00").setScale(2,BigDecimal.ROUND_HALF_UP); -BigDecimal totalPaymentsOut = new BigDecimal("0.00").setScale(2,BigDecimal.ROUND_HALF_UP); -tpayments = delegator.findByOr("Payment",["partyIdTo" : partyId,"partyIdFrom" : partyId]); -Iterator pl = tpayments.iterator(); -while (pl.hasNext()) { - payment = (GenericValue) pl.next(); - if (payment.statusId.equals("PMNT_CANCELLED")) continue; - if (payment.partyIdTo.equals(partyId)) - totalPaymentsIn = totalPaymentsIn.add(payment.getBigDecimal("amount")).setScale(2,BigDecimal.ROUND_HALF_UP); - else - totalPaymentsOut = totalPaymentsOut.add(payment.getBigDecimal("amount")).setScale(2,BigDecimal.ROUND_HALF_UP); -} - -// totals -BigDecimal totalSalesInvoice = new BigDecimal("0.00").setScale(2,BigDecimal.ROUND_HALF_UP); -BigDecimal totalPurchaseInvoice = new BigDecimal("0.00").setScale(2,BigDecimal.ROUND_HALF_UP); -BigDecimal totalInvoiceApplied = new BigDecimal("0.00").setScale(2,BigDecimal.ROUND_HALF_UP); -BigDecimal totalInvoiceNotApplied = new BigDecimal("0.00").setScale(2,BigDecimal.ROUND_HALF_UP); - -// payment and invoices list which will be updated with the amount applied -// to see what is left over... -List invoices = delegator.findByOr("Invoice",["partyId" : partyId , "partyIdFrom" : partyId] , ["invoiceDate"]); -List payments = delegator.findByOr("Payment",["partyIdTo" : partyId , "partyIdFrom" : partyId] , ["effectiveDate"]); - -List notAppliedInvoices = new LinkedList(); // to store the not fully applied invoices - -// start reading from the invoices list -if (invoices != null && invoices.size() > 0) { - Iterator inv = invoices.iterator(); - while (inv.hasNext()) { - invoice = (GenericValue) inv.next(); - if (invoice.statusId.equals("INVOICE_CANCELLED")) continue; - BigDecimal invoiceAmount = InvoiceWorker.getInvoiceTotalBd(invoice).setScale(2,BigDecimal.ROUND_HALF_UP); - invoiceApplied = InvoiceWorker.getInvoiceAppliedBd(invoice).setScale(2,BigDecimal.ROUND_HALF_UP); - if (invoice.getString("partyId").equals(partyId)) { //negate for outgoing payments - invoiceAmount = invoiceAmount.multiply(new BigDecimal("-1")); - invoiceApplied = invoiceApplied.multiply(new BigDecimal("-1")); - } - if (invoice.invoiceTypeId.equals("PURCHASE_INVOICE")) totalPurchaseInvoice = totalPurchaseInvoice.add(invoiceAmount); - if (invoice.invoiceTypeId.equals("SALES_INVOICE")) totalSalesInvoice = totalSalesInvoice.add(invoiceAmount); - totalInvoiceApplied = totalInvoiceApplied.add(invoiceApplied); -// Debug.logInfo("Invoice type: "+ invoice.getString("invoiceTypeId") + "amount: " + invoiceAmount + " applied: " + invoiceApplied,"??"); - if (!invoiceAmount.equals(invoiceApplied)) { - Map notAppliedInvoice = ["invoiceId" : invoice.invoiceId, - "invoiceTypeId" : invoice.invoiceTypeId.substring(0,1), - "invoiceDate" : invoice.invoiceDate.toString().substring(0,10), - "invoiceAmount" : invoiceAmount.toString(), - "invoiceNotApplied" : invoiceAmount.subtract(invoiceApplied).toString()]; - notAppliedInvoices.add(notAppliedInvoice); - totalInvoiceNotApplied = totalInvoiceNotApplied.add(invoiceAmount).subtract(invoiceApplied); - } - Map historyItem = ["invoiceId" : invoice.invoiceId, - "invoiceTypeId" : invoice.invoiceTypeId.substring(0,1), - "invoiceDate" : invoice.invoiceDate.toString().substring(0,10), - "invoiceAmount" : invoiceAmount.toString(), - "totInvoiceApplied" : invoiceApplied.toString() - ]; - // check for applications - List applications = invoice.getRelated("PaymentApplication",null,["paymentId"]); - if (applications != null && applications.size() > 0) { - Iterator appl = applications.iterator(); - oldPaymentId = new String(" "); - BigDecimal applied = new BigDecimal("0"); - boolean first = true; - while (appl.hasNext()) { // read the applications for this invoice - application = (GenericValue) appl.next(); - paymentId = application.paymentId; - - //reduce the payment amount in the payment list - pl = payments.iterator(); - while (pl.hasNext()) { - payment = (GenericValue) pl.next(); - if (paymentId.equals(payment.paymentId)) { - plInd = payments.indexOf(payment); - payment.amount = payment.getBigDecimal("amount").subtract(application.getBigDecimal("amountApplied")).doubleValue(); - payments.remove(plInd); - payments.add(plInd,payment); - break; - } - } - - // check if the payment number has changed, then we have to output a line.... - if (!first && !paymentId.equals(oldPaymentId)) { // if the payment number has changed, but not the first - payment = delegator.findByPrimaryKey("Payment",["paymentId" : oldPaymentId]); - BigDecimal amount = payment.getBigDecimal("amount").setScale(2,BigDecimal.ROUND_HALF_UP); - if (payment.getString("partyIdFrom").equals(partyId)) amount = amount.multiply(new BigDecimal("-1")); - historyItem = ["applied" : applied.toString(), - "paymentId" : oldPaymentId, - "amount" : amount.toString(), - "effectiveDate" : payment.effectiveDate.toString().substring(0,10)]; - historyList.add(historyItem); - historyItem = new HashMap(); - applied = new BigDecimal("0"); - } - applied = applied.add(application.getBigDecimal("amountApplied")).setScale(2,BigDecimal.ROUND_HALF_UP); - oldPaymentId = paymentId; - first = false; - } - if (!applied.equals("0")) { - payment = delegator.findByPrimaryKey("Payment",["paymentId" : oldPaymentId]); - if (payment != null) { - BigDecimal amount = payment.getBigDecimal("amount").setScale(2,BigDecimal.ROUND_HALF_UP); - if (payment.getString("partyIdFrom").equals(partyId)) amount = amount.multiply(new BigDecimal("-1")); - historyItem = ["invoiceId" : invoice.invoiceId, - "invoiceTypeId" : invoice.invoiceTypeId.substring(0,1), - "invoiceDate" : invoice.invoiceDate.toString().substring(0,10), - "invoiceAmount" : invoiceAmount.toString(), - "totInvoiceApplied" : invoiceApplied.toString(), - "applied" : applied.toString(), - "paymentId" : oldPaymentId, - "amount" : amount.toString(), - "effectiveDate" : payment.effectiveDate.toString().substring(0,10)]; - historyList.add(historyItem); - } - } - } - } - context.historyListInvoices = historyList; -} - -// totals -BigDecimal totalPaymentApplied = new BigDecimal("0.00").setScale(2,BigDecimal.ROUND_HALF_UP); -// list of payments where payments are applied -historyList = new LinkedList(); -if (payments) { - pay = payments.iterator(); - while (pay.hasNext()) { - payment = (GenericValue) pay.next(); - if (payment.statusId.equals("PMNT_CANCELLED")) continue; - applications = payment.getRelated("PaymentApplication", ["paymentId"]); - if (!applications) continue; // none found - Map historyItem = ["paymentId" : payment.paymentId , "effectiveDate" : payment.effectiveDate.toString().substring(0,10)]; - BigDecimal amount = payment.getBigDecimal("amount").setScale(2,BigDecimal.ROUND_HALF_UP); - if (payment.partyIdFrom.equals(organizationPartyId)) { - amount = amount.multiply(new BigDecimal("-1")); - } - historyItem.amount = amount.toString(); - ap = applications.iterator(); - while (ap.hasNext()) { - application = (GenericValue) ap.next(); - historyItem = ["toPaymentId" : application.paymentId, - "applied" : application.amountApplied]; - toPayment = application.getRelatedOne("Payment"); - historyItem.toEffectiveDate = toPayment.effectiveDate.toString().substring(0,10); - toAmount = toPayment.getBigDecimal("amount").setScale(2,BigDecimal.ROUND_HALF_UP); - if (toPayment.partyIdFrom.equals(partyId)) toAmount = toAmount.multiply(new BigDecimal("-1")); - //reduce the payment amount in the payment list - pl = payments.iterator(); - while (pl.hasNext()) { - payment = (GenericValue) pl.next(); - // reduce paymentId - if (application.paymentId.equals(payment.paymentId)) { - plInd = payments.indexOf(payment); - payment.amount = - payment.getBigDecimal("amount"). - subtract(application.getBigDecimal("amountApplied")).doubleValue(); - payments.remove(plInd); - payments.add(plInd,payment); - totalPaymentApplied = totalPaymentApplied.add(application.getBigDecimal("amountApplied")); - } - // reduce toPaymentId - if (application.toPaymentId.equals(payment.paymentId)) { - plInd = payments.indexOf(payment); - payment.amount = - payment.getBigDecimal("amount"). - subtract(application.getBigDecimal("amountApplied")).doubleValue(); - payments.remove(plInd); - payments.add(plInd,payment); - totalPaymentApplied = totalPaymentApplied.add(application.getBigDecimal("amountApplied")); - } - } - } - } - context.historyListPayments = historyList; -} - -// check if any invoices left not applied -if (notAppliedInvoices != null && notAppliedInvoices.size() > 0) { - context.historyListInvoicesN = notAppliedInvoices; -} - -/* -// list payments applied to other companies -historyList = new LinkedList(); -if (payments) { - Iterator pm = payments.iterator(); - while (pm.hasNext()) { - payment = (GenericValue) pm.next(); - // check if payment completely applied - BigDecimal amount = payment.getBigDecimal("amount").setScale(2,BigDecimal.ROUND_HALF_UP); - if (amount.compareTo(new BigDecimal("0.00")) == 0) - continue; - Debug.logInfo(" other company payments: " + payment.paymentId + " amount:" + payment.getBigDecimal("amount") + " applied:" + PaymentWorker.getPaymentAppliedBd(payment),"??"); - List paymentApplications = payment.getRelated("PaymentApplication"); - Iterator pa = paymentApplications.iterator(); - while (pa.hasNext()) { - paymentApplication = (GenericValue) pa.next(); - if (paymentApplication.invoiceId != null) { - invoice = paymentApplication.getRelatedOne("Invoice"); - if (!invoice.partyId.equals(partyId)) { - historyItem = new HashMap(); - Map historyItem = ["paymentId" : payment.paymentId, - "invoiceId" : paymentApplication.invoiceId, - "invoiceItemSeqId" : paymentApplication.invoiceItemSeqId, - "partyId" : invoice.partyIdFrom, - "amount" : amount.toString(), - "applied" : paymentApplication.getBigDecimal("amountApplied").setScale(2,BigDecimal.ROUND_HALF_UP).toString(), - "effectiveDate" : payment.effectiveDate.toString().substring(0,10)]; - historyList.add(historyItem); - } - } - } - } - context.historyListPaymentsO = historyList; -} -*/ -// list not applied payments -BigDecimal totalPaymentNotApplied = new BigDecimal("0.00").setScale(2,BigDecimal.ROUND_HALF_UP); -historyList = new LinkedList(); -if (payments != null && payments.size() > 0) { - Iterator pm = payments.iterator(); - while (pm.hasNext()) { - payment = (GenericValue) pm.next(); - payment = delegator.findByPrimaryKey("Payment",["paymentId" : payment.paymentId]); - notApplied = payment.getBigDecimal("amount").subtract(PaymentWorker.getPaymentAppliedBd(payment)).setScale(2,BigDecimal.ROUND_HALF_UP); - // check if payment completely applied - Debug.logInfo(" payment: " + payment.paymentId + " amount:" + payment.getBigDecimal("amount") + " applied:" + PaymentWorker.getPaymentAppliedBd(payment),"??"); - if (notApplied.compareTo(new BigDecimal("0.00")) == 0) - continue; - Map historyItem = new HashMap(); - BigDecimal amount = payment.getBigDecimal("amount").setScale(2,BigDecimal.ROUND_HALF_UP); - totalPaymentNotApplied = totalPaymentNotApplied.add(notApplied); - historyItem = ["paymentId" : payment.paymentId, - "amount" : amount.toString(), - "notApplied" : notApplied.toString(), - "effectiveDate" : payment.effectiveDate.toString().substring(0,10)]; - historyList.add(historyItem); - } - context.historyListPaymentsN = historyList; -} - -// create totals -finanSummary = ["totalSalesInvoice" : totalSalesInvoice.toString(), - "totalPurchaseInvoice" : totalPurchaseInvoice.toString(), - "totalPaymentsIn" : totalPaymentsIn.toString(), - "totalPaymentsOut" : totalPaymentsOut.toString(), - "totalInvoiceApplied" : totalInvoiceApplied.toString(), - "totalInvoiceNotApplied" : totalInvoiceNotApplied.toString(), - "totalPaymentNotApplied" : totalPaymentNotApplied.toString(), - "totalPaymentNotApplied" : totalPaymentNotApplied.toString()]; -totalToBePaid = totalSalesInvoice.add(totalPurchaseInvoice).subtract(totalInvoiceApplied).subtract(totalPaymentNotApplied); -if (totalToBePaid.compareTo(new BigDecimal("0.00")) < 0 ) finanSummary.totalToBePaid = totalToBePaid.toString(); -else if (totalToBePaid.compareTo(new BigDecimal("0.00")) > 0 ) finanSummary.totalToBeReceived = totalToBePaid.toString(); -else { - finanSummary.totalToBePaid = "0.00"; - finanSummary.totalToBeReceived = "0.00"; +import org.ofbiz.entity.*; +import org.ofbiz.entity.condition.*; +import org.ofbiz.entity.util.*; +import javolution.util.FastMap; + +Boolean actualCurrency = new Boolean(context.actualCurrency); +if (actualCurrency == null) { + actualCurrency = true; +} +actualCurrencyUomId = context.actualCurrencyUomId; +if (!actualCurrencyUomId) { + actualCurrencyUomId = context.defaultOrganizationPartyCurrencyUomId; +} +findOpts = new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, true); +//get total/unapplied/applied invoices separated by sales/purch amount: +totalInvSaApplied = BigDecimal.ZERO; +totalInvSaNotApplied = BigDecimal.ZERO; +totalInvPuApplied = BigDecimal.ZERO; +totalInvPuNotApplied = BigDecimal.ZERO; + +invExprs = + EntityCondition.makeCondition([ + EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "INVOICE_IN_PROCESS"), + EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "INVOICE_WRITEOFF"), + EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "INVOICE_CANCELLED"), + EntityCondition.makeCondition([ + EntityCondition.makeCondition([ + EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, parameters.partyId), + EntityCondition.makeCondition("partyIdFrom", EntityOperator.EQUALS, context.defaultOrganizationPartyId) + ],EntityOperator.AND), + EntityCondition.makeCondition([ + EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, context.defaultOrganizationPartyId), + EntityCondition.makeCondition("partyIdFrom", EntityOperator.EQUALS, parameters.partyId) + ],EntityOperator.AND) + ],EntityOperator.OR) + ],EntityOperator.AND); + +invIterator = delegator.find("InvoiceAndType", invExprs, null, null, null, findOpts); + +while (invoice = invIterator.next()) { + if ("PURCHASE_INVOICE".equals(invoice.parentTypeId)) { + totalInvPuApplied += InvoiceWorker.getInvoiceAppliedBd(invoice, actualCurrency).setScale(2,BigDecimal.ROUND_HALF_UP); + totalInvPuNotApplied += InvoiceWorker.getInvoiceNotApplied(invoice, actualCurrency).setScale(2,BigDecimal.ROUND_HALF_UP); + } + else if ("SALES_INVOICE".equals(invoice.parentTypeId)) { + totalInvSaApplied += InvoiceWorker.getInvoiceAppliedBd(invoice, actualCurrency).setScale(2,BigDecimal.ROUND_HALF_UP); + totalInvSaNotApplied += InvoiceWorker.getInvoiceNotApplied(invoice, actualCurrency).setScale(2,BigDecimal.ROUND_HALF_UP); + } + else { + Debug.logError("InvoiceType: " + invoice.invoiceTypeId + " without a valid parentTypeId: " + invoice.parentTypeId + " !!!! Should be either PURCHASE_INVOICE or SALES_INVOICE", ""); + } +} + +invIterator.close(); + +//get total/unapplied/applied payment in/out total amount: +totalPayInApplied = BigDecimal.ZERO; +totalPayInNotApplied = BigDecimal.ZERO; +totalPayOutApplied = BigDecimal.ZERO; +totalPayOutNotApplied = BigDecimal.ZERO; + +payExprs = + EntityCondition.makeCondition([ + EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "PMNT_NOTPAID"), + EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "PMNT_CANCELLED"), + EntityCondition.makeCondition([ + EntityCondition.makeCondition([ + EntityCondition.makeCondition("partyIdTo", EntityOperator.EQUALS, parameters.partyId), + EntityCondition.makeCondition("partyIdFrom", EntityOperator.EQUALS, context.defaultOrganizationPartyId) + ], EntityOperator.AND), + EntityCondition.makeCondition([ + EntityCondition.makeCondition("partyIdTo", EntityOperator.EQUALS, context.defaultOrganizationPartyId), + EntityCondition.makeCondition("partyIdFrom", EntityOperator.EQUALS, parameters.partyId) + ], EntityOperator.AND) + ], EntityOperator.OR) + ], EntityOperator.AND); + +payIterator = delegator.find("PaymentAndType", payExprs, null, null, null, findOpts); + +while (payment = payIterator.next()) { + if ("DISBURSEMENT".equals(payment.parentTypeId) || "TAX_PAYMENT".equals(payment.parentTypeId)) { + totalPayOutApplied += PaymentWorker.getPaymentAppliedBd(payment, actualCurrency).setScale(2,BigDecimal.ROUND_HALF_UP); + totalPayOutNotApplied += PaymentWorker.getPaymentNotAppliedBd(payment, actualCurrency).setScale(2,BigDecimal.ROUND_HALF_UP); + } + else if ("RECEIPT".equals(payment.parentTypeId)) { + totalPayInApplied += PaymentWorker.getPaymentAppliedBd(payment, actualCurrency).setScale(2,BigDecimal.ROUND_HALF_UP); + totalPayInNotApplied += PaymentWorker.getPaymentNotAppliedBd(payment, actualCurrency).setScale(2,BigDecimal.ROUND_HALF_UP); + } + else { + Debug.logError("PaymentTypeId: " + payment.paymentTypeId + " without a valid parentTypeId: " + payment.parentTypeId + " !!!! Should be either DISBURSEMENT, TAX_PAYMENT or RECEIPT", ""); + } +} +payIterator.close(); +context.finanSummary = FastMap.newInstance(); +context.finanSummary.totalSalesInvoice = totalInvSaApplied.add(totalInvSaNotApplied); +context.finanSummary.totalPurchaseInvoice = totalInvPuApplied.add(totalInvPuNotApplied); +context.finanSummary.totalPaymentsIn = totalPayInApplied.add(totalPayInNotApplied); +context.finanSummary.totalPaymentsOut = totalPayOutApplied.add(totalPayOutNotApplied); +context.finanSummary.totalInvoiceNotApplied = totalInvSaNotApplied.subtract(totalInvPuNotApplied); +context.finanSummary.totalPaymentNotApplied = totalPayInNotApplied.subtract(totalPayOutNotApplied); +transferAmount = totalInvSaApplied.add(totalInvSaNotApplied).subtract(totalInvPuApplied.add(totalInvPuNotApplied)).subtract(totalPayInApplied.add(totalPayInNotApplied).add(totalPayOutApplied.add(totalPayOutNotApplied))); +if (transferAmount.signum() == -1) { + context.finanSummary.totalToBePaid = transferAmount.negate(); +} else { + context.finanSummary.totalToBeReceived = transferAmount; } - context.finanSummary = finanSummary; - \ No newline at end of file + Added: ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/UnAppliedInvoicesForParty.groovy URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/UnAppliedInvoicesForParty.groovy?rev=729396&view=auto ============================================================================== --- ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/UnAppliedInvoicesForParty.groovy (added) +++ ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/UnAppliedInvoicesForParty.groovy Wed Dec 24 22:26:14 2008 @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import org.ofbiz.entity.*; +import org.ofbiz.base.util.Debug; +import org.ofbiz.common.*; +import org.ofbiz.webapp.control.*; +import org.ofbiz.accounting.invoice.*; +import org.ofbiz.accounting.payment.*; +import org.ofbiz.entity.*; +import org.ofbiz.entity.condition.*; +import org.ofbiz.entity.util.*; +import javolution.util.FastMap; + +Boolean actualCurrency = new Boolean(context.actualCurrency); +if (actualCurrency == null) { + actualCurrency = true; +} +findOpts = new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, true); + +invExprs = + EntityCondition.makeCondition([ + EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "INVOICE_IN_PROCESS"), + EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "INVOICE_WRITEOFF"), + EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "INVOICE_CANCELLED"), + EntityCondition.makeCondition([ + EntityCondition.makeCondition([ + EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, parameters.partyId), + EntityCondition.makeCondition("partyIdFrom", EntityOperator.EQUALS, context.defaultOrganizationPartyId) + ],EntityOperator.AND), + EntityCondition.makeCondition([ + EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, context.defaultOrganizationPartyId), + EntityCondition.makeCondition("partyIdFrom", EntityOperator.EQUALS, parameters.partyId) + ],EntityOperator.AND) + ],EntityOperator.OR) + ],EntityOperator.AND); + +invIterator = delegator.find("InvoiceAndType", invExprs, null, null, null, findOpts); +invoiceList = []; +while (invoice = invIterator.next()) { + unAppliedAmount = InvoiceWorker.getInvoiceNotApplied(invoice, actualCurrency).setScale(2,BigDecimal.ROUND_HALF_UP); + if (unAppliedAmount.signum() == 1) { + if (actualCurrency.equals(true)) { + invoiceCurrencyUomId = invoice.currencyUomId; + } else { + invoiceCurrencyUomId = context.defaultOrganizationPartyCurrencyUomId; + } + invoiceList.add([invoiceId : invoice.invoiceId, + invoiceDate : invoice.invoiceDate, + unAppliedAmount : unAppliedAmount, + invoiceCurrencyUomId : invoiceCurrencyUomId, + amount : InvoiceWorker.getInvoiceTotalBd(invoice, actualCurrency).setScale(2,BigDecimal.ROUND_HALF_UP), + invoiceTypeId : invoice.invoiceTypeId, + invoiceParentTypeId : invoice.parentTypeId]); + } +} +invIterator.close(); + +context.ListUnAppliedInvoices = invoiceList; Propchange: ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/UnAppliedInvoicesForParty.groovy ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/UnAppliedInvoicesForParty.groovy ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/UnAppliedInvoicesForParty.groovy ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/UnAppliedPaymentsForParty.groovy URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/UnAppliedPaymentsForParty.groovy?rev=729396&view=auto ============================================================================== --- ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/UnAppliedPaymentsForParty.groovy (added) +++ ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/UnAppliedPaymentsForParty.groovy Wed Dec 24 22:26:14 2008 @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import org.ofbiz.entity.*; +import org.ofbiz.base.util.Debug; +import org.ofbiz.common.*; +import org.ofbiz.webapp.control.*; +import org.ofbiz.accounting.invoice.*; +import org.ofbiz.accounting.payment.*; +import org.ofbiz.entity.*; +import org.ofbiz.entity.condition.*; +import org.ofbiz.entity.util.*; +import javolution.util.FastMap; + +Boolean actualCurrency = new Boolean(context.actualCurrency); +if (actualCurrency == null) { + actualCurrency = true; +} +findOpts = new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, true); + +payExprs = + EntityCondition.makeCondition([ + EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "PMNT_NOTPAID"), + EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "PMNT_CANCELLED"), + EntityCondition.makeCondition([ + EntityCondition.makeCondition([ + EntityCondition.makeCondition("partyIdTo", EntityOperator.EQUALS, parameters.partyId), + EntityCondition.makeCondition("partyIdFrom", EntityOperator.EQUALS, context.defaultOrganizationPartyId) + ], EntityOperator.AND), + EntityCondition.makeCondition([ + EntityCondition.makeCondition("partyIdTo", EntityOperator.EQUALS, context.defaultOrganizationPartyId), + EntityCondition.makeCondition("partyIdFrom", EntityOperator.EQUALS, parameters.partyId) + ], EntityOperator.AND) + ], EntityOperator.OR) + ], EntityOperator.AND); + +paymentList = []; +payIterator = delegator.find("PaymentAndType", payExprs, null, null, null, findOpts); + +while (payment = payIterator.next()) { + unAppliedAmount = PaymentWorker.getPaymentNotAppliedBd(payment, actualCurrency).setScale(2,BigDecimal.ROUND_HALF_UP); + if (unAppliedAmount.signum() == 1) { + if (actualCurrency.equals(true) && payment.actualCurrencyAmount && payment.actualCurrencyUomId) { + amount = payment.actualCurrencyAmount; + paymentCurrencyUomId = payment.actualCurrencyUomId; + } else { + amount = payment.amount; + paymentCurrencyUomId = payment.currencyUomId; + } + paymentList.add([paymentId : payment.paymentId, + effectiveDate : payment.effectiveDate, + unAppliedAmount : unAppliedAmount, + amount : amount, + paymentCurrencyUomId : paymentCurrencyUomId, + paymentTypeId : payment.paymentTypeId, + paymentParentTypeId : payment.parentTypeId]); + } +} +payIterator.close(); + +context.paymentList = paymentList; \ No newline at end of file Propchange: ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/UnAppliedPaymentsForParty.groovy ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/UnAppliedPaymentsForParty.groovy ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/UnAppliedPaymentsForParty.groovy ------------------------------------------------------------------------------ svn:mime-type = text/plain |
Free forum by Nabble | Edit this page |