/** * This method sums the amounts for a List of NonInvoiceds. This is used separately from * PaymentApplicationDocument.getTotalUnapplied() * * @return */ private static KualiDecimal getSumOfNonInvoiceds(List<NonInvoiced> nonInvoiceds) { KualiDecimal sum = new KualiDecimal(0); for (NonInvoiced nonInvoiced : nonInvoiceds) { sum = sum.add(nonInvoiced.getFinancialDocumentLineAmount()); } return sum; }
/** * This method... * * @param nonInvoiced * @param paymentApplicationDocument * @param totalFromControl * @return */ private static boolean validateNonInvoicedLineAmount( NonInvoiced nonInvoiced, PaymentApplicationDocument paymentApplicationDocument, KualiDecimal totalFromControl) { MessageMap errorMap = GlobalVariables.getMessageMap(); KualiDecimal nonArLineAmount = nonInvoiced.getFinancialDocumentLineAmount(); // check that dollar amount is not zero before continuing if (ObjectUtils.isNull(nonArLineAmount)) { errorMap.putError( ArPropertyConstants.PaymentApplicationDocumentFields.NON_INVOICED_LINE_AMOUNT, ArKeyConstants.PaymentApplicationDocumentErrors.NON_AR_AMOUNT_REQUIRED); return false; } else { KualiDecimal cashControlBalanceToBeApplied = totalFromControl; cashControlBalanceToBeApplied = cashControlBalanceToBeApplied.add(paymentApplicationDocument.getTotalFromControl()); cashControlBalanceToBeApplied.subtract(paymentApplicationDocument.getTotalApplied()); cashControlBalanceToBeApplied.subtract( paymentApplicationDocument.getNonAppliedHoldingAmount()); if (nonArLineAmount.isZero()) { errorMap.putError( ArPropertyConstants.PaymentApplicationDocumentFields.NON_INVOICED_LINE_AMOUNT, ArKeyConstants.PaymentApplicationDocumentErrors.AMOUNT_TO_BE_APPLIED_CANNOT_BE_ZERO); return false; } else if (nonArLineAmount.isNegative()) { errorMap.putError( ArPropertyConstants.PaymentApplicationDocumentFields.NON_INVOICED_LINE_AMOUNT, ArKeyConstants.PaymentApplicationDocumentErrors.AMOUNT_TO_BE_APPLIED_MUST_BE_POSTIIVE); return false; } // check that we're not trying to apply more funds to the invoice than the invoice has // balance (ie, over-applying) else if (KualiDecimal.ZERO.isGreaterThan( cashControlBalanceToBeApplied.subtract(nonArLineAmount))) { errorMap.putError( ArPropertyConstants.PaymentApplicationDocumentFields.NON_INVOICED_LINE_AMOUNT, ArKeyConstants.PaymentApplicationDocumentErrors .NON_AR_AMOUNT_EXCEEDS_BALANCE_TO_BE_APPLIED); return false; } } return true; }