666 lines
42 KiB
XML
666 lines
42 KiB
XML
<?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"
|
|
xmlns="http://ofbiz.apache.org/Simple-Method" xsi:schemaLocation="http://ofbiz.apache.org/Simple-Method http://ofbiz.apache.org/dtds/simple-methods.xsd">
|
|
|
|
<simple-method method-name="createPaymentApplication" short-description="Create a Payment Application">
|
|
<if-empty field="parameters.invoiceId">
|
|
<if-empty field="parameters.billingAccountId">
|
|
<if-empty field="parameters.taxAuthGeoId">
|
|
<if-empty field="parameters.toPaymentId">
|
|
<add-error>
|
|
<fail-property resource="AccountingUiLabels" property="AccountingPaymentApplicationParameterMissing"/>
|
|
</add-error>
|
|
<check-errors/>
|
|
</if-empty>
|
|
</if-empty>
|
|
</if-empty>
|
|
</if-empty>
|
|
|
|
<make-value entity-name="PaymentApplication" value-field="paymentAppl"/>
|
|
<set-nonpk-fields map="parameters" value-field="paymentAppl"/>
|
|
|
|
<entity-one entity-name="Payment" value-field="payment"/>
|
|
<if-empty field="payment">
|
|
<add-error>
|
|
<fail-property resource="AccountingUiLabels" property="AccountingPaymentApplicationParameterMissing"/>
|
|
</add-error>
|
|
<check-errors/>
|
|
</if-empty>
|
|
|
|
<call-class-method method-name="getPaymentNotApplied" class-name="org.apache.ofbiz.accounting.payment.PaymentWorker" ret-field="notAppliedPayment">
|
|
<field field="payment" type="GenericValue"/>
|
|
</call-class-method>
|
|
|
|
<if-not-empty field="parameters.invoiceId">
|
|
<!-- get the invoice and do some further validation against it -->
|
|
<entity-one entity-name="Invoice" value-field="invoice"/>
|
|
<!-- check the currencies if they are compatible -->
|
|
<if>
|
|
<condition>
|
|
<and>
|
|
<if-compare-field field="invoice.currencyUomId" operator="not-equals" to-field="payment.currencyUomId"/>
|
|
<if-compare-field field="invoice.currencyUomId" operator="not-equals" to-field="payment.actualCurrencyUomId"/>
|
|
</and>
|
|
</condition>
|
|
<then>
|
|
<add-error>
|
|
<fail-property resource="AccountingUiLabels" property="AccountingCurrenciesOfInvoiceAndPaymentNotCompatible"/>
|
|
</add-error>
|
|
</then>
|
|
</if>
|
|
<check-errors/>
|
|
<if>
|
|
<condition>
|
|
<and>
|
|
<if-compare-field field="invoice.currencyUomId" operator="not-equals" to-field="payment.currencyUomId"/>
|
|
<if-compare-field field="invoice.currencyUomId" operator="equals" to-field="payment.actualCurrencyUomId"/>
|
|
</and>
|
|
</condition>
|
|
<then><!-- if required get the payment amount in foreign currency (local we already have) -->
|
|
<set field="actual" value="true" type="Boolean"/>
|
|
<call-class-method method-name="getPaymentNotApplied" class-name="org.apache.ofbiz.accounting.payment.PaymentWorker" ret-field="notAppliedPayment">
|
|
<field field="payment" type="GenericValue"/>
|
|
<field field="actual" type="Boolean"/>
|
|
</call-class-method>
|
|
</then>
|
|
</if>
|
|
|
|
<!-- get the amount that has not been applied yet for the invoice (outstanding amount) -->
|
|
<call-class-method method-name="getInvoiceNotApplied" class-name="org.apache.ofbiz.accounting.invoice.InvoiceWorker" ret-field="notAppliedInvoice">
|
|
<field field="invoice" type="GenericValue"/>
|
|
</call-class-method>
|
|
|
|
<if-compare-field field="notAppliedInvoice" operator="less-equals" to-field="notAppliedPayment" type="BigDecimal">
|
|
<set field="paymentAppl.amountApplied" from-field="notAppliedInvoice"/>
|
|
<else>
|
|
<set field="paymentAppl.amountApplied" from-field="notAppliedPayment"/>
|
|
</else>
|
|
</if-compare-field>
|
|
|
|
<if-not-empty field="invoice.billingAccountId">
|
|
<set field="paymentAppl.billingAccountId" from-field="invoice.billingAccountId"/>
|
|
</if-not-empty>
|
|
</if-not-empty>
|
|
|
|
<if-not-empty field="parameters.toPaymentId">
|
|
<!-- get the to payment and check the parent types are compatible -->
|
|
<entity-one entity-name="Payment" value-field="toPayment">
|
|
<field-map field-name="paymentId" from-field="parameters.toPaymentId"/>
|
|
</entity-one>
|
|
<entity-one entity-name="PaymentType" value-field="toPaymentType">
|
|
<field-map field-name="paymentTypeId" from-field="toPayment.paymentTypeId"/>
|
|
</entity-one>
|
|
<entity-one entity-name="Payment" value-field="payment">
|
|
<field-map field-name="paymentId" from-field="parameters.paymentId"/>
|
|
</entity-one>
|
|
<entity-one entity-name="PaymentType" value-field="paymentType">
|
|
<field-map field-name="paymentTypeId" from-field="payment.paymentTypeId"/>
|
|
</entity-one>
|
|
|
|
<!-- when amount not provided use the the lowest value available -->
|
|
<if-empty field="parameters.amountApplied">
|
|
<call-class-method method-name="getPaymentNotApplied" class-name="org.apache.ofbiz.accounting.payment.PaymentWorker" ret-field="notAppliedPayment">
|
|
<field field="payment" type="GenericValue"/>
|
|
</call-class-method>
|
|
<call-class-method method-name="getPaymentNotApplied" class-name="org.apache.ofbiz.accounting.payment.PaymentWorker" ret-field="notAppliedToPayment">
|
|
<field field="toPayment" type="GenericValue"/>
|
|
</call-class-method>
|
|
<if-compare-field field="notAppliedPayment" operator="less" to-field="notAppliedToPayment">
|
|
<set field="paymentAppl.amountApplied" from-field="notAppliedPayment"/>
|
|
<else>
|
|
<set field="paymentAppl.amountApplied" from-field="notAppliedToPayment"/>
|
|
</else>
|
|
</if-compare-field>
|
|
</if-empty>
|
|
</if-not-empty>
|
|
|
|
<if-not-empty field="parameters.billingAccountId">
|
|
<if-empty field="paymentAppl.amountApplied">
|
|
<set field="paymentAppl.amountApplied" from-field="notAppliedPayment"/>
|
|
</if-empty>
|
|
</if-not-empty>
|
|
|
|
<if-not-empty field="parameters.taxAuthGeoId">
|
|
<if-empty field="paymentAppl.amountApplied">
|
|
<set field="paymentAppl.amountApplied" from-field="notAppliedPayment"/>
|
|
</if-empty>
|
|
</if-not-empty>
|
|
|
|
<sequenced-id sequence-name="PaymentApplication" field="paymentAppl.paymentApplicationId"/>
|
|
<field-to-result field="paymentAppl.amountApplied" result-name="amountApplied"/>
|
|
<field-to-result field="paymentAppl.paymentApplicationId" result-name="paymentApplicationId"/>
|
|
|
|
<create-value value-field="paymentAppl"/>
|
|
<entity-one entity-name="Payment" value-field="payment"/>
|
|
<field-to-result field="payment.paymentTypeId" result-name="paymentTypeId"/>
|
|
</simple-method>
|
|
|
|
<simple-method method-name="setPaymentStatus" short-description="Set The Payment Status">
|
|
<entity-one entity-name="Payment" value-field="payment"/>
|
|
<entity-one entity-name="StatusItem" value-field="statusItem">
|
|
<field-map field-name="statusId" from-field="parameters.statusId"/>
|
|
</entity-one>
|
|
<field-to-result field="payment.statusId" result-name="oldStatusId"/>
|
|
|
|
<if-compare-field field="payment.statusId" to-field="parameters.statusId" operator="not-equals">
|
|
<entity-one entity-name="StatusValidChange" value-field="statusChange" auto-field-map="false">
|
|
<field-map field-name="statusId" from-field="payment.statusId"/>
|
|
<field-map field-name="statusIdTo" from-field="parameters.statusId"/>
|
|
</entity-one>
|
|
<if-empty field="statusChange">
|
|
<add-error>
|
|
<fail-property resource="AccountingUiLabels" property="AccountingPSInvalidStatusChange"/>
|
|
</add-error>
|
|
<log level="error" message="Cannot change from ${payment.statusId} to ${parameters.statusId}"/>
|
|
<check-errors/>
|
|
<else>
|
|
<!-- payment method is mandatory when set to sent or received. -->
|
|
<if>
|
|
<condition>
|
|
<and>
|
|
<or>
|
|
<if-compare field="parameters.statusId" operator="equals" value="PMNT_RECEIVED"/>
|
|
<if-compare field="parameters.statusId" operator="equals" value="PMNT_SENT"/>
|
|
</or>
|
|
<if-empty field="payment.paymentMethodId"/>
|
|
</and>
|
|
</condition>
|
|
<then>
|
|
<add-error>
|
|
<fail-property resource="AccountingUiLabels" property="AccountingMissingPaymentMethod"/>
|
|
</add-error>
|
|
<log level="error" message="Cannot set status to ${parameters.statusId} on payment ${payment.paymentId}: payment method is missing"/>
|
|
<check-errors/>
|
|
</then>
|
|
</if>
|
|
|
|
<!-- check if the payment fully applied when set to confirmed-->
|
|
<if-compare field="parameters.statusId" operator="equals" value="PMNT_CONFIRMED">
|
|
<set field="notYetApplied" value="${groovy:org.apache.ofbiz.accounting.payment.PaymentWorker.getPaymentNotApplied(payment)}"/>
|
|
<if-compare field="notYetApplied" operator="greater" value="0.00" type="BigDecimal">
|
|
<add-error>
|
|
<fail-property resource="AccountingUiLabels" property="AccountingPSNotConfirmedNotFullyApplied"/>
|
|
</add-error>
|
|
<log level="error" message="Cannot change from ${payment.statusId} to ${parameters.statusId}, payment not fully applied: ${notYetapplied}"/>
|
|
<check-errors/>
|
|
</if-compare>
|
|
</if-compare>
|
|
|
|
<if-compare field="parameters.statusId" operator="equals" value="PMNT_CANCELLED">
|
|
<!-- if new status is cancelled delete existing payment applications. -->
|
|
<get-related value-field="payment" relation-name="PaymentApplication" list="paymentApplications"/>
|
|
<iterate list="paymentApplications" entry="paymentApplication">
|
|
<set field="removePaymentApplicationMap.paymentApplicationId" from-field="paymentApplication.paymentApplicationId"/>
|
|
<call-service service-name="removePaymentApplication" in-map-name="removePaymentApplicationMap"/>
|
|
</iterate>
|
|
<!-- if new status is cancelled and the payment is associated to an OrderPaymentPreference, update the status of that record too. -->
|
|
<get-related-one value-field="payment" relation-name="OrderPaymentPreference" to-value-field="orderPaymentPreference"/>
|
|
<if-not-empty field="orderPaymentPreference">
|
|
<set field="updateOrderPaymentPreferenceMap.orderPaymentPreferenceId" from-field="orderPaymentPreference.orderPaymentPreferenceId"/>
|
|
<set field="updateOrderPaymentPreferenceMap.statusId" value="PAYMENT_CANCELLED"/>
|
|
<call-service service-name="updateOrderPaymentPreference" in-map-name="updateOrderPaymentPreferenceMap"/>
|
|
</if-not-empty>
|
|
</if-compare>
|
|
|
|
<!-- everything ok so now change the status field -->
|
|
<set from-field="parameters.statusId" field="payment.statusId"/>
|
|
<store-value value-field="payment"/>
|
|
</else>
|
|
</if-empty>
|
|
</if-compare-field>
|
|
</simple-method>
|
|
|
|
<simple-method method-name="voidPayment" short-description="Service to void a payment">
|
|
<entity-one entity-name="Payment" value-field="payment"/>
|
|
<field-to-result field="payment.finAccountTransId" result-name="finAccountTransId"/>
|
|
<set field="transStatusId" value="FINACT_TRNS_CANCELED"/>
|
|
<field-to-result field="transStatusId" result-name="statusId"/>
|
|
<if-empty field="payment">
|
|
<add-error>
|
|
<fail-property resource="AccountingUiLabels" property="AccountingNoPaymentsfound"/>
|
|
</add-error>
|
|
<check-errors/>
|
|
</if-empty>
|
|
<set field="paymentId" from-field="parameters.paymentId"/>
|
|
<set field="paymentStatusCtx.paymentId" from-field="paymentId"/>
|
|
<set field="paymentStatusCtx.statusId" value="PMNT_VOID"/>
|
|
<call-service service-name="setPaymentStatus" in-map-name="paymentStatusCtx"/>
|
|
<get-related relation-name="PaymentApplication" value-field="payment" list="paymentApplications"/>
|
|
<iterate list="paymentApplications" entry="paymentApplication">
|
|
<get-related-one relation-name="Invoice" value-field="paymentApplication" to-value-field="updateInvoiceCtx"/>
|
|
<if-compare field="updateInvoiceCtx.statusId" operator="equals" value="INVOICE_PAID">
|
|
<set-service-fields service-name="setInvoiceStatus" map="updateInvoiceCtx" to-map="invoiceStatusCtx"/>
|
|
<set field="invoiceStatusCtx.paidDate" type="Timestamp" value=""/>
|
|
<set field="invoiceStatusCtx.statusId" value="INVOICE_READY"/>
|
|
<call-service service-name="setInvoiceStatus" in-map-name="invoiceStatusCtx"/>
|
|
</if-compare>
|
|
<set field="removePaymentApplicationCtx.paymentApplicationId" from-field="paymentApplication.paymentApplicationId"/>
|
|
<call-service service-name="removePaymentApplication" in-map-name="removePaymentApplicationCtx"/>
|
|
</iterate>
|
|
<entity-condition entity-name="AcctgTrans" list="acctgTransPaymentList">
|
|
<condition-list combine="and">
|
|
<condition-expr field-name="invoiceId" operator="equals" from-field="nullField"/>
|
|
<condition-expr field-name="paymentId" from-field="paymentId"/>
|
|
</condition-list>
|
|
</entity-condition>
|
|
<iterate list="acctgTransPaymentList" entry="acctgTransPayment">
|
|
<clear-field field="copyAcctgTransCtx"/>
|
|
<set field="copyAcctgTransCtx.fromAcctgTransId" from-field="acctgTransPayment.acctgTransId"/>
|
|
<set field="copyAcctgTransCtx.revert" value="Y"/>
|
|
<call-service service-name="copyAcctgTransAndEntries" in-map-name="copyAcctgTransCtx">
|
|
<result-to-field result-name="acctgTransId" field="postAcctgTransMap.acctgTransId"/>
|
|
</call-service>
|
|
<if-compare field="acctgTransPayment.isPosted" operator="equals" value="Y">
|
|
<call-service service-name="postAcctgTrans" in-map-name="postAcctgTransMap"/>
|
|
</if-compare>
|
|
<clear-field field="postAcctgTransMap"/>
|
|
</iterate>
|
|
</simple-method>
|
|
|
|
<simple-method method-name="createPaymentAndPaymentGroupForInvoices" short-description="Creates Payments, PaymentApplications and PaymentGroup for the same">
|
|
<entity-one entity-name="PaymentMethod" value-field="paymentMethod" auto-field-map="true"/>
|
|
<entity-one entity-name="FinAccount" value-field="finAccount" auto-field-map="false">
|
|
<field-map field-name="finAccountId" from-field="paymentMethod.finAccountId"/>
|
|
</entity-one>
|
|
<if-compare field="finAccount.statusId" operator="equals" value="FNACT_MANFROZEN">
|
|
<add-error>
|
|
<fail-property resource="AccountingErrorUiLabels.xml" property="AccountingFinAccountInactiveStatusError"/>
|
|
</add-error>
|
|
</if-compare>
|
|
<if-compare field="finAccount.statusId" operator="equals" value="FNACT_CANCELLED">
|
|
<add-error>
|
|
<fail-property resource="AccountingErrorUiLabels.xml" property="AccountingFinAccountStatusNotValidError"/>
|
|
</add-error>
|
|
</if-compare>
|
|
<check-errors/>
|
|
<set field="invoices" type="List"/>
|
|
<iterate list="parameters.invoiceIds" entry="invoiceId">
|
|
<entity-one entity-name="Invoice" value-field="invoice" auto-field-map="true"/>
|
|
<clear-field field="invoices"/>
|
|
<set field="invoices" from-field="partyInvoices.${invoice.partyIdFrom}"/>
|
|
<field-to-list field="invoice" list="invoices"/>
|
|
<set field="partyInvoices.${invoice.partyIdFrom}" from-field="invoices"/>
|
|
</iterate>
|
|
<clear-field field="invoices"/>
|
|
<iterate-map map="partyInvoices" key="partyId" value="invoices">
|
|
<set-service-fields service-name="createPaymentAndApplicationForParty" map="parameters" to-map="createPaymentAndApplicationForPartyMap"/>
|
|
<set field="createPaymentAndApplicationForPartyMap.paymentMethodTypeId" from-field="paymentMethod.paymentMethodTypeId"/>
|
|
<set field="createPaymentAndApplicationForPartyMap.finAccountId" from-field="paymentMethod.finAccountId"/>
|
|
<set field="createPaymentAndApplicationForPartyMap.partyId" from-field="partyId"/>
|
|
<set field="createPaymentAndApplicationForPartyMap.invoices" from-field="invoices"/>
|
|
<if-not-empty field="parameters.checkStartNumber">
|
|
<set field="parameters.checkStartNumber" value="${parameters.checkStartNumber + 1}" type="Long"/>
|
|
</if-not-empty>
|
|
<call-service service-name="createPaymentAndApplicationForParty" in-map-name="createPaymentAndApplicationForPartyMap">
|
|
<result-to-field result-name="paymentId" field="paymentId"/>
|
|
</call-service>
|
|
<field-to-list field="paymentId" list="paymentIds"/>
|
|
</iterate-map>
|
|
<if-not-empty field="paymentIds">
|
|
<set field="createPaymentGroupAndMemberMap.paymentIds" from-field="paymentIds"/>
|
|
<set field="createPaymentGroupAndMemberMap.paymentGroupTypeId" value="CHECK_RUN"/>
|
|
<set field="createPaymentGroupAndMemberMap.paymentGroupName" value="Payment group for Check Run(InvoiceIds-${parameters.invoiceIds})"/>
|
|
<call-service service-name="createPaymentGroupAndMember" in-map-name="createPaymentGroupAndMemberMap">
|
|
<result-to-field result-name="paymentGroupId"/>
|
|
<result-to-result result-name="paymentGroupId"/>
|
|
</call-service>
|
|
</if-not-empty>
|
|
<if-empty field="paymentGroupId">
|
|
<property-to-field property="AccountingNoInvoicesReadyOrOutstandingAmountZero" resource="AccountingUiLabels" field="errorMessage"/>
|
|
<field-to-result field="errorMessage" result-name="errorMessage"/>
|
|
</if-empty>
|
|
</simple-method>
|
|
|
|
<simple-method method-name="createPaymentGroupAndMember" short-description="creates PaymentGroup and PaymentGroupMembers">
|
|
<if-empty field="parameters.fromDate">
|
|
<now-timestamp field="parameters.fromDate"/>
|
|
</if-empty>
|
|
<set-service-fields service-name="createPaymentGroup" map="parameters" to-map="createPaymentGroupMap"/>
|
|
<if-empty field="parameters.paymentGroupName">
|
|
<set field="createPaymentGroupMap.paymentGroupName" value="Payment Group Name"/>
|
|
</if-empty>
|
|
<call-service service-name="createPaymentGroup" in-map-name="createPaymentGroupMap">
|
|
<result-to-field result-name="paymentGroupId"/>
|
|
<result-to-result result-name="paymentGroupId"/>
|
|
</call-service>
|
|
<set field="createPaymentGroupMemberMap.paymentGroupId" from-field="paymentGroupId"/>
|
|
<set field="createPaymentGroupMemberMap.fromDate" from-field="parameters.fromDate"/>
|
|
<iterate list="parameters.paymentIds" entry="paymentId">
|
|
<set field="createPaymentGroupMemberMap.paymentId" from-field="paymentId"/>
|
|
<call-service service-name="createPaymentGroupMember" in-map-name="createPaymentGroupMemberMap"/>
|
|
</iterate>
|
|
</simple-method>
|
|
|
|
<simple-method method-name="checkAndCreateBatchForValidPayments" short-description="Check the valid(unbatched) payment and create batch for same">
|
|
<set field="paymentIds" from-field="parameters.paymentIds"/>
|
|
<entity-condition entity-name="Payment" list="payments">
|
|
<condition-expr field-name="paymentId" operator="in" from-field="paymentIds"/>
|
|
</entity-condition>
|
|
<iterate list="payments" entry="payment">
|
|
<set field="isReceipt" value="${groovy:org.apache.ofbiz.accounting.util.UtilAccounting.isReceipt(payment)}" type="Boolean"/>
|
|
<if-compare field="isReceipt" operator="equals" value="false" type="Boolean">
|
|
<field-to-list field="payment.paymentId" list="disbursementPaymentIds"/>
|
|
</if-compare>
|
|
</iterate>
|
|
<if-not-empty field="disbursementPaymentIds">
|
|
<add-error>
|
|
<fail-property resource="AccountingUiLabels" property="AccountingCannotIncludeApPaymentError"/>
|
|
</add-error>
|
|
<check-errors/>
|
|
</if-not-empty>
|
|
<entity-condition entity-name="PaymentGroupMember" list="paymentGroupMembers" filter-by-date="true">
|
|
<condition-expr field-name="paymentId" operator="in" from-field="paymentIds"/>
|
|
</entity-condition>
|
|
<if-not-empty field="paymentGroupMembers">
|
|
<set field="batchPaymentIds" value="${groovy:org.apache.ofbiz.entity.util.EntityUtil.getFieldListFromEntityList(paymentGroupMembers, 'paymentId', true);}" type="List"/>
|
|
<add-error>
|
|
<fail-property resource="AccountingUiLabels" property="AccountingPaymentsAreAlreadyBatchedError"/>
|
|
</add-error>
|
|
<check-errors/>
|
|
<else>
|
|
<set-service-fields service-name="createPaymentGroupAndMember" map="parameters" to-map="createPaymentGroupAndMemberMap"/>
|
|
<call-service service-name="createPaymentGroupAndMember" in-map-name="createPaymentGroupAndMemberMap">
|
|
<result-to-result result-name="paymentGroupId"/>
|
|
</call-service>
|
|
</else>
|
|
</if-not-empty>
|
|
</simple-method>
|
|
<simple-method method-name="createPaymentFromOrder" short-description="Service auto create Payment from Order when payment does exist yet and not disabled by accounting config">
|
|
<entity-one entity-name="OrderHeader" value-field="orderHeader"/>
|
|
|
|
<if-compare operator="equals" value="PURCHASE_ORDER" field="orderHeader.orderTypeId">
|
|
<property-to-field resource="accounting" property="accounting.payment.purchaseorder.autocreate" field="purchaseAutoCreate" default="Y"/>
|
|
<if-compare operator="not-equals" value="Y" field="purchaseAutoCreate">
|
|
<log level="info" message="payment not created from approved order because config (accounting.payment.purchaseorder.autocreate) is not set to Y (accounting.properties)"/>
|
|
<return/>
|
|
</if-compare>
|
|
</if-compare>
|
|
|
|
<if-compare operator="equals" value="SALES_ORDER" field="orderHeader.orderTypeId">
|
|
<property-to-field resource="accounting" property="accounting.payment.salesorder.autocreate" field="salesAutoCreate" default="Y"/>
|
|
<if-compare operator="not-equals" value="Y" field="salesAutoCreate">
|
|
<log level="info" message="payment not created from approved order because config (accounting.payment.salesorder.autocreate) is not set to Y (accounting.properties)"/>
|
|
<return/>
|
|
</if-compare>
|
|
</if-compare>
|
|
<!-- check if orderPaymentPreference with payment already exist, if yes do not re-create -->
|
|
<entity-condition entity-name="OrderPaymentPrefAndPayment" list="orderPaymentPrefAndPayments">
|
|
<condition-list combine="and">
|
|
<condition-expr field-name="orderId" operator="equals" from-field="orderHeader.orderId"/>
|
|
<condition-expr field-name="statusId" operator="not-equals" value="PAYMENT_CANCELLED"/>
|
|
</condition-list>
|
|
</entity-condition>
|
|
|
|
<if-not-empty field="orderPaymentPrefAndPayments">
|
|
<log level="info" message="Payment not created for order ${orderHeader.orderId}, at least a single payment already exists"/>
|
|
<return/>
|
|
</if-not-empty>
|
|
|
|
<entity-and entity-name="OrderRole" list="orderRoleToList">
|
|
<field-map field-name="orderId" from-field="orderHeader.orderId"/>
|
|
<field-map field-name="roleTypeId" value="BILL_FROM_VENDOR"/>
|
|
</entity-and>
|
|
<first-from-list entry="orderRoleTo" list="orderRoleToList"/>
|
|
<entity-and entity-name="OrderRole" list="orderRoleFromList">
|
|
<field-map field-name="orderId" from-field="orderHeader.orderId"/>
|
|
<field-map field-name="roleTypeId" value="BILL_TO_CUSTOMER"/>
|
|
</entity-and>
|
|
<first-from-list entry="orderRoleFrom" list="orderRoleFromList"/>
|
|
<if-compare operator="equals" value="PURCHASE_ORDER" field="orderHeader.orderTypeId">
|
|
<entity-and entity-name="Agreement" list="agreementList" filter-by-date="true">
|
|
<field-map field-name="partyIdFrom" from-field="orderRoleFrom.partyId"/>
|
|
<field-map field-name="partyIdTo" from-field="orderRoleTo.partyId"/>
|
|
<field-map field-name="agreementTypeId" value="PURCHASE_AGREEMENT"/>
|
|
</entity-and>
|
|
<set field="parameters.paymentTypeId" value="VENDOR_PAYMENT"/>
|
|
<set field="organizationPartyId" from-field="orderRoleFrom.partyId"/>
|
|
<else>
|
|
<entity-and entity-name="Agreement" list="agreementList" filter-by-date="true">
|
|
<field-map field-name="partyIdFrom" from-field="orderRoleFrom.partyId"/>
|
|
<field-map field-name="partyIdTo" from-field="orderRoleTo.partyId"/>
|
|
<field-map field-name="agreementTypeId" value="SALES_AGREEMENT"/>
|
|
</entity-and>
|
|
<set field="parameters.paymentTypeId" value="CUSTOMER_PAYMENT"/>
|
|
<set field="organizationPartyId" from-field="orderRoleTo.partyId"/>
|
|
</else>
|
|
</if-compare>
|
|
<first-from-list entry="agreement" list="agreementList"/>
|
|
<if-not-empty field="agreement">
|
|
<entity-and entity-name="OrderTerm" list="orderTermList">
|
|
<field-map field-name="orderId" from-field="orderHeader.orderId"/>
|
|
<field-map field-name="termTypeId" value="FIN_PAYMENT_TERM"/>
|
|
</entity-and>
|
|
<first-from-list entry="orderTerm" list="orderTermList"/>
|
|
<if-not-empty field="orderTerm.termDays">
|
|
<set field="days" from-field="orderTerm.termDays" type="Integer"/>
|
|
<now-timestamp field="start"/>
|
|
<call-class-method class-name="org.apache.ofbiz.base.util.UtilDateTime" method-name="addDaysToTimestamp" ret-field="parameters.effectiveDate">
|
|
<field field="start" type="java.sql.Timestamp"/>
|
|
<field field="days" type="int"/>
|
|
</call-class-method>
|
|
</if-not-empty>
|
|
</if-not-empty>
|
|
<if-empty field="parameters.effectiveDate">
|
|
<now-timestamp field="parameters.effectiveDate"/>
|
|
</if-empty>
|
|
|
|
<!-- check currency and when required use invoice currency rate or convert when invoice not available -->
|
|
<set field="partyAccountingPreferencesMap.organizationPartyId" from-field="organizationPartyId"/>
|
|
<call-service service-name="getPartyAccountingPreferences" in-map-name="partyAccountingPreferencesMap">
|
|
<result-to-field result-name="partyAccountingPreference" field="partyAcctgPreference"/>
|
|
</call-service>
|
|
<if>
|
|
<condition>
|
|
<and>
|
|
<not>
|
|
<if-empty field="partyAcctgPreference.baseCurrencyUomId" />
|
|
</not>
|
|
<if-compare-field field="orderHeader.currencyUom" operator="equals" to-field="partyAcctgPreference.baseCurrencyUomId"/>
|
|
</and>
|
|
</condition>
|
|
<then>
|
|
<set field="parameters.currencyUomId" from-field="orderHeader.currencyUom" />
|
|
<set field="parameters.amount" from-field="orderHeader.grandTotal" />
|
|
<!-- get conversion rate from related invoice when exists -->
|
|
<entity-and entity-name="OrderItemBillingAndInvoiceAndItem" list="invoices">
|
|
<field-map field-name="orderId" from-field="orderId" />
|
|
</entity-and>
|
|
<if-not-empty field="invoices">
|
|
<entity-one entity-name="Invoice" value-field="invoice">
|
|
<field-map field-name="invoiceId" from-field="invoices[0].invoiceId" />
|
|
</entity-one>
|
|
<set field="convertUomInMap.asOfDate" from-field="invoice.invoiceDate" />
|
|
</if-not-empty>
|
|
<set field="convertUomInMap.originalValue" from-field="orderHeader.grandTotal" />
|
|
<set field="convertUomInMap.uomId" from-field="orderHeader.currencyUom" />
|
|
<set field="convertUomInMap.uomIdTo" from-field="partyAcctgPreference.baseCurrencyUomId" />
|
|
<log level="info" message="convertUomInMap = ${convertUomInMap}"/>
|
|
<call-service service-name="convertUom" in-map-name="convertUomInMap">
|
|
<result-to-field result-name="convertedValue" field="parameters.amount" />
|
|
</call-service>
|
|
<set field="parameters.actualCurrencyAmount" from-field="orderHeader.grandTotal" />
|
|
<set field="parameters.actualCurrencyUomId" from-field="orderHeader.currencyUom" />
|
|
<set field="parameters.currencyUomId" from-field="partyAcctgPreference.baseCurrencyUomId" />
|
|
</then>
|
|
<else>
|
|
<set field="parameters.currencyUomId" from-field="orderHeader.currencyUom" />
|
|
<set field="parameters.amount" from-field="orderHeader.grandTotal" />
|
|
</else>
|
|
</if>
|
|
|
|
<set field="parameters.partyIdFrom" from-field="orderRoleFrom.partyId"/>
|
|
<set field="parameters.partyIdTo" from-field="orderRoleTo.partyId"/>
|
|
<set field="parameters.paymentMethodTypeId" value="COMPANY_ACCOUNT"/>
|
|
<set field="parameters.statusId" value="PMNT_NOT_PAID"/>
|
|
<set-service-fields service-name="createPayment" map="parameters" to-map="createPayment"/>
|
|
<call-service service-name="createPayment" in-map-name="createPayment">
|
|
<result-to-field result-name="paymentId" field="parameters.paymentId"/>
|
|
</call-service>
|
|
<set field="parameters.orderId" from-field="orderHeader.orderId"/>
|
|
<set field="parameters.maxAmount" from-field="orderHeader.grandTotal"/>
|
|
|
|
<set-service-fields service-name="createOrderPaymentPreference" map="parameters" to-map="newOrderPaymentPreference"/>
|
|
<call-service service-name="createOrderPaymentPreference" in-map-name="newOrderPaymentPreference">
|
|
<result-to-field result-name="orderPaymentPreferenceId" field="parameters.paymentPreferenceId"/>
|
|
</call-service>
|
|
<set-service-fields service-name="updatePayment" map="parameters" to-map="updatePayment"/>
|
|
<call-service service-name="updatePayment" in-map-name="updatePayment"/>
|
|
<field-to-result field="parameters.paymentId" result-name="paymentId"/>
|
|
<log level="info" message="payment ${parameters.paymentId} with the not-paid status automatically created from order: ${parameters.orderId} (can be disabled in accounting.properties)"/>
|
|
</simple-method>
|
|
|
|
<simple-method method-name="createMatchingPaymentApplication" short-description="Create a payment application if either the invoice of payment could be found">
|
|
<property-to-field resource="accounting" property="accounting.payment.application.autocreate" field="autoCreate" default="Y"/>
|
|
<if-compare operator="not-equals" value="Y" field="autoCreate">
|
|
<log level="info" message="payment application not automatically created because config is not set to Y"/>
|
|
<return/>
|
|
</if-compare>
|
|
|
|
<if-not-empty field="parameters.invoiceId">
|
|
<entity-one entity-name="Invoice" value-field="invoice"/>
|
|
<if-not-empty field="invoice">
|
|
<call-class-method method-name="getInvoiceTotal" class-name="org.apache.ofbiz.accounting.invoice.InvoiceWorker" ret-field="invoiceTotal">
|
|
<field field="invoice" type="GenericValue"/>
|
|
</call-class-method>
|
|
|
|
<set field="checkInvoice.invoiceId" from="invoice.invoiceId"/>
|
|
<call-service service-name="isInvoiceInForeignCurrency" in-map-name="checkInvoice">
|
|
<result-to-field result-name="isForeign"/>
|
|
</call-service>
|
|
<if-compare operator="equals" value="true" field="isForeign">
|
|
<entity-condition entity-name="Payment" list="payments">
|
|
<condition-list combine="and">
|
|
<condition-expr field-name="statusId" value="PMNT_CONFIRMED" operator="not-equals"/>
|
|
<condition-expr field-name="partyIdFrom" operator="equals" from-field="invoice.partyId"/>
|
|
<condition-expr field-name="partyIdTo" operator="equals" from-field="invoice.partyIdFrom"/>
|
|
<condition-expr field-name="actualCurrencyAmount" operator="equals" from-field="invoiceTotal"/>
|
|
<condition-expr field-name="actualCurrencyUomId" operator="equals" from-field="invoice.currencyUomId"/>
|
|
</condition-list>
|
|
<order-by field-name="effectiveDate"/>
|
|
</entity-condition>
|
|
<else>
|
|
<entity-condition entity-name="Payment" list="payments">
|
|
<condition-list combine="and">
|
|
<condition-expr field-name="statusId" value="PMNT_CONFIRMED" operator="not-equals"/>
|
|
<condition-expr field-name="partyIdFrom" operator="equals" from-field="invoice.partyId"/>
|
|
<condition-expr field-name="partyIdTo" operator="equals" from-field="invoice.partyIdFrom"/>
|
|
<condition-expr field-name="amount" operator="equals" from-field="invoiceTotal"/>
|
|
<condition-expr field-name="currencyUomId" operator="equals" from-field="invoice.currencyUomId"/>
|
|
</condition-list>
|
|
<order-by field-name="effectiveDate"/>
|
|
</entity-condition>
|
|
</else>
|
|
</if-compare>
|
|
|
|
<if-not-empty field="payments">
|
|
<!-- check if already applied -->
|
|
<entity-and entity-name="PaymentApplication" list="paymentAppls">
|
|
<field-map field-name="paymentId" from-field="payments[0].paymentId"/>
|
|
</entity-and>
|
|
<if-empty field="paymentAppls">
|
|
<set field="createAppl.paymentId" from-field="payments[0].paymentId"/>
|
|
<set field="createAppl.invoiceId" from-field="parameters.invoiceId"/>
|
|
<if-compare operator="equals" value="true" field="isForeign">
|
|
<set field="createAppl.amountApplied" from-field="payments[0].actualCurrencyAmount"/>
|
|
<else>
|
|
<set field="createAppl.amountApplied" from-field="payments[0].amount"/>
|
|
</else>
|
|
</if-compare>
|
|
</if-empty>
|
|
</if-not-empty>
|
|
</if-not-empty>
|
|
</if-not-empty>
|
|
|
|
<if-not-empty field="parameters.paymentId">
|
|
<entity-one entity-name="Payment" value-field="payment"/>
|
|
<if-not-empty field="payment">
|
|
|
|
<entity-condition entity-name="Invoice" list="invoices">
|
|
<condition-list combine="and">
|
|
<condition-expr field-name="statusId" value="INVOICE_READY" operator="not-equals"/>
|
|
<condition-expr field-name="statusId" value="INVOICE_PAID" operator="not-equals"/>
|
|
<condition-expr field-name="statusId" value="INVOICE_CANCELLED" operator="not-equals"/>
|
|
<condition-expr field-name="statusId" value="INVOICE_WRITEOFF" operator="not-equals"/>
|
|
<condition-expr field-name="partyIdFrom" from-field="payment.partyIdTo"/>
|
|
<condition-expr field-name="partyId" from-field="payment.partyIdFrom"/>
|
|
</condition-list>
|
|
<order-by field-name="invoiceDate"/>
|
|
</entity-condition>
|
|
<iterate list="invoices" entry="invoice">
|
|
<set field="isPurchaseInvoice" value="${groovy: org.apache.ofbiz.entity.util.EntityTypeUtil.hasParentType(delegator, 'InvoiceType', 'invoiceTypeId', invoice.getString('invoiceTypeId'), 'parentTypeId', 'PURCHASE_INVOICE')}" type="Boolean"/>
|
|
<set field="isSalesInvoice" value="${groovy: org.apache.ofbiz.entity.util.EntityTypeUtil.hasParentType(delegator, 'InvoiceType', 'invoiceTypeId', invoice.getString('invoiceTypeId'), 'parentTypeId', 'SALES_INVOICE')}" type="Boolean"/>
|
|
<if>
|
|
<condition>
|
|
<or>
|
|
<if-compare field="isPurchaseInvoice" operator="equals" value="true" type="Boolean"/>
|
|
<if-compare field="isSalesInvoice" operator="equals" value="true" type="Boolean"/>
|
|
</or>
|
|
</condition>
|
|
<then>
|
|
<call-class-method method-name="getInvoiceTotal" class-name="org.apache.ofbiz.accounting.invoice.InvoiceWorker" ret-field="invoiceTotal">
|
|
<field field="invoice" type="GenericValue"/>
|
|
</call-class-method>
|
|
|
|
<set field="checkInvoice.invoiceId" from="invoice.invoiceId"/>
|
|
<call-service service-name="isInvoiceInForeignCurrency" in-map-name="checkInvoice">
|
|
<result-to-field result-name="isForeign"/>
|
|
</call-service>
|
|
<if-compare operator="equals" value="true" field="isForeign">
|
|
<if-compare-field field="invoiceTotal" operator="equals" to-field="payment.actualCurrencyAmount">
|
|
<if-compare-field field="invoice.currencyUomId" operator="equals" to-field="payment.actualCurrencyUomId">
|
|
<set field="invoiceId" from-field="invoice.invoiceId"/>
|
|
<set field="amountApplied" from-field="payment.actualCurrencyAmount"/>
|
|
</if-compare-field>
|
|
</if-compare-field>
|
|
<else>
|
|
<if-compare-field field="invoiceTotal" operator="equals" to-field="payment.amount">
|
|
<if-compare-field field="invoice.currencyUomId" operator="equals" to-field="payment.currencyUomId">
|
|
<set field="invoiceId" from-field="invoice.invoiceId"/>
|
|
<set field="amountApplied" from-field="payment.amount"/>
|
|
</if-compare-field>
|
|
</if-compare-field>
|
|
</else>
|
|
</if-compare>
|
|
</then>
|
|
</if>
|
|
</iterate>
|
|
<if-not-empty field="invoiceId">
|
|
<entity-and entity-name="PaymentApplication" list="paymentAppls">
|
|
<field-map field-name="invoiceId" from-field="invoiceId"/>
|
|
</entity-and>
|
|
<if-empty field="paymentAppls">
|
|
<set field="createAppl.paymentId" from-field="parameters.paymentId"/>
|
|
<set field="createAppl.invoiceId" from-field="invoiceId"/>
|
|
<set field="createAppl.amountApplied" from-field="amountApplied"/>
|
|
</if-empty>
|
|
</if-not-empty>
|
|
</if-not-empty>
|
|
</if-not-empty>
|
|
|
|
<if-not-empty field="createAppl.paymentId">
|
|
<if-not-empty field="createAppl.invoiceId">
|
|
<call-service service-name="createPaymentApplication" in-map-name="createAppl"/>
|
|
<log level="info" message="payment application automatically created between invoiceId: ${createAppl.invoiceId} and paymentId: ${createAppl.paymentId} for the amount: ${createAppl.appliedAmount} (can be disabled in accounting.properties)"/>
|
|
</if-not-empty>
|
|
</if-not-empty>
|
|
</simple-method>
|
|
</simple-methods>
|