blob: c4323bc764f16a03d5fad39c37ffa9dee6871e5f [file] [log] [blame]
<?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"
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/simple-methods-v2.xsd">
<!-- ================================================================ -->
<!-- FixedAsset Services -->
<!-- ================================================================ -->
<!-- create a new Fixed Asset header record -->
<simple-method method-name="createFixedAsset" short-description="Create an FixedAsset">
<!-- create new entity and create all the fields -->
<make-value value-field="newEntity" entity-name="FixedAsset"/>
<set-nonpk-fields map="parameters" value-field="newEntity"/>
<!-- create a non existing ID if not supplied -->
<if-empty field="parameters.fixedAssetId">
<sequenced-id sequence-name="FixedAsset" field="newEntity.fixedAssetId"/>
<else>
<!-- check the Duplicate ID> -->
<entity-one entity-name="FixedAsset" value-field="fixedAsset"/>
<if-not-empty field="fixedAsset">
<add-error>
<fail-property resource="AccountingUiLabels" property="AccountingFixedAssetIdAlreadyExists"/>
</add-error>
<log level="info" message="${AccountingUiLabels.AccountingFixedAssetIdAlreadyExists}"/>
<else>
<check-id field="parameters.fixedAssetId"/>
</else>
</if-not-empty>
<check-errors/>
<set from-field="parameters.fixedAssetId" field="newEntity.fixedAssetId"/>
</else>
</if-empty>
<field-to-result field="newEntity.fixedAssetId" result-name="fixedAssetId"/>
<!-- finally create the record (should not exist already)-->
<create-value value-field="newEntity"/>
</simple-method>
<!-- update an existing Fixed Asset header Record -->
<simple-method method-name="updateFixedAsset" short-description="Update an existing FixedAsset">
<entity-one entity-name="FixedAsset" value-field="lookedUpValue"/>
<set-nonpk-fields map="parameters" value-field="lookedUpValue"/>
<store-value value-field="lookedUpValue"/>
</simple-method>
<!-- ================================================================ -->
<!-- FixedAssetMember Services -->
<!-- ================================================================ -->
<!-- add a product to a fixed Asset -->
<simple-method method-name="addFixedAssetProduct" short-description="Add Product to FixedAsset">
<make-value value-field="newEntity" entity-name="FixedAssetProduct"/>
<set-pk-fields map="parameters" value-field="newEntity"/>
<set-nonpk-fields map="parameters" value-field="newEntity"/>
<if-empty field="newEntity.fromDate">
<now-timestamp field="newEntity.fromDate"/>
</if-empty>
<create-value value-field="newEntity"/>
</simple-method>
<!-- update the product to fixed Asset link -->
<simple-method method-name="updateFixedAssetProduct" short-description="Update Products of a FixedAsset">
<entity-one entity-name="FixedAssetProduct" value-field="lookedUpValue"/>
<set-nonpk-fields map="parameters" value-field="lookedUpValue"/>
<store-value value-field="lookedUpValue"/>
</simple-method>
<!-- remove the productlink from the Fixed Asset -->
<simple-method method-name="removeFixedAssetProduct" short-description="Remove Product From FixedAsset">
<entity-one entity-name="FixedAssetProduct" value-field="lookedUpValue"/>
<remove-value value-field="lookedUpValue"/>
</simple-method>
<!-- ================================================================ -->
<!-- FixedAssetCalendar Services -->
<!-- ================================================================ -->
<!-- update the calendar of the fixed Asset -->
<!-- <simple-method method-name="updateFixedAssetCalendar" short-description="Update the calendar of the FixedAsset">
<check-permission permission="ACCOUNTING" action="_UPDATE">
<alt-permission permission="ACCOUNTING_ROLE" action="_UPDATE"/>
<fail-property resource="AccountingUiLabels" property="AccountingUpdatePermissionError"/>
</check-permission>
<check-errors/>
<entity-one entity-name="FixedAsset" value-field="fixedAsset"/>
<make-value value-field="excDayPKMap" entity-name="TechDataCalendarExcDay"/>
<set-pk-fields field-name= "calendarId" map="fixedAsset" value-field="excDayPKMap"/>
<set-pk-fields fieldName= "exceptionDateStartTime" map="parameters" value-field="excDayPKMap"/>
<find-by entity-name="TechDataCalendarExcDay" map-name="excDayPKMap" value-name="lookedUpValue"/>
<set-nonpk-fields field-name="capacity" map="parameters" value-field="lookedUpValue"/>
<store-value value-field="lookedUpValue"/>
</simple-method>
-->
<!-- create a new FixedAssetStdCost -->
<simple-method method-name="createFixedAssetStdCost" short-description="Create a FixedAssetStdCost">
<!-- TODO: we should cancel the existing costs of the same type -->
<!-- create new entity and create all the fields -->
<!-- Check, should not exist already -->
<entity-one entity-name="FixedAssetStdCost" value-field="fixedAssetStdCost"/>
<if-not-empty field="fixedAssetStdCost">
<add-error>
<fail-property resource="AccountingUiLabels" property="AccountingFixedAssetStdCostAlreadyExists"/>
</add-error>
</if-not-empty>
<check-errors/>
<make-value value-field="newEntity" entity-name="FixedAssetStdCost"/>
<set-nonpk-fields map="parameters" value-field="newEntity"/>
<set-pk-fields map="parameters" value-field="newEntity"/>
<!-- finally create the record (should not exist already)-->
<create-value value-field="newEntity"/>
<check-errors/>
</simple-method>
<!-- update an existing FixedAssetStdCost -->
<simple-method method-name="updateFixedAssetStdCost" short-description="Update an existing FixedAssetStdCost">
<entity-one entity-name="FixedAssetStdCost" value-field="fixedAssetStdCost"/>
<set-nonpk-fields map="parameters" value-field="fixedAssetStdCost"/>
<store-value value-field="fixedAssetStdCost"/>
</simple-method>
<!-- cancel an existing Agreement -->
<simple-method method-name="cancelFixedAssetStdCost" short-description="Cancel an existing FixedAssetStdCost">
<entity-one entity-name="FixedAssetStdCost" value-field="fixedAssetStdCost"/>
<now-timestamp field="fixedAssetStdCost.thruDate"/>
<store-value value-field="fixedAssetStdCost"/>
</simple-method>
<!-- Fixed Asset Identification "FIXED_ASSET_IDENT"-->
<simple-method method-name="createFixedAssetIdent" short-description="Create an FixedAssetIdent">
<make-value value-field="newEntity" entity-name="FixedAssetIdent"/>
<set-nonpk-fields map="parameters" value-field="newEntity"/>
<set-pk-fields map="parameters" value-field="newEntity"/>
<create-value value-field="newEntity"/>
</simple-method>
<simple-method method-name="updateFixedAssetIdent" short-description="Update an existing FixedAssetIdent">
<entity-one entity-name="FixedAssetIdent" value-field="lookedUpValue"/>
<set-nonpk-fields map="parameters" value-field="lookedUpValue"/>
<store-value value-field="lookedUpValue"/>
</simple-method>
<simple-method method-name="removeFixedAssetIdent" short-description="Remove Fixed Assets Idents FixedAssetIdent">
<entity-one entity-name="FixedAssetIdent" value-field="lookedUpValue"/>
<remove-value value-field="lookedUpValue"/>
</simple-method>
<!-- FixedAsset Registration Create/Update/Delete"-->
<simple-method method-name="createFixedAssetRegistration" short-description="Create FixedAsset Registration">
<make-value value-field="newEntity" entity-name="FixedAssetRegistration"/>
<set-nonpk-fields map="parameters" value-field="newEntity"/>
<set-pk-fields map="parameters" value-field="newEntity"/>
<if-empty field="newEntity.fromDate">
<now-timestamp field="newEntity.fromDate"/>
</if-empty>
<create-value value-field="newEntity"/>
</simple-method>
<simple-method method-name="updateFixedAssetRegistration" short-description="Update an existing FixedAsset Registration">
<entity-one entity-name="FixedAssetRegistration" value-field="lookedUpValue"/>
<set-nonpk-fields map="parameters" value-field="lookedUpValue"/>
<store-value value-field="lookedUpValue"/>
</simple-method>
<simple-method method-name="deleteFixedAssetRegistration" short-description="Delete FixedAsset Registration">
<entity-one entity-name="FixedAssetRegistration" value-field="lookedUpValue"/>
<remove-value value-field="lookedUpValue"/>
</simple-method>
<!-- 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 value-field="fixedAsset" entity-name="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 value-field="workEffort" entity-name="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 list="wepas" entity-name="WorkEffortPartyAssignment" filter-by-date="true">
<condition-expr field-name="workEffortId" from-field="workEffortId" operator="equals"/>
</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="deleteFixedAssetMaint" short-description="Delete FixedAsset Maintenance">
<entity-one entity-name="FixedAssetMaint" value-field="lookedUpValue"/>
<remove-value value-field="lookedUpValue"/>
</simple-method>
<!-- create/update/delete FixedAssetMeter -->
<simple-method method-name="createFixedAssetMeter" short-description="Create a Fixed Asset Meter Reading">
<make-value entity-name="FixedAssetMeter" value-field="newEntity"/>
<set-pk-fields map="parameters" value-field="newEntity"/>
<set-nonpk-fields map="parameters" value-field="newEntity"/>
<create-value value-field="newEntity"/>
<check-errors/>
<set field="meterValue" from-field="newEntity"/>
<call-simple-method method-name="createMaintsFromMeterReading"/>
</simple-method>
<simple-method method-name="updateFixedAssetMeter" short-description="Update a Fixed Asset Meter Reading">
<entity-one entity-name="FixedAssetMeter" value-field="lookedUpValue"/>
<set-nonpk-fields map="parameters" value-field="lookedUpValue"/>
<store-value value-field="lookedUpValue"/>
<check-errors/>
<set field="meterValue" from-field="lookedUpValue"/>
<call-simple-method method-name="createMaintsFromMeterReading"/>
</simple-method>
<simple-method method-name="deleteFixedAssetMeter" short-description="Delete a Fixed Asset Meter Reading">
<entity-one entity-name="FixedAssetMeter" value-field="lookedUpValue"/>
<remove-value value-field="lookedUpValue"/>
</simple-method>
<simple-method method-name="createMaintsFromMeterReading" short-description="Create Fixed Asset Maintenances From A Meter Reading">
<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 list="productMaintList" entity-name="ProductMaint">
<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 list="maintList" entity-name="FixedAssetMaint">
<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="${util:size(maintList)}" 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(&quot;intervalQuantity&quot;));}" 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" to-map="createMaintCxt" map="productMaintValue"/>
<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 list="fixedAssets" entity-name="FixedAsset">
<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 list="productMaints" entity-name="ProductMaint">
<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 list="maintList" entity-name="FixedAssetMaintWorkEffort">
<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="${util:size(maintList)}" 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" to-map="createMaintCxt" map="productMaint"/>
<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="deleteFixedAssetMaintOrder" short-description="Delete FixedAsset Maintenance Order">
<entity-one entity-name="FixedAssetMaintOrder" value-field="lookedUpValue"/>
<remove-value value-field="lookedUpValue"/>
</simple-method>
<!-- ==============Party Fixed Asset Assignment============= -->
<simple-method method-name="createPartyFixedAssetAssignment" short-description="Associate Party to Fixed Asset">
<make-value entity-name="PartyFixedAssetAssignment" value-field="newEntity"/>
<set-pk-fields value-field="newEntity" map="parameters"/>
<set-nonpk-fields value-field="newEntity" map="parameters"/>
<if-empty field="newEntity.fromDate">
<now-timestamp field="nowTimestamp"/>
<set field="newEntity.fromDate" from-field="nowTimestamp"/>
</if-empty>
<create-value value-field="newEntity"/>
</simple-method>
<simple-method method-name="updatePartyFixedAssetAssignment" short-description="Update Party to Fixed Asset">
<entity-one entity-name="PartyFixedAssetAssignment" value-field="newEntity"/>
<set-nonpk-fields value-field="newEntity" map="parameters"/>
<store-value value-field="newEntity"/>
</simple-method>
<simple-method method-name="deletePartyFixedAssetAssignment" short-description="Delete Party to Fixed Asset">
<entity-one entity-name="PartyFixedAssetAssignment" value-field="newEntity"/>
<remove-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 list="assignedParties" entity-name="PartyFixedAssetAssignAndRole" 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"/>
<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"/>
<field-to-result field="depreciationTotal" result-name="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-method method-name="createFixedAssetTypeGlAccount" short-description="Create a Fixed Asset Type Gl Account Mapping">
<make-value entity-name="FixedAssetTypeGlAccount" value-field="newEntity"/>
<set-pk-fields value-field="newEntity" map="parameters"/>
<set-nonpk-fields value-field="newEntity" map="parameters"/>
<if-empty field="newEntity.fixedAssetId">
<set field="newEntity.fixedAssetId" from-field="_NA_"/>
</if-empty>
<if-empty field="newEntity.fixedAssetTypeId">
<set field="newEntity.fixedAssetTypeId" from-field="_NA_"/>
</if-empty>
<create-value value-field="newEntity"/>
</simple-method>
</simple-methods>