Search in sources :

Example 1 with GeneralLedgerPendingEntrySequenceHelper

use of org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper 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
 */
protected void populatePaymentGeneralLedgerPendingEntry(PaymentGroup paymentGroup, String achFdocTypeCode, String checkFdocTypeCod, boolean reversal) {
    List<PaymentAccountDetail> accountListings = new ArrayList<PaymentAccountDetail>();
    for (PaymentDetail paymentDetail : paymentGroup.getPaymentDetails()) {
        accountListings.addAll(paymentDetail.getAccountDetail());
    }
    BusinessObjectEntry businessObjectEntry = dataDictionaryService.getDataDictionary().getBusinessObjectEntry(PaymentDetail.class.getName());
    AttributeDefinition attributeDefinition = businessObjectEntry.getAttributeDefinition("paymentGroup.payeeName");
    AttributeSecurity originalPayeeNameAttributeSecurity = attributeDefinition.getAttributeSecurity();
    String maskLiteral = ((MaskFormatterLiteral) originalPayeeNameAttributeSecurity.getMaskFormatter()).getLiteral();
    GeneralLedgerPendingEntrySequenceHelper sequenceHelper = new GeneralLedgerPendingEntrySequenceHelper();
    for (PaymentAccountDetail paymentAccountDetail : accountListings) {
        GlPendingTransaction glPendingTransaction = new GlPendingTransaction();
        glPendingTransaction.setSequenceNbr(new KualiInteger(sequenceHelper.getSequenceCounter()));
        if (StringUtils.isNotBlank(paymentAccountDetail.getPaymentDetail().getFinancialSystemOriginCode()) && StringUtils.isNotBlank(paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode())) {
            glPendingTransaction.setFdocRefTypCd(paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode());
            glPendingTransaction.setFsRefOriginCd(paymentAccountDetail.getPaymentDetail().getFinancialSystemOriginCode());
        } else {
            glPendingTransaction.setFdocRefTypCd(PdpConstants.PDP_FDOC_TYPE_CODE);
            glPendingTransaction.setFsRefOriginCd(PdpConstants.PDP_FDOC_ORIGIN_CODE);
        }
        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());
        if (paymentGroup.getDisbursementType().getCode().equals(PdpConstants.DisbursementTypeCodes.ACH)) {
            glPendingTransaction.setFinancialDocumentTypeCode(achFdocTypeCode);
        } else if (paymentGroup.getDisbursementType().getCode().equals(PdpConstants.DisbursementTypeCodes.CHECK)) {
            glPendingTransaction.setFinancialDocumentTypeCode(checkFdocTypeCod);
        }
        glPendingTransaction.setFsOriginCd(PdpConstants.PDP_FDOC_ORIGIN_CODE);
        glPendingTransaction.setFdocNbr(paymentGroup.getDisbursementNbr().toString());
        Boolean relieveLiabilities = paymentGroup.getBatch().getCustomerProfile().getRelieveLiabilities();
        if ((relieveLiabilities != null) && (relieveLiabilities.booleanValue()) && paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode() != null) {
            OffsetDefinition offsetDefinition = SpringContext.getBean(OffsetDefinitionService.class).getByPrimaryId(glPendingTransaction.getUniversityFiscalYear(), glPendingTransaction.getChartOfAccountsCode(), paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode(), glPendingTransaction.getFinancialBalanceTypeCode());
            glPendingTransaction.setFinancialObjectCode(offsetDefinition != null ? offsetDefinition.getFinancialObjectCode() : paymentAccountDetail.getFinObjectCode());
            glPendingTransaction.setFinancialSubObjectCode(KFSConstants.getDashFinancialSubObjectCode());
        } else {
            glPendingTransaction.setFinancialObjectCode(paymentAccountDetail.getFinObjectCode());
            glPendingTransaction.setFinancialSubObjectCode(paymentAccountDetail.getFinSubObjectCode());
        }
        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)) {
            trnDesc = maskLiteral;
        } 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.setDescription(trnDesc);
        glPendingTransaction.setOrgDocNbr(paymentAccountDetail.getPaymentDetail().getOrganizationDocNbr());
        glPendingTransaction.setOrgReferenceId(paymentAccountDetail.getOrgReferenceId());
        glPendingTransaction.setFdocRefNbr(paymentAccountDetail.getPaymentDetail().getCustPaymentDocNbr());
        // update the offset account if necessary
        SpringContext.getBean(FlexibleOffsetAccountService.class).updateOffset(glPendingTransaction);
        this.businessObjectService.save(glPendingTransaction);
        sequenceHelper.increment();
        if (bankService.isBankSpecificationEnabled()) {
            this.populateBankOffsetEntry(paymentGroup, glPendingTransaction, sequenceHelper);
        }
    }
}
Also used : GlPendingTransaction(org.kuali.kfs.pdp.businessobject.GlPendingTransaction) KualiInteger(org.kuali.rice.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.krad.datadictionary.BusinessObjectEntry) FlexibleOffsetAccountService(org.kuali.kfs.sys.service.FlexibleOffsetAccountService) OffsetDefinition(org.kuali.kfs.coa.businessobject.OffsetDefinition) OffsetDefinitionService(org.kuali.kfs.coa.service.OffsetDefinitionService) AttributeSecurity(org.kuali.kfs.krad.datadictionary.AttributeSecurity) PaymentAccountDetail(org.kuali.kfs.pdp.businessobject.PaymentAccountDetail) MaskFormatterLiteral(org.kuali.kfs.krad.datadictionary.mask.MaskFormatterLiteral)

Example 2 with GeneralLedgerPendingEntrySequenceHelper

use of org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper in project cu-kfs by CU-CommunityApps.

the class CuPurapGeneralLedgerServiceImpl method generateEntriesPaymentRequest.

protected boolean generateEntriesPaymentRequest(PaymentRequestDocument preq, List encumbrances, List summaryAccounts, String processType) {
    LOG.debug("generateEntriesPaymentRequest() started");
    boolean success = true;
    preq.setGeneralLedgerPendingEntries(new ArrayList());
    /*
         * Can't let generalLedgerPendingEntryService just create all the entries because we need the sequenceHelper to carry over
         * from the encumbrances to the actuals and also because we need to tell the PaymentRequestDocumentRule customize entry
         * method how to customize differently based on if creating an encumbrance or actual.
         */
    GeneralLedgerPendingEntrySequenceHelper sequenceHelper = new GeneralLedgerPendingEntrySequenceHelper(getNextAvailableSequence(preq.getDocumentNumber()));
    // when cancelling a PREQ, do not book encumbrances if PO is CLOSED
    if (encumbrances != null && !(CANCEL_PAYMENT_REQUEST.equals(processType) && PurapConstants.PurchaseOrderStatuses.APPDOC_CLOSED.equals(preq.getPurchaseOrderDocument().getApplicationDocumentStatus()))) {
        LOG.debug("generateEntriesPaymentRequest() generate encumbrance entries");
        if (CREATE_PAYMENT_REQUEST.equals(processType)) {
            // on create, use CREDIT code for encumbrances
            preq.setDebitCreditCodeForGLEntries(GL_CREDIT_CODE);
        } else if (CANCEL_PAYMENT_REQUEST.equals(processType)) {
            // on cancel, use DEBIT code
            preq.setDebitCreditCodeForGLEntries(GL_DEBIT_CODE);
        } else if (MODIFY_PAYMENT_REQUEST.equals(processType)) {
        // no encumbrances for modify
        }
        preq.setGenerateEncumbranceEntries(true);
        for (Iterator iter = encumbrances.iterator(); iter.hasNext(); ) {
            AccountingLine accountingLine = (AccountingLine) iter.next();
            preq.generateGeneralLedgerPendingEntries(accountingLine, sequenceHelper);
            // increment for the next line
            sequenceHelper.increment();
        }
    }
    if (ObjectUtils.isNotNull(summaryAccounts) && !summaryAccounts.isEmpty()) {
        LOG.debug("generateEntriesPaymentRequest() now book the actuals");
        preq.setGenerateEncumbranceEntries(false);
        if (CREATE_PAYMENT_REQUEST.equals(processType) || MODIFY_PAYMENT_REQUEST.equals(processType)) {
            // on create and modify, use DEBIT code
            preq.setDebitCreditCodeForGLEntries(GL_DEBIT_CODE);
        } else if (CANCEL_PAYMENT_REQUEST.equals(processType)) {
            // on cancel, use CREDIT code
            preq.setDebitCreditCodeForGLEntries(GL_CREDIT_CODE);
        }
        for (Iterator iter = summaryAccounts.iterator(); iter.hasNext(); ) {
            SummaryAccount summaryAccount = (SummaryAccount) iter.next();
            preq.generateGeneralLedgerPendingEntries(summaryAccount.getAccount(), sequenceHelper);
            // increment for the next line
            sequenceHelper.increment();
        }
        // generate offset accounts for use tax if it exists (useTaxContainers will be empty if not a use tax document)
        List<UseTaxContainer> useTaxContainers = SpringContext.getBean(PurapAccountingService.class).generateUseTaxAccount(preq);
        for (UseTaxContainer useTaxContainer : useTaxContainers) {
            PurApItemUseTax offset = useTaxContainer.getUseTax();
            List<SourceAccountingLine> accounts = useTaxContainer.getAccounts();
            for (SourceAccountingLine sourceAccountingLine : accounts) {
                preq.generateGeneralLedgerPendingEntries(sourceAccountingLine, sequenceHelper, useTaxContainer.getUseTax());
                // increment for the next line
                sequenceHelper.increment();
            }
        }
        // Manually save preq summary accounts
        if (MODIFY_PAYMENT_REQUEST.equals(processType)) {
            // for modify, regenerate the summary from the doc
            List<SummaryAccount> summaryAccountsForModify = SpringContext.getBean(PurapAccountingService.class).generateSummaryAccountsWithNoZeroTotalsNoUseTax(preq);
            saveAccountsPayableSummaryAccounts(summaryAccountsForModify, preq.getPurapDocumentIdentifier(), PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT);
        } else {
            // for create and cancel, use the summary accounts
            saveAccountsPayableSummaryAccounts(summaryAccounts, preq.getPurapDocumentIdentifier(), PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT);
        }
        // manually save cm account change tables (CAMS needs this)
        if (CREATE_PAYMENT_REQUEST.equals(processType) || MODIFY_PAYMENT_REQUEST.equals(processType)) {
            SpringContext.getBean(PurapAccountRevisionService.class).savePaymentRequestAccountRevisions(preq.getItems(), preq.getPostingYearFromPendingGLEntries(), preq.getPostingPeriodCodeFromPendingGLEntries());
        } else if (CANCEL_PAYMENT_REQUEST.equals(processType)) {
            SpringContext.getBean(PurapAccountRevisionService.class).cancelPaymentRequestAccountRevisions(preq.getItems(), preq.getPostingYearFromPendingGLEntries(), preq.getPostingPeriodCodeFromPendingGLEntries());
        }
        // we would only want to do this when booking the actuals (not the encumbrances)
        if (preq.getGeneralLedgerPendingEntries() == null || preq.getGeneralLedgerPendingEntries().size() < 2) {
            LOG.warn("No gl entries for accounting lines.");
        } else {
            // upon create, build the entries normally
            if (CREATE_PAYMENT_REQUEST.equals(processType)) {
                getPaymentMethodGeneralLedgerPendingEntryService().generatePaymentMethodSpecificDocumentGeneralLedgerPendingEntries(preq, ((CuPaymentRequestDocument) preq).getPaymentMethodCode(), preq.getBankCode(), KRADConstants.DOCUMENT_PROPERTY_NAME + "." + "bankCode", preq.getGeneralLedgerPendingEntry(0), false, false, sequenceHelper);
            } else if (MODIFY_PAYMENT_REQUEST.equals(processType)) {
                // upon modify, we need to calculate the deltas here and pass them in so the appropriate adjustments are created
                KualiDecimal bankOffsetAmount = KualiDecimal.ZERO;
                Map<String, KualiDecimal> changesByChart = new HashMap<String, KualiDecimal>();
                if (ObjectUtils.isNotNull(summaryAccounts) && !summaryAccounts.isEmpty()) {
                    for (SummaryAccount a : (List<SummaryAccount>) summaryAccounts) {
                        bankOffsetAmount = bankOffsetAmount.add(a.getAccount().getAmount());
                        if (changesByChart.get(a.getAccount().getChartOfAccountsCode()) == null) {
                            changesByChart.put(a.getAccount().getChartOfAccountsCode(), a.getAccount().getAmount());
                        } else {
                            changesByChart.put(a.getAccount().getChartOfAccountsCode(), changesByChart.get(a.getAccount().getChartOfAccountsCode()).add(a.getAccount().getAmount()));
                        }
                    }
                }
                getPaymentMethodGeneralLedgerPendingEntryService().generatePaymentMethodSpecificDocumentGeneralLedgerPendingEntries(preq, ((CuPaymentRequestDocument) preq).getPaymentMethodCode(), preq.getBankCode(), KRADConstants.DOCUMENT_PROPERTY_NAME + "." + "bankCode", preq.getGeneralLedgerPendingEntry(0), true, false, sequenceHelper, bankOffsetAmount, changesByChart);
            }
        }
        preq.generateDocumentGeneralLedgerPendingEntries(sequenceHelper);
    // END MOD
    }
    // Manually save GL entries for Payment Request and encumbrances
    saveGLEntries(preq.getGeneralLedgerPendingEntries());
    return success;
}
Also used : SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) AccountingLine(org.kuali.kfs.sys.businessobject.AccountingLine) UseTaxContainer(org.kuali.kfs.module.purap.util.UseTaxContainer) PurApItemUseTax(org.kuali.kfs.module.purap.businessobject.PurApItemUseTax) ArrayList(java.util.ArrayList) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) PurapAccountingService(org.kuali.kfs.module.purap.service.PurapAccountingService) GeneralLedgerPendingEntrySequenceHelper(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper) PurapAccountRevisionService(org.kuali.kfs.module.purap.service.PurapAccountRevisionService) SummaryAccount(org.kuali.kfs.module.purap.util.SummaryAccount) CuPaymentRequestDocument(edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument) Iterator(java.util.Iterator) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with GeneralLedgerPendingEntrySequenceHelper

use of org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper in project cu-kfs by CU-CommunityApps.

the class CuPendingTransactionServiceImpl method generateCreditMemoReversalEntries.

/**
 * Generates the reversal entries for the given input VendorCreditMemoDocument.
 *
 * @param doc
 *            the VendorCreditMemoDocument for which we generate the reversal entries
 * @param sequenceHelper
 */
protected void generateCreditMemoReversalEntries(VendorCreditMemoDocument cm) {
    cm.setGeneralLedgerPendingEntries(new ArrayList());
    boolean success = true;
    GeneralLedgerPendingEntrySequenceHelper sequenceHelper = new GeneralLedgerPendingEntrySequenceHelper(getNextAvailableSequence(cm.getDocumentNumber()));
    if (!cm.isSourceVendor()) {
        LOG.debug("generateEntriesCreditMemo() create encumbrance entries for CM against a PO or PREQ (not vendor)");
        PurchaseOrderDocument po = null;
        if (cm.isSourceDocumentPurchaseOrder()) {
            LOG.debug("generateEntriesCreditMemo() PO type");
            po = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(cm.getPurchaseOrderIdentifier());
        } else if (cm.isSourceDocumentPaymentRequest()) {
            LOG.debug("generateEntriesCreditMemo() PREQ type");
            po = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(cm.getPaymentRequestDocument().getPurchaseOrderIdentifier());
        }
        // for CM cancel or create, do not book encumbrances if PO is CLOSED, but do update the amounts on the PO
        List encumbrances = getCreditMemoEncumbrance(cm, po);
        if (!(PurapConstants.PurchaseOrderStatuses.APPDOC_CLOSED.equals(po.getApplicationDocumentStatus()))) {
            if (encumbrances != null) {
                cm.setGenerateEncumbranceEntries(true);
                // even if generating encumbrance entries on cancel, call is the same because the method gets negative amounts
                // from
                // the map so Debits on negatives = a credit
                cm.setDebitCreditCodeForGLEntries(GL_DEBIT_CODE);
                for (Iterator iter = encumbrances.iterator(); iter.hasNext(); ) {
                    AccountingLine accountingLine = (AccountingLine) iter.next();
                    if (accountingLine.getAmount().compareTo(ZERO) != 0) {
                        cm.generateGeneralLedgerPendingEntries(accountingLine, sequenceHelper);
                        // increment for the next line
                        sequenceHelper.increment();
                    }
                }
            }
        }
    }
    List<SummaryAccount> summaryAccounts = SpringContext.getBean(PurapAccountingService.class).generateSummaryAccountsWithNoZeroTotalsNoUseTax(cm);
    if (summaryAccounts != null) {
        LOG.debug("generateEntriesCreditMemo() now book the actuals");
        cm.setGenerateEncumbranceEntries(false);
        for (Iterator iter = summaryAccounts.iterator(); iter.hasNext(); ) {
            SummaryAccount summaryAccount = (SummaryAccount) iter.next();
            cm.generateGeneralLedgerPendingEntries(summaryAccount.getAccount(), sequenceHelper);
            // increment for the next line
            sequenceHelper.increment();
        }
        // generate offset accounts for use tax if it exists (useTaxContainers will be empty if not a use tax document)
        List<UseTaxContainer> useTaxContainers = SpringContext.getBean(PurapAccountingService.class).generateUseTaxAccount(cm);
        for (UseTaxContainer useTaxContainer : useTaxContainers) {
            PurApItemUseTax offset = useTaxContainer.getUseTax();
            List<SourceAccountingLine> accounts = useTaxContainer.getAccounts();
            for (SourceAccountingLine sourceAccountingLine : accounts) {
                cm.generateGeneralLedgerPendingEntries(sourceAccountingLine, sequenceHelper, useTaxContainer.getUseTax());
                // increment for the next line
                sequenceHelper.increment();
            }
        }
        // manually save cm account change tables (CAMS needs this)
        SpringContext.getBean(PurapAccountRevisionService.class).cancelCreditMemoAccountRevisions(cm.getItems(), cm.getPostingYearFromPendingGLEntries(), cm.getPostingPeriodCodeFromPendingGLEntries());
    }
    businessObjectService.save(cm.getGeneralLedgerPendingEntries());
}
Also used : SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) AccountingLine(org.kuali.kfs.sys.businessobject.AccountingLine) UseTaxContainer(org.kuali.kfs.module.purap.util.UseTaxContainer) PurApItemUseTax(org.kuali.kfs.module.purap.businessobject.PurApItemUseTax) PurchaseOrderService(org.kuali.kfs.module.purap.document.service.PurchaseOrderService) ArrayList(java.util.ArrayList) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) PurapAccountingService(org.kuali.kfs.module.purap.service.PurapAccountingService) GeneralLedgerPendingEntrySequenceHelper(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper) PurapAccountRevisionService(org.kuali.kfs.module.purap.service.PurapAccountRevisionService) SummaryAccount(org.kuali.kfs.module.purap.util.SummaryAccount) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 with GeneralLedgerPendingEntrySequenceHelper

use of org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper in project cu-kfs by CU-CommunityApps.

the class CuLaborPendingEntryConverterServiceImplTest method testGetBenefitClearingPendingEntry.

public void testGetBenefitClearingPendingEntry() throws IllegalAccessException, InstantiationException, WorkflowException {
    CuSalaryExpenseTransferDocument document = CuSalaryExpenseTransferDocumentFixture.GOOD_ST.createSalaryExpenseDocument();
    AccountingDocumentTestUtils.saveDocument(document, documentService);
    GeneralLedgerPendingEntrySequenceHelper sequenceHelper = new GeneralLedgerPendingEntrySequenceHelper();
    LaborLedgerPendingEntry laborLedgerPendingEntry = ((CuLaborPendingEntryConverterServiceImpl) laborPendingEntryConverterService).getBenefitClearingPendingEntry(document, sequenceHelper, "R704750", "IT", "MX", new KualiDecimal(6916.68), "5200");
    assertEquals("1", laborLedgerPendingEntry.getEmplid());
}
Also used : CuSalaryExpenseTransferDocument(edu.cornell.kfs.module.ld.document.CuSalaryExpenseTransferDocument) LaborLedgerPendingEntry(org.kuali.kfs.module.ld.businessobject.LaborLedgerPendingEntry) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) GeneralLedgerPendingEntrySequenceHelper(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper)

Example 5 with GeneralLedgerPendingEntrySequenceHelper

use of org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper in project cu-kfs by CU-CommunityApps.

the class GlTransactionServiceImpl method generateGlPendingTransaction.

/**
 * Generate GlPendingTransaction
 *
 * @param paymentGroup
 * @param financialDocumentTypeCode
 * @param stale
 */
private void generateGlPendingTransaction(PaymentGroup paymentGroup, String financialDocumentTypeCode, boolean stale) {
    List<PaymentAccountDetail> accountListings = new ArrayList<PaymentAccountDetail>();
    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.setFdocRefTypCd(paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode());
        glPendingTransaction.setFsRefOriginCd(paymentAccountDetail.getPaymentDetail().getFinancialSystemOriginCode());
        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.setSubAccountNumber(paymentAccountDetail.getSubAccountNbr());
        glPendingTransaction.setChartOfAccountsCode(paymentAccountDetail.getFinChartCode());
        glPendingTransaction.setFdocNbr(paymentGroup.getDisbursementNbr().toString());
        // Set doc type and origin code
        glPendingTransaction.setFinancialDocumentTypeCode(financialDocumentTypeCode);
        glPendingTransaction.setFsOriginCd(CRConstants.CR_FDOC_ORIGIN_CODE);
        String clAcct = parameterService.getParameterValueAsString(CheckReconciliationImportStep.class, CRConstants.CLEARING_ACCOUNT);
        String obCode = parameterService.getParameterValueAsString(CheckReconciliationImportStep.class, CRConstants.CLEARING_OBJECT_CODE);
        String coaCode = parameterService.getParameterValueAsString(CheckReconciliationImportStep.class, CRConstants.CLEARING_COA);
        // Use clearing parameters if stale
        String accountNbr = stale ? clAcct : paymentAccountDetail.getAccountNbr();
        String finObjectCode = stale ? obCode : paymentAccountDetail.getFinObjectCode();
        String finCoaCd = stale ? coaCode : paymentAccountDetail.getFinChartCode();
        Boolean relieveLiabilities = paymentGroup.getBatch().getCustomerProfile().getRelieveLiabilities();
        if ((relieveLiabilities != null) && (relieveLiabilities.booleanValue()) && paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode() != null) {
            OffsetDefinition offsetDefinition = SpringContext.getBean(OffsetDefinitionService.class).getByPrimaryId(glPendingTransaction.getUniversityFiscalYear(), glPendingTransaction.getChartOfAccountsCode(), paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode(), glPendingTransaction.getFinancialBalanceTypeCode());
            glPendingTransaction.setAccountNumber(accountNbr);
            glPendingTransaction.setChartOfAccountsCode(finCoaCd);
            glPendingTransaction.setFinancialObjectCode(offsetDefinition != null ? offsetDefinition.getFinancialObjectCode() : finObjectCode);
            glPendingTransaction.setFinancialSubObjectCode(KFSConstants.getDashFinancialSubObjectCode());
        } else {
            glPendingTransaction.setAccountNumber(accountNbr);
            glPendingTransaction.setChartOfAccountsCode(finCoaCd);
            glPendingTransaction.setFinancialObjectCode(finObjectCode);
            glPendingTransaction.setFinancialSubObjectCode(paymentAccountDetail.getFinSubObjectCode());
        }
        glPendingTransaction.setProjectCd(paymentAccountDetail.getProjectCode());
        if (paymentAccountDetail.getAccountNetAmount().bigDecimalValue().signum() >= 0) {
            glPendingTransaction.setDebitCrdtCd(KFSConstants.GL_CREDIT_CODE);
        } else {
            glPendingTransaction.setDebitCrdtCd(KFSConstants.GL_DEBIT_CODE);
        }
        glPendingTransaction.setAmount(paymentAccountDetail.getAccountNetAmount().abs());
        String trnDesc;
        String payeeName = paymentGroup.getPayeeName();
        trnDesc = payeeName.length() > 40 ? payeeName.substring(0, 40) : StringUtils.rightPad(payeeName, 40);
        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.setDescription(trnDesc);
        glPendingTransaction.setOrgDocNbr(paymentAccountDetail.getPaymentDetail().getOrganizationDocNbr());
        glPendingTransaction.setOrgReferenceId(paymentAccountDetail.getOrgReferenceId());
        glPendingTransaction.setFdocRefNbr(paymentAccountDetail.getPaymentDetail().getCustPaymentDocNbr());
        // update the offset account if necessary
        SpringContext.getBean(FlexibleOffsetAccountService.class).updateOffset(glPendingTransaction);
        this.businessObjectService.save(glPendingTransaction);
        sequenceHelper.increment();
    }
}
Also used : GlPendingTransaction(org.kuali.kfs.pdp.businessobject.GlPendingTransaction) KualiInteger(org.kuali.rice.core.api.util.type.KualiInteger) AccountingPeriod(org.kuali.kfs.coa.businessobject.AccountingPeriod) ArrayList(java.util.ArrayList) GeneralLedgerPendingEntrySequenceHelper(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper) Date(java.sql.Date) Date(java.sql.Date) PaymentDetail(org.kuali.kfs.pdp.businessobject.PaymentDetail) FlexibleOffsetAccountService(org.kuali.kfs.sys.service.FlexibleOffsetAccountService) OffsetDefinition(org.kuali.kfs.coa.businessobject.OffsetDefinition) OffsetDefinitionService(org.kuali.kfs.coa.service.OffsetDefinitionService) PaymentAccountDetail(org.kuali.kfs.pdp.businessobject.PaymentAccountDetail)

Aggregations

GeneralLedgerPendingEntrySequenceHelper (org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper)10 ArrayList (java.util.ArrayList)7 PaymentDetail (org.kuali.kfs.pdp.businessobject.PaymentDetail)5 OffsetDefinition (org.kuali.kfs.coa.businessobject.OffsetDefinition)4 OffsetDefinitionService (org.kuali.kfs.coa.service.OffsetDefinitionService)4 AccountingLine (org.kuali.kfs.sys.businessobject.AccountingLine)4 Date (java.sql.Date)3 Iterator (java.util.Iterator)3 AccountingPeriod (org.kuali.kfs.coa.businessobject.AccountingPeriod)3 PurApItemUseTax (org.kuali.kfs.module.purap.businessobject.PurApItemUseTax)3 PurapAccountingService (org.kuali.kfs.module.purap.service.PurapAccountingService)3 SummaryAccount (org.kuali.kfs.module.purap.util.SummaryAccount)3 UseTaxContainer (org.kuali.kfs.module.purap.util.UseTaxContainer)3 GlPendingTransaction (org.kuali.kfs.pdp.businessobject.GlPendingTransaction)3 PaymentAccountDetail (org.kuali.kfs.pdp.businessobject.PaymentAccountDetail)3 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)3 FlexibleOffsetAccountService (org.kuali.kfs.sys.service.FlexibleOffsetAccountService)3 KualiInteger (org.kuali.rice.core.api.util.type.KualiInteger)3 CuPaymentRequestDocument (edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument)2 HashMap (java.util.HashMap)2