Author: sichen Date: Fri Oct 6 10:10:03 2006 New Revision: 453680 URL: http://svn.apache.org/viewvc?view=rev&rev=453680 Log: Fix up the days due for commission invoices, so that if it is not set in Agreement, then dueDate of invoice is also not set. Also fixed a bug where it was always set to 0.
Modified: incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/agreement/AgreementServices.java incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java Modified: incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/agreement/AgreementServices.java URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/agreement/AgreementServices.java?view=diff&rev=453680&r1=453679&r2=453680 ============================================================================== --- incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/agreement/AgreementServices.java (original) +++ incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/agreement/AgreementServices.java Fri Oct 6 10:10:03 2006 @@ -131,7 +131,9 @@ BigDecimal commission = ZERO; BigDecimal min = new BigDecimal("-1e12"); // Limit to 1 trillion commission BigDecimal max = new BigDecimal("1e12"); - long days = 0; + + // number of days due for commission, which will be the lowest termDays of all the AgreementTerms + long days = -1; Iterator itt = terms.iterator(); while (itt.hasNext()) { GenericValue elem = (GenericValue) itt.next(); @@ -150,9 +152,17 @@ } // TODO: Add other type of terms and handling here } + + // see if we need to update the number of days for paying commission Long termDays = elem.getLong("termDays"); if (termDays != null) { - days = Math.min(days, termDays.longValue()); + // if days is greater than zero, then it has been set with another value, so we use the lowest term days + // if days is less than zero, then it has not been set yet. + if (days > 0) { + days = Math.min(days, termDays.longValue()); + } else { + days = termDays.longValue(); + } } } if (commission.compareTo(min) < 0) @@ -161,14 +171,17 @@ commission = max; commission = negative ? commission.negate() : commission; commission = commission.setScale(decimals, rounding); - days = Math.max(0, days); - commissions.add(UtilMisc.toMap( + + Map partyCommissionResult = UtilMisc.toMap( "partyIdFrom", agreementItem.getString("partyIdFrom"), "partyIdTo", agreementItem.getString("partyIdTo"), "commission", commission, - "days", new Long(days), "currencyUomId", agreementItem.getString("currencyUomId"), - "productId", productId)); + "productId", productId); + if (days >= 0) { + partyCommissionResult.put("days", new Long(days)); + } + commissions.add(partyCommissionResult); } } } catch (GenericEntityException e) { Modified: incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java?view=diff&rev=453680&r1=453679&r2=453680 ============================================================================== --- incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java (original) +++ incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java Fri Oct 6 10:10:03 2006 @@ -777,14 +777,14 @@ List toStore = FastList.newInstance(); List commList = (List)pair.getValue(); // get the billing parties - // From and To are reversed between commission and invoice - if (commList == null || commList.size() == 0) + if (UtilValidate.isEmpty(commList)) { continue; + } + + // From and To are reversed between commission and invoice String partyIdBillTo = (String) ((Map)commList.get(0)).get("partyIdFrom"); String partyIdBillFrom = (String) ((Map)commList.get(0)).get("partyIdTo"); - Long termDays = (Long) ((Map)commList.get(0)).get("termDays"); - termDays = termDays == null ? new Long(0) : termDays; - Timestamp dueDate = UtilDateTime.getDayEnd(now, termDays.intValue()); + Long days = (Long) ((Map)commList.get(0)).get("days"); // create the invoice record // To and From are in commission's sense, opposite for invoice @@ -792,7 +792,10 @@ createInvoiceContext.put("partyId", partyIdBillTo); createInvoiceContext.put("partyIdFrom", partyIdBillFrom); createInvoiceContext.put("invoiceDate", now); - createInvoiceContext.put("dueDate", dueDate); + // if there were days associated with the commission agreement, then set a dueDate for the invoice. + if (days != null) { + createInvoiceContext.put("dueDate", UtilDateTime.getDayEnd(now, days.intValue())); + } createInvoiceContext.put("invoiceTypeId", invoiceType); // start with INVOICE_IN_PROCESS, in the INVOICE_READY we can't change the invoice (or shouldn't be able to...) createInvoiceContext.put("statusId", "INVOICE_IN_PROCESS");