<?php
session_start();
//set_time_limit(0);
  include("stilos/config.inc.php");
  include("../clases/BDConexion.php");
  include("../clases/clsPer.php");
  include("funcion/funciones.php");
  include("Funciones.php");
 
  $objPer=new clsPer;

/* header("Pragma: public");
header("Expires: 0");
$filename = "nombreArchivoQueDescarga.xls";
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); */



function redondeodecimal($valor){
$float_redondeado=round($valor * 100) / 100;
return $float_redondeado;
}
$rsdato=$objPer->getManTrans($matricula);				
 $rowdato=$objPer->NextRow($rsdato); 
 $mm=substr($fecha1,3,2); 
 

				$mess=substr($fecha1,3,2);
		  		$anio=substr($fecha1,6,4);
				$day="01";
				
				$mesess=$month;
				$anioss=$year;
				$diass=date(d);
				$ultimodia=date("t",mktime(0,0,0,$mesess,1,$anioss));
				$fecha1=$days1."-".$mesess."-".$anioss;
				//$fecha2=$ultimodia."-".$mesess."-".$anioss;
				$fecha2=$days."-".$mesess."-".$anioss; 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>..:: REPORTE ::..</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">

<link href="Estilos.css" rel="stylesheet" type="text/css">

<link href="stilos/Estilos.css" rel="stylesheet" type="text/css">

<!-- Copyright 2000,2001 Macromedia, Inc. All rights reserved. -->
<script language="JavaScript">
var nav = (navigator.appName).search("Microsoft");
function aCapa(capa, accion)
{
var act='none';
if (accion=='abrir') { act = 'block'; }
if (nav==-1)
{
document.getElementById(capa).style.display = act;
} else {
eval("document.all." + capa + ".style.display = act;")
}
return;
}
</script>
<script LANGUAGE=javascript>
function exportToXL(eSrc) {
var oExcel;
var oExcelSheet;
var oWkBooks;
var cols;
oExcel = new ActiveXObject('Excel.Application');
oWkBooks = oExcel.Workbooks.Add;
oExcelSheet = oWkBooks.Worksheets(1);
oExcelSheet.Activate();
if (eSrc.tagName != 'TABLE') {
alert('No ha sido posible exportar la tabla a excell');
return false;
}
cols = Math.ceil(eSrc.cells.length / eSrc.rows.length);
for (var i = 0; i < eSrc.cells.length; i ++)
{
var c, r;
r = Math.ceil((i+1) / cols);
c = (i+1)-((r-1)*cols)
if (eSrc.cells(i).tagName == 'TH') {
oExcel.ActiveSheet.Cells(r,c).Font.Bold = true;
oExcel.ActiveSheet.Cells(r,c).Interior.Color = 14474460;
}
if (eSrc.cells(i).childNodes.length > 0 && eSrc.cells(i).childNodes(0).tagName == "B")
oExcel.ActiveSheet.Cells(r,c).Font.Bold = true;
oExcel.ActiveSheet.Cells(r,c).Value = eSrc.cells(i).innerText;
}
oExcelSheet.Application.Visible = true;
}
</script>
</head>

<body onLoad="print()">

<!--<input type="button" value="EXPORTAR A EXCEL" id=button1 name=button1 onCLick="exportToXL(form1.all('idTable'))"> -->
<map name="Map">
  <area shape="rect" coords="2,5,22,21" href="fondo.php">
</map>
<table width="834" border="0">
  <tr class="lblcampo">
    <td width="189"><div align="left"><img src="../imagenes/logo_perenco.GIF" width="150" height="54"></div></td>
    <td colspan="<?=$days?>"><div align="left"><span class="lblTitulo">CONSOLIDADO HORAS-COSTO-JP1 <br>
      x CENTRO DE COSTOS ACUMULADOS x EMPRESA </span></div></td>
    <td width="255">&nbsp;</td>
  </tr>
  <tr class="lblcampo">
    <td colspan="3"><div align="left" class="lblCampo">
      <?
		  echo "Reporte del ".$days1." al ".$days." de ".meshoy($mesess)." del ".$anioss;
		  ?></div></td>
  </tr>
  <tr>
    <td colspan="3"><div align="left">
      <table width="<?=(404+$days*50)?>" border="1" cellpadding="0" cellspacing="0" style="<?=$stylo['tabla']?>" bgcolor="<?=$c_fondo['fondo tabla']?>" bordercolor="<?=$bordetabla?>">
        <tr class="lblCampoBlanco" bgcolor="<?=$c_fondo_tr["fondo tr"]?>">
          <td width="278">HORAS ACUMULADAS </td>
          <td colspan="<?=$days?>"><div align="center">DIAS</div></td>
          <td width="126">&nbsp;</td>
        </tr>
        <tr class="lblCampoBlanco" bgcolor="<?=$c_fondo_tr["fondo tr"]?>">
          <?
				$mess=substr($fecha1,3,2);
		  		$anio=substr($fecha1,6,4);
				$day="01";
				
				$mesess=$month;
				$anioss=$year;
				$diass=date(d);
				$ultimodia=date("t",mktime(0,0,0,$mesess,1,$anioss));
				$fecha1=$days1."-".$mesess."-".$anioss;
				//$fecha2=$ultimodia."-".$mesess."-".$anioss;
				$fecha2=$days."-".$mesess."-".$anioss;
				$horast=0;
				$rspcp=$objPer->TransHrs1(extraerfechamysql($fecha1),extraerfechamysql($fecha2));
				while($rowpcp=$objPer->NextRow($rspcp)){
					$rsht=$objPer->getHorasxMes($rowpcp['mat_trans'],extraerfechamysql($fecha1),extraerfechamysql($fecha2));
				  	$rowht=$objPer->NextRow($rsht);
					if($rowpcp['tipohora']=='T'){ $th=$rowht['horastec'];}elseif($rowpcp['tipohora']=='V'){ $th=$rowht['horasvol'];}
					$horast+=$th;						
				} 
				
				/* $rstipohora=$objPer->getConsolVuelosHrs(extraerfechamysql($fecha1),extraerfechamysql($fecha2));
				$rowtipohora=$objPer->NextRow($rstipohora); */
				
				
				/* $rst=$objPer->getTransTarifa($matricula); 
				$rowt=$objPer->NextRow($rst);				
					
				$rsthi=$objPer->getHoraIndisponible($matricula,extraerfechamysql($fecha1),extraerfechamysql($fecha2));
				$rowthi=$objPer->NextRow($rsthi); */				
				?>
          <td width="278"><div align="center">Centros de costos </div></td>
          <? for($j=intval($days1);$j<=$days;$j++){?>
          <td width="83"><div align="center">
              <?=$j?>
          </div></td>
          <? }?>
          <td><div align="center">Total Horas x Centro de Costo </div></td>
        </tr>
        <?
	$n=0;
	//$t=0;
					//extraerfechamysql($fecha1),extraerfechamysql($fecha2)
	$rscd=$objPer->manpercardiasTHrsEmp($matricula,$ccosto,$emp,extraerfechamysql($fecha1),extraerfechamysql($fecha2));
	$totalfilas=$objPer->totalrows($rscd);
	while($rowcd=$objPer->NextRow($rscd)){
	$n++;
	$tothorascc1=0;
	$sumap=0; 
	//$t=0;
	$thdia=0;
	?>
        <tr class="lblCampo">
          <td><div align="left">
              <?=$rowcd['ccosto']?>
          </div></td>
          <? for($i=$days1;$i<=$days;$i++){?>
          <td><div align="center">
              <? 
			  $t=0;
			  
			  if($rowcd['ccosto']){
			  
			      $rsdt=$objPer->TransHrsEmp($matricula,$emp,$rowcd['ccosto'],$anioss."-".$mesess."-".$i);
				  while($rowdt=$objPer->NextRow($rsdt)){
				  
				  $rstv=$objPer->manpercarHrsTecVol($rowdt['mat_trans'],extraerfechamysql($fecha1),extraerfechamysql($fecha2));
				  $rowtv=$objPer->NextRow($rstv);
				  
				  $rstipohora=$objPer->getConsolVuelos($rowdt['mat_trans'],extraerfechamysql($fecha1),extraerfechamysql($fecha2));
				  $rowtipohora=$objPer->NextRow($rstipohora);
			  	
				  $rshd=$objPer->getHorasxDia($rowdt['mat_trans'],$anioss."-".$mesess."-".$i);
				  $rowhd=$objPer->NextRow($rshd);
				  
				  $rspcdc=$objPer->manpercarpesodiscc1Emp($rowdt['mat_trans'],$rowcd['ccosto'],$emp,$anioss."-".$mesess."-".$i);
				  $rowpcdc=$objPer->NextRow($rspcdc);
				  
				  $rspcdt=$objPer->manpercarpesodish($rowdt['mat_trans'],$anioss."-".$mesess."-".$i);
				  $rowpcdt=$objPer->NextRow($rspcdt);
				  
				  $rscombusi=$objPer->getConsolCombusTDia($rowdt['mat_trans'],$anioss."-".$mesess."-".$i);
				  $rowcombusi=$objPer->NextRow($rscombusi);			  	  
				  
				  if($rowpcdt['dispesototal']!='' || $rowpcdt['dispesototal']!=0 || $rowpcdt['dispesototal']!=NULL){
				   
				  if($rowpcdt['dispesototal']!=0){$dispercar=$rowpcdc['dispercar']; $dispesototal=$rowpcdt['dispesototal'];}else{$dispercar=1; $dispesototal=1;}
				  if($rowtipohora['tipohora']=='T'){ $tipoh=$rowhd['horastec'];$tipohora=$rowtv['horatec'];}else{$tipoh=$rowhd['horasvol']; $tipohora=$rowtv['horavol'];}
				  
				  /* $t=$t+round(($rowpcdc['dispercar']/$rowpcdt['dispesototal'])*$tipoh*60,4)."<br>";
				  $tt1=round(($rowpcdc['dispercar']/$rowpcdt['dispesototal'])*$tipoh*60,4);
				  $sumap+=$rowpcdc['dispercar'];
				  $tothorascc1+=$tt1; */
				  $t=$t+(($dispercar/$dispesototal)*$tipoh*60);
				  $tt1=(($dispercar/$dispesototal)*$tipoh*60);
				  $sumap+=$dispercar;
				  $tothorascc1+=$tt1;
				  $tipohxd+=$tipoh;
				  
				  ////////////////////////////////////////////////////////////////////////////////////////////
				  if($rowppcd['sumdispercar']!=0){ $sumdispercar=$rowppcd['sumdispercar'];}else{$sumdispercar=1;}
				  ////////////////////////////////////////////////////////////////////////////////////////////
				  
				  $horasdia[]=array($rowdt['mat_trans'],$rowcd['ccosto'],$i,$tt1);
				  ////////////////////////////////////////////////////////////////////////////////////////////
				  $combustible=$rowcombusi['combus'];
				  //$thdia+=(($dispercar/$dispesototal)*$tipoh*60)."<br>";
				  $thdia=$tipoh;
				  $cfhora=($rowdt['tarifa']/28.5);
				  $cviaje=((round($tipohora)/3)*$rowdt['tarifav']);
				  $choratrans=($rowdt['tarifah']);
				  $horavoladas=$tipohora;
				  $horasdiacum[]=array($rowdt['mat_trans'],$rowcd['ccosto'],$i,round($tt1),$cfhora,$cviaje,$horavoladas,$thdia,$choratrans,$combustible);
				  
				      
					 }else{
					 "&nbsp;";
					 }
					 
				  }
				  
				} 	  
					  $divisora=60;
					  $minutosa=60;
					   
					  $tminutosa=$minutosa*(round($t)/60);    
					  $cocientea=floor($tminutosa/$divisora);
					  
					  $restoa=$tminutosa%$divisora;
					  if($restoa<10){
					  	if($cocientea.":0".$restoa!='0:00'){
					  		echo $cocientea.":0".$restoa."<br>";
						}
					  }else{
					  	if($cocientea.":0".$restoa!='0:00'){
					  		echo $cocientea.":".$restoa."<br>";
						}
					  } 
					 
				  ?>
          </div></td>
          <? }?>
          <td><div align="center">
              <?
				  //echo round($tothorascc1);
				  echo calcular_horas_formato_inversa(round($tothorascc1)/60);
				  $tothorascc1/60;
				  $totalhoracol=round($tothorascc1,1);
				  $totalhoracol1+=$totalhoracol;
				  ?>
              <?
					/* round(($tothorascc1)/60,1)."<br>";
					round($horast,1)."<br>";
					echo round(round($tothorascc1/60,1)/round($horast,1)*100,1); */
					?>
          </div></td>
        </tr>
        <? }$objPer->Liberar($rscd);?>
        <tr class="lblCampoBlanco" bgcolor="<?=$c_fondo_tr["fondo tr"]?>">
          <td>Total -&gt; </td>
          <? for($z=$days1;$z<=$days;$z++){?>
          <td><div align="center">
              <?
			$sumahourdia=0;
			if(isset($horasdia)){
			foreach($horasdia as $indicehd=>$valuehd)
			{
				if($z==$valuehd[2]){
				//echo $valuehd[3]."<br>";					
					$sumahourdia+=$valuehd[3];			
				}
			} 
			}
			
				$sumahourdia;
				if($sumahourdia!=''){
					if($sumahourdia!=0){
				  		echo calcular_horas_formato_inversa((round($sumahourdia,2)/60));
				  		/* $horaresumen[]=array($rowtrans['mat_trans'],$sumahourdia);
						$sumahourpt+=$sumahourp; */
					}else{echo "&nbsp;";}
				}else{
					echo "&nbsp;";
				}
				  /* if($z==1){if(isset($A1)){foreach($A1 as $b1){$sumab1+=$b1;}echo calcular_horas_formato_inversa(round($sumab1,2)/60);}}
				  if($z==2){if(isset($A2)){foreach($A2 as $b2){$sumab2+=$b2;}echo calcular_horas_formato_inversa(round($sumab2,2)/60);}}
				  if($z==3){if(isset($A3)){foreach($A3 as $b3){$sumab3+=$b3;}echo calcular_horas_formato_inversa(round($sumab3,2)/60);}}
				  if($z==4){if(isset($A4)){foreach($A4 as $b4){$sumab4+=$b4;}echo calcular_horas_formato_inversa(round($sumab4,2)/60);}}
				  if($z==5){if(isset($A5)){foreach($A5 as $b5){$sumab5+=$b5;}echo calcular_horas_formato_inversa(round($sumab5,2)/60);}}
				  if($z==6){if(isset($A6)){foreach($A6 as $b6){$sumab6+=$b6;}echo calcular_horas_formato_inversa(round($sumab6,2)/60);}}
				  if($z==7){if(isset($A7)){foreach($A7 as $b7){$sumab7+=$b7;}echo calcular_horas_formato_inversa(round($sumab7,2)/60);}}
				  if($z==8){if(isset($A8)){foreach($A8 as $b8){$sumab8+=$b8;}echo calcular_horas_formato_inversa(round($sumab8,2)/60);}}
				  if($z==9){if(isset($A9)){foreach($A9 as $b9){$sumab9+=$b9;}echo calcular_horas_formato_inversa(round($sumab9,2)/60);}}
				  if($z==10){if(isset($A10)){foreach($A10 as $b10){$sumab10+=$b10;}
				  echo calcular_horas_formato_inversa(round($sumab10,2)/60);				  
					  }
				  }
				  if($z==11){if(isset($A11)){foreach($A11 as $b11){$sumab11+=$b11;}echo calcular_horas_formato_inversa(round($sumab11,2)/60);}}
				  if($z==12){if(isset($A12)){foreach($A12 as $b12){$sumab12+=$b12;}echo calcular_horas_formato_inversa(round($sumab12,2)/60);}}
				  if($z==13){if(isset($A13)){foreach($A13 as $b13){$sumab13+=$b13;}echo calcular_horas_formato_inversa(round($sumab13,2)/60);}}
				  if($z==14){if(isset($A14)){foreach($A14 as $b14){$sumab14+=$b14;}echo calcular_horas_formato_inversa(round($sumab14,2)/60);}}
				  if($z==15){if(isset($A15)){foreach($A15 as $b15){$sumab15+=$b15;}echo calcular_horas_formato_inversa(round($sumab15,2)/60);}}
				  if($z==16){if(isset($A16)){foreach($A16 as $b16){$sumab16+=$b16;}echo calcular_horas_formato_inversa(round($sumab16,2)/60);}}
				  if($z==17){if(isset($A17)){foreach($A17 as $b17){$sumab17+=$b17;}echo calcular_horas_formato_inversa(round($sumab17,2)/60);}}
				  if($z==18){if(isset($A18)){foreach($A18 as $b18){$sumab18+=$b18;}echo calcular_horas_formato_inversa(round($sumab18,2)/60);}}
				  if($z==19){if(isset($A19)){foreach($A19 as $b19){$sumab19+=$b19;}echo calcular_horas_formato_inversa(round($sumab19,2)/60);}}
				  if($z==20){if(isset($A20)){foreach($A20 as $b20){$sumab20+=$b20;}echo calcular_horas_formato_inversa(round($sumab20,2)/60);}}
				  if($z==21){if(isset($A21)){foreach($A21 as $b21){$sumab21+=$b21;}
				  $veinte1=(round($sumab21/60,2));
				  $div=60;
					  $min=60;					   
					  $tmin=round($min*$veinte1)."<br>";    
					  $coci=floor($tmin/$div);					  
					  $res=$tmin%60;
					  if($res<10){
					  	if($coci.":0".$res!='0:00'){
					  		echo $coci.":0".$res;
						}
					  }else{
					  	if($coci.":0".$res!='0:00'){
					  		echo $coci.":".$res;
						}
					  }
				  }}
				  if($z==22){if(isset($A22)){foreach($A22 as $b22){$sumab22+=$b22;}echo calcular_horas_formato_inversa(round($sumab22,2)/60);}}
				  if($z==23){if(isset($A23)){foreach($A23 as $b23){$sumab23+=$b23;}echo calcular_horas_formato_inversa(round($sumab23,2)/60);}}
				  if($z==24){if(isset($A24)){foreach($A24 as $b24){$sumab24+=$b24;}echo calcular_horas_formato_inversa(round($sumab24,2)/60);}}
				  if($z==25){if(isset($A25)){foreach($A25 as $b25){$sumab25+=$b25;}echo calcular_horas_formato_inversa(round($sumab25,2)/60);}}
				  if($z==26){if(isset($A26)){foreach($A26 as $b26){$sumab26+=$b26;}echo calcular_horas_formato_inversa(round($sumab26,2)/60);}}
				  if($z==27){if(isset($A27)){foreach($A27 as $b27){$sumab27+=$b27;}echo calcular_horas_formato_inversa(round($sumab27,2)/60);}}
				  if($z==28){if(isset($A28)){foreach($A28 as $b28){$sumab28+=$b28;}echo calcular_horas_formato_inversa(round($sumab28,2)/60);}}
				  if($z==29){if(isset($A29)){foreach($A29 as $b29){$sumab29+=$b29;}echo calcular_horas_formato_inversa(round($sumab29,2)/60);}}
				  if($z==30){if(isset($A30)){foreach($A30 as $b30){$sumab30+=$b30;}echo calcular_horas_formato_inversa(round($sumab30,2)/60);}}
				  if($z==31){if(isset($A31)){foreach($A31 as $b31){$sumab31+=$b31;}echo calcular_horas_formato_inversa(round($sumab31,2)/60);}} */
				  ?>
          </div></td>
          <? }?>
          <td><div align="center">
              <?
				  echo calcular_horas_formato_inversa(round($totalhoracol1)/60)."/".round(round($totalhoracol1)/60,2);
				  ?>
              <? //echo "100.00";?>
          </div></td>
        </tr>
      </table>
    </div></td>
  </tr>
  <tr>
    <td colspan="3"><div align="left">
      <table width="<?=(404+$days*50)?>" border="1" cellpadding="0" cellspacing="0" style="<?=$stylo['tabla']?>" bgcolor="<?=$c_fondo['fondo tabla']?>" bordercolor="<?=$bordetabla?>">
        <tr class="lblCampoBlanco" bgcolor="<?=$c_fondo_tr["fondo tr"]?>">
          <td>COSTO HORAS EN US$ </td>
          <td colspan="<?=$days?>"><div align="center">DIAS</div></td>
          <td width="126">&nbsp;</td>
        </tr>
        <tr class="lblCampoBlanco" bgcolor="<?=$c_fondo_tr["fondo tr"]?>">
          <?
				/* $mess=substr($fecha1,3,2);
		  		$anio=substr($fecha1,6,4);
				$day="01";
				
				$mesess=$month;
				$anioss=$year;
				$diass=date(d);
				$ultimodia=date("t",mktime(0,0,0,$mesess,1,$anioss));
				$fecha1=$days1."-".$mesess."-".$anioss;
				//$fecha2=$ultimodia."-".$mesess."-".$anioss;
				$fecha2=$days."-".$mesess."-".$anioss;
				$horast=0;
				$rspcp=$objPer->TransHrs1(extraerfechamysql($fecha1),extraerfechamysql($fecha2));
				while($rowpcp=$objPer->NextRow($rspcp)){
					$rsht=$objPer->getHorasxMes($rowpcp['mat_trans'],extraerfechamysql($fecha1),extraerfechamysql($fecha2));
				  	$rowht=$objPer->NextRow($rsht);
					if($rowpcp['tipohora']=='T'){ $th=$rowht['horastec'];}elseif($rowpcp['tipohora']=='V'){ $th=$rowht['horasvol'];}
					$horast+=$th;			
					
				}  */
				
				/* $rstipohora=$objPer->getConsolVuelosHrs(extraerfechamysql($fecha1),extraerfechamysql($fecha2));
				$rowtipohora=$objPer->NextRow($rstipohora); */
				
				
				/* $rst=$objPer->getTransTarifa($matricula); 
				$rowt=$objPer->NextRow($rst);				
					
				$rsthi=$objPer->getHoraIndisponible($matricula,extraerfechamysql($fecha1),extraerfechamysql($fecha2));
				$rowthi=$objPer->NextRow($rsthi); */				
				?>
          <td width="279"><div align="center">Centros de costos </div></td>
          <? for($j=intval($days1);$j<=$days;$j++){?>
          <td width="83"><div align="center">
              <?=$j?>
          </div></td>
          <? }?>
          <td width="126"><div align="center">Total Costo Horas en US$ x Centro de Costo </div></td>
        </tr>
        <?
	$n=0;
	//$t=0;
					//extraerfechamysql($fecha1),extraerfechamysql($fecha2)
	$rscd=$objPer->manpercardiasTHrsEmp($matricula,$ccosto,$emp,extraerfechamysql($fecha1),extraerfechamysql($fecha2));
	$totalfilas=$objPer->totalrows($rscd);
	while($rowcd=$objPer->NextRow($rscd)){
	$n++;
	$tothorascc1=0;
	$sumap=0; 
	//$t=0;
	$thdia=0;
	$ctotalcalculado=0;
	?>
        <tr class="lblCampo">
          <td><div align="left">
              <?=$rowcd['ccosto']?>
          </div></td>
          <? for($i=$days1;$i<=$days;$i++){?>
          <td><div align="right">
              <? 
			  $t=0;
			  $ctotalcalcu=0;
			  
			  if($rowcd['ccosto']){
			  
			      $rsdt=$objPer->TransHrsEmp($matricula,$emp,$rowcd['ccosto'],$anioss."-".$mesess."-".$i);
				  while($rowdt=$objPer->NextRow($rsdt)){
				  			  				 
								$sumahourdiacum=0;
								$sumahdiacum=0;
								$sumacfhdiacum=0;
								$sumacvdiacum=0;
								$sumahvolacum=0;
								$sumachvoltrans=0;
								foreach($horasdiacum as $indicehda=>$valuehda)
								{
									if($rowdt['mat_trans']==$valuehda[0] && $rowcd['ccosto']==$valuehda[1] && $i==$valuehda[2]){	
										//echo $valuehda[3]."-".$rowdt['mat_trans']."<br>";
										$sumahdiacum+=$valuehda[7]."<br>";
										//$rowdt['mat_trans']."<br>";
										$sumahourdiacum+=$valuehda[3];
										$sumacfhdiacum=$valuehda[4];$sumacvdiacum=$valuehda[5];$sumahvolacum=$valuehda[6];$sumachvoltrans=$valuehda[8];
										
								
									}
									//if($rowdt['mat_trans']==$valuehda[0]){$sumahdiacum+=$valuehda[7];$sumacfhdiacum=$valuehda[4];$sumacvdiacum=$valuehda[5];$sumahvolacum=$valuehda[6];$sumachvoltrans=$valuehda[8];}
								}
								if($sumahourdiacum!=''){
								calcular_horas_formato_inversa(($sumahourdiacum/60));
								calcular_horas_formato_inversa(($sumahdiacum/60));
								
								$hdiacc=($sumahourdiacum/60);
								
								if(($sumahdiacum/60)!=''){
									if(($sumahdiacum/60)!=0){
										$hdiat=($sumahdiacum);	
									}
								}else{$hdiat=1;}
								
								$cfhtrans=$sumacfhdiacum;
								$cviajetrans=$sumacvdiacum;
								$horavoladatrans=$sumahvolacum;
								$costotranshora=$sumachvoltrans;
								
										//echo $rowdt['mat_trans']."<br>";
										if($rowdt['mat_trans']=='OB-317'){
											$ctotalcal=round(($hdiacc/3)*$cviajetrans,2);
											
										}elseif($rowdt['mat_trans']=='OB-1842 P'){									
											if($horavoladatrans<=40){
												$ci1=$hdiacc*(1000);
											}elseif($horavoladatrans>40 && $horavoladatrans<=60){ 							
												$ci1=$hdiacc*2500;
											}elseif($horavoladatrans>60){							
												$ci1=$hdiacc*2400;
											}
											$cotofijohdia=($cfhtrans/$hdiat)*$hdiacc;
											
											$ctotalcal=round($cotofijohdia+$ci1,2);
											
										}elseif($rowdt['mat_trans']=='C-GKHL'){											
												$cotofijohdia=($cfhtrans/$hdiat)*$hdiacc;
												$ci1=$hdiacc*(2400);
												
												$ctotalcal=round($cotofijohdia+$ci1,2);
												
										}elseif($rowdt['mat_trans']=='CFIGR'){												
											if($horavoladatrans<=120){$ci1=$hdiacc*2800;}elseif($horavoladatrans>120){$ci1=$hdiacc*3190;}
											//echo $horavoladatrans."<br>";
											//echo $hdiacc."<br>";
											//echo $hdiat."<br>";
											//echo $cfhtrans."<br>";
											$cotofijohdia=($cfhtrans/$hdiat)*$hdiacc;						
											$ctotalcal=round($cotofijohdia+$ci1,2);
															
										}else{							
											$cotofijohdia=($cfhtrans/$hdiat)*$hdiacc;						
											$ctotalcal=round($cotofijohdia+($hdiacc*$costotranshora),2);
											
										} 
										$ctotalcalcu+=round($ctotalcal,2);
										//$ctotalcalculado+=$ctotalcalcu;
										
								} 
								
				  }$objPer->Liberar($rsdt);
				  
				  if($ctotalcalcu!=0){echo number_format($ctotalcalcu,2,'.',' ');$ctotalcalculado+=$ctotalcalcu;$costohoras[]=array($i,$ctotalcalcu);}else{echo "&nbsp;";}
				} 	  
					  
					 
				  ?>
          </div></td>
          <? }?>
          <td><div align="right">
              <?
			  echo number_format($ctotalcalculado,2,'.','');
			  $ctotalcalculado1+=$ctotalcalculado;
			  ?>
              <?
					/* round(($tothorascc1)/60,1)."<br>";
					round($horast,1)."<br>";
					echo round(round($tothorascc1/60,1)/round($horast,1)*100,1); */
					?>
          </div></td>
        </tr>
        <? }$objPer->Liberar($rscd);?>
        <tr class="lblCampoBlanco" bgcolor="<?=$c_fondo_tr["fondo tr"]?>">
          <td>Total -&gt; </td>
          <? for($z=intval($days1);$z<=$days;$z++){?>
          <td><div align="right">
              <?
			$sumadiahc=0;
			if(isset($costohoras)){
			foreach($costohoras as $indicehc=>$valuehc)
			{
				if($z==$valuehc[0]){
				//echo $valuehc[1]."<br>";					
					$sumadiahc+=$valuehc[1];			
				}
			}
			} 
			
				
				if($sumadiahc!=''){
					if($sumadiahc!=0){				  		
				  		echo number_format($sumadiahc,2,'.',' ');
					}else{ "&nbsp;";}
				}else{
					 "&nbsp;";
				}
				  
				  ?>
          </div></td>
          <? }?>
          <td><div align="right">
              <?
			  echo number_format($ctotalcalculado1,2,'.',' ');
			  ?>
              <? //echo "100.00";?>
          </div></td>
        </tr>
      </table>
    </div></td>
  </tr>
  <tr>
    <td colspan="3"><div align="left">
      <table width="<?=(404+$days*50)?>" border="1" cellpadding="0" cellspacing="0" style="<?=$stylo['tabla']?>" bgcolor="<?=$c_fondo['fondo tabla']?>" bordercolor="<?=$bordetabla?>">
        <tr class="lblCampoBlanco" bgcolor="<?=$c_fondo_tr["fondo tr"]?>">
          <td>COSTO JP-1 EN US$</td>
          <td colspan="<?=$days?>"><div align="center">DIAS</div></td>
          <td width="126">&nbsp;</td>
        </tr>
        <tr class="lblCampoBlanco" bgcolor="<?=$c_fondo_tr["fondo tr"]?>">
          <?
				/* $mess=substr($fecha1,3,2);
		  		$anio=substr($fecha1,6,4);
				$day="01";
				
				$mesess=$month;
				$anioss=$year;
				$diass=date(d);
				$ultimodia=date("t",mktime(0,0,0,$mesess,1,$anioss));
				$fecha1=$days1."-".$mesess."-".$anioss;
				//$fecha2=$ultimodia."-".$mesess."-".$anioss;
				$fecha2=$days."-".$mesess."-".$anioss;
				$horast=0;
				$rspcp=$objPer->TransHrs1(extraerfechamysql($fecha1),extraerfechamysql($fecha2));
				while($rowpcp=$objPer->NextRow($rspcp)){
					$rsht=$objPer->getHorasxMes($rowpcp['mat_trans'],extraerfechamysql($fecha1),extraerfechamysql($fecha2));
				  	$rowht=$objPer->NextRow($rsht);
					if($rowpcp['tipohora']=='T'){ $th=$rowht['horastec'];}elseif($rowpcp['tipohora']=='V'){ $th=$rowht['horasvol'];}
					$horast+=$th;			
					
				}  */
				
				/* $rstipohora=$objPer->getConsolVuelosHrs(extraerfechamysql($fecha1),extraerfechamysql($fecha2));
				$rowtipohora=$objPer->NextRow($rstipohora); */
				
				
				/* $rst=$objPer->getTransTarifa($matricula); 
				$rowt=$objPer->NextRow($rst);				
					
				$rsthi=$objPer->getHoraIndisponible($matricula,extraerfechamysql($fecha1),extraerfechamysql($fecha2));
				$rowthi=$objPer->NextRow($rsthi); */				
				?>
          <td width="280"><div align="center">Centros de costos </div></td>
          <? for($j=intval($days1);$j<=$days;$j++){?>
          <td width="85"><div align="center">
              <?=$j?>
          </div></td>
          <? }?>
          <td width="126"><div align="center">Total Costo Combustible en US$ x Centro de Costo </div></td>
        </tr>
        <?
	$n=0;
	//$t=0;
					//extraerfechamysql($fecha1),extraerfechamysql($fecha2)
	$rscd=$objPer->manpercardiasTHrsEmp($matricula,$ccosto,$emp,extraerfechamysql($fecha1),extraerfechamysql($fecha2));
	$totalfilas=$objPer->totalrows($rscd);
	while($rowcd=$objPer->NextRow($rscd)){
	$n++;
	$tothorascc1=0;
	$sumap=0; 
	//$t=0;
	$thdia=0;
	$ctotalcalculadocombus=0;
	?>
        <tr class="lblCampo">
          <td><div align="left">
              <?=$rowcd['ccosto']?>
          </div></td>
          <? for($i=$days1;$i<=$days;$i++){?>
          <td><div align="right">
              <? 
			  $t=0;
			  $ctotalcalcucombus=0;
			  
			  if($rowcd['ccosto']){
			  
			      $rsdt=$objPer->TransHrsEmp($matricula,$emp,$rowcd['ccosto'],$anioss."-".$mesess."-".$i);
				  while($rowdt=$objPer->NextRow($rsdt)){
				  			  				 
								$sumahourdiacum=0;
								$sumahdiacum=0;
								$sumacfhdiacum=0;
								$sumacvdiacum=0;
								$sumahvolacum=0;
								$sumachvoltrans=0;
								foreach($horasdiacum as $indicehda=>$valuehda)
								{
									if($rowdt['mat_trans']==$valuehda[0] && $rowcd['ccosto']==$valuehda[1] && $i==$valuehda[2]){											
										$sumahdiacum+=$valuehda[7];										
										$sumahourdiacum+=$valuehda[3];
										$sumacfhdiacum=$valuehda[4];$sumacvdiacum=$valuehda[5];$sumahvolacum=$valuehda[6];$sumachvoltrans=$valuehda[8];$combust=$valuehda[9];						
									}
									//if($rowdt['mat_trans']==$valuehda[0]){$sumahdiacum+=$valuehda[7];$sumacfhdiacum=$valuehda[4];$sumacvdiacum=$valuehda[5];$sumahvolacum=$valuehda[6];$sumachvoltrans=$valuehda[8];}
								}
								if($sumahourdiacum!=''){
								calcular_horas_formato_inversa(($sumahourdiacum/60));
								calcular_horas_formato_inversa(($sumahdiacum/60));
								
								$hdiacc=($sumahourdiacum/60);
								
								if(($sumahdiacum/60)!=''){
									if(($sumahdiacum/60)!=0){
										$hdiat=($sumahdiacum);	
									}
								}else{$hdiat=1;}
								if($costocombus!=''){$costocombusapli=$costocombus;}else{$costocombusapli=3;}
								$cfhtrans=$sumacfhdiacum;
								$cviajetrans=$sumacvdiacum;
								$horavoladatrans=$sumahvolacum;
								$costotranshora=$sumachvoltrans;
								
										
										if($rowdt['mat_trans']=='OB-317'){
											//$ctotalcal=round(($hdiacc/3)*$cviajetrans,2);
											$costocombustible=round((($hdiacc*$combust)/$hdiat)*$costocombusapli,2);
										}elseif($rowdt['mat_trans']=='OB-1842 P'){									
											if($horavoladatrans<=40){
												$ci1=$hdiacc*(1000);
											}elseif($horavoladatrans>40 && $horavoladatrans<=60){ 							
												$ci1=$hdiacc*2500;
											}elseif($horavoladatrans>60){							
												$ci1=$hdiacc*2400;
											}
											$cotofijohdia=($cfhtrans/$hdiat)*$hdiacc;
											
											//$ctotalcal=round($cotofijohdia+$ci1,2);
											$costocombustible=round((($hdiacc*$combust)/$hdiat)*$costocombusapli,2);
										}elseif($rowdt['mat_trans']=='C-GKHL'){											
												$cotofijohdia=($cfhtrans/$hdiat)*$hdiacc;
												$ci1=$hdiacc*(2400);
												
												//$ctotalcal=round($cotofijohdia+$ci1,2);
												$costocombustible=round((($hdiacc*$combust)/$hdiat)*$costocombusapli,2);
										}elseif($rowdt['mat_trans']=='CFIGR'){												
											if($horavoladatrans<=120){$ci1=$hdiacc*2800;}elseif($horavoladatrans>120){$ci1=$hdiacc*3190;}
											//echo $horavoladatrans."<br>";
											//echo $hdiacc."<br>";
											//echo $hdiat."<br>";
											//echo $cfhtrans."<br>";
											$cotofijohdia=($cfhtrans/$hdiat)*$hdiacc;						
											//$ctotalcal=round($cotofijohdia+$ci1,2);
											$costocombustible=round((($hdiacc*$combust)/$hdiat)*$costocombusapli,2);				
										}else{							
											$cotofijohdia=($cfhtrans/$hdiat)*$hdiacc;						
											//$ctotalcal=round($cotofijohdia+($hdiacc*$costotranshora),2);
											$costocombustible=round((($hdiacc*$combust)/$hdiat)*$costocombusapli,2);
										} 
										$ctotalcalcucombus+=round($costocombustible,2);
										//$ctotalcalculado+=$ctotalcalcu;
										//$CostoTotaldiaTrans[]=array($rowtransVerti['mat_trans'],round($ctotalcal,2));
								} 
								
				  }$objPer->Liberar($rsdt);
				  
				  if($ctotalcalcucombus!=0){echo number_format($ctotalcalcucombus,2,'.',' ');$ctotalcalculadocombus+=$ctotalcalcucombus;$costocombusti[]=array($i,$ctotalcalcucombus);}else{echo "&nbsp;";}
				} 	  
					  
					 
				  ?>
          </div></td>
          <? }?>
          <td><div align="right">
              <?
			  echo number_format($ctotalcalculadocombus,2,'.',' ');
			  $ctotalcalculadocombus1+=$ctotalcalculadocombus;
			  ?>
              <?
					/* round(($tothorascc1)/60,1)."<br>";
					round($horast,1)."<br>";
					echo round(round($tothorascc1/60,1)/round($horast,1)*100,1); */
					?>
          </div></td>
        </tr>
        <? }$objPer->Liberar($rscd);?>
        <tr class="lblCampoBlanco" bgcolor="<?=$c_fondo_tr["fondo tr"]?>">
          <td>Total -&gt; </td>
          <? for($z=$days1;$z<=$days;$z++){?>
          <td><div align="right">
              <?
			$sumadiacc=0;
			if(isset($costocombusti)){
			foreach($costocombusti as $indicecc=>$valuecc)
			{
				if($z==$valuecc[0]){
				//echo $valuehd[3]."<br>";					
					$sumadiacc+=$valuecc[1];			
				}
			}
			} 
			
				$sumadiacc;
				if($sumadiacc!=''){
					if($sumadiacc!=0){
				  		echo number_format($sumadiacc,2,'.',' ');
					}else{ "&nbsp;";}
				}else{
					 "&nbsp;";
				}
				  
				  ?>
          </div></td>
          <? }?>
          <td><div align="right">
              <?
			  echo number_format($ctotalcalculadocombus1,2,'.',' ');
			  ?>
              <? //echo "100.00";?>
          </div></td>
        </tr>
      </table>
    </div></td>
  </tr>
</table>
</body>

</html>

