<?php
session_start();
if($_SESSION["sistema"]!= "1"){ header("location: ../../index.php"); exit();}
require_once ("../../config/Cado.php");


require_once ("../usuario/cUsuarioprograma.php");
$oUsuarioprograma = new cUsuarioprograma();

$dts=$oUsuarioprograma->mostrar_uno($_SESSION['usuario_id'],'5');
$numrows = mysqli_num_rows($dts);
if($numrows>0){
	$bantraspaso = true;
}else{
	$bantraspaso = false;
}


if($bantraspaso==true){


?>

<div class="content-header" >
      <div class="container-fluid">
        <div class="row mb-2">
		 <div class="col-sm-6">
			<h1>
			Traspaso
			<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">Traspaso</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_agregar" onClick="traspaso_form('insertar')" class="btn btn-primary">Agregar</button>
		          <button id="btn_actualizar" class="btn btn-default">Actualizar</button>		        
		        </div>
		    </div>
		</div>
	</div>
	</div>
</section>


					<!-- BUSQUEDA DE REGISTROS-->
					<div id="div_traspaso_filtro" > </div>
					<!-- LISTADO DE REGISTROS-->
					<div id="div_traspaso_tabla" > </div>
					
			<!-- formulario de registros -->
			<div class="modal fade" id="div_traspaso_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_traspaso_form" style="padding:0%;" >
			</div>			
			<br />			<br />			
			</div>			
			</div>			
			</div>

			<!-- formulario de registro -->
			<div class="modal fade" id="div_productomarca_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_productomarca_form" >

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

			<div class="modal-content">

			<div class="modal-body div_traspasoval_form" >

			</div>
			<br />
			<br />
			</div>
			</div>
			</div>          	
	

<script type="text/javascript">
	function traspaso_filtro()
	{
		$.ajax({
			type: "POST",
			url: "../traspaso/traspaso_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_traspaso_filtro').html(div);
		},
		success: function(html){
			$('#div_traspaso_filtro').html(html);
		},
		complete: function(){
		
		}
	});
	}

	function traspaso_tabla(){
		$.ajax({
			type: "POST",
			url: "../traspaso/traspaso_tabla.php",
			async:true,
			dataType: "html",                      
			data: $("#for_fil_tra").serialize(),                    
			beforeSend: function() {
				$('#div_traspaso_tabla').addClass("ui-state-disabled");
			},
			success: function(html){
				$('#div_traspaso_tabla').html(html);
			},
			complete: function(){			
				$('#div_traspaso_tabla').removeClass("ui-state-disabled");
			}
		});     
	}
	
	function traspaso_form(act,idf)
	{
		$('#div_traspaso_form_dialog').modal();
		
		$('body').css('overflow-y','hidden');
		$.ajax({
			type: "POST",
			url: "../traspaso/traspaso_form.php",
			async:true,
			dataType: "html",                      
			data: ({
				action: act,
				tra_id:	idf
			}),
			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_traspaso_form').html(div);
			},
			success: function(html){
				$('.div_traspaso_form').html(html);				
			}
		});
	}

	function traspaso_form_val(idf)
	{
		$('#div_traspasoval_form_dialog').modal();
		$.ajax({
			type: "POST",
			url: "../traspaso/traspaso_formval.php",
			async:true,
			dataType: "html",                      
			data: ({
				tra_id:	idf
			}),
			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_traspasoval_form').html(div);
			},
			success: function(html){
				$('.div_traspasoval_form').html(html);				
			}
		});
	}

	function traspaso_impr_ticket(idf){
		if(confirm("Desea imprimir este Traspaso?")){
			traspaso_imppos_datos(idf);
		}
	}
	function traspaso_imppos_datos(id_tra){	
		//if(confirm("Desea imprimir éste documento?")){
			$.ajax({
				type: "POST",
				url: "../traspaso/traspaso_imppos_datos.php",
				async:true,
				dataType: "json",                      
				data: ({ tra_id: id_tra}),
				beforeSend: function() {
					//$('#msj_venta').html("Imprimiendo...");
					//$('#msj_venta').show(100);
				},
				success: function(data){
					console.log(data);
					traspaso_imppos_comprobante(data,data.imp_doc);
					//$('#div_venta_form').dialog("close");
				}
			});
		//}
	}

	function traspaso_imppos_comprobante(datos,url_doc){	
		$.ajax({
			type: "POST",
			url: url_doc,
			async:true,
			dataType: "html",                      
			data: datos,
			beforeSend: function()
			{
				console.log(datos);
				//$('#msj_venta_imp').html("Imprimiendo...");
				//$('#msj_venta_imp').show(100);
			},
			success: function(html){						
				//$('#msj_venta_imp').html(html);		
			}
		});
	}
	function traspaso_impresion(idf){
		$.ajax({
			type: "POST",
			url: "traspaso_preimpresion.php",
			async:true,
			dataType: "html",                      
			data: ({
				tra_id:	idf
			}),
			beforeSend: function() {
				$('#div_traspaso_impresion').dialog("open");
				$('#div_traspaso_impresion').html('Cargando...');
			},
			success: function(html){
				$('#div_traspaso_impresion').html(html);				
			}
		});
	}
	
	function eliminar_traspaso(id)
	{      
		if(confirm("Realmente desea anular este Trapaso ?")){
			$.ajax({
				type: "POST",
				url: "../traspaso/traspaso_reg.php",
				async:true,
				dataType: "json",
				data: ({
					action: "eliminar",
					tra_id:		id
				}),
				beforeSend: function() {
					
				},
				success: function(data){
						toastr["success"](data.tra_msj);	
				},
				complete: function(){
					traspaso_tabla();
				}
			});
		}
	}


	function compra_reporte()
	{	
		$("#for_fil_com").submit();
	}

	function compra_reporte_xls(){
		$("#hdd_tabla").val( $("<div>").append( $("#tabla_compra").eq(0).clone()).html()); 
		$("#for_rep_xls").submit();
	}

	function modo(url){
		$('#hdd_modo').val(url);
		compra_tabla();
	}


	$(function() {

		$('#btn_actualizar').click(function() {
			$("#contenido").load("../traspaso/traspaso_vista.php");
		});
		
		$("#div_traspaso_form_dialog").on('hidden.bs.modal', function () {
		   	$('body').css('overflow-y','scroll');
    });
	
			$("#div_productomarca_form_dialog").on('hidden.bs.modal', function () {
		   	$('body').css('overflow-y','scroll');
    });
	
		
	
		$('#div_traspaso_form_dialog').on('shown.bs.modal', function () { $("#txt_bus_pro_codbar").focus(); }); 


		
		traspaso_filtro();		
		
		setTitle("TRASPASO - "+nombreEmpresa);
		
});
</script>




<?php }else{
?>	
	<br/>

<section class="content">
	<div class="container-fluid">
	<div class="row">
	    <div class="col-lg-12 col-md-12 col-sm-12 col-12" style="padding:0px;">
		    <div class="card">
		        <div class="card-header">
				<center>
					<span style="font-size:1.5rem;font-family:arial;" >Usted no tiene permisos para ver esta pantalla.</span>
		        </center>
				</div>
		    </div>
		</div>
	</div>
	</div>
</section>


	
<?php	
}?>


