Search in sources :

Example 6 with KualiInteger

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

the class CuPaymentMaintenanceServiceImpl method cancelDisbursement.

@Override
public boolean cancelDisbursement(Integer paymentGroupId, Integer paymentDetailId, String note, Person user) {
    LOG.debug("cancelDisbursement() started");
    if (!pdpAuthorizationService.hasCancelPaymentPermission(user.getPrincipalId())) {
        LOG.warn("cancelDisbursement() User " + user.getPrincipalId() + " does not have rights to cancel " + "payments. This should not happen unless user is URL spoofing.");
        throw new RuntimeException("cancelDisbursement() User " + user.getPrincipalId() + " does not have rights to cancel payments. This should not happen unless user is URL spoofing.");
    }
    PaymentGroup paymentGroup = this.paymentGroupService.get(paymentGroupId);
    if (paymentGroup == null) {
        LOG.debug("cancelDisbursement() Disbursement not found; throw exception.");
        GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.PaymentDetail.ErrorMessages.ERROR_DISBURSEMENT_NOT_FOUND);
        return false;
    }
    // get the target PaymentGroup info
    PaymentDetail targetPd = getPaymentDetail(paymentDetailId);
    KualiInteger targetGroupId = targetPd.getPaymentGroupId();
    PaymentGroup targetPg = getPaymentGroup(targetGroupId);
    String targetDvTypeCode = targetPg.getDisbursementTypeCode();
    String targetDvBankCode = targetPg.getBankCode();
    String paymentStatus = paymentGroup.getPaymentStatus().getCode();
    if (!(PdpConstants.PaymentStatusCodes.CANCEL_DISBURSEMENT.equals(paymentStatus))) {
        if (((PdpConstants.PaymentStatusCodes.EXTRACTED.equals(paymentStatus)) && (ObjectUtils.isNotNull(paymentGroup.getDisbursementDate()))) || (PdpConstants.PaymentStatusCodes.PENDING_ACH.equals(paymentStatus))) {
            LOG.debug("cancelDisbursement() Payment status is " + paymentStatus + "; continue with cancel.");
            List<PaymentGroup> allDisbursementPaymentGroups = this.paymentGroupService.getByDisbursementNumber(paymentGroup.getDisbursementNbr().intValue());
            for (PaymentGroup element : allDisbursementPaymentGroups) {
                // should be the same DV type and the same bank
                if (!(element.getDisbursementTypeCode().equalsIgnoreCase(targetDvTypeCode) && element.getBankCode().equalsIgnoreCase(targetDvBankCode))) {
                    continue;
                }
                PaymentGroupHistory pgh = new PaymentGroupHistory();
                if (!element.getPaymentDetails().get(0).isDisbursementActionAllowed()) {
                    LOG.warn("cancelDisbursement() Payment does not allow disbursement action. This should " + "not happen unless user is URL spoofing.");
                    throw new RuntimeException("cancelDisbursement() Payment does not allow disbursement action. " + "This should not happen unless user is URL spoofing.");
                }
                if ((ObjectUtils.isNotNull(element.getDisbursementType())) && (element.getDisbursementType().getCode().equals(PdpConstants.DisbursementTypeCodes.CHECK))) {
                    pgh.setPmtCancelExtractStat(Boolean.FALSE);
                }
                changeStatus(element, PdpConstants.PaymentStatusCodes.CANCEL_DISBURSEMENT, PdpConstants.PaymentChangeCodes.CANCEL_DISBURSEMENT, note, user, pgh);
                glPendingTransactionService.generateCancellationGeneralLedgerPendingEntry(element);
                // set primary cancel indicator for EPIC to use
                // these payment details will be canceled when running processPdpCancelAndPaidJOb
                Map<String, KualiInteger> primaryKeys = new HashMap<>();
                primaryKeys.put(PdpPropertyConstants.PaymentDetail.PAYMENT_DETAIL_PAYMENT_GROUP_ID, element.getId());
                // cancel all  payment details for payment group
                List<PaymentDetail> pds = (List<PaymentDetail>) this.businessObjectService.findMatching(PaymentDetail.class, primaryKeys);
                if (pds != null && !pds.isEmpty()) {
                    for (PaymentDetail pd : pds) {
                        pd.setPrimaryCancelledPayment(Boolean.TRUE);
                        this.businessObjectService.save(pd);
                    }
                }
            }
            LOG.debug("cancelDisbursement() Disbursement cancelled; exit method.");
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("cancelDisbursement() Payment status is " + paymentStatus + " and disbursement date is " + paymentGroup.getDisbursementDate() + "; cannot cancel payment in this status");
            }
            GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.PaymentDetail.ErrorMessages.ERROR_DISBURSEMENT_INVALID_TO_CANCEL);
            return false;
        }
    } else {
        LOG.debug("cancelDisbursement() Disbursement has already been cancelled; exit method.");
    }
    return true;
}
Also used : PaymentGroup(org.kuali.kfs.pdp.businessobject.PaymentGroup) PaymentDetail(org.kuali.kfs.pdp.businessobject.PaymentDetail) PaymentGroupHistory(org.kuali.kfs.pdp.businessobject.PaymentGroupHistory) HashMap(java.util.HashMap) KualiInteger(org.kuali.kfs.core.api.util.type.KualiInteger) List(java.util.List)

Example 7 with KualiInteger

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

the class PendingTransactionServiceImpl method populatePaymentGeneralLedgerPendingEntry.

/**
 * Populates and stores a new GLPE for each account detail in the payment group.
 *
 * @param paymentGroup     payment group to generate entries for
 * @param achFdocTypeCode  doc type for ach disbursements
 * @param checkFdocTypeCod doc type for check disbursements
 * @param reversal         boolean indicating if this is a reversal
 * @param expenseOrLiability boolean indicating if these should be expense (reversal=false) or liability
 *                           (reversal=true) entries
 */
protected void populatePaymentGeneralLedgerPendingEntry(PaymentGroup paymentGroup, String achFdocTypeCode, String checkFdocTypeCod, boolean reversal, boolean expenseOrLiability) {
    List<PaymentAccountDetail> accountListings = new ArrayList<>();
    for (PaymentDetail paymentDetail : paymentGroup.getPaymentDetails()) {
        accountListings.addAll(paymentDetail.getAccountDetail());
    }
    GeneralLedgerPendingEntrySequenceHelper sequenceHelper = new GeneralLedgerPendingEntrySequenceHelper();
    for (PaymentAccountDetail paymentAccountDetail : accountListings) {
        GlPendingTransaction glPendingTransaction = new GlPendingTransaction();
        glPendingTransaction.setSequenceNbr(new KualiInteger(sequenceHelper.getSequenceCounter()));
        glPendingTransaction.setFinancialBalanceTypeCode(KFSConstants.BALANCE_TYPE_ACTUAL);
        Date transactionTimestamp = new Date(dateTimeService.getCurrentDate().getTime());
        glPendingTransaction.setTransactionDt(transactionTimestamp);
        AccountingPeriod fiscalPeriod = accountingPeriodService.getByDate(new java.sql.Date(transactionTimestamp.getTime()));
        glPendingTransaction.setUniversityFiscalYear(fiscalPeriod.getUniversityFiscalYear());
        glPendingTransaction.setUnivFiscalPrdCd(fiscalPeriod.getUniversityFiscalPeriodCode());
        glPendingTransaction.setAccountNumber(paymentAccountDetail.getAccountNbr());
        glPendingTransaction.setSubAccountNumber(paymentAccountDetail.getSubAccountNbr());
        glPendingTransaction.setChartOfAccountsCode(paymentAccountDetail.getFinChartCode());
        glPendingTransaction.setProjectCd(paymentAccountDetail.getProjectCode());
        glPendingTransaction.setDebitCrdtCd(pdpUtilService.isDebit(paymentAccountDetail, reversal) ? KFSConstants.GL_DEBIT_CODE : KFSConstants.GL_CREDIT_CODE);
        glPendingTransaction.setAmount(paymentAccountDetail.getAccountNetAmount().abs());
        // Changes for Research Participant Upload
        String trnDesc = StringUtils.EMPTY;
        CustomerProfile customerProfile = paymentGroup.getBatch().getCustomerProfile();
        if (researchParticipantPaymentValidationService.isResearchParticipantPayment(customerProfile)) {
            BusinessObjectEntry businessObjectEntry = businessObjectDictionaryService.getBusinessObjectEntry(PaymentDetail.class.getName());
            AttributeDefinition attributeDefinition = businessObjectEntry.getAttributeDefinition("paymentGroup.payeeName");
            AttributeSecurity originalPayeeNameAttributeSecurity = attributeDefinition.getAttributeSecurity();
            // This is a temporary work around for an issue introduced with KFSCNTRB-705.
            if (ObjectUtils.isNotNull(originalPayeeNameAttributeSecurity)) {
                trnDesc = ((MaskFormatterLiteral) originalPayeeNameAttributeSecurity.getMaskFormatter()).getLiteral();
            }
        } else {
            String payeeName = paymentGroup.getPayeeName();
            if (StringUtils.isNotBlank(payeeName)) {
                trnDesc = payeeName.length() > 40 ? payeeName.substring(0, 40) : StringUtils.rightPad(payeeName, 40);
            }
            if (reversal) {
                String poNbr = paymentAccountDetail.getPaymentDetail().getPurchaseOrderNbr();
                if (StringUtils.isNotBlank(poNbr)) {
                    trnDesc += " " + (poNbr.length() > 9 ? poNbr.substring(0, 9) : StringUtils.rightPad(poNbr, 9));
                }
                String invoiceNbr = paymentAccountDetail.getPaymentDetail().getInvoiceNbr();
                if (StringUtils.isNotBlank(invoiceNbr)) {
                    trnDesc += " " + (invoiceNbr.length() > 14 ? invoiceNbr.substring(0, 14) : StringUtils.rightPad(invoiceNbr, 14));
                }
                if (trnDesc.length() > 40) {
                    trnDesc = trnDesc.substring(0, 40);
                }
            }
        }
        glPendingTransaction.setOrgDocNbr(paymentAccountDetail.getPaymentDetail().getOrganizationDocNbr());
        glPendingTransaction.setOrgReferenceId(paymentAccountDetail.getOrgReferenceId());
        final boolean relieveLiabilities = paymentGroup.getBatch().getCustomerProfile().getRelieveLiabilities();
        final OffsetDefinition offsetDefinition = offsetDefinitionService.getByPrimaryId(glPendingTransaction.getUniversityFiscalYear(), glPendingTransaction.getChartOfAccountsCode(), paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode(), glPendingTransaction.getFinancialBalanceTypeCode());
        if (expenseOrLiability && relieveLiabilities) {
            updateGeneralLedgerPendingEntryAsExpenseOrLiability(reversal, paymentAccountDetail, trnDesc, offsetDefinition, glPendingTransaction);
        } else {
            updateGeneralLedgerPendingEntryAsCheck(relieveLiabilities, paymentGroup.getDisbursementType().getCode(), paymentGroup.getDisbursementNbr(), achFdocTypeCode, checkFdocTypeCod, paymentAccountDetail, trnDesc, offsetDefinition, glPendingTransaction);
        }
        // update the offset account if necessary
        flexibleOffsetAccountService.updateOffset(glPendingTransaction);
        businessObjectService.save(glPendingTransaction);
        sequenceHelper.increment();
        if (bankService.isBankSpecificationEnabled() && !expenseOrLiability) {
            populateBankOffsetEntry(paymentGroup, glPendingTransaction, sequenceHelper);
        }
    }
}
Also used : GlPendingTransaction(org.kuali.kfs.pdp.businessobject.GlPendingTransaction) KualiInteger(org.kuali.kfs.core.api.util.type.KualiInteger) AccountingPeriod(org.kuali.kfs.coa.businessobject.AccountingPeriod) ArrayList(java.util.ArrayList) AttributeDefinition(org.kuali.kfs.krad.datadictionary.AttributeDefinition) CustomerProfile(org.kuali.kfs.pdp.businessobject.CustomerProfile) GeneralLedgerPendingEntrySequenceHelper(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper) Date(java.sql.Date) Date(java.sql.Date) PaymentDetail(org.kuali.kfs.pdp.businessobject.PaymentDetail) BusinessObjectEntry(org.kuali.kfs.kns.datadictionary.BusinessObjectEntry) OffsetDefinition(org.kuali.kfs.coa.businessobject.OffsetDefinition) AttributeSecurity(org.kuali.kfs.krad.datadictionary.AttributeSecurity) PaymentAccountDetail(org.kuali.kfs.pdp.businessobject.PaymentAccountDetail)

Example 8 with KualiInteger

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

the class PaymentFileServiceImpl method createNewBatch.

/**
 * Create a new {@link Batch} record for the payment file.
 *
 * @param paymentFile parsed payment file object
 * @param fileName    payment file name (without path)
 * @return {@link Batch} object
 */
protected Batch createNewBatch(PaymentFileLoad paymentFile, String fileName) {
    Timestamp now = dateTimeService.getCurrentTimestamp();
    Calendar nowPlus30 = Calendar.getInstance();
    nowPlus30.setTime(now);
    nowPlus30.add(Calendar.DATE, 30);
    Calendar nowMinus30 = Calendar.getInstance();
    nowMinus30.setTime(now);
    nowMinus30.add(Calendar.DATE, -30);
    Batch batch = new Batch();
    CustomerProfile customer = customerProfileService.get(paymentFile.getChart(), paymentFile.getUnit(), paymentFile.getSubUnit());
    batch.setCustomerProfile(customer);
    batch.setCustomerFileCreateTimestamp(new Timestamp(paymentFile.getCreationDate().getTime()));
    batch.setFileProcessTimestamp(now);
    batch.setPaymentCount(new KualiInteger(paymentFile.getPaymentCount()));
    if (fileName.length() > 30) {
        batch.setPaymentFileName(fileName.substring(0, 30));
    } else {
        batch.setPaymentFileName(fileName);
    }
    batch.setPaymentTotalAmount(paymentFile.getPaymentTotalAmount());
    batch.setSubmiterUserId(GlobalVariables.getUserSession().getPerson().getPrincipalId());
    return batch;
}
Also used : Batch(org.kuali.kfs.pdp.businessobject.Batch) Calendar(java.util.Calendar) KualiInteger(org.kuali.kfs.core.api.util.type.KualiInteger) CustomerProfile(org.kuali.kfs.pdp.businessobject.CustomerProfile) Timestamp(java.sql.Timestamp)

Example 9 with KualiInteger

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

the class FormatAction method continueFormat.

/**
 * This method performs the format process.
 *
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
public ActionForward continueFormat(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    FormatForm formatForm = (FormatForm) form;
    KualiInteger processId = formatForm.getFormatProcessSummary().getProcessId();
    try {
        formatService.performFormat(processId.intValue());
    } catch (FormatException e) {
        // errors added to global message map
        return mapping.findForward(PdpConstants.MAPPING_CONTINUE);
    }
    String lookupUrl = buildUrl(String.valueOf(processId.intValue()));
    return new ActionForward(lookupUrl, true);
}
Also used : KualiInteger(org.kuali.kfs.core.api.util.type.KualiInteger) FormatException(org.kuali.kfs.pdp.service.impl.exception.FormatException) ActionForward(org.apache.struts.action.ActionForward)

Example 10 with KualiInteger

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

the class FormatAction method cancel.

/**
 * This method cancels the format process
 *
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    FormatForm formatForm = (FormatForm) form;
    KualiInteger processId = formatForm.getFormatProcessSummary().getProcessId();
    if (processId != null) {
        formatService.clearUnfinishedFormat(processId.intValue());
    }
    return mapping.findForward(KRADConstants.MAPPING_PORTAL);
}
Also used : KualiInteger(org.kuali.kfs.core.api.util.type.KualiInteger)

Aggregations

KualiInteger (org.kuali.kfs.core.api.util.type.KualiInteger)26 ArrayList (java.util.ArrayList)8 KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)7 PaymentDetail (org.kuali.kfs.pdp.businessobject.PaymentDetail)7 Date (java.sql.Date)5 HashMap (java.util.HashMap)5 CustomerProfile (org.kuali.kfs.pdp.businessobject.CustomerProfile)5 PaymentNoteText (org.kuali.kfs.pdp.businessobject.PaymentNoteText)5 Date (java.util.Date)4 GlPendingTransaction (org.kuali.kfs.pdp.businessobject.GlPendingTransaction)4 PaymentAccountDetail (org.kuali.kfs.pdp.businessobject.PaymentAccountDetail)4 CheckReconciliation (com.rsmart.kuali.kfs.cr.businessobject.CheckReconciliation)3 AccountingPeriod (org.kuali.kfs.coa.businessobject.AccountingPeriod)3 OffsetDefinition (org.kuali.kfs.coa.businessobject.OffsetDefinition)3 Batch (org.kuali.kfs.pdp.businessobject.Batch)3 PaymentGroup (org.kuali.kfs.pdp.businessobject.PaymentGroup)3 GeneralLedgerPendingEntrySequenceHelper (org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper)3 Timestamp (java.sql.Timestamp)2 Calendar (java.util.Calendar)2 List (java.util.List)2