📄 accountshelper.java
字号:
// add them together and put in balance map balanceAmount = balanceAmount.add(debitBalance); balances.put(balance.get("partyId"), balanceAmount); } return balances; } /** Gets ACCOUNTS_RECEIVABLE balances for all customers in an organizatoin up to the asOfDateTime. Returns a Map of partyId keys to BigDecimal balance values */ public static Map getBalancesForAllCustomers(String organizationPartyId, String glFiscalTypeId, Timestamp asOfDateTime, GenericDelegator delegator) throws GenericEntityException { return getBalancesHelper("ACCOUNTS_RECEIVABLE", organizationPartyId, null, glFiscalTypeId, asOfDateTime, delegator); } /** Gets ACCOUNTS_PAYABLE balances for all vendors in an organizatoin up to the asOfDateTime. Returns a Map of partyId keys to BigDecimal balance values */ public static Map getBalancesForAllVendors(String organizationPartyId, String glFiscalTypeId, Timestamp asOfDateTime, GenericDelegator delegator) throws GenericEntityException { return getBalancesHelper("ACCOUNTS_PAYABLE", organizationPartyId, null, glFiscalTypeId, asOfDateTime, delegator); } /** Gets ACCOUNTS_RECEIVABLE balance for a given customer in an organizatoin up to the asOfDateTime. Returns the balance as a BigDecimal */ public static BigDecimal getBalanceForCustomerPartyId(String customerPartyId, String organizationPartyId, String glFiscalTypeId, Timestamp asOfDateTime, GenericDelegator delegator) throws GenericEntityException { return (BigDecimal) getBalancesHelper("ACCOUNTS_RECEIVABLE", organizationPartyId, customerPartyId, glFiscalTypeId, asOfDateTime, delegator).get(customerPartyId); } /** Gets ACCOUNTS_PAYABLE balance for a given vendor in an organizatoin up to the asOfDateTime. Returns the balance as a BigDecimal */ public static BigDecimal getBalanceForVendorPartyId(String vendorPartyId, String organizationPartyId, String glFiscalTypeId, Timestamp asOfDateTime, GenericDelegator delegator) throws GenericEntityException { return (BigDecimal) getBalancesHelper("ACCOUNTS_PAYABLE", organizationPartyId, vendorPartyId, glFiscalTypeId, asOfDateTime, delegator).get(vendorPartyId); } /** * Gets unpaid invoice balances for customer (SALES_INVOICE) * See getUnpaidInvoicesHelper for parameter information */ public static Map getUnpaidInvoicesForCustomers(String organizationPartyId, List daysOutstandingPoints, Timestamp asOfDateTime, GenericDelegator delegator) throws GenericEntityException { return getUnpaidInvoicesHelper(organizationPartyId, "SALES_INVOICE", daysOutstandingPoints, asOfDateTime, delegator); } /** * Gets unpaid invoice balances for vendor (PURCHASE_INVOICE) * See getUnpaidInvoicesHelper for parameter information */ public static Map getUnpaidInvoicesForVendors(String organizationPartyId, List daysOutstandingPoints, Timestamp asOfDateTime, GenericDelegator delegator) throws GenericEntityException { return getUnpaidInvoicesHelper(organizationPartyId, "PURCHASE_INVOICE", daysOutstandingPoints, asOfDateTime, delegator); } /** * Returns a Map of Integer (not int) days outstanding breakpoints and List of InvoiceWithOutstandingBalance objects for invoices whose days outstanding * is just less than the breakpoint days, but greater than the preceding (smaller) days outstanding breakpoint. * * @param organizationPartyId * @param invoiceTypeId * @param daysOutstandingPoints List of Integer (not int) days outstanding breakpoints, ie: UtilMisc.toList(new Integer(0), new Integer(30), new Integer(60), new Integer(90) * @param asOfDateTime * @param delegator * @return * @throws GenericEntityException */ public static Map getUnpaidInvoicesHelper(String organizationPartyId, String invoiceTypeId, List daysOutstandingPoints, Timestamp asOfDateTime, GenericDelegator delegator) throws GenericEntityException { // which field is equal to the organizationPartyId? Depends on the invoice type String organizationInvoiceField = "partyIdFrom"; if (invoiceTypeId.equals("PURCHASE_INVOICE")) { organizationInvoiceField = "partyId"; } // used to select invoices which are not paid by the as of date time but which are created before the as of date // TODO: some kind of invoice status condition as well, to filter out the READY invoice status? EntityConditionList invoiceDateConditions = new EntityConditionList(UtilMisc.toList( new EntityExpr("paidDate", EntityOperator.GREATER_THAN, asOfDateTime), new EntityExpr("paidDate", EntityOperator.EQUALS, null)), EntityOperator.OR); EntityConditionList conditions = new EntityConditionList(UtilMisc.toList( new EntityExpr("invoiceTypeId", EntityOperator.EQUALS, invoiceTypeId), new EntityExpr("invoiceDate", EntityOperator.LESS_THAN_EQUAL_TO, asOfDateTime), new EntityExpr(organizationInvoiceField, EntityOperator.EQUALS, organizationPartyId), invoiceDateConditions), EntityOperator.AND); // search and sort results on invoiceDate ascending List invoices = delegator.findByCondition("Invoice", conditions, null, UtilMisc.toList("invoiceDate")); // Create outstandingInvoices map, populate with empty buckets, and store the maximum days outstanding of all the break points Map outstandingInvoicesByAge = FastMap.newInstance(); int maxDaysOutstanding = 0; for (Iterator it = daysOutstandingPoints.iterator(); it.hasNext(); ) { Integer nextDaysOutstanding = (Integer) it.next(); outstandingInvoicesByAge.put(nextDaysOutstanding, new LinkedList()); if (nextDaysOutstanding.intValue() > maxDaysOutstanding) { maxDaysOutstanding = nextDaysOutstanding.intValue(); } } // loop through invoices and put it into the right date bucket Iterator iter = invoices.iterator(); while (iter.hasNext()) { GenericValue invoice = (GenericValue) iter.next(); BigDecimal balance = InvoiceWorker.getInvoiceNotApplied(invoice, asOfDateTime); if (balance.compareTo(ZERO) != 0) { Timestamp invoiceTimestamp = invoice.getTimestamp("invoiceDate"); // Calculate number of days elapsed, rounded as a BigDecimal BigDecimal numberOfDays = new BigDecimal(UtilDateTime.getInterval(invoice.getTimestamp("invoiceDate"), asOfDateTime)).divide(MILLISECONDS_PER_DAY, decimals, rounding); // create object of invoice with outstanding balance and whether it's past due or not boolean isPastDue = false; if ((invoice.getTimestamp("dueDate") != null) && (invoice.getTimestamp("dueDate").before(asOfDateTime))) { isPastDue = true; } InvoiceWithOutstandingBalance invoiceWithBalance = new InvoiceWithOutstandingBalance(invoice, balance, isPastDue); // Put this invoice into the List at the first days outstanding (DSO) break point which is greater than the current one, or // the last DSO break point in the list of DSO break points, whichever one comes first boolean foundDaysOutstandingPoint = false; Iterator it = daysOutstandingPoints.iterator(); while ((it.hasNext()) && (!foundDaysOutstandingPoint) ) { Integer daysOutstandingPoint = (Integer) it.next(); if (numberOfDays.compareTo(new BigDecimal(daysOutstandingPoint.intValue())) == -1) { // -1 is less than List invoicesByDaysOutstanding = (LinkedList) outstandingInvoicesByAge.get(daysOutstandingPoint); invoicesByDaysOutstanding.add(invoiceWithBalance); foundDaysOutstandingPoint = true; } } if (!foundDaysOutstandingPoint) { List invoicesByDaysOutstanding = (LinkedList) outstandingInvoicesByAge.get(new Integer(maxDaysOutstanding)); invoicesByDaysOutstanding.add(invoiceWithBalance); } } } return outstandingInvoicesByAge; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -