<?php
session_start();
date_default_timezone_set('America/Lima');
$y=date('Y');
$m=date('m');
$d=date('d');

$fec1="$d-$m-$y";
$fec2="$d-$m-$y";

$fec1gra="01-$m-$y";

if($_SESSION['usuariogrupo_id']==1 || $_SESSION['usuariogrupo_id']==2){
		
	}
	else{
 	$punven_id = $_SESSION['puntoventa_id'];
 	}
	



?>



<section class="content">
	<div class="container-fluid">
	<div class="row">
	    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
		    <div class="card">
		        <div class="card-header">
				
					<div class="row" id="filtroregistros">
						
						<form id="for_fil_ven" action="POST">
														
				<div class="row">
				
				<div class=" col-lg-2 col-sm-6 col-6 form-group">
                  <label>Fecha 1:</label>

                  <div class="input-group">
                    <div class="input-group-prepend">
                      <span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
                    </div>
                    <input name="txt_fil_ven_fec1" type="text" id="txt_fil_ven_fec1" value="<?php echo $fec1?>" class="form-control" >
                  </div>
                </div>
				
				<div class=" col-lg-2 col-sm-6 col-6 form-group">
                  <label>Fecha 2:</label>

                  <div class="input-group">
                    <div class="input-group-prepend">
                      <span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
                    </div>
                    <input name="txt_fil_ven_fec2" type="text" id="txt_fil_ven_fec2" value="<?php echo $fec2 ?>" class="form-control" >
                  </div>
                </div>

							<div class="col-lg-2 col-sm-6 col-sm-3 col-6">				
								<label for="cmb_fil_puntoventa_id">Punto Venta:</label>
								<select name="cmb_fil_puntoventa_id" id="cmb_fil_puntoventa_id" class="form-control input-sm">
								</select>
													
							</div>
							
							<div class="col-lg-2 col-sm-6 col-6">
								<label>Doc:</label>
								<select name="cmb_fil_doc_id" id="cmb_fil_doc_id" class="form-control input-sm"></select> 				
							</div>
							
							<div class="col-lg-2 col-sm-6 col-6">
								<label>Serie/Numero:</label>
								<input type="text" id="txt_fil_docnum" name="txt_fil_docnum" class="form-control  input-sm" /> 
							</div>
							
							<div class="col-lg-2 col-sm-6 col-6">
								<label for="cmb_fil_mon_id">Moneda:</label>
								<select name="cmb_fil_mon_id" id="cmb_fil_mon_id" class="form-control input-sm">
								</select>    
							</div>
							
							<div class="col-lg-4 col-sm-6 col-6">
								<label>Cliente:</label>
								<input type="hidden" id="hdd_fil_cli_id" name="hdd_fil_cli_id" />
								<input type="text" id="txt_fil_cli" name="txt_fil_cli" class="form-control  input-sm" /> 
							</div>

							<div class="col-lg-2 col-sm-6 col-6">
								<label>Estado:</label> 
								<select name="cmb_fil_ven_est" id="cmb_fil_ven_est" style="cursor:pointer;" class="form-control">
									<option value="">TODAS VENTAS</option>
									<option value="1" selected>REGISTRADA</option>
									<option value="2">ANULADA</option>
									<option value="3">FACTURADO/BOLETEADO</option>
								</select>
							</div>
							
							<!--
							<div class="col-lg-2 col-xs-6">
								<label>Mozo:</label>
								<select name="cmb_fil_moz_id" id="cmb_fil_moz_id" class="form-control"></select> 
							</div>
							-->
							
							
							<div class="col-lg-2 col-sm-6 col-6">
								<label>Estado Sunat:</label>
								<select name="cmb_fil_ven_estsun" id="cmb_fil_ven_estsun" style="cursor:pointer;" class="form-control">
									<option value="" selected >TODAS VENTAS</option>
									<option value="1" >ACEPTADA</option>
									<option value="0">RECHAZADA</option>
								</select>
							</div>
							

							<div  class="col-lg-2 col-sm-5 col-6" style="display: inline-block; white-space: nowrap;padding-top:30px;">								
									<span onClick="venta_tabla()" style="cursor:pointer" class="btn btn-primary "><i class="fas fa-search"></i></span>									
									<span onClick="venta_filtro()" style="cursor:pointer" class="btn btn-default">RESTABLECER</span>																
							</div> 
							
							</div> 
							
						</form>	
						
					</div>
				
				
					<div class="row" style="display:none;" id="filtrograficos">
						
						<form id="for_fil_vengra" action="POST">
														
				<div class="row">
				
				<div class=" col-lg-2 col-sm-6 col-xs-6 form-group">
                  <label>Fecha 1:</label>

                  <div class="input-group">
                    <div class="input-group-prepend">
                      <span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
                    </div>
                    <input name="txt_fil_ven_fec1gra" type="text" id="txt_fil_ven_fec1gra" value="<?php echo $fec1gra?>" class="form-control" >
                  </div>
                </div>
				
				<div class=" col-lg-2 col-sm-6 col-xs-6 form-group">
                  <label>Fecha 2:</label>

                  <div class="input-group">
                    <div class="input-group-prepend">
                      <span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
                    </div>
                    <input name="txt_fil_ven_fec2gra" type="text" id="txt_fil_ven_fec2gra" value="<?php echo $fec2 ?>" class="form-control" >
                  </div>
                </div>

							<div class="col-lg-2 col-sm-6 col-sm-3 col-xs-6">				
								<label for="cmb_fil_puntoventa_idgra">Punto Venta:</label>
								<select name="cmb_fil_puntoventa_idgra" id="cmb_fil_puntoventa_idgra" class="form-control input-sm">
								</select>
													
							</div>
							
							<div class="col-lg-2 col-sm-6 col-xs-6">
								<label>Doc:</label>
								<select name="cmb_fil_doc_idgra" id="cmb_fil_doc_idgra" class="form-control input-sm"></select> 				
							</div>
							
							<div class="col-lg-2 col-sm-6 col-xs-6">
								<label>Serie/Numero:</label>
								<input type="text" id="txt_fil_docnumgra" name="txt_fil_docnumgra" class="form-control  input-sm" /> 
							</div>
													
							<div class="col-lg-2 col-sm-6 col-xs-6">
								<label for="cmb_fil_mon_idgra">Moneda:</label>
								<select name="cmb_fil_mon_idgra" id="cmb_fil_mon_idgra" class="form-control">
								<option selected value="1">SOLES</option>
								<option value="2">DOLARES AMERICANOS</option>
								</select>    
							</div>
							
							<div class="col-lg-4 col-sm-6 col-xs-6">
								<label>Cliente:</label>
								<input type="hidden" id="hdd_fil_cli_idgra" name="hdd_fil_cli_id" />
								<input type="text" id="txt_fil_cligra" name="txt_fil_cligra" class="form-control  input-sm" /> 
							</div>

							<!--
							<div class="col-lg-2 col-xs-6">
								<label>Mozo:</label>
								<select name="cmb_fil_moz_id" id="cmb_fil_moz_id" class="form-control"></select> 
							</div>
							-->
	
							<div class="col-lg-2 col-sm-6 col-xs-6">
								<label>Estado:</label>
								<select name="cmb_fil_ven_estgra" id="cmb_fil_ven_estgra" style="cursor:pointer;" class="form-control">
									<option value="">TODAS VENTAS</option>
									<option value="1" selected>REGISTRADA</option>
									<option value="2">ANULADA</option>
									<option value="3">FACTURADO/BOLETEADO</option>
								</select>
							</div>

							<div  class="col-lg-2 col-sm-5 col-xs-12" style="display: inline-block; white-space: nowrap;padding-top:30px;">								
									<span onClick="venta_grafica()" style="cursor:pointer" class="btn btn-info "><i class="fas fa-search"></i></span>									
									<span onClick="venta_filtro()" style="cursor:pointer" class="btn btn-default">RESTABLECER</span>																
							</div> 
							
							</div> 
							
						</form>	
						
					</div>
				
				
				
				</div>
			</div>
		</div>
	</div>
	</div>
</section>

<script type="text/javascript">


cmb_fil_puntoventa_id(<?php echo $punven_id; ?>);
cmb_fil_puntoventa_idgra(<?php echo $punven_id; ?>);

function cmb_fil_puntoventa_id(punven){
		$.ajax({
 					type: "POST",
 					url: "../puntoventa/cmb_punven_id.php",
 					async:true,
 					dataType: "html",                      
 					data: ({						
 						emp_id:'',
						punven_id :punven,
 						vista:	''
 					}),
 					beforeSend: function() {
 						$('#cmb_fil_puntoventa_id').html('<option value="">Cargando...</option>');
 					},
 					success: function(html){			
 						$('#cmb_fil_puntoventa_id').html(html);
 					},
 					complete: function(){
 						$('#txt_punven_id').val($('#cmb_fil_puntoventa_id').val());
 						}
 					});
}
function cmb_fil_puntoventa_idgra(punven){
		$.ajax({
 					type: "POST",
 					url: "../puntoventa/cmb_punven_id.php",
 					async:true,
 					dataType: "html",                      
 					data: ({						
 						emp_id:'',
						punven_id :punven,
 						vista:	''
 					}),
 					beforeSend: function() {
 						$('#cmb_fil_puntoventa_idgra').html('<option value="">Cargando...</option>');
 					},
 					success: function(html){			
 						$('#cmb_fil_puntoventa_idgra').html(html);
 					},
 					complete: function(){
 						
 						}
 					});
}

	
	
	function cmb_fil_doc_id()
	{	
		$.ajax({
			type: "POST",
			url: "../documento/cmb_doc_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				mod_id:	'3',
				nosel_def : true,
				vista:	'<?php echo $_POST['action']?>'
			}),
			beforeSend: function() {
				$('#cmb_fil_doc_id').html('<option value="">Cargando...</option>');
			},
			success: function(html){			
				$('#cmb_fil_doc_id').html(html);
			}
		});
	}

	
	function cmb_fil_doc_idgra()
	{	
		$.ajax({
			type: "POST",
			url: "../documento/cmb_doc_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				mod_id:	'3',
				nosel_def : true,
				vista:	'<?php echo $_POST['action']?>'
			}),
			beforeSend: function() {
				$('#cmb_fil_doc_idgra').html('<option value="">Cargando...</option>');
			},
			success: function(html){			
				$('#cmb_fil_doc_idgra').html(html);
			}
		});
	}

	function cmb_fil_mon_id(moneid)
	{	
		$.ajax({
			type: "POST",
			url: "../moneda/cmb_mon_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				mon_id: moneid
			}),
			beforeSend: function(){
				$('#cmb_fil_mon_id').html('<option value="">Cargando...</option>');
			},
			success: function(html){
				$('#cmb_fil_mon_id').html(html);
				venta_tabla();
			}
		});
	}
	
		
	$(function(){

	/* 	$('input').iCheck({
		checkboxClass: 'icheckbox_square-blue',
		radioClass: 'iradio_square-blue',
		increaseArea: '20%' 
		}); */

		
		
		
	cmb_fil_mon_id();
		
	$('#txt_fil_ven_fec1, #txt_fil_ven_fec2, #txt_fil_ven_fec2gra,#txt_fil_ven_fec1gra').datepicker({
			format: 'dd-mm-yyyy',
			autoclose:true
		}).on('changeDate', function(e){
			//venta_tabla();
		}); 
		
	cmb_fil_doc_id();
	cmb_fil_doc_idgra();


	$("#txt_fil_cli").autocomplete({
	minLength: 1,
	source: "../cliente/cliente_complete_nom.php",
	select: function(event, ui){
		$("#hdd_fil_cli_id").val(ui.item.id);		
		venta_tabla();		
		}
	});
	
	$("#txt_fil_cligra").autocomplete({
	minLength: 1,
	source: "../cliente/cliente_complete_nom.php",
	select: function(event, ui){
		$("#hdd_fil_cli_idgra").val(ui.item.id);		
		venta_grafica();		
		}
	});

	
	$("#txt_fil_cli").change(function(){
	var cli=$("#txt_fil_cli").val();
	if(cli=="")$("#hdd_fil_cli_id").val('');
	});
	
	
	$("#txt_fil_cligra").change(function(){
	var cli=$("#txt_fil_cligra").val();
	if(cli=="")$("#hdd_fil_cli_idgra").val('');
	});
	
	$('#cmb_fil_doc_id,#cmb_fil_doc_idgra, #cmb_fil_moz_id ,#cmb_fil_mon_id, #cmb_fil_mon_idgra , #txt_fil_docnum').change(function(e) {
	//venta_tabla();
	});
	
	$('#cmb_fil_ven_est').change(function(e) {
		venta_tabla();
	});
	
	$('#cmb_fil_ven_estgra').change(function(e) {
		venta_grafica();
	});

	$('#cmb_fil_empresa_id').change(function(e) {
	//cmb_punven_id($('#cmb_fil_empresa_id').val());
	});

	/* $('#cmb_fil_punven_id').change(function(e) {
	cmb_piso_id($('#cmb_fil_punven_id').val());
	}); */
	
	$("#txt_fil_cli").focus();

});	
</script>
