{
 "name": "Nácar · pedidos de catering",
 "nodes": [
  {
   "id": "d92467b6-3db4-431e-aa1b-0fd99a74901f",
   "name": "Nota 3150",
   "type": "n8n-nodes-base.stickyNote",
   "typeVersion": 1,
   "position": [
    -40,
    -300
   ],
   "parameters": {
    "content": "## Pedidos de catering\nUna empresa pide catering por el formulario. La IA saca personas, fecha, servicio y restricciones; la cotización sale de la carta (no la inventa la IA), se guarda en la planilla y en el CRM, y el cliente recibe la cotización. Si el evento es en menos de 72 h, el aviso al dueño es urgente.",
    "width": 520,
    "height": 200,
    "color": 7
   }
  },
  {
   "id": "ca8191e1-14da-433a-93ca-6c03ee747c48",
   "name": "Pedido de catering",
   "type": "n8n-nodes-base.formTrigger",
   "typeVersion": 2.6,
   "position": [
    0,
    0
   ],
   "parameters": {
    "formTitle": "Catering para empresas · Nácar",
    "formDescription": "Cuéntanos tu evento con tus palabras: cuántas personas, qué día y qué te gustaría servir. Te enviamos la cotización por correo.",
    "formFields": {
     "values": [
      {
       "fieldLabel": "Empresa",
       "fieldName": "empresa",
       "fieldType": "text",
       "requiredField": true,
       "placeholder": "Estudio Rivas & Asociados"
      },
      {
       "fieldLabel": "Tu nombre",
       "fieldName": "contacto",
       "fieldType": "text",
       "requiredField": true,
       "placeholder": "Laura Rivas"
      },
      {
       "fieldLabel": "Correo",
       "fieldName": "email",
       "fieldType": "email",
       "requiredField": true,
       "placeholder": "laura@empresa.com"
      },
      {
       "fieldLabel": "Teléfono",
       "fieldName": "telefono",
       "fieldType": "text",
       "requiredField": false,
       "placeholder": "11 5555 0000"
      },
      {
       "fieldLabel": "Tu evento",
       "fieldName": "pedido",
       "fieldType": "textarea",
       "requiredField": true,
       "placeholder": "Somos 30 el jueves 8 de octubre, queremos un coffee break a las 10 con opciones sin TACC…"
      }
     ]
    },
    "responseMode": "onReceived",
    "options": {
     "appendAttribution": false,
     "buttonLabel": "Pedir cotización",
     "path": "catering-nacar",
     "respondWithOptions": {
      "values": {
       "respondWith": "text",
       "formSubmittedText": "¡Gracias! Te respondemos en minutos por mail."
      }
     }
    }
   },
   "webhookId": "2ba9d0f4-fcd3-44da-b213-98f592d13c0f"
  },
  {
   "id": "f23f936a-9c07-401c-9c6d-77e0995ba3f7",
   "name": "La IA lee el pedido",
   "type": "@n8n/n8n-nodes-langchain.informationExtractor",
   "typeVersion": 1.2,
   "position": [
    260,
    0
   ],
   "parameters": {
    "text": "={{ 'Hoy es ' + $now.toFormat('yyyy-MM-dd (cccc)', { locale: 'es' }) + '.\\nPedido: ' + $json.pedido }}",
    "schemaType": "fromAttributes",
    "attributes": {
     "attributes": [
      {
       "name": "personas",
       "type": "number",
       "description": "Cantidad de personas",
       "required": true
      },
      {
       "name": "fecha_evento",
       "type": "string",
       "description": "Fecha del evento en formato AAAA-MM-DD (resuelve «el jueves», «mañana» con la fecha de hoy). Vacío si no la dice."
      },
      {
       "name": "servicio",
       "type": "string",
       "description": "Uno de: desayuno, coffee, merienda, almuerzo",
       "required": true
      },
      {
       "name": "tipo_evento",
       "type": "string",
       "description": "Qué es el evento, en 2 a 4 palabras (por ejemplo «capacitación interna»)"
      },
      {
       "name": "restricciones",
       "type": "string",
       "description": "Alergias, sin TACC, veganos, horario, etc. Vacío si no hay."
      }
     ]
    },
    "options": {
     "systemPromptTemplate": "Extraes datos de pedidos de catering escritos en español. Sólo lo que el texto dice o se deduce sin dudas; si falta un dato, déjalo vacío."
    }
   }
  },
  {
   "id": "a9284181-59c5-4bb3-89de-6c0b67788c35",
   "name": "Claude",
   "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
   "typeVersion": 1.6,
   "position": [
    300,
    220
   ],
   "parameters": {
    "model": {
     "__rl": true,
     "mode": "id",
     "value": "claude-sonnet-5-5"
    },
    "options": {
     "maxTokensToSample": 1200,
     "thinkingMode": "adaptive",
     "effort": "low"
    }
   },
   "credentials": {
    "anthropicApi": {
     "id": "",
     "name": "Claude (demos)"
    }
   }
  },
  {
   "id": "773a0741-dea0-4d6c-9211-234ebcd0c719",
   "name": "Cotizar con la carta",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    560,
    0
   ],
   "parameters": {
    "mode": "runOnceForEachItem",
    "jsCode": "\n// Cotización con los precios de la CARTA (no los inventa la IA): servicio por persona, descuento por volumen y envío.\nconst TARIFAS = { desayuno: ['Desayuno ejecutivo', 9800], coffee: ['Coffee break', 7500], merienda: ['Merienda Nácar', 11500], almuerzo: ['Almuerzo liviano', 14900] };\nconst d = $json.output || {};\nconst personas = Math.max(1, Math.round(Number(d.personas) || 0));\nconst clave = String(d.servicio || '').toLowerCase();\nconst [servicio, porPersona] = TARIFAS[clave] || TARIFAS.coffee;\nconst descuento = personas >= 50 ? 0.12 : personas >= 25 ? 0.07 : 0;\nconst envio = 18000;\nconst subtotal = personas * porPersona;\nconst total = Math.round(subtotal * (1 - descuento) + envio);\nconst hoy = new Date(); hoy.setHours(0, 0, 0, 0);\nconst evento = d.fecha_evento ? new Date(d.fecha_evento + 'T00:00:00') : null;\nconst horas = evento ? Math.round((evento - hoy) / 36e5) : 999;\nconst f = $('Pedido de catering').item.json;\nconst $$ = (n) => '$ ' + Math.round(n).toLocaleString('es-AR');\nreturn { ...f, ...d, personas, servicio, porPersona, descuento, envio, subtotal, total, horas_al_evento: horas,\n  cotizacion_texto: `${personas} × ${servicio} (${$$(porPersona)} c/u)${descuento ? ` · ${Math.round(descuento * 100)} % por volumen` : ''} · envío ${$$(envio)} = ${$$(total)}`,\n  total_texto: $$(total) };\n"
   }
  },
  {
   "id": "2335835a-d445-41ab-9247-d27f11846747",
   "name": "Planilla de pedidos",
   "type": "n8n-nodes-base.dataTable",
   "typeVersion": 1.1,
   "position": [
    800,
    0
   ],
   "parameters": {
    "resource": "row",
    "operation": "insert",
    "dataTableId": {
     "__rl": true,
     "mode": "id",
     "value": ""
    },
    "columns": {
     "mappingMode": "defineBelow",
     "value": {
      "recibido": "={{ $now.toISODate() }}",
      "empresa": "={{ $json.empresa }}",
      "contacto": "={{ $json.contacto }}",
      "email": "={{ $json.email }}",
      "personas": "={{ $json.personas }}",
      "fecha_evento": "={{ $json.fecha_evento }}",
      "tipo_evento": "={{ $json.tipo_evento }}",
      "presupuesto": "={{ $json.total }}",
      "restricciones": "={{ $json.restricciones }}",
      "cotizacion": "={{ $json.total }}",
      "estado": "cotizado"
     },
     "matchingColumns": [],
     "schema": [
      {
       "id": "recibido",
       "displayName": "recibido",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "empresa",
       "displayName": "empresa",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "contacto",
       "displayName": "contacto",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "email",
       "displayName": "email",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "personas",
       "displayName": "personas",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "fecha_evento",
       "displayName": "fecha_evento",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "tipo_evento",
       "displayName": "tipo_evento",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "presupuesto",
       "displayName": "presupuesto",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "restricciones",
       "displayName": "restricciones",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "cotizacion",
       "displayName": "cotizacion",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "estado",
       "displayName": "estado",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      }
     ]
    },
    "options": {}
   }
  },
  {
   "id": "8b7c0f1b-8233-4544-9374-75735a01a3a3",
   "name": "CRM · contacto",
   "type": "n8n-nodes-base.dataTable",
   "typeVersion": 1.1,
   "position": [
    1040,
    0
   ],
   "parameters": {
    "resource": "row",
    "operation": "upsert",
    "dataTableId": {
     "__rl": true,
     "mode": "id",
     "value": ""
    },
    "columns": {
     "mappingMode": "defineBelow",
     "value": {
      "nombre": "={{ $('Cotizar con la carta').item.json.contacto + ' (' + $('Cotizar con la carta').item.json.empresa + ')' }}",
      "email": "={{ $('Cotizar con la carta').item.json.email }}",
      "telefono": "={{ $('Cotizar con la carta').item.json.telefono }}",
      "origen": "Catering Nácar",
      "etapa": "Cotización enviada",
      "asesor": "Dueño",
      "proximo_seguimiento": "={{ $now.plus({ days: 2 }).toISODate() }}",
      "notas": "={{ $('Cotizar con la carta').item.json.cotizacion_texto }}"
     },
     "matchingColumns": [],
     "schema": [
      {
       "id": "nombre",
       "displayName": "nombre",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "email",
       "displayName": "email",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "telefono",
       "displayName": "telefono",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "origen",
       "displayName": "origen",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "etapa",
       "displayName": "etapa",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "asesor",
       "displayName": "asesor",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "proximo_seguimiento",
       "displayName": "proximo_seguimiento",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "notas",
       "displayName": "notas",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      }
     ]
    },
    "options": {},
    "filters": {
     "conditions": [
      {
       "keyName": "email",
       "condition": "eq",
       "keyValue": "={{ $('Cotizar con la carta').item.json.email }}"
      }
     ]
    }
   }
  },
  {
   "id": "a51eb35e-721d-446e-b6ca-4a61306eabbe",
   "name": "Cotización al cliente",
   "type": "n8n-nodes-base.emailSend",
   "typeVersion": 2.1,
   "position": [
    1280,
    -120
   ],
   "parameters": {
    "fromEmail": "Nácar · café y té <pedidos@nacar.demo>",
    "toEmail": "={{ $('Cotizar con la carta').item.json.email }}",
    "subject": "={{ 'Tu cotización de catering · Nácar · ' + $('Cotizar con la carta').item.json.total_texto }}",
    "emailFormat": "html",
    "html": "={{ `<div style=\"font-family:Georgia,serif;max-width:560px;margin:auto;color:#231B16\">\n<p style=\"letter-spacing:.3em;font-size:22px;margin:0\">NÁCAR</p><p style=\"color:#A88A56;font-size:11px;letter-spacing:.25em;margin:2px 0 24px\">CAFÉ · TÉ · DE AUTOR</p>\n<p>Hola, ${$('Cotizar con la carta').item.json.contacto}:</p><p>Gracias por pensar en Nácar para <b>${$('Cotizar con la carta').item.json.tipo_evento || 'tu evento'}</b> de ${$('Cotizar con la carta').item.json.empresa}. Esta es la cotización:</p>\n<table style=\"width:100%;border-collapse:collapse;font-family:Arial,sans-serif;font-size:14px\">\n<tr><td style=\"padding:8px 0;border-bottom:1px solid #E3D9CA\">Servicio</td><td style=\"text-align:right;border-bottom:1px solid #E3D9CA\">${$('Cotizar con la carta').item.json.servicio}</td></tr>\n<tr><td style=\"padding:8px 0;border-bottom:1px solid #E3D9CA\">Personas</td><td style=\"text-align:right;border-bottom:1px solid #E3D9CA\">${$('Cotizar con la carta').item.json.personas}</td></tr>\n<tr><td style=\"padding:8px 0;border-bottom:1px solid #E3D9CA\">Fecha</td><td style=\"text-align:right;border-bottom:1px solid #E3D9CA\">${$('Cotizar con la carta').item.json.fecha_evento || 'a confirmar'}</td></tr>\n${$('Cotizar con la carta').item.json.restricciones ? `<tr><td style=\"padding:8px 0;border-bottom:1px solid #E3D9CA\">A tener en cuenta</td><td style=\"text-align:right;border-bottom:1px solid #E3D9CA\">${$('Cotizar con la carta').item.json.restricciones}</td></tr>` : ''}\n<tr><td style=\"padding:12px 0\"><b>Total</b></td><td style=\"text-align:right\"><b>${$('Cotizar con la carta').item.json.total_texto}</b></td></tr></table>\n<p style=\"font-family:Arial,sans-serif;font-size:13px;color:#7A6E64\">${$('Cotizar con la carta').item.json.cotizacion_texto}. Válida por 7 días. Para confirmar, responde este correo.</p>\n<p style=\"font-size:11px;color:#7A6E64;margin-top:32px\">Demostración: Nácar es un negocio ficticio y este correo quedó en un buzón de prueba.</p></div>` }}",
    "options": {
     "appendAttribution": false
    }
   },
   "credentials": {
    "smtp": {
     "id": "",
     "name": "Buzón de prueba (Mailpit)"
    }
   }
  },
  {
   "id": "f0652376-2d85-4775-911a-73b12bc2c921",
   "name": "¿Es en menos de 72 h?",
   "type": "n8n-nodes-base.if",
   "typeVersion": 2.3,
   "position": [
    1280,
    120
   ],
   "parameters": {
    "conditions": {
     "options": {
      "caseSensitive": true,
      "leftValue": "",
      "typeValidation": "loose",
      "version": 2
     },
     "conditions": [
      {
       "id": "1c73528e-5f74-4051-9c90-384b35135c98",
       "leftValue": "={{ $('Cotizar con la carta').item.json.horas_al_evento }}",
       "rightValue": 72,
       "operator": {
        "type": "number",
        "operation": "lt"
       }
      }
     ],
     "combinator": "and"
    },
    "options": {}
   }
  },
  {
   "id": "2646d5dc-eac2-48dc-8890-99cfc1a072cd",
   "name": "Aviso URGENTE al dueño",
   "type": "n8n-nodes-base.emailSend",
   "typeVersion": 2.1,
   "position": [
    1540,
    40
   ],
   "parameters": {
    "fromEmail": "Nácar · café y té <pedidos@nacar.demo>",
    "toEmail": "dueno@nacar.demo",
    "subject": "={{ '⚠ Catering para ' + $('Cotizar con la carta').item.json.fecha_evento + ': ' + $('Cotizar con la carta').item.json.personas + ' personas' }}",
    "emailFormat": "html",
    "html": "={{ `<p><b>Evento en menos de 72 h.</b></p><p>${$('Cotizar con la carta').item.json.empresa} · ${$('Cotizar con la carta').item.json.contacto} · ${$('Cotizar con la carta').item.json.telefono || 'sin teléfono'}</p><p>${$('Cotizar con la carta').item.json.cotizacion_texto}</p><p>${$('Cotizar con la carta').item.json.restricciones || ''}</p>` }}",
    "options": {
     "appendAttribution": false
    }
   },
   "credentials": {
    "smtp": {
     "id": "",
     "name": "Buzón de prueba (Mailpit)"
    }
   }
  },
  {
   "id": "1770a0a3-01b5-48ac-8e5d-304685970db0",
   "name": "Aviso al dueño",
   "type": "n8n-nodes-base.emailSend",
   "typeVersion": 2.1,
   "position": [
    1540,
    220
   ],
   "parameters": {
    "fromEmail": "Nácar · café y té <pedidos@nacar.demo>",
    "toEmail": "dueno@nacar.demo",
    "subject": "={{ 'Nuevo pedido de catering: ' + $('Cotizar con la carta').item.json.empresa }}",
    "emailFormat": "html",
    "html": "={{ `<p>${$('Cotizar con la carta').item.json.empresa} pidió ${$('Cotizar con la carta').item.json.servicio} para ${$('Cotizar con la carta').item.json.personas} personas (${$('Cotizar con la carta').item.json.fecha_evento || 'fecha a confirmar'}).</p><p>Cotizado: ${$('Cotizar con la carta').item.json.total_texto}. Ya está en la planilla y en el CRM.</p>` }}",
    "options": {
     "appendAttribution": false
    }
   },
   "credentials": {
    "smtp": {
     "id": "",
     "name": "Buzón de prueba (Mailpit)"
    }
   }
  }
 ],
 "connections": {
  "Pedido de catering": {
   "main": [
    [
     {
      "node": "La IA lee el pedido",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Claude": {
   "ai_languageModel": [
    [
     {
      "node": "La IA lee el pedido",
      "type": "ai_languageModel",
      "index": 0
     }
    ]
   ]
  },
  "La IA lee el pedido": {
   "main": [
    [
     {
      "node": "Cotizar con la carta",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Cotizar con la carta": {
   "main": [
    [
     {
      "node": "Planilla de pedidos",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Planilla de pedidos": {
   "main": [
    [
     {
      "node": "CRM · contacto",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "CRM · contacto": {
   "main": [
    [
     {
      "node": "Cotización al cliente",
      "type": "main",
      "index": 0
     },
     {
      "node": "¿Es en menos de 72 h?",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "¿Es en menos de 72 h?": {
   "main": [
    [
     {
      "node": "Aviso URGENTE al dueño",
      "type": "main",
      "index": 0
     }
    ],
    [
     {
      "node": "Aviso al dueño",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "settings": {
  "executionOrder": "v1",
  "timezone": "America/Argentina/Buenos_Aires",
  "saveManualExecutions": true
 }
}