Exemplo n.º 1
0
    function cdatos()
    {
        $this->rapyd->uri->keep_persistence();
        $this->rapyd->load('datagrid2', 'fields');
        function ctipo($id, $tipo, $ejecuta)
        {
            if ($tipo == 'C') {
                return 'Calculado';
            } else {
                $rt = str_replace('return', '', $ejecuta);
                $rt = str_replace(';', '', $rt);
                $name = "pvalor[{$id}]";
                $data = array('name' => $name, 'id' => $name, 'value' => trim($rt), 'maxlength' => '100', 'size' => '15', 'class' => 'inputnum');
                return form_input($data);
            }
        }
        //echo date('Y-m-d H:i:s',mktime(0, 0, 0, date('n')-1, 1)).' - '.date('Y-m-d H:i:s',mktime(0, 0, 0, date('n')  , 0));
        $fdesde = new dateonlyField('Fecha de inicio: ', 'fdesde');
        $fhasta = new dateonlyField('Fecha Final: ', 'fhasta');
        $fdesde->insertValue = date('Y-m-d H:i:s', mktime(0, 0, 0, date('n') - 1, 1));
        $fhasta->insertValue = date('Y-m-d H:i:s', mktime(0, 0, 0, date('n'), 0));
        $fdesde->status = $fhasta->status = 'create';
        $fdesde->size = $fhasta->size = 8;
        $fdesde->dbformat = $fhasta->dbformat = 'Ymd';
        $fdesde->build();
        $fhasta->build();
        $fcorte1 = new dateonlyField('Fecha de Corte: ', 'fcorte1');
        $fcorte1->insertValue = date('Y-m-d H:i:s', mktime(0, 0, 0, date('n') - 1, 15));
        $fcorte1->dbformat = 'Ymd';
        $fcorte1->status = 'create';
        $fcorte1->size = 8;
        $fcorte1->build();
        $error = $msj = '';
        if ($this->input->post('pros') !== false) {
            $fdesde->_getNewValue();
            $fhasta->_getNewValue();
            $fcorte1->_getNewValue();
            $url = $this->url . 'ejecutor/' . $fdesde->newValue . '/' . $fcorte1->newValue . '/' . $fhasta->newValue;
            redirect($url);
            $pmargen = $this->input->post('pmargen');
            $pobject = $this->input->post('pobjetivo');
            $pvalor = $this->input->post('pvalor');
            if (is_array($pmargen)) {
                if (array_sum($pmargen) == 100) {
                    foreach ($pmargen as $id => $pm) {
                        if (is_numeric($pobject[$id])) {
                            $po = $pobject[$id];
                        } else {
                            $po = 0;
                        }
                        if (isset($pvalor[$id]) && is_numeric($pvalor[$id])) {
                            $pv = 'return ' . $pvalor[$id] . ';';
                        } else {
                            $pv = null;
                        }
                        if (is_numeric($pm) && $pm >= 0) {
                            $this->db->where('id', $id);
                            $data = array();
                            $data['puntos'] = $pm;
                            $data['objetivo'] = $po;
                            if (!empty($pv)) {
                                $data['ejecuta'] = $pv;
                            }
                            $this->db->update('gestion_indicador', $data);
                        } else {
                            $error .= 'Valor no numérico o negativo ' . $id;
                        }
                    }
                } else {
                    $error .= 'La suma de los valores debe dar exactamente 100';
                }
            } else {
                $error = 'No se puede procesar el requerimiento';
            }
        }
        $ggrid = form_open('/finanzas/gestion/cdatos') . '<p align="center">';
        $ggrid .= '<b>' . $fdesde->label . '</b>' . $fdesde->output;
        $ggrid .= '<b>' . $fhasta->label . '</b>' . $fhasta->output;
        $ggrid .= br() . '<b>' . $fcorte1->label . '</b>' . $fcorte1->output;
        $ggrid .= '</p>';
        $grid = new DataGrid2('Selecci&oacute;n de indicadores');
        $grid->agrupar(' ', 'nomgrup');
        $grid->use_function('ctipo');
        $select = array('a.descrip', 'a.indicador', 'a.tipo', 'a.puntos', 'a.id', 'a.objetivo', 'a.ejecuta', 'b.nombre AS nomgrup', 'unidad');
        $grid->db->select($select);
        $grid->db->from('gestion_indicador AS a');
        $grid->db->join('gestion_grupo AS b', 'a.id_gestion_grupo=b.id');
        $grid->db->where('a.activo', 'S');
        $grid->order_by('nomgrup');
        $campo = new inputField('Campo', 'puntos');
        $campo->grid_name = 'pmargen[<#id#>]';
        $campo->status = 'modify';
        $campo->size = 6;
        $campo->autocomplete = false;
        $campo->css_class = 'inputnum';
        $campo->disable_paste = true;
        $meta = new inputField('Meta', 'objetivo');
        $meta->grid_name = 'pobjetivo[<#id#>]';
        $meta->status = 'modify';
        $meta->size = 15;
        $meta->autocomplete = false;
        $meta->css_class = 'inputnum';
        $meta->disable_paste = true;
        $grid->column_orderby('Indicador', 'indicador', 'indicador');
        $grid->column('Puntos %', $campo, 'align=\'center\'');
        $grid->column('Objetivo', $meta, 'align=\'center\'');
        $grid->column('Unidad', 'unidad');
        $grid->column('Tipo', "<ctipo><#id#>|<#tipo#>|<#ejecuta#></ctipo>");
        $action = "javascript:window.location='" . site_url('ventas/metas/filteredgrid') . "'";
        $grid->button('btn_regresa', 'Regresar', $action, 'TR');
        $grid->submit('pros', 'Generar', 'BR');
        $grid->build();
        $ggrid .= $grid->output;
        $ggrid .= form_close();
        $script = '<script language="javascript" type="text/javascript">
		$(function(){
			$(".inputnum").numeric(".");

			$(\'input[name^="pmargen"]\').focus(function() {
				obj  = $(this);
				vval = Number(obj.val());

				tota=0;
				$(\'input[name^="pmargen"]\').each(function (i) {
					tota+=Number(this.value);
				});
				val=roundNumber(100-(tota-vval),2);
				obj.val(val);
				obj.select();
			});
		});
		</script>';
        $data['content'] = '<div class="alert">' . $error . '</div>';
        $data['content'] .= '<div>' . $msj . '</div>';
        $data['content'] .= $ggrid;
        $data['title'] = heading('Indicadores de Gesti&oacute;n');
        $data['script'] = $script;
        $data['script'] .= phpscript('nformat.js');
        $data['head'] = $this->rapyd->get_head() . script('jquery.pack.js') . script('plugins/jquery.numeric.pack.js') . script('plugins/jquery.floatnumber.js');
        $data['head'] .= style('estilos.css');
        $data['head'] .= phpscript('nformat.js');
        $this->load->view('view_ventanas', $data);
    }