svn commit: r604522 - in /ofbiz/trunk/applications/accounting: script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml servicedef/secas_ledger.xml servicedef/services_ledger.xml

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r604522 - in /ofbiz/trunk/applications/accounting: script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml servicedef/secas_ledger.xml servicedef/services_ledger.xml

ashish-18
Author: ashish
Date: Sat Dec 15 14:33:47 2007
New Revision: 604522

URL: http://svn.apache.org/viewvc?rev=604522&view=rev
Log:
Applied patch from JIRA Issue # OFBIZ-1483 with Minor Changes.
Thanks to Alok Agnihotri for your patch .

I initialized the "amountFromOrder" to "0".

Also we are thankful to Pranay Pandey,Mridul Pathak,Pankaj Savita,Vikas Mayur & others for helping Alok for finishing this work.

Modified:
    ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml
    ofbiz/trunk/applications/accounting/servicedef/secas_ledger.xml
    ofbiz/trunk/applications/accounting/servicedef/services_ledger.xml

Modified: ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml?rev=604522&r1=604521&r2=604522&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml (original)
+++ ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml Sat Dec 15 14:33:47 2007
@@ -1410,4 +1410,114 @@
             <field-to-result field-name="acctgTransId" result-name="acctgTransId"/>
         </if-compare>      
     </simple-method>
+    
+    <!-- Service for the automatic creation of accounting transaction for Purchase Invoice -->
+    <simple-method method-name="createAcctgTransForPurchaseInvoice" short-description="Create an accounting transaction for a purchase invoice">
+        <!-- retrieve ledger rounding properties -->
+        <property-to-field resource="arithmetic" property="ledger.decimals" field-name="ledgerDecimals"/>
+        <property-to-field resource="arithmetic" property="ledger.rounding" field-name="roundingMode"/>
+        <log level="info" message="Using ledger decimals [${ledgerDecimals}] and rounding [${roundingMode}]"/>
+        <set field="totalAmountFromInvoice" type="BigDecimal" value="0"/>
+        <set field="amountFromOrder" type="BigDecimal" value="0"/>
+        
+        <entity-one entity-name="Invoice" value-name="invoice"/>
+        <if-compare field-name="invoice.invoiceTypeId" operator="equals" value="PURCHASE_INVOICE">
+            <get-related value-name="invoice" relation-name="InvoiceItem" list-name="invoiceItems"/>
+            <iterate list-name="invoiceItems" entry-name="invoiceItem">
+                <if-empty field-name="invoiceItem.quantity">
+                    <set field="invoiceItem.quantity" value="1"/>
+                </if-empty>
+                <calculate field-name="amountFromInvoice"  type="BigDecimal" decimal-scale="${ledgerDecimals}" rounding-mode="${roundingMode}">
+                    <calcop operator="multiply">
+                        <calcop operator="get" field-name="invoiceItem.quantity"/>
+                        <calcop operator="get" field-name="invoiceItem.amount"/>
+                    </calcop>
+                </calculate>
+                <calculate field-name="totalAmountFromInvoice" type="BigDecimal" decimal-scale="${ledgerDecimals}" rounding-mode="${roundingMode}">
+                    <calcop operator="add">
+                        <calcop operator="get" field-name="totalAmountFromInvoice"/>
+                        <calcop operator="get" field-name="amountFromInvoice"/>
+                    </calcop>
+                </calculate>
+                <get-related value-name="invoiceItem" relation-name="OrderItemBilling" list-name="orderItemBillings"/>
+                <iterate list-name="orderItemBillings" entry-name="orderItemBilling">
+                    <get-related-one value-name="orderItemBilling" relation-name="OrderItem" to-value-name="orderItem"/>
+                    <calculate field-name="amountFromOrder" type="BigDecimal"  decimal-scale="${ledgerDecimals}" rounding-mode="${roundingMode}">
+                        <calcop field-name="amountFromOrder" operator="add">
+                            <calcop operator="multiply">
+                                <calcop operator="get" field-name="orderItemBilling.quantity"/>
+                                <calcop operator="get" field-name="orderItem.unitPrice"/>
+                            </calcop>
+                        </calcop>
+                    </calculate>
+                </iterate>
+                <!-- Debit -->
+                <if>
+                    <condition>
+                        <and>
+                            <if-compare-field field-name="amountFromInvoice" operator="not-equals" to-field-name="amountFromOrder"/>
+                            <if-compare field-name="amountFromOrder" operator="greater" value="0" type="BigDecimal"/>
+                        </and>
+                    </condition>
+                    <then>
+                        <make-value entity-name="AcctgTransEntry" value-name="debitEntry"/>
+                        <set field="debitEntry.debitCreditFlag" value="D"/>
+                        <set field="debitEntry.organizationPartyId" from-field="invoice.partyId"/>
+                        <set field="debitEntry.partyId" from-field="invoice.partyIdFrom"/>
+                        <set field="debitEntry.roleTypeId" value="BILL_FROM_VENDOR"/>
+                        <set field="debitEntry.productId" from-field="invoiceItem.productId"/>
+                        <set field="debitEntry.glAccountTypeId" value="PURCHASE_PRICE_VAR"/>
+                        <calculate field-name="origAmount" type="BigDecimal" decimal-scale="${ledgerDecimals}" rounding-mode="${roundingMode}">
+                            <calcop operator="subtract">
+                                <calcop operator="get" field-name="amountFromInvoice"/>
+                                <calcop operator="get" field-name="amountFromOrder"/>
+                            </calcop>
+                        </calculate>
+                        <set field="debitEntry.origAmount" from-field="origAmount"/>
+                        <set field="debitEntry.origCurrencyUomId" from-field="invoice.currencyUomId"/>
+                        <set field="acctgTransEntries[]" from-field="debitEntry" type="Object"/>
+                    </then>
+                </if>
+                <make-value entity-name="AcctgTransEntry" value-name="debitEntry"/>
+                <set field="debitEntry.debitCreditFlag" value="D"/>
+                <set field="debitEntry.organizationPartyId" from-field="invoice.partyId"/>
+                <set field="debitEntry.partyId" from-field="invoice.partyIdFrom"/>
+                <set field="debitEntry.roleTypeId" value="BILL_FROM_VENDOR"/>
+                <set field="debitEntry.productId" from-field="invoiceItem.productId"/>
+                <set field="debitEntry.glAccountTypeId" from-field="invoiceItem.invoiceItemTypeId"/>
+                <set field="debitEntry.glAccountId" from-field="invoiceItem.overrideGlAccountId"/>
+                <if-compare field-name="amountFromOrder" operator="greater" value="0" type="BigDecimal">
+                    <set field="origAmount" from-field="amountFromOrder"/>
+                <else>
+                    <set field="origAmount" from-field="amountFromInvoice"/>
+                </else>
+                </if-compare>
+                <set field="debitEntry.origAmount" from-field="origAmount"/>
+                <set field="debitEntry.origCurrencyUomId" from-field="invoice.currencyUomId"/>
+                <set field="acctgTransEntries[]" from-field="debitEntry" type="Object"/>
+            </iterate>
+        </if-compare>
+        <!-- Credit -->
+        <make-value entity-name="AcctgTransEntry" value-name="creditEntry"/>
+        <set field="creditEntry.debitCreditFlag" value="C"/>
+        <set field="creditEntry.organizationPartyId" from-field="invoice.partyId"/>
+        <set field="creditEntry.glAccountTypeId" value="ACCOUNTS_PAYABLE"/>
+        <set field="creditEntry.origAmount" from-field="totalAmountFromInvoice"/>
+        <set field="creditEntry.origCurrencyUomId" from-field="invoice.currencyUomId"/>
+        <set field="creditEntry.partyId" from-field="invoice.partyIdFrom"/>
+        <set field="creditEntry.roleTypeId" value="BILL_FROM_VENDOR"/>
+        <set field="acctgTransEntries[]" from-field="creditEntry" type="Object"/>
+
+        <!-- Set header fields (AcctgTrans) -->
+        <set field="createAcctgTransAndEntriesInMap.glFiscalTypeId" value="ACTUAL"/>
+        <set field="createAcctgTransAndEntriesInMap.acctgTransTypeId" value="PURCHASE_INVOICE"/>
+        <set field="createAcctgTransAndEntriesInMap.partyId" from-field="invoice.partyIdFrom"/>
+        <set field="createAcctgTransAndEntriesInMap.roleTypeId" value="BILL_FROM_VENDOR"/>
+        <set field="createAcctgTransAndEntriesInMap.acctgTransEntries" from-field="acctgTransEntries"/>
+        <call-service service-name="createAcctgTransAndEntries" in-map-name="createAcctgTransAndEntriesInMap">
+            <result-to-field result-name="acctgTransId"/>
+        </call-service>
+        <field-to-result field-name="acctgTransId" result-name="acctgTransId"/>
+    </simple-method>
+    
 </simple-methods>

Modified: ofbiz/trunk/applications/accounting/servicedef/secas_ledger.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/secas_ledger.xml?rev=604522&r1=604521&r2=604522&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/servicedef/secas_ledger.xml (original)
+++ ofbiz/trunk/applications/accounting/servicedef/secas_ledger.xml Sat Dec 15 14:33:47 2007
@@ -89,4 +89,14 @@
         <condition field-name="oldStatusId" operator="not-equals" value="PMNT_RECEIVED"/>
         <action service="createAcctgTransAndEntriesForIncomingPayment" mode="sync"/>
     </eca>
+    
+    <!-- attemp to create AcctgTrans for Purchase Invoice -->
+    <eca service="setInvoiceStatus" event="commit">
+        <condition field-name="invoiceId" operator="is-not-empty"/>
+        <condition field-name="statusId" operator="equals" value="INVOICE_READY"/>
+        <condition field-name="oldStatusId" operator="not-equals" value="INVOICE_READY"/>
+        <condition field-name="oldStatusId" operator="not-equals" value="INVOICE_PAID"/>
+        <action service="createAcctgTransForPurchaseInvoice" mode="sync"/>
+    </eca>
+    
 </service-eca>

Modified: ofbiz/trunk/applications/accounting/servicedef/services_ledger.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/services_ledger.xml?rev=604522&r1=604521&r2=604522&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/servicedef/services_ledger.xml (original)
+++ ofbiz/trunk/applications/accounting/servicedef/services_ledger.xml Sat Dec 15 14:33:47 2007
@@ -432,4 +432,12 @@
         <attribute name="acctgTransId" type="String" mode="OUT" optional="true"/>
     </service>
 
+    <!-- An automatic GL Posting for Purchase Invoice-->
+    <service name="createAcctgTransForPurchaseInvoice" engine="simple" auth="true"
+        location="org/ofbiz/accounting/ledger/GeneralLedgerServices.xml" invoke="createAcctgTransForPurchaseInvoice">
+        <description>Create an accounting transaction for a purchase invoice</description>
+        <attribute name="invoiceId" type="String" mode="IN" optional="false"/>
+        <attribute name="acctgTransId" type="String" mode="OUT" optional="true"/>
+    </service>
+    
 </services>