<?php
  include("stilos/config.inc.php");
  include("../clases/BDConexion.php");
  include("../clases/clsPer.php");
  include("funcion/funciones.php");
  include("Funciones.php");
  session_start();
  $objPer=new clsPer;  
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><MMString:LoadString id="insertbar/formsHidden" /></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"> 
<!--
function print_1(sURL,x,y) {
if (!window.focus) return;
			var par;
			par = "width=" +x + ",height="+y+","
			par = par + "dependent=no,scrollbars=yes,resizable=yes,"
			par = par + "menubar=no,toolbar=no,status=no"
			var ventana = window.open(sURL,"Ver",par)
			ventana.focus();
}
//--> 
</script>
<SCRIPT language=JavaScript src="js/calendario.js"></SCRIPT>
<script language="javascript" type="text/javascript">
  function volver(){
     window.location="fondo.php";
                   }
</script>
</head>

<body background="../imagenes/fondo.jpg">
<table width="891" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="25"><img src="../estilo_tabla/parte_sup_izq.gif" width="25" height="25"></td>
    <td width="841" background="../estilo_tabla/parte_sup_cen.gif" valign="bottom">
      <div align="left" class="lblTitulo" >Distribucion de centro de costo por Viaje <?=round(round(0.49,1))?></div></td>
    <td width="25"><img src="../estilo_tabla/parte_sup_der.gif" width="25" height="25" border="0" usemap="#MapMap"></td>
  </tr>
  <tr>
    <td width="25" background="../estilo_tabla/parte_med_izq.gif">&nbsp;</td>
    <td width="841" height="86" background="../estilo_tabla/parte_med_cen.gif"><div align="center">
        <table width="835" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="15"><div align="center"><? //date("d")?></div></td>
          </tr>
          <tr>
            <form action="p_distri_cc_viaje.php?cal=1" method="post" name="form1">
              <td height="15">
                <div align="left" class="lblForm">
                  <table width="736" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="57"><div align="right">Tipo : </div></td>
                      <td width="203"><div align="left">
                          <select name="matricula" id="select2" onkeyup=fn(this.form,this)>
                            <option value="0" <? if($mat_trans=="0"){?> selected <? }?>>Ninguno</option>
                            <? 
						echo $objPer->getCboTransCC($matricula);
						?>
                          </select>
                      </div></td>
                      <td width="59"><div align="right">Fechas : </div></td>
                      <td width="198"><div align="left">
                          <table width="197" height="19" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                              <td width="108"><div align="left">
                                  <table width="87" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                      <td width="67"><div align="left">
                                          <input name="fecha1" type="text" class="lblCampo" id="fecha15" value="<? echo $fecha1?>" size="12" maxlength="10" title="FORMATO dd/mm/AA">
                                      </div></td>
                                      <td width="10">&nbsp;</td>
                                      <td width="109"><div align="left"> <a onMouseOver="window.status='Calendario';return true;" onMouseOut="window.status='';return true;"  href="javascript:show_calendar('form1.fecha1');"> <img src="../imagenes/calendar.jpg" alt="Calendario" width="16" height="15" border="0"> </a> </div></td>
                                    </tr>
                                  </table>
                              </div></td>
                              <td width="144"><div align="left">
                                  <table width="87" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                      <td width="67"><div align="left">
                                          <input name="fecha2" type="text" class="lblCampo" id="fecha25" value="<? echo $fecha2?>" size="12" maxlength="10" title="FORMATO dd/mm/AA">
                                      </div></td>
                                      <td width="10">&nbsp;</td>
                                      <td width="109"><div align="left"> <a onMouseOver="window.status='Calendario';return true;" onMouseOut="window.status='';return true;"  href="javascript:show_calendar('form1.fecha2');"> <img src="../imagenes/calendar.jpg" alt="Calendario" width="16" height="15" border="0" > </a> </div></td>
                                    </tr>
                                  </table>
                              </div></td>
                            </tr>
                          </table>
                      </div></td>
                      <td width="145"><input type="submit" name="Submit" value="<? if($cal==1){ echo 'Presione Nuevamente para calcular el costo';}else{ echo 'Calcular';}?>" style="<?=$stylo['st2']?>" class="botira"></td>
                      <td width="74"><div align="left">
                      </div></td>
                    </tr>
                  </table>
              </div></td>
            </form>
          </tr>
		   
          <tr>
            <td><div align="center">
                <table width="833" border="1" cellpadding="0" cellspacing="0" style="<?=$stylo['tabla']?>" bgcolor="<?=$c_fondo['fondo tabla']?>" bordercolor="<?=$bordetabla?>">
                  <?
					
					if($matricula!='0'){
					$resultado=$objPer->getRutaCabecera(extraerfechamysql($fecha1),extraerfechamysql($fecha2),$matricula);				
					}
					
                  while($filas=$objPer->NextRow($resultado))
                   {
				   $n++;
				   ?>
				  <tr valign="top" class="lblCampoBlanco" bgcolor="<?=$c_fondo_tr["fondo tr"]?>">
                    <td colspan="10"><div align="left">
					Fecha: <?=$filas['fecha_ruta']."<br>"?> 
					Plan de Viaje <?=$filas['cod_ruta']."<br>"?> <br> 					
					<table width="449" height="13" border="0" cellpadding="0" cellspacing="0">					
                      <tr>
                        <td width="44"><div align="center">Origen</div></td>
                        <td width="44"><div align="center">Destino</div></td>
                        <td width="44"><div align="center">Har</div></td>
                        <td width="44"><div align="center">HS</div></td>
                        <td width="44"><div align="center">Hl</div></td>
                        <td width="44"><div align="center">Hap</div></td>
                        <td width="50"><div align="center">TVC</div></td>
                        <td width="45"><div align="center">TVA</div></td>
                      </tr>
					  <? 
					$rsrd=$objPer->getRutaDetalle($filas['cod_ruta']);
					while($rowrd=$objPer->NextRow($rsrd)){									
					?>					  
                      <tr>
                        <td><div align="center"><?=$rowrd['de']?></div></td>
                        <td><div align="center">
                          <?=$rowrd['para']?>
                        </div></td>
                        <td><div align="center">
                          <?=substr($rowrd['har'],0,5)?>
                        </div></td>
                        <td><div align="center">
                          <?=substr($rowrd['hs'],0,5)?>
                        </div></td>
                        <td><div align="center">
                          <?=substr($rowrd['hl'],0,5)?>
                        </div></td>
                        <td><div align="center">
                          <?=substr($rowrd['hap'],0,5)?>
                        </div></td>
                        <td><div align="center">
                          <?=substr($rowrd['tvhm'],0,5)?>
                        </div></td>
                        <td><div align="center">
                          <?=substr($rowrd['tvthm'],0,5)?>
                        </div></td>
                      </tr>
					  <? }$objPer->Liberar($rsrd); ?>
                    </table> 
					</div></td>
                  </tr>
                  <tr valign="top" class="lblCampoBlanco" bgcolor="<?=$c_fondo_tr["fondo tr"]?>">
                    <td width="19"><div align="center">N&ordm;</div></td>
                    <td colspan="3">                    <div align="center">Centro de Costo </div></td>
                    <td width="53"><div align="center">Horas</div></td>
                    <td width="70"><div align="center"># Pax</div></td>
                    <td width="82"><div align="center">Peso Carga Kg </div></td>
                    <td width="57"><div align="center">%</div></td>
                    <td width="80"><div align="center">Costo a Facturar </div></td>
                    <td width="74"><div align="center">Division x Centro de Costo </div></td>
                  </tr>
                 <?
				 $numhparcialt=0;
				 $porcentajet=0;
				 $dcct=0;
				 $rscc=$objPer->getCCostoDetalle($filas['cod_ruta']);
				 while($rowcc=$objPer->NextRow($rscc)){
				 ?>
                  <tr valign="top" class="lblForm" >
                    <td class="lblForm">
                      <div align="center">  </div></td>
                    <td colspan="3" class="lblForm"><div align="left"><?=$rowcc['ccosto']?></div>
                    </td>
                    <td>                      <div align="center">
					<?
					$sumadishp=0;
					$sumdishp=0;
					$sumdishc=0;
					$numhparcial=0;
					$sumadishc=0;
					$a=0;
					$b=0;
					$rshcal=$objPer->getRutaHorasCal($filas['cod_ruta']);
					$rowhcal=$objPer->NextRow($rshcal);
					
					
					/* $rsthp=$objPer->getCCTotalHoraPass($filas['cod_ruta']);
					$rowthp=$objPer->NextRow($rsthp);
					
					$rsthc=$objPer->getCCTotalHoraCarga($filas['cod_ruta']);
					$rowthc=$objPer->NextRow($rsthc); */
					$rsthpc=$objPer->getCCPerCarHT($filas['cod_ruta']);
					$rowthpc=$objPer->NextRow($rsthpc);
					
					$totaldistancia=$rowthpc['totaldis'];
					if($filas['tipohora']=='V'){$tipohora=$rowhcal['tvcom'];}else{$tipohora=$rowhcal['tvtec'];}
					//*******************************************Pasajero hora********************************************************************
					if($rowcc['ccosto']){
					/* $rshp=$objPer->getCCHoraPass($filas['cod_ruta'],$rowcc['ccosto']);
				    while($rowhp=$objPer->NextRow($rshp)){
										
					$sumdishp=$sumdishp+($rowhp['distanciapesoper']/$totaldistancia)*$tipohora*60;
					$sumadishp=$sumadishp+($rowhp['distanciapesoper']/$totaldistancia)*$tipohora*60;					
					$a=$a+$rowhp['distanciapesoper']/$totaldistancia."<br>";
					}$objPer->Liberar($rshp);
					//********************************************Carga hora******************************************************************************
					$rshc=$objPer->getCCHoraCarga($filas['cod_ruta'],$rowcc['ccosto']);
				    while($rowhc=$objPer->NextRow($rshc)){
										
					$sumdishc=$sumdishc+($rowhc['distanciapesocar']/$totaldistancia)*$tipohora*60;
					$sumadishc=$sumadishc+($rowhc['distanciapesocar']/$totaldistancia)*$tipohora*60;
					$b=$b+$rowhc['distanciapesocar']/$totaldistancia."<br>";
					}$objPer->Liberar($rshc); */
					$rspc=$objPer->getCCPerCarUnion($filas['cod_ruta'],$rowcc['ccosto']);
				    while($rowpc=$objPer->NextRow($rspc)){
					$sumdishp=$sumdishp+($rowpc['distanciapesopercar']/$totaldistancia)*$tipohora*60;
					$sumadishp=$sumadishp+($rowpc['distanciapesopercar']/$totaldistancia)*$tipohora*60;
					}$objPer->Liberar($rspc);
					}
					//**************************************************************************************************************************************
					if($rowcc['ccosto']){					
					
					$numhparcial=round(round(($sumdishp),1));
					$numhparcialito=$sumdishp+$sumdishc;
					$nummintohora=($numhparcial/60);
					$numhparcialt=$numhparcialt+$numhparcialito;
					  $divisora=60;
					  $minutosa=60;
					   
					  $tminutosa=$minutosa*$nummintohora;    
					  $cocientea=floor($tminutosa/$divisora);
					  
					  $restoa=$tminutosa%$divisora;
					  if($restoa<10){
					  echo $cocientea.":0".$restoa;
					  }else{
					  echo $cocientea.":".$restoa;
					  }
					  $totalparcialvuelo=$totalparcialvuelo+($sumadishp+$sumadishc);
					  }
					  
					?>
                    </div></td>

                    <td><div align="center">
					<?
					$rsnp=$objPer->getCCNumPax($filas['cod_ruta'],$rowcc['ccosto']);
				    while($rownp=$objPer->NextRow($rsnp)){
					echo $rownp['numpax'];
					$numeropax=$numeropax+$rownp['numpax'];
					}$objPer->Liberar($rsnp);
					?>
                    </div></td>
                    <td><div align="center">
                      <?
					$rskg=$objPer->getCCCargaKg($filas['cod_ruta'],$rowcc['ccosto']);
				    while($rowkg=$objPer->NextRow($rskg)){
					echo $rowkg['cargakg'];
					$pesocarga=$pesocarga+$rowkg['cargakg'];
					}$objPer->Liberar($rskg);
					?>
</div></td>
                    <td>
					  <div align="center">
					  <?
					  if($rowcc['ccosto']){
					  
					  $nummintohorass=($numhparcial)."<br>";
					  $divin=$tipohora*60;					  
					  echo $porcentaje=round((($nummintohorass/$divin)*100),1);
					  $porcentajet=$porcentajet+$porcentaje;
					  }
					  ?>
					  </div></td>
                    <td>                    <div align="center">
                      <? 
					$rst=$objPer->getTransTarifa($matricula); 
					$rowt=$objPer->NextRow($rst);				
					
					$rsthi=$objPer->getHoraInd($matricula,extraerfechamysql($fecha1),extraerfechamysql($fecha2));
					$rowthi=$objPer->NextRow($rsthi);
							$mess=date(m);
							$anios=date(Y);
							$dias=date(d);
							$ultimodia=date("t",mktime(0,0,0,$meses,$dias,$anios));
				if($matricula=='OB-317'){
				echo $ctotalcal=($tipohora/3)*$rowt['tarifav'];
				}else{
					if($rowt['horamaxtra']!=''){
						//if($rowt['tipohora']=='V'){$dind=$rowthi['horasv']/$rowt['horamaxtra'];}elseif($rowt['tipohora']=='T'){$dind=$rowthi['horastec']/$rowt['horamaxtra'];}
						$dind=$tipohora/$rowt['horamaxtra']; 
						if($dind>$rowt['dias_indotor']){
							$diaind=$dind;							
							echo $ctotalcal=round((($rowt['tarifa']*($ultimodia-$diaind)/$ultimodia)+($tipohora*$rowt['tarifah'])),2);
						}elseif($dind<=$rowt['dias_indotor']){
							$diaind=0;
							echo $ctotalcal=round((($rowt['tarifa']*($ultimodia-$diaind)/$ultimodia)+($tipohora*$rowt['tarifah'])),2);
						}					
					}
				}
					?>
                    </div></td>
                    <td><div align="center">
                      <?
					
					echo $dcc=number_format((($porcentaje/100)*$ctotalcal),2,'.','');
					$dcct=$dcct+$dcc;
					?>
                    </div></td>
                  </tr>
                  <? 
				  }$objPer->Liberar($rscc); 
				  ?>
                    
			    <tr valign="top" class="lblForm" >
                    <td colspan="4" class="lblForm">&nbsp;                    </td>
                    <td class="lblForm"><div align="center">
					<?
					
					//$totaldistanciah=$totaldistancia;
					
					$numhparciales=round(($numhparcialt/60),2);
					$numminutospar=$numhparcialt;
					$totalhorasminutos=$totalhorasminutos+$numminutospar;
					$divisor=60;
					  $minutos=60;
					   
					  $tminutos=round($minutos*$numhparciales);    
					  $cociente=floor($tminutos/$divisor);
					  
					  $resto=$tminutos%$divisor;
					  if($resto<10){
					  echo $cociente.":0".$resto;
					  }else{
					  echo $cociente.":".$resto;
					  }
					  
					?>
</div></td>
                    <td class="lblForm"><div align="center"></div></td>
                    <td class="lblForm"><div align="center"></div></td>
                    <td><div align="center"><?=$porcentajet;?>
                    </div></td>
                    <td>                    <div align="center">
                    </div></td>
                    <td><div align="center">
                      <? 
					//echo $totalm;
					echo number_format($dcct,2,'.','');
					$totaldistri=$totaldistri+number_format($dcct,2,'.','');
					?>
                    </div></td>
			    </tr>
			    <tr valign="top" class="lblForm" >
			      <td colspan="4" class="lblForm">
				    <div align="left">					</div></td>
			      <td class="lblForm"><div align="center">
				  </div></td>
			      <td class="lblForm"><div align="center">
			      </div></td>
			      <td class="lblForm"><div align="center"></div></td>
			      <td>&nbsp;</td>
			      <td>&nbsp;</td>
			      <td><div align="center"></div></td>
			    </tr>
			    
			    <? 
			}
			$objPer->Liberar($resultado); 
			 
			?>
			<tr valign="top" class="lblForm" >
			      <td colspan="4" class="lblForm">&nbsp;</td>
			      <td class="lblForm"><div align="center">
			        <?
				  $totalhorasminutos;
				  $divisorhm=60;
					  $minutoshm=60;
					   
					  $tminutoshm=$minutoshm*($totalhorasminutos/60);    
					  $cocientehm=floor($tminutoshm/$divisorhm);
					  
					  $restohm=$tminutoshm%$divisorhm;
					  if($restohm<10){
					  $cocientehm.":0".$restohm;
					  }else{
					  $cocientehm.":".$restohm;
					  }
				  ?>
			      </div></td>
			      <td class="lblForm"><div align="center"><?=$numeropax?></div></td>
			      <td class="lblForm"><div align="center">
			        <?=$pesocarga?>
			      </div></td>
			      <td><div align="center"></div></td>
			      <td><div align="center"></div></td>
			      <td><div align="center">
			        <?=number_format($totaldistri,2,'.','');?>
			      </div></td>
			      </tr>
                </table>
            </div></td>
          </tr>
		  
          <tr class="lblCampo">
            <td><div align="center"></div></td>
          </tr>
          <tr>
		  <form name="form2" method="post" action="p_distri_cc_viaje_print.php">
            <td><div align="center">
              
                <table width="450" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="104"><div align="right">
                        <input type="button" name="Submit2" value=".:Imprimir:." style="<?=$stylo['st2']?>" class="botira" onClick="javascript:print_1('p_distri_cc_viaje_print.php?fecha1=<?=$fecha1?>&fecha2=<?=$fecha2?>&matricula=<?=$matricula?>&monto=<?=$monto?>',800,600)">
                    </div></td>
                    <td width="93">&nbsp;                        </td>
                    <td width="104"><div align="left">
                        <input type="button" name="Submit2" value=".:    Salir    :." style="<?=$stylo['st2']?>" class="botira" onClick="volver();">
                    </div></td>
                  </tr>
                </table>
              
            </div></td>
			</form>
          </tr>
        </table>
    </div></td>
    <td background="../estilo_tabla/parte_med_der.gif">&nbsp;</td>
  </tr>
  <tr>
    <td><img src="../estilo_tabla/parte_inf_izq.gif" width="25" height="25"></td>
    <td background="../estilo_tabla/parte_inf_cen.gif">&nbsp;</td>
    <td><img src="../estilo_tabla/parte_inf_der.gif" width="25" height="25"></td>
  </tr>
</table>
<map name="MapMap">
  <area shape="rect" coords="2,5,22,21" href="fondo.php">
</map>
<map name="Map">
  <area shape="rect" coords="2,5,22,21" href="fondo.php">
</map>
</body>

</html>

