Search in sources :

Example 1 with PurApItemUseTax

use of org.kuali.kfs.module.purap.businessobject.PurApItemUseTax 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 2 with PurApItemUseTax

use of org.kuali.kfs.module.purap.businessobject.PurApItemUseTax 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 3 with PurApItemUseTax

use of org.kuali.kfs.module.purap.businessobject.PurApItemUseTax in project cu-kfs by CU-CommunityApps.

the class PurchasingAccountsPayableDocumentBase method getDeletionAwareUseTaxItems.

/**
 * Build deletion list of use tax items for PurAp generic use.
 *
 * @return
 */
@SuppressWarnings("rawtypes")
protected List getDeletionAwareUseTaxItems() {
    List<PurApItemUseTax> deletionAwareUseTaxItems = new ArrayList<PurApItemUseTax>();
    List<PurApItemBase> subManageList = this.getItems();
    for (PurApItemBase subManage : subManageList) {
        deletionAwareUseTaxItems.addAll(subManage.getUseTaxItems());
    }
    return deletionAwareUseTaxItems;
}
Also used : PurApItemUseTax(org.kuali.kfs.module.purap.businessobject.PurApItemUseTax) PurApItemBase(org.kuali.kfs.module.purap.businessobject.PurApItemBase) ArrayList(java.util.ArrayList)

Example 4 with PurApItemUseTax

use of org.kuali.kfs.module.purap.businessobject.PurApItemUseTax in project cu-kfs by CU-CommunityApps.

the class CuPendingTransactionServiceImpl method generateEntriesPaymentRequest.

/**
 * Creates the general ledger entries for Payment Request actions.
 *
 * @param preq Payment Request document to create entries
 * @param encumbrances List of encumbrance accounts if applies
 * @param accountingLines List of preq accounts to create entries
 * @param processType Type of process (create, modify, cancel)
 * @return Boolean returned indicating whether entry creation succeeded
 */
protected boolean generateEntriesPaymentRequest(PaymentRequestDocument preq, List encumbrances, List summaryAccounts) {
    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) {
        // on cancel, use DEBIT code
        preq.setDebitCreditCodeForGLEntries(GL_DEBIT_CODE);
        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);
        // 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 GL entries for Payment Request and encumbrances
    LOG.debug("saveGLEntries() started");
    businessObjectService.save(preq.getGeneralLedgerPendingEntries());
    return success;
}
Also used : SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) AccountingLine(org.kuali.kfs.sys.businessobject.AccountingLine) SummaryAccount(org.kuali.kfs.module.purap.util.SummaryAccount) UseTaxContainer(org.kuali.kfs.module.purap.util.UseTaxContainer) PurApItemUseTax(org.kuali.kfs.module.purap.businessobject.PurApItemUseTax) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) PurapAccountingService(org.kuali.kfs.module.purap.service.PurapAccountingService) GeneralLedgerPendingEntrySequenceHelper(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper)

Aggregations

ArrayList (java.util.ArrayList)4 PurApItemUseTax (org.kuali.kfs.module.purap.businessobject.PurApItemUseTax)4 Iterator (java.util.Iterator)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 AccountingLine (org.kuali.kfs.sys.businessobject.AccountingLine)3 GeneralLedgerPendingEntrySequenceHelper (org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper)3 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)3 PurapAccountRevisionService (org.kuali.kfs.module.purap.service.PurapAccountRevisionService)2 CuPaymentRequestDocument (edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 PurApItemBase (org.kuali.kfs.module.purap.businessobject.PurApItemBase)1 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)1 PurchaseOrderService (org.kuali.kfs.module.purap.document.service.PurchaseOrderService)1 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)1