Search in sources :

Example 1 with VendorCreditMemoDocument

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

use of org.kuali.kfs.module.purap.document.VendorCreditMemoDocument in project cu-kfs by CU-CommunityApps.

the class CuPurchasingAccountsPayableModuleServiceImpl method handlePurchasingBatchCancels.

/**
 * @see org.kuali.kfs.integration.pdp.service.PurchasingAccountsPayableModuleService#handlePurchasingBatchCancels(java.lang.String)
 */
public void handlePurchasingBatchCancels(String documentNumber, String documentTypeCode, boolean primaryCancel, boolean disbursedPayment, boolean crCancel) {
    ParameterService parameterService = SpringContext.getBean(ParameterService.class);
    PaymentRequestService paymentRequestService = SpringContext.getBean(PaymentRequestService.class);
    CreditMemoService creditMemoService = SpringContext.getBean(CreditMemoService.class);
    String preqCancelNote = parameterService.getParameterValueAsString(PaymentRequestDocument.class, PurapParameterConstants.PURAP_PDP_PREQ_CANCEL_NOTE);
    String preqResetNote = parameterService.getParameterValueAsString(PaymentRequestDocument.class, PurapParameterConstants.PURAP_PDP_PREQ_RESET_NOTE);
    String cmCancelNote = parameterService.getParameterValueAsString(VendorCreditMemoDocument.class, PurapParameterConstants.PURAP_PDP_CM_CANCEL_NOTE);
    String cmResetNote = parameterService.getParameterValueAsString(VendorCreditMemoDocument.class, PurapParameterConstants.PURAP_PDP_CM_RESET_NOTE);
    if (PurapConstants.PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT.equals(documentTypeCode)) {
        PaymentRequestDocument pr = paymentRequestService.getPaymentRequestByDocumentNumber(documentNumber);
        if (pr != null) {
            if (disbursedPayment || primaryCancel || crCancel) {
                if (!crCancel) {
                    paymentRequestService.cancelExtractedPaymentRequest(pr, preqCancelNote);
                }
            } else {
                paymentRequestService.resetExtractedPaymentRequest(pr, preqResetNote);
            }
        } else {
            LOG.error("processPdpCancels() DOES NOT EXIST, CANNOT PROCESS - Payment Request with doc type of " + documentTypeCode + " with id " + documentNumber);
        }
    } else if (PurapConstants.PurapDocTypeCodes.CREDIT_MEMO_DOCUMENT.equals(documentTypeCode)) {
        VendorCreditMemoDocument cm = creditMemoService.getCreditMemoByDocumentNumber(documentNumber);
        if (cm != null) {
            if (disbursedPayment || primaryCancel || crCancel) {
                if (!crCancel) {
                    creditMemoService.cancelExtractedCreditMemo(cm, cmCancelNote);
                }
            } else {
                creditMemoService.resetExtractedCreditMemo(cm, cmResetNote);
            }
        } else {
            LOG.error("processPdpCancels() DOES NOT EXIST, CANNOT PROCESS - Credit Memo with doc type of " + documentTypeCode + " with id " + documentNumber);
        }
    }
}
Also used : VendorCreditMemoDocument(org.kuali.kfs.module.purap.document.VendorCreditMemoDocument) ParameterService(org.kuali.kfs.coreservice.framework.parameter.ParameterService) PaymentRequestService(org.kuali.kfs.module.purap.document.service.PaymentRequestService) PaymentRequestDocument(org.kuali.kfs.module.purap.document.PaymentRequestDocument) CreditMemoService(org.kuali.kfs.module.purap.document.service.CreditMemoService)

Example 3 with VendorCreditMemoDocument

use of org.kuali.kfs.module.purap.document.VendorCreditMemoDocument in project cu-kfs by CU-CommunityApps.

the class CreditMemoForeignDraftValidation method validate.

/**
 * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
 */
public boolean validate(AttributedDocumentEvent event) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("validate start");
    }
    boolean isValid = true;
    VendorCreditMemoDocument document = (VendorCreditMemoDocument) accountingDocumentForValidation;
    if (!PaymentMethod.PM_CODE_FOREIGN_DRAFT.equals(((CuVendorCreditMemoDocument) document).getPaymentMethodCode())) {
        return true;
    }
    MessageMap errors = GlobalVariables.getMessageMap();
    errors.addToErrorPath(KFSPropertyConstants.DOCUMENT);
    errors.addToErrorPath(CUPurapPropertyConstants.CM_WIRE_TRANSFER);
    /* currency type code required */
    if (StringUtils.isBlank(((CuVendorCreditMemoDocument) document).getCmWireTransfer().getCmForeignCurrencyTypeCode())) {
        errors.putError(CUPurapPropertyConstants.CM_FD_CURRENCY_TYPE_CODE, KFSKeyConstants.ERROR_PAYMENT_SOURCE_CURRENCY_TYPE_CODE);
        isValid = false;
    }
    /* currency type name required */
    if (StringUtils.isBlank(((CuVendorCreditMemoDocument) document).getCmWireTransfer().getCmForeignCurrencyTypeName())) {
        errors.putError(CUPurapPropertyConstants.CM_FD_CURRENCY_TYPE_NAME, KFSKeyConstants.ERROR_PAYMENT_SOURCE_CURRENCY_TYPE_NAME);
        isValid = false;
    }
    errors.removeFromErrorPath(CUPurapPropertyConstants.CM_WIRE_TRANSFER);
    errors.removeFromErrorPath(KFSPropertyConstants.DOCUMENT);
    return isValid;
}
Also used : CuVendorCreditMemoDocument(edu.cornell.kfs.module.purap.document.CuVendorCreditMemoDocument) VendorCreditMemoDocument(org.kuali.kfs.module.purap.document.VendorCreditMemoDocument) CuVendorCreditMemoDocument(edu.cornell.kfs.module.purap.document.CuVendorCreditMemoDocument) MessageMap(org.kuali.kfs.krad.util.MessageMap)

Example 4 with VendorCreditMemoDocument

use of org.kuali.kfs.module.purap.document.VendorCreditMemoDocument in project cu-kfs by CU-CommunityApps.

the class CreditMemoWireTransferValidation method validate.

/**
 * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
 */
public boolean validate(AttributedDocumentEvent event) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("validate start");
    }
    boolean isValid = true;
    VendorCreditMemoDocument document = (VendorCreditMemoDocument) accountingDocumentForValidation;
    CreditMemoWireTransfer wireTransfer = ((CuVendorCreditMemoDocument) document).getCmWireTransfer();
    if (!PaymentMethod.PM_CODE_WIRE.equals(((CuVendorCreditMemoDocument) document).getPaymentMethodCode())) {
        return isValid;
    }
    MessageMap errors = GlobalVariables.getMessageMap();
    errors.addToErrorPath(KFSPropertyConstants.DOCUMENT);
    errors.addToErrorPath(CUPurapPropertyConstants.CM_WIRE_TRANSFER);
    isValid &= isValid(wireTransfer.getCmBankName(), CUPurapConstants.LABEL_BANK_NAME, CUPurapPropertyConstants.CM_BANK_NAME);
    isValid &= isValid(wireTransfer.getCmBankCityName(), CUPurapConstants.LABEL_BANK_CITY, CUPurapPropertyConstants.CM_BANK_CITY_NAME);
    isValid &= isValid(wireTransfer.getCmBankCountryCode(), CUPurapConstants.LABEL_BANK_COUNTRY, CUPurapPropertyConstants.CM_BANK_COUNTRY_CODE);
    isValid &= isValid(wireTransfer.getCmCurrencyTypeName(), CUPurapConstants.LABEL_CURRENCY, CUPurapPropertyConstants.CM_CURRENCY_TYPE_NAME);
    isValid &= isValid(wireTransfer.getCmPayeeAccountNumber(), CUPurapConstants.LABEL_BANK_ACCT_NUMBER, CUPurapPropertyConstants.CM_PAYEE_ACCT_NUMBER);
    isValid &= isValid(wireTransfer.getCmPayeeAccountName(), CUPurapConstants.LABEL_BANK_ACCT_NAME, CUPurapPropertyConstants.CM_PAYEE_ACCT_NAME);
    if (KFSConstants.COUNTRY_CODE_UNITED_STATES.equals(wireTransfer.getCmBankCountryCode()) && StringUtils.isBlank(wireTransfer.getCmBankRoutingNumber())) {
        errors.putError(CUPurapPropertyConstants.CM_BANK_ROUTING_NUMBER, KFSKeyConstants.ERROR_PAYMENT_SOURCE_BANK_ROUTING_NUMBER);
        isValid = false;
    }
    if (KFSConstants.COUNTRY_CODE_UNITED_STATES.equals(wireTransfer.getCmBankCountryCode()) && StringUtils.isBlank(wireTransfer.getCmBankStateCode())) {
        errors.putError(CUPurapPropertyConstants.CM_BANK_STATE_CODE, KFSKeyConstants.ERROR_REQUIRED, "Bank State");
        isValid = false;
    }
    errors.removeFromErrorPath(CUPurapPropertyConstants.CM_WIRE_TRANSFER);
    errors.removeFromErrorPath(KFSPropertyConstants.DOCUMENT);
    return isValid;
}
Also used : CuVendorCreditMemoDocument(edu.cornell.kfs.module.purap.document.CuVendorCreditMemoDocument) VendorCreditMemoDocument(org.kuali.kfs.module.purap.document.VendorCreditMemoDocument) CuVendorCreditMemoDocument(edu.cornell.kfs.module.purap.document.CuVendorCreditMemoDocument) CreditMemoWireTransfer(edu.cornell.kfs.module.purap.businessobject.CreditMemoWireTransfer) MessageMap(org.kuali.kfs.krad.util.MessageMap)

Example 5 with VendorCreditMemoDocument

use of org.kuali.kfs.module.purap.document.VendorCreditMemoDocument in project cu-kfs by CU-CommunityApps.

the class CuCreditMemoDocumentPreRules method doPrompts.

@Override
public boolean doPrompts(Document document) {
    boolean preRulesOK = true;
    // KFSUPGRADE-779
    preRulesOK &= checkWireTransferTabState((VendorCreditMemoDocument) document);
    AccountsPayableDocument accountsPayableDocument = (AccountsPayableDocument) document;
    // Check if the total does not match the submitted credit if the document hasn't been completed.
    if (!SpringContext.getBean(PurapService.class).isFullDocumentEntryCompleted(accountsPayableDocument)) {
        preRulesOK = confirmInvoiceNoMatchOverride(accountsPayableDocument);
    } else if (SpringContext.getBean(PurapService.class).isFullDocumentEntryCompleted(accountsPayableDocument)) {
        // if past full document entry complete, then set override to true to skip validation
        accountsPayableDocument.setUnmatchedOverride(true);
    }
    return preRulesOK;
}
Also used : CuVendorCreditMemoDocument(edu.cornell.kfs.module.purap.document.CuVendorCreditMemoDocument) VendorCreditMemoDocument(org.kuali.kfs.module.purap.document.VendorCreditMemoDocument) AccountsPayableDocument(org.kuali.kfs.module.purap.document.AccountsPayableDocument)

Aggregations

VendorCreditMemoDocument (org.kuali.kfs.module.purap.document.VendorCreditMemoDocument)18 CuVendorCreditMemoDocument (edu.cornell.kfs.module.purap.document.CuVendorCreditMemoDocument)7 PaymentRequestDocument (org.kuali.kfs.module.purap.document.PaymentRequestDocument)5 Note (org.kuali.kfs.krad.bo.Note)3 LinkedHashMap (java.util.LinkedHashMap)2 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)2 Document (org.kuali.kfs.krad.document.Document)2 MessageMap (org.kuali.kfs.krad.util.MessageMap)2 PurApAccountingLine (org.kuali.kfs.module.purap.businessobject.PurApAccountingLine)2 PurApItem (org.kuali.kfs.module.purap.businessobject.PurApItem)2 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)2 CreditMemoWireTransfer (edu.cornell.kfs.module.purap.businessobject.CreditMemoWireTransfer)1 CuPaymentRequestDocument (edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 DisbursementVoucherDocument (org.kuali.kfs.fp.document.DisbursementVoucherDocument)1 Entry (org.kuali.kfs.gl.businessobject.Entry)1 ExtraButton (org.kuali.kfs.kns.web.ui.ExtraButton)1