Author: adrianc
Date: Wed Aug  6 14:22:29 2008
New Revision: 683418

URL: http://svn.apache.org/viewvc?rev=683418&view=rev
Log:
A couple of improvements to fixed asset maintenance:

1. When a fixed asset maint status is changed to Completed, the associated work 
effort status is changed to Completed as well. In addition, work effort party 
assignment thruDates are updated.

2. A scheduled job looks for fixed asset product maints set up on time 
intervals and automatically creates maintenances when the specified time 
interval passes. Right now it only supports day, month, and year intervals. 
More can be added if needed.

Modified:
    ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml
    
ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/fixedasset/FixedAssetServices.xml
    ofbiz/trunk/applications/accounting/servicedef/services_fixedasset.xml

Modified: ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml?rev=683418&r1=683417&r2=683418&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml (original)
+++ ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml Wed Aug  6 
14:22:29 2008
@@ -158,6 +158,12 @@
     <StatusItem description="Completed" sequenceId="10" statusCode="COMPLETED" 
statusId="FAM_COMPLETED" statusTypeId="FIXEDAST_MNT_STATUS"/>
     <StatusItem description="Cancelled" sequenceId="99" statusCode="CANCELLED" 
statusId="FAM_CANCELLED" statusTypeId="FIXEDAST_MNT_STATUS"/>
     
+    <!-- The following three elements set up a regularly scheduled job that 
will automatically create
+        fixed asset maintenances from ProductMaint time intervals. -->
+    <RecurrenceRule recurrenceRuleId="FAM_AUTO_CREATE" untilDateTime="" 
frequency="MINUTELY" intervalNumber="5" countNumber="-1"/>
+    <RecurrenceInfo recurrenceInfoId="FAM_AUTO_CREATE" 
startDateTime="2000-01-01 00:00:00.000" recurrenceRuleId="FAM_AUTO_CREATE" 
recurrenceCount="0"/>
+    <JobSandbox jobId="FAM_AUTO_CREATE" jobName="Auto-create Fixed Asset 
Maintenances" runTime="2000-01-01 00:00:00.000" 
serviceName="createMaintsFromTimeInterval" poolId="pool" runAsUser="system" 
recurrenceInfoId="FAM_AUTO_CREATE"/>
+
     <!-- Fixed Asset Maintenance party roles -->
     <RoleType description="Fixed Asset Maint Assignee" hasTable="N" 
roleTypeId="FAM_ASSIGNEE"/>
     <RoleType description="Maintenance Supplier or Service" hasTable="N" 
parentTypeId="FAM_ASSIGNEE" roleTypeId="FAM_SUPPLIER"/>

Modified: 
ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/fixedasset/FixedAssetServices.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/fixedasset/FixedAssetServices.xml?rev=683418&r1=683417&r2=683418&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/fixedasset/FixedAssetServices.xml
 (original)
+++ 
ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/fixedasset/FixedAssetServices.xml
 Wed Aug  6 14:22:29 2008
@@ -244,7 +244,8 @@
     </simple-method>   
     <simple-method method-name="updateFixedAssetMaint" 
short-description="Update an existing FixedAsset Maintenance">
         <entity-one entity-name="FixedAssetMaint" value-name="lookedUpValue"/>
-        <field-to-result field-name="lookedUpValue.statusId" 
result-name="oldStatusId"/>
+        <set field="oldStatusId" from-field="lookedUpValue.statusId"/>
+        <field-to-result field-name="oldStatusId"/>
         <set-nonpk-fields map-name="parameters" value-name="lookedUpValue"/>
         <if-not-empty field="parameters.productMaintSeqId">
             <entity-one entity-name="FixedAsset" value-name="fixedAsset"/>
@@ -255,6 +256,47 @@
             <set field="lookedUpValue.productMaintTypeId" 
from-field="productMaint.productMaintTypeId"/>
         </if-not-empty>
         <store-value value-name="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-name="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-to-env env-name="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-name="wepas" 
entity-name="WorkEffortPartyAssignment" filter-by-date="true">
+                            <condition-expr field-name="workEffortId" 
env-name="workEffortId" operator="equals"/>
+                        </entity-condition>
+                        <iterate list-name="wepas" entry-name="wepa">
+                            <set field="wepa.thruDate" 
from-field="nowTimestamp"/>
+                            <store-value value-name="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-name="lookedUpValue"/>
@@ -337,6 +379,80 @@
             </if-compare-field>
         </iterate>
     </simple-method>
+    <simple-method method-name="createMaintsFromTimeInterval" 
short-description="Create Fixed Asset Maintenances From A Product Maint Time 
Interval">
+        <now-timestamp-to-env env-name="nowTimestamp"/>
+        <entity-condition list-name="fixedAssets" entity-name="FixedAsset">
+            <condition-list combine="and">
+                <condition-expr field-name="instanceOfProductId" 
operator="not-equals" env-name="null"/>
+                <condition-expr field-name="actualEndOfLife" operator="equals" 
env-name="null"/>
+            </condition-list>
+        </entity-condition>
+        <iterate list-name="fixedAssets" entry-name="fixedAsset">
+            <entity-condition list-name="productMaints" 
entity-name="ProductMaint">
+                <condition-list combine="and">
+                    <condition-expr field-name="productId" 
env-name="fixedAsset.instanceOfProductId"/>
+                    <condition-expr field-name="intervalUomId" operator="like" 
value="TF_%"/>
+                </condition-list>
+            </entity-condition>
+            <iterate list-name="productMaints" entry-name="productMaint">
+                <set field="repeatCount" from-field="productMaint.repeatCount" 
default-value="0" type="Long"/>
+                <entity-condition list-name="maintList" 
entity-name="FixedAssetMaintWorkEffort">
+                    <condition-list combine="and">
+                        <condition-expr field-name="fixedAssetId" 
operator="equals" env-name="fixedAsset.fixedAssetId"/>
+                        <condition-expr field-name="productMaintTypeId" 
operator="equals" env-name="productMaint.productMaintTypeId"/>
+                        <condition-expr field-name="intervalUomId" 
operator="equals" env-name="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="${bsh:maintList.size();}" 
type="Long"/>
+                    </if-not-empty>
+                    <set field="lastSvcLong" value="0" type="Long"/>
+                    <set field="lastSvcDate" from-field="lastSvcLong" 
type="Timestamp"/>
+                    <iterate list-name="maintList" entry-name="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-name="createMaintCxt" 
map-name="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>
     <simple-method method-name="migrateFixedAssetMaintMeter" 
short-description="Copy FixedAssetMaintMeter To FixedAssetMeter">
         <entity-condition list-name="maintMeterList" 
entity-name="FixedAssetMaintMeter"/>
         <iterate list-name="maintMeterList" entry-name="maintMeter">

Modified: ofbiz/trunk/applications/accounting/servicedef/services_fixedasset.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/services_fixedasset.xml?rev=683418&r1=683417&r2=683418&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/servicedef/services_fixedasset.xml 
(original)
+++ ofbiz/trunk/applications/accounting/servicedef/services_fixedasset.xml Wed 
Aug  6 14:22:29 2008
@@ -168,6 +168,13 @@
         <permission-service service-name="fixedAssetPermissionCheck" 
main-action="DELETE"/>
         <auto-attributes include="pk" mode="IN" optional="false"/>
     </service>
+    <service name="createMaintsFromTimeInterval" engine="simple" 
use-transaction="false"
+                
location="org/ofbiz/accounting/fixedasset/FixedAssetServices.xml" 
invoke="createMaintsFromTimeInterval" auth="true">
+        <description>Create Fixed Asset Maintenances from ProductMaint time 
intervals. Currently works
+        with day, month, and year interval types. This service is intended to 
be run as a regularly
+        scheduled job.</description>
+        <permission-service service-name="fixedAssetPermissionCheck" 
main-action="CREATE"/>
+    </service>
     <!-- FixedAsset Maintenance Meter Create/Update/Delete-->
     <service name="createFixedAssetMeter" 
default-entity-name="FixedAssetMeter" engine="simple"
                 
location="org/ofbiz/accounting/fixedasset/FixedAssetServices.xml" 
invoke="createFixedAssetMeter" auth="true">


Reply via email to