Author: hansbak
Date: Wed Dec 16 08:46:06 2009
New Revision: 891159

URL: http://svn.apache.org/viewvc?rev=891159&view=rev
Log:
added get exchange rate service

Modified:
    
ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/admin/AcctgAdminServices.xml
    ofbiz/trunk/applications/accounting/servicedef/services_admin.xml

Modified: 
ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/admin/AcctgAdminServices.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/admin/AcctgAdminServices.xml?rev=891159&r1=891158&r2=891159&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/admin/AcctgAdminServices.xml
 (original)
+++ 
ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/admin/AcctgAdminServices.xml
 Wed Dec 16 08:46:06 2009
@@ -133,4 +133,44 @@
         </if-empty>
         <call-service service-name="createUomConversionDated" 
in-map-name="createParams"/>
     </simple-method>
+    
+    <!-- Get currency conversion rates in the UomConversionDated entity -->
+    <simple-method method-name="getFXConversion" short-description="Get 
Foreign Exchange conversion rate">
+        <if-empty field="parameters.asOfTimestamp">
+            <now-timestamp field="asOfTimestamp"/>
+            <else>
+                <set field="asOfTimestamp" 
from-field="parameters.asOfTimestamp"/>
+            </else>
+        </if-empty>
+        <!-- find the existing exchange rates-->
+        <entity-condition entity-name="UomConversionDated" list="rates" 
filter-by-date="true">
+            <condition-list combine="and">
+                <condition-expr field-name="uomId" 
from-field="parameters.uomId"/>
+                <condition-expr field-name="uomIdTo" 
from-field="parameters.uomIdTo"/>
+                <condition-expr field-name="fromDate" operator="less-equals" 
from-field="asOfTimestamp"/>
+                <condition-list combine="or">
+                    <condition-expr field-name="thruDate" 
operator="greater-equals" from-field="asOfTimestamp"/>
+                    <condition-expr field-name="thruDate" operator="equals" 
from-field="nullField"/>
+                </condition-list>
+            </condition-list>
+            <order-by field-name="-fromDate"/>
+        </entity-condition>
+        
+        <set field="conversionRate" type="BigDecimal" value="1"/>
+        <if-not-empty field="rates">
+            <set field="conversionFactor" 
from-field="rates[0].conversionFactor"/>
+            <set field="originalValue" type="BigDecimal" value="1"/>
+            
+            <calculate field="conversionRate" type="BigDecimal" 
decimal-scale="2" rounding-mode="HalfUp">
+                <calcop operator="divide">
+                    <calcop operator="get" field="originalValue"/>
+                    <calcop operator="get" field="conversionFactor"/>
+                </calcop>
+            </calculate>
+            <else>
+                <log level="error" message="Could not find conversion 
rate"></log>
+            </else>
+        </if-not-empty>
+        <field-to-result field="conversionRate" result-name="conversionRate"/>
+    </simple-method>
 </simple-methods>

Modified: ofbiz/trunk/applications/accounting/servicedef/services_admin.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/services_admin.xml?rev=891159&r1=891158&r2=891159&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/servicedef/services_admin.xml (original)
+++ ofbiz/trunk/applications/accounting/servicedef/services_admin.xml Wed Dec 
16 08:46:06 2009
@@ -130,4 +130,13 @@
         <description>Accounting Foreign Exchange Permission Checking 
Logic</description>
         <implements service="permissionInterface"/>
     </service>
+    
+    <service name="getFXConversion" engine="simple"
+        
location="component://accounting/script/org/ofbiz/accounting/admin/AcctgAdminServices.xml"
 invoke="getFXConversion">
+        <description>get the conversion rate</description>
+        <attribute type="String" mode="IN" name="uomId" optional="false"/>
+        <attribute type="String" mode="IN" name="uomIdTo" optional="false"/>
+        <attribute type="Timestamp" mode="IN" name="asOfTimestamp" 
optional="true"/>
+        <attribute type="BigDecimal" mode="OUT" name="conversionRate" 
optional="false"/>
+    </service>
 </services>


Reply via email to