<?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="invoice-capture" name="Invoice Capture" isExecutable="true">
    <bpmn:extensionElements>
      <zeebe:versionTag value="1.0.0"/>
    </bpmn:extensionElements>
    <bpmn:startEvent id="invoice-received" name="Invoice received">
      <bpmn:outgoing>Flow_invoice-received_extract-invoice</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:serviceTask id="extract-invoice" name="Extract invoice data">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="document-extract"/>
        <zeebe:ioMapping>
          <zeebe:output source="=fields" target="invoice"/>
          <zeebe:output source="=confidence" target="extractionConfidence"/>
        </zeebe:ioMapping>
        <zeebe:taskHeaders>
          <zeebe:header key="model" value="invoice"/>
        </zeebe:taskHeaders>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_invoice-received_extract-invoice</bpmn:incoming>
      <bpmn:outgoing>Flow_extract-invoice_validate-totals</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:scriptTask id="validate-totals" name="Validate totals">
      <bpmn:extensionElements>
        <zeebe:script expression="=abs(invoice.net + invoice.tax - invoice.gross) &lt; 0.01" resultVariable="totalsValid"/>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_extract-invoice_validate-totals</bpmn:incoming>
      <bpmn:outgoing>Flow_validate-totals_straight-through</bpmn:outgoing>
    </bpmn:scriptTask>
    <bpmn:exclusiveGateway id="straight-through" name="Straight-through?" default="Flow_straight-through_verify-invoice">
      <bpmn:incoming>Flow_validate-totals_straight-through</bpmn:incoming>
      <bpmn:outgoing>Flow_straight-through_straight-through_join</bpmn:outgoing>
      <bpmn:outgoing>Flow_straight-through_verify-invoice</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:userTask id="verify-invoice" name="Verify extracted data">
      <bpmn:extensionElements>
        <zeebe:userTask/>
        <zeebe:formDefinition formId="invoice-verification"/>
        <zeebe:assignmentDefinition candidateGroups="accounts-payable"/>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_straight-through_verify-invoice</bpmn:incoming>
      <bpmn:outgoing>Flow_verify-invoice_straight-through_join</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:serviceTask id="post-invoice" name="Post to ERP">
      <bpmn:extensionElements>
        <zeebe:taskDefinition type="erp-invoice-post"/>
        <zeebe:ioMapping>
          <zeebe:output source="=documentNumber" target="erpDocument"/>
        </zeebe:ioMapping>
      </bpmn:extensionElements>
      <bpmn:incoming>Flow_straight-through_join_post-invoice</bpmn:incoming>
      <bpmn:outgoing>Flow_post-invoice_invoice-posted</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:endEvent id="invoice-posted" name="Invoice posted">
      <bpmn:incoming>Flow_post-invoice_invoice-posted</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:exclusiveGateway id="straight-through_join">
      <bpmn:incoming>Flow_straight-through_straight-through_join</bpmn:incoming>
      <bpmn:incoming>Flow_verify-invoice_straight-through_join</bpmn:incoming>
      <bpmn:outgoing>Flow_straight-through_join_post-invoice</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:sequenceFlow id="Flow_invoice-received_extract-invoice" sourceRef="invoice-received" targetRef="extract-invoice"/>
    <bpmn:sequenceFlow id="Flow_extract-invoice_validate-totals" sourceRef="extract-invoice" targetRef="validate-totals"/>
    <bpmn:sequenceFlow id="Flow_validate-totals_straight-through" sourceRef="validate-totals" targetRef="straight-through"/>
    <bpmn:sequenceFlow id="Flow_straight-through_straight-through_join" sourceRef="straight-through" targetRef="straight-through_join" name="auto">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">=totalsValid and extractionConfidence &gt;= 0.9</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_straight-through_verify-invoice" sourceRef="straight-through" targetRef="verify-invoice" name="verify"/>
    <bpmn:sequenceFlow id="Flow_verify-invoice_straight-through_join" sourceRef="verify-invoice" targetRef="straight-through_join"/>
    <bpmn:sequenceFlow id="Flow_post-invoice_invoice-posted" sourceRef="post-invoice" targetRef="invoice-posted"/>
    <bpmn:sequenceFlow id="Flow_straight-through_join_post-invoice" sourceRef="straight-through_join" targetRef="post-invoice"/>
  </bpmn:process>
  <bpmndi:BPMNDiagram id="invoice-capture_di">
    <bpmndi:BPMNPlane id="invoice-capture_di_plane" bpmnElement="invoice-capture">
      <bpmndi:BPMNShape id="invoice-received_di" bpmnElement="invoice-received">
        <dc:Bounds x="58" y="42" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="20" y="82" width="112" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="extract-invoice_di" bpmnElement="extract-invoice">
        <dc:Bounds x="194" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="validate-totals_di" bpmnElement="validate-totals">
        <dc:Bounds x="394" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="straight-through_di" bpmnElement="straight-through">
        <dc:Bounds x="594" y="35" width="50" height="50"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="560" y="89" width="119" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="verify-invoice_di" bpmnElement="verify-invoice">
        <dc:Bounds x="744" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="post-invoice_di" bpmnElement="post-invoice">
        <dc:Bounds x="1094" y="20" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="invoice-posted_di" bpmnElement="invoice-posted">
        <dc:Bounds x="1294" y="42" width="36" height="36"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="1263" y="82" width="98" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="straight-through_join_di" bpmnElement="straight-through_join">
        <dc:Bounds x="944" y="35" width="50" height="50"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_invoice-received_extract-invoice_di" bpmnElement="Flow_invoice-received_extract-invoice">
        <di:waypoint x="94" y="60"/>
        <di:waypoint x="194" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_extract-invoice_validate-totals_di" bpmnElement="Flow_extract-invoice_validate-totals">
        <di:waypoint x="294" y="60"/>
        <di:waypoint x="394" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_validate-totals_straight-through_di" bpmnElement="Flow_validate-totals_straight-through">
        <di:waypoint x="494" y="60"/>
        <di:waypoint x="594" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_straight-through_straight-through_join_di" bpmnElement="Flow_straight-through_straight-through_join">
        <di:waypoint x="619" y="35"/>
        <di:waypoint x="619" y="-20"/>
        <di:waypoint x="969" y="-20"/>
        <di:waypoint x="969" y="35"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="774" y="-44" width="40" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_straight-through_verify-invoice_di" bpmnElement="Flow_straight-through_verify-invoice">
        <di:waypoint x="644" y="60"/>
        <di:waypoint x="744" y="60"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds x="673" y="36" width="42" height="14"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_verify-invoice_straight-through_join_di" bpmnElement="Flow_verify-invoice_straight-through_join">
        <di:waypoint x="844" y="60"/>
        <di:waypoint x="944" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_post-invoice_invoice-posted_di" bpmnElement="Flow_post-invoice_invoice-posted">
        <di:waypoint x="1194" y="60"/>
        <di:waypoint x="1294" y="60"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_straight-through_join_post-invoice_di" bpmnElement="Flow_straight-through_join_post-invoice">
        <di:waypoint x="994" y="60"/>
        <di:waypoint x="1094" y="60"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

