<?php
   class clsEpp extends BDConexion
   {
     function clsEpp()
     {
       $this->conectar();
     } 
	 	 
	 function ListPersonal($varPersonal,$val_per,$disabled=0){
		 $sql="Select * from personal  order by appat_per  asc";
		 $result = $this->BDConsulta($sql);
		 $disabled = ($disabled) ? "disabled" : "";
		 echo "<select name=\"$varPersonal\" size=\"1\" $disabled onchange='EnviarcodPer();'>";
	     $i=0;
		 echo "<option $selected value='0'>-----------Personal----------- </option>";
		 while($fila=$this->NextRow($result)){
			        $selected = "";
			   if ($fila['dociden_per'] == $val_per) 
					 $selected = "selected";
					echo "<option $selected value=".$fila['dociden_per'].">".$fila['appat_per']." ".$fila['apmat_per'].",".$fila['nom_per']."</option>";
			   }
			   echo "</select>";
		}  
		 
	function ListEpp($varEpp,$val_Epp,$disabled=0){
		 $sql="Select * from epp  order by tipo_epp asc";
		 $result = $this->BDConsulta($sql);
		 $disabled = ($disabled) ? "disabled" : "";
		 echo "<select name=\"$varEpp\" size=\"1\" $disabled onchange='EnviarEPP();'>";
	     $i=0;
		 echo "<option value='0'>------EPP------ </option>";
		 while($fila=$this->NextRow($result)){
			        $selected = "";
			   if ($fila[0] == $val_Epp) 
					 $selected = "selected";
				  	
					echo "<option $selected value=\"$fila[0]\">".$fila['tipo_epp']."</option>";
					$i+=1;
			   }
			   echo "</select>";
				
		}
 	 
	 function ListTipoEntre($varTipoEn,$val_TEnt,$disabled=0){
		 $sql="Select * from tipo_en_epp  order by desc_tipo_ent asc";
		 $result = $this->BDConsulta($sql);
		 $disabled = ($disabled) ? "disabled" : "";
		 echo "<select name=\"$varTipoEn\" size=\"1\" $disabled onchange='TipoEnt();'>";
	     $i=0;
		 echo "<option $selected value='0'>-----Tipo Entrega----- </option>";
		 while($fila=$this->NextRow($result)){
			        $selected = "";
			   if ($fila[0] == $val_TEnt) 
					 $selected = "selected";
					
					echo "<option $selected value=\"$fila[0]\">".$fila['desc_tipo_ent']."</option>";
					$i+=1;
			   }
			   echo "</select>";
				
		}
	function ListLugar($varLugar,$val_Lug,$disabled=0){
		 $sql="Select * from lugares order by nom_lugar asc";
		 $result = $this->BDConsulta($sql);
		 $disabled = ($disabled) ? "disabled" : "";
		 echo "<select name=\"$varLugar\" size=\"1\" $disabled onchange='TipoEnt();'>";
	     $i=0;
		 echo "<option $selected value='0'>------Lugares----- </option>";
		 while($fila=$this->NextRow($result)){
			        $selected = "";
			   if ($fila[0] == $val_Lug) 
					 $selected = "selected";
					
					echo "<option $selected value=\"$fila[0]\">".$fila['nom_lugar']."</option>";
					$i+=1;
			   }
			   echo "</select>";
				
		}
	 	function ListRespLogisti($varLog,$val_Log,$disabled=0){
		 $sql="Select * from responsable_logistico  order by nom_resp asc";
		 $result = $this->BDConsulta($sql);
		 $disabled = ($disabled) ? "disabled" : "";
		 echo "<select name=\"$varLog\" size=\"1\" $disabled onchange='TipoEnt();'>";
	     $i=0;
		 echo "<option $selected value='0'>-----Responsable---- </option>";
		 while($fila=$this->NextRow($result)){
			        $selected = "";
			   if ($fila[0] == $val_Log) 
					 $selected = "selected";
					
					echo "<option $selected value=\"$fila[0]\">".$fila['nom_resp']." ".$fila['apell_pat_resp']."</option>";
					$i+=1;
			   }
			   echo "</select>";
				
		}
	function  DevolPersEmpxCod($cod){
	        $sql="Select p.*,e.* from personal as p, empresas as e where p.cod_emp = e.cod_emp and p.dociden_per = '$cod'";
			return $this->BDConsulta($sql);
								 } 
	function DevolEppxCod($cod){
			$sql="Select * from epp where id_epp =$cod ";
			return $this->BDConsulta($sql);	
							} 
   function GrabarTipoEntr($tipo){
           $sql="Insert Into tipo_en_epp (desc_tipo_ent) values('$tipo')";
           $this->BDConsulta($sql);	
                      }
	function GrabarPerRes($nom_resp,$apell_pat_resp,$pell_mat_resp,$doc_id,$cargo){
           $sql="Insert Into responsable_logistico  (nom_resp,apell_pat_resp,apell_mat_resp,doc_id,cargo) values('$nom_resp','$apell_pat_resp','$pell_mat_resp','$doc_id','$cargo')";
           $this->BDConsulta($sql);	
                      }
   function GrabarEquipoEPP($tipo_epp,$marca,$umedida,$clase,$tiempo_duracion,$observacion){
           $sql="Insert Into  epp (tipo_epp,marca,clase,umedida,tiempo_duracion,observacion) values('$tipo_epp','$marca','$umedida','$clase','$tiempo_duracion','$observacion')";
           $this->BDConsulta($sql);	
                      }
	function GrabarEntregaEPP($id_persona, $id_epp,$fecha_entrega, $fecha_duracion, $cantidad, $tipo_en_epp, $id_lugar, $id_per_res, $observacion ){
	     $sql="Insert Into  entrega_epp (id_persona, id_epp, fecha_entrega, fecha_duracion, cantidad, tipo_en_epp, id_lugar, id_per_res,observacion ) values('$id_persona', $id_epp,'$fecha_entrega', '$fecha_duracion', $cantidad, $tipo_en_epp, $id_lugar, $id_per_res,'$observacion')";
		 $this->BDConsulta($sql);	
			}
	function DevolverCantDadaEPP($codPer){
		$sql="SELECT e.tipo_epp,sum(en.cantidad) as total, e.umedida FROM personal as p, epp as e, entrega_epp as en WHERE en.id_persona = p.dociden_per and en.id_epp = e.id_epp and p.dociden_per = '$codPer' GROUP BY e.tipo_epp ORDER BY e.tipo_epp";
		return $this->BDConsulta($sql);
			}
			
    function DevolverEPPxPersona($dni){
	      $sql="Select entrega_epp.*, epp.* From entrega_epp, epp WHERE entrega_epp.id_epp = epp.id_epp AND entrega_epp.id_persona = '$dni' ORDER BY fecha_entrega";
	      return $this->BDConsulta($sql);
	        } 
	function DevolverEPPxPersonaxfecha($dni,$fecha1, $fecha2){
	      $sql="Select entrega_epp.*, epp.* From entrega_epp, epp WHERE entrega_epp.id_epp = epp.id_epp AND entrega_epp.id_persona = '$dni' AND entrega_epp.fecha_entrega between '$fecha1' and '$fecha2' ORDER BY fecha_entrega";
	      return $this->BDConsulta($sql);
	        } 
	function DevolverPersonaEpp($dni){
	      $sql="Select concat(p.appat_per,' ',p.apmat_per,' ',p.nom_per) as nombre, p.cargo_per, e.razon_emp From personal as p, empresas as e Where e.cod_emp = p.cod_emp AND p.dociden_per = '$dni' ";
	      return $this->BDConsulta($sql);
	        } 	
   function DevolverDnixfechas($fecha1, $fecha2){
         $sql="Select entrega_epp.id_persona from entrega_epp, personal  where entrega_epp.id_persona = personal.dociden_per AND entrega_epp.fecha_entrega between '$fecha1' and '$fecha2'   Group by entrega_epp.id_persona ORDER BY personal.appat_per";
         return $this->BDConsulta($sql);
             }
    function PersonasEntregdasEppxFecha($fecha1, $fecha2){
         $sql="Select concat(personal.appat_per,' ',personal.apmat_per,' ',personal.nom_per) as nombre, empresas.razon_emp from entrega_epp, personal,empresas  where empresas.cod_emp = personal.cod_emp AND entrega_epp.id_persona = personal.dociden_per AND entrega_epp.fecha_entrega between '$fecha1' and '$fecha2'   Group by entrega_epp.id_persona ORDER BY personal.appat_per";
         return $this->BDConsulta($sql);
           }
	function DevolverCantDadaEPPxFecha($fecha1, $fecha2){
		$sql="SELECT e.tipo_epp,sum(en.cantidad) as total, e.umedida FROM personal as p, epp as e, entrega_epp as en WHERE en.id_persona = p.dociden_per and en.id_epp = e.id_epp  AND en.fecha_entrega between '$fecha1' and '$fecha2'  GROUP BY e.tipo_epp ORDER BY e.tipo_epp";
		return $this->BDConsulta($sql);
			}
     }
	?>