<?php if ( ! defined('BASEPATH')) exit('No esta permitido el acceso directo');//impide el acceso directo a este script

if(!function_exists('mostrar_info')){

	function mostrar_info($ventas,$prospecciones,$cotizaciones,$vta_perdidas){
		//VENTAS
		$v_ventas = "<table class='table table-bordered table-hover table-condensed'>
						<thead>
							<tr>
								<th>Artículo</th>
								<th>Status</th>
								<th>Cantidad</th>
								<!--<th>Sucursal</th>-->
							</tr>
						</thead>
						<tbody>";
		if(count($ventas) != 0){
			foreach ($ventas as $registro):
				$v_ventas.= "<tr class='table-success'>
								<td>".$registro->tipo_articulo."</td>
								<td>VENTAS</td>
								<td>".$registro->tot."</td>
								<!--<td>".$registro->nombre."</td>-->
						  	</tr>";
			endforeach;
		}
		else
			$v_ventas.= "<tr class='table-danger'>
							<td colspan='4' align='center'>NO CUENTAN CON VENTAS DE NINGÚN TIPO</td>
					  	</tr>";
		$v_ventas.= "	</tbody>
					</table>";
		//PROSPECCIONES
		$v_prospecciones = "<table class='table table-bordered table-hover table-condensed'>
						<thead>
							<tr>
								<th>Status</th>
								<th>Cantidad</th>
								<!--<th>Sucursal</th>-->
							</tr>
						</thead>
						<tbody>";
		if(count($prospecciones) != 0){
			foreach ($prospecciones as $registro):
				$v_prospecciones.= "<tr class='table-success'>
										<td>PROSPECCIONES</td>
										<td>".$registro->tot."</td>
										<!--<td>".$registro->empleado_de."</td>-->
						  			</tr>";
			endforeach;
		}
		else
			$v_prospecciones.= "<tr class='table-danger'>
							<td colspan='3' align='center'>NO CUENTAN CON PROSPECCIONES DE NINGÚN TIPO</td>
					  	</tr>";
		$v_prospecciones.= "	</tbody>
							</table>";
		//COTIZACIONES
		$v_cotizaciones = "<table class='table table-bordered table-hover table-condensed'>
						<thead>
							<tr>
								<th>Artículo</th>
								<th>Status</th>
								<th>Cantidad</th>
								<!--<th>Sucursal</th>-->
							</tr>
						</thead>
						<tbody>";
		if(count($cotizaciones) != 0){
			foreach ($cotizaciones as $registro):
				$v_cotizaciones.= "<tr class='table-success'>
								<td>".$registro->tipo_articulo."</td>
								<td>COTIZACIONES</td>
								<td>".$registro->tot."</td>
								<!--<td>".$registro->nombre."</td>-->
						  	</tr>";
			endforeach;
		}
		else
			$v_cotizaciones.= "<tr class='table-danger'>
							<td colspan='4' align='center'>NO CUENTAN CON COTIZACIONES DE NINGÚN TIPO</td>
					  	</tr>";
		$v_cotizaciones.= "	</tbody>
					</table>";
		//VENTAS PERDIDAS
		$v_vta_perdida = "<table class='table table-bordered table-hover table-condensed'>
						<thead>
							<tr>
								<th>Artículo</th>
								<th>Status</th>
								<th>Cantidad</th>
								<!--<th>Sucursal</th>-->
							</tr>
						</thead>
						<tbody>";
		if(count($vta_perdidas) != 0){
			foreach ($vta_perdidas as $registro):
				$v_vta_perdida.= "	<tr class='table-success'>
								<td>".$registro->tipo_articulo."</td>
								<td>VENTAS PERDIDAS</td>
								<td>".$registro->tot."</td>
								<!--<td>".$registro->empleado_de."</td>-->
						  	</tr>";
			endforeach;
		}
		else
			$v_vta_perdida.= "<tr class='table-danger'>
							<td colspan='4' align='center'>NO CUENTAN CON VENTAS PERDIDAS DE NINGÚN TIPO</td>
					  	</tr>";
		$v_vta_perdida.= "	</tbody>
					</table>";
		/*****MOSTRAMOS LA INFO*****/
		$vista = "<br /><center>".form_button(array('type' => 'submit','content' => 'Descargar Análisis de Venta','class' => 'btn btn-success','onclick' => ''))."</center>";
		$vista.= "<br /><legend>A continuación, se muestra la sig. información de acuerdo al rango de fechas seleccionado.</legend>";
		$vista.= "<ul id='myTabs' class='nav nav-tabs' role='tablist'>
					<li role='presentation' class='nav-item'><a href='#ventas' id='ventas-tab' role='tab' data-toggle='tab' aria-controls='ventas' class='nav-link active'>VENTAS</a></li>
					<li role='presentation'><a href='#prospecciones' id='prospecciones-tab' role='tab' data-toggle='tab' aria-controls='prospecciones' class='nav-link'>PROSPECCIONES</a></li>
					<li role='presentation'><a href='#cotizaciones' id='cotizaciones-tab' role='tab' data-toggle='tab' aria-controls='cotizaciones' class='nav-link'>COTIZACIONES</a></li>
					<li role='presentation'><a href='#vta_perdidas' id='vta_perdidas-tab' role='tab' data-toggle='tab' aria-controls='vta_perdidas' class='nav-link'>VENTAS PERDIDAS</a></li>
				</ul>
				<div id='myTabContent' class='tab-content'>
					<div role='tabpanel' class='tab-pane fade show active' id='ventas' aria-labelledBy='ventas-tab'>
						<p>
							".$v_ventas."
						</p>
				    </div>
				    <div role='tabpanel' class='tab-pane fade' id='prospecciones' aria-labelledBy='prospecciones-tab'>
						<p>
							".$v_prospecciones."
						</p>
				    </div>
					<div role='tabpanel' class='tab-pane fade' id='cotizaciones' aria-labelledBy='cotizaciones-tab'>
						<p>
							".$v_cotizaciones."
						</p>
				    </div>
				    <div role='tabpanel' class='tab-pane fade' id='vta_perdidas' aria-labelledBy='vta_perdidas-tab'>
						<p>
							".$v_vta_perdida."
						</p>
				    </div>
				</div>";
		return $vista;
	}
}

if(!function_exists('descargar_excel')){

	function descargar_excel($cat_tipo_articulo,$empleados,$a_metas_ventas,$a_realizado_ventas,$a_metas_prospecciones,$a_realizado_prospecciones,$a_metas_cotizaciones,$a_realizado_cotizaciones,$a_realizado_vta_perdidas,$detalle_ejecutivo){
		$meses = array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
		$meses_num = array("01","02","03","04","05","06","07","08","09","10","11","12");
		//instanciamos el objeto para poder obtener todas sus propiedades
		$CI =& get_instance();
		$CI->load->library('reportes/excel/Excel_lib');

		//activate worksheet number 1
		$CI->excel_lib->setActiveSheetIndex(0);
		//name the worksheet
		$CI->excel_lib->getActiveSheet()->setTitle('Análisis de Ventas');
		//set cell A1 content with some text
		$CI->excel_lib->getActiveSheet()->setCellValue('B1', 'Análisis de Ventas (maquinaria y equipos solo CNH)');
		//merge cell A1 until D1
		$CI->excel_lib->getActiveSheet()->mergeCells('B1:K1');
		//set aligment to center for that merged cell (A1 to D1)
		$CI->excel_lib->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle('B1')->applyFromArray(
		    array(
		        'fill' => array(
		        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
		            'color' => array('rgb' => '0D14E7')
		        ),
		       	'font' => array(
		    		'color' => array('rgb' => 'FFFFFF'),
		    		'size' => 12,
		    		'name' => 'Arial'
		    		)
		    	)
		);
		$CI->excel_lib->getActiveSheet()->setCellValue('B2', 'Distribuidor');
		$CI->excel_lib->getActiveSheet()->setCellValue('G2', 'Fecha');
		/**************VENTAS*******************/
		$CI->excel_lib->getActiveSheet()->setCellValue('B3', 'Ventas (Unidades)');
		$CI->excel_lib->getActiveSheet()->mergeCells('B3:C3');
		$CI->excel_lib->getActiveSheet()->getStyle('B3')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle('B3')->applyFromArray(
		    array(
		        'fill' => array(
		        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
		            'color' => array('rgb' => '0D14E7')
		        ),
		       	'font' => array(
		    		'color' => array('rgb' => 'FFFFFF'),
		    		'size' => 12,
		    		'name' => 'Arial'
		    	)
			)
		);
		$CI->excel_lib->setActiveSheetIndex(0)
			->setCellValue('D3', 'Ene')
			->setCellValue('E3', 'Feb')
			->setCellValue('F3', 'Mar')
			->setCellValue('G3', 'Abr')
			->setCellValue('H3', 'May')
			->setCellValue('I3', 'Jun')
			->setCellValue('J3', 'Jul')
			->setCellValue('K3', 'Ago')
			->setCellValue('L3', 'Sep')
			->setCellValue('M3', 'Oct')
			->setCellValue('N3', 'Nov')
			->setCellValue('O3', 'Dic')
			->setCellValue('P3', 'Acumulado');
		$CI->excel_lib->getActiveSheet()->getColumnDimension('P')->setAutoSize(true);

		$CI->excel_lib->getActiveSheet()->getStyle('D3:P3')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle('D3:P3')->applyFromArray(
		    array(
		       	'font' => array(
		       		'bold' => true,
		    		'size' => 10,
		    		'name' => 'Arial'
		    	)
			)
		);
		$CI->excel_lib->getActiveSheet()->getColumnDimension('A')
			->setWidth(2)
			->setAutoSize(false);
		$CI->excel_lib->getActiveSheet()->getColumnDimension('B')->setWidth(13);
		$CI->excel_lib->getActiveSheet()->getColumnDimension('C')->setWidth(20);
		$CI->excel_lib->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

		$a = 4;
		foreach ($cat_tipo_articulo as $dato) {
			//Ajuste de texto
			$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->getAlignment()->setWrapText(true);
			//combinar y centrar
			$CI->excel_lib->getActiveSheet()->mergeCells('B'.$a.':B'.($a+2));
			$CI->excel_lib->getActiveSheet()->getStyle('B'.$a.':B'.($a+2))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$CI->excel_lib->getActiveSheet()->getStyle('B'.$a.':B'.($a+2))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$CI->excel_lib->getActiveSheet()->setCellValue('B'.$a, $dato->descripcion);
			//METAS
			$CI->excel_lib->getActiveSheet()->setCellValue('C'.$a, 'Objetivo *');
			//iniciamos en col D
			$columna = "D";
			//inicializamos
			$tot_fila_obj = 0;
			for($i = 0; $i <= 11; $i++){
				//Vemos si tiene metas (Objetivo) el articulo en el mes correspondiente
				if(isset($a_metas_ventas[$dato->descripcion][$meses[$i]])){
					$tot = $a_metas_ventas[$dato->descripcion][$meses[$i]];
					$tot_fila_obj += $tot;
				}
				else
					$tot = 0;
				//lo pegamos en la celda
				$CI->excel_lib->getActiveSheet()->setCellValue($columna.$a, $tot);
				$columna++;
			}
			//pegamos el acumulado
			//Obtenemos el porcentaje y lo pegamos en la celda
			//$CI->excel_lib->getActiveSheet()->setCellValue($columna.$a, '=SUMA(D'.$a.':O'.$a.')');
			//$CI->excel_lib->getActiveSheet()->setCellValue($columna.$a, '=SUMA(D4:E4)');
			$CI->excel_lib->getActiveSheet()->setCellValue($columna.$a, $tot_fila_obj);
			$CI->excel_lib->getActiveSheet()->getStyle($columna.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$CI->excel_lib->getActiveSheet()->getStyle($columna.$a)->applyFromArray(
			    array(
			        'fill' => array(
			        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
			            'color' => array('rgb' => 'FFF856')
			        ),
			       	'font' => array(
			    		'size' => 10,
			    		'name' => 'Arial'
			    	)
				)
			);
			//REALIZADO
			$CI->excel_lib->getActiveSheet()->setCellValue('C'.($a+1), 'Realizado **');
			//iniciamos en col D
			$columna = "D";
			//inicializamos
			$tot_fila_obj = 0;
			for($i = 0; $i <= 11; $i++){
				//Vemos si tiene metas (Objetivo) el articulo en el mes correspondiente
				if(isset($a_realizado_ventas[$dato->descripcion][$meses_num[$i]])){
					$tot = $a_realizado_ventas[$dato->descripcion][$meses_num[$i]];
					$tot_fila_obj += $tot;
				}
				else
					$tot = 0;
				//lo pegamos en la celda
				$CI->excel_lib->getActiveSheet()->setCellValue($columna.($a+1), $tot);
				$columna++;
			}
			//pegamos el acumulado
			$CI->excel_lib->getActiveSheet()->setCellValue($columna.($a+1), $tot_fila_obj);
			$CI->excel_lib->getActiveSheet()->getStyle($columna.($a+1))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$CI->excel_lib->getActiveSheet()->getStyle($columna.($a+1))->applyFromArray(
			    array(
			        'fill' => array(
			        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
			            'color' => array('rgb' => 'FFF856')
			        ),
			       	'font' => array(
			    		'size' => 10,
			    		'name' => 'Arial'
			    	)
				)
			);
			//PORCENTAJE
			$CI->excel_lib->getActiveSheet()->setCellValue('C'.($a+2), '% absorción de objetivos');
			//iniciamos en col D
			$columna = "D";
			//inicializamos
			$tot_fila_obj = 0;
			for($i = 0; $i < 13; $i++){
				//Obtenemos el porcentaje y lo pegamos en la celda
				$CI->excel_lib->getActiveSheet()->setCellValue($columna.($a+2), '='.$columna.($a+1).'/'.$columna.$a);
				$columna++;
			}
			$CI->excel_lib->getActiveSheet()->getStyle('D'.($a+2).':P'.($a+2))
				->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00);
			$CI->excel_lib->getActiveSheet()->getStyle('D'.($a+2))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$CI->excel_lib->getActiveSheet()->getStyle('D'.($a+2).':P'.($a+2))->applyFromArray(
			    array(
			        'fill' => array(
			        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
			            'color' => array('rgb' => 'FFF856')
			        ),
			       	'font' => array(
			    		'size' => 10,
			    		'name' => 'Arial'
			    	)
				)
			);
			
			$a += 3;
		}

		$CI->excel_lib->getActiveSheet()->setCellValue('B'.$a, 'Ventas totales realizadas (Unidades)');
		$CI->excel_lib->getActiveSheet()->mergeCells('B'.$a.':C'.$a);
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a.':P'.$a)->applyFromArray(
		    array(
		        'fill' => array(
		        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
		            'color' => array('rgb' => 'FFDD55')
		        ),
		       	'font' => array(
		    		'size' => 10,
		    		'name' => 'Arial'
		    	)
			)
		);


		$a+= 2;
		/*************************PROSPECCIONES***************************/
		$CI->excel_lib->getActiveSheet()->setCellValue('B'.$a, 'Prospecciones (Total de Contactos)');
		$CI->excel_lib->getActiveSheet()->mergeCells('B'.$a.':C'.$a);
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->applyFromArray(
		    array(
		        'fill' => array(
		        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
		            'color' => array('rgb' => '0D14E7')
		        ),
		       	'font' => array(
		    		'color' => array('rgb' => 'FFFFFF'),
		    		'size' => 12,
		    		'name' => 'Arial'
		    	)
			)
		);
		$CI->excel_lib->setActiveSheetIndex(0)
			->setCellValue('D'.$a, 'Ene')
			->setCellValue('E'.$a, 'Feb')
			->setCellValue('F'.$a, 'Mar')
			->setCellValue('G'.$a, 'Abr')
			->setCellValue('H'.$a, 'May')
			->setCellValue('I'.$a, 'Jun')
			->setCellValue('J'.$a, 'Jul')
			->setCellValue('K'.$a, 'Ago')
			->setCellValue('L'.$a, 'Sep')
			->setCellValue('M'.$a, 'Oct')
			->setCellValue('N'.$a, 'Nov')
			->setCellValue('O'.$a, 'Dic')
			->setCellValue('P'.$a, 'Acumulado');
		$CI->excel_lib->getActiveSheet()->getColumnDimension('P')->setAutoSize(true);

		$CI->excel_lib->getActiveSheet()->getStyle('D'.$a.':P'.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle('D'.$a.':P'.$a)->applyFromArray(
		    array(
		       	'font' => array(
		       		'bold' => true,
		    		'size' => 10,
		    		'name' => 'Arial'
		    	)
			)
		);
		$CI->excel_lib->getActiveSheet()->getColumnDimension('A')
			->setWidth(2)
			->setAutoSize(false);
		$CI->excel_lib->getActiveSheet()->getColumnDimension('B')->setWidth(13);
		$CI->excel_lib->getActiveSheet()->getColumnDimension('C')->setWidth(20);
		$CI->excel_lib->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

		$a++;

		//Ajuste de texto
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->getAlignment()->setWrapText(true);
		//combinar y centrar
		$CI->excel_lib->getActiveSheet()->mergeCells('B'.$a.':B'.($a+2));
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a.':B'.($a+2))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a.':B'.($a+2))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		$CI->excel_lib->getActiveSheet()->setCellValue('B'.$a, "Contactos / Visitas");
		//METAS
		$CI->excel_lib->getActiveSheet()->setCellValue('C'.$a, 'Objetivo ***');
		//iniciamos en col D
		$columna = "D";
		//inicializamos
		$tot_fila_obj = 0;
		for($i = 0; $i <= 11; $i++){
			//Vemos si tiene metas (Objetivo) el articulo en el mes correspondiente
			if(isset($a_metas_prospecciones[$meses[$i]])){
				$tot = $a_metas_prospecciones[$meses[$i]];
				$tot_fila_obj += $tot;
			}
			else
				$tot = 0;
			//lo pegamos en la celda
			$CI->excel_lib->getActiveSheet()->setCellValue($columna.$a, $tot);
			$columna++;
		}
		//pegamos el acumulado
		$CI->excel_lib->getActiveSheet()->setCellValue($columna.$a, $tot_fila_obj);
		$CI->excel_lib->getActiveSheet()->getStyle($columna.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle($columna.$a)->applyFromArray(
		    array(
		        'fill' => array(
		        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
		            'color' => array('rgb' => 'FFF856')
		        ),
		       	'font' => array(
		    		'size' => 10,
		    		'name' => 'Arial'
		    	)
			)
		);
		//REALIZADO
		$CI->excel_lib->getActiveSheet()->setCellValue('C'.($a+1), 'Realizado');
		//iniciamos en col D
		$columna = "D";
		//inicializamos
		$tot_fila_obj = 0;
		for($i = 0; $i <= 11; $i++){
			//Vemos si tiene metas (Objetivo) el articulo en el mes correspondiente
			if(isset($a_realizado_prospecciones[$meses_num[$i]])){
				$tot = $a_realizado_prospecciones[$meses_num[$i]];
				$tot_fila_obj += $tot;
			}
			else
				$tot = 0;
			//lo pegamos en la celda
			$CI->excel_lib->getActiveSheet()->setCellValue($columna.($a+1), $tot);
			$columna++;
		}
		//pegamos el acumulado
		$CI->excel_lib->getActiveSheet()->setCellValue($columna.($a+1), $tot_fila_obj);
		$CI->excel_lib->getActiveSheet()->getStyle($columna.($a+1))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle($columna.($a+1))->applyFromArray(
		    array(
		        'fill' => array(
		        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
		            'color' => array('rgb' => 'FFF856')
		        ),
		       	'font' => array(
		    		'size' => 10,
		    		'name' => 'Arial'
		    	)
			)
		);
		$CI->excel_lib->getActiveSheet()->getStyle($columna.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle($columna.$a)->applyFromArray(
		    array(
		        'fill' => array(
		        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
		            'color' => array('rgb' => 'FFF856')
		        ),
		       	'font' => array(
		    		'size' => 10,
		    		'name' => 'Arial'
		    	)
			)
		);
		$CI->excel_lib->getActiveSheet()->setCellValue('C'.($a+2), '% absorción de objetivos');
		//iniciamos en col D
		$columna = "D";
		//inicializamos
		$tot_fila_obj = 0;
		for($i = 0; $i < 13; $i++){
			//Obtenemos el porcentaje y lo pegamos en la celda
			$CI->excel_lib->getActiveSheet()->setCellValue($columna.($a+2), '='.$columna.($a+1).'/'.$columna.$a);
			$columna++;
		}
		$CI->excel_lib->getActiveSheet()->getStyle('D'.($a+2).':P'.($a+2))
			->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00);
		$CI->excel_lib->getActiveSheet()->getStyle('D'.($a+2))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle('D'.($a+2).':P'.($a+2))->applyFromArray(
		    array(
		        'fill' => array(
		        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
		            'color' => array('rgb' => 'FFF856')
		        ),
		       	'font' => array(
		    		'size' => 10,
		    		'name' => 'Arial'
		    	)
			)
		);

		$a += 3;
	

		$a++;
		/*************************COTIZACIONES***************************/
		$CI->excel_lib->getActiveSheet()->setCellValue('B'.$a, 'Cotizaciones ***');
		$CI->excel_lib->getActiveSheet()->mergeCells('B'.$a.':C'.$a);
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->applyFromArray(
		    array(
		        'fill' => array(
		        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
		            'color' => array('rgb' => '0D14E7')
		        ),
		       	'font' => array(
		    		'color' => array('rgb' => 'FFFFFF'),
		    		'size' => 12,
		    		'name' => 'Arial'
		    	)
			)
		);
		$CI->excel_lib->setActiveSheetIndex(0)
			->setCellValue('D'.$a, 'Ene')
			->setCellValue('E'.$a, 'Feb')
			->setCellValue('F'.$a, 'Mar')
			->setCellValue('G'.$a, 'Abr')
			->setCellValue('H'.$a, 'May')
			->setCellValue('I'.$a, 'Jun')
			->setCellValue('J'.$a, 'Jul')
			->setCellValue('K'.$a, 'Ago')
			->setCellValue('L'.$a, 'Sep')
			->setCellValue('M'.$a, 'Oct')
			->setCellValue('N'.$a, 'Nov')
			->setCellValue('O'.$a, 'Dic')
			->setCellValue('P'.$a, 'Acumulado');
		$CI->excel_lib->getActiveSheet()->getColumnDimension('P')->setAutoSize(true);

		$CI->excel_lib->getActiveSheet()->getStyle('D'.$a.':P'.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle('D'.$a.':P'.$a)->applyFromArray(
		    array(
		       	'font' => array(
		       		'bold' => true,
		    		'size' => 10,
		    		'name' => 'Arial'
		    	)
			)
		);
		$CI->excel_lib->getActiveSheet()->getColumnDimension('A')
			->setWidth(2)
			->setAutoSize(false);
		$CI->excel_lib->getActiveSheet()->getColumnDimension('B')->setWidth(13);
		$CI->excel_lib->getActiveSheet()->getColumnDimension('C')->setWidth(20);
		$CI->excel_lib->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

		$a++;

		$b = 5;//fila donde inicia la comparativa de % de efectividad vs ventas
		foreach ($cat_tipo_articulo as $dato) {
			//Ajuste de texto
			$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->getAlignment()->setWrapText(true);
			//combinar y centrar
			$CI->excel_lib->getActiveSheet()->mergeCells('B'.$a.':B'.($a+2));
			$CI->excel_lib->getActiveSheet()->getStyle('B'.$a.':B'.($a+2))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$CI->excel_lib->getActiveSheet()->getStyle('B'.$a.':B'.($a+2))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$CI->excel_lib->getActiveSheet()->setCellValue('B'.$a, $dato->descripcion);
			//METAS
			$CI->excel_lib->getActiveSheet()->setCellValue('C'.$a, 'Objetivo');
			//iniciamos en col D
			$columna = "D";
			//inicializamos
			$tot_fila_obj = 0;
			for($i = 0; $i <= 11; $i++){
				//Vemos si tiene metas (Objetivo) el articulo en el mes correspondiente
				if(isset($a_metas_cotizaciones[$dato->descripcion][$meses[$i]])){
					$tot = $a_metas_cotizaciones[$dato->descripcion][$meses[$i]];
					$tot_fila_obj += $tot;
				}
				else
					$tot = 0;
				//lo pegamos en la celda
				$CI->excel_lib->getActiveSheet()->setCellValue($columna.$a, $tot);
				$columna++;
			}
			//pegamos el acumulado
			$CI->excel_lib->getActiveSheet()->setCellValue($columna.$a, $tot_fila_obj);
			$CI->excel_lib->getActiveSheet()->getStyle($columna.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$CI->excel_lib->getActiveSheet()->getStyle($columna.$a)->applyFromArray(
			    array(
			        'fill' => array(
			        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
			            'color' => array('rgb' => 'FFF856')
			        ),
			       	'font' => array(
			    		'size' => 10,
			    		'name' => 'Arial'
			    	)
				)
			);
			//REALIZADO
			$CI->excel_lib->getActiveSheet()->setCellValue('C'.($a+1), 'Realizado');
			//iniciamos en col D
			$columna = "D";
			//inicializamos
			$tot_fila_obj = 0;
			for($i = 0; $i <= 11; $i++){
				//Vemos si tiene metas (Objetivo) el articulo en el mes correspondiente
				if(isset($a_realizado_cotizaciones[$dato->descripcion][$meses_num[$i]])){
					$tot = $a_realizado_cotizaciones[$dato->descripcion][$meses_num[$i]];
					$tot_fila_obj += $tot;
				}
				else
					$tot = 0;
				//lo pegamos en la celda
				$CI->excel_lib->getActiveSheet()->setCellValue($columna.($a+1), $tot);
				$columna++;
			}
			//pegamos el acumulado
			$CI->excel_lib->getActiveSheet()->setCellValue($columna.($a+1), $tot_fila_obj);
			$CI->excel_lib->getActiveSheet()->getStyle($columna.($a+1))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$CI->excel_lib->getActiveSheet()->getStyle($columna.($a+1))->applyFromArray(
			    array(
			        'fill' => array(
			        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
			            'color' => array('rgb' => 'FFF856')
			        ),
			       	'font' => array(
			    		'size' => 10,
			    		'name' => 'Arial'
			    	)
				)
			);
			$CI->excel_lib->getActiveSheet()->setCellValue('C'.($a+2), '% absorción de objetivos');
			//iniciamos en col D
			$columna = "D";
			//inicializamos
			$tot_fila_obj = 0;
			for($i = 0; $i < 13; $i++){
				//Obtenemos el porcentaje y lo pegamos en la celda
				$CI->excel_lib->getActiveSheet()->setCellValue($columna.($a+2), '='.$columna.($a+1).'/'.$columna.$a);
				$columna++;
			}
			$CI->excel_lib->getActiveSheet()->getStyle('D'.($a+2).':P'.($a+2))
				->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00);
			$CI->excel_lib->getActiveSheet()->getStyle('D'.($a+2))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$CI->excel_lib->getActiveSheet()->getStyle('D'.($a+2).':P'.($a+2))->applyFromArray(
			    array(
			        'fill' => array(
			        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
			            'color' => array('rgb' => 'FFF856')
			        ),
			       	'font' => array(
			    		'size' => 10,
			    		'name' => 'Arial'
			    	)
				)
			);

			$a += 3;

			$CI->excel_lib->getActiveSheet()->setCellValue('B'.$a, '% de efectividad cotizaciones vs ventas');
			//iniciamos en col D
			$columna = "D";
			//inicializamos
			$tot_fila_obj = 0;
			for($i = 0; $i < 13; $i++){
				//Obtenemos el porcentaje y lo pegamos en la celda
				$CI->excel_lib->getActiveSheet()->setCellValue($columna.$a, '='.$columna.($b).'/'.$columna.($a-2));
				$columna++;
			}
			$CI->excel_lib->getActiveSheet()->getStyle('D'.$a.':P'.$a)
				->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00);
			$CI->excel_lib->getActiveSheet()->mergeCells('B'.$a.':C'.$a);
			$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$CI->excel_lib->getActiveSheet()->getStyle('B'.$a.':P'.$a)->applyFromArray(
			    array(
			        'fill' => array(
			        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
			            'color' => array('rgb' => '79A6FF')
			        ),
			       	'font' => array(
			    		'size' => 10,
			    		'name' => 'Arial'
			    	)
				)
			);

			$a++;
			$b += 3;
		}

		$a++;
		/*************************VENTAS PERDIDAS***************************/
		$CI->excel_lib->getActiveSheet()->setCellValue('B'.$a, 'Ventas Perdidas');
		$CI->excel_lib->getActiveSheet()->mergeCells('B'.$a.':C'.$a);
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->applyFromArray(
		    array(
		        'fill' => array(
		        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
		            'color' => array('rgb' => '0D14E7')
		        ),
		       	'font' => array(
		    		'color' => array('rgb' => 'FFFFFF'),
		    		'size' => 12,
		    		'name' => 'Arial'
		    	)
			)
		);
		$CI->excel_lib->setActiveSheetIndex(0)
			->setCellValue('D'.$a, 'Ene')
			->setCellValue('E'.$a, 'Feb')
			->setCellValue('F'.$a, 'Mar')
			->setCellValue('G'.$a, 'Abr')
			->setCellValue('H'.$a, 'May')
			->setCellValue('I'.$a, 'Jun')
			->setCellValue('J'.$a, 'Jul')
			->setCellValue('K'.$a, 'Ago')
			->setCellValue('L'.$a, 'Sep')
			->setCellValue('M'.$a, 'Oct')
			->setCellValue('N'.$a, 'Nov')
			->setCellValue('O'.$a, 'Dic')
			->setCellValue('P'.$a, 'Acumulado');
		$CI->excel_lib->getActiveSheet()->getColumnDimension('P')->setAutoSize(true);

		$CI->excel_lib->getActiveSheet()->getStyle('D'.$a.':P'.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle('D'.$a.':P'.$a)->applyFromArray(
		    array(
		       	'font' => array(
		       		'bold' => true,
		    		'size' => 10,
		    		'name' => 'Arial'
		    	)
			)
		);
		$CI->excel_lib->getActiveSheet()->getColumnDimension('A')
			->setWidth(2)
			->setAutoSize(false);
		$CI->excel_lib->getActiveSheet()->getColumnDimension('B')->setWidth(13);
		$CI->excel_lib->getActiveSheet()->getColumnDimension('C')->setWidth(20);
		$CI->excel_lib->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

		$a++;

		foreach ($cat_tipo_articulo as $dato) {
			//Ajuste de texto
			$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->getAlignment()->setWrapText(true);
			//combinar y centrar
			$CI->excel_lib->getActiveSheet()->mergeCells('B'.$a.':C'.$a);
			$CI->excel_lib->getActiveSheet()->getStyle('B'.$a.':C'.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$CI->excel_lib->getActiveSheet()->getStyle('B'.$a.':C'.$a)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$CI->excel_lib->getActiveSheet()->setCellValue('B'.$a, $dato->descripcion);
			//REALIZADO
			//iniciamos en col D
			$columna = "D";
			//inicializamos
			$tot_fila_obj = 0;
			for($i = 0; $i <= 11; $i++){
				//Vemos si tiene metas (Objetivo) el articulo en el mes correspondiente
				if(isset($a_realizado_vta_perdidas[$dato->descripcion][$meses_num[$i]])){
					$tot = $a_realizado_vta_perdidas[$dato->descripcion][$meses_num[$i]];
					$tot_fila_obj += $tot;
				}
				else
					$tot = 0;
				//lo pegamos en la celda
				$CI->excel_lib->getActiveSheet()->setCellValue($columna.$a, $tot);
				$columna++;
			}
			//pegamos el acumulado
			$CI->excel_lib->getActiveSheet()->setCellValue($columna.$a, $tot_fila_obj);
			$a ++;
		}

		$CI->excel_lib->getActiveSheet()->setCellValue('B'.$a, 'Total de Ventas Perdidas');
		//iniciamos en col D
		$columna = "D";
		//inicializamos
		$tot_fila_obj = 0;
		for($i = 0; $i < 13; $i++){
			//Obtenemos el porcentaje y lo pegamos en la celda
			$CI->excel_lib->getActiveSheet()->setCellValue($columna.$a, '=SUM('.$columna.($a-4).':'.$columna.($a-1).')');
			$columna++;
		}
		//$CI->excel_lib->getActiveSheet()->getStyle('D'.$a.':P'.$a)
			//->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00);
		$CI->excel_lib->getActiveSheet()->mergeCells('B'.$a.':C'.$a);
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a.':P'.$a)->applyFromArray(
		    array(
		        'fill' => array(
		        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
		            'color' => array('rgb' => '79A6FF')
		        ),
		       	'font' => array(
		    		'size' => 10,
		    		'name' => 'Arial'
		    	)
			)
		);

		/*$CI->excel_lib->getActiveSheet()->mergeCells('B'.$a.':C'.$a);
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a.':P'.$a)->applyFromArray(
		    array(
		        'fill' => array(
		        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
		            'color' => array('rgb' => 'FFDD55')
		        ),
		       	'font' => array(
		    		'size' => 10,
		    		'name' => 'Arial'
		    	)
			)
		);*/

		$a = 1;

		/**************NUEVA HOJA DE EXCEL****************/
		$CI->excel_lib->createSheet(1);
		//activate worksheet number 1
		$CI->excel_lib->setActiveSheetIndex(1);
		//name the worksheet
		$CI->excel_lib->getActiveSheet()->setTitle('Análisis por Ejecutivo');

		//ejecutivos de venta
		//set cell A1 content with some text
		$CI->excel_lib->getActiveSheet()->setCellValue('B'.$a, 'Análisis de Ventas (detallada por ejecutvo de ventas)');
		//merge cell A1 until D1
		$CI->excel_lib->getActiveSheet()->mergeCells('B'.$a.':K'.$a);
		//set aligment to center for that merged cell (A1 to D1)
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->applyFromArray(
		    array(
		        'fill' => array(
		        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
		            'color' => array('rgb' => '0D14E7')
		        ),
		       	'font' => array(
		    		'color' => array('rgb' => 'FFFFFF'),
		    		'size' => 12,
		    		'name' => 'Arial'
		    		)
		    	)
		);
		$a += 3;

		$CI->excel_lib->getActiveSheet()->setCellValue('B'.$a, 'V = Ventas     P = Prospecciones     C =  Cotizaciones     VP = Ventas Perdidas');
		$CI->excel_lib->getActiveSheet()->mergeCells('B'.$a.':K'.$a);
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->applyFromArray(
		    array(
		        /*'fill' => array(
		        	'type' => PHPExcel_Style_Fill::FILL_SOLID
		        ),*/
		       	'font' => array(
		       		'bold' => true,
		    		'size' => 10,
		    		'name' => 'Arial'
		    		)
		    	)
		);

		$a += 2;
		
		//$CI->excel_lib->getActiveSheet()->setCellValue('B'.$a, 'Ventas (Unidades)');
		$CI->excel_lib->getActiveSheet()->mergeCells('B'.$a.':C'.$a);
		$CI->excel_lib->getActiveSheet()->mergeCells('B'.$a.':B'.($a+1));
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->applyFromArray(
		    array(
		        'fill' => array(
		        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
		            'color' => array('rgb' => '0D14E7')
		        ),
		       	'font' => array(
		    		'color' => array('rgb' => 'FFFFFF'),
		    		'size' => 12,
		    		'name' => 'Arial'
		    	)
			)
		);
		$CI->excel_lib->setActiveSheetIndex(1)
			->setCellValue('D'.$a, 'Ene')
			->setCellValue('H'.$a, 'Feb')
			->setCellValue('L'.$a, 'Mar')
			->setCellValue('P'.$a, 'Abr')
			->setCellValue('T'.$a, 'May')
			->setCellValue('X'.$a, 'Jun')
			->setCellValue('AB'.$a, 'Jul')
			->setCellValue('AF'.$a, 'Ago')
			->setCellValue('AJ'.$a, 'Sep')
			->setCellValue('AN'.$a, 'Oct')
			->setCellValue('AR'.$a, 'Nov')
			->setCellValue('AV'.$a, 'Dic');
		$CI->excel_lib->getActiveSheet()->getColumnDimension('P')->setAutoSize(true);

		$CI->excel_lib->getActiveSheet()->getStyle('D'.$a.':AY'.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle('D'.$a.':AY'.$a)->applyFromArray(
		    array(
		       	'font' => array(
		       		'bold' => true,
		    		'size' => 10,
		    		'name' => 'Arial'
		    	)
			)
		);

		$CI->excel_lib->getActiveSheet()->getStyle('D'.($a+1).':AY'.($a+1))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$CI->excel_lib->getActiveSheet()->getStyle('D'.($a+1).':AY'.($a+1))->applyFromArray(
		    array(
		       	'font' => array(
		       		'bold' => true,
		    		'size' => 10,
		    		'name' => 'Arial'
		    	)
			)
		);

		$i = 1;
		$status = array('VP','V','P','C');
		for($col = 'D'; $col !== 'AZ'; $col++){
			if($i == 4){
				$CI->excel_lib->getActiveSheet()->mergeCells($col_inicio.$a.':'.$col.$a);
				$i = 0;
			}
			elseif($i == 1)
				$col_inicio = $col;

			$CI->excel_lib->getActiveSheet()->setCellValue($col.($a+1), $status[$i]);
			$CI->excel_lib->getActiveSheet()->getColumnDimension($col)
				->setWidth(4)
				->setAutoSize(false);
			$i++;
		}

		$CI->excel_lib->getActiveSheet()->getColumnDimension('A')
			->setWidth(2)
			->setAutoSize(false);

		$CI->excel_lib->getActiveSheet()->getColumnDimension('B')->setWidth(13);
		$CI->excel_lib->getActiveSheet()->getColumnDimension('C')->setWidth(25);
		$CI->excel_lib->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

		$a += 2;











		$status = array('V','P','C','VP');

		foreach ($empleados as $dato) {

			//Ajuste de texto
			$CI->excel_lib->getActiveSheet()->getStyle('B'.$a)->getAlignment()->setWrapText(true);
			//combinar y centrar
			$CI->excel_lib->getActiveSheet()->mergeCells('B'.$a.':B'.($a+4));
			$CI->excel_lib->getActiveSheet()->getStyle('B'.$a.':B'.($a+4))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$CI->excel_lib->getActiveSheet()->getStyle('B'.$a.':B'.($a+4))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$CI->excel_lib->getActiveSheet()->setCellValue('B'.$a, $dato->ejecutivo);

			foreach ($cat_tipo_articulo as $articulo) {
				$CI->excel_lib->getActiveSheet()->setCellValue('C'.$a, $articulo->descripcion);
				//iniciamos en col D
				$columna = "D";
				//inicializamos
				$tot_fila_obj = 0;
				for($i = 0; $i <= 11; $i++){
					for($j = 0; $j < 4; $j++){
						if($j != 1){
							if(isset($detalle_ejecutivo[$dato->ejecutivo][$articulo->descripcion][$status[$j]][$meses_num[$i]])){
								$tot = $detalle_ejecutivo[$dato->ejecutivo][$articulo->descripcion][$status[$j]][$meses_num[$i]];
							}
							else
								$tot = 0;
							//lo pegamos en la celda
							$CI->excel_lib->getActiveSheet()->setCellValue($columna.$a, $tot);
						}
						else{
							if(isset($detalle_ejecutivo[$dato->ejecutivo][$status[$j]][$meses_num[$i]])){
								$tot = $detalle_ejecutivo[$dato->ejecutivo][$status[$j]][$meses_num[$i]];
							}
							else
								$tot = 0;
							//combinar y centrar
							$CI->excel_lib->getActiveSheet()->mergeCells($columna.$a.':'.$columna.($a+1));
							//$CI->excel_lib->getActiveSheet()->getStyle($columna.$a.':'.$columna.($a+3))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
							//$CI->excel_lib->getActiveSheet()->getStyle($columna.$a.':'.$columna.($a+3))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
							//lo pegamos en la celda
							$CI->excel_lib->getActiveSheet()->setCellValue($columna.$a, $tot);
						}
						$columna++;
					}
				}
				
				$CI->excel_lib->getActiveSheet()->getStyle($columna.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$CI->excel_lib->getActiveSheet()->getStyle($columna.$a)->applyFromArray(
				    array(
				       	'font' => array(
				    		'size' => 10,
				    		'name' => 'Arial'
				    	)
					)
				);

				$a++;
				
			}

			//TOTALES por COLUMNA
			$CI->excel_lib->getActiveSheet()->setCellValue('C'.$a, 'TOTAL');
			//iniciamos en col D
			$columna = "D";
			//inicializamos
			$tot_fila_obj = 0;
			for($i = 0; $i < 48; $i++){
				//Obtenemos el porcentaje y lo pegamos en la celda
				$CI->excel_lib->getActiveSheet()->setCellValue($columna.$a, '=SUM('.$columna.($a-4).':'.$columna.($a-1).')');
				$columna++;
			}
			
			$CI->excel_lib->getActiveSheet()->getStyle('D'.$a)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$CI->excel_lib->getActiveSheet()->getStyle('C'.$a.':AY'.$a)->applyFromArray(
		    array(
		        'fill' => array(
		        	'type' => PHPExcel_Style_Fill::FILL_SOLID,
		            'color' => array('rgb' => 'FFDD55')
		        ),
		       	'font' => array(
		    		'size' => 10,
		    		'name' => 'Arial'
		    	)
			)
			);

			$a++;
			
		}














		$CI->excel_lib->setActiveSheetIndex(0);
		//Descargar fichero
		$filename='Análisis de Ventas.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
		            
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($CI->excel_lib, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

}