OFBiz
  1. OFBiz
  2. OFBIZ-1434 General Ledger
  3. OFBIZ-1483

Implement an automatic GL posting service for purchase invoices

    Details

    • Type: Sub-task Sub-task
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: SVN trunk
    • Fix Version/s: None
    • Component/s: accounting
    • Labels:
      None

      Description

      Name of the service: "createAcctgTransForPurchaseInvoice" or similar
      Service definition:
      <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>

      The eca rule will be:

      <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>

      This is the general description: this service will call the createAcctgTransAndEntries with the following input parameters:
      a) acctgTransTypeId="PURCHASE_INVOICE"
      b) partyId = invoice.partyIdFrom
      c) roleTypeId = "BILL_FROM_VENDOR"
      d) invoiceId = invoice.invoiceId
      e) acctgTransEntries: a list composed by the following AcctgTransEntry elements:
      e1) for each element of the InvoiceItems:
      e1.1) compute the value amountFromInvoice = invoiceItem.quantity * invoiceItem.amount (NOTE: if quantity is not set, then default to 1)
      e1.2) get the list of OrderItemBilling records associated to the item and iterate over them, getting the OrderItem associated and computing the following amount: OrderItemBilling.quantity * OrderItem.unitPrice; compute the sum of all the values in the iteration (amountFromOrder);

      e1.3) if (amountFromInvoice != amountFromOrder and amountFromOrder > 0) then prepare an AcctgTransEntry with the following values:
      – debitCreditFlag = D
      – organizationPartyId = invoice.partyId
      – partyId = invoice.partyIdFrom
      – roleTypeId = "BILL_FROM_VENDOR"
      – productId = invoiceItem.productId
      – glAccountTypeId = PURCHASE_PRICE_VAR
      – origAmount = amountFromInvoice - amountFromOrder
      – origCurrencyUomId = invoice.currencyUomId

      e1.4) prepare an AcctgTransEntry with the following values:
      – debitCreditFlag = D
      – organizationPartyId = invoice.partyId
      – partyId = invoice.partyIdFrom
      – roleTypeId = "BILL_FROM_VENDOR"
      – productId = invoiceItem.productId
      – glAccountTypeId = invoiceItem.invoiceItemTypeId
      – glAccountId = invoiceItem.overrideGlAccountId
      – origAmount = if (amountFromOrder > 0) then amountFromOrder else amountFromInvoice
      – origCurrencyUomId = invoice.currencyUomId

      f) one element for the invoice total (the sum of all the items' amount*quantity):
      – debitCreditFlag = C
      – organizationPartyId = invoice.partyId
      – glAccountTypeId = ACCOUNTS_PAYABLE
      – origAmount = the sum of all the items' amountFromInvoice
      – origCurrencyUomId = invoice.currencyUomId
      – partyId = invoice.partyIdFrom
      – roleTypeId = "BILL_FROM_VENDOR"

      Some more details about the logic:

      1) get the Invoice record
      2) if Invoice.invoiceTypeId != PURCHASE_INVOICE return
      3) get the InvoiceItems and iterate over them to create the entries (e) and compute the total for the entry for the total (f)
      4) call the createAcctgTransAndEntries service

      Add information on the wiki page: http://docs.ofbiz.org/x/Qw0

      1. GL_Purchase_Invoice.patch
        11 kB
        Alok Agnihotri
      2. GL_Purchase_Invoice.patch
        10 kB
        Pranay Pandey
      3. GL_Purchase_Invoice.patch
        10 kB
        Alok Agnihotri

        Activity

        Jacopo Cappellato created issue -
        Jacopo Cappellato made changes -
        Field Original Value New Value
        Assignee Jacopo Cappellato [ jacopoc ]
        Jacopo Cappellato made changes -
        Assignee Jacopo Cappellato [ jacopoc ]
        Description Name of the service: "createAcctgTransForPurchaseInvoice" or similar
        Service definition:
            <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>

        The eca rule will be:

        <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>

        This is the general description: this service will call the createAcctgTransAndEntries with the following input parameters:
        a) acctgTransTypeId="PURCHASE_INVOICE"
        b) partyId = invoice.partyIdFrom
        c) roleTypeId = "BILL_FROM_VENDOR"
        d) invoiceId = invoice.invoiceId
        e) acctgTransEntries: a list composed by the following AcctgTransEntry elements:
        e1) one element for each of the InvoiceItems; here is the content of each of these elements:
        -- debitCreditFlag = D
        -- organizationPartyId = invoice.partyId
        -- partyId = invoice.partyIdFrom
        -- roleTypeId = "BILL_FROM_VENDOR"
        -- productId = invoiceItem.productId
        -- glAccountTypeId = invoiceItem.invoiceItemTypeId
        -- glAccountId = invoiceItem.overrideGlAccountId
        TODO: work in progress
        -- origAmount = invoiceItem.quantity * invoiceItem.amount (NOTE: if quantity is not set, then default to 1)
        -- origCurrencyUomId = invoice.currencyUomId
        f) one element for the invoice total (the sum of all the items' amount*quantity):
        -- debitCreditFlag = C
        -- organizationPartyId = invoice.partyId
        -- glAccountTypeId = ACCOUNTS_PAYABLE
        -- origAmount = the sum of all the items' amount*quantity
        -- origCurrencyUomId = invoice.currencyUomId
        -- partyId = invoice.partyIdFrom
        -- roleTypeId = "BILL_FROM_VENDOR"

        Some more details about the logic:

        1) get the Invoice record
        2) if Invoice.invoiceTypeId != PURCHASE_INVOICE return
        3) get the InvoiceItems and iterate over them to create the entries (e) and compute the total for the entry for the total (f)
        4) call the createAcctgTransAndEntries service

        Add information on the wiki page: http://docs.ofbiz.org/x/Qw0
        Name of the service: "createAcctgTransForPurchaseInvoice" or similar
        Service definition:
            <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>

        The eca rule will be:

        <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>

        This is the general description: this service will call the createAcctgTransAndEntries with the following input parameters:
        a) acctgTransTypeId="PURCHASE_INVOICE"
        b) partyId = invoice.partyIdFrom
        c) roleTypeId = "BILL_FROM_VENDOR"
        d) invoiceId = invoice.invoiceId
        e) acctgTransEntries: a list composed by the following AcctgTransEntry elements:
        e1) for each element of the InvoiceItems:
        e1.1) compute the value amountFromInvoice = invoiceItem.quantity * invoiceItem.amount (NOTE: if quantity is not set, then default to 1)
        e1.2) get the list of OrderItemBilling records associated to the item and iterate over them, getting the OrderItem associated and computing the following amount: OrderItemBilling.quantity * OrderItem.unitPrice; compute the sum of all the values in the iteration (amountFromOrder);

        e1.3) if (amountFromInvoice != amountFromOrder and amountFromOrder > 0) then prepare an AcctgTransEntry with the following values:
        -- debitCreditFlag = D
        -- organizationPartyId = invoice.partyId
        -- partyId = invoice.partyIdFrom
        -- roleTypeId = "BILL_FROM_VENDOR"
        -- productId = invoiceItem.productId
        -- glAccountTypeId = PURCHASE_PRICE_VAR
        -- origAmount = amountFromInvoice - amountFromOrder
        -- origCurrencyUomId = invoice.currencyUomId

        e1.4) prepare an AcctgTransEntry with the following values:
        -- debitCreditFlag = D
        -- organizationPartyId = invoice.partyId
        -- partyId = invoice.partyIdFrom
        -- roleTypeId = "BILL_FROM_VENDOR"
        -- productId = invoiceItem.productId
        -- glAccountTypeId = invoiceItem.invoiceItemTypeId
        -- glAccountId = invoiceItem.overrideGlAccountId
        -- origAmount = if (amountFromOrder > 0) then amountFromOrder else amountFromInvoice
        -- origCurrencyUomId = invoice.currencyUomId

        f) one element for the invoice total (the sum of all the items' amount*quantity):
        -- debitCreditFlag = C
        -- organizationPartyId = invoice.partyId
        -- glAccountTypeId = ACCOUNTS_PAYABLE
        -- origAmount = the sum of all the items' amountFromInvoice
        -- origCurrencyUomId = invoice.currencyUomId
        -- partyId = invoice.partyIdFrom
        -- roleTypeId = "BILL_FROM_VENDOR"

        Some more details about the logic:

        1) get the Invoice record
        2) if Invoice.invoiceTypeId != PURCHASE_INVOICE return
        3) get the InvoiceItems and iterate over them to create the entries (e) and compute the total for the entry for the total (f)
        4) call the createAcctgTransAndEntries service

        Add information on the wiki page: http://docs.ofbiz.org/x/Qw0
        Anil K Patel made changes -
        Assignee Anil K Patel [ anilpatel ]
        Alok Agnihotri made changes -
        Attachment GL_Purchase_Invoice.patch [ 12371287 ]
        Pranay Pandey made changes -
        Attachment GL_Purchase_Invoice.patch [ 12371645 ]
        Alok Agnihotri made changes -
        Attachment GL_Purchase_Invoice.patch [ 12371725 ]
        Ashish Vijaywargiya made changes -
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Closed [ 6 ]
        Gavin made changes -
        Workflow jira [ 12418434 ] OFbiz Workflow [ 12505491 ]

          People

          • Assignee:
            Anil K Patel
            Reporter:
            Jacopo Cappellato
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development