<?php

//ini_set('display_errors',1);

session_start();
if($_SESSION["sistema"]!= "1"){ header("location: ../login/index.php"); exit();}
date_default_timezone_set('America/Lima');
require_once ("../../config/Cado.php");
require_once ("../consumopagar/cConsumopagar.php");
	$oConsumopagar = new cConsumopagar();
require_once ("../producto/cCatalogo.php");
$oCatalogo = new cCatalogo();
require_once("../tipocambiotesoreria/cTipocambiotesoreria.php");
$oTipocambiotesoreria = new cTipocambiotesoreria();
require_once("../formatos/formato.php");
	unset($_SESSION['consumopagar_catid']);
	unset($_SESSION['consumopagar_marid']);
	unset($_SESSION['consumopagar_des']);
	unset($_SESSION['consumopagar_can']);
	unset($_SESSION['consumopagar_preven']);
	
	
	
	$dts = $oConsumopagar->mostrarUno($_POST['conpagid']);
	$dt = mysqli_fetch_array($dts);
	$reg = mostrarFechaHora($dt['tb_consumopagar_reg']);
	$fec = mostrarFecha($dt['tb_consumopagar_fec']);
	$doc_id	= $dt['tb_documento_id'];
	$numdoc	= $dt['tb_consumopagar_numdoc'];
	$cli_id	= $dt['tb_cliente_id'];
	$cli_nom = $dt['tb_cliente_nom'];
	$cli_doc = $dt['tb_cliente_doc'];
	$cli_dir = $dt['tb_cliente_dir'];
	$cli_tip = $dt['tb_cliente_tip'];
	$cli_pla = $dt['tb_cliente_pla'];
	$mec_id = $dt['tb_mecanico_id'];
	$mec_nom = $dt['tb_mecanico_nom'];
	$mon_id = $dt['tb_moneda_id'];
	$tipcam = $dt['tb_consumopagar_tipcam'];
	$valven	= $dt['tb_consumopagar_valven'];
	$igv	= $dt['tb_consumopagar_igv'];
	$tot	= $dt['tb_consumopagar_tot'];
	$est	= $dt['tb_consumopagar_est'];
	$dia	= $dt['tb_consumopagar_dia'];
	$edit	= $dt['tb_consumopagar_edi'];
	$estgenven	= $dt['tb_consumopagar_genven'];
	$punven_id	= $dt['punvenid'];
	$ven_nom	= $dt['tb_usuario_nom'];
	mysqli_free_result($dts);
	
	$fecha = date('Y-m-d');
	$rstes = $oTipocambiotesoreria->consultar($fecha);  
	$dttes = mysqli_fetch_array($rstes);
	$tipcamtes =  formato_money($dttes['tb_tipocambiotesoreria_val']);
	
	//echo '--'.$est;
	
	if($edit==1){
	?>
	
<div class="col-lg-12 col-sm-12 col-12"  >
	
	<div class="modal-header">		
		<h4 class="modal-title" id="titlemodal">ADVERTENCIA..! <?php echo $numdoc; ?></h4> 
		<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	</div>
	
	<div class="modal-body">
	<div class="row">
	<div class="col-12"> 
	<div class="col-lg-12 col-sm-12 col-12"> 
		<strong>ALGUIEN MAS ESTA VIENDO EL CONSUMO, NO PUEDE EDITAR NI HACER NINGUN CAMBIO...O ALGUIEN YA HIZO ALGUNA MODIFICACION.</strong>
	</div>	
	</div>
	</div>
	</div>	
	<div class="box-footer pull-right ">
		<span data-dismiss="modal" id="btn_cancelar" class="btn btn-default ">CANCELAR</span>				
	</div>
</div>
		
	
	<?php 	
	}else{
	
	if($est==1){
	//$oConsumopagar->modificar_campo($_POST['conpagid'],'edi','1');
	}
	
	$dtsc=$oConsumopagar->mostrarconsumopagardetalle($_POST['conpagid']);
	$num_rows= mysqli_num_rows($dtsc);
	
	
	while($dtc = mysqli_fetch_array($dtsc))
    {
		
		$dts1=$oCatalogo->mostrarUno($dtc['tb_catalogo_id'],$dtc['tb_marca_id']);
		$dt1 = mysqli_fetch_array($dts1);
		
		$_SESSION['consumopagar_catcod'][$dtc['tb_catalogo_id'].$dtc['tb_marca_id']]= $dtc['tb_catalogo_cod'];	
		$_SESSION['consumopagar_catid'][$dtc['tb_catalogo_id'].$dtc['tb_marca_id']]= $dtc['tb_catalogo_id'];	
		$_SESSION['consumopagar_marid'][$dtc['tb_catalogo_id'].$dtc['tb_marca_id']]= $dtc['tb_marca_id'];	
		$_SESSION['consumopagar_can'][$dtc['tb_catalogo_id'].$dtc['tb_marca_id']]= $dtc['tb_consumopagardetalle_can']*1;	
		$_SESSION['consumopagar_preven'][$dtc['tb_catalogo_id'].$dtc['tb_marca_id']]=($dtc['tb_consumopagardetalle_valuni']);	
		$_SESSION['consumopagar_des'][$dtc['tb_catalogo_id'].$dtc['tb_marca_id']]= $dtc['tb_consumopagardetalle_des'];	
	
	
	}
?>
<style type="text/css">
.ui-autocomplete
{
    z-index: 99999; 
}
</style>
<script type="text/javascript">
	/* function cmb_ven_id(idf){
		$.ajax({
			type: "POST",
			url: "../vendedor/cmb_ven_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				ven_id: idf	
			}),
			beforeSend: function() {
				$('#cmb_ven_id').html('<option value="">Cargando...</option>');
			},
			success: function(html){			
				$('#cmb_ven_id').html(html);
			},
			complete: function(){			
			}
		});
	} */
	
	
<?php if($est==1){
?>
<?php 
}else{
?>	
$("#cmb_ven_cli_dir,#cmb_ven_cli_vehi,#txt_cot_mec_nom,#txt_cot_dia_edi").attr('disabled','disabled');
<?php	
}?>	
	
	
	
function cargar_direcciones(idcli,dir){
		$.ajax({
 					type: "POST",
 					url: "../cliente/cmb_clidir_id.php",
 					async:true,
 					dataType: "html",                      
 					data: ({						
 						cli_id: idcli,
 						dir: dir,
 						vista:	''
 					}),
 					beforeSend: function() {
 						$('#cmb_ven_cli_dir').html('<option value="">Cargando...</option>');
 					},
 					success: function(html){			
 						$('#cmb_ven_cli_dir').html(html);
 					},
 					complete: function(){
 						
 						}
 					});
}
function cargar_vehiculos(idcli,veh){
	
		$.ajax({
 					type: "POST",
 					url: "../cliente/cmb_clivehi_id.php",
 					async:true,
 					dataType: "html",                      
 					data: ({						
 						cli_id: idcli,
 						veh: veh,
 						vista:	''
 					}),
 					beforeSend: function() {
 						$('#cmb_ven_cli_vehi').html('<option value="">Cargando...</option>');
 					},
 					success: function(html){			
 						$('#cmb_ven_cli_vehi').html(html);
 					},
 					complete: function(){
 						
 						}
 					});
}
	
function cmb_mone_id(moneid)
	{	
		$.ajax({
			type: "POST",
			url: "../moneda/cmb_mon_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				mon_id: moneid
			}),
			beforeSend: function(){
				$('#cmb_mone_id_vis').html('<option value="">Cargando...</option>');
			},
			success: function(html){
				$('#cmb_mone_id_vis').html(html);
				
			}
		});
	}
	
	function cmb_doc_id(idf){
		$.ajax({
			type: "POST",
			url: "../documento/cmb_doc_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				mod_id: '15',
				def : '0',
				doc_id: idf,
				vista:	''
			}),
			beforeSend: function() {
				$('#cmb_doc_id_vis').html('<option value="">Cargando...</option>');
			},
			success: function(html){			
				$('#cmb_doc_id_vis').html(html);
			},
			complete: function(){
			}
		});
	}
	function consumopagar_detalle_tabla_vis(conpagid,estgenven){
		
		<?php if($est==1){?>
		$.ajax({
			type: "POST",
			url: "../consumopagar/consumopagar_detalle_tabla_insertar_editar.php",
			async:true,
			dataType: "html",                      
			data: ({
				conpagid:	conpagid,
				estgenven:estgenven,
				est: <?php echo $est; ?>
			}),
			beforeSend: function() {
				$('#div_consumopagar_detalle_tabla_vis').addClass("ui-state-disabled");
			},
			success: function(html){
				$('#div_consumopagar_detalle_tabla_vis').html(html);
			},
			complete: function(){			
				$('#div_consumopagar_detalle_tabla_vis').removeClass("ui-state-disabled");
			}
		});  
		<?php }else{
		?>
		
		$.ajax({
			type: "POST",
			url: "../consumopagar/consumopagar_detalle_tabla_vista.php",
			async:true,
			dataType: "html",                      
			data: ({
				conpagid:	conpagid,
				estgenven:estgenven
			}),
			beforeSend: function() {
				$('#div_consumopagar_detalle_tabla_vis').addClass("ui-state-disabled");
			},
			success: function(html){
				$('#div_consumopagar_detalle_tabla_vis').html(html);
			},
			complete: function(){			
				$('#div_consumopagar_detalle_tabla_vis').removeClass("ui-state-disabled");
			}
		});  
		
		<?php 	
		}?>
		
	}
	$(function() {
		
		cargar_direcciones('<?php echo $cli_id?>','<?php echo $cli_dir?>');
		//cargar_vehiculos('<?php echo $cli_id?>','<?php echo $cli_pla?>');
			cmb_mone_id(<?php echo $mon_id?>);
			cmb_doc_id(<?php echo $doc_id?>);
			$("#txt_ven_numdoc_vis").addClass("ui-state-active");
			/* cmb_ven_id(<?php echo $ven_id?>); */
			
			consumopagar_detalle_tabla_vis('<?php echo $_POST["conpagid"]?>','<?php echo $estgenven; ?>');
			
			$("#btn_editarconsumo").hide(100);
			
			// $('#cmb_ven_est, #cmb_doc_id_vis, #cmb_ven_id,#cmb_mone_id_vis').attr('disabled','disabled');
			
		$('#div_consumopagar_form_dialog').keypress(function(e){
            if(e.which == 116){
                //  alert('Has pulsado enter!');
            }
		}); 
		
		
		$( "#txt_cot_mec_nom" ).autocomplete({
		minLength: 1,
		source: "../mecanico/mecanico_complete_nom.php",
		select: function(event, ui){			
			$("#hdd_cot_mec_id").val(ui.item.id);							
		}
	});
	
			
		});
	</script>
	<div class="col-lg-12 col-sm-12 col-12 "  >
	
	<div class="modal-header">		
		<h4 class="modal-title" id="titlemodal">Información del Consumo <?php if($estgenven==1){?> <strong style="margin-left:50px;" class="text-red">YA SE HA GENERADO EL DOCUMENTO</strong>  <?php }?></h4> 
		
		
		<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		
	</div>
	
	
	<div class="col-lg-12 col-sm-12 col-12 ">
	<div class="row">
	
	<input type="hidden" id="txt_mone_id" value="<?php echo $mon_id?>" />
	<input type="hidden" id="txt_puntoconsumopagar_id" value="<?php echo $punven_id?>" />
	<input type="hidden" id="txt_cot_fec" value="<?php echo $fec?>" />
	
	<div class="col-lg-4 col-sm-12 col-12 no-padding"> 
	
		<div class="box box-widget box-success">
			<div class="box-header with-border">
				<div class="user-block"> 
					<img class="img-circle" src="../../imagenes/users/user1.jpg" alt="User Image" title="">
					<span class="username text-dark"><a class="text-dark" title="DNI - RUC : <?php echo $cli_doc?>" href="javascript:void(0)"><?php echo "CLIENTE: ".$cli_nom;?></a></span>
				
					<strong class="description text-danger" style="color:#eee;" > <?php echo ' DOC: '.$cli_doc?></strong>
					<!--
					<span class="description"> <?php echo ' PLACA: '.$cli_pla?></span>
				-->	
					
					<!--
					<div class="col-lg-12 col-sm-12 col-12">
 						<div id="div_clientecuenta_detalle"></div>
 						<label for="cmb_ven_cli_vehi">Vehiculo:</label>
						<select name="cmb_ven_cli_vehi" id="cmb_ven_cli_vehi" class="form-control" >
						<option value="">-</option>
						</select>
					</div>	
					-->
				
				</div>	

					
					
			</div>
		</div>
		</div>
		
			
			<div class="col-lg-2 col-sm-2 col-6 d-none ">
 						<label for="cmb_ven_cli_dir">Dirección:</label>
 						<select name="cmb_ven_cli_dir" id="cmb_ven_cli_dir" class="form-control" >
						<option value="">-</option>
						</select>						   
 					</div>
					
			<div class="col-lg-2 col-sm-2 col-6 "> 
				<label for="txt_cot_dia_edi">Dias:</label>
				<input type="text" value="<?php echo $dia ?>" autocomplete="off" class="form-control input-sm" name="txt_cot_dia_edi" id="txt_cot_dia_edi" />
			</div>
			
			<div class="col-lg-2 col-sm-2 col-6 "> 
				<label for="txt_ven_fec_vis">Fecha:</label>
				<input title="FECHA DE REGISTRO : <?php echo "$reg";  ?>" 
				name="txt_ven_fec_vis" type="text" class=" form-control input-sm fecha" id="txt_ven_fec_vis" readonly value="<?php echo $fec?>" size="10"  maxlength="10" readonly>
			</div>
			
			<div class="col-lg-2 col-sm-2 col-6 "> 
				<label for="txt_ven_numdoc_vis">N° Doc:</label>
				<input style="font-weight: bold" name="txt_ven_numdoc_vis" readonly type="text" id="txt_ven_numdoc_vis"   value="<?php echo $numdoc?>"  readonly class=" form-control input-sm text-orange">
			</div>
			<div class="col-lg-2 col-sm-2 col-6 d-none">
				<label for="cmb_mone_id_vis">Moneda:</label>
				<select   name="cmb_mone_id_vis" id="cmb_mone_id_vis" readonly class="form-control input-sm"></select>
			</div>
			
			
			
		
		<!--	
			<div class="col-lg-12 col-sm-12 col-12">
 				<div id="div_clientecuenta_detalle"></div>
 				<label for="txt_cot_mec_nom">Taller/Mec.:</label>
	<input name="txt_cot_mec_nom" id="txt_cot_mec_nom" class="form-control" value="<?php echo $mec_nom?>"/>
				<input type="hidden" id="hdd_cot_mec_id" name="hdd_cot_mec_id" value="<?php echo $mec_id?>" />							 
 			</div>
		-->		
				
						
		<div class="col-lg-12 col-sm-12 col-12" style="height:15px;"></div>
		
		<?php if($estgenven!=1){?>
		
 				<div id="fieldset_producto" style="position:relative" class="col-lg-12 col-md-12 col-12 " >
 									<div class="box box-default box-solid box-primary ">
 										<div class="box-body">
 											<div class="row">
 												<div class="col-lg-1 col-sm-3 col-6">
 													<label for="cmb_forpaf_id" style="color:#00ACC1" >COD. BAR.:</label> 
														
 														<input name="txt_bus_pro_codbar_edi" autocomplete="off"  type="text" id="txt_bus_pro_codbar_edi" class="form-control" >
 														<input name="hdd_com_numite" id="hdd_com_numite" type="hidden">
 												</div>
												
 												<div class="col-lg-1 col-sm-3 col-6 d-none">
													<label for="txt_bus_pro_cod">Codigo:</label>
													<input name="txt_bus_pro_cod" type="text" autocomplete="off"  id="txt_bus_pro_cod"  class="form-control" >	
												</div>
													
												<div class="col-lg-2 col-sm-3 col-6">
								<label for="txt_fil_pro_dat1_edi">Busqueda:</label>
								<input name="txt_fil_pro_dat1_edi" type="text" id="txt_fil_pro_dat1_edi" autocomplete="off" class="form-control">
												</div>
							
							<div class="col-lg-2 col-sm-3 col-6">
								<label for="txt_fil_pro_dat2_edi">-</label>
								<input name="txt_fil_pro_dat2_edi" type="text" id="txt_fil_pro_dat2_edi" autocomplete="off"  class="form-control">
							</div>
							
							<div class="col-lg-2 col-sm-3 col-6">
								<label for="txt_fil_pro_dat3_edi">-</label>
								<input name="txt_fil_pro_dat3_edi" type="text" id="txt_fil_pro_dat3_edi" autocomplete="off"  class="form-control">
							</div>
							
							<div class="col-lg-2 col-sm-3 col-6">
								<label for="txt_fil_pro_dat4_edi">-</label>
								<input name="txt_fil_pro_dat4_edi" type="text" id="txt_fil_pro_dat4_edi" autocomplete="off"  class="form-control">
							</div>
							
													<div style="display: inline-block; white-space: nowrap;padding-top: 30px;" class="col-lg-2 col-sm-3 col-12 d-none">
														<div class="btn-group">
															<a title="Restablecer consumopagar" onClick="agregar_producto('restablecer');" id="btn_rest_car" class="btn btn-primary" href="javascript:void(0)"><i class="fa fa-retweet"></i> </a>
															<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
																<span class="caret"></span>														
															</button>
															<ul class="dropdown-menu" role="menu">
																<li><a onClick="agregar_producto_lista();" href="javascript:void(0)"> <i class="fa fa-filter"></i> Seleccionar productos</a></li>
															<!--	<li><a onClick="producto_form('insertar')" href="javascript:void(0)"><i class="fa fa-plus"></i> Nuevo Producto</a></li> -->
															</ul>
														</div> 
													</div>
													
 												
 													
 												</div> 
 											</div>
 										</div>
 									</div>
								
		
		<?php } ?>
		
			<div class="col-lg-12 col-sm-12 col-12" style="height:20px;"></div>
			<div class="col-lg-12 col-sm-12 col-12"> 
			
				<div id="div_consumopagar_detalle_tabla_vis"></div>
			</div>
	
		
		<input name="action_consumopagar_vis" id="action_consumopagar_vis" type="hidden" value="<?php echo $_POST['action']?>">
  
	</div>	
	</div>	
	

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




cmb_puntoconsumopagar_id('<?php echo $punven_id;?>');




$("#cmb_puntoconsumopagar_id,#txt_ven_fec_vis,#cmb_mone_id_vis").attr('disabled','disabled');

$("#txt_bus_pro_cod").keydown(function(e){
			if (e.which == 13){
			
			agregar_producto_lista('','','','');
				return false;
			}
		});
$('#txt_bus_pro_cod').change(function()
{
	$(this).val($(this).val().toUpperCase());
});
	
	
		$("#txt_bus_pro_codbar_edi").keydown(function(e){
			if (e.which == 13){
			
			buscar_producto($("#txt_bus_pro_codbar_edi").val());
				return false;
			}
		});
	
	
		$( "#txt_fil_pro_dat1_edi" ).keydown(function(e){
			if(e.which==32)
			{
				$( "#txt_fil_pro_dat2_edi" ).focus();
				//producto_tabla();
				//e.preventDefault();
			}
		});
		$( "#txt_fil_pro_dat2_edi" ).keydown(function(e){
			if(e.which==32)
			{
				$( "#txt_fil_pro_dat3_edi" ).focus();
				//producto_tabla();
				//e.preventDefault();
			}
		});
		$( "#txt_fil_pro_dat3_edi" ).keydown(function(e){
			if(e.which==32)
			{
				$( "#txt_fil_pro_dat4_edi" ).focus();
				//producto_tabla();
				//e.preventDefault();
			}
		});
		
		$( "#txt_fil_pro_dat1_edi" ).keydown(function(e){
			if(e.which==13)
			{
				
				agregar_producto_lista('','','','');
				return false;
			
			}
		});
		
			$( "#txt_fil_pro_dat2_edi" ).keydown(function(e){
			if(e.which==13)
			{
				
				agregar_producto_lista('','','','');
				return false;
			}
		});
		
		
			$( "#txt_fil_pro_dat3_edi" ).keydown(function(e){
			if(e.which==13)
			{
				
				agregar_producto_lista('','','','');
				return false;
			
			}
		});
		
		$( "#txt_fil_pro_dat4_edi" ).keydown(function(e){
			if(e.which==13)
			{
			agregar_producto_lista('','','','');
			return false;
			}
		});
		
		
		
		$("#txt_fil_pro_dat4_edi").keydown(function(e){
			if(e.which==8)
			{
				if($("#txt_fil_pro_dat4_edi").val()==""){
					$("#txt_fil_pro_dat3_edi").focus();
				}	
					
			}
		});
		
		
		$("#txt_fil_pro_dat3_edi").keydown(function(e){
			if(e.which==8)
			{
				if($("#txt_fil_pro_dat3_edi").val()==""){
					$("#txt_fil_pro_dat2_edi").focus();
				}	
					
			}
		});
		
		
		$("#txt_fil_pro_dat2_edi").keydown(function(e){
			if(e.which==8)
			{
				if($("#txt_fil_pro_dat2_edi").val()==""){
					$("#txt_fil_pro_dat1_edi").focus();
				}	
					
			}
		});
		
	
function cmb_puntoconsumopagar_id(punven_id){
		$.ajax({
 					type: "POST",
 					url: "../puntoventa/cmb_punven_id.php",
 					async:true,
 					dataType: "html",                      
 					data: ({						
 						emp_id:'',
						punven_id : punven_id,
 						vista:	''
 					}),
 					beforeSend: function() {
 						$('#cmb_puntoconsumopagar_id').html('<option value="">Cargando...</option>');
 					},
 					success: function(html){			
 						$('#cmb_puntoconsumopagar_id').html(html);
 					},
 					complete: function(){
 						
 						}
 					});
}
	
	function guardarcoti(act,valven,igv,tot){
		
		// alert($("#txt_ven_tot_vis").val());
		// alert(conpagid);
		$('#div_mensaje_dialog').modal();
		$.ajax({
				type: "POST",
				url: "../consumopagar/consumopagar_reg.php",
				async:true,
				dataType: "json",                      
				data: ({
					action:act,
					valven:valven,
					igv:igv,
					tot:tot,
					conpagid:<?php echo $_POST['conpagid']; ?>,
					dia: $("#txt_cot_dia_edi").val()
					//clidir: $("#cmb_ven_cli_dir").val()
				}),
				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_mensaje').html(div);
					
				},
				success: function(data){
					
					if(data.conpag_act==1){
						//consumopagar_ticket_datos(data.conpagid);
					}
					
					toastr["info"](data.msj);
					//generar_pdf(data.conpagid);
					consumopagar_tabla();	
							
					$('.modal').modal('hide');
					$('.in').removeClass('modal-backdrop');
				
				//abrirEnPestana('="../../../../files/consumopagar/consumopagar_imp_doc.php?conpagid='+data.conpagid);
					
					
				}
			});
		
	}
	
	
	
	
	function abrirEnPestana(url) {
		var a = document.createElement("a");
		a.target = "_blank";
		a.href = url;
		a.click();
	}
	
	
	
 function buscar_producto(codbar){
	 if(codbar!=""){
		 
		$('#div_mensaje_dialog').modal('show');
	$.ajax({
			type: "POST",
			url: "../producto/producto_codbar_data.php",
			async:true,
			dataType: "json",                      
			data: ({
				codbar: codbar
			}),
			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_mensaje').html(div);
			},
			success: function(data){
			if(data.est=='1'){
				
				agregar_producto('agregaritem',data.catid,data.can,'',data.marid,'');
				
			}else{
			toastr["error"]('No existe ningun porducto con ese COD. BAR.');	
			}
			
			$('#div_mensaje_dialog').modal('hide');
				
			}
		});
	 
	}else{
		toastr["error"]('Ingrese un codigo de barras.');	
	}
 
 }
    

	
	
function agregar_producto(act,idf, cantidad, preven, marid, conpagdet_id)
{
	//if(!( idf>0 )) idf = $('#hdd_bus_cat_id').val();	

	if(act=='quitaritem'){
		
	}else if(act=='actualizaritem'){
		
	}else{
		act = 'agregaritem';
	}
	
	$.ajax({
		type: "POST",
		url: "../consumopagar/consumopagar_reg.php",
		async:true,
		dataType: "json",                      
		data: ({
			action:act ,
			cat_id:	idf,
			cat_can: cantidad || $('#txt_bus_cat_can').val(),
			cat_preven: preven || $('#txt_bus_cat_preven').val(),
			mar_id: marid,	
			conpagdet_id: conpagdet_id,	
			conpagid: <?php echo $_POST['conpagid']; ?>
		}),
		beforeSend: function() {
		},
		success: function(data){
			
			if(data.est==false)
			{				
				if(data.dat.tipo=="preven")
				{
					limpiar_campos();
					consumopagar_detalle_tabla_vis('<?php echo $_POST["conpagid"]?>');
					toastr["warning"](data.msj);
				}
			}
		},
		complete: function(data)
		{
			var dat=JSON.parse(data.responseText);
			if(dat.est==true)
			{
				if(dat.dat.tipo=="agregado")
				{
					limpiar_campos();
				}
				
				if(dat.dat.tipo=="foco")
				{
					limpiar_campos();
				}
				consumopagar_detalle_tabla_vis('<?php echo $_POST["conpagid"]?>');
				$('#btn_editarconsumo').show(100);
			}
		}
	});
}
	
	
	
	
	
	
function limpiar_campos()
{
	
	$("#txt_bus_pro_codbar_edi").val('');
	$("#txt_bus_pro_cod").val('');
	$("#txt_fil_pro_dat1_edi").val('');
	$("#txt_fil_pro_dat2_edi").val('');
	$("#txt_fil_pro_dat3_edi").val('');
	$("#txt_fil_pro_dat4_edi").val('');
	$("#txt_bus_pro_cod").focus();
}
	
	
	function agregar_producto_lista(codmar,dat1,dat2,dat3,dat4,punven_id){
			$('#div_productomarca_form_dialog').modal();
		//$('body').css('overflow-y','hidden');
		
		
		$.ajax({
				type: "POST",
				url: "../compra/seleccionarproducto.php",
				async:true,
				dataType: "html",                      
				data: ({
					codmar:codmar || $("#txt_bus_pro_cod").val(),
					dat1:dat1 || $("#txt_fil_pro_dat1_edi").val(),
					dat2:dat2 || $("#txt_fil_pro_dat2_edi").val(),
					dat3:dat3 || $("#txt_fil_pro_dat3_edi").val(),
					dat4:dat4 || $("#txt_fil_pro_dat4_edi").val(),
					punven_id:punven_id || $("#txt_puntoconsumopagar_id").val(),
					vista:'consumopagar_form'
				}),
				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_productomarca_form').html(div);
				},
				success: function(html){
					$('.div_productomarca_form').html(html);				
				}
			});
		
		/* 
			$.ajax({
				type: "POST",
				url: "../compra/seleccionarproducto.php",
				async:true,
				dataType: "html",                      
				data: ({
					codmar:codmar || $("#txt_bus_pro_cod").val(),
					dat1:dat1 || $("#txt_fil_pro_dat1_edi").val(),
					dat2:dat2 || $("#txt_fil_pro_dat2_edi").val(),
					dat3:dat3 || $("#txt_fil_pro_dat3_edi").val(),
					dat4:dat4 || $("#txt_fil_pro_dat4_edi").val(),
					vista:'consumopagar_form',
					conpagid:<?php echo $_POST['conpagid']; ?>
				}),
				beforeSend: function() {
					var div = "<center><div class='overlay col-lg-12 col-sm-12 col-12' style='background-color:#fff;padding:0%;font-size:3rem;' >  <i class='fa fa-refresh fa-spin ' ></i> </div>  </center>";	
					$('.div_productomarca_form').html(div);
				},
				success: function(html){
					$('.div_productomarca_form').html(html);				
				}
			}); */
		}
	
</script>		
	<?php 
	}		
	?>
		
		