{
  "name": "Docket — 02 · Post-approbation (écriture comptable + Drive + notification)",
  "metadata": {
    "instant": true,
    "version": 1,
    "scenario": {
      "roundtrips": 1,
      "maxErrors": 3,
      "autoCommit": true,
      "autoCommitTriggerLast": true,
      "sequential": true,
      "confidential": false,
      "dataloss": false,
      "dlq": true,
      "freshVariables": false
    },
    "designer": { "orphans": [] },
    "zone": "eu1.make.com"
  },
  "flow": [
    {
      "id": 1,
      "module": "gateway:CustomWebHook",
      "version": 1,
      "parameters": { "hook": "{{webhook.docket_approved}}", "maxResults": 1 },
      "mapper": {},
      "metadata": { "designer": { "x": 0, "y": 0 } },
      "note": "Webhook instantané déclenché par Docket QUAND un humain appuie sur « Approuver ». Jamais avant."
    },
    {
      "id": 2,
      "module": "http:ActionSendData",
      "version": 3,
      "parameters": {},
      "mapper": {
        "url": "https://api.pennylane.com/api/external/v2/supplier_invoices",
        "method": "post",
        "bodyType": "raw",
        "contentType": "application/json",
        "headers": [
          { "name": "Authorization", "value": "Bearer {{env.PENNYLANE_TOKEN}}" },
          { "name": "Content-Type", "value": "application/json" }
        ],
        "data": "{\n  \"supplier_invoice\": {\n    \"supplier_name\": \"{{1.fields.vendor.value}}\",\n    \"invoice_number\": \"{{1.fields.invoiceNumber.value}}\",\n    \"date\": \"{{1.fields.issueDate.value}}\",\n    \"deadline\": \"{{1.fields.dueDate.value}}\",\n    \"amount_without_vat\": {{1.fields.totalHT.value}},\n    \"vat_amount\": {{1.fields.vatAmount.value}},\n    \"currency\": \"{{1.fields.currency.value}}\",\n    \"labels\": [\"docket\", \"valide-humain\"]\n  }\n}"
      },
      "metadata": { "designer": { "x": 200, "y": 0 } },
      "note": "Écriture fournisseur dans Pennylane. Les valeurs proviennent des champs VALIDÉS (corrections humaines incluses), pas de l'extraction brute."
    },
    {
      "id": 3,
      "module": "google-drive:uploadFile",
      "version": 2,
      "parameters": { "connection": "{{google.compte_cabinet}}" },
      "mapper": {
        "folderId": "{{env.DRIVE_FOLDER_ID}}",
        "newName": "{{formatDate(1.fields.issueDate.value; \"YYYY-MM\")}}_{{1.fields.vendor.value}}_{{1.fields.totalTTC.value}}{{1.fields.currency.value}}.pdf"
      },
      "metadata": { "designer": { "x": 400, "y": 0 } },
      "note": "Archivage : PDF renommé AAAA-MM_fournisseur_montant.pdf dans le dossier du mois."
    },
    {
      "id": 4,
      "module": "slack:CreateMessage",
      "version": 3,
      "parameters": { "connection": "{{slack.cabinet}}" },
      "mapper": {
        "channel": "#compta",
        "text": ":white_check_mark: *{{1.fields.vendor.value}}* — {{1.fields.totalTTC.value}} {{1.fields.currency.value}} validé et comptabilisé ({{2.body.id}}). Archivé : {{3.webViewLink}}"
      },
      "metadata": { "designer": { "x": 600, "y": 0 } },
      "note": "Notification finale avec lien de l'écriture et du fichier archivé."
    },
    {
      "id": 5,
      "module": "airtable:ActionUpdateRecord",
      "version": 3,
      "parameters": { "base": "{{env.AIRTABLE_BASE_ID}}", "table": "Documents" },
      "mapper": {
        "recordId": "{{1.airtableRecordId}}",
        "Status": "approved",
        "PennylaneId": "{{2.body.id}}"
      },
      "metadata": { "designer": { "x": 800, "y": 0 } },
      "note": "Traçabilité : l'ID Pennylane est réinjecté dans Airtable (piste d'audit de bout en bout)."
    }
  ]
}
