<?xml version="1.0" encoding="UTF-8"?>
<!-- Nafa: commande sur mesure (made-to-order), from the deposit to delivery.

     Started with: client, article, prixTotal, acompte, dateLivraison (amounts in FCFA).

     Commande créée
       → Acompte ≤ prix total ?        no  → Refusée : acompte supérieur au prix total
       → Calculer le reliquat           statut EN_COURS, reliquat = prixTotal - acompte
       → Confection                     user task; finish it with statut "ANNULE" to cancel
       → Commande annulée ?             yes → Annulée
       → Marquer prêt                   user task; a deposit made since the order is
                                        recorded here by setting acompte to the total paid
       → Rédiger le message             statut PRET, reliquat, and messageClient:
                                        « Votre commande est prête, reliquat : X FCFA »
       → Prévenir le client (WhatsApp)  user task: the merchant sends messageClient
       → Livraison et encaissement du reliquat   user task
       → Solder la commande             statut SOLDE_LIVRE, reliquat 0
       → Livrée et soldée

     The variable statut follows the order's status in Nafa (OrderStatus): EN_COURS,
     PRET, SOLDE_LIVRE or ANNULE. The business rule tasks evaluate the decisions in
     nafa_commande_sur_mesure.dmn, which is deployed with this process. Nothing here
     calls an outside service: the WhatsApp message is a variable the merchant sends. -->
<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/nafa"
  id="def_nafa_commande_sur_mesure">

  <process id="nafa_commande_sur_mesure" name="Nafa : commande sur mesure" isExecutable="true">
    <documentation>Commande sur mesure d'une boutique, d'un styliste ou d'un bijoutier au Sénégal : acompte à la commande, reliquat à la livraison, montants en FCFA.</documentation>

    <startEvent id="commande_creee" name="Commande créée"/>

    <exclusiveGateway id="gw_acompte" name="Acompte ≤ prix total ?" default="f_acompte_refuse"/>

    <endEvent id="refusee" name="Refusée : acompte supérieur au prix total"/>

    <businessRuleTask id="calculer_reliquat" name="Calculer le reliquat">
      <extensionElements>
        <zeebe:calledDecision decisionId="nafa_commande_en_cours"/>
      </extensionElements>
    </businessRuleTask>

    <userTask id="confection" name="Confection">
      <documentation>Statut EN_COURS. Pour annuler la commande, terminez cette étape avec statut = "ANNULE".</documentation>
    </userTask>

    <exclusiveGateway id="gw_annulation" name="Commande annulée ?" default="f_poursuivre"/>

    <endEvent id="annulee" name="Annulée"/>

    <userTask id="marquer_pret" name="Marquer prêt">
      <documentation>Passe la commande au statut PRET. Un acompte versé depuis la commande se déclare ici en mettant acompte au total déjà payé.</documentation>
    </userTask>

    <businessRuleTask id="rediger_message" name="Rédiger le message">
      <extensionElements>
        <zeebe:calledDecision decisionId="nafa_commande_prete"/>
      </extensionElements>
    </businessRuleTask>

    <userTask id="prevenir_client" name="Prévenir le client (WhatsApp)">
      <documentation>Envoyez messageClient au client sur WhatsApp : « Votre commande est prête, reliquat : X FCFA ».</documentation>
    </userTask>

    <userTask id="livraison_encaissement" name="Livraison et encaissement du reliquat">
      <documentation>Remettez la commande et encaissez le reliquat (Espèces, Wave ou Orange Money).</documentation>
    </userTask>

    <businessRuleTask id="solder_commande" name="Solder la commande">
      <extensionElements>
        <zeebe:calledDecision decisionId="nafa_commande_soldee"/>
      </extensionElements>
    </businessRuleTask>

    <endEvent id="livree_soldee" name="Livrée et soldée"/>

    <sequenceFlow id="f_creee" sourceRef="commande_creee" targetRef="gw_acompte"/>
    <sequenceFlow id="f_acompte_ok" name="oui" sourceRef="gw_acompte" targetRef="calculer_reliquat">
      <conditionExpression xsi:type="tFormalExpression">acompte &gt;= 0 and acompte &lt;= prixTotal</conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="f_acompte_refuse" name="non" sourceRef="gw_acompte" targetRef="refusee"/>
    <sequenceFlow id="f_reliquat" sourceRef="calculer_reliquat" targetRef="confection"/>
    <sequenceFlow id="f_confection" sourceRef="confection" targetRef="gw_annulation"/>
    <sequenceFlow id="f_annuler" name="oui" sourceRef="gw_annulation" targetRef="annulee">
      <conditionExpression xsi:type="tFormalExpression">statut = "ANNULE"</conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="f_poursuivre" name="non" sourceRef="gw_annulation" targetRef="marquer_pret"/>
    <sequenceFlow id="f_pret" sourceRef="marquer_pret" targetRef="rediger_message"/>
    <sequenceFlow id="f_message" sourceRef="rediger_message" targetRef="prevenir_client"/>
    <sequenceFlow id="f_prevenu" sourceRef="prevenir_client" targetRef="livraison_encaissement"/>
    <sequenceFlow id="f_encaisse" sourceRef="livraison_encaissement" targetRef="solder_commande"/>
    <sequenceFlow id="f_soldee" sourceRef="solder_commande" targetRef="livree_soldee"/>
  </process>

  <bpmndi:BPMNDiagram id="diagram_nafa_commande_sur_mesure">
    <bpmndi:BPMNPlane id="plane_nafa_commande_sur_mesure" bpmnElement="nafa_commande_sur_mesure">
      <bpmndi:BPMNShape id="shape_commande_creee" bpmnElement="commande_creee">
        <dc:Bounds x="80" y="202" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_gw_acompte" bpmnElement="gw_acompte" isMarkerVisible="true">
        <dc:Bounds x="170" y="195" width="50" height="50"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_refusee" bpmnElement="refusee">
        <dc:Bounds x="177" y="340" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_calculer_reliquat" bpmnElement="calculer_reliquat">
        <dc:Bounds x="280" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_confection" bpmnElement="confection">
        <dc:Bounds x="440" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_gw_annulation" bpmnElement="gw_annulation" isMarkerVisible="true">
        <dc:Bounds x="600" y="195" width="50" height="50"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_annulee" bpmnElement="annulee">
        <dc:Bounds x="607" y="340" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_marquer_pret" bpmnElement="marquer_pret">
        <dc:Bounds x="710" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_rediger_message" bpmnElement="rediger_message">
        <dc:Bounds x="870" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_prevenir_client" bpmnElement="prevenir_client">
        <dc:Bounds x="1030" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_livraison_encaissement" bpmnElement="livraison_encaissement">
        <dc:Bounds x="1190" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_solder_commande" bpmnElement="solder_commande">
        <dc:Bounds x="1350" y="180" width="100" height="80"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape_livree_soldee" bpmnElement="livree_soldee">
        <dc:Bounds x="1512" y="202" width="36" height="36"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge_f_creee" bpmnElement="f_creee">
        <di:waypoint x="116" y="220"/>
        <di:waypoint x="170" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_acompte_ok" bpmnElement="f_acompte_ok">
        <di:waypoint x="220" y="220"/>
        <di:waypoint x="280" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_acompte_refuse" bpmnElement="f_acompte_refuse">
        <di:waypoint x="195" y="245"/>
        <di:waypoint x="195" y="340"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_reliquat" bpmnElement="f_reliquat">
        <di:waypoint x="380" y="220"/>
        <di:waypoint x="440" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_confection" bpmnElement="f_confection">
        <di:waypoint x="540" y="220"/>
        <di:waypoint x="600" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_annuler" bpmnElement="f_annuler">
        <di:waypoint x="625" y="245"/>
        <di:waypoint x="625" y="340"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_poursuivre" bpmnElement="f_poursuivre">
        <di:waypoint x="650" y="220"/>
        <di:waypoint x="710" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_pret" bpmnElement="f_pret">
        <di:waypoint x="810" y="220"/>
        <di:waypoint x="870" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_message" bpmnElement="f_message">
        <di:waypoint x="970" y="220"/>
        <di:waypoint x="1030" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_prevenu" bpmnElement="f_prevenu">
        <di:waypoint x="1130" y="220"/>
        <di:waypoint x="1190" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_encaisse" bpmnElement="f_encaisse">
        <di:waypoint x="1290" y="220"/>
        <di:waypoint x="1350" y="220"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge_f_soldee" bpmnElement="f_soldee">
        <di:waypoint x="1450" y="220"/>
        <di:waypoint x="1512" y="220"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>
