This is an automated email from the ASF dual-hosted git repository.
akashjain 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 68d210a Improved: Purchase Order Email Support (OFBIZ-11864) 68d210a is described below commit 68d210a7d0bd60e25ec34c7b2a32890bea723d9b Author: Akash Jain <[hidden email]> AuthorDate: Mon Aug 3 17:29:13 2020 +0530 Improved: Purchase Order Email Support (OFBIZ-11864) --- applications/order/data/OrderTypeData.xml | 4 ++- applications/order/servicedef/services.xml | 7 ++++ .../apache/ofbiz/order/order/OrderServices.java | 40 ++++++++++++++++++++++ applications/order/template/order/OrderInfo.ftl | 10 ++++++ .../template/order/SendPurchaseOrderEmail.ftl | 31 +++++++++++++++++ .../order/webapp/ordermgr/WEB-INF/controller.xml | 6 ++++ .../order/widget/ordermgr/OrderHeaderScreens.xml | 18 ++++++++++ 7 files changed, 115 insertions(+), 1 deletion(-) diff --git a/applications/order/data/OrderTypeData.xml b/applications/order/data/OrderTypeData.xml index 2638999..a68cb90 100644 --- a/applications/order/data/OrderTypeData.xml +++ b/applications/order/data/OrderTypeData.xml @@ -33,5 +33,7 @@ under the License. <EmailTemplateSetting emailTemplateSettingId="CUST_REQ_NOTE_ADDED" bodyScreenLocation="component://order/widget/ordermgr/CustRequestScreens.xml#AddNoteCustRequestNotification" subject="OFBiz - A Note has been added to your request: '${custRequestName}' #CR${custRequestId}"/> - + <EmailTemplateSetting emailTemplateSettingId="SEND_PO_EMAIL" + bodyScreenLocation="component://order/widget/ordermgr/OrderHeaderScreens.xml#SendPOEmail" + subject="Your Purchase Order #${orderId}"/> </entity-engine-xml> diff --git a/applications/order/servicedef/services.xml b/applications/order/servicedef/services.xml index 76d5eb0..a974c0b 100644 --- a/applications/order/servicedef/services.xml +++ b/applications/order/servicedef/services.xml @@ -72,6 +72,13 @@ under the License. <implements service="orderNotificationInterface"/> </service> + <service name="sendPOEmail" engine="java" require-new-transaction="true" max-retry="3" + location="org.apache.ofbiz.order.order.OrderServices" invoke="sendPOEmail"> + <description>Send Purchase Order Email</description> + <attribute name="orderId" type="String" mode="IN" optional="false"/> + <attribute name="emailTemplateSettingId" type="String" mode="IN" optional="true"/> + </service> + <service name="sendProcessNotification" engine="java" require-new-transaction="true" max-retry="3" location="org.apache.ofbiz.order.order.OrderServices" invoke="sendProcessNotification"> <description>Limit Service for order processing workflow; sends activitiy notifications</description> diff --git a/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java b/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java index 400baf9..da143c4 100644 --- a/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java +++ b/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java @@ -7399,4 +7399,44 @@ public class OrderServices { } return ServiceUtil.returnSuccess(); } + + public static Map<String, Object> sendPOEmail(DispatchContext dctx, Map<String, ? extends Object> context) { + LocalDispatcher dispatcher = dctx.getDispatcher(); + Delegator delegator = dctx.getDelegator(); + GenericValue userLogin = (GenericValue) context.get("userLogin"); + String orderId = (String) context.get("orderId"); + String emailTemplateSettingId = (String) context.get("emailTemplateSettingId"); + + if (orderId != null && emailTemplateSettingId != null) { + try { + GenericValue orderHeader = EntityQuery.use(delegator).from("OrderHeader").where("orderId", orderId).queryOne(); + + if (orderHeader != null && "PURCHASE_ORDER".equals(orderHeader.getString("orderTypeId"))) { + GenericValue vendor = EntityQuery.use(delegator).from("OrderRole").where("orderId", orderId, "roleTypeId", "BILL_FROM_VENDOR").queryFirst(); + if (vendor != null) { + String partyIdTo = vendor.getString("partyId"); + GenericValue contactMech = PartyWorker.findPartyLatestContactMech(partyIdTo, "EMAIL_ADDRESS", delegator); + if (contactMech != null && contactMech.getString("infoString") != null) { + GenericValue emailTemplateSetting = EntityQuery.use(delegator).from("EmailTemplateSetting").where("emailTemplateSettingId", emailTemplateSettingId).queryOne(); + if (emailTemplateSetting != null) { + String partyIdFrom = null; + GenericValue company = EntityQuery.use(delegator).from("OrderRole").where("orderId", orderId, "roleTypeId", "BILL_TO_CUSTOMER").queryFirst(); + if (company != null) { + partyIdFrom = company.getString("partyId"); + } + Map<String, Object> bodyParameters = UtilMisc.toMap("orderId", orderId, "partyIdTo", partyIdTo, "partyIdFrom", partyIdFrom); + + Map<String, Object> emailCtx = UtilMisc.toMap("emailTemplateSettingId", emailTemplateSettingId, "sendTo", contactMech.getString("infoString"), "bodyParameters", bodyParameters); + emailCtx.put("userLogin", userLogin); + dispatcher.runAsync("sendMailFromTemplateSetting", emailCtx); + } + } + } + } + } catch (GenericEntityException | GenericServiceException e) { + Debug.logError(e, MODULE); + } + } + return ServiceUtil.returnSuccess(); + } } diff --git a/applications/order/template/order/OrderInfo.ftl b/applications/order/template/order/OrderInfo.ftl index 1e74f87..d091098 100644 --- a/applications/order/template/order/OrderInfo.ftl +++ b/applications/order/template/order/OrderInfo.ftl @@ -36,6 +36,16 @@ under the License. </form> </li> </#if> + + <#if "PURCHASE_ORDER" == orderHeader.orderTypeId && ("ORDER_REJECTED" != currentStatus.statusId || "ORDER_CANCELLED" != currentStatus.statusId)> + <li><a href="javascript:document.SendPOEmail.submit()">Send Email</a> + <form name="SendPOEmail" method="post" action="<@ofbizUrl>sendPOEmail</@ofbizUrl>"> + <input type="hidden" name="orderId" value="${orderHeader.orderId!}"/> + <input type="hidden" name="emailTemplateSettingId" value="SEND_PO_EMAIL"/> + </form> + </li> + </#if> + <#if "ORDER_CREATED" == currentStatus.statusId || "ORDER_PROCESSING" == currentStatus.statusId> <li><a href="javascript:document.OrderApproveOrder.submit()">${uiLabelMap.OrderApproveOrder}</a> <form class ="basic-form" name="OrderApproveOrder" method="post" action="<@ofbizUrl>changeOrderStatus/orderview</@ofbizUrl>"> diff --git a/applications/order/template/order/SendPurchaseOrderEmail.ftl b/applications/order/template/order/SendPurchaseOrderEmail.ftl new file mode 100644 index 0000000..14724f2 --- /dev/null +++ b/applications/order/template/order/SendPurchaseOrderEmail.ftl @@ -0,0 +1,31 @@ +<#-- +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. +--> +<html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> + <title>${title}</title> + </head> + <body> + <p>Hello ${supplier.firstName!} ${supplier.lastName!} ${supplier.groupName!},</p> + <p>Here is your purchase order <a href="${StringUtil.wrapString(baseSecureUrl!)}/ordermgr/control/orderview?orderId=${orderId}">${orderId}</a></p> + <br /> + Regards,<br /> + ${company.groupName!} + </body> +</html> \ No newline at end of file diff --git a/applications/order/webapp/ordermgr/WEB-INF/controller.xml b/applications/order/webapp/ordermgr/WEB-INF/controller.xml index c1c4936..f8cc97a 100644 --- a/applications/order/webapp/ordermgr/WEB-INF/controller.xml +++ b/applications/order/webapp/ordermgr/WEB-INF/controller.xml @@ -90,6 +90,12 @@ under the License. <security https="true" auth="true"/> <response name="success" type="view" value="OrderHistory"/> </request-map> + <request-map uri="sendPOEmail"> + <security https="true" auth="true"/> + <event type="service" path="" invoke="sendPOEmail"/> + <response name="success" type="view" value="orderview"/> + <response name="error" type="view" value="orderview"/> + </request-map> <!-- Order Manager Mass Change Requests --> <request-map uri="massApproveOrders"> diff --git a/applications/order/widget/ordermgr/OrderHeaderScreens.xml b/applications/order/widget/ordermgr/OrderHeaderScreens.xml index dd74147..4ba4fc5 100644 --- a/applications/order/widget/ordermgr/OrderHeaderScreens.xml +++ b/applications/order/widget/ordermgr/OrderHeaderScreens.xml @@ -91,4 +91,22 @@ under the License. </widgets> </section> </screen> + <screen name="SendPOEmail"> + <section> + <actions> + <entity-one entity-name="PartyNameView" value-field="supplier"> + <field-map field-name="partyId" from-field="partyIdTo"/> + </entity-one> + <entity-one entity-name="PartyNameView" value-field="company"> + <field-map field-name="partyId" from-field="partyIdFrom"/> + </entity-one> + <set field="title" value="Your Purchase Order #${orderId}"/> + </actions> + <widgets> + <platform-specific><html> + <html-template location="component://order/template/order/SendPurchaseOrderEmail.ftl"/> + </html></platform-specific> + </widgets> + </section> + </screen> </screens> |
Free forum by Nabble | Edit this page |