<?php
session_start(); 
require_once('../conexion.php');
require_once('../include/sesiones.php');
$ord_id=$_GET['ord_id'];                        
?>
<table class="table table-bordered table-hover table-striped">
<tr>
	<th width="7%">CODIGO</th>
	<th width="7%">CANTIDAD</th>
	<th><span class="pull-center">DESCRIPCION</span></th>
	<th width="10%"><span class="pull-right">PRECIO U</span></th>
	<th width="7%"><span class="pull-right">DESCUENTO</span></th>
	<th width="10%"><span class="pull-right">PRECIO T</span></th>
	<th width="10%"></th>
</tr>
<?php
	$descuentof=0;
  	$descuento=0;
  	$neto=0;
  	$sumador_total=0;
  	$iva_total=0;
	
	$sql=mysqli_query($con, "SELECT * from  orden_detalle where orden_servicios_ord_id='$ord_id' ");
	while ($row=mysqli_fetch_array($sql))
	{
		$id=$row["ordt_id"];
		$ordt_id=$row["ordt_id"];
		$ordt_referencia=$row['ordt_referencia'];
		$ordt_nombre=$row['ordt_nombre'];
		$ordt_cantidad=$row['ordt_cantidad'];
		$ordt_precio=$row['ordt_precio'];
		$ordt_iva=$row['ordt_iva'];
		$ordt_descuento=$row['ordt_desc'];

		$ivaf=$ordt_iva/100;
		$precio_total=$ordt_precio*$ordt_cantidad;
		$sumador_total+=$precio_total;//Sumador
	  	$descuento=($ordt_descuento/100)*$precio_total;
	  	$descuentof+=$descuento;

		$iva=$ordt_precio*$ivaf;
		$ivat=$iva*$ordt_cantidad;
		$sin_iva=($ordt_precio-$iva);
	  	$sin_ivat=($ordt_precio-$iva)*$ordt_cantidad;
	  	$iva_total+=$ivat;
	  	$neto+=$precio_total-$ivat;
		?>
		<tr>
			<td><?php echo $ordt_referencia;?></td>
			<td><?php echo $ordt_cantidad;?></td>
			<td><?php echo $ordt_nombre;?></td>
			<td><span class="pull-right"><?php echo number_format($sin_iva,0);?></span></td>
		
			<td><span class="pull-right"><?php echo number_format($descuento,0);?></span></td>
			<td><span class="pull-right"><?php echo number_format($precio_total,0);?></span></td>
			<td ><a data-id="<?php echo $id;?>" class="btn btn-edit btn-xs btn-warning"> <i class="btn-icon-only icon-edit"></i></a>
				<a href="#" id="del-<?php echo $row["ordt_id"];?>" class="btn btn-xs btn-danger"> <i class="btn-icon-only icon-remove"></i></a>
				<script>
				$("#del-"+<?php echo $row["ordt_id"];?>).click(function(e){
					e.preventDefault();
					p = confirm("Estas seguro?");
					if(p){
						$.get("./php_orden_de_servicios/z_eliminar_articulo.php","ordt_id="+<?php echo $row["ordt_id"];?>,function(data){
							loadTabla();
						});
					}
				});
				</script>
				<?php
                if($negocio_neg_id=='1')
                {
                    $can1=mysqli_query($con,"SELECT * FROM orden_detalle_seriales where ordt_id='$ordt_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;?>" class="btn btn-ser btn-xs btn-info" 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-info" title="Serial"> <i class="btn-icon-only icon-barcode"></i></a>
                <?php } }?>
			</td>
		</tr>		
<?php } ?>
<tr>
	<td colspan=5><span class="pull-right">NETO $</span></td>
	<td><span class="pull-right"><strong><?php echo number_format($neto,0);?></strong></span></td>
	<td></td>
</tr>
<tr>
	<td colspan=5><span class="pull-right">DESCUENTO %</span></td>
	<td><span class="pull-right"><strong><?php echo number_format($descuentof,0);?></strong></span></td>
	<td></td>
</tr>
<tr>
	<td colspan=5><span class="pull-right">TOTAL $</span></td>
	<td><span class="pull-right"><strong><?php echo number_format($sumador_total-$descuentof,2);?></strong></span></td>
	<td></td>
</tr>
</table>

<script>
	$(".btn-edit").click(function(){
		id = $(this).data("id");
		$.get("./php_orden_de_servicios/z_form_editar_articulo.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">
      	<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 class="modal-body">
        		<div id="form-edit"></div>
        	</div>
      	</div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<script>
$(".btn-ser").click(function(){
  id = $(this).data("id");
  $.get("./php_orden_de_servicios/z_form_seriales.php","id="+id,function(data){
    $("#form-ser").html(data);
  });
  $('#serModal').modal('show');
});
</script>
<div class="modal fade" id="serModal" 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-ser"></div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<script>
$(".btn-ser_tabla").click(function(){
  id = $(this).data("id");
  $.get("./php_orden_de_servicios/z_form_tabla_serial.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 -->

<div class="modal fade" id="n_serial" 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">Nuevo Serial</h4>
            </div>
            <div class="modal-body">
                <div id="form-n_serial"></div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal --> 