{
    "type": "Ext.grid.Panel",
    "reference": {
        "name": "items",
        "type": "array"
    },
    "codeClass": null,
    "userConfig": {
        "id": "gridTardanza",
        "itemId": "gridTardanza",
        "designer|userClassName": "gridTardanza",
        "designer|userAlias": "gridtardanza",
        "title": null,
        "lockedViewConfig": [
            "{\r",
            "    scroll: false\r",
            "}"
        ],
        "normalGridConfig": [
            "{\r",
            "    scroll: 'both'\r",
            "}"
        ],
        "columnLines": true
    },
    "designerId": "dabbc91f-7f6e-48ae-a72a-abcb8a7b2492",
    "cn": [
        {
            "type": "Ext.grid.View",
            "reference": {
                "name": "viewConfig",
                "type": "object"
            },
            "codeClass": null,
            "designerId": "f6ffe75b-8871-4265-93b0-b6b3bb826527"
        },
        {
            "type": "Ext.grid.column.Number",
            "reference": {
                "name": "columns",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "hidden": true,
                "dataIndex": "id_vinculo",
                "lockable": true,
                "locked": true,
                "text": "Id_vinculo"
            },
            "designerId": "b1ac43e4-729a-42fc-b2bd-b00c7e6e3a13"
        },
        {
            "type": "Ext.grid.column.Column",
            "reference": {
                "name": "columns",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "width": 65,
                "dataIndex": "indiv_dni",
                "lockable": true,
                "locked": true,
                "text": "D.N.I."
            },
            "designerId": "9605bcf3-51fc-4186-b910-9b9067e5648b"
        },
        {
            "type": "Ext.grid.column.Column",
            "reference": {
                "name": "columns",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "minWidth": 180,
                "dataIndex": "nombre_persona",
                "lockable": true,
                "locked": true,
                "text": "Apellidos y Nombres",
                "flex": 2
            },
            "designerId": "cb539fa4-e159-4f0c-ae8b-7bd57af2b978"
        },
        {
            "type": "Ext.grid.column.Column",
            "reference": {
                "name": "columns",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "minWidth": 150,
                "dataIndex": "cargo",
                "lockable": true,
                "locked": true,
                "text": "Cargo",
                "flex": 1
            },
            "designerId": "2ec62f1e-fdda-4b33-af93-d9d32a9cdcb7"
        },
        {
            "type": "Ext.grid.column.Column",
            "reference": {
                "name": "columns",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "minWidth": 90,
                "dataIndex": "situacionlaboral",
                "lockable": true,
                "locked": true,
                "text": "Situac. Laboral",
                "flex": 1
            },
            "designerId": "9630b863-a467-47ce-ad8c-5d43a57409ad"
        },
        {
            "type": "Ext.grid.column.Column",
            "reference": {
                "name": "columns",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "minWidth": 40,
                "dataIndex": "jornada",
                "lockable": true,
                "locked": true,
                "text": "Jorn",
                "flex": 1
            },
            "designerId": "88f98ff6-ae56-4e58-8b99-7db88bd68623"
        },
        {
            "type": "Ext.toolbar.Toolbar",
            "reference": {
                "name": "dockedItems",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "dock": "top",
                "height": 35
            },
            "designerId": "b93845d8-33f3-4f75-8ce5-a8f3ce72ff43",
            "cn": [
                {
                    "type": "Ext.form.Label",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null,
                        "itemId": "txtInstitucion",
                        "text": null
                    },
                    "designerId": "0a8cf4c0-0627-4eb9-870f-3ba7fae23375"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "8858e1e7-d36d-4bc4-bce0-1199c65f7d1a"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "4e73a6b1-2729-4780-9209-66f803caa3f4"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "7ce9569c-4aff-462c-9e6d-c9574f72c969"
                },
                {
                    "type": "Ext.form.Label",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null,
                        "itemId": "txtNivel",
                        "text": null
                    },
                    "designerId": "5c452300-6cf9-4b55-92ac-3936aa20a128"
                },
                {
                    "type": "Ext.form.Label",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null,
                        "hidden": true,
                        "itemId": "txtie",
                        "text": null
                    },
                    "designerId": "293d6db2-e7ac-48c9-b20b-6701f9dfa304"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "5611940a-a1dc-4c7e-bc4e-c85bd150b2ca"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "84f7d5f7-a6c9-48ed-b03a-60a756c22138"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "cb7f951a-f7f5-4091-9ef7-3b7301b268f4"
                },
                {
                    "type": "Ext.form.field.ComboBox",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null,
                        "autoRender": false,
                        "id": "id_meses2",
                        "margin": "0 0 0 5",
                        "width": 152,
                        "fieldLabel": "Mes",
                        "labelAlign": "right",
                        "labelWidth": 40,
                        "name": "id_meses",
                        "value": [
                            "new Date().getMonth() + 1"
                        ],
                        "enableKeyEvents": true,
                        "selectOnFocus": true,
                        "editable": false,
                        "displayField": "nombre_meses",
                        "store": "meses",
                        "typeAhead": true,
                        "valueField": "id_meses"
                    },
                    "designerId": "bf087e60-b1fd-4a37-a7fe-7cb6642994f0",
                    "cn": [
                        {
                            "type": "basiceventbinding",
                            "reference": {
                                "name": "listeners",
                                "type": "array"
                            },
                            "codeClass": null,
                            "userConfig": {
                                "fn": "onId_meses2AfterRender",
                                "implHandler": [
                                    "var v = new Date().getMonth() + 1; // 1..12\r",
                                    "var s = component.getStore();\r",
                                    "if (!s) return;\r",
                                    "// Si el store no está cargado, espera a que cargue\r",
                                    "if (s.isLoading()) {\r",
                                    "    s.on('load', function(){ component.setValue(v); }, { single:true });\r",
                                    "} else if (s.getCount() === 0 && s.load) {\r",
                                    "    s.load(function(){ component.setValue(v); });\r",
                                    "} else {\r",
                                    "    component.setValue(v);\r",
                                    "}\r",
                                    ""
                                ],
                                "name": "afterrender",
                                "scope": "me"
                            },
                            "designerId": "36e584d2-d2b2-4669-a11c-d0e98494ea57"
                        }
                    ]
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "696b48eb-cf2f-45a5-b89c-1b4942915adf"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "c275ed96-5925-42af-a0f7-568aab5c6f5b"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "152bb6d3-95c6-4193-bea4-fc022e0cb9e6"
                },
                {
                    "type": "Ext.form.field.Number",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null,
                        "id": "anio2",
                        "width": 107,
                        "fieldLabel": "Año",
                        "labelAlign": "right",
                        "labelWidth": 40,
                        "submitValue": false,
                        "value": [
                            "new Date().getFullYear()"
                        ],
                        "maxValue": 2030,
                        "minValue": 2025
                    },
                    "designerId": "85d835de-663b-4484-bbf5-1e091ed2afc2"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "ebd8e129-38fd-4dc6-988a-5632061bba05"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "83fd3bf7-8622-4cb6-96a6-02575628d01e"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "75f9686f-e090-4807-a2a8-ee7249633d0c"
                },
                {
                    "type": "Ext.form.field.ComboBox",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null,
                        "id": "idtipotrabajador4",
                        "itemId": "idtipotrabajador4",
                        "width": 193,
                        "fieldLabel": "Tip. Trab.",
                        "labelAlign": "right",
                        "labelWidth": 60,
                        "name": "idtipotrabajador",
                        "submitValue": false,
                        "value": [
                            "new Date().getFullYear()"
                        ],
                        "allowBlank": false,
                        "enableKeyEvents": true,
                        "selectOnFocus": true,
                        "editable": false,
                        "displayField": "nombretipotrabajador",
                        "forceSelection": true,
                        "store": "tipotrabajador",
                        "valueField": "idtipotrabajador"
                    },
                    "designerId": "b8e7e79a-1625-415c-beb6-bdffe8f1991d"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "41d67afe-c6ce-4563-bcfa-21fe3ae50db7"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "8f234f86-043e-499e-adab-0dda7e16e84e"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "52801a16-d9e8-4257-8005-0dfddda4d8ac"
                },
                {
                    "type": "Ext.button.Button",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null,
                        "height": 23,
                        "width": 67,
                        "icon": "img/demo16.png",
                        "text": "Aceptar"
                    },
                    "designerId": "9e0f1913-ec8b-4877-84ff-193743be6674",
                    "cn": [
                        {
                            "type": "basicfunction",
                            "reference": {
                                "name": "items",
                                "type": "array"
                            },
                            "codeClass": null,
                            "userConfig": {
                                "fn": "handler",
                                "implHandler": [
                                    "var w = Ext.ComponentQuery.query('asistencia')[0];\r",
                                    "\r",
                                    "// ==============================\r",
                                    "// OBTENER CODIE\r",
                                    "// ==============================\r",
                                    "var codie = '';\r",
                                    "var cmpIe = w.down('#txtie');\r",
                                    "\r",
                                    "if (cmpIe) {\r",
                                    "    var raw = cmpIe.text || \r",
                                    "    (cmpIe.getEl() && cmpIe.getEl().dom && cmpIe.getEl().dom.textContent) || '';\r",
                                    "    codie = raw.replace(/^CODIE:\\s*/,'').trim();\r",
                                    "}\r",
                                    "\r",
                                    "// ==============================\r",
                                    "// OBTENER FILTROS\r",
                                    "// ==============================\r",
                                    "var mes  = (Ext.getCmp('id_meses2') && Ext.getCmp('id_meses2').getValue()) || '';\r",
                                    "var anio = (Ext.getCmp('anio2') && Ext.getCmp('anio2').getValue()) || '';\r",
                                    "var idtipotrabajador2 = (Ext.getCmp('idtipotrabajador4') && Ext.getCmp('idtipotrabajador4').getValue()) || '';\r",
                                    "\r",
                                    "// ==============================\r",
                                    "// VALIDACIONES\r",
                                    "// ==============================\r",
                                    "if (!mes || mes < 1 || mes > 12) {\r",
                                    "    Ext.Msg.alert('Validación', 'Seleccione un mes válido.');\r",
                                    "    return;\r",
                                    "}\r",
                                    "\r",
                                    "if (!anio || anio < 2020) {\r",
                                    "    Ext.Msg.alert('Validación', 'Ingrese un año válido.');\r",
                                    "    return;\r",
                                    "}\r",
                                    "\r",
                                    "if (!codie) {\r",
                                    "    Ext.Msg.alert('Validación', 'No se encontró el CODIE.');\r",
                                    "    return;\r",
                                    "}\r",
                                    "\r",
                                    "// ==============================\r",
                                    "// PETICIÓN AJAX\r",
                                    "// ==============================\r",
                                    "Ext.Ajax.request({\r",
                                    "    url: 'controladores/TardanzaMensualDiario.php',\r",
                                    "    method: 'POST',\r",
                                    "    params: {\r",
                                    "        codie: codie,\r",
                                    "        mes: mes,\r",
                                    "        anio: anio,\r",
                                    "        idtipotrabajador2: idtipotrabajador2\r",
                                    "    },\r",
                                    "\r",
                                    "    success: function(response) {\r",
                                    "\r",
                                    "        var json = Ext.decode(response.responseText);\r",
                                    "\r",
                                    "        if (!json.success) {\r",
                                    "            Ext.Msg.alert('Error', 'No se pudo cargar el reporte.');\r",
                                    "            return;\r",
                                    "        }\r",
                                    "\r",
                                    "        var grid  = Ext.getCmp('gridTardanza');\r",
                                    "        var store = Ext.data.StoreManager.lookup('TardanzaMensualStore');\r",
                                    "\r",
                                    "        grid.suspendLayouts();\r",
                                    "\r",
                                    "        // ==============================\r",
                                    "        // CREAR MODELO DINÁMICO\r",
                                    "        // ==============================\r",
                                    "        var nuevosCampos = [];\r",
                                    "\r",
                                    "        function extraerCampos(cols) {\r",
                                    "            Ext.Array.each(cols, function(col) {\r",
                                    "                if (col.dataIndex) {\r",
                                    "                    nuevosCampos.push(col.dataIndex);\r",
                                    "                }\r",
                                    "                if (col.columns) {\r",
                                    "                    extraerCampos(col.columns);\r",
                                    "                }\r",
                                    "            });\r",
                                    "        }\r",
                                    "\r",
                                    "        extraerCampos(json.columnas);\r",
                                    "\r",
                                    "        Ext.define('TardanzaModelDinamico', {\r",
                                    "            extend: 'Ext.data.Model',\r",
                                    "            fields: nuevosCampos\r",
                                    "        });\r",
                                    "\r",
                                    "        // 👉 FORMA CORRECTA EN EXT 4\r",
                                    "        store.model = Ext.ModelManager.getModel('TardanzaModelDinamico');\r",
                                    "        store.removeAll(true);\r",
                                    "\r",
                                    "        // ==============================\r",
                                    "        // RECONFIGURAR GRID\r",
                                    "        // ==============================\r",
                                    "        grid.reconfigure(store, json.columnas);\r",
                                    "\r",
                                    "        // ==============================\r",
                                    "        // CARGAR DATA\r",
                                    "        // ==============================\r",
                                    "        store.loadData(json.data);\r",
                                    "\r",
                                    "        grid.getView().refresh(true);\r",
                                    "        grid.resumeLayouts(true);\r",
                                    "        grid.updateLayout();\r",
                                    "    },\r",
                                    "\r",
                                    "    failure: function() {\r",
                                    "        Ext.Msg.alert('Error', 'Error de conexión con el servidor.');\r",
                                    "    }\r",
                                    "});\r",
                                    ""
                                ]
                            },
                            "designerId": "ec2768cb-5ecf-4b41-b42c-f3b815e92122"
                        }
                    ]
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "ac0338c8-e7b4-4d2d-b3b8-ed51a310333a"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "0bf84a25-e97e-49a6-8058-2878fd567f78"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "a6f5b926-a0d0-4610-8139-f4d27b139dc0"
                },
                {
                    "type": "Ext.button.Button",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null,
                        "icon": "img/excel.png",
                        "text": "Excel"
                    },
                    "designerId": "86a848c0-30f5-4cda-bb25-93af0df3bb38",
                    "cn": [
                        {
                            "type": "basicfunction",
                            "reference": {
                                "name": "items",
                                "type": "array"
                            },
                            "codeClass": null,
                            "userConfig": {
                                "fn": "handler",
                                "implHandler": [
                                    "var w     = Ext.ComponentQuery.query('asistencia')[0];\r",
                                    "var codie = '';\r",
                                    "var cmpIe = w.down('#txtie');\r",
                                    "if (cmpIe) {\r",
                                    "    var raw = cmpIe.text || (cmpIe.getEl() && cmpIe.getEl().dom && cmpIe.getEl().dom.textContent) || '';\r",
                                    "    codie = raw.replace(/^CODIE:\\s*/,'').trim();\r",
                                    "}\r",
                                    "var mes   = Ext.getCmp('id_meses2').getValue();\r",
                                    "var anio  = Ext.getCmp('anio2').getValue();\r",
                                    "var idtipotrabajador2 = Ext.getCmp('idtipotrabajador4').getValue();\r",
                                    "\r",
                                    "var form = Ext.DomHelper.append(Ext.getBody(), {\r",
                                    "    tag: 'form',\r",
                                    "    method: 'POST',\r",
                                    "    action: 'export_excel_tardanza.php',\r",
                                    "    style: 'display:none'\r",
                                    "}, true);\r",
                                    "\r",
                                    "form.createChild({ tag:'input', type:'hidden', name:'mes', value: mes });\r",
                                    "form.createChild({ tag:'input', type:'hidden', name:'anio', value: anio });\r",
                                    "form.createChild({ tag:'input', type:'hidden', name:'codie', value: codie });\r",
                                    "form.createChild({ tag:'input', type:'hidden', name:'idtipotrabajador2', value: idtipotrabajador2 });\r",
                                    "\r",
                                    "form.dom.submit();\r",
                                    "form.remove();"
                                ]
                            },
                            "designerId": "2802885c-7128-4d52-a801-fd62aff207ce"
                        }
                    ]
                },
                {
                    "type": "Ext.toolbar.Fill",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "a4907047-a5fc-45e8-81d8-225e7a9f6bc0"
                },
                {
                    "type": "Ext.button.Button",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null,
                        "icon": "img/exit.png",
                        "text": "Salir"
                    },
                    "designerId": "a8d130cd-1e4a-46e3-bde3-b6c96cb1bfb8",
                    "cn": [
                        {
                            "type": "basicfunction",
                            "reference": {
                                "name": "items",
                                "type": "array"
                            },
                            "codeClass": null,
                            "userConfig": {
                                "fn": "handler",
                                "designer|params": [
                                    "button"
                                ],
                                "implHandler": [
                                    "var win    = button.up('window');\r",
                                    "win.close();\r",
                                    ""
                                ]
                            },
                            "designerId": "c5d9976e-c22f-4d27-a608-a5c3847d0bf1"
                        }
                    ]
                }
            ]
        }
    ]
}