<?php
date_default_timezone_set('America/Lima');
session_start();

$y=date('Y');
$m=date('m');
$d=date('d');

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



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

require_once("../formatos/formato.php");

?>

<section class="content">
	<div class="container-fluid">
	<div class="row">
	    <div class="col-lg-12 col-md-12 col-sm-12 col-12">
		    <div class="card">
		        <div class="card-header">
    		<div class="row">
						
				<form name="for_fil_com" id="for_fil_com" target="_blank" action="compra_reporte.php" method="post">
												
				<div class="row">
					
				<div class=" col-lg-2 col-6 form-group">
                  <label>Desde:</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_com_fec1" type="text" id="txt_fil_com_fec1" value="<?php echo $fec1?>" class="form-control" >
                  </div>
                </div>
				
				
				<div class=" col-lg-2 col-6 form-group">
                  <label>Hasta:</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_com_fec2" type="text" id="txt_fil_com_fec2" value="<?php echo $fec2?>" class="form-control" >
                  </div>
                </div>
				
										
							<div class="col-lg-2  col-sm-3 col-6">
								<label for="cmb_fil_usuario_id">Usuario:</label>
								<select name="cmb_fil_usuario_id" id="cmb_fil_usuario_id" class="form-control">
								<option value=""></option>
								</select>
							</div>
							
							<div class="col-lg-2  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 ">
								</select>									
							</div>
							
							<div class="col-lg-2 col-6">
								<label for="cmb_fil_mon_id">Moneda:</label>
								<select name="cmb_fil_mon_id" id="cmb_fil_mon_id" class="form-control">
								</select>    
							</div>							

							<div style="display: inline-block; white-space: nowrap;padding-top: 30px;" class="col-lg-2 col-sm-3 col-6">		
								<span onClick="ventageneral_cst_tabla()" id="btn_filtrar" style="cursor:pointer" class="btn btn-info "><i class="fas fa-search"></i></span>
								<span onClick="ventageneral_cst_filtro()" id="btn_resfil"  style="cursor:pointer" class="btn btn-default ">Restablecer</span>
							</div>   
							</div>   
						</form>	
						
					</div>
				</div>
			</div>
		</div>
	</div>
	</div>
</section>

<script type="text/javascript">
	cmb_usuario_id();
	cmb_fil_mon_id('1');
	
	 function cmb_usuario_id(usuid){
	
	  	$.ajax({
			type: "POST",
			url: "../usuario/cmb_usu_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				usu_id:usuid
			}),
			beforeSend: function() {
				$('#cmb_fil_usuario_id').html('<option value="">Cargando...</option>');
			},
			success: function(html){	
			
				$('#cmb_fil_usuario_id').html(html);
								
			}
		});		
  
  }

cmb_fil_puntoventa_id(<?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_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);
			}
		});
	}
	$(function(){
				
		$('#txt_fil_com_fec1, #txt_fil_com_fec2').datepicker({
			format: 'dd-mm-yyyy',
			autoclose:true
		}).on('changeDate', function(e){
			//compra_tabla();
		}); 

		$("#cmb_fil_mon_id").change(function(){
			ventageneral_cst_tabla();
		});
		
		ventageneral_cst_tabla();
		
	});	
</script> 