Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ency07/B2B-import/llms.txt

Use this file to discover all available pages before exploring further.

The Leads & CRM module is the commercial backbone of B2B Import ERP. It centralizes every inbound prospect — whether they arrived through the public Wizard, a manual entry by a sales rep, or a marketing campaign — into a single pipeline where automated scoring, stage tracking, and activity logging drive the conversion process from first contact to closed deal.

Lead Sources

Wizard Form

Visitors who complete the public pre-engineering calculator at /wizard are automatically registered as scored leads the moment they submit the form.

Manual Entry

Sales representatives can create leads directly from the dashboard at /dashboard/leads, associating them with an existing client and contact record.

Marketing Campaigns

Leads generated from external campaigns (email, WhatsApp broadcasts, landing page contact forms) are captured via submitContactForm() and scored on arrival.

Lead Scoring Algorithm

Every lead is scored automatically by calculateLeadScore() in src/app/actions/leads.ts. The algorithm accumulates points from three independent factors, then applies SPAM detection, and finally maps the total to a risk level.

Scoring Factors

Professional Role

+40 pts — Director de Planta, Gerente de Mantenimiento, Supervisor de HVAC / Operaciones+25 pts — Ingeniero de Proyectos, Compras / Abastecimiento+10 pts — Any other role

Urgency

+40 ptsalta (emergency, same-day SLA)+20 ptsmedia (priority project)+5 ptsbaja (planning stage)

Email Domain

−20 pts — Public domains: gmail.com, yahoo.com, outlook.com, hotmail.com, live.com, icloud.comSPAM — Disposable domains: yopmail.com, mailinator.com, tempmail.com
The final score is clamped to the range 0–100. Disposable email domains bypass scoring entirely — the lead is classified as SPAM with a score of 0 regardless of role or urgency.

Score Thresholds

Score RangeRisk Level
Disposable / invalid emailSPAM
70 – 100CALIENTE
40 – 69TIBIO
0 – 39FRIO

Risk Levels

Risk levels are intentionally stored in Spanish (CALIENTE, TIBIO, FRIO, SPAM) to match the target market. The database constraint in 20260617000035_industrial_cms.sql enforces these exact string values and rejects any English equivalents.

🔥 CALIENTE

High-priority prospect. Score ≥ 70. Corporate email, senior role, and high urgency. Assign immediately; expected short sales cycle.

🌡️ TIBIO

Moderate engagement. Score 40–69. Needs nurturing — schedule a follow-up call and add to an email sequence.

❄️ FRIO

Low engagement or low-value indicators. Score < 40. Keep in pipeline but deprioritize; may still convert over a longer cycle.

🚫 SPAM

Disposable email detected, or address is malformed. Score forced to 0. Filtered out of the active pipeline automatically.

TypeScript Interface

interface LeadScoreResult {
  score: number;
  riskLevel: "CALIENTE" | "TIBIO" | "FRIO" | "SPAM";
}

Server Actions

Both actions are defined in src/app/actions/leads.ts and run exclusively on the server under the Supabase Service Role.

calculateLeadScore

Computes the score and risk level for a given email, role, and urgency string. Pure function with no database side effects — safe to call for previews or dry-runs.
calculateLeadScore(
  email: string,
  role: string,
  urgency: string
): Promise<LeadScoreResult>

createLeadWithScore

Calls calculateLeadScore internally, then inserts a new row into the leads table with status: "NUEVO", lead_source: "WEBSITE", and the computed score and risk_level. Returns the full persisted lead record.
createLeadWithScore(
  tenantCode: string | null,
  leadData: {
    clientId: string;
    contactId: string;
    notes?: string;
    role: string;
    urgency: string;
    email: string;
  }
): Promise<Lead>

CRM Pipeline Stages

Leads move through the following ordered stages. Stage transitions are logged in crm_activity_logs with an immutable trigger that blocks physical deletion — all audit records are preserved indefinitely.
Nuevo → En Contacto → Calificado → Propuesta → Negociación → Ganado
                                                            ↘ Perdido
StageDescription
NuevoLead just created; awaiting first contact
En ContactoFirst outreach made; conversation open
CalificadoBudget, authority, need, and timeline confirmed
PropuestaFormal quote or technical proposal delivered
NegociaciónTerms, pricing, or scope being negotiated
GanadoDeal closed; converts to a work order or invoice
PerdidoOpportunity closed without a sale; reason logged

Dashboard

Access the full lead pipeline at:
/dashboard/leads?tenant=<code>
The dashboard surfaces lead count by stage, average score per source, and a quick-filter panel by risk level.

Build docs developers (and LLMs) love