Search in sources :

Example 31 with KualiDecimal

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

the class PurchasingActionBase method refresh.

/**
 * @see org.kuali.kfs.sys.web.struts.KualiAccountingDocumentActionBase#refresh(org.apache.struts.action.ActionMapping,
 *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
@Override
public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    PurchasingAccountsPayableFormBase baseForm = (PurchasingAccountsPayableFormBase) form;
    PurchasingDocument document = (PurchasingDocument) baseForm.getDocument();
    String refreshCaller = baseForm.getRefreshCaller();
    BusinessObjectService businessObjectService = SpringContext.getBean(BusinessObjectService.class);
    PhoneNumberService phoneNumberService = SpringContext.getBean(PhoneNumberService.class);
    // Format phone numbers
    document.setInstitutionContactPhoneNumber(phoneNumberService.formatNumberIfPossible(document.getInstitutionContactPhoneNumber()));
    document.setRequestorPersonPhoneNumber(phoneNumberService.formatNumberIfPossible(document.getRequestorPersonPhoneNumber()));
    document.setDeliveryToPhoneNumber(phoneNumberService.formatNumberIfPossible(document.getDeliveryToPhoneNumber()));
    // names in KIM are longer than what we store these names at; truncate them to match our data dictionary maxlengths
    if (StringUtils.equals(refreshCaller, "kimPersonLookupable")) {
        Integer deliveryToNameMaxLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(document.getClass(), PurapPropertyConstants.DELIVERY_TO_NAME);
        // KFSPTS-518/KFSUPGRADE-351
        if (deliveryToNameMaxLength == null && document instanceof PurchaseOrderAmendmentDocument) {
            deliveryToNameMaxLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(PurchaseOrderDocument.class, PurapPropertyConstants.DELIVERY_TO_NAME);
        }
        if (StringUtils.isNotEmpty(document.getDeliveryToName()) && ObjectUtils.isNotNull(deliveryToNameMaxLength) && document.getDeliveryToName().length() > deliveryToNameMaxLength.intValue()) {
            document.setDeliveryToName(document.getDeliveryToName().substring(0, deliveryToNameMaxLength));
            GlobalVariables.getMessageMap().clearErrorPath();
            GlobalVariables.getMessageMap().addToErrorPath(PurapConstants.DELIVERY_TAB_ERRORS);
            GlobalVariables.getMessageMap().putWarning(PurapPropertyConstants.DELIVERY_TO_NAME, PurapKeyConstants.WARNING_DELIVERY_TO_NAME_TRUNCATED);
            GlobalVariables.getMessageMap().removeFromErrorPath(PurapConstants.DELIVERY_TAB_ERRORS);
        }
        Integer requestorNameMaxLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(document.getClass(), PurapPropertyConstants.REQUESTOR_PERSON_NAME);
        // KFSPTS-518/KFSUPGRADE-351
        if (requestorNameMaxLength == null && document instanceof PurchaseOrderAmendmentDocument) {
            requestorNameMaxLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(PurchaseOrderDocument.class, PurapPropertyConstants.REQUESTOR_PERSON_NAME);
        }
        if (StringUtils.isNotEmpty(document.getRequestorPersonName()) && ObjectUtils.isNotNull(requestorNameMaxLength) && document.getRequestorPersonName().length() > requestorNameMaxLength.intValue()) {
            document.setRequestorPersonName(document.getRequestorPersonName().substring(0, requestorNameMaxLength));
            GlobalVariables.getMessageMap().clearErrorPath();
            GlobalVariables.getMessageMap().addToErrorPath(PurapConstants.ADDITIONAL_TAB_ERRORS);
            GlobalVariables.getMessageMap().putWarning(PurapPropertyConstants.REQUESTOR_PERSON_NAME, PurapKeyConstants.WARNING_REQUESTOR_NAME_TRUNCATED);
            GlobalVariables.getMessageMap().removeFromErrorPath(PurapConstants.ADDITIONAL_TAB_ERRORS);
        }
    }
    // Refreshing the fields after returning from a vendor lookup in the vendor tab
    if (StringUtils.equals(refreshCaller, VendorConstants.VENDOR_LOOKUPABLE_IMPL) && document.getVendorDetailAssignedIdentifier() != null && document.getVendorHeaderGeneratedIdentifier() != null) {
        document.setVendorContractGeneratedIdentifier(null);
        document.refreshReferenceObject("vendorContract");
        // retrieve vendor based on selection from vendor lookup
        document.refreshReferenceObject("vendorDetail");
        document.templateVendorDetail(document.getVendorDetail());
        // KFSPTS-1612 : populate vendor contract name
        if (CollectionUtils.isNotEmpty(document.getVendorDetail().getVendorContracts())) {
            for (VendorContract vendorContract : document.getVendorDetail().getVendorContracts()) {
                if (vendorContract.isActive()) {
                    document.setVendorContractGeneratedIdentifier(vendorContract.getVendorContractGeneratedIdentifier());
                    document.refreshReferenceObject("vendorContract");
                }
            }
        }
        // populate default address based on selected vendor
        VendorAddress defaultAddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(document.getVendorDetail().getVendorAddresses(), document.getVendorDetail().getVendorHeader().getVendorType().getAddressType().getVendorAddressTypeCode(), document.getDeliveryCampusCode());
        if (defaultAddress == null) {
            GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_DOC_ADDRESS, PurapKeyConstants.ERROR_INACTIVE_VENDORADDRESS);
        }
        document.templateVendorAddress(defaultAddress);
        // CU enhancement KFSUPGRDE-348
        document.setPurchaseOrderTransmissionMethodCode(((CuVendorAddressExtension) defaultAddress.getExtension()).getPurchaseOrderTransmissionMethodCode());
    }
    // Refreshing the fields after returning from a contract lookup in the vendor tab
    if (StringUtils.equals(refreshCaller, VendorConstants.VENDOR_CONTRACT_LOOKUPABLE_IMPL)) {
        if (StringUtils.isNotEmpty(request.getParameter(KFSPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.VENDOR_CONTRACT_ID))) {
            // retrieve Contract based on selection from contract lookup
            VendorContract refreshVendorContract = new VendorContract();
            refreshVendorContract.setVendorContractGeneratedIdentifier(document.getVendorContractGeneratedIdentifier());
            refreshVendorContract = (VendorContract) businessObjectService.retrieve(refreshVendorContract);
            // retrieve Vendor based on selected contract
            document.setVendorHeaderGeneratedIdentifier(refreshVendorContract.getVendorHeaderGeneratedIdentifier());
            document.setVendorDetailAssignedIdentifier(refreshVendorContract.getVendorDetailAssignedIdentifier());
            document.refreshReferenceObject("vendorDetail");
            document.templateVendorDetail(document.getVendorDetail());
            // always template contract after vendor to keep contract defaults last
            document.templateVendorContract(refreshVendorContract);
            // populate default address from selected vendor
            VendorAddress defaultAddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(document.getVendorDetail().getVendorAddresses(), document.getVendorDetail().getVendorHeader().getVendorType().getAddressType().getVendorAddressTypeCode(), "");
            if (defaultAddress == null) {
                GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_DOC_ADDRESS, PurapKeyConstants.ERROR_INACTIVE_VENDORADDRESS);
            }
            document.templateVendorAddress(defaultAddress);
            // update internal dollar limit for PO since the contract might affect this value
            if (document instanceof PurchaseOrderDocument) {
                PurchaseOrderDocument poDoc = (PurchaseOrderDocument) document;
                KualiDecimal limit = SpringContext.getBean(PurchaseOrderService.class).getInternalPurchasingDollarLimit(poDoc);
                poDoc.setInternalPurchasingLimit(limit);
            }
        }
    }
    // Refreshing the fields after returning from an address lookup in the vendor tab
    if (StringUtils.equals(refreshCaller, VendorConstants.VENDOR_ADDRESS_LOOKUPABLE_IMPL)) {
        if (StringUtils.isNotEmpty(request.getParameter(KFSPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.VENDOR_ADDRESS_ID))) {
            // retrieve address based on selection from address lookup
            VendorAddress refreshVendorAddress = new VendorAddress();
            refreshVendorAddress.setVendorAddressGeneratedIdentifier(document.getVendorAddressGeneratedIdentifier());
            refreshVendorAddress = (VendorAddress) businessObjectService.retrieve(refreshVendorAddress);
            document.templateVendorAddress(refreshVendorAddress);
        }
    }
    // Refreshing corresponding fields after returning from various kuali lookups
    if (StringUtils.equals(refreshCaller, KFSConstants.KUALI_LOOKUPABLE_IMPL)) {
        if (request.getParameter("document.deliveryCampusCode") != null) {
            // returning from a building or campus lookup on the delivery tab (update billing address)
            BillingAddress billingAddress = new BillingAddress();
            billingAddress.setBillingCampusCode(document.getDeliveryCampusCode());
            Map keys = SpringContext.getBean(PersistenceService.class).getPrimaryKeyFieldValues(billingAddress);
            billingAddress = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(BillingAddress.class, keys);
            document.templateBillingAddress(billingAddress);
            if (request.getParameter("document.deliveryBuildingName") == null) {
                // came from campus lookup not building, so clear building
                clearDeliveryBuildingInfo(document, true);
            } else {
                // came from building lookup then turn off "OTHER" and clear room and line2address
                document.setDeliveryBuildingOtherIndicator(false);
                document.setDeliveryBuildingRoomNumber("");
                document.setDeliveryBuildingLine2Address("");
            }
        } else if (request.getParameter("document.chartOfAccountsCode") != null) {
            // returning from a chart/org lookup on the document detail tab (update receiving address)
            document.loadReceivingAddress();
        } else {
            // returning from a building lookup in a capital asset tab location (update location address)
            String buildingCodeParam = findBuildingCodeFromCapitalAssetBuildingLookup(request);
            if (!StringUtils.isEmpty(buildingCodeParam)) {
                PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
                updateCapitalAssetLocation(request, purchasingForm, document, buildingCodeParam);
            }
        }
    }
    return super.refresh(mapping, form, request, response);
}
Also used : PurchaseOrderAmendmentDocument(org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument) PhoneNumberService(org.kuali.kfs.vnd.service.PhoneNumberService) VendorContract(org.kuali.kfs.vnd.businessobject.VendorContract) PurchaseOrderService(org.kuali.kfs.module.purap.document.service.PurchaseOrderService) PurchasingDocument(org.kuali.kfs.module.purap.document.PurchasingDocument) DataDictionaryService(org.kuali.kfs.kns.service.DataDictionaryService) BusinessObjectService(org.kuali.kfs.krad.service.BusinessObjectService) VendorService(org.kuali.kfs.vnd.document.service.VendorService) BillingAddress(org.kuali.kfs.module.purap.businessobject.BillingAddress) PersistenceService(org.kuali.kfs.krad.service.PersistenceService) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) VendorAddress(org.kuali.kfs.vnd.businessobject.VendorAddress) Map(java.util.Map) MessageMap(org.kuali.kfs.krad.util.MessageMap)

Example 32 with KualiDecimal

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

the class PurchaseOrderDocument method getTotalPreTaxDollarAmount.

/**
 * Gets the pre tax total dollar amount for this Purchase Order.
 *
 * @param includeInactive indicates whether inactive items shall be included.
 * @param includeBelowTheLine indicates whether below the line items shall be included.
 * @return the total dollar amount for this Purchase Order.
 */
public KualiDecimal getTotalPreTaxDollarAmount(boolean includeInactive, boolean includeBelowTheLine) {
    KualiDecimal total = new KualiDecimal(BigDecimal.ZERO);
    for (PurchaseOrderItem item : (List<PurchaseOrderItem>) getItems()) {
        ItemType it = item.getItemType();
        if ((includeBelowTheLine || it.isLineItemIndicator()) && (includeInactive || item.isItemActiveIndicator())) {
            KualiDecimal extendedPrice = item.getExtendedPrice();
            KualiDecimal itemTotal = (extendedPrice != null) ? extendedPrice : KualiDecimal.ZERO;
            total = total.add(itemTotal);
        }
    }
    return total;
}
Also used : PurchaseOrderItem(org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem) ItemType(org.kuali.kfs.module.purap.businessobject.ItemType) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) ArrayList(java.util.ArrayList) List(java.util.List)

Example 33 with KualiDecimal

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

the class PurchasingAccountsPayableDocumentBase method getTotalDollarAmountWithExclusionsSubsetItems.

/**
 * This method...
 *
 * @param excludedTypes
 * @param includeBelowTheLine
 * @param itemsForTotal
 * @return
 */
protected KualiDecimal getTotalDollarAmountWithExclusionsSubsetItems(String[] excludedTypes, boolean includeBelowTheLine, List<PurApItem> itemsForTotal) {
    if (excludedTypes == null) {
        excludedTypes = new String[] {};
    }
    KualiDecimal total = new KualiDecimal(BigDecimal.ZERO);
    for (PurApItem item : itemsForTotal) {
        item.refreshReferenceObject(PurapPropertyConstants.ITEM_TYPE);
        ItemType it = item.getItemType();
        if ((includeBelowTheLine || it.isLineItemIndicator()) && !ArrayUtils.contains(excludedTypes, it.getItemTypeCode())) {
            KualiDecimal totalAmount = item.getTotalAmount();
            KualiDecimal itemTotal = (totalAmount != null) ? totalAmount : KualiDecimal.ZERO;
            total = total.add(itemTotal);
        }
    }
    return total;
}
Also used : PurApItem(org.kuali.kfs.module.purap.businessobject.PurApItem) ItemType(org.kuali.kfs.module.purap.businessobject.ItemType) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal)

Example 34 with KualiDecimal

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

the class ConcurStandardAccountExtractPdpEntryServiceImplTest method assertTotals.

private void assertTotals(Map<DebitCreditTotal, KualiDecimal> totals, double debitTotal, double creditTotal) {
    assertEquals("Debit total expected to be " + debitTotal, new KualiDecimal(debitTotal), totals.get(DebitCreditTotal.DEBIT));
    assertEquals("Credit total expected to be " + creditTotal, new KualiDecimal(creditTotal), totals.get(DebitCreditTotal.CREDIT));
}
Also used : KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal)

Example 35 with KualiDecimal

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

the class ConcurStandardAccountingExtractCollectorBatchBuilderTest method assertReportStatisticHasCorrectTotals.

protected void assertReportStatisticHasCorrectTotals(List<ConcurSAEDetailLineFixture> lineFixtures, Predicate<ConcurSAEDetailLineFixture> fixtureFilter, ConcurBatchReportSummaryItem actualSummary) throws Exception {
    ConcurSAEDetailLineFixture[] filteredItems = lineFixtures.stream().filter(fixtureFilter).toArray(ConcurSAEDetailLineFixture[]::new);
    KualiDecimal expectedAmount = Arrays.stream(filteredItems).mapToDouble(ConcurSAEDetailLineFixture::getJournalAmount).mapToObj(KualiDecimal::new).reduce(KualiDecimal.ZERO, KualiDecimal::add);
    assertEquals("Wrong record count for statistic", filteredItems.length, actualSummary.getRecordCount());
    assertEquals("Wrong dollar amount for statistic", expectedAmount, actualSummary.getDollarAmount());
}
Also used : ConcurSAEDetailLineFixture(edu.cornell.kfs.concur.batch.fixture.ConcurSAEDetailLineFixture) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal)

Aggregations

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