<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="@bpmnkit/core" exporterVersion="0.0.23" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.9.0">
  <bpmn:process id="purchase-request-approval" name="Purchase Request Approval" isExecutable="true">
    <bpmn:extensionElements>
      <zeebe:versionTag value="1.0.0"/>
    </bpmn:extensionElements>
    <bpmn:startEvent id="request-submitted" name="Purchase request submitted">
      <bpmn:outgoing>Flow_request-submitted_route-request</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:businessRuleTask id="route-request" name="Determine approver">
      <bpmn:extensionElements>
        <zeebe:calledDecision decisionId="approval-matrix" resultVariable="routing"/>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_request-submitted_route-request</bpmn:incoming>
      <bpmn:outgoing>Flow_route-request_auto-approve</bpmn:outgoing>
    </bpmn:businessRuleTask>
    <bpmn:exclusiveGateway id="auto-approve" name="Auto-approve?" default="Flow_auto-approve_approve-request">
      <bpmn:incoming>Flow_route-request_auto-approve</bpmn:incoming>
      <bpmn:outgoing>Flow_auto-approve_po-merge</bpmn:outgoing>
      <bpmn:outgoing>Flow_auto-approve_approve-request</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:userTask id="approve-request" name="Approve purchase request">
      <bpmn:extensionElements>
        <zeebe:userTask/>
        <zeebe:assignmentDefinition candidateGroups="=routing.approverGroup"/>
        <zeebe:taskSchedule dueDate="=now() + duration(&quot;P3D&quot;)"/>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_auto-approve_approve-request</bpmn:incoming>
      <bpmn:outgoing>Flow_approve-request_approved</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:exclusiveGateway id="approved" name="Approved?" default="Flow_approved_notify-rejected">
      <bpmn:incoming>Flow_approve-request_approved</bpmn:incoming>
      <bpmn:outgoing>Flow_approved_po-merge</bpmn:outgoing>
      <bpmn:outgoing>Flow_approved_notify-rejected</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:serviceTask id="notify-rejected" name="Notify requester: rejected">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="requester-notify"/>
        <zeebe:taskHeaders>
          <zeebe:header key="template" value="purchase-rejected"/>
        </zeebe:taskHeaders>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_approved_notify-rejected</bpmn:incoming>
      <bpmn:outgoing>Flow_notify-rejected_request-rejected</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:endEvent id="request-rejected" name="Request rejected">
      <bpmn:incoming>Flow_notify-rejected_request-rejected</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:exclusiveGateway id="po-merge">
      <bpmn:incoming>Flow_auto-approve_po-merge</bpmn:incoming>
      <bpmn:incoming>Flow_approved_po-merge</bpmn:incoming>
      <bpmn:outgoing>Flow_po-merge_create-po</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:serviceTask id="create-po" name="Create purchase order">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="erp-purchase-order-create"/>
        <zeebe:ioMapping>
          <zeebe:output source="=poNumber" target="poNumber"/>
        </zeebe:ioMapping>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_po-merge_create-po</bpmn:incoming>
      <bpmn:outgoing>Flow_create-po_notify-approved</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:serviceTask id="notify-approved" name="Notify requester: approved">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="requester-notify"/>
        <zeebe:taskHeaders>
          <zeebe:header key="template" value="purchase-approved"/>
        </zeebe:taskHeaders>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_create-po_notify-approved</bpmn:incoming>
      <bpmn:outgoing>Flow_notify-approved_po-created</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:endEvent id="po-created" name="Purchase order created">
      <bpmn:incoming>Flow_notify-approved_po-created</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_request-submitted_route-request" sourceRef="request-submitted" targetRef="route-request"/>
    <bpmn:sequenceFlow id="Flow_route-request_auto-approve" sourceRef="route-request" targetRef="auto-approve"/>
    <bpmn:sequenceFlow id="Flow_auto-approve_po-merge" sourceRef="auto-approve" targetRef="po-merge" name="auto">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=routing.autoApprove</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_auto-approve_approve-request" sourceRef="auto-approve" targetRef="approve-request" name="review"/>
    <bpmn:sequenceFlow id="Flow_approve-request_approved" sourceRef="approve-request" targetRef="approved"/>
    <bpmn:sequenceFlow id="Flow_approved_po-merge" sourceRef="approved" targetRef="po-merge" name="yes">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=approved</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_approved_notify-rejected" sourceRef="approved" targetRef="notify-rejected" name="no"/>
    <bpmn:sequenceFlow id="Flow_notify-rejected_request-rejected" sourceRef="notify-rejected" targetRef="request-rejected"/>
    <bpmn:sequenceFlow id="Flow_po-merge_create-po" sourceRef="po-merge" targetRef="create-po"/>
    <bpmn:sequenceFlow id="Flow_create-po_notify-approved" sourceRef="create-po" targetRef="notify-approved"/>
    <bpmn:sequenceFlow id="Flow_notify-approved_po-created" sourceRef="notify-approved" targetRef="po-created"/>
  </bpmn:process>
  <bpmndi:BPMNDiagram id="purchase-request-approval_di">
    <bpmndi:BPMNPlane id="purchase-request-approval_di_plane" bpmnElement="purchase-request-approval">
      <bpmndi:BPMNShape id="request-submitted_di" bpmnElement="request-submitted">
        <dc:Bounds x="93" y="42" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="20" y="82" width="182" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="route-request_di" bpmnElement="route-request">
        <dc:Bounds x="229" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="auto-approve_di" bpmnElement="auto-approve">
        <dc:Bounds x="429" y="35" width="50" height="50"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="409" y="89" width="91" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="approve-request_di" bpmnElement="approve-request">
        <dc:Bounds x="579" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="approved_di" bpmnElement="approved">
        <dc:Bounds x="779" y="35" width="50" height="50"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="773" y="89" width="63" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="notify-rejected_di" bpmnElement="notify-rejected">
        <dc:Bounds x="929" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="request-rejected_di" bpmnElement="request-rejected">
        <dc:Bounds x="1161" y="42" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="1123" y="82" width="112" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="po-merge_di" bpmnElement="po-merge">
        <dc:Bounds x="954" y="195" width="50" height="50"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="create-po_di" bpmnElement="create-po">
        <dc:Bounds x="1129" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="notify-approved_di" bpmnElement="notify-approved">
        <dc:Bounds x="1329" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="po-created_di" bpmnElement="po-created">
        <dc:Bounds x="1529" y="202" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="1470" y="242" width="154" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_request-submitted_route-request_di" bpmnElement="Flow_request-submitted_route-request">
        <di:waypoint x="129" y="60"/>
        <di:waypoint x="229" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_route-request_auto-approve_di" bpmnElement="Flow_route-request_auto-approve">
        <di:waypoint x="329" y="60"/>
        <di:waypoint x="429" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_auto-approve_po-merge_di" bpmnElement="Flow_auto-approve_po-merge">
        <di:waypoint x="454" y="85"/>
        <di:waypoint x="454" y="220"/>
        <di:waypoint x="954" y="220"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="684" y="196" width="40" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_auto-approve_approve-request_di" bpmnElement="Flow_auto-approve_approve-request">
        <di:waypoint x="479" y="60"/>
        <di:waypoint x="579" y="60"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="508" y="36" width="42" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_approve-request_approved_di" bpmnElement="Flow_approve-request_approved">
        <di:waypoint x="679" y="60"/>
        <di:waypoint x="779" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_approved_po-merge_di" bpmnElement="Flow_approved_po-merge">
        <di:waypoint x="804" y="85"/>
        <di:waypoint x="804" y="148"/>
        <di:waypoint x="979" y="148"/>
        <di:waypoint x="979" y="195"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="872" y="124" width="40" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_approved_notify-rejected_di" bpmnElement="Flow_approved_notify-rejected">
        <di:waypoint x="829" y="60"/>
        <di:waypoint x="929" y="60"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="859" y="36" width="40" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_notify-rejected_request-rejected_di" bpmnElement="Flow_notify-rejected_request-rejected">
        <di:waypoint x="1029" y="60"/>
        <di:waypoint x="1161" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_po-merge_create-po_di" bpmnElement="Flow_po-merge_create-po">
        <di:waypoint x="1004" y="220"/>
        <di:waypoint x="1129" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_create-po_notify-approved_di" bpmnElement="Flow_create-po_notify-approved">
        <di:waypoint x="1229" y="220"/>
        <di:waypoint x="1329" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_notify-approved_po-created_di" bpmnElement="Flow_notify-approved_po-created">
        <di:waypoint x="1429" y="220"/>
        <di:waypoint x="1529" y="220"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

