Search in sources :

Example 1 with DisbursementNumberRange

use of org.kuali.kfs.pdp.businessobject.DisbursementNumberRange in project cu-kfs by CU-CommunityApps.

the class AchBundlerFormatServiceImpl method assignDisbursementNumbersAndBundle.

/**
 * MOD: This method assigns disbursement numbers and tries to combine payment groups with disbursement type check and ACH if possible.
 *
 * @param paymentProcess
 * @param postFormatProcessSummary
 */
protected boolean assignDisbursementNumbersAndBundle(PaymentProcess paymentProcess, FormatProcessSummary postFormatProcessSummary) {
    boolean successful = true;
    // keep a map with paymentGroupKey and PaymentInfo (disbursementNumber, noteLines)
    Map<String, PaymentInfo> combinedPaymentGroupMap = new HashMap<String, PaymentInfo>();
    Iterator<PaymentGroup> paymentGroupIterator = SpringContext.getBean(PaymentGroupService.class).getByProcess(paymentProcess);
    int maxNoteLines = getMaxNoteLines();
    while (paymentGroupIterator.hasNext()) {
        PaymentGroup paymentGroup = paymentGroupIterator.next();
        LOG.debug("performFormat() Payment Group ID " + paymentGroup.getId());
        // Use the customer's profile's campus code to check for disbursement ranges
        String campus = paymentGroup.getBatch().getCustomerProfile().getDefaultPhysicalCampusProcessingCode();
        // Where should this come from?
        List<DisbursementNumberRange> disbursementRanges = paymentDetailDao.getDisbursementNumberRanges(campus);
        DisbursementNumberRange range = getRange(disbursementRanges, paymentGroup.getBank(), paymentGroup.getDisbursementType().getCode());
        if (range == null) {
            GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.Format.ErrorMessages.ERROR_FORMAT_DISBURSEMENT_MISSING, campus, paymentGroup.getBank().getBankCode(), paymentGroup.getDisbursementType().getCode());
            successful = false;
            return successful;
        }
        if (PdpConstants.DisbursementTypeCodes.CHECK.equals(paymentGroup.getDisbursementType().getCode()) || PdpConstants.DisbursementTypeCodes.ACH.equals(paymentGroup.getDisbursementType().getCode())) {
            if (paymentGroup.getPymtAttachment().booleanValue() || paymentGroup.getProcessImmediate().booleanValue() || paymentGroup.getPymtSpecialHandling().booleanValue() || (!paymentGroup.getCombineGroups())) {
                assignDisbursementNumber(campus, range, paymentGroup, postFormatProcessSummary);
            } else {
                String paymentGroupKey = paymentGroup.toStringKey();
                // check if there was another paymentGroup we can combine with
                if (combinedPaymentGroupMap.containsKey(paymentGroupKey)) {
                    PaymentInfo paymentInfo = combinedPaymentGroupMap.get(paymentGroupKey);
                    paymentInfo.noteLines = paymentInfo.noteLines.add(new KualiInteger(paymentGroup.getNoteLines()));
                    // if CHECK and noteLines don't excede the maximum assign the same disbursementNumber
                    if (PdpConstants.DisbursementTypeCodes.ACH.equals(paymentGroup.getDisbursementType().getCode()) || (PdpConstants.DisbursementTypeCodes.CHECK.equals(paymentGroup.getDisbursementType().getCode()) && paymentInfo.noteLines.intValue() <= maxNoteLines)) {
                        paymentGroup.setDisbursementNbr(paymentInfo.disbursementNumber);
                        // update payment info for new noteLines value
                        combinedPaymentGroupMap.put(paymentGroupKey, paymentInfo);
                    } else // if noteLines more than maxNoteLines we remove the old entry and get a new disbursement number
                    if (PdpConstants.DisbursementTypeCodes.CHECK.equals(paymentGroup.getDisbursementType().getCode()) && paymentInfo.noteLines.intValue() > maxNoteLines) {
                        // remove old entry for this paymentGroupKey
                        combinedPaymentGroupMap.remove(paymentGroupKey);
                        // get a new check number and the paymentGroup noteLines
                        KualiInteger checkNumber = assignDisbursementNumber(campus, range, paymentGroup, postFormatProcessSummary);
                        int noteLines = paymentGroup.getNoteLines();
                        // create new payment info with these two
                        paymentInfo = new PaymentInfo(checkNumber, new KualiInteger(noteLines));
                        // add new entry in the map for this paymentGroupKey
                        combinedPaymentGroupMap.put(paymentGroupKey, paymentInfo);
                    } else {
                        // if it isn't check or ach, we're in trouble
                        LOG.error("assignDisbursementNumbersAndBundle() Payment group " + paymentGroup.getId() + " must be CHCK or ACH.  It is: " + paymentGroup.getDisbursementType());
                        throw new IllegalArgumentException("Payment group " + paymentGroup.getId() + " must be Check or ACH");
                    }
                } else // if no entry in the map for this payment group we create a new one
                {
                    // get a new disbursement number and the paymentGroup noteLines
                    KualiInteger disbursementNumber = assignDisbursementNumber(campus, range, paymentGroup, postFormatProcessSummary);
                    int noteLines = paymentGroup.getNoteLines();
                    // create new payment info with these two
                    PaymentInfo paymentInfo = new PaymentInfo(disbursementNumber, new KualiInteger(noteLines));
                    // add new entry in the map for this paymentGroupKey
                    combinedPaymentGroupMap.put(paymentGroupKey, paymentInfo);
                }
            }
        } else {
            // if it isn't check or ach, we're in trouble
            LOG.error("assignDisbursementNumbers() Payment group " + paymentGroup.getId() + " must be CHCK or ACH.  It is: " + paymentGroup.getDisbursementType());
            throw new IllegalArgumentException("Payment group " + paymentGroup.getId() + " must be Check or ACH");
        }
        businessObjectService.save(paymentGroup);
        // Generate a GL entry for CHCK & ACH
        SpringContext.getBean(PendingTransactionService.class).generatePaymentGeneralLedgerPendingEntry(paymentGroup);
        // Update all the ranges
        LOG.debug("assignDisbursementNumbers() Save ranges");
        for (DisbursementNumberRange element : disbursementRanges) {
            businessObjectService.save(element);
        }
    }
    return successful;
}
Also used : PaymentGroup(org.kuali.kfs.pdp.businessobject.PaymentGroup) PendingTransactionService(org.kuali.kfs.pdp.service.PendingTransactionService) HashMap(java.util.HashMap) KualiInteger(org.kuali.rice.core.api.util.type.KualiInteger) DisbursementNumberRange(org.kuali.kfs.pdp.businessobject.DisbursementNumberRange) PaymentGroupService(org.kuali.kfs.pdp.service.PaymentGroupService)

Aggregations

HashMap (java.util.HashMap)1 DisbursementNumberRange (org.kuali.kfs.pdp.businessobject.DisbursementNumberRange)1 PaymentGroup (org.kuali.kfs.pdp.businessobject.PaymentGroup)1 PaymentGroupService (org.kuali.kfs.pdp.service.PaymentGroupService)1 PendingTransactionService (org.kuali.kfs.pdp.service.PendingTransactionService)1 KualiInteger (org.kuali.rice.core.api.util.type.KualiInteger)1