View
Código PHP:
<?php if ($this->session->userdata('logged_in')['tipo_perfil'] == 3 ) { ?>
<div class="row">
<div class="col-xs-6 ">
<div class="box-body">
<div class="chart">
<div id="container" style="min-width: 200px; height: 200px; margin: 0 auto"></div>
</div>
</div >
</div>
<div class="col-xs-6">
<select id="inputVendedor" name="inputVendedor" class="form-control" >
<option value="0" >Seleccione Un vendedor</option>
<?php foreach ($usuarios as $usuario) { ?>
<option value="<?php echo $usuario['id']; ?>"><?php echo $usuario['nombre'].' '.$usuario['apellido']; ?></option>
<?php } ?>
</select>
<div class="chart">
<div id="container3" style="min-width: 200px; height: 200px; margin: 0 auto"></div>
</div>
</div >
</div>
</div>
</div>
<?php } else { ?>
<div class="row">
<div class="col-xs-12 ">
<div class="box-body">
<div class="chart">
<div id="container2" style="min-width: 200px; height: 200px; margin: 0 auto"></div>
</div>
</div>
</div>
</div>
<?php } ?>
</section>
<script>
(function(a){a.createModal=function(b){defaults={title:"",message:"Your Message Goes Here!",closeButton:true,scrollable:false};var b=a.extend({},defaults,b);var c=(b.scrollable===true)?'style="max-height: 420px;overflow-y: auto;"':"";html='<div class="modal fade" id="myModal">';html+='<div class="modal-dialog">';html+='<div class="modal-content">';html+='<div class="modal-header">';html+='<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>';if(b.title.length>0){html+='<h4 class="modal-title">'+b.title+"</h4>"}html+="</div>";html+='<div class="modal-body" '+c+">";html+=b.message;html+="</div>";html+='<div class="modal-footer">';if(b.closeButton===true){html+='<button type="button" class="btn btn-primary" data-dismiss="modal">Cerrar</button>'}html+="</div>";html+="</div>";html+="</div>";html+="</div>";a("body").prepend(html);a("#myModal").modal().on("hidden.bs.modal",function(){a(this).remove()})}})(jQuery);
$(function(){
$('.view-pdf').on('click',function(){
var pdf_link = $(this).attr('href');
//var iframe = '<div class="iframe-container"><iframe src="'+pdf_link+'"></iframe></div>'
//var iframe = '<object data="'+pdf_link+'" type="application/pdf"><embed src="'+pdf_link+'" type="application/pdf" /></object>'
var iframe = '<object type="application/pdf" data="'+pdf_link+'" width="100%" height="400">No Support</object>'
$.createModal({
title:'REPORTE',
message: iframe,
closeButton:true,
scrollable:false
});
return false;
});
})
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container3',
type: 'bar',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'Total de gestiones realizadas </b><br/> por vendedores ',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: []
},
yAxis: {
title: {
text: 'Requests'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y;
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: []
}
$.getJSON("<?php echo site_url('/index.php/reportes/grupo');?>", function(json) {
options.xAxis.categories = json[0]['data'];
options.series[0] = json[1];
chart = new Highcharts.Chart(options);
});
});
</script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
Código PHP:
class Reportes extends CI_COntroller
{
function __construct()
{
parent::__construct();
$this->load->model('cliente');
$this->load->model('user');
$this->load->model('reporte_gestion');
}
function index()
{
if( $this->session->userdata('logged_in') ){
$session = $this->session->userdata('logged_in');
$content = array( 'clientes' => $this->cliente->mis_clientes(),
'usuarios' => $this->user->all_users() );
$body_view = $this->load->view('crm/reportes/home', $content, TRUE);
$modal = $this->load->view('template/modal', '' , TRUE);
$data = array( 'title' => 'Reportes',
'content_header' => array('Reportes','Home'),
'breadcrumb_inicio' => 'Reportes',
'breadcrumbs' => NULL,
'content_body' => $body_view,
'modal' => $modal,
'active' => 'reportes'
);
$this->load->view('template/template',$data);
}
else
redirect('index.php/main','refresh');
}
public function grupo() //Funcion de Graficos Array de Datos
{
$data = $this->reporte_gestion->get_group();
$category = array();
$category['name'] = 'Category';
$series1 = array();
$series1['name'] = 'Gestiones Realizadas';
foreach ($data as $row)
{
$category['data'][] = $row->vendedor;
$series1['data'][] = $row->total;
}
$result = array();
array_push($result,$category);
array_push($result,$series1);
print json_encode($result, JSON_NUMERIC_CHECK);
}
Modelo
Código PHP:
function get_group()
{
$this->db->select('tipo_gestion,Count(tipo_gestion.id) AS total,CONCAT(nombre,apellido)as vendedor');
$this->db->from('gestiones, tipo_gestion,users ');
$this->db->where('tipo_gestion_id = tipo_gestion.id AND gestiones.usuario_id = users.id AND MONTH(fecha) = MONTH(CURDATE())
AND YEAR(fecha) = YEAR(CURDATE()) ');
$this->db->where('users.id' , $vendedor);
$this->db->group_by('vendedor');
$query = $this->db->get();
return $query->result();
}