Search in sources :

Example 16 with KualiDecimal

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

the class BalanceInquiryLookupAction method getSelectedObjectIds.

/**
 * put all entities into select object map. This implementation only deals with the money amount objects.
 *
 * @param multipleValueLookupForm the given struts form
 * @param resultTable             the given result table that holds all data being presented
 * @return the map containing all entries available for selection
 */
private Map<String, String> getSelectedObjectIds(MultipleValueLookupForm multipleValueLookupForm, List<ResultRow> resultTable) {
    String businessObjectClassName = multipleValueLookupForm.getBusinessObjectClassName();
    SegmentedBusinessObject segmentedBusinessObject;
    try {
        segmentedBusinessObject = (SegmentedBusinessObject) Class.forName(multipleValueLookupForm.getBusinessObjectClassName()).newInstance();
    } catch (Exception e) {
        throw new RuntimeException("Fail to create an object of " + businessObjectClassName + e);
    }
    Map<String, String> selectedObjectIds = new HashMap<>();
    Collection<String> segmentedPropertyNames = segmentedBusinessObject.getSegmentedPropertyNames();
    for (ResultRow row : resultTable) {
        for (Column column : row.getColumns()) {
            String propertyName = column.getPropertyName();
            if (segmentedPropertyNames.contains(propertyName)) {
                String propertyValue = StringUtils.replace(column.getPropertyValue(), ",", "");
                // Cornell Customization If there is a negative value, we need to convert it from (##.##) to -##.##
                if (StringUtils.contains(propertyValue, "(")) {
                    propertyValue = StringUtils.replace(propertyValue, "(", "-");
                    propertyValue = StringUtils.replace(propertyValue, ")", "");
                }
                KualiDecimal amount = new KualiDecimal(propertyValue);
                if (amount.isNonZero()) {
                    String objectId = row.getObjectId() + "." + propertyName + "." + KRADUtils.convertDecimalIntoInteger(amount);
                    selectedObjectIds.put(objectId, objectId);
                }
            }
        }
    }
    return selectedObjectIds;
}
Also used : ResultRow(org.kuali.kfs.kns.web.ui.ResultRow) HashMap(java.util.HashMap) Column(org.kuali.kfs.kns.web.ui.Column) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) SegmentedBusinessObject(org.kuali.kfs.integration.ld.SegmentedBusinessObject)

Example 17 with KualiDecimal

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

the class DisbursementVoucherDocument method templateEmployee.

/**
 * Convenience method to set dv payee detail fields based on a given Employee.
 *
 * @param employee
 */
public void templateEmployee(Person employee) {
    if (employee == null) {
        return;
    }
    this.getDvPayeeDetail().setDisbursementVoucherPayeeTypeCode(KFSConstants.PaymentPayeeTypes.EMPLOYEE);
    this.getDvPayeeDetail().setDisbVchrPayeeIdNumber(employee.getEmployeeId());
    this.getDvPayeeDetail().setDisbVchrPayeePersonName(employee.getName());
    final ParameterService parameterService = this.getParameterService();
    if (parameterService.parameterExists(DisbursementVoucherDocument.class, FPParameterConstants.USE_DEFAULT_EMPLOYEE_ADDRESS) && parameterService.getParameterValueAsBoolean(DisbursementVoucherDocument.class, FPParameterConstants.USE_DEFAULT_EMPLOYEE_ADDRESS)) {
        this.getDvPayeeDetail().setDisbVchrPayeeLine1Addr(employee.getAddressLine1Unmasked());
        this.getDvPayeeDetail().setDisbVchrPayeeLine2Addr(employee.getAddressLine2Unmasked());
        this.getDvPayeeDetail().setDisbVchrPayeeCityName(employee.getAddressCityUnmasked());
        this.getDvPayeeDetail().setDisbVchrPayeeStateCode(employee.getAddressStateProvinceCodeUnmasked());
        this.getDvPayeeDetail().setDisbVchrPayeeZipCode(employee.getAddressPostalCodeUnmasked());
        this.getDvPayeeDetail().setDisbVchrPayeeCountryCode(employee.getAddressCountryCodeUnmasked());
    } else {
        final EntityAddress address = getNonDefaultAddress(employee);
        if (address != null) {
            this.getDvPayeeDetail().setDisbVchrPayeeLine1Addr(address.getLine1Unmasked());
            this.getDvPayeeDetail().setDisbVchrPayeeLine2Addr(address.getLine2Unmasked());
            this.getDvPayeeDetail().setDisbVchrPayeeCityName(address.getCityUnmasked());
            this.getDvPayeeDetail().setDisbVchrPayeeStateCode(address.getStateProvinceCodeUnmasked());
            this.getDvPayeeDetail().setDisbVchrPayeeZipCode(address.getPostalCodeUnmasked());
            this.getDvPayeeDetail().setDisbVchrPayeeCountryCode(address.getCountryCodeUnmasked());
        } else {
            this.getDvPayeeDetail().setDisbVchrPayeeLine1Addr("");
            this.getDvPayeeDetail().setDisbVchrPayeeLine2Addr("");
            this.getDvPayeeDetail().setDisbVchrPayeeCityName("");
            this.getDvPayeeDetail().setDisbVchrPayeeStateCode("");
            this.getDvPayeeDetail().setDisbVchrPayeeZipCode("");
            this.getDvPayeeDetail().setDisbVchrPayeeCountryCode("");
        }
    }
    // "Is this payee an employee" = No
    if (employee.isActive()) {
        this.getDvPayeeDetail().setDisbVchrPayeeEmployeeCode(true);
    } else {
        this.getDvPayeeDetail().setDisbVchrPayeeEmployeeCode(false);
    }
    // I'm assuming that if a tax id type code other than 'TAX' is present, then the employee must be foreign
    for (String externalIdentifierTypeCode : employee.getExternalIdentifiers().keySet()) {
        if (KimConstants.PersonExternalIdentifierTypes.TAX.equals(externalIdentifierTypeCode)) {
            this.getDvPayeeDetail().setDisbVchrNonresidentPaymentCode(false);
        }
    }
    // Determine if employee is a research subject
    ParameterEvaluator researchPaymentReasonCodeEvaluator = /*REFACTORME*/
    SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(DisbursementVoucherDocument.class, FPParameterConstants.RESEARCH_PAYMENT_REASONS, this.getDvPayeeDetail().getDisbVchrPaymentReasonCode());
    if (researchPaymentReasonCodeEvaluator.evaluationSucceeds()) {
        if (getParameterService().parameterExists(DisbursementVoucherDocument.class, FPParameterConstants.RESEARCH_NON_VENDOR_PAY_LIMIT_AMOUNT)) {
            String researchPayLimit = getParameterService().getParameterValueAsString(DisbursementVoucherDocument.class, FPParameterConstants.RESEARCH_NON_VENDOR_PAY_LIMIT_AMOUNT);
            if (StringUtils.isNotBlank(researchPayLimit)) {
                KualiDecimal payLimit = new KualiDecimal(researchPayLimit);
                if (getDisbVchrCheckTotalAmount().isLessThan(payLimit)) {
                    this.getDvPayeeDetail().setDvPayeeSubjectPaymentCode(true);
                }
            }
        }
    }
    this.disbVchrPayeeTaxControlCode = "";
    this.disbVchrPayeeW9CompleteCode = true;
}
Also used : ParameterService(org.kuali.kfs.coreservice.framework.parameter.ParameterService) EntityAddress(org.kuali.kfs.kim.impl.identity.address.EntityAddress) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) ParameterEvaluator(org.kuali.kfs.core.api.parameter.ParameterEvaluator) ParameterEvaluatorService(org.kuali.kfs.core.api.parameter.ParameterEvaluatorService)

Example 18 with KualiDecimal

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

the class CapitalAssetInformationActionBase method capitalAccountingLineAmountDistributed.

/**
 * Checks to see if all the capital assets' distributed amount is the same as
 * the capital accounting lines (there is only one lines, of course).
 *
 * @param capitalAccountingLine
 * @param capitalAssetsInformation
 * @return true if accounting line amount equals to capital asset amount, else false.
 */
protected boolean capitalAccountingLineAmountDistributed(CapitalAccountingLines capitalAccountingLine, List<CapitalAssetInformation> capitalAssetsInformation) {
    KualiDecimal amountDistributed = KualiDecimal.ZERO;
    for (CapitalAssetInformation capitalAsset : capitalAssetsInformation) {
        amountDistributed = amountDistributed.add(getAccountingLineAmount(capitalAsset, capitalAccountingLine));
    }
    KualiDecimal capitalAccountingLineAmount = capitalAccountingLine.getAmount();
    return amountDistributed.equals(capitalAccountingLineAmount);
}
Also used : CapitalAssetInformation(org.kuali.kfs.fp.businessobject.CapitalAssetInformation) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal)

Example 19 with KualiDecimal

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

the class CapitalAssetInformationActionBase method getAccountingLineAmount.

/**
 * Returns the amount of the group accounting line from the capital asset information that
 * matches the capital accounting lines (only one lines, of course). If none exists, zero is returned.
 *
 * @param capitalAsset
 * @param capitalAccountingLine
 * @return accountLineAmount
 */
protected KualiDecimal getAccountingLineAmount(CapitalAssetInformation capitalAsset, CapitalAccountingLines capitalAccountingLine) {
    KualiDecimal accountLineAmount = KualiDecimal.ZERO;
    List<CapitalAssetAccountsGroupDetails> groupAccountLines = capitalAsset.getCapitalAssetAccountsGroupDetails();
    for (CapitalAssetAccountsGroupDetails groupAccountLine : groupAccountLines) {
        if (groupAccountLine.getCapitalAssetLineNumber().compareTo(capitalAsset.getCapitalAssetLineNumber()) == 0 && groupAccountLine.getSequenceNumber().compareTo(capitalAccountingLine.getSequenceNumber()) == 0 && groupAccountLine.getFinancialDocumentLineTypeCode().equals(KFSConstants.SOURCE.equals(capitalAccountingLine.getLineType()) ? KFSConstants.SOURCE_ACCT_LINE_TYPE_CODE : KFSConstants.TARGET_ACCT_LINE_TYPE_CODE) && groupAccountLine.getChartOfAccountsCode().equals(capitalAccountingLine.getChartOfAccountsCode()) && groupAccountLine.getAccountNumber().equals(capitalAccountingLine.getAccountNumber()) && groupAccountLine.getFinancialObjectCode().equals(capitalAccountingLine.getFinancialObjectCode())) {
            return groupAccountLine.getAmount();
        }
    }
    return accountLineAmount;
}
Also used : KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) CapitalAssetAccountsGroupDetails(org.kuali.kfs.fp.businessobject.CapitalAssetAccountsGroupDetails)

Example 20 with KualiDecimal

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

the class CapitalAssetInformationActionBase method adjustVarianceOnCapitalAssets.

/**
 * adjusts variances on capital assets where distribution method is set
 * as "distribute evenly" and capital asset amount is odd value.  Reduce the
 * capital asset amount line by 0.01 and then adjust the account amounts. Finally
 * any variance between capital accounting lines and capital assets is added
 * to the last capital asset and its accounting lines.
 *
 * @param capitalAssetInformation
 */
protected void adjustVarianceOnCapitalAssets(List<CapitalAssetInformation> capitalAssetInformation) {
    KualiDecimal adjustedCapitalAssetBalance = KualiDecimal.ZERO;
    CapitalAssetInformation lastCapitalAsset = null;
    for (CapitalAssetInformation capitalAsset : capitalAssetInformation) {
        // look at only cost equal assets...
        if (KFSConstants.CapitalAssets.DISTRIBUTE_COST_EQUALLY_CODE.equalsIgnoreCase(capitalAsset.getDistributionAmountCode())) {
            if (capitalAsset.getCapitalAssetLineAmount().mod(new KualiDecimal(2)) != KualiDecimal.ZERO) {
                capitalAsset.setCapitalAssetLineAmount(capitalAsset.getCapitalAssetLineAmount().subtract(new KualiDecimal(0.01)));
                adjustedCapitalAssetBalance = adjustedCapitalAssetBalance.add(new KualiDecimal(0.01));
                lastCapitalAsset = capitalAsset;
            }
        }
    }
    if (ObjectUtils.isNotNull(lastCapitalAsset) && adjustedCapitalAssetBalance.isNonZero()) {
        lastCapitalAsset.setCapitalAssetLineAmount(lastCapitalAsset.getCapitalAssetLineAmount().add(adjustedCapitalAssetBalance));
    }
}
Also used : CapitalAssetInformation(org.kuali.kfs.fp.businessobject.CapitalAssetInformation) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal)

Aggregations

KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)280 ArrayList (java.util.ArrayList)46 HashMap (java.util.HashMap)36 Test (org.junit.Test)28 AbstractKualiDecimal (org.kuali.kfs.core.api.util.type.AbstractKualiDecimal)21 BigDecimal (java.math.BigDecimal)18 List (java.util.List)18 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)15 Date (java.sql.Date)14 CapitalAssetInformation (org.kuali.kfs.fp.businessobject.CapitalAssetInformation)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 ConcurStandardAccountingExtractDetailLine (edu.cornell.kfs.concur.batch.businessobject.ConcurStandardAccountingExtractDetailLine)11 KualiInteger (org.kuali.kfs.core.api.util.type.KualiInteger)11 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)11 IOException (java.io.IOException)10 InvoiceDetailAccountObjectCode (org.kuali.kfs.module.ar.businessobject.InvoiceDetailAccountObjectCode)10 Map (java.util.Map)9 ParameterEvaluator (org.kuali.kfs.core.api.parameter.ParameterEvaluator)9 CapitalAccountingLines (org.kuali.kfs.fp.businessobject.CapitalAccountingLines)9 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)8