blob: dbe12dfcf8cc186aefb9cf8dfd40e8f07a0e89f0 [file] [log] [blame]
<?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"
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/simple-methods-v2.xsd">
<simple-method method-name="createOrderDeliverySchedule" short-description="Creates a new Purchase Order Schedule">
<!-- Verify the user is allowed to set the fields -->
<set value="createOrderDeliverySchedule" field="callingMethodName"/>
<set value="CREATE" field="checkAction"/>
<call-simple-method method-name="checkSupplierRelatedPermission"/>
<check-errors/>
<make-value entity-name="OrderDeliverySchedule" value-field="schedule"/>
<set-pk-fields map="parameters" value-field="schedule"/>
<if-empty field="schedule.orderItemSeqId">
<set value="_NA_" field="schedule.orderItemSeqId"/>
</if-empty>
<!-- only set statusId if hasScheduleAdminRelatedPermission -->
<set-nonpk-fields value-field="schedule" map="parameters"/>
<if-has-permission permission="ORDERMGR" action="_${checkAction}">
<else>
<!-- no permission, set to initial -->
<set value="ODS_SUBMITTED" field="schedule.statusId"/>
</else>
</if-has-permission>
<create-value value-field="schedule"/>
</simple-method>
<simple-method method-name="updateOrderDeliverySchedule" short-description="Updates an existing Purchase Order Schedule">
<!-- Verify the user is allowed to edit the fields -->
<set value="updateOrderDeliverySchedule" field="callingMethodName"/>
<set value="UPDATE" field="checkAction"/>
<call-simple-method method-name="checkSupplierRelatedPermission"/>
<check-errors/>
<!-- Lookup the existing schedule to modify -->
<make-value entity-name="OrderDeliverySchedule" value-field="lookupPkMap"/>
<set-pk-fields map="parameters" value-field="lookupPkMap"/>
<find-by-primary-key entity-name="OrderDeliverySchedule" map="lookupPkMap" value-field="schedule"/>
<!-- only set statusId if hasScheduleAdminRelatedPermission -->
<set from-field="schedule.statusId" field="saveStatusId"/>
<set-nonpk-fields value-field="schedule" map="parameters"/>
<if-has-permission permission="ORDERMGR" action="_${checkAction}">
<else>
<!-- no permission, restore saved status -->
<set from-field="saveStatusId" field="schedule.statusId"/>
</else>
</if-has-permission>
<!-- Update the actual schedule -->
<store-value value-field="schedule"/>
</simple-method>
<simple-method method-name="sendOrderDeliveryScheduleNotification" short-description="Send Order Delivery Schedule Notification">
<set value="sendOrderDeliveryScheduleNotification" field="callingMethodName"/>
<set value="UPDATE" field="checkAction"/>
<call-simple-method method-name="checkSupplierRelatedPermission"/>
<check-errors/>
<if-empty field="parameters.orderItemSeqId">
<set field="parameters.orderItemSeqId" value="_NA_"/>
</if-empty>
<make-value entity-name="OrderDeliverySchedule" value-field="orderDeliverySchedule"/>
<set-pk-fields value-field="orderDeliverySchedule" map="parameters"/>
<find-by-primary-key map="orderDeliverySchedule" value-field="orderDeliverySchedule"/>
<!-- find email address for currently logged in user, set as sendFrom -->
<set field="curUserPcmFindMap.partyId" from-field="userLogin.partyId"/>
<set field="curUserPcmFindMap.contactMechTypeId" value="EMAIL_ADDRESS"/>
<find-by-and entity-name="PartyAndContactMech" map="curUserPcmFindMap" list="curUserPartyAndContactMechs"/>
<first-from-list entry="curUserPartyAndContactMech" list="curUserPartyAndContactMechs"/>
<string-append field="sendEmailMap.sendFrom" string="${curUserPartyAndContactMech.infoString}" prefix=","/>
<!-- find email addresses of all parties in SHIPMENT_CLERK roleTypeId, set as sendTo -->
<set value="SHIPMENT_CLERK" field="shipmentClerkFindMap.roleTypeId"/>
<find-by-and entity-name="PartyRole" map="shipmentClerkFindMap" list="shipmentClerkRoles"/>
<iterate entry="shipmentClerkRole" list="shipmentClerkRoles">
<set field="sendToPartyIdMap[shipmentClerkRole.partyId]" from-field="shipmentClerkRole.partyId"/>
</iterate>
<!-- go through all send to parties and get email addresses -->
<iterate-map key="sendToPartyId" value="sendToPartyIdValue" map="sendToPartyIdMap">
<set field="sendToPartyPcmFindMap.partyId" from-field="sendToPartyId"/>
<set field="sendToPartyPcmFindMap.contactMechTypeId" value="EMAIL_ADDRESS"/>
<find-by-and entity-name="PartyAndContactMech" map="sendToPartyPcmFindMap" list="sendToPartyPartyAndContactMechs"/>
<iterate entry="sendToPartyPartyAndContactMech" list="sendToPartyPartyAndContactMechs">
<string-append field="sendEmailMap.sendTo" string="${sendToPartyPartyAndContactMech.infoString}" prefix=","/>
</iterate>
</iterate-map>
<!-- set subject, contentType, templateName, templateData -->
<set field="sendEmailMap.subject" value="Delivery Information Updated for Order #${orderDeliverySchedule.orderId}"/>
<if-compare field="orderDeliverySchedule.orderItemSeqId" operator="not-equals" value="_NA_">
<string-append string=" Item #${orderDeliverySchedule.orderItemSeqId}" field="sendEmailMap.subject"/>
</if-compare>
<set field="sendEmailMap.contentType" value="text/html"/>
<set field="sendEmailMap.templateName" value="default/OrderDeliveryUpdatedNotice.ftl"/>
<set field="sendEmailMap.templateData.orderDeliverySchedule" from-field="orderDeliverySchedule"/>
<!-- call sendGenericNotificationEmail service, if enough information was found -->
<log level="info" message="Sending generic notification email (if all info is in place): ${sendEmailMap}"/>
<if>
<condition>
<and>
<not><if-empty field="sendEmailMap.sendTo"/></not>
<not><if-empty field="sendEmailMap.sendFrom"/></not>
</and>
</condition>
<then>
<call-service service-name="sendGenericNotificationEmail" in-map-name="sendEmailMap"/>
</then>
<else>
<log level="error" message="Insufficient data to send notice email: ${sendEmailMap}"/>
</else>
</if>
</simple-method>
<simple-method method-name="checkSupplierRelatedOrderPermissionService" short-description="Check Supplier Related Permission Service">
<set field="checkAction" from-field="parameters.checkAction"/>
<set field="callingMethodName" from-field="parameters.callingMethodName"/>
<call-simple-method method-name="checkSupplierRelatedPermission"/>
<field-to-result field="hasSupplierRelatedPermission"/>
</simple-method>
<!-- Should be called in-line to use its out parameter indicating whether the user has permission or not. -->
<simple-method method-name="checkSupplierRelatedPermission" short-description="Check Supplier Related Permission">
<if-empty field="callingMethodName">
<set value="this operation" field="callingMethodName"/>
</if-empty>
<if-empty field="checkAction">
<set value="UPDATE" field="checkAction"/>
</if-empty>
<set field="hasSupplierRelatedPermission" value="false"/>
<if>
<condition>
<if-has-permission permission="ORDERMGR" action="_${checkAction}"/>
</condition>
<then>
<set field="hasSupplierRelatedPermission" value="true"/>
</then>
<else>
<set from-field="parameters.orderId" field="lookupOrderRoleMap.orderId"/>
<set from-field="userLogin.partyId" field="lookupOrderRoleMap.partyId"/>
<set value="SUPPLIER_AGENT" field="lookupOrderRoleMap.roleTypeId"/>
<find-by-primary-key entity-name="OrderRole" map="lookupOrderRoleMap" value-field="permOrderRole"/>
<if>
<condition>
<if-empty field="permOrderRole"/>
</condition>
<then>
<set field="hasSupplierRelatedPermission" value="false"/>
<string-to-list list="error_list" string="ERROR: You do not have permission to ${checkAction} Delivery Schedule Information; you must be associated with this order as a Supplier Agent or have the ORDERMGR_${checkAction} permission."/>
</then>
<else>
<set field="hasSupplierRelatedPermission" value="true"/>
</else>
</if>
</else>
</if>
<log level="info" message="hasSupplierRelatedPermission is: ${hasSupplierRelatedPermission}"/>
</simple-method>
</simple-methods>