Search in sources :

Example 76 with KualiDecimal

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

the class CheckReconciliationImportStep method updateCheckStatus.

/**
 * Get Check Status  and update pdp
 *
 * @param cr Check Reconciliation Object
 * @return String
 */
private String updateCheckStatus(CheckReconciliation cr, Collection<Bank> banks, List<CheckReconError> records) throws Exception {
    String defaultStatus = CRConstants.EXCP;
    String oldStatus = CRConstants.EXCP;
    List<String> bankCodes = new ArrayList<String>();
    // Generate list of valid bank codes
    for (Bank bank : banks) {
        if (bank.getBankAccountNumber().equals(cr.getBankAccountNumber())) {
            bankCodes.add(bank.getBankCode());
        }
    }
    if (bankCodes.size() == 0) {
        throw new Exception("Invalid Bank Account Number : " + cr.getBankAccountNumber());
    }
    Collection<PaymentGroup> paymentGroups = glTransactionService.getAllPaymentGroupForSearchCriteria(cr.getCheckNumber(), bankCodes);
    KualiDecimal totalNetAmount = getTotalNetAmount(paymentGroups);
    for (PaymentGroup paymentGroup : paymentGroups) {
        /*
        	 * At Cornell Check amount may consist of one or more payment group amounts.  
        	 * 
            if( !cr.getAmount().equals(paymentGroup.getNetPaymentAmount()) ) {
                records.add(getCheckReconError(cr, "The check amount does not match payment net amount."));
            }
            */
        if (!(totalNetAmount.doubleValue() == cr.getAmount().doubleValue())) {
            records.add(getCheckReconError(cr, "The check amount does not match payment net amount from the payment groups."));
        }
        if (statusMap.get(cr.getStatus()) != null) {
            defaultStatus = statusMap.get(cr.getStatus());
            oldStatus = paymentGroup.getPaymentStatusCode();
            // Update PDP status and save
            KualiCode code = businessObjectService.findBySinglePrimaryKey(PaymentStatus.class, defaultStatus);
            if (paymentGroup.getPaymentStatus() != ((PaymentStatus) code)) {
                paymentGroup.setPaymentStatus((PaymentStatus) code);
                paymentGroup.setLastUpdatedTimestamp(new Timestamp(cr.getStatusChangeDate().getTime()));
            }
            if (defaultStatus.equals(CRConstants.CLEARED)) {
                if (PaymentStatusCodes.EXTRACTED.equals(oldStatus)) {
                    businessObjectService.save(paymentGroup);
                    LOG.info("Check Status in the bank file is cleared. Updated Payment Group : " + paymentGroup.getId() + " Disbursement  " + paymentGroup.getDisbursementNbr());
                } else {
                    LOG.warn("Check Status in the bank file is cleared, but Payment Group " + paymentGroup.getId() + " for Disbursement " + paymentGroup.getDisbursementNbr() + " has a current status of " + oldStatus + " and cannot be cleared.");
                }
            }
        } else {
            LOG.warn("Update Payment Group Failed ( " + cr.getStatus() + ") ID : " + paymentGroup.getId());
        }
    }
    if (paymentGroups == null) {
        LOG.info("No Payments Found : " + cr.getBankAccountNumber() + "-" + cr.getCheckNumber());
    } else if (paymentGroups.size() == 0) {
        LOG.info("No Payments Found : " + cr.getBankAccountNumber() + "-" + cr.getCheckNumber());
    }
    return defaultStatus;
}
Also used : PaymentGroup(org.kuali.kfs.pdp.businessobject.PaymentGroup) Bank(org.kuali.kfs.sys.businessobject.Bank) KualiCode(org.kuali.kfs.krad.bo.KualiCode) ArrayList(java.util.ArrayList) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) Timestamp(java.sql.Timestamp) ParseException(java.text.ParseException) PaymentStatus(org.kuali.kfs.pdp.businessobject.PaymentStatus)

Example 77 with KualiDecimal

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

the class ConcurCashAdvancePdpFeedFileServiceImpl method buildPdpFeedBaseEntry.

private PdpFeedFileBaseEntry buildPdpFeedBaseEntry(ConcurRequestExtractFile requestExtractFile, ConcurRequestExtractBatchReportData reportData) {
    int totalPdpDetailRecordsCount = 0;
    KualiDecimal totalPdpDetailRecordsAmount = KualiDecimal.ZERO;
    PdpFeedFileBaseEntry pdpBaseEntry = new PdpFeedFileBaseEntry();
    pdpBaseEntry.setHeader(buildPdpFeedHeaderEntry(requestExtractFile.getBatchDate()));
    List<PdpFeedGroupEntry> groupEntries = new ArrayList<PdpFeedGroupEntry>();
    for (ConcurRequestExtractRequestDetailFileLine detailFileLine : requestExtractFile.getRequestDetails()) {
        if (isDetailFileLineValidCashAdvanceRequest(detailFileLine)) {
            PdpFeedDetailEntry pdpDetailEntry = buildPdpFeedDetailEntry(detailFileLine, buildPdpFeedAccountingEntry(detailFileLine));
            List<PdpFeedDetailEntry> pdpDetailEntries = new ArrayList<PdpFeedDetailEntry>();
            pdpDetailEntries.add(pdpDetailEntry);
            groupEntries.add(buildPdpFeedGroupEntry(detailFileLine, buildPdpFeedPayeeIdEntry(detailFileLine), pdpDetailEntries));
            recordCashAdvanceGenerationInDuplicateTrackingTable(detailFileLine, pdpDetailEntry.getSourceDocNbr(), requestExtractFile.getFileName());
            totalPdpDetailRecordsCount++;
            totalPdpDetailRecordsAmount = totalPdpDetailRecordsAmount.add(detailFileLine.getRequestAmount());
        }
        updateReportDataForDetailFileLineBeingProcessed(reportData, detailFileLine, totalPdpDetailRecordsCount, totalPdpDetailRecordsAmount);
    }
    pdpBaseEntry.setGroup(groupEntries);
    pdpBaseEntry.setTrailer(buildPdpFeedTrailerEntry(totalPdpDetailRecordsCount, totalPdpDetailRecordsAmount));
    pdpBaseEntry.setVersion(ConcurConstants.FEED_FILE_ENTRY_HEADER_VERSION);
    return pdpBaseEntry;
}
Also used : PdpFeedFileBaseEntry(edu.cornell.kfs.concur.batch.xmlObjects.PdpFeedFileBaseEntry) ArrayList(java.util.ArrayList) ConcurRequestExtractRequestDetailFileLine(edu.cornell.kfs.concur.batch.businessobject.ConcurRequestExtractRequestDetailFileLine) PdpFeedDetailEntry(edu.cornell.kfs.concur.batch.xmlObjects.PdpFeedDetailEntry) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) PdpFeedGroupEntry(edu.cornell.kfs.concur.batch.xmlObjects.PdpFeedGroupEntry)

Example 78 with KualiDecimal

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

the class SubmitTripWebServiceImpl method buildDisbursementVoucher.

/**
 * @param dvDescription
 * @param dvExplanation
 * @param tripNumber
 * @param travelerNetId
 * @param initiatorNetId
 * @param totalAmount
 * @param checkStubText
 * @return
 * @throws Exception
 */
private String buildDisbursementVoucher(String dvDescription, String dvExplanation, String tripNumber, String travelerNetId, String initiatorNetId, double totalAmount, String checkStubText) throws Exception {
    try {
        if (!isValidDocumentInitiator(initiatorNetId, DISBURSEMENT_VOUCHER)) {
            throw new RuntimeException("Initiator identified does not have permission to create a DV.");
        }
    } catch (Exception ex) {
        throw new RuntimeException("Initiator identified does not have permission to create a DV.", ex);
    }
    // create and route doc as system user
    GlobalVariables.setUserSession(new UserSession(initiatorNetId));
    MessageMap documentErrorMap = new MessageMap();
    GlobalVariables.setMessageMap(documentErrorMap);
    // Create document with description provided
    CuDisbursementVoucherDocument dvDoc = null;
    try {
        dvDoc = (CuDisbursementVoucherDocument) SpringContext.getBean(DocumentService.class).getNewDocument(DisbursementVoucherDocument.class);
    } catch (WorkflowException e) {
        throw new RuntimeException("Error creating new disbursement voucher document: " + e.getMessage(), e);
    }
    if (dvDoc != null) {
        dvDoc.getDocumentHeader().setDocumentDescription(dvDescription);
        dvDoc.getDocumentHeader().setExplanation(dvExplanation);
        dvDoc.getDocumentHeader().setOrganizationDocumentNumber(tripNumber);
        dvDoc.initiateDocument();
        // Set vendor to traveler using netID provided
        Person traveler = SpringContext.getBean(PersonService.class).getPersonByPrincipalName(travelerNetId);
        for (EntityAffiliationContract entityAffiliation : ((PersonImpl) traveler).getAffiliations()) {
            if (entityAffiliation.isDefaultValue()) {
                if (StringUtils.equalsIgnoreCase(entityAffiliation.getAffiliationType().getCode(), CuDisbursementVoucherConstants.PayeeAffiliations.STUDENT)) {
                    dvDoc.templateStudent(traveler);
                } else if (StringUtils.equalsIgnoreCase(entityAffiliation.getAffiliationType().getCode(), CuDisbursementVoucherConstants.PayeeAffiliations.ALUMNI)) {
                    dvDoc.templateAlumni(traveler);
                } else if (StringUtils.equalsIgnoreCase(entityAffiliation.getAffiliationType().getCode(), CuDisbursementVoucherConstants.PayeeAffiliations.FACULTY) || StringUtils.equalsIgnoreCase(entityAffiliation.getAffiliationType().getCode(), CuDisbursementVoucherConstants.PayeeAffiliations.STAFF)) {
                    dvDoc.templateEmployee(traveler);
                }
            }
        }
        dvDoc.setPayeeAssigned(true);
        dvDoc.getDvPayeeDetail().setDisbVchrPaymentReasonCode("J");
        dvDoc.setDisbVchrCheckTotalAmount(new KualiDecimal(totalAmount));
        dvDoc.setDisbVchrPaymentMethodCode("P");
        dvDoc.setDisbVchrCheckStubText(checkStubText);
        dvDoc.setTripId(tripNumber);
        dvDoc.setTripAssociationStatusCode(CULegacyTravelServiceImpl.TRIP_ASSOCIATIONS.IS_TRIP_DOC);
        // Persist document
        SpringContext.getBean(DocumentService.class).saveDocument(dvDoc);
        return dvDoc.getDocumentNumber();
    } else {
        return "";
    }
}
Also used : EntityAffiliationContract(org.kuali.rice.kim.api.identity.affiliation.EntityAffiliationContract) CuDisbursementVoucherDocument(edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument) PersonImpl(org.kuali.rice.kim.impl.identity.PersonImpl) UserSession(org.kuali.kfs.krad.UserSession) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) PersonService(org.kuali.rice.kim.api.identity.PersonService) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) Person(org.kuali.rice.kim.api.identity.Person) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) MessageMap(org.kuali.kfs.krad.util.MessageMap) DocumentService(org.kuali.kfs.krad.service.DocumentService)

Example 79 with KualiDecimal

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

the class CUPaymentMethodGeneralLedgerPendingEntryServiceImpl method generateClearingAccountOffsetEntries.

/**
 * When the "A" payment method is used for AP Credit Cards - generate the needed entries in the clearing account.
 *
 * @param document Document into which to add the generated GL Entries.
 * @param sequenceHelper helper class to keep track of GLPE sequence
 */
public boolean generateClearingAccountOffsetEntries(PaymentMethod pm, AccountingDocument document, GeneralLedgerPendingEntrySequenceHelper sequenceHelper, Map<String, KualiDecimal> actualTotalsByChart) {
    if (actualTotalsByChart == null) {
        actualTotalsByChart = getNonOffsetActualTotalsByChart(document);
    }
    for (String chart : actualTotalsByChart.keySet()) {
        KualiDecimal offsetAmount = actualTotalsByChart.get(chart);
        if (!KualiDecimal.ZERO.equals(offsetAmount)) {
            PaymentMethodChart pmc = pm.getPaymentMethodChartInfo(chart, new java.sql.Date(document.getDocumentHeader().getWorkflowDocument().getDateCreated().getMillis()));
            if (pmc == null) {
                LOG.warn("No Applicable PaymentMethodChart found for chart: " + chart + " and date: " + document.getDocumentHeader().getWorkflowDocument().getDateCreated());
                // skip this line - still attempt for other charts
                continue;
            }
            String clearingChartCode = pmc.getClearingChartOfAccountsCode();
            String clearingAccountNumber = pmc.getClearingAccountNumber();
            // liability object code
            String clearingObjectCode = pmc.getClearingFinancialObjectCode();
            GeneralLedgerPendingEntry apOffsetEntry = new GeneralLedgerPendingEntry(document.getGeneralLedgerPendingEntry(0));
            apOffsetEntry.setTransactionLedgerEntrySequenceNumber(new Integer(sequenceHelper.getSequenceCounter()));
            apOffsetEntry.setChartOfAccountsCode(clearingChartCode);
            apOffsetEntry.setAccountNumber(clearingAccountNumber);
            apOffsetEntry.setFinancialObjectCode(clearingObjectCode);
            // if internal billing
            if (StringUtils.equals(PaymentMethod.PM_CODE_INTERNAL_BILLING, pm.getPaymentMethodCode())) {
                apOffsetEntry.setFinancialSubObjectCode(pmc.getClearingFinancialSubObjectCode());
                apOffsetEntry.setSubAccountNumber(pmc.getClearingSubAccountNumber());
            } else {
                apOffsetEntry.setFinancialSubObjectCode(GENERAL_LEDGER_PENDING_ENTRY_CODE.getBlankFinancialSubObjectCode());
                apOffsetEntry.setSubAccountNumber(GENERAL_LEDGER_PENDING_ENTRY_CODE.getBlankSubAccountNumber());
            }
            apOffsetEntry.setProjectCode(GENERAL_LEDGER_PENDING_ENTRY_CODE.getBlankProjectCode());
            // retrieve object type
            ObjectCode objectCode = getObjectCodeService().getByPrimaryIdForCurrentYear(clearingChartCode, clearingObjectCode);
            if (objectCode == null) {
                LOG.fatal("Specified offset object code: " + clearingChartCode + "-" + clearingObjectCode + " does not exist - failed to generate CC offset entries", new RuntimeException());
                return false;
            }
            apOffsetEntry.setFinancialObjectTypeCode(objectCode.getFinancialObjectTypeCode());
            apOffsetEntry.setTransactionLedgerEntryAmount(offsetAmount.abs());
            apOffsetEntry.setTransactionDebitCreditCode(offsetAmount.isNegative() ? KFSConstants.GL_DEBIT_CODE : KFSConstants.GL_CREDIT_CODE);
            apOffsetEntry.setFinancialBalanceTypeCode(KFSConstants.BALANCE_TYPE_ACTUAL);
            document.addPendingEntry(apOffsetEntry);
            sequenceHelper.increment();
            // handle the offset entry
            GeneralLedgerPendingEntry offsetEntry = new GeneralLedgerPendingEntry(apOffsetEntry);
            getGeneralLedgerPendingEntryService().populateOffsetGeneralLedgerPendingEntry(document.getPostingYear(), apOffsetEntry, sequenceHelper, offsetEntry);
            document.addPendingEntry(offsetEntry);
            sequenceHelper.increment();
        }
    }
    return true;
}
Also used : PaymentMethodChart(edu.cornell.kfs.fp.businessobject.PaymentMethodChart) GeneralLedgerPendingEntry(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) ObjectCode(org.kuali.kfs.coa.businessobject.ObjectCode)

Example 80 with KualiDecimal

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

the class ScheduledAccountingLineServiceImpl method isAccountingLineTotalMoreThanRecurranceTotal.

private boolean isAccountingLineTotalMoreThanRecurranceTotal(ScheduledSourceAccountingLine scheduledAccountingLine) {
    KualiDecimal totalAmount = calculateTotalAmount(scheduledAccountingLine.getAmount());
    double recurranceTotal = scheduledAccountingLine.getPartialAmount().doubleValue() * Integer.parseInt(scheduledAccountingLine.getPartialTransactionCount());
    boolean isAccountingLineTotalMoreThanRecurranceTotal = totalAmount.doubleValue() > recurranceTotal;
    if (LOG.isDebugEnabled()) {
        LOG.debug("totalAmount = " + totalAmount + "  recurranceTotal: " + recurranceTotal + "  scheduledAccountingLine.getPartialTransactionCount(): " + scheduledAccountingLine.getPartialTransactionCount() + "  isAccountingLineTotalMoreThanRecurranceTotal: " + (isAccountingLineTotalMoreThanRecurranceTotal));
    }
    return isAccountingLineTotalMoreThanRecurranceTotal;
}
Also used : KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal)

Aggregations

KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)209 ArrayList (java.util.ArrayList)37 HashMap (java.util.HashMap)19 Test (org.junit.Test)19 List (java.util.List)15 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)15 CapitalAssetInformation (org.kuali.kfs.fp.businessobject.CapitalAssetInformation)14 BigDecimal (java.math.BigDecimal)13 Date (java.sql.Date)13 Iterator (java.util.Iterator)12 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)12 KualiInteger (org.kuali.rice.core.api.util.type.KualiInteger)12 PaymentRequestItem (org.kuali.kfs.module.purap.businessobject.PaymentRequestItem)11 IOException (java.io.IOException)10 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)10 Map (java.util.Map)9 CapitalAccountingLines (org.kuali.kfs.fp.businessobject.CapitalAccountingLines)9 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)9 PaymentGroup (org.kuali.kfs.pdp.businessobject.PaymentGroup)9 RequisitionDocument (org.kuali.kfs.module.purap.document.RequisitionDocument)8