For terceros, _guardar_envio stores the automation date in the factura field (not a patient id), so COALESCE(factura, cedula) still collapsed all terceros into one row. Now GROUP BY uses cedula for tipo=terceros and factura for transaccion/ventas. Template hides the date in the factura column for terceros rows. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>