<!-- PANEL ADMINISTRATIVO -->		
<script type="text/javascript" src="js/cat_producto_1.js"></script>	
<script type="text/javascript" src="js/cat_producto_2.js"></script>	
<script src="js/jquery.min_productos.js"></script>  
<script src="js/bootstrap.min_productos.js.js"></script>  			
<div class="contentpanel">
 <?php

		
 if($_GET['proceso']=="1NS3RT"){
				$cod_empleado=strip_tags($_POST['cod_empleado']);
				$cuotas_pago=strip_tags($_POST['cuotas_pago']);
				$chequear_datos=mysql_query("Select * from  tabla_rrhh_prestamos where cod_empleado='$cod_empleado' and eliminar='0' and estatus='1' ",$link);
				$chequear=mysql_fetch_row($chequear_datos);
				if($chequear[0]!="")
					{
					echo'
                        <div class="alert alert-warning fade in">
                            <i class="fa-fw fa fa-warning"></i>
                                <strong>Advertencia !</strong> Datos ya registrados en la base de datos.
                        </div>
					';
					}   
				else 
					{ 
								
					$consultar_sql_ver_emple=mysql_query("select * from  tabla_rrhh_empleado where id='$cod_empleado' ORDER BY id DESC ",$link);
					$ver_consultar_sql_ver_emple=mysql_fetch_array($consultar_sql_ver_emple);
					$bono=$ver_consultar_sql_ver_emple['monto']; 
					$monto_prestamo=$_POST['monto_prestamo']; 
					$monto_calcular=$monto_prestamo/$cuotas_pago;
					$monto_descontar=number_format($monto_calcular, 2, '.','');
				
						mysql_query("INSERT INTO tabla_rrhh_prestamos(cod_empleado,salario,fecha_solicitud,monto_prestamo,monto_descontar,cuotas_pago,cuotas_pagadas,estatus,token_registro,eliminar,token_eliminar) VALUES ('".$cod_empleado."','".$bono."','".$fecha_actualxls."','".$_POST['monto_prestamo']."','".$monto_descontar."','".$_POST['cuotas_pago']."','0','1','".$token_proceso."','0','-')",$link);
					echo'
                        <div class="alert alert-success fade in">
                            <i class="fa-fw fa fa-check"></i>
                               <strong>Exelente !</strong> Muchas gracias datos registrados.
                        </div>
					';
					}				
				
			}
		if($_GET['proceso']=="D3L3T3"){
			$id_control=$_GET['token'];
			mysql_query("update tabla_rrhh_prestamos set eliminar='1',token_eliminar='$token_proceso'  where  id='$id_control'",$link);
					echo'
                        <div class="alert alert-warning fade in">
                            <i class="fa-fw fa fa-warning"></i>
                               <strong>Advertencia !</strong> El registro fue eleminado de la Base de Datos.
                        </div>	
					';
		}	
		if($_GET['proceso']=="PAGAR_DEUDA"){
			$id_control=$_GET['token'];
			mysql_query("update tabla_rrhh_prestamos set estatus='2',pagar_saldar='$token_proceso'  where  id='$id_control'",$link);
					echo'
                        <div class="alert alert-success fade in">
                            <i class="fa-fw fa fa-check"></i>
                               <strong>Advertencia !</strong> EL EMPLEADO FUE SALDA SU PRESTAMO.
                        </div>	
					';
		}			
  		$consultar_sql_ver=mysql_query("select * from  tabla_rrhh_empleado where eliminar='0' ORDER BY id DESC ",$link);
		$ver_consultar_sql_ver=mysql_num_rows($consultar_sql_ver);
 ?>
<div class="row row-stat">
	<div class="col-md-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                <div class="panel-btns">
                    <a href="#" class="panel-minimize tooltips" data-toggle="tooltip" title="Minimize Panel"><i class="fa fa-minus"></i></a>
                    <a href="#" class="panel-close tooltips" data-toggle="tooltip" title="Close Panel"><i class="fa fa-times"></i></a>
                </div>
                <h4 class="panel-title"><?php echo $ver_cpanel_sub_menu['titulo']; ?></h4>
                <p><?php echo $ver_cpanel_sub_menu['descripcion']; ?>.</p>
            </div>
            <div class="panel-body nopadding">

				<div class="col-md-12">
				

                    <div class="table-responsive"><br>
						<!--BOTONES DE EXPORTACION-->

						<div class="pull-left">
							<div class="btn-group">
                                <button class="btn btn-default btn-sm " type="button"><i class="fa fa-print mr5"></i> Imprimir</button>
								<a href='' TARGET="_BLANK"  class="btn btn-default btn-sm " type="submit" id="export_data" name='export_data'><i class="fa fa-file-excel-o mr5"></i> Descargar XLS</a>
								<button class="btn btn-default btn-sm " type="button"><?php echo $ver_consultar_sql_ver; ?> Empleados registrados</button>
							</div>
						</div>
						<!--BOTONES DE EXPORTACION-->	
						
						<!--BOTONES DE AGREGAR-->						
						<!--<div class="pull-right">
						    <div class="btn-group">
                                <button class="btn btn-success btn-sm " type="button" data-toggle="modal" data-target=".bs-example-modal-lg"><i class="fa  fa-plus-square mr5"></i> AGREGAR PRESTAMOS </button>
						   </div>
						</div>-->
						<br>
						<br>
						<br>
						<div class="input-group mb15 has-warning">
                            <span class="input-group-addon"><b>BUSCAR</b></span>
                            <input type="text" autofocus="autofocus" placeholder="Buscar empleados" id="search" class="form-control" />
                        </div>					

							<table id="employee_table" class="table table-striped table-bordered responsive">
                                <thead class="">
                                    <tr>
                                        <th>Cedula</th>
                                        <th>Nombre y apellido</th>
                                        <th>Monto</th>
                                        <th>Monto del prest.</th>
                                        <th>Descontar</th>
                                        <th>Cuotas calculadas / pagadas </th>
                                        <th>Opcion</th>
                                    </tr>
                                </thead>
								
                                <tbody>
								<?php

										$consultar_sql_ver=mysql_query("select * from  tabla_rrhh_empleado where eliminar='0' and estatus='1'  ",$link);
										while($ver_consultar_sql_ver=mysql_fetch_array($consultar_sql_ver)){
											$cod_empleado=$ver_consultar_sql_ver['id'];
												$consultar_sql_verx=mysql_query("select * from tabla_rrhh_prestamos where cod_empleado='$cod_empleado' and eliminar='0' and estatus='1' ORDER BY id DESC ",$link);
												$ver_consultar_sql_verx=mysql_fetch_array($consultar_sql_verx);
								?>
                                    <tr>
										<td><?php echo $ver_consultar_sql_ver['cedula_trabajador']; ?> </td>										
										<td><?php echo $ver_consultar_sql_ver['nombre_apellido']; ?> </td>										
										<td style="text-align: right;"><?php echo $ver_consultar_sql_ver['monto']; ?> </td>										
										<td style="text-align: right;"><?php if($ver_consultar_sql_verx['monto_prestamo']=='') { echo '0.00'; } else { echo number_format($ver_consultar_sql_verx['monto_prestamo'], 2, '.','');}  ?></td>
										<td style="text-align: right;"><?php if($ver_consultar_sql_verx['monto_descontar']=='') { echo '0.00'; } else { echo number_format($ver_consultar_sql_verx['monto_descontar'], 2, '.','');}  ?></td>
										<td style="text-align: right;">Cuotas <?php if($ver_consultar_sql_verx['cuotas_pago']=='') { echo '0'; } else { echo $ver_consultar_sql_verx['cuotas_pago'];}  ?> / <?php if($ver_consultar_sql_verx['cuotas_pagadas']=='') { echo '0'; } else { echo $ver_consultar_sql_verx['cuotas_pagadas'];}  ?> </td>										
										<td><a href=""   title="Agregar" data-toggle="modal" data-target=".bs-example-modal-lg-<?php echo $ver_consultar_sql_ver['id']; ?>"  class=" btn-success btn-sm" >[ + ] PREST. </a>&nbsp; 
											<?php if($ver_consultar_sql_verx['monto_prestamo']!='') { ?>
												 <a href="<?php echo $url_global;?>&proceso=PAGAR_DEUDA&token=<?php echo $ver_consultar_sql_verx['id']; ?>"   title="Agregar"  class=" btn-primary btn-sm" ><b>PAGAR</b>
											<?php  }  ?>
										</td>										
                                    </tr> 
									<?php } ?>
                                </tbody>
                            </table>
							<script>  
								  $(document).ready(function(){  
									   $('#search').keyup(function(){  
											search_table($(this).val());  
									   });  
									   function search_table(value){  
											$('#employee_table tr').each(function(){  
												 var found = 'false';  
												 $(this).each(function(){  
													  if($(this).text().toLowerCase().indexOf(value.toLowerCase()) >= 0)  
													  {  
														   found = 'true';  
													  }  
												 });  
												 if(found == 'true')  
												 {  
													  $(this).show();  
												 }  
												 else  
												 {  
													  $(this).hide();  
												 }  
											});  
									   }  
								  });  
							 </script>
					</div>
                </div>								
            </div>     
            </div>
        </div>
	</div>
</div>
<!--MODAL -->
<?php
	$consultar_sql_vere=mysql_query("select * from  tabla_rrhh_empleado where eliminar='0' and estatus='1'  ",$link);
	while($ver_consultar_sql_vere=mysql_fetch_array($consultar_sql_vere)){
		
		$consultar_sql_verx=mysql_query("select * from tabla_rrhh_prestamos where cod_empleado='".$ver_consultar_sql_vere['id']."' and eliminar='0' and estatus='1' ORDER BY id DESC ",$link);
		$ver_consultar_sql_verx=mysql_fetch_array($consultar_sql_verx);		
?>
    <div class="modal fade bs-example-modal-lg-<?php echo $ver_consultar_sql_vere['id']; ?>" tabindex="-1" role="dialog">
            <div class="modal-dialog modal-lg">
              <div class="modal-content">
                  <div class="modal-header">
                      <button aria-hidden="true" data-dismiss="modal" class="close" type="button">&times;</button>
                      <h4 class="modal-title"><?php echo $ver_cpanel_sub_menu['titulo']; ?></h4>
                  </div>
				  <div class="panel-heading">
                      <p><?php echo $ver_cpanel_sub_menu['descripcion']; ?>.</p>
                  </div>
                  <div class="modal-body">
				  <!-- CONTROL DEL FORMULARIO -->
                      <div class="alert alert-warning fade in">
                            <i class="fa-fw fa fa-warning"></i>
                               <strong>Advertencia !</strong> Si el empleado ya tiene un prestamo, <b>NO</b> debera pedir uno nuevo hasta no pagar el actual.
                        </div>				  
				  <form action="<?php echo $url_global.'&proceso=1NS3RT'?>" method="POST" class="form-bordered" name='formulario'>
												 <input type="hidden" name="cod_empleado" value="<?php echo $ver_consultar_sql_vere['id']; ?>">					

 												<div class="col-sm-12">
													<h3><?php echo $ver_consultar_sql_vere['cedula_trabajador']; ?> - <?php echo $ver_consultar_sql_vere['nombre_apellido']; ?></h3>
												<br>
												</div>	
												
												<div class="col-sm-4">
													<input	class='form-control'
															type='text' 
															name='monto' 
															id='monto'
															autocomplete="off"
															autofocus="autofocus"
															required="required"
															title='Campo requerido, no dejar en blanco'
															value=''
															min='10'
															max='35000000'
															placeholder=' BONO <?php echo $ver_consultar_sql_vere['monto']; ?>'
															onChange="javascript:this.value=this.value.toUpperCase();"
															disabled
													/>
												</div>		
												<div class="col-sm-4">
													<input	class='form-control'
															type='number' 
															name='monto_prestamo' 
															id='monto_prestamo'
															autocomplete="off"
															autofocus="autofocus"
															required="required"
															title='Campo requerido, no dejar en blanco'
															value=''
															min='10'
															<?php if($codigo!='1'){ ?>
															max='<?php echo $ver_consultar_sql_vere['monto']; ?>'
															<?php } ?>
															placeholder='MONTO DEL PRESTAMO'
															onChange="javascript:this.value=this.value.toUpperCase();"
															
													/>
												</div>	 
																	
												<div class="col-sm-4">
											      <select id="cuotas_pago" name='cuotas_pago'  class='form-control' required="required" >
													<option value='' >CUOTAS DE PAGO</option>
															<option value="1">1</option>
															<option value="2">2</option>
															<option value="3">3</option>
															<option value="4">4</option>
															<?php if($codigo=='1'){?>
															<option value="5">5</option>
															<option value="6">6</option>
															<option value="7">7</option>
															<option value="8">8</option>
															<option value="9">9</option>
															<option value="10">10</option>
															<option value="11">11</option>
															<option value="12">12</option>
															<option value="13">13</option>
															<option value="14">14</option>
															<option value="15">15</option>
															<option value="16">16</option>
															<option value="17">17</option>
															<option value="18">18</option>
															<option value="19">19</option>
															<option value="20">20</option>
															<option value="21">21</option>
															<option value="22">22</option>
															<option value="23">23</option>
															<option value="24">24</option>
															<?php } ?>
													</select>
												</div>  
												
												<br>	
												<br>
												<br>
												<br><br>
												<br>
												<br>
								<?php if($ver_consultar_sql_verx['estatus']!='1') { ?>				
										<div class="pull-right">
											<button type="submit" name="submit" value='Guardar' class="btn btn-success btn-sm">GUARDAR <i class="fa fa-floppy-o ml5"></i></button>
										</div>
								<?php } ?>	
								<?php if($ver_consultar_sql_verx['estatus']=='1') { ?>				
										<div class="pull-right">
											<b href='' class="btn btn-default btn-sm">GUARDAR <i class="fa fa-floppy-o ml5"></i></b>
										</div>
								<?php } ?>		
							</form>  
				  
				  <!-- CONTROL DEL FORMULARIO -->
				  			<br>
												<br>
												<br>
												
								<table class="table table-striped table-bordered responsive">
                                <thead class="">
                                    <tr>
                                        <th>Fecha del prestamo</th>
                                        <th>Monto del prestamo</th>
                                        <th>Cuotas</th>
                                        <th>Estatus</th>
                                        <th>Opcion</th>
                                    </tr>
                                </thead>
								
                                <tbody>
								<?php			$consultar_sql_verx1=mysql_query("select * from tabla_rrhh_prestamos where cod_empleado='".$ver_consultar_sql_vere['id']."' and eliminar='0' ORDER BY id DESC ",$link);
												while($ver_consultar_sql_verx1=mysql_fetch_array($consultar_sql_verx1)){
								?>
                                    <tr>
										<td><?php echo $ver_consultar_sql_verx1['fecha_solicitud']; ?> </td>										
										<td><?php echo $ver_consultar_sql_verx1['monto_prestamo']; ?> </td>										
										<td><?php echo $ver_consultar_sql_verx1['cuotas_pago']; ?> </td>										
										<td><?php if( $ver_consultar_sql_verx1['estatus']=='1') { echo '<b>PAGANDO</b>'; } else { echo 'PAGA'; } ?> </td>										
										<td>	<a href="<?php echo $url_global;?>&proceso=D3L3T3&token=<?php echo $ver_consultar_sql_verx1['id']; ?>"   title="Eliminar"  class=" btn-danger btn-sm" ><i class="fa fa-trash-o"></i></a></td>										
                                    </tr> 
									<?php } ?>
                                </tbody>
                            </table>												
				  </div>
              </div>
            </div>
        </div>
	<?php } ?>