|
[Opentaps-fincommits] r58 - trunk/src/com/opensourcestrategies/financials/ledger
From: <leon@gr...> - 2006-02-27 20:25
|
Author: leon
Date: 2006-02-27 12:25:43 -0800 (Mon, 27 Feb 2006)
New Revision: 58
Modified:
trunk/src/com/opensourcestrategies/financials/ledger/LedgerServices.java
Log:
Added new return invoice type to postInvoiceToGl
Modified: trunk/src/com/opensourcestrategies/financials/ledger/LedgerServices.java
===================================================================
--- trunk/src/com/opensourcestrategies/financials/ledger/LedgerServices.java 2006-02-27 20:07:02 UTC (rev 57)
+++ trunk/src/com/opensourcestrategies/financials/ledger/LedgerServices.java 2006-02-27 20:25:43 UTC (rev 58)
@@ -64,6 +64,7 @@
public static final String module = LedgerServices.class.getName();
public static final String INVOICE_PRODUCT_ITEM_TYPE = "INV_FPROD_ITEM"; // invoiceTypeId for invoice items which are products
public static final String PURCHINV_PRODUCT_ITEM_TYPE = "PINV_FPROD_ITEM"; // invoiceTypeId for invoice items which are products
+ public static final String RETINV_PRODUCT_ITEM_TYPE = "RINV_FPROD_ITEM"; // invoiceTypeId for invoice items which are products
// TODO: replace code that uses epsilon with BigDecimal and also set BigDecimal config in some common class/properties file
public static final double epsilon = 0.000001; // smallest allowable rounding error in accounting transactions
@@ -118,6 +119,15 @@
// Right now we're not looking for a product specific uninvoiced shipment receipt account, but if we needed to,
// just add a defaultProductGlAccountTypeId here. Without it, we'll look for it in the GlAccountTypeDefault for the organization
defaultProductOrgGlAccountTypeId = "UNINVOICED_SHIP_RCPT";
+ } else if ("CUST_RTN_INVOICE".equals(invoiceTypeId)) {
+ acctgTransTypeId = "OBLIGATION_ACCTG_TRA";
+ offsettingGlAccountTypeId = "CUSTOMER_CREDIT";
+ organizationPartyId = invoice.getString("partyId");
+ transactionPartyId = invoice.getString("partyIdFrom");
+ transactionPartyRoleTypeId = "BILL_TO_CUSTOMER";
+ defaultDebitCreditFlag = "D";
+ offsettingDebitCreditFlag = "C";
+ defaultProductOrgGlAccountTypeId = "SALES_RETURN";
} else {
return ServiceUtil.returnError("Unknown invoiceTypeId '" + invoiceTypeId + "' for Invoice [" + invoiceId + "]");
}
@@ -248,21 +258,28 @@
continue;
}
- String invoiceItemPostingGlAccountId = null; // GL account for posting this invoice item
+ // GL account for posting this invoice item, default to overrideGlAccountId if present
+ String invoiceItemPostingGlAccountId = invoiceItem.getString("overrideGlAccountId");
- // if this invoice item is for a product, check to see if it has a particular GL account defined in ProductGlAccount,
- // or, alternatively, in GlAccountTypeDefault
- String invoiceItemTypeId = invoiceItem.getString("invoiceItemTypeId");
- if ((invoiceItemTypeId.equals(INVOICE_PRODUCT_ITEM_TYPE)) || (invoiceItemTypeId.equals(PURCHINV_PRODUCT_ITEM_TYPE))) {
- input = new HashMap();
- input.put("productId", invoiceItem.getString("productId"));
- input.put("productGlAccountTypeId", defaultProductGlAccountTypeId);
- input.put("organizationPartyId", organizationPartyId);
- input.put("glAccountTypeId", defaultProductOrgGlAccountTypeId);
- input.put("userLogin", userLogin);
- serviceResult = dispatcher.runSync("getProductOrgGlAccount", input);
- if (!ServiceUtil.isError(serviceResult))
- invoiceItemPostingGlAccountId = (String) serviceResult.get("glAccountId");
+ if (invoiceItemPostingGlAccountId == null) {
+
+ // if this invoice item is for a product, check to see if it has a particular GL account defined in ProductGlAccount,
+ // or, alternatively, in GlAccountTypeDefault
+ String invoiceItemTypeId = invoiceItem.getString("invoiceItemTypeId");
+ if ((invoiceItemTypeId.equals(INVOICE_PRODUCT_ITEM_TYPE))
+ || (invoiceItemTypeId.equals(PURCHINV_PRODUCT_ITEM_TYPE))
+ || invoiceItemTypeId.equals(RETINV_PRODUCT_ITEM_TYPE)) {
+ input = new HashMap();
+ input.put("productId", invoiceItem.getString("productId"));
+ input.put("productGlAccountTypeId", defaultProductGlAccountTypeId);
+ input.put("organizationPartyId", organizationPartyId);
+ input.put("glAccountTypeId", defaultProductOrgGlAccountTypeId);
+ input.put("userLogin", userLogin);
+ serviceResult = dispatcher.runSync("getProductOrgGlAccount", input);
+ if (!ServiceUtil.isError(serviceResult)) {
+ invoiceItemPostingGlAccountId = (String) serviceResult.get("glAccountId");
+ }
+ }
}
// specific invoice type processing for each invoice item
@@ -277,7 +294,7 @@
organizationPartyId, transactionPartyId, transactionPartyRoleTypeId,
defaultDebitCreditFlag, defaultProductGlAccountTypeId, defaultProductOrgGlAccountTypeId
);
- } else {
+ } else { // for both purchase and return invoices, run processPurchaseInvoiceItem
tmpResult = processPurchaseInvoiceItem(
delegator, dispatcher, userLogin,
invoice, invoiceItem, acctgTransEntries,
@@ -303,7 +320,7 @@
* For purchase invoices, this method creates accounting transaction entries first
* for uninvoiced shipment receipts. Then it reconciles the aggregate value of all order items
* related to the invoice item with the actual value of the invoice item and posts it as a
- * purchase price variance.
+ * purchase price variance. Note that this method is also used for return invoices.
*/
private static Map processPurchaseInvoiceItem(
GenericDelegator delegator, LocalDispatcher dispatcher, GenericValue userLogin,
@@ -404,9 +421,6 @@
int decimals = UtilNumber.getBigDecimalScale("invoice.decimals");
int rounding = UtilNumber.getBigDecimalRoundingMode("invoice.rounding");
- // There is an override GL account defined in InvoiceItem. If it is defined, then it supersedes all of the above
- invoiceItemPostingGlAccountId = invoiceItem.getString("overrideGlAccountId");
-
// If there is still no account, try getting a default account
if ((invoiceItemPostingGlAccountId == null) || invoiceItemPostingGlAccountId.equals("")) {
invoiceItemPostingGlAccountId = getDefaultGlAccount(invoiceItem, organizationPartyId);
@@ -521,9 +535,11 @@
* If an invoice item is not a product, or if it has no specific GL account defined,
* check if there is a GL account defined generally for this invoice item type and
* this accounting organization (party). If there is still no organization-specific
- * GL account for this invoice item type, then use InvoiceItemType's default GL account
+ * GL account for this invoice item type, then use InvoiceItemType's default GL account.
+ * However, if an overrideGlAccountId is present in the invoiceItem, return that instead.
*/
private static String getDefaultGlAccount(GenericValue invoiceItem, String organizationPartyId) throws GenericEntityException {
+ if (invoiceItem.getString("overrideGlAccountId") != null) return invoiceItem.getString("overrideGlAccountId");
GenericValue invoiceItemType = invoiceItem.getRelatedOne("InvoiceItemType");
List orgInvoiceItemTypeGlAccounts = invoiceItemType.getRelatedByAnd("InvoiceItemTypeGlAccount", UtilMisc.toMap("organizationPartyId", organizationPartyId));
if ((orgInvoiceItemTypeGlAccounts != null) && (orgInvoiceItemTypeGlAccounts.size() == 1)) {
|
| Thread | Author | Date |
|---|---|---|
| [Opentaps-fincommits] r58 - trunk/src/com/opensourcestrategies/financials/ledger | <leon@gr...> |