<?php 

session_start();
if(isset($_SESSION['ordencompra_can'])){
$num_rows=count($_SESSION['ordencompra_can']);
}else {
	$num_rows= 0 ;
}

?>


<style type="text/css">
select{
	cursor:pointer;
}
</style>
<div class="content-header" >
      <div class="container-fluid">
        <div class="row mb-2">
		 <div class="col-sm-6">
			<h1>
			Inventario inicial
			<small>modulo</small>
			</h1>
		</div>	
		
		<div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
				<li class="breadcrumb-item" >Inicio</li>
				<li class="breadcrumb-item" >Almacen</li>
				<li class="breadcrumb-item active">Inventario inicial</li>
            </ol>
          </div>
		</div>
	</div>
</div>
<section class="content">
	<div class="container-fluid">
	<div class="row">
	    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="padding:0px;" >
		    <div class="card">
		        <div class="card-header">
		          <button id="btn_actualizar" class="btn btn-default">Actualizar</button>

<div id="btn_verproductoagregado" style="cursor:pointer;margin-top:8px;<?php if($num_rows>0){ echo 'display:block;';}else{ echo 'display:none;'; }?>" data-toggle="tooltip" data-placement="top" 
					title="Ver productos agregados" class="btn btn-sm btn-danger float-right "><i class="fa fa-eye"></i> GENERAR ORDEN</div>
					
		        </div>
		    </div>
		</div>
	</div>
	</div>
</section>
	<!-- busqueda de registros -->
	<div id="div_inventarioinicial_filtro"></div>
	<!-- listado de registros -->
	<div id="div_inventarioinicial_tabla"></div>
	
	
	
	<div class="modal fade" id="div_inventarioveralmacenes_form_dialog" role="dialog" data-keyboard="false" data-backdrop="static" tabindex="-1" 
			style="padding:0px;overflow-y:scroll;">
			<div class="modal-dialog modal-md" role="document" >
			<div class="modal-content">
			<div class="modal-body div_inventarioveralmacenes_form" style="padding:0px;" >
			</div>
			<br />
			<br />
			</div>
			</div>
			</div>
			
			
	
	<div class="modal fade" id="div_ordencompraproducto_form_dialog" role="dialog" data-keyboard="false" data-backdrop="static" tabindex="-1" 
			style="padding:0px;overflow-y:scroll;">
			<div class="modal-dialog modal-md" role="document" >
			<div class="modal-content">
			<div class="modal-body div_ordencompraproducto_form" style="padding:0px;" >
			</div>
			<br />
			<br />
			</div>
			</div>
			</div>
			
			
			
	<!-- formulario de registro -->
			<div class="modal fade" id="div_ordencompra_form_dialog" role="dialog" data-keyboard="false" data-backdrop="static" tabindex="-1"  style="padding:0px; overflow-y:scroll;">
			<div class="modal-dialog modal-xl"   style="" role="document" >

			<div class="modal-content">

			<div class="modal-body div_ordencompra_form" style="padding:0%;" >

			</div>
			<br />
			<br />
			</div>
			</div>
			</div>
				
	<!-- formulario de registro -->
			<div class="modal fade" id="div_productocodigo_form_dialog" role="dialog" data-keyboard="false" data-backdrop="static" tabindex="-1"  style="padding:0px; overflow-y:scroll;">
			<div class="modal-dialog modal-md"   style="" role="document" >

			<div class="modal-content">

			<div class="modal-body div_productocodigo_form" style="padding:0%;" >

			</div>
			<br />
			<br />
			</div>
			</div>
			</div>
			
		<!-- formulario de registro para proveedores -->
		<div class="modal fade" id="div_proveedor_form_dialog" role="dialog" data-keyboard="false" data-backdrop="static" tabindex="-1"  style="padding:0px; overflow-y:scroll;">
			<div class="modal-dialog modal-lg"  role="document" >

			<div class="modal-content">

			<div class="modal-body div_proveedor_form"  >

			</div>
			<br />
			<br />
			</div>
			</div>
			</div>
	
<script type="text/javascript">


	
	
function ver_almacenes(cat_id,mar_id,alm_id)
	{
	
	$('#div_inventarioveralmacenes_form_dialog').modal();
	$.ajax({
		type: "POST",
		url: "../stock/stock_form_almacenes.php",
		async:true,
		dataType: "html",                      
		data: ({
			vista : 'inventarioinicial_tabla',
			cat_id:cat_id,
			mar_id:mar_id,
			alm_id:alm_id
		}),
		beforeSend: function() {

			var div = "<center> <br> <span class='spinner-border spinner-border-lg mr-2'></span> <span style='font-size:1.5rem;'>PROCESANDO PETICIÓN</span></center>";	
			$('.div_inventarioveralmacenes_form').html(div);
        },
		success: function(html){
			$('.div_inventarioveralmacenes_form').html(html);
		},
		complete: function(){			
		}
	});    
	}	



	function agregar_productoordencompra(cat_id,mar_id)
	{
		
	
	$('#div_ordencompraproducto_form_dialog').modal('show');
	$.ajax({
		type: "POST",
		url: "../ordencompra/ordencompra_productoform.php",
		async:true,
		dataType: "html",                      
		data: ({
			cat_id: cat_id,
			mar_id : mar_id
		}),
		beforeSend: function() {

			var div = "<center> <br> <span class='spinner-border spinner-border-lg mr-2'></span> <span style='font-size:1.5rem;'>PROCESANDO PETICIÓN</span></center>";	
			$('.div_ordencompraproducto_form').html(div);
        },
		success: function(html){
			$('.div_ordencompraproducto_form').html(html);
		},
		complete: function(){			
		}
	});    
	}	
	
	

	function inventarioinicial_filtro()
	{
		$.ajax({
			type: "POST",
			url: "../inventarioinicial/inventarioinicial_filtro.php",
			async:true,
			dataType: "html",                      
		data: ({
		}),
		beforeSend: function() {
			var div = "<center> <br> <span class='spinner-border spinner-border-lg mr-2'></span> <span style='font-size:1.5rem;'>PROCESANDO PETICIÓN</span></center>";
			$('#div_inventarioinicial_filtro').html(div);
		},
		success: function(html){
			$('#div_inventarioinicial_filtro').html(html);
		},
		complete: function(){
		}
	});
	}
	function inventarioinicial_tabla()
	{
		$.ajax({
			type: "POST",
			url: "../inventarioinicial/inventarioinicial_tabla.php",
			async:true,
			dataType: "html", 
			data: $("#for_fil_invini").serialize(),                    
			beforeSend: function() {		
				$('#div_inventarioinicial_tabla').addClass("ui-state-disabled");
			},
			success: function(html){
				$('#div_inventarioinicial_tabla').html(html);
			},
			complete: function(){			
				$('#div_inventarioinicial_tabla').removeClass("ui-state-disabled");
			}
		});     
	}
	
	
	
	
	function agregar_dato(act,catid,marid,fecven,preven)
	{
		$.ajax({
			type: "POST",
			url: "../gestionxstock/gestionxstock_reg.php",
			async:true,
			dataType: "json", 
			data: ({
				action : act,
				catid : catid,
				marid : marid,
				fecven : fecven,
				preven : preven
			}),                    
			beforeSend: function() {		
				
			},
			success: function(data){
				toastr["info"](data.msj);
			},
			complete: function(){			
				gestionxstock_tabla();
			}
		});     
	}
	
	
	
function ordencompra_form(act,id)
	{
	
	$('#div_ordencompra_form_dialog').modal();
	$.ajax({
		type: "POST",
		url: "../ordencompra/ordencompra_form.php",
		async:true,
		dataType: "html",                      
		data: ({
			action : act,
			vista : 'stockgeneral_form',
			ordcom_id:id
		}),
		beforeSend: function() {

			//var div = "<center> <br> <span class='spinner-border spinner-border-lg mr-2'></span> <span style='font-size:1.5rem;'>PROCESANDO PETICIÓN</span></center>";	
			//$('.div_ordencompradetalle_form').html(div);
        },
		success: function(html){
			$('.div_ordencompra_form').html(html);
		},
		complete: function(){			
		}
	});    
	}	


function agregar_pedidocompra(act,can,cat_id,mar_id,vista){
		$.ajax({
			type: "POST",
			url: "../ordencompra/agregar_producto.php",
			async:true,
			dataType: "json",                      
			data: ({
				action: act,
				cat_id : cat_id ,
				mar_id : mar_id ,
				can : can,
				vista:	'stockgeneral_form'
			}),
			beforeSend: function() {
				
			},
			success: function(data){
				
				if(data.dat.tipo=="can")
				{
					toastr["warning"](data.msj);
					
				}else if(data.dat.tipo=="agregado")
				{
					
					toastr["info"](data.msj);
				}
				else if(data.dat.tipo=="quitado")
				{
					
					toastr["info"](data.msj);
					ordencompra_detalle_tabla();
				}
				
				
			},
			complete: function(){
				if(vista=="agregar"){
					$("#txt_ordcom_can").val('');		
				}else if(vista=="quitar" || vista=="editar"){
					ordencompra_detalle_tabla();
				}	
			}
		});
	}


	
	
$(function() {
	
			
$("#btn_verproductoagregado").click(function(){
		ordencompra_form('insertar');
});

	
	$('#btn_actualizar').click(function() {
		$("#contenido").load("../inventarioinicial/inventarioinicial_vista.php");
	});
	 
	inventarioinicial_filtro();	
	setTitle("INVENTARIO INICIAL - "+nombreEmpresa);	
	
});
</script>