<?xml version="1.0" encoding="UTF-8"?>
<!-- Expense Approval (template expense-approval).

     Started with: employee, amount, category.

     Expense submitted
       -> Manager approval            user task; complete with approved = true to approve
       -> Approved by the manager?    no -> Tell the employee -> Rejected
       -> Over 1,000?                 no -> Reimburse
       -> Finance audit               user task; complete with auditPassed = true
       -> Audit passed?               no -> Tell the employee -> Rejected
       -> Reimburse the employee      user task
       -> Reimbursed

     Anything other than true counts as no. The threshold is 1,000 in the claim's
     currency: change it on the flow "over 1,000".

     The answers are variables their steps are completed with: approved, auditPassed. The
     template's sample variables start each of them as null, so a step closed
     without its answer takes the safe branch. A run started without them stops with
     an incident at the first gateway whose variable was never set, because the
     engine never reads a missing variable as a no, and the hosted API cannot resume
     a run in INCIDENT. -->
<definitions
  xmlns="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:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:zeebe="http://camunda.org/schema/zeebe/1.0"
  targetNamespace="http://priostack.com/templates"
  id="def_expense_approval">

  <process id="expense_approval" name="Expense Approval" isExecutable="true">
    <documentation>An employee's expense claim: the manager approves it, finance audits any claim over 1,000, and the employee is reimbursed or told why not.</documentation>

    <startEvent id="expense_submitted" name="Expense submitted"/>

    <userTask id="manager_approval" name="Manager approval">
      <documentation>Complete with approved = true to approve the claim, or false to reject it.</documentation>
    </userTask>

    <exclusiveGateway id="gw_approved" name="Approved by the manager?" default="f_manager_rejected"/>

    <exclusiveGateway id="gw_large" name="Over 1,000?" default="f_small"/>

    <userTask id="finance_audit" name="Finance audit">
      <documentation>Check the receipts and the policy for a claim over 1,000. Complete with auditPassed = true to let it be paid, or false to reject it.</documentation>
    </userTask>

    <exclusiveGateway id="gw_audit" name="Audit passed?" default="f_audit_failed"/>

    <userTask id="reimburse" name="Reimburse the employee">
      <documentation>Pay the claim with the next payroll or by transfer.</documentation>
    </userTask>

    <endEvent id="reimbursed" name="Reimbursed"/>

    <userTask id="tell_employee" name="Tell the employee">
      <documentation>Tell the employee the claim was rejected, and why.</documentation>
    </userTask>

    <endEvent id="rejected" name="Rejected"/>

    <sequenceFlow id="f_submitted" sourceRef="expense_submitted" targetRef="manager_approval"/>
    <sequenceFlow id="f_manager_done" sourceRef="manager_approval" targetRef="gw_approved"/>
    <sequenceFlow id="f_manager_approved" name="yes" sourceRef="gw_approved" targetRef="gw_large">
      <conditionExpression xsi:type="tFormalExpression">approved = true</conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="f_manager_rejected" name="no" sourceRef="gw_approved" targetRef="tell_employee"/>
    <sequenceFlow id="f_large" name="over 1,000" sourceRef="gw_large" targetRef="finance_audit">
      <conditionExpression xsi:type="tFormalExpression">amount &gt; 1000</conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="f_small" name="1,000 or less" sourceRef="gw_large" targetRef="reimburse"/>
    <sequenceFlow id="f_audited" sourceRef="finance_audit" targetRef="gw_audit"/>
    <sequenceFlow id="f_audit_passed" name="yes" sourceRef="gw_audit" targetRef="reimburse">
      <conditionExpression xsi:type="tFormalExpression">auditPassed = true</conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="f_audit_failed" name="no" sourceRef="gw_audit" targetRef="tell_employee"/>
    <sequenceFlow id="f_paid" sourceRef="reimburse" targetRef="reimbursed"/>
    <sequenceFlow id="f_told" sourceRef="tell_employee" targetRef="rejected"/>
  </process>

  <bpmndi:BPMNDiagram id="diagram_expense_approval">
    <bpmndi:BPMNPlane id="plane_expense_approval" bpmnElement="expense_approval">
      <bpmndi:BPMNShape id="shape_expense_submitted" bpmnElement="expense_submitted">
        <dc:Bounds x="82" y="102" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_manager_approval" bpmnElement="manager_approval">
        <dc:Bounds x="215" y="80" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_gw_approved" bpmnElement="gw_approved" isMarkerVisible="true">
        <dc:Bounds x="415" y="95" width="50" height="50"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_gw_large" bpmnElement="gw_large" isMarkerVisible="true">
        <dc:Bounds x="585" y="95" width="50" height="50"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_finance_audit" bpmnElement="finance_audit">
        <dc:Bounds x="725" y="220" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_gw_audit" bpmnElement="gw_audit" isMarkerVisible="true">
        <dc:Bounds x="925" y="235" width="50" height="50"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_reimburse" bpmnElement="reimburse">
        <dc:Bounds x="1065" y="80" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_reimbursed" bpmnElement="reimbursed">
        <dc:Bounds x="1272" y="102" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_tell_employee" bpmnElement="tell_employee">
        <dc:Bounds x="1065" y="360" width="110" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_rejected" bpmnElement="rejected">
        <dc:Bounds x="1272" y="382" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge_f_submitted" bpmnElement="f_submitted">
        <di:waypoint x="118" y="120"/>
        <di:waypoint x="215" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_manager_done" bpmnElement="f_manager_done">
        <di:waypoint x="325" y="120"/>
        <di:waypoint x="415" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_manager_approved" bpmnElement="f_manager_approved">
        <di:waypoint x="465" y="120"/>
        <di:waypoint x="585" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_manager_rejected" bpmnElement="f_manager_rejected">
        <di:waypoint x="440" y="145"/>
        <di:waypoint x="440" y="400"/>
        <di:waypoint x="1065" y="400"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_large" bpmnElement="f_large">
        <di:waypoint x="610" y="145"/>
        <di:waypoint x="610" y="260"/>
        <di:waypoint x="725" y="260"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_small" bpmnElement="f_small">
        <di:waypoint x="635" y="120"/>
        <di:waypoint x="1065" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_audited" bpmnElement="f_audited">
        <di:waypoint x="835" y="260"/>
        <di:waypoint x="925" y="260"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_audit_passed" bpmnElement="f_audit_passed">
        <di:waypoint x="950" y="235"/>
        <di:waypoint x="950" y="120"/>
        <di:waypoint x="1065" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_audit_failed" bpmnElement="f_audit_failed">
        <di:waypoint x="950" y="285"/>
        <di:waypoint x="950" y="400"/>
        <di:waypoint x="1065" y="400"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_paid" bpmnElement="f_paid">
        <di:waypoint x="1175" y="120"/>
        <di:waypoint x="1272" y="120"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_told" bpmnElement="f_told">
        <di:waypoint x="1175" y="400"/>
        <di:waypoint x="1272" y="400"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>
