Implement an automatic GL posting service for outgoing payments
---------------------------------------------------------------

                 Key: OFBIZ-1491
                 URL: https://issues.apache.org/jira/browse/OFBIZ-1491
             Project: OFBiz
          Issue Type: Sub-task
          Components: accounting
            Reporter: Jacopo Cappellato


The service is very similar to the one described in OFBIZ-1490.

Name of the service: "createAcctgTransAndEntriesForOutgoingPayment" or similar
Service definition:
    <service name="createAcctgTransAndEntriesForOutgoingPayment" 
engine="simple" auth="true"
        location="org/ofbiz/accounting/ledger/GeneralLedgerServices.xml" 
invoke="createAcctgTransAndEntriesForOutgoingPayment">
        <description>Create an accounting transaction for an outgoing 
payment</description>
        <attribute name="paymentId" type="String" mode="IN" optional="false"/>
        <attribute name="acctgTransId" type="String" mode="OUT" 
optional="true"/>
    </service>

1) get the Payment by paymentId
2) if (!UtilAccounting.isDisbursement(payment)) then return; (hint: in 
Minilang, use the "call-class-method" operation)
3) organizationPartyId = payment.partyIdFrom
4) partyId = payment.partyIdTo and roleTypeId = "BILL_FROM_VENDOR"

5) create an AcctgTransEntry with:
5.1) debitCreditFlag=C, glAccountTypeId: do not set for now (<!--TODO-->), 
origAmount=payment.amount, origCurrencyUomId=payment.currencyUomId

6) get the debitGlAccountTypeId in the following way:
6.1) get the PaymentGlAccountTypeMap for the given Payment.paymentTypeId and 
organizationPartyId
6.2) debitGlAccountTypeId = PaymentGlAccountTypeMap.glAccountTypeId

7) for the debit entries: select the PaymentApplications associated to the 
Payment and for each one:
7.1) create a AcctgTransEntry with:
debitCreditFlag=D,
origAmount=paymentApplication.amountApplied,
origCurrencyUomId=payment.currencyUomId,
glAccountTypeId=debitGlAccountTypeId,
glAccountId=paymentApplication.overrideGlAccountId OR
                     if (paymentApplication.taxAuthGeoId is not empty) get the 
glAccountId from the TaxAuthorityGlAccount record using as constraints 
organizationPartyId, taxAuthGeoId, taxAuthPartyId=partyId, OR
                     payment.overrideGlAccountId
7.2) amountAppliedTotal = amountAppliedTotal + paymentApplication.amountApplied
8) if ((payment.amount - amountAppliedTotal) > 0) then create another debit 
entry with: debitCreditFlag=D, origAmount=(payment.amount - 
amountAppliedTotal), origCurrencyUomId=payment.currencyUomId, 
glAccountId=payment.overrideGlAccountId, glAccountTypeId=debitGlAccountTypeId

9) call the createAcctgTransAndEntries with the following fields
9.1) acctgTransEntries prepared at points 5, 7 and 8
9.2) acctgTransTypeId="OUTGOING_PAYMENT"
9.3) partyId e roleTypeId (point 4), paymentId

Add the following secas to trigger the service:

<eca service="createPayment" event="commit">
    <condition field-name="statusId" operator="equals" value="PMNT_SENT"/>
    <action service="createAcctgTransAndEntriesForOutgoingPayment" mode="sync"/>
</eca>
<eca service="setPaymentStatus" event="commit">
    <condition field-name="statusId" operator="equals" value="PMNT_SENT"/>
    <condition field-name="oldStatusId" operator="not-equals" 
value="PMNT_SENT"/>
    <action service="createAcctgTransAndEntriesForOutgoingPayment" mode="sync"/>
</eca> 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to