1aa2uX6gqHINUP_h-HcNsxJzlwSI1OnSVzqMaFaI_8NE)Code.gsCode.gs que se encuentra en este repositorioCtrl+S)inicializarHoja del menú desplegableLa función creará automáticamente:
Tu hoja “Informes” ahora tendrá estas columnas:
| Col | Nombre | Descripción |
|---|---|---|
| A | Timestamp | Fecha y hora de registro |
| B | NumInforme | Número de informe generado (EA-AAMM-NOM) |
| C | TipoOrden | OT o OTB |
| D | OT | Número de orden de trabajo |
| E | NOM | Código de NOM (011, 022, 025, etc.) |
| F | Cliente | Razón social del cliente |
| G | Solicitante | Nombre del solicitante |
| H | RFC | RFC del cliente |
| I | Telefono | Teléfono de contacto |
| J | Direccion | Dirección del centro de trabajo |
| K | FechaServicio | Fecha de emisión de OT |
| L | FechaEntrega | Fecha compromiso de entrega (+15 días) |
| M | EsCapacitacion | SI o NO (para OTB-CAP) |
| N | Estatus | EN PROCESO / FINALIZADO / CANCELADO |
| O | LinkDrive | URL de la carpeta en Drive |
createExpediente (POST)Cambios principales:
numInforme ya generado desde el frontendtipoOrden (OT o OTB)PERFIL_DATOS para guardar el Excel1. ORDEN_TRABAJO2. PERFIL_DATOS3. HOJAS_CAMPO4. CROQUIS_PLANOSPayload esperado:
{
"action": "createExpediente",
"data": {
"ot": "OT25-0106-001",
"numInforme": "EA-2501-011",
"tipoOrden": "OT",
"nom": "011",
"cliente": "Empresa SA de CV",
"solicitante": "Juan Pérez",
"rfc": "EMP123456ABC",
"telefono": "5512345678",
"direccion": "Calle Principal 123",
"fecha": "2025-01-15",
"entrega": "2025-01-30",
"esCapacitacion": false
},
"files": [
{
"name": "OT-001.pdf",
"type": "application/pdf",
"content": "base64string...",
"category": "ORDEN_TRABAJO"
},
{
"name": "Perfil.xlsx",
"type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"content": "base64string...",
"category": "PERFIL_DATOS"
}
]
}
Respuesta:
{
"success": true,
"numInforme": "EA-2501-011",
"tipoOrden": "OT",
"ot": "OT25-0106-001",
"fechaEntrega": "2025-01-30",
"driveLink": "https://drive.google.com/..."
}
updateEstatus (POST) - ¡NUEVA!Permite cambiar el estatus de un expediente desde el tablero.
Payload:
{
"action": "updateEstatus",
"ot": "OT25-0106-001",
"estatus": "FINALIZADO"
}
Estatus válidos:
EN PROCESOFINALIZADOCANCELADORespuesta:
{
"success": true,
"message": "Estatus actualizado a 'FINALIZADO' para OT: OT25-0106-001",
"ot": "OT25-0106-001",
"estatus": "FINALIZADO"
}
getTablero (GET) - ActualizadaRetorna todos los expedientes con los campos nuevos.
URL:
https://script.google.com/macros/s/TU_SCRIPT_ID/exec?action=getTablero&callback=miCallback
Respuesta:
{
"success": true,
"data": [
{
"timestamp": "2025-01-15 10:30:00",
"numInforme": "EA-2501-011",
"tipoOrden": "OT",
"ot": "OT25-0106-001",
"nom": "011",
"cliente": "Empresa SA",
"solicitante": "Juan Pérez",
"rfc": "EMP123456ABC",
"telefono": "5512345678",
"direccion": "Calle Principal 123",
"fecha": "2025-01-15",
"fechaEntrega": "2025-01-30",
"esCapacitacion": "NO",
"estatus": "EN PROCESO",
"linkDrive": "https://drive.google.com/..."
}
]
}
inicializarHoja()Crea los encabezados en la hoja de cálculo si no existen.
Cómo ejecutarla:
inicializarHoja en el menú de funcionesobtenerEstadisticas()Muestra estadísticas del sistema en los logs.
Cómo ejecutarla:
obtenerEstadisticas en el menú de funcionesEjemplo de salida:
📊 ESTADÍSTICAS DEL SISTEMA
═══════════════════════════
Total de expedientes: 45
- OT (Serie Regular): 32
- OTB (Serie Independiente): 13
- Con Capacitación: 5
Por Estatus:
- En Proceso: 12
- Finalizados: 28
- Cancelados: 5
El script utiliza LockService.getScriptLock() para evitar conflictos cuando múltiples usuarios envían datos simultáneamente.
createExpediente y updateEstatusSi ya tienes datos en la hoja con la estructura antigua:
inicializarHoja() en la hoja “Informes”function migrarDatosAntiguos() {
const ss = SpreadsheetApp.openById(SPREADSHEET_ID);
const oldSheet = ss.getSheetByName('Informes_OLD'); // Renombra tu hoja antigua
const newSheet = ss.getSheetByName(SHEET_NAME);
if (!oldSheet || !newSheet) {
Logger.log('❌ Verifica que existan las hojas');
return;
}
const oldData = oldSheet.getRange(2, 1, oldSheet.getLastRow() - 1, 9).getValues();
oldData.forEach(row => {
newSheet.appendRow([
row[0], // A: Timestamp (mantener)
row[1], // B: NumInforme (mantener)
row[2].includes('OTB') ? 'OTB' : 'OT', // C: TipoOrden (detectar)
row[2], // D: OT (mantener)
row[3], // E: NOM (mantener)
row[4], // F: Cliente (mantener)
'', // G: Solicitante (vacío)
'', // H: RFC (vacío)
'', // I: Telefono (vacío)
'', // J: Direccion (vacío)
row[5], // K: FechaServicio (mantener)
row[6], // L: FechaEntrega (mantener)
'NO', // M: EsCapacitacion (por defecto NO)
row[7], // N: Estatus (mantener)
row[8] // O: LinkDrive (mantener)
]);
});
Logger.log('✅ Migración completada');
}
inicializarHoja() ejecutadaOT25-0106-001 o OTB25-0106-001inicializarHoja() desde Apps ScriptupdateEstatus no está implementadaSi encuentras algún problema:
obtenerEstadisticas() para verificar el estado del sistemaVersión: 2.0 Última actualización: 2025-01-17 Compatibilidad: Google Apps Script, Google Sheets, Google Drive