Search in sources :

Example 1 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class CuPaymentFileValidationServiceImpl method processGroupValidation.

@Override
protected void processGroupValidation(PaymentFileLoad paymentFile, MessageMap errorMap) {
    int groupCount = 0;
    for (PaymentGroup paymentGroup : paymentFile.getPaymentGroups()) {
        groupCount++;
        int noteLineCount = 0;
        int detailCount = 0;
        // We've encountered Payment Files that have address lines exceeding the column size in DB table;
        // so adding extra validation on payment group BO, especially the max length, based on DD definitions.
        // Check that PaymentGroup String properties don't exceed maximum allowed length
        checkPaymentGroupPropertyMaxLength(paymentGroup, errorMap);
        // verify payee id and owner code if customer requires them to be filled in
        if (paymentFile.getCustomer().getPayeeIdRequired() && StringUtils.isBlank(paymentGroup.getPayeeId())) {
            LOG.debug("processGroupValidation, No payee");
            errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_PAYEE_ID_REQUIRED, Integer.toString(groupCount));
        }
        if (paymentFile.getCustomer().getOwnershipCodeRequired() && StringUtils.isBlank(paymentGroup.getPayeeOwnerCd())) {
            LOG.debug("processGroupValidation, no ownership code");
            errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_PAYEE_OWNER_CODE, Integer.toString(groupCount));
        }
        // validate payee id type
        if (StringUtils.isNotBlank(paymentGroup.getPayeeIdTypeCd())) {
            PayeeType payeeType = businessObjectService.findBySinglePrimaryKey(PayeeType.class, paymentGroup.getPayeeIdTypeCd());
            if (payeeType == null) {
                LOG.debug("processGroupValidation, no payee type");
                errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INVALID_PAYEE_ID_TYPE, Integer.toString(groupCount), paymentGroup.getPayeeIdTypeCd());
            }
        }
        // validate vendor id and customer institution number
        if (paymentGroup.getPayeeId().split("-").length > 1) {
            try {
                paymentGroup.validateVendorIdAndCustomerInstitutionIdentifier();
            } catch (RuntimeException e1) {
                LOG.error("processGroupValidation, there was an error validating customer institution information", e1);
                errorMap.putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_BATCH_UPLOAD_PARSING, new String[] { e1.getMessage() });
            }
        } else {
            LOG.debug("processGroupValidation, found a non vendor number payee ID: " + paymentGroup.getPayeeId());
            if (cuPdpEmployeeService.shouldPayeeBeProcessedAsEmployeeForThisCustomer(paymentFile)) {
                Person employee = findPerson(paymentGroup.getPayeeId());
                if (ObjectUtils.isNull(employee)) {
                    LOG.error("processGroupValidation, unable to get a person from the employee id");
                    errorMap.putError(KFSConstants.GLOBAL_ERRORS, CUPdpKeyConstants.ERROR_PDP_PAYMENTLOAD_INVALID_EMPLOYEE_ID, paymentGroup.getPayeeId());
                }
            }
        }
        // validate bank
        String bankCode = paymentGroup.getBankCode();
        if (StringUtils.isNotBlank(bankCode)) {
            Bank bank = bankService.getByPrimaryId(bankCode);
            if (bank == null) {
                LOG.debug("processGroupValidation, no bank");
                errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INVALID_BANK_CODE, Integer.toString(groupCount), bankCode);
            } else if (!bank.isActive()) {
                LOG.debug("processGroupValidation, bank isn't active");
                errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INACTIVE_BANK_CODE, Integer.toString(groupCount), bankCode);
            }
        }
        KualiDecimal groupTotal = KualiDecimal.ZERO;
        for (PaymentDetail paymentDetail : paymentGroup.getPaymentDetails()) {
            detailCount++;
            // CU Customization: Check max lengths on Payment Detail properties.
            checkPaymentDetailPropertyMaxLength(paymentDetail, errorMap);
            // Add a line to print the invoice number
            noteLineCount++;
            noteLineCount = noteLineCount + paymentDetail.getNotes().size();
            if ((paymentDetail.getNetPaymentAmount() == null) && (!paymentDetail.isDetailAmountProvided())) {
                paymentDetail.setNetPaymentAmount(paymentDetail.getAccountTotal());
            } else if ((paymentDetail.getNetPaymentAmount() == null) && (paymentDetail.isDetailAmountProvided())) {
                paymentDetail.setNetPaymentAmount(paymentDetail.getCalculatedPaymentAmount());
            }
            // compare net to accounting segments
            if (paymentDetail.getAccountTotal().compareTo(paymentDetail.getNetPaymentAmount()) != 0) {
                LOG.debug("processGroupValidation, account total (" + paymentDetail.getAccountTotal() + ") not equal to net amount total (" + paymentDetail.getNetPaymentAmount() + ")");
                errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_DETAIL_TOTAL_MISMATCH, Integer.toString(groupCount), Integer.toString(detailCount), paymentDetail.getAccountTotal().toString(), paymentDetail.getNetPaymentAmount().toString());
            }
            // validate origin code if given
            if (StringUtils.isNotBlank(paymentDetail.getFinancialSystemOriginCode())) {
                OriginationCode originationCode = originationCodeService.getByPrimaryKey(paymentDetail.getFinancialSystemOriginCode());
                if (originationCode == null) {
                    LOG.debug("processGroupValidation, origination code is null");
                    errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INVALID_ORIGIN_CODE, Integer.toString(groupCount), Integer.toString(detailCount), paymentDetail.getFinancialSystemOriginCode());
                }
            }
            // validate doc type if given
            if (StringUtils.isNotBlank(paymentDetail.getFinancialDocumentTypeCode())) {
                if (!documentTypeService.isActiveByName(paymentDetail.getFinancialDocumentTypeCode())) {
                    LOG.debug("processGroupValidation, " + paymentDetail.getFinancialDocumentTypeCode() + " is not active.");
                    errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INVALID_DOC_TYPE, Integer.toString(groupCount), Integer.toString(detailCount), paymentDetail.getFinancialDocumentTypeCode());
                }
            }
            groupTotal = groupTotal.add(paymentDetail.getNetPaymentAmount());
        }
        // verify total for group is not negative
        if (groupTotal.doubleValue() < 0) {
            LOG.debug("processGroupValidation, group total less than zero");
            errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_NEGATIVE_GROUP_TOTAL, Integer.toString(groupCount));
        }
        // check that the number of detail items and note lines will fit on a check stub
        if (noteLineCount > getMaxNoteLines()) {
            LOG.debug("processGroupValidation, too many notes");
            errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_MAX_NOTE_LINES, Integer.toString(groupCount), Integer.toString(noteLineCount), Integer.toString(getMaxNoteLines()));
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("After processGroupValidation: " + printErrorMap(errorMap));
        }
    }
}
Also used : PaymentGroup(org.kuali.kfs.pdp.businessobject.PaymentGroup) Bank(org.kuali.kfs.sys.businessobject.Bank) PayeeType(org.kuali.kfs.pdp.businessobject.PayeeType) PaymentDetail(org.kuali.kfs.pdp.businessobject.PaymentDetail) OriginationCode(org.kuali.kfs.sys.businessobject.OriginationCode) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) Person(org.kuali.kfs.kim.api.identity.Person)

Example 2 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class CuExtractPaymentServiceImpl method writePaymentDetailToAchFile.

/*
     * New method created due to refactoring the code from ExtractPaymentServiceImpl and AchBundlerExtractPaymnetServiceImpl
     */
protected void writePaymentDetailToAchFile(BufferedWriter os, PaymentGroup paymentGroup, PaymentDetail paymentDetail, Map<String, Integer> unitCounts, Map<String, KualiDecimal> unitTotals, SimpleDateFormat sdf) throws IOException {
    try {
        writeOpenTag(os, 6, "payment");
        // Write detail info
        writeTag(os, 8, "purchaseOrderNbr", paymentDetail.getPurchaseOrderNbr());
        writeTag(os, 8, "invoiceNbr", paymentDetail.getInvoiceNbr());
        writeTag(os, 8, "requisitionNbr", paymentDetail.getRequisitionNbr());
        writeTag(os, 8, "custPaymentDocNbr", paymentDetail.getCustPaymentDocNbr());
        writeTag(os, 8, "invoiceDate", sdf.format(paymentDetail.getInvoiceDate()));
        writeTag(os, 8, "origInvoiceAmount", paymentDetail.getOrigInvoiceAmount().toString());
        writeTag(os, 8, "netPaymentAmount", paymentDetail.getNetPaymentAmount().toString());
        writeTag(os, 8, "invTotDiscountAmount", paymentDetail.getInvTotDiscountAmount().toString());
        writeTag(os, 8, "invTotShipAmount", paymentDetail.getInvTotShipAmount().toString());
        writeTag(os, 8, "invTotOtherDebitAmount", paymentDetail.getInvTotOtherDebitAmount().toString());
        writeTag(os, 8, "invTotOtherCreditAmount", paymentDetail.getInvTotOtherCreditAmount().toString());
        writeOpenTag(os, 8, "notes");
        for (PaymentNoteText note : paymentDetail.getNotes()) {
            writeTag(os, 10, "note", updateNoteLine(escapeString(note.getCustomerNoteText())));
        }
        writeCloseTag(os, 8, "notes");
        writeCloseTag(os, 6, "payment");
        String unit = paymentGroup.getBatch().getCustomerProfile().getChartCode() + "-" + paymentGroup.getBatch().getCustomerProfile().getUnitCode() + "-" + paymentGroup.getBatch().getCustomerProfile().getSubUnitCode();
        int count = 1;
        if (unitCounts.containsKey(unit)) {
            count = 1 + unitCounts.get(unit);
        }
        unitCounts.put(unit, count);
        KualiDecimal unitTotal = paymentDetail.getNetPaymentAmount();
        if (unitTotals.containsKey(unit)) {
            unitTotal = paymentDetail.getNetPaymentAmount().add(unitTotals.get(unit));
        }
        unitTotals.put(unit, unitTotal);
    } catch (IOException ioe) {
        LOG.error("writePaymentDetailToAchFile(): Problem writing to file - IOException caught and rethrown.");
        throw ioe;
    }
}
Also used : PaymentNoteText(org.kuali.kfs.pdp.businessobject.PaymentNoteText) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) IOException(java.io.IOException)

Example 3 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class CuExtractPaymentServiceImpl method writeExtractAchFile.

@Override
protected void writeExtractAchFile(PaymentStatus extractedStatus, String filename, Date processDate, SimpleDateFormat sdf) {
    BufferedWriter os = null;
    try {
        List<String> notificationEmailAddresses = this.getBankPaymentFileNotificationEmailAddresses();
        // Writes out the BNY Mellon Fast Track formatted file for ACH payments.  We need to do this first since the status is set in this method which
        // causes the writeExtractAchFileMellonBankFastTrack method to not find anything.
        writeExtractAchFileMellonBankFastTrack(extractedStatus, filename, processDate, sdf, notificationEmailAddresses);
        // totals for summary
        Map<String, Integer> unitCounts = new HashMap<String, Integer>();
        Map<String, KualiDecimal> unitTotals = new HashMap<String, KualiDecimal>();
        Iterator iter = paymentGroupService.getByDisbursementTypeStatusCode(PdpConstants.DisbursementTypeCodes.ACH, PdpConstants.PaymentStatusCodes.PENDING_ACH);
        if (iter.hasNext()) {
            OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(filename), StandardCharsets.UTF_8);
            os = new BufferedWriter(writer);
            os.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
            writeOpenTag(os, 0, "achPayments");
            while (iter.hasNext()) {
                PaymentGroup paymentGroup = (PaymentGroup) iter.next();
                if (!testMode) {
                    paymentGroup.setDisbursementDate(new java.sql.Date(processDate.getTime()));
                    paymentGroup.setPaymentStatus(extractedStatus);
                    businessObjectService.save(paymentGroup);
                }
                writePayeeSpecificsToAchFile(os, paymentGroup, processDate, sdf);
                // Write all payment level information
                writeOpenTag(os, 4, "payments");
                List<PaymentDetail> pdList = paymentGroup.getPaymentDetails();
                for (PaymentDetail paymentDetail : pdList) {
                    writePaymentDetailToAchFile(os, paymentGroup, paymentDetail, unitCounts, unitTotals, sdf);
                }
                writeCloseTag(os, 4, "payments");
                writeCloseTag(os, 2, "ach");
            }
            writeCloseTag(os, 0, "achPayments");
            paymentFileEmailService.sendAchSummaryEmail(unitCounts, unitTotals, dateTimeService.getCurrentDate());
        }
    } catch (IOException ie) {
        LOG.error("extractAchPayments() Problem reading file:  " + filename, ie);
        throw new IllegalArgumentException("Error writing to output file: " + ie.getMessage());
    } finally {
        // Close file
        if (os != null) {
            try {
                os.close();
            } catch (IOException ie) {
            // Not much we can do now
            }
        }
    }
}
Also used : PaymentGroup(org.kuali.kfs.pdp.businessobject.PaymentGroup) HashMap(java.util.HashMap) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) KualiInteger(org.kuali.kfs.core.api.util.type.KualiInteger) PaymentDetail(org.kuali.kfs.pdp.businessobject.PaymentDetail) FileOutputStream(java.io.FileOutputStream) Iterator(java.util.Iterator) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) OutputStreamWriter(java.io.OutputStreamWriter)

Example 4 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class CuExtractPaymentServiceImpl method writeExtractBundledAchFile.

/**
 * A custom method that goes through and extracts all pending ACH payments and bundles them by payee/disbursement nbr.
 * Changes made to this method due to re-factoring the code so that common pieces could be used
 * by both ExtractPaymentServiceImpl.writeExtractAchFile and AchBundlerExtractPaymentServiceImpl.writeExtractBundledAchFile
 * as well as incorporating the Mellon file creation.
 * --Added the call to method writeExtractAchFileMellonBankFastTrack
 * --Added the call to writePayeeSpecificsToAchFile for re-factored code
 * --Added the call to writePaymentDetailToAchFile for re-factored code
 * --Made the "finally" clause match the ExtractPaymentServiceImpl.writeExtractAchFile finally so that the XML files are named the same regardless of which routine is invoked.
 * --Added call to get the parameterized bank notification email addresses
 *
 * @param extractedStatus
 * @param filename
 * @param processDate
 * @param sdf
 */
protected void writeExtractBundledAchFile(PaymentStatus extractedStatus, String filename, Date processDate, SimpleDateFormat sdf) {
    LOG.info("writeExtractBundledAchFile started.");
    BufferedWriter os = null;
    try {
        List<String> notificationEmailAddresses = getBankPaymentFileNotificationEmailAddresses();
        // Writes out the BNY Mellon Fast Track formatted file for ACH payments.
        // We need to do this first since the status is set in this method which
        // causes the writeExtractAchFileMellonBankFastTrack method to not find anything.
        writeExtractAchFileMellonBankFastTrack(extractedStatus, filename, processDate, sdf, notificationEmailAddresses);
        // totals for summary
        Map<String, Integer> unitCounts = new HashMap<String, Integer>();
        Map<String, KualiDecimal> unitTotals = new HashMap<String, KualiDecimal>();
        os = new BufferedWriter(new FileWriter(filename, StandardCharsets.UTF_8));
        os.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        writeOpenTag(os, 0, "achPayments");
        HashSet<String> bankCodes = getAchBundlerHelperService().getDistinctBankCodesForPendingAchPayments();
        for (String bankCode : bankCodes) {
            HashSet<Integer> disbNbrs = getAchBundlerHelperService().getDistinctDisbursementNumbersForPendingAchPaymentsByBankCode(bankCode);
            for (Iterator<Integer> iter = disbNbrs.iterator(); iter.hasNext(); ) {
                Integer disbursementNbr = iter.next();
                boolean first = true;
                KualiDecimal totalNetAmount = new KualiDecimal(0);
                // this seems wasteful, but since the total net amount is needed on the first payment detail...it's needed
                Iterator<PaymentDetail> i2 = getAchBundlerHelperService().getPendingAchPaymentDetailsByDisbursementNumberAndBank(disbursementNbr, bankCode);
                while (i2.hasNext()) {
                    PaymentDetail pd = i2.next();
                    totalNetAmount = totalNetAmount.add(pd.getNetPaymentAmount());
                }
                Iterator<PaymentDetail> paymentDetails = getAchBundlerHelperService().getPendingAchPaymentDetailsByDisbursementNumberAndBank(disbursementNbr, bankCode);
                while (paymentDetails.hasNext()) {
                    PaymentDetail paymentDetail = paymentDetails.next();
                    PaymentGroup paymentGroup = paymentDetail.getPaymentGroup();
                    if (!testMode) {
                        paymentGroup.setDisbursementDate(new java.sql.Date(processDate.getTime()));
                        paymentGroup.setPaymentStatus(extractedStatus);
                        businessObjectService.save(paymentGroup);
                    }
                    if (first) {
                        writePayeeSpecificsToAchFile(os, paymentGroup, processDate, sdf);
                        writeOpenTag(os, 4, "payments");
                    }
                    writePaymentDetailToAchFile(os, paymentGroup, paymentDetail, unitCounts, unitTotals, sdf);
                    first = false;
                }
                writeCloseTag(os, 4, "payments");
                // open for this tag is in method writePayeeSpecificsToAchFile
                writeCloseTag(os, 2, "ach");
            }
        }
        writeCloseTag(os, 0, "achPayments");
        getPaymentFileEmailService().sendAchSummaryEmail(unitCounts, unitTotals, dateTimeService.getCurrentDate());
    } catch (IOException ie) {
        LOG.error("MOD: extractAchFile() Problem reading file:  " + filename, ie);
        throw new IllegalArgumentException("Error writing to output file: " + ie.getMessage());
    } finally {
        // Close file
        if (os != null) {
            try {
                os.close();
                // Need to do this at the end to indicate that the file is NOT USED after it is closed.
                renameFile(filename, filename + ".NOT_USED");
            } catch (IOException ie) {
                // Not much we can do now
                LOG.error("IOException encountered in writeExtractBundledAchFile.  Message is: " + ie.getMessage());
            }
        }
    }
}
Also used : PaymentGroup(org.kuali.kfs.pdp.businessobject.PaymentGroup) HashMap(java.util.HashMap) FileWriter(java.io.FileWriter) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) KualiInteger(org.kuali.kfs.core.api.util.type.KualiInteger) PaymentDetail(org.kuali.kfs.pdp.businessobject.PaymentDetail) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal)

Example 5 with KualiDecimal

use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.

the class CuExtractPaymentServiceImpl method writeExtractCheckFile.

@Override
protected void writeExtractCheckFile(PaymentStatus extractedStatus, PaymentProcess p, String filename, Integer processId) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
    Date processDate = dateTimeService.getCurrentDate();
    BufferedWriter os = null;
    BufferedWriter osI = null;
    boolean wroteImmediateHeaderRecords = false;
    boolean wroteCheckHeaderRecords = false;
    String immediateFilename = filename.replace("check", "check_immediate");
    String checkFilename = filename;
    boolean first = true;
    boolean isImmediate = false;
    // customer profile, then change the filename to append the RP-Upload prefix.
    if (isResearchParticipantExtractFile(processId)) {
        String checkFilePrefix = this.kualiConfigurationService.getPropertyValueAsString(PdpKeyConstants.ExtractPayment.CHECK_FILENAME);
        checkFilePrefix = MessageFormat.format(checkFilePrefix, new Object[] { null });
        checkFilePrefix = PdpConstants.RESEARCH_PARTICIPANT_FILE_PREFIX + KFSConstants.DASH + checkFilePrefix;
        filename = getOutputFile(checkFilePrefix, processDate);
    }
    try {
        List<String> notificationEmailAddresses = this.getBankPaymentFileNotificationEmailAddresses();
        writeExtractCheckFileMellonBankFastTrack(extractedStatus, p, filename, processId, notificationEmailAddresses);
        List<String> bankCodes = paymentGroupService.getDistinctBankCodesForProcessAndType(processId, PdpConstants.DisbursementTypeCodes.CHECK);
        for (String bankCode : bankCodes) {
            List<Integer> disbNbrs = paymentGroupService.getDisbursementNumbersByDisbursementTypeAndBankCode(processId, PdpConstants.DisbursementTypeCodes.CHECK, bankCode);
            for (Integer disbursementNbr : disbNbrs) {
                first = true;
                KualiDecimal totalNetAmount = new KualiDecimal(0);
                // this seems wasteful, but since the total net amount is needed on the first payment detail...it's needed
                Iterator<PaymentDetail> i2 = paymentDetailService.getByDisbursementNumber(disbursementNbr, processId, PdpConstants.DisbursementTypeCodes.CHECK, bankCode);
                while (i2.hasNext()) {
                    PaymentDetail pd = i2.next();
                    totalNetAmount = totalNetAmount.add(pd.getNetPaymentAmount());
                }
                List<KualiInteger> paymentGroupIdsSaved = new ArrayList<>();
                Iterator<PaymentDetail> paymentDetails = paymentDetailService.getByDisbursementNumber(disbursementNbr, processId, PdpConstants.DisbursementTypeCodes.CHECK, bankCode);
                while (paymentDetails.hasNext()) {
                    PaymentDetail detail = paymentDetails.next();
                    PaymentGroup group = detail.getPaymentGroup();
                    if (!testMode) {
                        if (!paymentGroupIdsSaved.contains(group.getId())) {
                            group.setDisbursementDate(new java.sql.Date(processDate.getTime()));
                            group.setPaymentStatus(extractedStatus);
                            this.businessObjectService.save(group);
                            paymentGroupIdsSaved.add(group.getId());
                        }
                    }
                    isImmediate = group.getProcessImmediate();
                    if (first && !isImmediate) {
                        if (!wroteCheckHeaderRecords) {
                            os = new BufferedWriter(new FileWriter(checkFilename, StandardCharsets.UTF_8));
                            os.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
                            writeOpenTagAttribute(os, 0, "checks", "processId", processId.toString(), "campusCode", p.getCampusCode());
                            wroteCheckHeaderRecords = true;
                        }
                        writeOpenTagAttribute(os, 2, "check", "disbursementNbr", group.getDisbursementNbr().toString());
                        // Write check level information
                        writeBank(os, 4, group.getBank());
                        writeTag(os, 4, "disbursementDate", sdf.format(processDate));
                        writeTag(os, 4, "netAmount", totalNetAmount.toString());
                        writePayee(os, 4, group);
                        writeTag(os, 4, "campusAddressIndicator", group.getCampusAddress() ? "Y" : "N");
                        writeTag(os, 4, "attachmentIndicator", group.getPymtAttachment() ? "Y" : "N");
                        writeTag(os, 4, "specialHandlingIndicator", group.getPymtSpecialHandling() ? "Y" : "N");
                        writeTag(os, 4, "immediatePaymentIndicator", group.getProcessImmediate() ? "Y" : "N");
                        writeTag(os, 4, "customerUnivNbr", group.getCustomerInstitutionNumber());
                        writeTag(os, 4, "paymentDate", sdf.format(group.getPaymentDate()));
                        // Write customer profile information
                        CustomerProfile cp = group.getBatch().getCustomerProfile();
                        writeCustomerProfile(os, 4, cp);
                        writeOpenTag(os, 4, "payments");
                        first = false;
                    }
                    if (first && isImmediate) {
                        if (!wroteImmediateHeaderRecords) {
                            osI = new BufferedWriter(new FileWriter(immediateFilename, StandardCharsets.UTF_8));
                            osI.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
                            writeOpenTagAttribute(osI, 0, "checks", "processId", processId.toString(), "campusCode", p.getCampusCode());
                            wroteImmediateHeaderRecords = true;
                        }
                        writeOpenTagAttribute(osI, 2, "check", "disbursementNbr", group.getDisbursementNbr().toString());
                        // Write check level information
                        writeBank(osI, 4, group.getBank());
                        writeTag(osI, 4, "disbursementDate", sdf.format(processDate));
                        writeTag(osI, 4, "netAmount", totalNetAmount.toString());
                        writePayee(osI, 4, group);
                        writeTag(osI, 4, "campusAddressIndicator", group.getCampusAddress() ? "Y" : "N");
                        writeTag(osI, 4, "attachmentIndicator", group.getPymtAttachment() ? "Y" : "N");
                        writeTag(osI, 4, "specialHandlingIndicator", group.getPymtSpecialHandling() ? "Y" : "N");
                        writeTag(osI, 4, "immediatePaymentIndicator", group.getProcessImmediate() ? "Y" : "N");
                        writeTag(osI, 4, "customerUnivNbr", group.getCustomerInstitutionNumber());
                        writeTag(osI, 4, "paymentDate", sdf.format(group.getPaymentDate()));
                        // Write customer profile information
                        CustomerProfile cp = group.getBatch().getCustomerProfile();
                        writeCustomerProfile(osI, 4, cp);
                        writeOpenTag(osI, 4, "payments");
                        first = false;
                    }
                    if (!isImmediate && wroteCheckHeaderRecords) {
                        writeOpenTag(os, 6, "payment");
                        writeTag(os, 8, "purchaseOrderNbr", detail.getPurchaseOrderNbr());
                        writeTag(os, 8, "invoiceNbr", detail.getInvoiceNbr());
                        writeTag(os, 8, "requisitionNbr", detail.getRequisitionNbr());
                        writeTag(os, 8, "custPaymentDocNbr", detail.getCustPaymentDocNbr());
                        writeTag(os, 8, "invoiceDate", sdf.format(detail.getInvoiceDate()));
                        writeTag(os, 8, "origInvoiceAmount", detail.getOrigInvoiceAmount().toString());
                        writeTag(os, 8, "netPaymentAmount", detail.getNetPaymentAmount().toString());
                        writeTag(os, 8, "invTotDiscountAmount", detail.getInvTotDiscountAmount().toString());
                        writeTag(os, 8, "invTotShipAmount", detail.getInvTotShipAmount().toString());
                        writeTag(os, 8, "invTotOtherDebitAmount", detail.getInvTotOtherDebitAmount().toString());
                        writeTag(os, 8, "invTotOtherCreditAmount", detail.getInvTotOtherCreditAmount().toString());
                        writeOpenTag(os, 8, "notes");
                        for (PaymentNoteText note : detail.getNotes()) {
                            writeTag(os, 10, "note", note.getCustomerNoteText());
                        }
                        writeCloseTag(os, 8, "notes");
                        writeCloseTag(os, 6, "payment");
                    }
                    if (isImmediate && wroteImmediateHeaderRecords) {
                        writeOpenTag(osI, 6, "payment");
                        writeTag(osI, 8, "purchaseOrderNbr", detail.getPurchaseOrderNbr());
                        writeTag(osI, 8, "invoiceNbr", detail.getInvoiceNbr());
                        writeTag(osI, 8, "requisitionNbr", detail.getRequisitionNbr());
                        writeTag(osI, 8, "custPaymentDocNbr", detail.getCustPaymentDocNbr());
                        writeTag(osI, 8, "invoiceDate", sdf.format(detail.getInvoiceDate()));
                        writeTag(osI, 8, "origInvoiceAmount", detail.getOrigInvoiceAmount().toString());
                        writeTag(osI, 8, "netPaymentAmount", detail.getNetPaymentAmount().toString());
                        writeTag(osI, 8, "invTotDiscountAmount", detail.getInvTotDiscountAmount().toString());
                        writeTag(osI, 8, "invTotShipAmount", detail.getInvTotShipAmount().toString());
                        writeTag(osI, 8, "invTotOtherDebitAmount", detail.getInvTotOtherDebitAmount().toString());
                        writeTag(osI, 8, "invTotOtherCreditAmount", detail.getInvTotOtherCreditAmount().toString());
                        writeOpenTag(osI, 8, "notes");
                        for (PaymentNoteText note : detail.getNotes()) {
                            writeTag(osI, 10, "note", note.getCustomerNoteText());
                        }
                        writeCloseTag(osI, 8, "notes");
                        writeCloseTag(osI, 6, "payment");
                    }
                }
                if (wroteCheckHeaderRecords && !isImmediate) {
                    writeCloseTag(os, 4, "payments");
                    writeCloseTag(os, 2, "check");
                }
                if (wroteImmediateHeaderRecords && isImmediate) {
                    writeCloseTag(osI, 4, "payments");
                    writeCloseTag(osI, 2, "check");
                }
            }
        }
    } catch (IOException ie) {
        LOG.error("extractChecks() Problem reading file:  " + filename, ie);
        throw new IllegalArgumentException("Error writing to output file: " + ie.getMessage());
    } finally {
        // Close file
        if (os != null) {
            try {
                writeCloseTag(os, 0, "checks");
                os.close();
                // An XML file containing these records are NEVER sent to anyone at this time.
                renameFile(checkFilename, checkFilename + ".NOT_USED");
                createDoneFile(checkFilename + ".NOT_USED");
            } catch (IOException ie) {
            // Not much we can do now
            }
        }
        if (osI != null) {
            try {
                writeCloseTag(osI, 0, "checks");
                osI.close();
                // An XML file containing these records are ONLY used for local check printing.
                renameFile(immediateFilename, immediateFilename + ".READY");
                createDoneFile(immediateFilename + ".READY");
            } catch (IOException ie) {
                // Not much we can do now
                LOG.error("IOException encountered in writeExtractCheckFile.  Message is: " + ie.getMessage());
            }
        }
    }
}
Also used : PaymentGroup(org.kuali.kfs.pdp.businessobject.PaymentGroup) KualiInteger(org.kuali.kfs.core.api.util.type.KualiInteger) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) CustomerProfile(org.kuali.kfs.pdp.businessobject.CustomerProfile) IOException(java.io.IOException) Date(java.util.Date) BufferedWriter(java.io.BufferedWriter) KualiInteger(org.kuali.kfs.core.api.util.type.KualiInteger) PaymentDetail(org.kuali.kfs.pdp.businessobject.PaymentDetail) PaymentNoteText(org.kuali.kfs.pdp.businessobject.PaymentNoteText) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)280 ArrayList (java.util.ArrayList)46 HashMap (java.util.HashMap)36 Test (org.junit.Test)28 AbstractKualiDecimal (org.kuali.kfs.core.api.util.type.AbstractKualiDecimal)21 BigDecimal (java.math.BigDecimal)18 List (java.util.List)18 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)15 Date (java.sql.Date)14 CapitalAssetInformation (org.kuali.kfs.fp.businessobject.CapitalAssetInformation)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 ConcurStandardAccountingExtractDetailLine (edu.cornell.kfs.concur.batch.businessobject.ConcurStandardAccountingExtractDetailLine)11 KualiInteger (org.kuali.kfs.core.api.util.type.KualiInteger)11 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)11 IOException (java.io.IOException)10 InvoiceDetailAccountObjectCode (org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)10 Map (java.util.Map)9 ParameterEvaluator (org.kuali.kfs.core.api.parameter.ParameterEvaluator)9 CapitalAccountingLines (org.kuali.kfs.fp.businessobject.CapitalAccountingLines)9 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)8