Search in sources :

Example 6 with SourceAccountingLine

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

the class CuPurapServiceImpl method prorateForTradeInAndFullOrderDiscount.

public void prorateForTradeInAndFullOrderDiscount(PurchasingAccountsPayableDocument purDoc) {
    if (purDoc instanceof VendorCreditMemoDocument) {
        throw new RuntimeException("This method not applicable for VCM documents");
    }
    // TODO: are we throwing sufficient errors in this method?
    PurApItem fullOrderDiscount = null;
    PurApItem tradeIn = null;
    KualiDecimal totalAmount = KualiDecimal.ZERO;
    KualiDecimal totalTaxAmount = KualiDecimal.ZERO;
    List<PurApAccountingLine> distributedAccounts = null;
    List<SourceAccountingLine> summaryAccounts = null;
    // iterate through below the line and grab FoD and TrdIn.
    for (PurApItem item : purDoc.getItems()) {
        if (item.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE)) {
            fullOrderDiscount = item;
        } else if (item.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE)) {
            tradeIn = item;
        }
    }
    // If Discount is not null or zero get proration list for all non misc items and set (if not empty?)
    if (fullOrderDiscount != null && fullOrderDiscount.getExtendedPrice() != null && fullOrderDiscount.getExtendedPrice().isNonZero()) {
        // empty
        KNSGlobalVariables.getMessageList().add("Full order discount accounts cleared and regenerated");
        fullOrderDiscount.getSourceAccountingLines().clear();
        // total amount is pretax dollars
        totalAmount = purDoc.getTotalDollarAmountAboveLineItems().subtract(purDoc.getTotalTaxAmountAboveLineItems());
        totalTaxAmount = purDoc.getTotalTaxAmountAboveLineItems();
        // Before we generate account summary, we should update the account amounts first.
        purapAccountingService.updateAccountAmounts(purDoc);
        // calculate tax
        boolean salesTaxInd = SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapParameterConstants.ENABLE_SALES_TAX_IND);
        boolean useTaxIndicator = purDoc.isUseTaxIndicator();
        if (salesTaxInd == true && (ObjectUtils.isNull(fullOrderDiscount.getItemTaxAmount()) && useTaxIndicator == false)) {
            KualiDecimal discountAmount = fullOrderDiscount.getExtendedPrice();
            KualiDecimal discountTaxAmount = discountAmount.divide(totalAmount).multiply(totalTaxAmount);
            fullOrderDiscount.setItemTaxAmount(discountTaxAmount);
        }
        // generate summary
        summaryAccounts = purapAccountingService.generateSummary(PurApItemUtils.getAboveTheLineOnly(purDoc.getItems()));
        if (summaryAccounts.size() == 0) {
            if (purDoc.shouldGiveErrorForEmptyAccountsProration()) {
                GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_SUMMARY_ACCOUNTS_LIST_EMPTY, "full order discount");
            }
        } else {
            // prorate accounts
            distributedAccounts = purapAccountingService.generateAccountDistributionForProration(summaryAccounts, totalAmount.add(totalTaxAmount), 2, fullOrderDiscount.getAccountingLineClass());
            for (PurApAccountingLine distributedAccount : distributedAccounts) {
                // KFSPTS-2200 : set item, so it can be verified as discount when validating
                if (distributedAccount instanceof PurApAccountingLineBase) {
                    ((PurApAccountingLineBase) distributedAccount).setDiscountTradeIn(true);
                }
                BigDecimal percent = distributedAccount.getAccountLinePercent();
                BigDecimal roundedPercent = new BigDecimal(Math.round(percent.doubleValue()));
                distributedAccount.setAccountLinePercent(roundedPercent);
            }
            // update amounts on distributed accounts
            purapAccountingService.updateAccountAmountsWithTotal(distributedAccounts, totalAmount, fullOrderDiscount.getTotalAmount());
            fullOrderDiscount.setSourceAccountingLines(distributedAccounts);
        }
    } else if (fullOrderDiscount != null && (fullOrderDiscount.getExtendedPrice() == null || fullOrderDiscount.getExtendedPrice().isZero())) {
        fullOrderDiscount.getSourceAccountingLines().clear();
    }
    // If tradeIn is not null or zero get proration list for all non misc items and set (if not empty?)
    if (tradeIn != null && tradeIn.getExtendedPrice() != null && tradeIn.getExtendedPrice().isNonZero()) {
        tradeIn.getSourceAccountingLines().clear();
        totalAmount = purDoc.getTotalDollarAmountForTradeIn();
        KualiDecimal tradeInTotalAmount = tradeIn.getTotalAmount();
        // Before we generate account summary, we should update the account amounts first.
        purapAccountingService.updateAccountAmounts(purDoc);
        // Before generating the summary, lets replace the object code in a cloned accounts collection sothat we can
        // consolidate all the modified object codes during summary generation.
        List<PurApItem> clonedTradeInItems = new ArrayList<PurApItem>();
        Collection<String> objectSubTypesRequiringQty = new ArrayList<String>(SpringContext.getBean(ParameterService.class).getParameterValuesAsString(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapParameterConstants.OBJECT_SUB_TYPES_REQUIRING_QUANTITY));
        Collection<String> purchasingObjectSubTypes = new ArrayList<String>(SpringContext.getBean(ParameterService.class).getParameterValuesAsString(KfsParameterConstants.CAPITAL_ASSETS_BATCH.class, PurapParameterConstants.PURCHASING_OBJECT_SUB_TYPES));
        String tradeInCapitalObjectCode = SpringContext.getBean(ParameterService.class).getParameterValueAsString(PurapConstants.PURAP_NAMESPACE, "Document", "TRADE_IN_OBJECT_CODE_FOR_CAPITAL_ASSET");
        String tradeInCapitalLeaseObjCd = SpringContext.getBean(ParameterService.class).getParameterValueAsString(PurapConstants.PURAP_NAMESPACE, "Document", "TRADE_IN_OBJECT_CODE_FOR_CAPITAL_LEASE");
        for (PurApItem item : purDoc.getTradeInItems()) {
            PurApItem cloneItem = (PurApItem) ObjectUtils.deepCopy(item);
            List<PurApAccountingLine> sourceAccountingLines = cloneItem.getSourceAccountingLines();
            for (PurApAccountingLine accountingLine : sourceAccountingLines) {
                if (objectSubTypesRequiringQty.contains(accountingLine.getObjectCode().getFinancialObjectSubTypeCode())) {
                    accountingLine.setFinancialObjectCode(tradeInCapitalObjectCode);
                } else if (purchasingObjectSubTypes.contains(accountingLine.getObjectCode().getFinancialObjectSubTypeCode())) {
                    accountingLine.setFinancialObjectCode(tradeInCapitalLeaseObjCd);
                }
            }
            clonedTradeInItems.add(cloneItem);
        }
        summaryAccounts = purapAccountingService.generateSummary(clonedTradeInItems);
        if (summaryAccounts.size() == 0) {
            if (purDoc.shouldGiveErrorForEmptyAccountsProration()) {
                GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_SUMMARY_ACCOUNTS_LIST_EMPTY, "trade in");
            }
        } else {
            distributedAccounts = purapAccountingService.generateAccountDistributionForProration(summaryAccounts, totalAmount, 2, tradeIn.getAccountingLineClass());
            for (PurApAccountingLine distributedAccount : distributedAccounts) {
                // KFSPTS-2200 : set item, so it can be verified as discount when validating
                if (distributedAccount instanceof PurApAccountingLineBase) {
                    ((PurApAccountingLineBase) distributedAccount).setDiscountTradeIn(true);
                }
                BigDecimal percent = distributedAccount.getAccountLinePercent();
                BigDecimal roundedPercent = new BigDecimal(Math.round(percent.doubleValue()));
                distributedAccount.setAccountLinePercent(roundedPercent);
                // set the accountAmount same as tradeIn amount not line item's amount
                resetAccountAmount(distributedAccount, tradeInTotalAmount);
            }
            tradeIn.setSourceAccountingLines(distributedAccounts);
        }
    }
}
Also used : VendorCreditMemoDocument(org.kuali.kfs.module.purap.document.VendorCreditMemoDocument) PurApItem(org.kuali.kfs.module.purap.businessobject.PurApItem) ParameterService(org.kuali.kfs.coreservice.framework.parameter.ParameterService) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) KfsParameterConstants(org.kuali.kfs.sys.service.impl.KfsParameterConstants) ArrayList(java.util.ArrayList) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) PurApAccountingLineBase(org.kuali.kfs.module.purap.businessobject.PurApAccountingLineBase) BigDecimal(java.math.BigDecimal) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal)

Example 7 with SourceAccountingLine

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

the class CuPurapGeneralLedgerServiceImpl method reencumberEncumbrance.

@Override
protected List<SourceAccountingLine> reencumberEncumbrance(PaymentRequestDocument preq) {
    LOG.debug("reencumberEncumbrance() started");
    PurchaseOrderDocument po = purchaseOrderService.getCurrentPurchaseOrder(preq.getPurchaseOrderIdentifier());
    Map encumbranceAccountMap = new HashMap();
    // Get each item one by one
    for (Iterator items = preq.getItems().iterator(); items.hasNext(); ) {
        PaymentRequestItem payRequestItem = (PaymentRequestItem) items.next();
        PurchaseOrderItem poItem = getPoItem(po, payRequestItem.getItemLineNumber(), payRequestItem.getItemType());
        // Amount to reencumber for this item
        KualiDecimal itemReEncumber = null;
        String logItmNbr = "Item # " + payRequestItem.getItemLineNumber();
        if (LOG.isDebugEnabled()) {
            LOG.debug("reencumberEncumbrance() " + logItmNbr);
        }
        // If there isn't a PO item or the total amount is 0, we don't need encumbrances
        final KualiDecimal preqItemTotalAmount = (payRequestItem.getTotalAmount() == null) ? KualiDecimal.ZERO : payRequestItem.getTotalAmount();
        if ((poItem == null) || (preqItemTotalAmount.doubleValue() == 0)) {
            if (poItem != null) {
                // KFSUPGRADE-893 recumber $0 item too
                if (poItem.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("reencumberEncumbrance() " + logItmNbr + " Calculate encumbrance based on quantity");
                    }
                    // Do disencumbrance calculations based on quantity
                    KualiDecimal preqQuantity = payRequestItem.getItemQuantity() == null ? ZERO : payRequestItem.getItemQuantity();
                    KualiDecimal outstandingEncumberedQuantity = poItem.getItemOutstandingEncumberedQuantity() == null ? ZERO : poItem.getItemOutstandingEncumberedQuantity();
                    KualiDecimal invoicedTotal = poItem.getItemInvoicedTotalQuantity() == null ? ZERO : poItem.getItemInvoicedTotalQuantity();
                    poItem.setItemInvoicedTotalQuantity(invoicedTotal.subtract(preqQuantity));
                    poItem.setItemOutstandingEncumberedQuantity(outstandingEncumberedQuantity.add(preqQuantity));
                }
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug("reencumberEncumbrance() " + logItmNbr + " No encumbrances required");
            }
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("reencumberEncumbrance() " + logItmNbr + " Calculate encumbrance GL entries");
            }
            // Do we calculate the encumbrance amount based on quantity or amount?
            if (poItem.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("reencumberEncumbrance() " + logItmNbr + " Calculate encumbrance based on quantity");
                }
                // Do disencumbrance calculations based on quantity
                KualiDecimal preqQuantity = payRequestItem.getItemQuantity() == null ? ZERO : payRequestItem.getItemQuantity();
                KualiDecimal outstandingEncumberedQuantity = poItem.getItemOutstandingEncumberedQuantity() == null ? ZERO : poItem.getItemOutstandingEncumberedQuantity();
                KualiDecimal invoicedTotal = poItem.getItemInvoicedTotalQuantity() == null ? ZERO : poItem.getItemInvoicedTotalQuantity();
                poItem.setItemInvoicedTotalQuantity(invoicedTotal.subtract(preqQuantity));
                poItem.setItemOutstandingEncumberedQuantity(outstandingEncumberedQuantity.add(preqQuantity));
                // do math as big decimal as doing it as a KualiDecimal will cause the item price to round to 2 digits
                itemReEncumber = new KualiDecimal(preqQuantity.bigDecimalValue().multiply(poItem.getItemUnitPrice()));
                // add tax for encumbrance
                KualiDecimal itemTaxAmount = poItem.getItemTaxAmount() == null ? ZERO : poItem.getItemTaxAmount();
                KualiDecimal encumbranceTaxAmount = preqQuantity.divide(poItem.getItemQuantity()).multiply(itemTaxAmount);
                itemReEncumber = itemReEncumber.add(encumbranceTaxAmount);
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("reencumberEncumbrance() " + logItmNbr + " Calculate encumbrance based on amount");
                }
                itemReEncumber = preqItemTotalAmount;
                // this prevents negative encumbrance
                if ((poItem.getTotalAmount() != null) && (poItem.getTotalAmount().bigDecimalValue().signum() < 0)) {
                    // po item extended cost is negative
                    if ((poItem.getTotalAmount().compareTo(itemReEncumber)) > 0) {
                        itemReEncumber = poItem.getTotalAmount();
                    }
                } else if ((poItem.getTotalAmount() != null) && (poItem.getTotalAmount().bigDecimalValue().signum() >= 0)) {
                    // po item extended cost is positive
                    if ((poItem.getTotalAmount().compareTo(itemReEncumber)) < 0) {
                        itemReEncumber = poItem.getTotalAmount();
                    }
                }
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug("reencumberEncumbrance() " + logItmNbr + " Amount to reencumber: " + itemReEncumber);
            }
            KualiDecimal outstandingEncumberedAmount = poItem.getItemOutstandingEncumberedAmount() == null ? ZERO : poItem.getItemOutstandingEncumberedAmount();
            if (LOG.isDebugEnabled()) {
                LOG.debug("reencumberEncumbrance() " + logItmNbr + " PO Item Outstanding Encumbrance Amount set to: " + outstandingEncumberedAmount);
            }
            KualiDecimal newOutstandingEncumberedAmount = outstandingEncumberedAmount.add(itemReEncumber);
            if (LOG.isDebugEnabled()) {
                LOG.debug("reencumberEncumbrance() " + logItmNbr + " New PO Item Outstanding Encumbrance Amount to set: " + newOutstandingEncumberedAmount);
            }
            poItem.setItemOutstandingEncumberedAmount(newOutstandingEncumberedAmount);
            KualiDecimal invoicedTotalAmount = poItem.getItemInvoicedTotalAmount() == null ? ZERO : poItem.getItemInvoicedTotalAmount();
            if (LOG.isDebugEnabled()) {
                LOG.debug("reencumberEncumbrance() " + logItmNbr + " PO Item Invoiced Total Amount set to: " + invoicedTotalAmount);
            }
            KualiDecimal newInvoicedTotalAmount = invoicedTotalAmount.subtract(preqItemTotalAmount);
            if (LOG.isDebugEnabled()) {
                LOG.debug("reencumberEncumbrance() " + logItmNbr + " New PO Item Invoiced Total Amount to set: " + newInvoicedTotalAmount);
            }
            poItem.setItemInvoicedTotalAmount(newInvoicedTotalAmount);
            // make the list of accounts for the reencumbrance entry
            PurchaseOrderAccount lastAccount = null;
            KualiDecimal accountTotal = ZERO;
            // Sort accounts
            Collections.sort((List) poItem.getSourceAccountingLines());
            for (Iterator accountIter = poItem.getSourceAccountingLines().iterator(); accountIter.hasNext(); ) {
                PurchaseOrderAccount account = (PurchaseOrderAccount) accountIter.next();
                if (!account.isEmpty()) {
                    SourceAccountingLine acctString = account.generateSourceAccountingLine();
                    // amount = item reencumber * account percent / 100
                    KualiDecimal reencumbranceAmount = itemReEncumber.multiply(new KualiDecimal(account.getAccountLinePercent().toString())).divide(HUNDRED);
                    account.setItemAccountOutstandingEncumbranceAmount(account.getItemAccountOutstandingEncumbranceAmount().add(reencumbranceAmount));
                    // For rounding check at the end
                    accountTotal = accountTotal.add(reencumbranceAmount);
                    lastAccount = account;
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("reencumberEncumbrance() " + logItmNbr + " " + acctString + " = " + reencumbranceAmount);
                    }
                    if (encumbranceAccountMap.containsKey(acctString)) {
                        KualiDecimal currentAmount = (KualiDecimal) encumbranceAccountMap.get(acctString);
                        encumbranceAccountMap.put(acctString, reencumbranceAmount.add(currentAmount));
                    } else {
                        encumbranceAccountMap.put(acctString, reencumbranceAmount);
                    }
                }
            }
            // account for rounding by adjusting last account as needed
            if (lastAccount != null) {
                KualiDecimal difference = itemReEncumber.subtract(accountTotal);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("reencumberEncumbrance() difference: " + logItmNbr + " " + difference);
                }
                SourceAccountingLine acctString = lastAccount.generateSourceAccountingLine();
                KualiDecimal amount = (KualiDecimal) encumbranceAccountMap.get(acctString);
                if (amount == null) {
                    encumbranceAccountMap.put(acctString, difference);
                } else {
                    encumbranceAccountMap.put(acctString, amount.add(difference));
                }
                lastAccount.setItemAccountOutstandingEncumbranceAmount(lastAccount.getItemAccountOutstandingEncumbranceAmount().add(difference));
            }
        }
    }
    SpringContext.getBean(BusinessObjectService.class).save(po);
    List<SourceAccountingLine> encumbranceAccounts = new ArrayList<SourceAccountingLine>();
    for (Iterator<SourceAccountingLine> iter = encumbranceAccountMap.keySet().iterator(); iter.hasNext(); ) {
        SourceAccountingLine acctString = iter.next();
        KualiDecimal amount = (KualiDecimal) encumbranceAccountMap.get(acctString);
        if (amount.doubleValue() != 0) {
            acctString.setAmount(amount);
            encumbranceAccounts.add(acctString);
        }
    }
    return encumbranceAccounts;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) BusinessObjectService(org.kuali.kfs.krad.service.BusinessObjectService) PurchaseOrderItem(org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem) PaymentRequestItem(org.kuali.kfs.module.purap.businessobject.PaymentRequestItem) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) Iterator(java.util.Iterator) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) HashMap(java.util.HashMap) Map(java.util.Map) PurchaseOrderAccount(org.kuali.kfs.module.purap.businessobject.PurchaseOrderAccount)

Example 8 with SourceAccountingLine

use of org.kuali.kfs.sys.businessobject.SourceAccountingLine 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 9 with SourceAccountingLine

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

the class GlLineServiceImpl method createAssetPaymentDocument.

/**
 * @see GlLineService#createAssetPaymentDocument(GeneralLedgerEntry, Integer)
 */
@Override
@NonTransactional
public Document createAssetPaymentDocument(GeneralLedgerEntry primaryGlEntry, Integer capitalAssetLineNumber) throws WorkflowException {
    // Find out the GL Entry
    // initiate a new document
    AssetPaymentDocument document = (AssetPaymentDocument) documentService.getNewDocument(DocumentTypeName.ASSET_PAYMENT);
    document.setCapitalAssetBuilderOriginIndicator(true);
    // populate the capital asset line distribution amount code to the payment document.
    CapitalAssetInformation capitalAssetInformation = findCapitalAssetInformation(primaryGlEntry.getDocumentNumber(), capitalAssetLineNumber);
    if (ObjectUtils.isNotNull(capitalAssetInformation)) {
        // setup asset allocation info accordingly so it can be changed on Asset Payment Document
        if (ObjectUtils.isNull(capitalAssetInformation.getDistributionAmountCode())) {
            document.setAssetPaymentAllocationTypeCode(KFSConstants.CapitalAssets.DISTRIBUTE_COST_EQUALLY_CODE);
            document.setAllocationFromFPDocuments(false);
        } else {
            document.setAssetPaymentAllocationTypeCode(capitalAssetInformation.getDistributionAmountCode());
            document.setAllocationFromFPDocuments(true);
        }
    }
    document.getDocumentHeader().setDocumentDescription(CAB_DESC_PREFIX + primaryGlEntry.getDocumentNumber());
    updatePreTagInformation(primaryGlEntry, document, capitalAssetLineNumber);
    // Asset Payment Detail - sourceAccountingLines on the document....
    document.getSourceAccountingLines().addAll(createAssetPaymentDetails(primaryGlEntry, document, 0, capitalAssetLineNumber));
    KualiDecimal assetAmount = KualiDecimal.ZERO;
    List<SourceAccountingLine> sourceAccountingLines = document.getSourceAccountingLines();
    for (SourceAccountingLine sourceAccountingLine : sourceAccountingLines) {
        assetAmount = assetAmount.add(sourceAccountingLine.getAmount());
    }
    List<AssetPaymentAssetDetail> assetPaymentDetails = document.getAssetPaymentAssetDetail();
    for (AssetPaymentAssetDetail assetPaymentDetail : assetPaymentDetails) {
        assetPaymentDetail.setAllocatedAmount(assetAmount);
    }
    // Asset payment asset detail
    // save the document
    documentService.saveDocument(document);
    markCapitalAssetProcessed(primaryGlEntry, capitalAssetLineNumber);
    deactivateGLEntries(primaryGlEntry, document, capitalAssetLineNumber);
    return document;
}
Also used : CapitalAssetInformation(org.kuali.kfs.fp.businessobject.CapitalAssetInformation) AssetPaymentDocument(org.kuali.kfs.module.cam.document.AssetPaymentDocument) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) AssetPaymentAssetDetail(org.kuali.kfs.module.cam.businessobject.AssetPaymentAssetDetail) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) NonTransactional(org.kuali.kfs.sys.service.NonTransactional)

Example 10 with SourceAccountingLine

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

the class SalaryExpenseTransferDocument method checkOjbectCodeForWorkstudy.

/**
 * KFSMI-4606 check routeNode condition
 *
 * @return boolean
 */
protected boolean checkOjbectCodeForWorkstudy() {
    Collection<String> workstudyRouteObjectcodes = SpringContext.getBean(ParameterService.class).getParameterValuesAsString(KfsParameterConstants.FINANCIAL_SYSTEM_DOCUMENT.class, KFSConstants.WORKSTUDY_ROUTE_OBJECT_CODES_PARM_NM);
    List<SourceAccountingLine> sourceAccountingLines = getSourceAccountingLines();
    List<TargetAccountingLine> targetAccountingLines = getTargetAccountingLines();
    // check object code in source and target accounting lines
    for (SourceAccountingLine sourceLine : sourceAccountingLines) {
        if (workstudyRouteObjectcodes.contains(sourceLine.getFinancialObjectCode())) {
            return true;
        }
    }
    for (TargetAccountingLine targetLine : targetAccountingLines) {
        if (workstudyRouteObjectcodes.contains(targetLine.getFinancialObjectCode())) {
            return true;
        }
    }
    return false;
}
Also used : ParameterService(org.kuali.kfs.coreservice.framework.parameter.ParameterService) TargetAccountingLine(org.kuali.kfs.sys.businessobject.TargetAccountingLine) KfsParameterConstants(org.kuali.kfs.sys.service.impl.KfsParameterConstants) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine)

Aggregations

SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)33 ArrayList (java.util.ArrayList)14 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)14 HashMap (java.util.HashMap)7 Iterator (java.util.Iterator)7 Map (java.util.Map)5 AccountingLine (org.kuali.kfs.sys.businessobject.AccountingLine)5 CuDisbursementVoucherDocument (edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument)4 Date (java.sql.Date)4 DisbursementVoucherDocument (org.kuali.kfs.fp.document.DisbursementVoucherDocument)4 PurchaseOrderAccount (org.kuali.kfs.module.purap.businessobject.PurchaseOrderAccount)4 PurapAccountingService (org.kuali.kfs.module.purap.service.PurapAccountingService)4 List (java.util.List)3 Test (org.junit.Test)3 PurApItemUseTax (org.kuali.kfs.module.purap.businessobject.PurApItemUseTax)3 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)3 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)3 SummaryAccount (org.kuali.kfs.module.purap.util.SummaryAccount)3 UseTaxContainer (org.kuali.kfs.module.purap.util.UseTaxContainer)3 TargetAccountingLine (org.kuali.kfs.sys.businessobject.TargetAccountingLine)3