<?php
session_start();
require_once('../conexion.php');
require_once('../include/sesiones.php');
?>
<table class="table table-bordered table-hover table-striped">
<tr>
	<th width="10%">CODIGO</th>
	<th width="8%">CANTIDAD</th>
	<th>NOMBRE</th>
	<th>PROBLEMA</th>
	<th width="10%"></th>
</tr>
<?php
	$sumador_total=0;
	$sql=mysqli_query($con, "SELECT * from  garantia_pro_detalle_temp  where usuario='$usu_id' and empresa='$empresa' ");
	while ($row=mysqli_fetch_array($sql))
	{
	$id=$row["gard_id"];
	$gard_id=$row["gard_id"];
	$gard_referencia=$row['gard_referencia'];
	$gard_nombre=$row['gard_nombre'];
	$gard_cantidad=$row['gard_cantidad'];
	$gard_precio=$row['gard_precio'];
	$gard_problema=$row['gard_problema'];
	$gard_serial=$row['gard_serial'];
	$gard_accesorios=$row['gard_accesorios'];
	$precio_total=$gard_precio*$gard_cantidad;
	$sumador_total+=$precio_total;//Sumador
?>
		<tr>
			<td><?php echo $gard_referencia;?></td>
			<td><?php echo $gard_cantidad;?></td>
			<td><?php echo $gard_nombre;?></td>
			<td><?php echo $gard_problema;?></td>
			<td >
				<a data-id="<?php echo $id;?>" class="btn btn-edit btn-xs btn-info"> <i class="btn-icon-only icon-edit"></i></a>
				<a href="#" id="del-<?php echo $row["gard_id"];?>" class="btn btn-xs btn-danger"> <i class="btn-icon-only icon-remove"></i></a>
				<?php
        		$can1=mysqli_query($con,"SELECT * FROM serial_garantias_temp where garantia_detalle_temp_gard_id='$gard_id'") or die(mysqli_error($con)); 
        		$dat=mysqli_fetch_array($can1);
                $result = mysqli_num_rows($can1);
                if($result == 0)
                {
     			?>
    	      	<a data-id="<?php echo $id;?>" data-toggle="modal" class="btn btn-ser btn-xs btn-default" title="Serial"> <i class="btn-icon-only icon-barcode"></i></a>
      			<?php } else { ?>
    	      	<a data-id="<?php echo $id;?>" data-toggle="modal" class="btn btn-ser_tabla btn-xs btn-default" title="Serial"> <i class="btn-icon-only icon-barcode"></i></a>
          		<?php } ?>
				<script>
				$("#del-"+<?php echo $row["gard_id"];?>).click(function(e){
					e.preventDefault();
					p = confirm("Estas seguro?");
					if(p){
						$.get("./php_garantias_proveedor/eliminar.php","gard_id="+<?php echo $row["gard_id"];?>,function(data){
							loadTabla();
						});
					}
				});
				</script>
			</td>
		</tr>		
		<?php
	}
?>
</table>
<script>
	$(".btn-edit").click(function(){
		id = $(this).data("id");
		$.get("./php_garantias_proveedor/form_editar.php","id="+id,function(data){
			$("#form-edit").html(data);
		});
		$('#editModal').modal('show');
	});
</script>
 <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
      	<div class="modal-content">
        	<div class="modal-header">
          		<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          		<h4 class="modal-title">Actualizar</h4>
        	</div>
        	<div id="form-edit"></div>
      	</div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->



<script>
  	$(".btn-ser").click(function(){
  		id = $(this).data("id");
  		$.get("./php_garantias_proveedor/form_serial.php","id="+id,function(data){
  			$("#form-serial").html(data);
  		});
  		$('#reg_ser').modal('show');
  	});
</script>
<div class="modal fade" id="reg_ser" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Agregar Seriales</h4>
            </div>
            <div class="modal-body">
                <div id="form-serial"></div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->



<script>
  	$(".btn-ser_tabla").click(function(){
  		id = $(this).data("id");
  		$.get("./php_garantias_proveedor/form_serial_tabla.php","id="+id,function(data){
  			$("#form-tabla_serial").html(data);
  		});
  		$('#reg_ser_tabla').modal('show');
  	});
</script>
<div class="modal fade" id="reg_ser_tabla" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Seriales</h4>
            </div>
            <div class="modal-body">
                <div id="form-tabla_serial"></div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->