Author: hansbak Date: Fri Jun 21 05:44:15 2013 New Revision: 1495294 URL: http://svn.apache.org/r1495294 Log: make automatic application also working with foreign invoices and payments
Modified: ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/payment/PaymentServices.xml ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml Modified: ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml?rev=1495294&r1=1495293&r2=1495294&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml (original) +++ ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml Fri Jun 21 05:44:15 2013 @@ -997,4 +997,30 @@ under the License. <call-service service-name="updateSimpleTextContent" in-map-name="updateSimpleText"/> </simple-method> + <simple-method method-name="isInvoiceForeign" short-description="check if a invoice is in a foreign currency related to the accounting company."> + <entity-one value-field="invoice" entity-name="InvoiceAndType"> + <field-map field-name="invoiceId" from-field="parameters.invoiceId"/> + </entity-one> + <if-empty field="invoice"> + <log level="error" message="Invoice not found"/> + <return/> + </if-empty> + <if-compare field="invoice.parentTypeId" operator="equals" value="PURCHASE_INVOICE"> + <set field="pref.organizationPartyId" from-field="invoice.partyIdFrom"/> + </if-compare> + <if-compare field="invoice.parentTypeId" operator="equals" value="SALES_INVOICE"> + <set field="pref.organizationPartyId" from-field="invoice.partyId"/> + </if-compare> + <call-service service-name="getPartyAccountingPreferences" in-map-name="pref"> + <result-to-field result-name="prefResult"/> + </call-service> + <if-compare-field to-field="prefResult.partyAccountingPreference.baseCurrencyUomId" operator="equals" field="invoice.currencyUomId"> + <set field="isForeign" value="false" type="Boolean"/> + <else> + <set field="isForeign" value="true" type="Boolean"/> + </else> + </if-compare-field> + <field-to-result field="isForeign"/> + </simple-method> + </simple-methods> Modified: ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/payment/PaymentServices.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/payment/PaymentServices.xml?rev=1495294&r1=1495293&r2=1495294&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/payment/PaymentServices.xml (original) +++ ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/payment/PaymentServices.xml Fri Jun 21 05:44:15 2013 @@ -1016,15 +1016,36 @@ under the License. <call-class-method method-name="getInvoiceTotal" class-name="org.ofbiz.accounting.invoice.InvoiceWorker" ret-field="invoiceTotal"> <field field="invoice" type="GenericValue"/> </call-class-method> - <entity-condition list="payments" entity-name="Payment"> - <condition-list combine="and"> - <condition-expr field-name="statusId" value="PMNT_CONFIRMED" operator="not-equals"/> - <condition-expr field-name="partyIdFrom" from-field="invoice.partyId" operator="equals"/> - <condition-expr field-name="partyIdTo" from-field="invoice.partyIdFrom" operator="equals"/> - <condition-expr field-name="amount" from-field="invoiceTotal" operator="equals"/> - </condition-list> - <order-by field-name="effectiveDate"/> - </entity-condition> + + <set field="checkInvoice.invoiceId" from="invoice.invoiceId"/> + <call-service service-name="isInvoiceForeign" in-map-name="checkInvoice"> + <result-to-field result-name="isForeign"/> + </call-service> + <if-compare operator="equals" value="true" field="isForeign"> + <entity-condition list="payments" entity-name="Payment"> + <condition-list combine="and"> + <condition-expr field-name="statusId" value="PMNT_CONFIRMED" operator="not-equals"/> + <condition-expr field-name="partyIdFrom" from-field="invoice.partyId" operator="equals"/> + <condition-expr field-name="partyIdTo" from-field="invoice.partyIdFrom" operator="equals"/> + <condition-expr field-name="actualCurrencyAmount" from-field="invoiceTotal" operator="equals"/> + <condition-expr field-name="actualCurrencyUomId" from-field="invoice.currencyUomId" operator="equals"/> + </condition-list> + <order-by field-name="effectiveDate"/> + </entity-condition> + <else> + <entity-condition list="payments" entity-name="Payment"> + <condition-list combine="and"> + <condition-expr field-name="statusId" value="PMNT_CONFIRMED" operator="not-equals"/> + <condition-expr field-name="partyIdFrom" from-field="invoice.partyId" operator="equals"/> + <condition-expr field-name="partyIdTo" from-field="invoice.partyIdFrom" operator="equals"/> + <condition-expr field-name="amount" from-field="invoiceTotal" operator="equals"/> + <condition-expr field-name="currencyUomId" from-field="invoice.currencyUomId" operator="equals"/> + </condition-list> + <order-by field-name="effectiveDate"/> + </entity-condition> + </else> + </if-compare> + <if-not-empty field="payments"> <!-- check if already applied --> <entity-and list="paymentAppls" entity-name="PaymentApplication"> @@ -1042,6 +1063,7 @@ under the License. <if-not-empty field="parameters.paymentId"> <entity-one value-field="payment" entity-name="Payment"/> <if-not-empty field="payment"> + <entity-condition list="invoices" entity-name="Invoice"> <condition-list combine="and"> <condition-expr field-name="statusId" value="INVOICE_READY" operator="not-equals"/> @@ -1057,9 +1079,25 @@ under the License. <call-class-method method-name="getInvoiceTotal" class-name="org.ofbiz.accounting.invoice.InvoiceWorker" ret-field="invoiceTotal"> <field field="invoice" type="GenericValue"/> </call-class-method> - <if-compare-field operator="equals" field="invoiceTotal" to-field="payment.amount"> - <set field="invoiceId" from-field="invoice.invoiceId"/> - </if-compare-field> + + <set field="checkInvoice.invoiceId" from="invoice.invoiceId"/> + <call-service service-name="isInvoiceForeign" in-map-name="checkInvoice"> + <result-to-field result-name="isForeign"/> + </call-service> + <if-compare operator="equals" value="true" field="isForeign"> + <if-compare-field operator="equals" field="invoiceTotal" to-field="payment.actualCurrencyAmount"> + <if-compare-field operator="equals" field="invoice.currencyUomId" to-field="payment.actualCurrencyUomId"> + <set field="invoiceId" from-field="invoice.invoiceId"/> + </if-compare-field> + </if-compare-field> + <else> + <if-compare-field operator="equals" field="invoiceTotal" to-field="payment.amount"> + <if-compare-field operator="equals" field="invoice.currencyUomId" to-field="payment.currencyUomId"> + <set field="invoiceId" from-field="invoice.invoiceId"/> + </if-compare-field> + </if-compare-field> + </else> + </if-compare> </iterate> <if-not-empty field="invoiceId"> <entity-and list="paymentAppls" entity-name="PaymentApplication"> Modified: ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml?rev=1495294&r1=1495293&r2=1495294&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml (original) +++ ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml Fri Jun 21 05:44:15 2013 @@ -425,5 +425,11 @@ under the License. <attribute name="textDataResourceId" type="String" mode="IN" optional="true"/> <attribute name="text" type="String" mode="IN" optional="true" allow-html="safe"/> </service> + <service name="isInvoiceForeign" engine="simple" + location="component://accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml" invoke="isInvoiceForeign" auth="true"> + <description>check if a invoice is in a foreign currency related to the accounting company.</description> + <attribute name="invoiceId" type="String" mode="IN" optional="false"/> + <attribute name="isForeign" type="Boolean" mode="OUT" optional="false"/> + </service> </services>