* Improved: Converted all FixedAssetMeter services from simple to entity-auto. * Improved: Added seca rule for creating maints from meter reading, earlier it was called inline while creating or updating FixedAssetMeter record. (OFBIZ-11611)
751 lines
46 KiB
XML
751 lines
46 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!--
|
|
Licensed to the Apache Software Foundation (ASF) under one
|
|
or more contributor license agreements. See the NOTICE file
|
|
distributed with this work for additional information
|
|
regarding copyright ownership. The ASF licenses this file
|
|
to you under the Apache License, Version 2.0 (the
|
|
"License"); you may not use this file except in compliance
|
|
with the License. You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing,
|
|
software distributed under the License is distributed on an
|
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
KIND, either express or implied. See the License for the
|
|
specific language governing permissions and limitations
|
|
under the License.
|
|
-->
|
|
|
|
<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
xmlns="http://ofbiz.apache.org/Simple-Method" xsi:schemaLocation="http://ofbiz.apache.org/Simple-Method http://ofbiz.apache.org/dtds/simple-methods.xsd">
|
|
|
|
<!-- create/update/delete FixedAssetMaint -->
|
|
<simple-method method-name="createFixedAssetMaint" short-description="create a FixedAssetMaint">
|
|
<make-value entity-name="FixedAssetMaint" value-field="newEntity"/>
|
|
<set-pk-fields map="parameters" value-field="newEntity"/>
|
|
<make-next-seq-id value-field="newEntity" seq-field-name="maintHistSeqId"/> <!-- this finds the next sub-sequence ID -->
|
|
<field-to-result field="newEntity.maintHistSeqId" result-name="maintHistSeqId"/>
|
|
<set-nonpk-fields map="parameters" value-field="newEntity"/>
|
|
<if-not-empty field="parameters.productMaintSeqId">
|
|
<entity-one entity-name="FixedAsset" value-field="fixedAsset"/>
|
|
<entity-one entity-name="ProductMaint" value-field="productMaint">
|
|
<field-map field-name="productId" from-field="fixedAsset.instanceOfProductId"/>
|
|
<field-map field-name="productMaintSeqId" from-field="parameters.productMaintSeqId"/>
|
|
</entity-one>
|
|
<set field="newEntity.productMaintTypeId" from-field="productMaint.productMaintTypeId"/>
|
|
</if-not-empty >
|
|
<if-not-empty field="productMaint.maintTemplateWorkEffortId">
|
|
<set field="maintTemplateWorkEffortId" from-field="productMaint.maintTemplateWorkEffortId"/>
|
|
<else>
|
|
<!-- User can still pick a Template workEffort -->
|
|
<set field="maintTemplateWorkEffortId" from-field="parameters.maintTemplateWorkEffortId"/>
|
|
</else>
|
|
</if-not-empty>
|
|
<if-not-empty field="maintTemplateWorkEffortId">
|
|
|
|
<set field="duplicateTemplateWorkEffortMap.oldWorkEffortId" from-field="maintTemplateWorkEffortId"/>
|
|
<sequenced-id sequence-name="WorkEffort" field="duplicateTemplateWorkEffortMap.workEffortId"/>
|
|
<set field="duplicateTemplateWorkEffortMap.duplicateWorkEffortAssocs" value="Y"/>
|
|
<set field="duplicateTemplateWorkEffortMap.duplicateWorkEffortNotes" value="Y"/>
|
|
<set field="duplicateTemplateWorkEffortMap.duplicateWorkEffortContents" value="Y"/>
|
|
<set field="duplicateTemplateWorkEffortMap.duplicateWorkEffortAssignmentRates" value="Y"/>
|
|
<call-service service-name="duplicateWorkEffort" in-map-name="duplicateTemplateWorkEffortMap"/>
|
|
<set field="newEntity.scheduleWorkEffortId" from-field="duplicateTemplateWorkEffortMap.workEffortId"/>
|
|
|
|
<else>
|
|
<!-- Create the WorkEffort -->
|
|
<!-- Maintenance WorkEffort entity -->
|
|
<entity-one entity-name="FixedAsset" value-field="fixedAsset"/>
|
|
<property-to-field field="workEffortName" resource="AccountingUiLabels" property="AccountingFixedAssetMaintWorkEffortName"/>
|
|
<set from-field="workEffortName" field="maintWorkEffortMap.workEffortName"/>
|
|
<set value="TASK" field="maintWorkEffortMap.workEffortTypeId"/>
|
|
<set value="WEPT_MAINTENANCE" field="maintWorkEffortMap.workEffortPurposeTypeId"/>
|
|
<set value="CAL_TENTATIVE" field="maintWorkEffortMap.currentStatusId"/>
|
|
<set from-field="userLogin.partyId" field="maintWorkEffortMap.quickAssignPartyId"/>
|
|
<set from-field="newEntity.fixedAssetId" field="maintWorkEffortMap.fixedAssetId"/>
|
|
<get-related-one to-value-field="productMaintType" relation-name="ProductMaintType" value-field="newEntity"/>
|
|
<set field="maintWorkEffortMap.description" from-field="productMaintType.description"/>
|
|
<!-- Optional dates supplied by Fixed Asset Calendar -->
|
|
<set from-field="parameters.estimatedStartDate" field="maintWorkEffortMap.estimatedStartDate"/>
|
|
<set from-field="parameters.estimatedCompletionDate" field="maintWorkEffortMap.estimatedCompletionDate"/>
|
|
<call-service service-name="createWorkEffort" in-map-name="maintWorkEffortMap">
|
|
<result-to-field result-name="workEffortId" field="newEntity.scheduleWorkEffortId"/>
|
|
</call-service>
|
|
</else>
|
|
</if-not-empty>
|
|
<create-value value-field="newEntity"/>
|
|
<check-errors/>
|
|
<set field="workEffortId" from-field="newEntity.scheduleWorkEffortId"/>
|
|
<call-simple-method method-name="autoAssignFixedAssetPartiesToMaintenance"/>
|
|
</simple-method>
|
|
<simple-method method-name="updateFixedAssetMaint" short-description="Update an existing FixedAsset Maintenance">
|
|
<entity-one entity-name="FixedAssetMaint" value-field="lookedUpValue"/>
|
|
<set field="oldStatusId" from-field="lookedUpValue.statusId"/>
|
|
<field-to-result field="oldStatusId"/>
|
|
<set-nonpk-fields map="parameters" value-field="lookedUpValue"/>
|
|
<if-not-empty field="parameters.productMaintSeqId">
|
|
<entity-one entity-name="FixedAsset" value-field="fixedAsset"/>
|
|
<entity-one entity-name="ProductMaint" value-field="productMaint">
|
|
<field-map field-name="productId" from-field="fixedAsset.instanceOfProductId"/>
|
|
<field-map field-name="productMaintSeqId" from-field="parameters.productMaintSeqId"/>
|
|
</entity-one>
|
|
<set field="lookedUpValue.productMaintTypeId" from-field="productMaint.productMaintTypeId"/>
|
|
</if-not-empty>
|
|
<store-value value-field="lookedUpValue"/>
|
|
<check-errors/>
|
|
<if>
|
|
<condition>
|
|
<and>
|
|
<if-compare field="lookedUpValue.statusId" value="FAM_COMPLETED" operator="equals"/>
|
|
<if-compare-field field="oldStatusId" to-field="lookedUpValue.statusId" operator="not-equals"/>
|
|
</and>
|
|
</condition>
|
|
<then>
|
|
<set field="workEffortId" from-field="lookedUpValue.scheduleWorkEffortId"/>
|
|
<entity-one entity-name="WorkEffort" value-field="workEffort"/>
|
|
<if>
|
|
<condition>
|
|
<and>
|
|
<not><if-empty field="workEffort"/></not>
|
|
<if-empty field="workEffort.actualCompletionDate"/>
|
|
<if-compare field="workEffort.currentStatusId" value="CAL_COMPLETED" operator="not-equals"/>
|
|
</and>
|
|
</condition>
|
|
<then>
|
|
<now-timestamp field="nowTimestamp"/>
|
|
<set field="updateWorkEffortCtx.workEffortId" from-field="workEffortId"/>
|
|
<set field="updateWorkEffortCtx.currentStatusId" value="CAL_ACCEPTED"/>
|
|
<call-service service-name="updateWorkEffort" in-map-name="updateWorkEffortCtx"/>
|
|
<check-errors/>
|
|
<set field="updateWorkEffortCtx.currentStatusId" value="CAL_COMPLETED"/>
|
|
<set field="updateWorkEffortCtx.actualCompletionDate" from-field="nowTimestamp"/>
|
|
<call-service service-name="updateWorkEffort" in-map-name="updateWorkEffortCtx"/>
|
|
<check-errors/>
|
|
<entity-condition entity-name="WorkEffortPartyAssignment" list="wepas" filter-by-date="true">
|
|
<condition-expr field-name="workEffortId" operator="equals" from-field="workEffortId"/>
|
|
</entity-condition>
|
|
<iterate list="wepas" entry="wepa">
|
|
<set field="wepa.thruDate" from-field="nowTimestamp"/>
|
|
<store-value value-field="wepa"/>
|
|
<check-errors/>
|
|
</iterate>
|
|
</then>
|
|
</if>
|
|
</then>
|
|
</if>
|
|
</simple-method>
|
|
<simple-method method-name="createMaintsFromMeterReading" short-description="Create Fixed Asset Maintenances From A Meter Reading">
|
|
<set field="meterValue" from-field="parameters"/>
|
|
<if-not-empty field="meterValue.maintHistSeqId">
|
|
<return/>
|
|
</if-not-empty>
|
|
<entity-one entity-name="FixedAsset" value-field="fixedAssetValue"/>
|
|
<if-empty field="fixedAssetValue.instanceOfProductId">
|
|
<return/>
|
|
</if-empty>
|
|
<entity-and entity-name="ProductMaint" list="productMaintList">
|
|
<field-map field-name="productId" from-field="fixedAssetValue.instanceOfProductId"/>
|
|
<field-map field-name="intervalMeterTypeId" from-field="meterValue.productMeterTypeId"/>
|
|
</entity-and>
|
|
<iterate list="productMaintList" entry="productMaintValue">
|
|
<set field="repeatCount" from-field="productMaintValue.repeatCount" default-value="0" type="Long"/>
|
|
<entity-condition entity-name="FixedAssetMaint" list="maintList">
|
|
<condition-list combine="and">
|
|
<condition-expr field-name="fixedAssetId" operator="equals" from-field="fixedAssetValue.fixedAssetId"/>
|
|
<condition-expr field-name="productMaintTypeId" operator="equals" from-field="productMaintValue.productMaintTypeId"/>
|
|
<condition-expr field-name="intervalMeterTypeId" operator="equals" from-field="productMaintValue.intervalMeterTypeId"/>
|
|
<condition-expr field-name="statusId" operator="not-equals" value="FAM_CANCELLED"/>
|
|
</condition-list>
|
|
</entity-condition>
|
|
<set field="listSize" value="0" type="Long"/>
|
|
<if-not-empty field="maintList">
|
|
<set field="listSize" value="${groovy:maintList.size()}" type="Long"/>
|
|
</if-not-empty>
|
|
<set field="maxIntervalQty" value="0" type="BigDecimal"/>
|
|
<iterate list="maintList" entry="maintValue">
|
|
<if-not-empty field="maintValue.intervalQuantity">
|
|
<if-compare-field field="maintValue.intervalQuantity" operator="greater" to-field="maxIntervalQty" type="BigDecimal">
|
|
<set field="maxIntervalQty" from-field="maintValue.intervalQuantity" type="BigDecimal"/>
|
|
</if-compare-field>
|
|
</if-not-empty>
|
|
</iterate>
|
|
<set field="nextIntervalQty" value="${groovy:maxIntervalQty.add(productMaintValue.getBigDecimal("intervalQuantity"));}" type="BigDecimal"/>
|
|
<if-not-empty field="meterValue.meterValue">
|
|
<if-compare-field field="nextIntervalQty" operator="less-equals" to-field="meterValue.meterValue" type="BigDecimal">
|
|
<set field="maintDue" value="false"/>
|
|
<if-compare field="repeatCount" operator="greater" value="0" type="Long">
|
|
<if-compare-field field="listSize" operator="less" to-field="repeatCount" type="Long">
|
|
<set field="maintDue" value="true"/>
|
|
</if-compare-field>
|
|
<else>
|
|
<set field="maintDue" value="true"/>
|
|
</else>
|
|
</if-compare>
|
|
<if-compare field="maintDue" operator="equals" value="true">
|
|
<set-service-fields service-name="createFixedAssetMaint" map="productMaintValue" to-map="createMaintCxt"/>
|
|
<set field="createMaintCxt.fixedAssetId" from-field="fixedAssetValue.fixedAssetId"/>
|
|
<set field="createMaintCxt.intervalQuantity" from-field="meterValue.meterValue"/>
|
|
<set field="createMaintCxt.statusId" value="FAM_CREATED"/>
|
|
<call-service service-name="createFixedAssetMaint" in-map-name="createMaintCxt"/>
|
|
<check-errors/>
|
|
</if-compare>
|
|
</if-compare-field>
|
|
</if-not-empty>
|
|
</iterate>
|
|
</simple-method>
|
|
<simple-method method-name="createMaintsFromTimeInterval" short-description="Create Fixed Asset Maintenances From A Product Maint Time Interval">
|
|
<now-timestamp field="nowTimestamp"/>
|
|
<entity-condition entity-name="FixedAsset" list="fixedAssets">
|
|
<condition-list combine="and">
|
|
<condition-expr field-name="instanceOfProductId" operator="not-equals" from-field="null"/>
|
|
<condition-expr field-name="actualEndOfLife" operator="equals" from-field="null"/>
|
|
</condition-list>
|
|
</entity-condition>
|
|
<iterate list="fixedAssets" entry="fixedAsset">
|
|
<entity-condition entity-name="ProductMaint" list="productMaints">
|
|
<condition-list combine="and">
|
|
<condition-expr field-name="productId" from-field="fixedAsset.instanceOfProductId"/>
|
|
<condition-expr field-name="intervalUomId" operator="like" value="TF_%"/>
|
|
</condition-list>
|
|
</entity-condition>
|
|
<iterate list="productMaints" entry="productMaint">
|
|
<set field="repeatCount" from-field="productMaint.repeatCount" default-value="0" type="Long"/>
|
|
<entity-condition entity-name="FixedAssetMaintWorkEffort" list="maintList">
|
|
<condition-list combine="and">
|
|
<condition-expr field-name="fixedAssetId" operator="equals" from-field="fixedAsset.fixedAssetId"/>
|
|
<condition-expr field-name="productMaintTypeId" operator="equals" from-field="productMaint.productMaintTypeId"/>
|
|
<condition-expr field-name="intervalUomId" operator="equals" from-field="productMaint.intervalUomId"/>
|
|
<condition-expr field-name="statusId" operator="not-equals" value="FAM_CANCELLED"/>
|
|
</condition-list>
|
|
<order-by field-name="maintHistSeqId"/>
|
|
</entity-condition>
|
|
<set field="intervalQuantity" from-field="productMaint.intervalQuantity" default-value="0" type="Integer"/>
|
|
<if-compare field="productMaint.intervalUomId" operator="equals" value="TF_day">
|
|
<set-calendar field="compareDate" from-field="nowTimestamp" days="-${intervalQuantity}"/>
|
|
<else>
|
|
<if-compare field="productMaint.intervalUomId" operator="equals" value="TF_mon">
|
|
<set-calendar field="compareDate" from-field="nowTimestamp" months="-${intervalQuantity}"/>
|
|
<else>
|
|
<if-compare field="productMaint.intervalUomId" operator="equals" value="TF_yr">
|
|
<set-calendar field="compareDate" from-field="nowTimestamp" years="-${intervalQuantity}"/>
|
|
</if-compare>
|
|
</else>
|
|
</if-compare>
|
|
</else>
|
|
</if-compare>
|
|
<if-not-empty field="compareDate">
|
|
<set field="listSize" value="0" type="Long"/>
|
|
<if-not-empty field="maintList">
|
|
<set field="listSize" value="${groovy:maintList.size()}" type="Long"/>
|
|
</if-not-empty>
|
|
<set field="lastSvcLong" value="0" type="Long"/>
|
|
<set field="lastSvcDate" from-field="lastSvcLong" type="Timestamp"/>
|
|
<iterate list="maintList" entry="maintValue">
|
|
<set field="lastSvcDate" from-field="maintValue.actualCompletionDate" set-if-null="true"/>
|
|
</iterate>
|
|
<if-not-empty field="lastSvcDate">
|
|
<if-compare-field field="lastSvcDate" operator="less" to-field="compareDate" type="Timestamp">
|
|
<set field="maintDue" value="false"/>
|
|
<if-compare field="repeatCount" operator="greater" value="0" type="Long">
|
|
<if-compare-field field="listSize" operator="less" to-field="repeatCount" type="Long">
|
|
<set field="maintDue" value="true"/>
|
|
</if-compare-field>
|
|
<else>
|
|
<set field="maintDue" value="true"/>
|
|
</else>
|
|
</if-compare>
|
|
<if-compare field="maintDue" operator="equals" value="true">
|
|
<set-service-fields service-name="createFixedAssetMaint" map="productMaint" to-map="createMaintCxt"/>
|
|
<set field="createMaintCxt.fixedAssetId" from-field="fixedAsset.fixedAssetId"/>
|
|
<set field="createMaintCxt.statusId" value="FAM_CREATED"/>
|
|
<call-service service-name="createFixedAssetMaint" in-map-name="createMaintCxt"/>
|
|
<check-errors/>
|
|
</if-compare>
|
|
</if-compare-field>
|
|
</if-not-empty>
|
|
</if-not-empty>
|
|
</iterate>
|
|
</iterate>
|
|
</simple-method>
|
|
|
|
<!-- create/update/delete FixedAssetMaintOrder -->
|
|
<simple-method method-name="createFixedAssetMaintOrder" short-description="Create a FixedAsset Maintenance Order">
|
|
<!-- Check, should exist orderId and orderItemId -->
|
|
<entity-one entity-name="OrderHeader" value-field="lookedUpValue"/>
|
|
<if-empty field="lookedUpValue">
|
|
<set field="orderId" from-field="parameters.orderId"/>
|
|
<add-error>
|
|
<fail-property resource="AccountingUiLabels" property="AccountingOrderWithIdNotFound"/>
|
|
</add-error>
|
|
</if-empty>
|
|
<check-errors/>
|
|
|
|
<!-- Check if user has not passed in orderItemSeqId then get list of OrderItems from database and default to first item -->
|
|
<if-empty field="parameters.orderItemSeqId">
|
|
<entity-and entity-name="OrderItem" list="orderItems">
|
|
<field-map field-name="orderId" from-field="parameters.orderId"/>
|
|
</entity-and>
|
|
<if-not-empty field="orderItems">
|
|
<set field="orderItem" from-field="orderItems[0]"/>
|
|
<if-not-empty field="orderItem">
|
|
<set field="parameters.orderItemSeqId" from-field="orderItem.orderItemSeqId"/>
|
|
</if-not-empty>
|
|
</if-not-empty>
|
|
|
|
<else>
|
|
<!-- Check, should exist orderId and orderItemId -->
|
|
<entity-one entity-name="OrderItem" value-field="lookedUpValue"/>
|
|
<if-empty field="lookedUpValue">
|
|
<set field="orderItemSeqId" from-field="parameters.orderItemSeqId"/>
|
|
<add-error>
|
|
<fail-property resource="AccountingUiLabels" property="AccountingOrderItemWithIdNotFound"/>
|
|
</add-error>
|
|
</if-empty>
|
|
</else>
|
|
</if-empty>
|
|
<check-errors/>
|
|
|
|
<make-value entity-name="FixedAssetMaintOrder" value-field="newEntity"/>
|
|
<set-pk-fields map="parameters" value-field="newEntity"/>
|
|
<set-nonpk-fields map="parameters" value-field="newEntity"/>
|
|
<create-value value-field="newEntity"/>
|
|
</simple-method>
|
|
|
|
<simple-method method-name="autoAssignFixedAssetPartiesToMaintenance" login-required="true"
|
|
short-description="Auto-assign Fixed Asset Parties to a Fixed Asset Maintenance">
|
|
<if-empty field="maintHistSeqId">
|
|
<set field="maintHistSeqId" from-field="parameters.maintHistSeqId"/>
|
|
</if-empty>
|
|
<if-empty field="fixedAssetId">
|
|
<set field="fixedAssetId" from-field="parameters.fixedAssetId"/>
|
|
</if-empty>
|
|
<entity-one entity-name="FixedAssetMaint" value-field="maintValue"/>
|
|
<if-empty field="workEffortId">
|
|
<set field="workEffortId" from-field="maintValue.scheduleWorkEffortId"/>
|
|
</if-empty>
|
|
<entity-and entity-name="PartyFixedAssetAssignAndRole" list="assignedParties" filter-by-date="true">
|
|
<field-map field-name="fixedAssetId" from-field="fixedAssetId"/>
|
|
<field-map field-name="parentTypeId" value="FAM_ASSIGNEE"/>
|
|
</entity-and>
|
|
<iterate list="assignedParties" entry="assignedParty">
|
|
<set field="assignPartyCtx.partyId" from-field="assignedParty.partyId"/>
|
|
<set field="assignPartyCtx.roleTypeId" from-field="assignedParty.roleTypeId"/>
|
|
<set field="assignPartyCtx.workEffortId" from-field="workEffortId"/>
|
|
<set field="assignPartyCtx.statusId" value="PRTYASGN_ASSIGNED"/>
|
|
<call-service service-name="assignPartyToWorkEffort" in-map-name="assignPartyCtx"/>
|
|
<check-errors/>
|
|
</iterate>
|
|
</simple-method>
|
|
|
|
<!-- ============== Fixed Asset Depreciation methods ============== -->
|
|
<simple-method method-name="straightLineDepreciation" short-description="Calculate straight line depreciation to Fixed Asset[ (PC-SV)/expLife ]">
|
|
<set field="expEndOfLifeYear" from-field="parameters.expEndOfLifeYear" type="Integer"/>
|
|
<set field="assetAcquiredYear" from-field="parameters.assetAcquiredYear" type="Integer"/>
|
|
<set field="purchaseCost" from-field="parameters.purchaseCost"/>
|
|
<set field="salvageValue" from-field="parameters.salvageValue"/>
|
|
<call-object-method obj-field="parameters.usageYears" method-name="intValue" ret-field="intUsageYears"/>
|
|
|
|
<!-- Past depreciation based on standard formula -->
|
|
<set field="depreciationTotal" value="0.0" type="BigDecimal"/>
|
|
<if>
|
|
<condition>
|
|
<and>
|
|
<if-compare field="intUsageYears" operator="greater" value="0.0" type="BigDecimal"/>
|
|
<not><if-empty field="parameters.fixedAssetId"/></not>
|
|
</and>
|
|
</condition>
|
|
<then>
|
|
<set field="depreciation" value="0.0" type="BigDecimal"/>
|
|
<!--FORMULA : depreciation = (purchaseCost - salvageValue) / (expectedEndOfLife - dateAcquired) -->
|
|
<calculate field="numberOfYears">
|
|
<calcop operator="subtract">
|
|
<calcop operator="get" field="expEndOfLifeYear"/>
|
|
<calcop operator="get" field="assetAcquiredYear"/>
|
|
</calcop>
|
|
</calculate>
|
|
<if-compare field="numberOfYears" operator="greater" value="0.0" type="BigDecimal">
|
|
<calculate field="depreciation" decimal-scale="2">
|
|
<calcop operator="divide">
|
|
<calcop operator="subtract">
|
|
<calcop operator="get" field="purchaseCost"/>
|
|
<calcop operator="get" field="salvageValue"/>
|
|
</calcop>
|
|
<calcop operator="get" field="numberOfYears"/>
|
|
</calcop>
|
|
</calculate>
|
|
</if-compare>
|
|
<set field="depreciationYear" from-field="assetAcquiredYear" type="BigDecimal"/>
|
|
<if-compare-field field="numberOfYears" operator="less" to-field="intUsageYears" type="BigDecimal">
|
|
<set field="intUsageYears" from-field="numberOfYears" type="BigDecimal"/>
|
|
</if-compare-field>
|
|
<loop count="${intUsageYears}">
|
|
<calculate field="purchaseCost">
|
|
<calcop operator="subtract">
|
|
<calcop operator="get" field="purchaseCost"/>
|
|
<calcop operator="get" field="depreciation"/>
|
|
</calcop>
|
|
</calculate>
|
|
<calculate field="depreciationTotal">
|
|
<calcop operator="add">
|
|
<calcop operator="get" field="depreciationTotal"/>
|
|
<calcop operator="get" field="depreciation"/>
|
|
</calcop>
|
|
</calculate>
|
|
<field-to-list list="assetDepreciationTillDate" field="depreciation"/>
|
|
<field-to-list list="assetNBVAfterDepreciation" field="purchaseCost"/>
|
|
<clear-field field="assetDepreciationInfo"/>
|
|
<set field="assetDepreciationInfo.year" from-field="depreciationYear"/>
|
|
<set field="assetDepreciationInfo.depreciation" from-field="depreciation"/>
|
|
<set field="assetDepreciationInfo.depreciationTotal" from-field="depreciationTotal"/>
|
|
<set field="assetDepreciationInfo.nbv" from-field="purchaseCost"/>
|
|
<field-to-list list="assetDepreciationInfoList" field="assetDepreciationInfo"/>
|
|
<calculate field="depreciationYear">
|
|
<calcop operator="add">
|
|
<calcop operator="get" field="depreciationYear"/>
|
|
<number value="1"/>
|
|
</calcop>
|
|
</calculate>
|
|
</loop>
|
|
</then>
|
|
</if>
|
|
<if-empty field="assetDepreciationTillDate">
|
|
<set field="depreciation" value="0.0" type="BigDecimal"/>
|
|
<field-to-list list="assetDepreciationTillDate" field="depreciation"/>
|
|
<field-to-list list="assetNBVAfterDepreciation" field="purchaseCost"/>
|
|
<set field="assetDepreciationInfo.year" from-field="assetAcquiredYear"/>
|
|
<set field="assetDepreciationInfo.depreciation" from-field="depreciation"/>
|
|
<set field="assetDepreciationInfo.depreciationTotal" from-field="depreciationTotal"/>
|
|
<set field="assetDepreciationInfo.nbv" from-field="purchaseCost"/>
|
|
<field-to-list list="assetDepreciationInfoList" field="assetDepreciationInfo"/>
|
|
</if-empty>
|
|
<log level="info" message="Using straight line formula depreciation calculated for fixedAsset (${parameters.fixedAssetId}) is ${depreciation}"/>
|
|
<field-to-result field="assetDepreciationTillDate"/>
|
|
<field-to-result field="assetNBVAfterDepreciation"/>
|
|
<field-to-result field="assetDepreciationInfoList"/>
|
|
|
|
<!-- Next depreciation based on actual depreciation history -->
|
|
<set field="nextDepreciationAmount" value="0.0" type="BigDecimal"/>
|
|
<if>
|
|
<condition>
|
|
<not><if-empty field="parameters.fixedAssetId"/></not>
|
|
</condition>
|
|
<then>
|
|
<entity-one entity-name="FixedAsset" value-field="fixedAsset"/>
|
|
<!--FORMULA : depreciation = (purchaseCost - salvageValue - pastDepreciations) / remainingYears -->
|
|
<calculate field="remainingYears">
|
|
<calcop operator="subtract">
|
|
<calcop operator="get" field="expEndOfLifeYear"/>
|
|
<calcop operator="get" field="assetAcquiredYear"/>
|
|
<calcop operator="get" field="intUsageYears"/>
|
|
</calcop>
|
|
</calculate>
|
|
<if-compare field="remainingYears" operator="greater" value="0.0" type="BigDecimal">
|
|
<calculate field="nextDepreciationAmount" decimal-scale="2">
|
|
<calcop operator="divide">
|
|
<calcop operator="subtract">
|
|
<calcop operator="get" field="fixedAsset.purchaseCost"/>
|
|
<calcop operator="get" field="salvageValue"/>
|
|
<calcop operator="get" field="fixedAsset.depreciation"/>
|
|
</calcop>
|
|
<calcop operator="get" field="remainingYears"/>
|
|
</calcop>
|
|
</calculate>
|
|
</if-compare>
|
|
</then>
|
|
</if>
|
|
<field-to-result field="nextDepreciationAmount"/>
|
|
<calculate field="plannedPastDepreciationTotal">
|
|
<calcop operator="subtract">
|
|
<calcop operator="get" field="depreciationTotal"/>
|
|
<calcop operator="get" field="fixedAsset.depreciation"/>
|
|
</calcop>
|
|
</calculate>
|
|
<field-to-result field="plannedPastDepreciationTotal"/>
|
|
</simple-method>
|
|
|
|
<simple-method method-name="doubleDecliningBalanceDepreciation" short-description="Calculate double declining balance depreciation to Fixed Asset">
|
|
<set field="expEndOfLifeYear" from-field="parameters.expEndOfLifeYear" type="Integer"/>
|
|
<set field="assetAcquiredYear" from-field="parameters.assetAcquiredYear" type="Integer"/>
|
|
<set field="purchaseCost" from-field="parameters.purchaseCost"/>
|
|
<set field="salvageValue" from-field="parameters.salvageValue"/>
|
|
<call-object-method obj-field="parameters.usageYears" method-name="intValue" ret-field="intUsageYears"/>
|
|
<!-- Next depreciation based on actual depreciation history -->
|
|
<set field="nextDepreciationAmount" value="0.0" type="BigDecimal"/>
|
|
<if>
|
|
<condition>
|
|
<not><if-empty field="parameters.fixedAssetId"/></not>
|
|
</condition>
|
|
<then>
|
|
<entity-one entity-name="FixedAsset" value-field="fixedAsset"/>
|
|
<!--FORMULA : depreciation = 2 * (purchaseCost - salvageValue - pastDepreciations) / remainingYears -->
|
|
<calculate field="remainingYears">
|
|
<calcop operator="subtract">
|
|
<calcop operator="get" field="expEndOfLifeYear"/>
|
|
<calcop operator="get" field="assetAcquiredYear"/>
|
|
<calcop operator="get" field="intUsageYears"/>
|
|
</calcop>
|
|
</calculate>
|
|
<if-compare field="remainingYears" operator="greater" value="0.0" type="BigDecimal">
|
|
<calculate field="nextDepreciationAmount" decimal-scale="2">
|
|
<calcop operator="multiply">
|
|
<calcop operator="divide">
|
|
<calcop operator="subtract">
|
|
<calcop operator="get" field="fixedAsset.purchaseCost"/>
|
|
<calcop operator="get" field="salvageValue"/>
|
|
<calcop operator="get" field="fixedAsset.depreciation"/>
|
|
</calcop>
|
|
<calcop operator="get" field="remainingYears"/>
|
|
</calcop>
|
|
<number value="2"/>
|
|
</calcop>
|
|
</calculate>
|
|
</if-compare>
|
|
</then>
|
|
</if>
|
|
<field-to-result field="nextDepreciationAmount"/>
|
|
|
|
<!-- Past depreciation based on standard formula -->
|
|
<set field="depreciationTotal" value="0.0" type="BigDecimal"/>
|
|
<if>
|
|
<condition>
|
|
<and>
|
|
<if-compare field="intUsageYears" operator="greater" value="0.0" type="BigDecimal"/>
|
|
<not><if-empty field="parameters.fixedAssetId"/></not>
|
|
</and>
|
|
</condition>
|
|
<then>
|
|
<set field="depreciationYear" from-field="assetAcquiredYear" type="BigDecimal"/>
|
|
<loop count="${intUsageYears}">
|
|
<set field="depreciation" value="0.0" type="BigDecimal"/>
|
|
<!--FORMULA : depreciation = (NBV - salvageValue) * 2 / (expectedEndOfLife - dateAcquired) -->
|
|
<calculate field="numberOfYears">
|
|
<calcop operator="subtract">
|
|
<calcop operator="get" field="expEndOfLifeYear"/>
|
|
<calcop operator="get" field="assetAcquiredYear"/>
|
|
</calcop>
|
|
</calculate>
|
|
<if-compare field="numberOfYears" operator="greater" value="0.0" type="BigDecimal">
|
|
<calculate field="depreciation" decimal-scale="2">
|
|
<calcop operator="multiply">
|
|
<calcop operator="divide">
|
|
<calcop operator="subtract">
|
|
<calcop operator="get" field="purchaseCost"/>
|
|
<calcop operator="get" field="salvageValue"/>
|
|
</calcop>
|
|
<calcop operator="get" field="numberOfYears"/>
|
|
</calcop>
|
|
<number value="2"/>
|
|
</calcop>
|
|
</calculate>
|
|
</if-compare>
|
|
<calculate field="assetAcquiredYear">
|
|
<calcop operator="add">
|
|
<calcop operator="get" field="assetAcquiredYear"/>
|
|
<number value="1"/>
|
|
</calcop>
|
|
</calculate>
|
|
<calculate field="purchaseCost">
|
|
<calcop operator="subtract">
|
|
<calcop operator="get" field="purchaseCost"/>
|
|
<calcop operator="get" field="depreciation"/>
|
|
</calcop>
|
|
</calculate>
|
|
<calculate field="depreciationTotal">
|
|
<calcop operator="add">
|
|
<calcop operator="get" field="depreciationTotal"/>
|
|
<calcop operator="get" field="depreciation"/>
|
|
</calcop>
|
|
</calculate>
|
|
<field-to-list list="assetDepreciationTillDate" field="depreciation"/>
|
|
<field-to-list list="assetNBVAfterDepreciation" field="purchaseCost"/>
|
|
<clear-field field="assetDepreciationInfo"/>
|
|
<set field="assetDepreciationInfo.year" from-field="depreciationYear"/>
|
|
<set field="assetDepreciationInfo.depreciation" from-field="depreciation"/>
|
|
<set field="assetDepreciationInfo.depreciationTotal" from-field="depreciationTotal"/>
|
|
<set field="assetDepreciationInfo.nbv" from-field="purchaseCost"/>
|
|
<field-to-list list="assetDepreciationInfoList" field="assetDepreciationInfo"/>
|
|
<calculate field="depreciationYear">
|
|
<calcop operator="add">
|
|
<calcop operator="get" field="depreciationYear"/>
|
|
<number value="1"/>
|
|
</calcop>
|
|
</calculate>
|
|
</loop>
|
|
</then>
|
|
</if>
|
|
<if-empty field="assetDepreciationTillDate">
|
|
<set field="depreciation" value="0.0" type="BigDecimal"/>
|
|
<field-to-list list="assetDepreciationTillDate" field="depreciation"/>
|
|
<field-to-list list="assetNBVAfterDepreciation" field="purchaseCost"/>
|
|
<set field="assetDepreciationInfo.year" from-field="assetAcquiredYear"/>
|
|
<set field="assetDepreciationInfo.depreciation" from-field="depreciation"/>
|
|
<set field="assetDepreciationInfo.depreciationTotal" from-field="depreciationTotal"/>
|
|
<set field="assetDepreciationInfo.nbv" from-field="purchaseCost"/>
|
|
<field-to-list list="assetDepreciationInfoList" field="assetDepreciationInfo"/>
|
|
</if-empty>
|
|
<log level="info" message="Using double decline formula depreciation calculated for fixedAsset (${parameters.fixedAssetId}) is ${assetDepreciationTillDate}"/>
|
|
<field-to-result field="assetDepreciationTillDate"/>
|
|
<field-to-result field="assetNBVAfterDepreciation"/>
|
|
<field-to-result field="assetDepreciationInfoList"/>
|
|
<field-to-result field="depreciationTotal" result-name="plannedPastDepreciationTotal"/>
|
|
</simple-method>
|
|
|
|
<simple-method method-name="calculateFixedAssetDepreciation" short-description="Service to calculate the yearly depreciation from dateAcquired year to current financial year">
|
|
<entity-one entity-name="FixedAsset" value-field="fixedAsset"/>
|
|
<if-empty field="fixedAsset">
|
|
<add-error>
|
|
<fail-property resource="ManufacturingUiLabels" property="ManufacturingFixedAssetNotExist"/>
|
|
</add-error>
|
|
<check-errors/>
|
|
</if-empty>
|
|
<set field="startIndex" value="0" type="Integer"/>
|
|
<set field="endIndex" value="4" type="Integer"/>
|
|
|
|
<!-- Extract asset end of life year from field expectedEndOfLife -->
|
|
<if-not-empty field="fixedAsset.expectedEndOfLife">
|
|
<set field="expectedEndOfLife" from-field="fixedAsset.expectedEndOfLife"/>
|
|
<to-string field="expectedEndOfLife"/>
|
|
<call-object-method method-name="substring" obj-field="expectedEndOfLife" ret-field="expEndOfLifeYear">
|
|
<field field="startIndex" type="int"/>
|
|
<field field="endIndex" type="int"/>
|
|
</call-object-method>
|
|
<else>
|
|
<property-to-field resource="AccountingUiLabels" property="AccountingExpEndOfLifeIsEmpty" field="successMessageList[]"/>
|
|
<return/>
|
|
</else>
|
|
</if-not-empty>
|
|
|
|
<!-- Extract asset acquired year from field dateAcquired -->
|
|
<if-not-empty field="fixedAsset.dateAcquired">
|
|
<set field="dateAcquired" from-field="fixedAsset.dateAcquired"/>
|
|
<to-string field="dateAcquired"/>
|
|
<call-object-method method-name="substring" obj-field="dateAcquired" ret-field="assetAcquiredYear">
|
|
<field field="startIndex" type="int"/>
|
|
<field field="endIndex" type="int"/>
|
|
</call-object-method>
|
|
<else>
|
|
<property-to-field resource="AccountingUiLabels" property="AccountingDateAcquiredIsEmpty" field="successMessageList[]"/>
|
|
<return/>
|
|
</else>
|
|
</if-not-empty>
|
|
|
|
<!-- if any asset's salvage value is empty then set it by 0 -->
|
|
<if-empty field="fixedAsset.salvageValue">
|
|
<set field="salvageValue" value="0.0" type="BigDecimal"/>
|
|
<else>
|
|
<set field="salvageValue" from-field="fixedAsset.salvageValue"/>
|
|
</else>
|
|
</if-empty>
|
|
|
|
<!-- Get running year -->
|
|
<now-timestamp field="nowTimestamp"/>
|
|
<to-string field="nowTimestamp"/>
|
|
<call-object-method method-name="substring" obj-field="nowTimestamp" ret-field="currentYear">
|
|
<field field="startIndex" type="int"/>
|
|
<field field="endIndex" type="int"/>
|
|
</call-object-method>
|
|
|
|
<!-- Calculate asset's total run in years -->
|
|
<calculate field="usageYears" type="Integer">
|
|
<calcop operator="subtract">
|
|
<calcop operator="get" field="currentYear"/>
|
|
<calcop operator="get" field="assetAcquiredYear"/>
|
|
</calcop>
|
|
</calculate>
|
|
|
|
<entity-and entity-name="FixedAssetDepMethod" list="fixedAssetDepMethods" filter-by-date="true">
|
|
<field-map field-name="fixedAssetId" from-field="parameters.fixedAssetId"/>
|
|
</entity-and>
|
|
<if-not-empty field="fixedAssetDepMethods">
|
|
<first-from-list list="fixedAssetDepMethods" entry="fixedAssetDepMethod"/>
|
|
<get-related-one relation-name="CustomMethod" value-field="fixedAssetDepMethod" to-value-field="customMethod"/>
|
|
<log level="info" message="Depreciation service name for the FixedAsset ${parameters.fixedAssetId} is ${customMethod.customMethodName}"/>
|
|
|
|
<set field="serviceInMap.fixedAssetId" from-field="parameters.fixedAssetId"/>
|
|
<set field="serviceInMap.expEndOfLifeYear" from-field="expEndOfLifeYear" type="Integer"/>
|
|
<set field="serviceInMap.assetAcquiredYear" from-field="assetAcquiredYear" type="Integer"/>
|
|
<set field="serviceInMap.purchaseCost" from-field="fixedAsset.purchaseCost"/>
|
|
<set field="serviceInMap.salvageValue" from-field="salvageValue"/>
|
|
<set field="serviceInMap.usageYears" from-field="usageYears" type="Integer"/>
|
|
<call-service service-name="${customMethod.customMethodName}" in-map-name="serviceInMap">
|
|
<result-to-field result-name="assetDepreciationTillDate"/>
|
|
<result-to-field result-name="assetNBVAfterDepreciation"/>
|
|
<result-to-field result-name="assetDepreciationInfoList"/>
|
|
<result-to-field result-name="nextDepreciationAmount"/>
|
|
<result-to-field result-name="plannedPastDepreciationTotal"/>
|
|
</call-service>
|
|
<log level="info" message="Asset's depreciation calculated till date are ${assetDepreciationTillDate}"/>
|
|
<log level="info" message="Asset's Net Book Values (NBV) from acquired date after deducting depreciation are ${assetNBVAfterDepreciation}"/>
|
|
<field-to-result field="assetDepreciationTillDate"/>
|
|
<field-to-result field="assetNBVAfterDepreciation"/>
|
|
<field-to-result field="assetDepreciationInfoList"/>
|
|
<field-to-result field="nextDepreciationAmount"/>
|
|
<field-to-result field="plannedPastDepreciationTotal"/>
|
|
<else>
|
|
<property-to-field resource="AccountingUiLabels" property="AccountingFixedAssetDepreciationMethodNotFound" field="successMessageList[]"/>
|
|
<return/>
|
|
</else>
|
|
</if-not-empty>
|
|
</simple-method>
|
|
|
|
<simple-method method-name="checkUpdateFixedAssetDepreciation" login-required="true"
|
|
short-description="If the accounting transaction is a depreciation transaction for a fixed asset, update the depreciation amount in the FixedAsset entity.">
|
|
<entity-one entity-name="AcctgTrans" value-field="acctgTrans"/>
|
|
<if>
|
|
<condition>
|
|
<and>
|
|
<if-compare field="acctgTrans.acctgTransTypeId" operator="equals" value="DEPRECIATION"/>
|
|
<not><if-empty field="acctgTrans.fixedAssetId"/></not>
|
|
</and>
|
|
</condition>
|
|
<then>
|
|
<get-related-one relation-name="FixedAsset" value-field="acctgTrans" to-value-field="fixedAsset"/>
|
|
<set field="creditCondition.debitCreditFlag" value="C"/>
|
|
<get-related relation-name="AcctgTransEntry" value-field="acctgTrans" list="creditTransactions" map="creditCondition"/>
|
|
<set field="depreciation" value="0.0" type="BigDecimal"/>
|
|
<iterate list="creditTransactions" entry="creditTransaction">
|
|
<if-empty field="fixedAsset.purchaseCostUomId">
|
|
<log level="warning" message="Found empty purchaseCostUomId for FixedAsset [${fixedAsset.fixedAssetId}]: setting it to ${creditTransaction.currencyUomId} to match the one used in the gl."/>
|
|
<set field="fixedAsset.purchaseCostUomId" from-field="creditTransaction.currencyUomId"/>
|
|
<store-value value-field="fixedAsset"/>
|
|
</if-empty>
|
|
<if-compare-field field="fixedAsset.purchaseCostUomId" operator="equals" to-field="creditTransaction.currencyUomId">
|
|
<calculate field="depreciation">
|
|
<calcop operator="add">
|
|
<calcop operator="get" field="depreciation"/>
|
|
<calcop operator="get" field="creditTransaction.amount"/>
|
|
</calcop>
|
|
</calculate>
|
|
<else>
|
|
<if-compare-field field="fixedAsset.purchaseCostUomId" operator="equals" to-field="creditTransaction.origCurrencyUomId">
|
|
<calculate field="depreciation">
|
|
<calcop operator="add">
|
|
<calcop operator="get" field="depreciation"/>
|
|
<calcop operator="get" field="creditTransaction.origAmount"/>
|
|
</calcop>
|
|
</calculate>
|
|
<else>
|
|
<log level="warning" message="Found an accounting transaction for depreciation of FixedAsset [${fixedAsset.fixedAssetId}] with a cuurency that doesn't match the currency used in the fixed asset: the depreciation total in the fixed asset will not be updated."/>
|
|
<return/>
|
|
</else>
|
|
</if-compare-field>
|
|
</else>
|
|
</if-compare-field>
|
|
</iterate>
|
|
<set field="depreciationTotal" from-field="fixedAsset.depreciation" default-value="0.0" type="BigDecimal"/>
|
|
<calculate field="depreciationTotal">
|
|
<calcop operator="add">
|
|
<calcop operator="get" field="depreciation"/>
|
|
<calcop operator="get" field="depreciationTotal"/>
|
|
</calcop>
|
|
</calculate>
|
|
<set field="fixedAsset.depreciation" from-field="depreciationTotal"/>
|
|
<store-value value-field="fixedAsset"/>
|
|
</then>
|
|
</if>
|
|
</simple-method>
|
|
|
|
</simple-methods>
|