<?php
  session_start();

  if (isset($_SESSION['tipousuario'])){
    if ($_SESSION['tipousuario']=='1'){
      header ('location:menu_personal.php');
    }
  }

  if (trim($_SESSION['nombre_validar'])==''){
    header ('location:index.php');
  }
  
  include ("fphp.php");
  include ("calendario/calendario.php");
  require_once 'PHPExcel/PHPExcel.php';
  $enlace=cargar_conexion();

  $objPHPExcel = new PHPExcel();

  $objPHPExcel->getProperties()->setCreator("Saireh")
  ->setLastModifiedBy("Saireh")->setTitle("Reporte de aportes a la caja de ahorros")
  ->setSubject("Reporte de aportes a la caja de ahorros ")->setDescription("Reporte")
  ->setKeywords("reporte")->setCategory("Reporte Ahorros");
  
  PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);

  // ----------------------------------------------------------------------

  $objPHPExcel->getActiveSheet()->setCellValue("A1","MERSAN CA");
  $objPHPExcel->getActiveSheet()->getStyle("A1")->getFont()->setBold( true );
  
  $objPHPExcel->getActiveSheet()->setCellValue("C2","VACACIONES DE NOMINA MENSUAL");
  $objPHPExcel->getActiveSheet()->getStyle("C2")->getFont()->setBold( true );

  // ----------------------------------------------------------------------

  $objPHPExcel->getActiveSheet()->setCellValue("A3","Periodo: …");
  $objPHPExcel->getActiveSheet()->setCellValue("A4","Antiguedad: …");
  $objPHPExcel->getActiveSheet()->setCellValue("A5","Fecha desde: …");
  $objPHPExcel->getActiveSheet()->setCellValue("A6","Fecha Hasta: …");
  $objPHPExcel->getActiveSheet()->setCellValue("A7","Fecha de Reincorporacion: …");

  // ----------------------------------------------------------------------

  $objPHPExcel->getActiveSheet()->setCellValue("A9","DATOS DEL TRABAJADOR:");
  $objPHPExcel->getActiveSheet()->getStyle("A9")->getFont()->setBold( true );

  $objPHPExcel->getActiveSheet()->setCellValue("A10","Nombre:");
  $objPHPExcel->getActiveSheet()->setCellValue("B10","JORGE RODRIGUEZ");
  $objPHPExcel->getActiveSheet()->setCellValue("A11","Cedula:");
  $objPHPExcel->getActiveSheet()->setCellValue("B11","12345678");
  $objPHPExcel->getActiveSheet()->setCellValue("A12","Fecha de Ingreso:");
  $objPHPExcel->getActiveSheet()->setCellValue("B12","12-12-2020");
  $objPHPExcel->getActiveSheet()->setCellValue("A13","Departamento:");
  $objPHPExcel->getActiveSheet()->setCellValue("B13","Departamento");
  $objPHPExcel->getActiveSheet()->setCellValue("A14","Unidad:");
  $objPHPExcel->getActiveSheet()->setCellValue("B14","Unidad Ejemplo");
  $objPHPExcel->getActiveSheet()->setCellValue("A15","Cargo:");
  $objPHPExcel->getActiveSheet()->setCellValue("B15","Cargo Ejemplo");
  $objPHPExcel->getActiveSheet()->setCellValue("A16","Fecha de procesado:");
  $objPHPExcel->getActiveSheet()->setCellValue("B16","11-11-2020");
  $objPHPExcel->getActiveSheet()->setCellValue("A17","Nomina:");
  $objPHPExcel->getActiveSheet()->setCellValue("B17","200");

  $objPHPExcel->getActiveSheet()->getStyle('A9:A17')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  $objPHPExcel->getActiveSheet()->getStyle('B9:B17')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);

  // ----------------------------------------------------------------------
  
  $objPHPExcel->getActiveSheet()->setCellValue("D9","DATOS DEL PAQUETE:");
  $objPHPExcel->getActiveSheet()->getStyle("D9")->getFont()->setBold( true );

  $objPHPExcel->getActiveSheet()->setCellValue("D10","Paquete mens (USD):");
  $objPHPExcel->getActiveSheet()->setCellValue("E10","$ 1000.00");
  $objPHPExcel->getActiveSheet()->setCellValue("D11","Salario diario en (USD):");
  $objPHPExcel->getActiveSheet()->setCellValue("E11","$ 33.33");
  $objPHPExcel->getActiveSheet()->setCellValue("D12","Tasa Bs/$ para cálculos:");
  $objPHPExcel->getActiveSheet()->setCellValue("E12","4.57");
  
  $objPHPExcel->getActiveSheet()->getStyle('D9:D17')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  $objPHPExcel->getActiveSheet()->getStyle('E9:E17')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);

  // ----------------------------------------------------------------------

  $objPHPExcel->getActiveSheet()->setCellValue("B19","CALCULO DE VACACIONES EN USD ($)");
  $objPHPExcel->getActiveSheet()->getStyle("B19")->getFont()->setBold( true );

  $objPHPExcel->getActiveSheet()->setCellValue("B20","Dias");
  $objPHPExcel->getActiveSheet()->setCellValue("C20","Salario Diario");

  $objPHPExcel->getActiveSheet()->setCellValue("A21","VACACIONES");
  $objPHPExcel->getActiveSheet()->setCellValue("B21","15");
  $objPHPExcel->getActiveSheet()->setCellValue("C21","$33.33");
  $objPHPExcel->getActiveSheet()->setCellValue("D21","$500.00");
  $objPHPExcel->getActiveSheet()->getStyle('A21')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  $objPHPExcel->getActiveSheet()->getStyle('B21')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  $objPHPExcel->getActiveSheet()->getStyle('C21')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  $objPHPExcel->getActiveSheet()->getStyle('D21')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  $objPHPExcel->getActiveSheet()->getStyle("B21")->getFont()->setBold( true );

  $objPHPExcel->getActiveSheet()->setCellValue("A22","DIAS ADIC");
  $objPHPExcel->getActiveSheet()->setCellValue("B22","3");
  $objPHPExcel->getActiveSheet()->setCellValue("C22","$33.33");
  $objPHPExcel->getActiveSheet()->setCellValue("D22","$100.00");
  $objPHPExcel->getActiveSheet()->getStyle('A22')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  $objPHPExcel->getActiveSheet()->getStyle('B22')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  $objPHPExcel->getActiveSheet()->getStyle('C22')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  $objPHPExcel->getActiveSheet()->getStyle('D22')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  $objPHPExcel->getActiveSheet()->getStyle("B22")->getFont()->setBold( true );

  $objPHPExcel->getActiveSheet()->setCellValue("A23","DIAS BON VACAC");
  $objPHPExcel->getActiveSheet()->setCellValue("B23","38");
  $objPHPExcel->getActiveSheet()->setCellValue("C23","$33.33");
  $objPHPExcel->getActiveSheet()->setCellValue("D23","$1,266.67");
  $objPHPExcel->getActiveSheet()->getStyle('A23')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  $objPHPExcel->getActiveSheet()->getStyle('B23')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  $objPHPExcel->getActiveSheet()->getStyle('C23')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  $objPHPExcel->getActiveSheet()->getStyle('D23')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  $objPHPExcel->getActiveSheet()->getStyle("B23")->getFont()->setBold( true );

  $objPHPExcel->getActiveSheet()->setCellValue("A23","DIAS DESCANSO");
  $objPHPExcel->getActiveSheet()->setCellValue("B23","6");
  $objPHPExcel->getActiveSheet()->setCellValue("C23","$33.33");
  $objPHPExcel->getActiveSheet()->setCellValue("D23","$200.00");
  $objPHPExcel->getActiveSheet()->getStyle('A23')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  $objPHPExcel->getActiveSheet()->getStyle('B23')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  $objPHPExcel->getActiveSheet()->getStyle('C23')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  $objPHPExcel->getActiveSheet()->getStyle('D23')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  $objPHPExcel->getActiveSheet()->getStyle("B23")->getFont()->setBold( true );

  $objPHPExcel->getActiveSheet()->setCellValue("A24","BONO POST VACIONAL");
  $objPHPExcel->getActiveSheet()->setCellValue("B24","15");
  $objPHPExcel->getActiveSheet()->setCellValue("C24","$33.33");
  $objPHPExcel->getActiveSheet()->setCellValue("D24","$500.00");
  $objPHPExcel->getActiveSheet()->getStyle('A24')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  $objPHPExcel->getActiveSheet()->getStyle('B24')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  $objPHPExcel->getActiveSheet()->getStyle('C24')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  $objPHPExcel->getActiveSheet()->getStyle('D24')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  $objPHPExcel->getActiveSheet()->getStyle("B24")->getFont()->setBold( true );

  $objPHPExcel->getActiveSheet()->setCellValue("C25","Total vacaciones calculadas en $");
  $objPHPExcel->getActiveSheet()->setCellValue("D25","$2,566.67");
  $objPHPExcel->getActiveSheet()->getStyle('C25')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  $objPHPExcel->getActiveSheet()->getStyle('D25')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  $objPHPExcel->getActiveSheet()->getStyle("D25")->getFont()->setBold( true );

  $objPHPExcel->getActiveSheet()->getColumnDimension("B")->setAutoSize(true);
  $objPHPExcel->getActiveSheet()->getColumnDimension("D")->setAutoSize(true);

  
  $objPHPExcel->getActiveSheet()->getStyle('A19:D19')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_MEDIUM);
  $objPHPExcel->getActiveSheet()->getStyle('D19:D25')->getBorders()->getRight()->setBorderStyle(PHPExcel_Style_Border::BORDER_MEDIUM);
  $objPHPExcel->getActiveSheet()->getStyle('A19:A25')->getBorders()->getLeft()->setBorderStyle(PHPExcel_Style_Border::BORDER_MEDIUM);
  $objPHPExcel->getActiveSheet()->getStyle('A25:D25')->getBorders()->getBottom()->setBorderStyle(PHPExcel_Style_Border::BORDER_MEDIUM);

  // ----------------------------------------------------------------------
  
  $objPHPExcel->getActiveSheet()->setCellValue("A28","Monto cancelado");
  $objPHPExcel->getActiveSheet()->setCellValue("B28","141.67");

  $objPHPExcel->getActiveSheet()->setCellValue("A29","Total real a pagar en $ (en efectivo)");
  $objPHPExcel->getActiveSheet()->setCellValue("B29","$2,425.00");

  $objPHPExcel->getActiveSheet()->setCellValue("A30","Porcion 52%");
  $objPHPExcel->getActiveSheet()->setCellValue("B30","$4.07");

  $objPHPExcel->getActiveSheet()->setCellValue("A31","Porcion 48%");
  $objPHPExcel->getActiveSheet()->setCellValue("B31","$4.07");

  $objPHPExcel->getActiveSheet()->getStyle('A28:A31')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  $objPHPExcel->getActiveSheet()->getStyle('B28:B31')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);

  // ----------------------------------------------------------------------


  $objPHPExcel->getActiveSheet()->setTitle('VACACIONES');
  $objPHPExcel->setActiveSheetIndex(0);

  $sheet = $objPHPExcel->getActiveSheet();
  $cellIterator = $sheet->getRowIterator()->current()->getCellIterator();
  $cellIterator->setIterateOnlyExistingCells(true);
  
  foreach ($cellIterator as $cell) {
      $sheet->getColumnDimension($cell->getColumn())->setAutoSize(true);
  }

  $fecha = date("dmY-His");
  $fileName = "vacaciones-".$fecha.".xlsx";


  $nombrearch="Asientos_Utilidades";
  header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  header('Content-Disposition: attachment;filename="'.$fileName.'"');
  header('Cache-Control: max-age=0');
  header('Cache-Control: max-age=1');
  header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  header ('Cache-Control: cache, must-revalidate');
  header ('Pragma: public');
  $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  $objWriter->save('php://output');
  exit;

?>
