DOCUMENTACIÓN OXIPRO
Manual de instrucciones - Base de Datos
 
×
Menú
Índice
 

3.6. ba_equipos_cierre_mes

 
Nombre de la tabla en Redash:
ba_equipos_cierre_mes
Nombre de la tabla en BD:
ba_equipos_cierre_mes
Descripción del objetivo de la Tabla:
Es una tabla con el inventario del mes anterior AGRUPADA por ubicación y subtipo, estado de equipo (paciente una sola ubicación por Regional) Esta tabla se construye agrupada basado en ba_equipos_inventario. Se toma una foto el primer día del mes a la madrugada; añomes, añomes dia, añomessemana a la vista ba_equipos_inventario.
Tipo de tabla:
Historica
Fecha versión actual:
--------------------------------------------------------------------------------------
Declaración SQL:
SELECT date_format(NOW(), '%Y%m%d') AS agno_mes_dia,
        DATE_FORMAT(NOW(), '%Y%m') AS agno_mes,
        yearweek(NOW(), 0) AS agno_semana,
       activo.propietario AS propietario,
       activo.linea_servicio AS linea_servicio,
        activo.supertipo AS supertipo,
        activo.tipo_equipo AS tipo_equipo,
        activo.subtipo AS subtipo,
        activo.modeloequipo AS modeloequipo,
       activo.situacionequipo AS Situacionequipo,
 #01   (CASE
            WHEN (crminfo.setype = 'PacientesII') THEN concat(substr(
                                                                           (SELECT acc.groupname
                                                                            FROM (vtiger_accountgrouprelation acc
                                                                                  JOIN vtiger_pacientesii pac)
                                                                            WHERE ((activo.ubicacion = pac.pacientesiiid)
                                                                                   AND (pac.accountid = acc.accountid))),1, 4), '-', 'Pacientes')
            WHEN (crminfo.setype = 'Sedes') THEN concat(substr(
                                                                     (SELECT vtiger_sedescf.cf_2271
                                                                      FROM vtiger_sedescf
                                                                      WHERE (activo.ubicacion = vtiger_sedescf.sedesid)),1, 4), '-',
                                                              (SELECT vtiger_sedescf.cf_2239
                                                               FROM vtiger_sedescf
                                                               WHERE (activo.ubicacion = vtiger_sedescf.sedesid)))
            WHEN (crminfo.setype = 'PlanillasTrabajo') THEN concat(substr(
                                                                                (SELECT rutascf.cf_2961
                                                                                 FROM (vtiger_rutascf rutascf
                                                                                       JOIN vtiger_planillastrabajo pt)
                                                                                 WHERE ((activo.ubicacion = pt.planillastrabajoid)
                                                                                        AND (pt.ruta = rutascf.rutasid))),1, 4), '-', 'Planilla', '-',
                                                                         (SELECT rutas.tiporuta
                                                                          FROM (vtiger_rutas rutas
                                                                                JOIN vtiger_planillastrabajo pt)
                                                                          WHERE ((activo.ubicacion = pt.planillastrabajoid)
                                                                                 AND (pt.ruta = rutas.rutasid))))
        END) AS AgroupUbic,
            crminfo.setype AS TipoUbicacion,
 #02     (CASE
              WHEN (crminfo.setype = 'PacientesII') THEN
                     (SELECT acc.groupname
                      FROM (vtiger_accountgrouprelation acc
                            JOIN vtiger_pacientesii pac)
                      WHERE ((activo.ubicacion = pac.pacientesiiid)
                             AND (pac.accountid = acc.accountid)))
              WHEN (crminfo.setype = 'Sedes') THEN
                     (SELECT vtiger_sedescf.cf_2271
                      FROM vtiger_sedescf
                      WHERE (activo.ubicacion = vtiger_sedescf.sedesid))
              WHEN (crminfo.setype = 'PlanillasTrabajo') THEN
                     (SELECT rutascf.cf_2961
                      FROM (vtiger_rutascf rutascf
                            JOIN vtiger_planillastrabajo pt)
                      WHERE ((activo.ubicacion = pt.planillastrabajoid)
                             AND (pt.ruta = rutascf.rutasid)))
              WHEN (crminfo.setype = 'Vendors') THEN 'CUNDINAMARCA'
              WHEN (crminfo.setype = 'Accounts') THEN
                     (SELECT acc.groupname
                      FROM (vtiger_accountgrouprelation acc
                            JOIN vtiger_account vac)
                      WHERE ((activo.ubicacion = vac.accountid)
                             AND (vac.accountid = acc.accountid)))
          END) AS Regional,
 #03      (CASE
              WHEN (crminfo.setype = 'PacientesII') THEN
                     (SELECT pacf.cf_1679
                      FROM (vtiger_pacientesii pac
                            JOIN vtiger_pacientesiicf pacf on((pac.pacientesiiid = pacf.pacientesiiid)))
                      WHERE (activo.ubicacion = pac.pacientesiiid))
              WHEN (crminfo.setype = 'Sedes') THEN
                     (SELECT vtiger_sedes.clasesede
                      FROM vtiger_sedes
                      WHERE (activo.ubicacion = vtiger_sedes.sedesid))
              WHEN (crminfo.setype = 'PlanillasTrabajo') THEN 'PlanillasTrabaj\no'
              WHEN (crminfo.setype = 'Accounts') THEN 'Accounts'
          END) AS ClaseSede,
        
       
 #04      (CASE
              WHEN (crminfo.setype = 'PacientesII') THEN
                     (SELECT vac.epsconsolidada
                      FROM (vtiger_account vac
                            JOIN vtiger_pacientesii pac on((pac.accountid = vac.accountid)))
                      WHERE (activo.ubicacion = pac.pacientesiiid))
              WHEN (crminfo.setype = 'Sedes') THEN
                     (SELECT vtiger_sedes.clasesede
                      FROM vtiger_sedes
                      WHERE (activo.ubicacion = vtiger_sedes.sedesid))
              WHEN (crminfo.setype = 'PlanillasTrabajo') THEN
                     (SELECT rutas.tiporuta
                      FROM (vtiger_rutas rutas
                            JOIN vtiger_planillastrabajo pt)
                      WHERE ((activo.ubicacion = pt.planillastrabajoid)
                             AND (pt.ruta = rutas.rutasid)))
              WHEN (crminfo.setype = 'Accounts') THEN
                     (SELECT vac.epsconsolidada
                      FROM vtiger_account vac
                      WHERE (activo.ubicacion = vac.accountid))
              WHEN (crminfo.setype = 'Vendors') THEN vendor.vendorname
          END) AS N1,
 #04     (CASE
              WHEN (crminfo.setype = 'PacientesII') THEN
                     (SELECT vtiger_pacientesii.entidadpadrename
                      FROM vtiger_pacientesii
                      WHERE (activo.ubicacion = vtiger_pacientesii.pacientesiiid))
              WHEN (crminfo.setype = 'Sedes') THEN
                     (SELECT vtiger_sedes.sede
                      FROM vtiger_sedes
                      WHERE (activo.ubicacion = vtiger_sedes.sedesid))
              WHEN (crminfo.setype = 'PlanillasTrabajo') THEN
                     (SELECT pt.identificador
                      FROM (vtiger_rutas rutas
                            JOIN vtiger_planillastrabajo pt)
                      WHERE ((activo.ubicacion = pt.planillastrabajoid)
                             AND (pt.ruta = rutas.rutasid)))
              WHEN (crminfo.setype = 'Accounts') THEN
                     (SELECT vac.epsconsolidada
                      FROM vtiger_account vac
                      WHERE (activo.ubicacion = vac.accountname))
              WHEN (crminfo.setype = 'Vendors') THEN vendor.vendorname
          END) AS N2,
 #05     (CASE
              WHEN (crminfo.setype = 'PacientesII') THEN
                     (SELECT pac_cf.cf_1619
                      FROM (vtiger_pacientesii
                            JOIN vtiger_pacientesiicf pac_cf)
                      WHERE ((activo.ubicacion = vtiger_pacientesii.pacientesiiid)
                             AND (pac_cf.pacientesiiid = vtiger_pacientesii.pacientesiiid)))
              WHEN (crminfo.setype = 'Sedes') THEN
                     (SELECT vtiger_sedescf.cf_2235
                      FROM (vtiger_sedes
                            JOIN vtiger_sedescf)
                      WHERE ((activo.ubicacion = vtiger_sedes.sedesid)
                             AND (vtiger_sedes.sedesid = vtiger_sedescf.sedesid)))
              WHEN (crminfo.setype = 'PlanillasTrabajo') THEN convert(
                                                                        (SELECT if((pt.fecha_fin > (curdate() - 4)),'Activa', 'Inactiva')
                                                                         FROM vtiger_planillastrabajo pt
                                                                         WHERE (activo.ubicacion = pt.planillastrabajoid)) USING latin1)
              WHEN (crminfo.setype = 'Accounts') THEN
                     (SELECT vac.visualizacioncreacionpaciente
                      FROM vtiger_account vac
                      WHERE (activo.ubicacion = vac.accountname))
              WHEN (crminfo.setype = 'Vendors') THEN vendor.situacionproveedor
          END) AS EstadoUbicacion,
  (SELECT vtiger_sedescf.cf_3330
   FROM (vtiger_sedes
         JOIN vtiger_sedescf)
   WHERE ((activo.ubicacion = vtiger_sedes.sedesid)
          AND (vtiger_sedes.sedesid = vtiger_sedescf.sedesid))) AS enproceso_Sede,
 #06 (CASE
      WHEN isnull(cilindro.cilindrosid) THEN 'Electrico'
      WHEN (cilindro.cilindrosid IS NOT NULL) THEN 'Gases'
  END) AS modulo,
 activo.abrv AS abrv,
 activo.estado_activo AS estado_activo,
 activo.ubicacion AS ubicacion,
 #07     (CASE
              WHEN (crminfo.setype = 'PacientesII') THEN
                     (SELECT vtiger_pacientesii.entidadpadrename
                      FROM vtiger_pacientesii
                      WHERE (activo.ubicacion = vtiger_pacientesii.pacientesiiid))
              WHEN (crminfo.setype = 'Sedes') THEN
                     (SELECT vtiger_sedes.sede
                      FROM vtiger_sedes
                      WHERE (activo.ubicacion = vtiger_sedes.sedesid))
              WHEN (crminfo.setype = 'PlanillasTrabajo') THEN
                     (SELECT pt.identificador
                      FROM (vtiger_rutas rutas
                            JOIN vtiger_planillastrabajo pt)
                      WHERE ((activo.ubicacion = pt.planillastrabajoid)
                             AND (pt.ruta = rutas.rutasid)))
              WHEN (crminfo.setype = 'Accounts') THEN
                     (SELECT vac.epsconsolidada
                      FROM vtiger_account vac
                      WHERE (activo.ubicacion = vac.accountid))
              WHEN (crminfo.setype = 'Vendors') THEN vendor.vendorname
          END) AS NomUbicacion,
 Sum(1) AS frec,
 
 count(*) AS Cantidad
    left join vtiger_crmentity crminfo on activo.ubicacion = crminfo.crmid
       LEFT JOIN vtiger_cilindros cilindro on activo.activosretornablesid = cilindro.cilindrosid
      LEFT JOIN vtiger_vendor vendor on activo.vendor_id = vendor.vendorid
group by 
         activo.subtipo,
         activo.propietario,
         NomUbicacion,
         activo.modeloequipo,
         EstadoUbicacion,
         activo.estado_activo;
Tablas involucradas:
  •  vtiger_activosretornables (Equipos Electricos).
  •  vtiger_crmentity (Datos de creación).
  •  vtiger_cilindros (Equipos de gases).
  •  vtiger_vendor (Proveedores).
Columnas involucradas:
  •  date_format(NOW(), '%Y%m%d') (Fecha actual, año, mes y dia).
  •  DATE_FORMAT(NOW(), '%Y%m') (Fecha actual, año y mes).
  •  yearweek(NOW(), 0) (Fecha actual, año y semana).
  •  activo.propietario (Propietario).
  •  activo.linea_servicio (Linea de servicio).
  •  activo.supertipo (Supertipo).
  •  activo.tipo_equipo (Tipo de equipo).
  •  activo.subtipo (Subtipo).
  •  activo.modeloequipo (Modelo de equipo).
  •  activo.situacionequipo (Situacion de equipo).
  •  #01 (Agrupar ubicación).
  •  crminfo.setype (Tipo de ubicación).
  •  #02 (Regional).
  •  #03 (Clase sede).
  •  #04 (N2).
  •  #05 (En proceso sede).
  •  #06 (Modulo).
  •  activo.abrv (Abrv).
  •  activo.estado_activo (Estado activo).
  •  activo.ubicacion (Ubicacion).
  •  #07 (Nombre de la ubicación).
  •  Sum(1) (Frecuencia).
  •  count(*) (Cantidad).
Ubicación (URL) en Redash:
Ubicación (RUTA) en base de datos:
206.189.187.192/CRM/Tables/ba_equipos_cierre_mes
Especificaciones técnicas de los campos involucrados:
Tiempo de ejecución CRON: