This is an automated email from the ASF dual-hosted git repository. nmalin pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push: new 4112f1c Improved: Convert createInvoiceItemPayrol service from mini-lang to groovy DSL (OFBIZ-11503) 4112f1c is described below commit 4112f1cb4b750690ebdeb1cfd76dcc7b45bde0c9 Author: Nicolas Malin <nicolas.ma...@nereide.fr> AuthorDate: Fri Sep 17 15:19:24 2021 +0200 Improved: Convert createInvoiceItemPayrol service from mini-lang to groovy DSL (OFBIZ-11503) Thanks to Nitish Mishra for started this issue --- .../groovyScripts/invoice/InvoiceServices.groovy | 35 ++++++++++++++++++-- .../accounting/minilang/invoice/InvoiceEvents.xml | 37 +--------------------- .../webapp/accounting/WEB-INF/controller.xml | 2 +- 3 files changed, 35 insertions(+), 39 deletions(-) diff --git a/applications/accounting/groovyScripts/invoice/InvoiceServices.groovy b/applications/accounting/groovyScripts/invoice/InvoiceServices.groovy index 83745ac..bf17d4b 100644 --- a/applications/accounting/groovyScripts/invoice/InvoiceServices.groovy +++ b/applications/accounting/groovyScripts/invoice/InvoiceServices.groovy @@ -125,7 +125,38 @@ def invoiceSequenceRestart() { //get the current year string for prefix, etc; simple 4 digit year date string (using system defaults) Integer curYearString = UtilDateTime.getYear(partyAcctgPreference.lastInvoiceRestartDate, timeZone, locale) - result.invoiceId = "${curYearString}-${partyAcctgPreference.lastInvoiceNumber}" - return result + return success(invoiceId: "${curYearString}-${partyAcctgPreference.lastInvoiceNumber}") +} + +//Create a new Invoice Item with Payrol Item Type +def createInvoiceItemPayrol() { + List<GenericValue> payRolList = from("InvoiceItemType").queryList() + from("InvoiceItemType") + .where("parentTypeId", "PAYROL") + .queryList() + .each { payRolGroup -> + payRolList.each { payRol -> + if (payRol.parentTypeId == payRolGroup.invoiceItemTypeId) { + Map createInvoiceItem = [invoiceId : parameters.invoiceId, + invoiceItemTypeId: payRol.invoiceItemTypeId, + description : "${payRolGroup.description}: ${payRol.description}", + quantity : parameters."${payRol.invoiceItemTypeId}_Quantity" ?: 1d, + amount : parameters."${payRol.invoiceItemTypeId}_Amount" ?: 0d] + + if (parameters."${payRol.invoiceItemTypeId}_Quantity" || + parameters."${payRol.invoiceItemTypeId}_Amount") { + if ("PAYROL_EARN_HOURS" != payRolGroup.invoiceItemTypeId) { + createInvoiceItem.amount = createInvoiceItem.amount.negate() + } + Map serviceResult = run service: 'createInvoiceItem', with: createInvoiceItem + if (ServiceUtil.isError(serviceResult)) { + return serviceResult + } + } + } + } + } + + return success() } diff --git a/applications/accounting/minilang/invoice/InvoiceEvents.xml b/applications/accounting/minilang/invoice/InvoiceEvents.xml index a26e2a4..b5d14aa 100644 --- a/applications/accounting/minilang/invoice/InvoiceEvents.xml +++ b/applications/accounting/minilang/invoice/InvoiceEvents.xml @@ -20,41 +20,6 @@ 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="createInvoiceItemPayrol" short-description="Create a new Invoice Item with Payrol Item Type"> - <entity-condition entity-name="InvoiceItemType" list="PayrolGroup"> - <condition-expr field-name="parentTypeId" value="PAYROL"/> - </entity-condition> - <entity-condition entity-name="InvoiceItemType" list="PayrolList"/> - <iterate list="PayrolGroup" entry="payrolGroup"> - <iterate list="PayrolList" entry="payrolList"> - <if-compare field="payrolList.parentTypeId" value="${payrolGroup.invoiceItemTypeId}" operator="equals"> - <set field="AddInvoiceItem" value="N"/> - <set field="createInvoiceItem.invoiceId" from-field="parameters.invoiceId"/> - <set field="createInvoiceItem.invoiceItemTypeId" from-field="payrolList.invoiceItemTypeId"/> - <set field="createInvoiceItem.description" value="${payrolGroup.description} : ${payrolList.description}"/> - <set field="createInvoiceItem.quantity" from-field="parameters.${payrolList.invoiceItemTypeId}_Quantity"/> - <if-not-empty field="parameters.${payrolList.invoiceItemTypeId}_Quantity"> - <set field="AddInvoiceItem" value="Y"/> - </if-not-empty> - <set field="createInvoiceItem.amount" from-field="parameters.${payrolList.invoiceItemTypeId}_Amount"/> - <if-not-empty field="parameters.${payrolList.invoiceItemTypeId}_Amount"> - <set field="AddInvoiceItem" value="Y"/> - </if-not-empty> - <if-compare field="AddInvoiceItem" value="Y" operator="equals"> - <!-- negate amount if required --> - <if-compare field="payrolGroup.invoiceItemTypeId" value="PAYROL_EARN_HOURS" operator="not-equals"> - <calculate field="createInvoiceItem.amount"> - <calcop operator="multiply" field="createInvoiceItem.amount"> - <number value="-1"/> - </calcop> - </calculate> - </if-compare> - <call-service service-name="createInvoiceItem" in-map-name="createInvoiceItem"/> - </if-compare> - </if-compare> - </iterate> - </iterate> - </simple-method> + </simple-methods> diff --git a/applications/accounting/webapp/accounting/WEB-INF/controller.xml b/applications/accounting/webapp/accounting/WEB-INF/controller.xml index 331b1ea..8cfd63f 100644 --- a/applications/accounting/webapp/accounting/WEB-INF/controller.xml +++ b/applications/accounting/webapp/accounting/WEB-INF/controller.xml @@ -187,7 +187,7 @@ under the License. </request-map> <request-map uri="createInvoiceItemPayrol"> <security https="true" auth="true"/> - <event type="simple" invoke="createInvoiceItemPayrol" path="component://accounting/minilang/invoice/InvoiceEvents.xml"/> + <event type="groovy" invoke="createInvoiceItemPayrol" path="component://accounting/groovyScripts/invoice/InvoiceServices.groovy"/> <response name="success" type="view" value="listInvoiceItems"/> <response name="error" type="view" value="listInvoiceItems"/> </request-map>