<?php
 // ini_set('display_erros',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 ("cOrdencompra.php");
$oOrdencompra = new cOrdencompra();

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

if($_POST['action']=="insertar")
{
	$fec=date('d-m-Y');
	$fecguia=date('d-m-Y');
	$m=date('m');
	$y=date('Y');
	$emp_id=''; //$_SESSION['empresa_id'];
	$punven_id=$_SESSION['puntoventa_id'];
	$caj_id=$_SESSION['caja_id'];
	$est="1";
	//$pro_id	=1;
	$mon_id	='';
	$com_id	='';
	$doc_id	='32';
	$tippro = 1;
	$tot = 0;
	$ordcom_est = 1;
}

if($_POST['action']=="editar")
{
	$dts= $oOrdencompra->mostrarUno($_POST['ordcom_id']);
	$dt = mysqli_fetch_array($dts);
	$fec	=mostrarFecha($dt['tb_ordencompra_fec']);
	$numdoc	=$dt['tb_ordencompra_numdoc'];
	$pro_doc=$dt['tb_proveedor_doc'];
	$pro_nom=$dt['tb_proveedor_nom'];
	$pro_id=$dt['tb_proveedor_id'];
	$emp_id=$dt['tb_empresa_id'];
	$ordcom_est=$dt['tb_ordencompra_est'];
	
	
}


// echo $_POST['vista'];

?>
<style type="text/css">
.ui-autocomplete
{
    z-index: 99999; 
}
</style>
			<div class="col-lg-12 col-md-12 col-12 " >
					<form  id="for_ordcom"  > 
						<input name="action" id="action" type="hidden" value="<?php echo $_POST['action']?>">
						<input name="hdd_ordcom_id" id="hdd_ordcom_id" type="hidden" value="<?php echo $_POST['ordcom_id']?>">
						<input name="hdd_usu_id" id="hdd_usu_id" type="hidden" value="<?php echo $_SESSION['usuario_id']?>">
						<input name="hdd_emp_id" id="hdd_emp_id" type="hidden" value="<?php echo $_SESSION['empresa_id']?>">
						
						<div class="box-header with-border">
							<h3 class="box-title">Registrar Orden de compra</h3>			
						</div>
						
						<div class="row">
							
						<div class="col-lg-7 col-md-12 col-12 "> 
							
					
										<div class="row">


										
										<?php if($ordcom_est=="1"){?>
											<div class="col-lg-5 col-sm-4 col-6 errorprov ">
												<label for="txt_ordcom_pro_doc">RUC/DNI:</label>
												<div class="input-group">
													<div class="input-group-btn">
														<button type="button" class="btn btn-warning dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><i class="fa fa-cog"></i>
															</button>
															<ul class="dropdown-menu">

																<?php if($_POST['action']=='insertar'){?>
																<a class="dropdown-item  " onClick="proveedor_form('insertar')" href="javascript:void(0)"><i class="fa fa-plus"></i> Agregar Proveedor</a>
																<?php }?>
																 
															</ul>
														</div>
														<input type="text" class="form-control" id="txt_ordcom_pro_doc" name="txt_ordcom_pro_doc" autocomplete="off" value="<?php echo $pro_doc?>" /> 
													</div>
												</div>
										<?php }else{
											?>
											
											<div class="col-lg-5 col-sm-8 col-4">
													<label for="txt_ordcom_pro_doc">RUC/DNI:</label>
													<input type="text" autocomplete="off" id="txt_ordcom_pro_doc" class="form-control " name="txt_ordcom_pro_doc"  value="<?php echo $pro_doc?>" /> 
													
												</div> 
											
											
											<?php 
										}?>
												<div class="col-lg-5 col-sm-8 col-6">
													<label for="txt_ordcom_pro_nom">Proveedor:</label>
													<input type="text" autocomplete="off" id="txt_ordcom_pro_nom" class="form-control " name="txt_ordcom_pro_nom"  value="<?php echo $pro_nom?>" /> 
													<input type="hidden"   id="hdd_ordcom_pro_id" name="hdd_ordcom_pro_id" value="<?php echo $pro_id?>" />
												</div> 
												
											</div>
											
										
							
						</div>
											
						<div class="col-lg-5 col-md-12 col-12">
								<div class="nav-tabs-custom">
									
									<div class="tab-content">
										<div class="active tab-pane" id="tab_3">
											<div class="row">

												<div class="col-lg-4 col-sm-3 col-6 ">
													<label for="txt_ordcom_numdoc">Num. Doc.:</label>
													<input  class="form-control text-orange" style="text-align:right; font-size:14px" 
													type="text" name="txt_ordcom_numdoc" id="txt_ordcom_numdoc"  value="<?php echo $numdoc?>" readonly >
												</div> 
												
												<div class="col-lg-4  col-ms-3 col-6">
													<label>Empresa:</label>
													<select name="cmb_empresa_id" id="cmb_empresa_id" class="form-control input-sm"  ></select>
												</div>	
										
												<div class="col-lg-4 col-sm-3 col-6">
													<label for="txt_ordcom_fec">Fecha:</label>
													<input  name="txt_ordcom_fec" type="text"  class="form-control"  id="txt_ordcom_fec" value="<?php echo $fec?>"  maxlength="10">
												</div>

																				
											</div> 
										</div>

									</div>
								</div>  
						</div>
						
						
						<div class="col-lg-12 col-md-12 col-12" style="height:10px;"></div>
						
						<?php if($ordcom_est=="1"){?>
						
						<div id="fieldset_producto" style="position: relative;" class="col-lg-12 col-md-12 col-12 d-none ">
 									<div class="box box-default box-solid box-primary ">
 										<div class="box-body">
 											<div class="row">

 										<div class="col-lg-1 col-sm-4 col-6 d-none">
												<label for="txt_bus_pro_codbar" class="text-red" >COD. BAR.:</label> 
												<input name="txt_bus_pro_codbar" type="text" autocomplete="off" id="txt_bus_pro_codbar" autofocus class="form-control form-control-sm " >
 												<input name="hdd_com_numite" id="hdd_com_numite" type="hidden">
 										</div>

 											<div class="col-lg-1 col-sm-5 col-6">
												<label for="txt_bus_pro_cod">Codigo:</label>
												<input name="txt_bus_pro_cod" autocomplete="off" style="padding:5px;" type="text" id="txt_bus_pro_cod"  class="form-control form-control-sm" >	
											</div>
												
										<div class="col-lg-1 col-sm-5 col-6">
											<label for="txt_bus_pro_mar">Marca:</label>
											<input name="txt_bus_pro_mar" autocomplete="off" style="padding:5px;" type="text" id="txt_bus_pro_mar"  class="form-control form-control-sm" >	
										</div>
													
							<div class="col-lg-2 col-sm-3 col-6">
								<label for="txt_fil_pro_dat1">Busqueda:</label>
								<input name="txt_fil_pro_dat1" autocomplete="off" style="padding:5px;" type="text" id="txt_fil_pro_dat1" class="form-control form-control-sm">
							</div>
							
							<div class="col-lg-2 col-sm-3 col-6">
								<label for="txt_fil_pro_dat2">-</label>
								<input name="txt_fil_pro_dat2" autocomplete="off" style="padding:5px;" type="text" id="txt_fil_pro_dat2"  class="form-control form-control-sm ">
							</div>
							
							<div class="col-lg-2 col-sm-3 col-6">
								<label for="txt_fil_pro_dat3">-</label>
								<input name="txt_fil_pro_dat3" autocomplete="off" style="padding:5px;" type="text" id="txt_fil_pro_dat3"  class="form-control form-control-sm ">
							</div>
							
							<div class="col-lg-1 col-sm-3 col-6 d-none">
								<label for="txt_fil_pro_med">Medida</label>
								<input name="txt_fil_pro_med" autocomplete="off" style="padding:5px;" type="text" id="txt_fil_pro_med"  class="form-control form-control-sm ">
							</div>
							
							<div class="col-lg-1 col-sm-3 col-6 d-none ">
								<label for="txt_fil_pro_mod">Modelo</label>
								<input name="txt_fil_pro_mod" autocomplete="off" style="padding:5px;" type="text" id="txt_fil_pro_mod"  class="form-control form-control-sm ">
							</div>
							
							<div class="col-lg-1 col-sm-3 col-6 d-none ">
								<label for="txt_fil_pro_mot">Motor</label>
								<input name="txt_fil_pro_mot" autocomplete="off" style="padding:5px;" type="text" id="txt_fil_pro_mot"  class="form-control form-control-sm ">
							</div>
							
							<div class="col-lg-1 col-sm-3 col-6 d-none">
								<label for="txt_fil_pro_int">Interno</label>
								<input name="txt_fil_pro_int" autocomplete="off" style="padding:5px;" type="text" id="txt_fil_pro_int"  class="form-control form-control-sm ">
							</div>
							
 								</div>
 							</div>
 						</div>
 					</div>
							
						<?php }?>
						  
						<div class="col-lg-12 col-md-12 col-12" style="height:10px;"></div>
						<div class="col-lg-12 col-md-12 col-12">
							<div id="div_ordencompra_detalle_tabla"></div>
						</div> 									 
																	 
						<input type="hidden"  id="txt_ordcom_tipcam_uno" />
						
						</div> 
						</form> 
						

				<div class="box-footer float-right ">
				<span  data-dismiss="modal" class="btn btn-default cancel">Cancelar</span>
				<?php if($ordcom_est=="1"){?>
				<span class="btn btn-primary" id="save_form">Guardar</span>
				<?php }?>
				</div>
				
				
			</div>
						
<script type="text/javascript">
									
			
		
	$('#txt_ordcom_fec').datepicker({
 				format: 'dd-mm-yyyy',
 				autoclose:true			
	});
	
	
	
	
	
		
	function agregar_producto_lista(codmar,dat1,dat2,dat3,dat4,mar,med,mod,mot,inte){
		
		if($("#cmb_puntoventa_id").val()==''){
				
				toastr["info"]('Seleccione un punto de venta.');
				
			}else{
			}
				
				
			$('#div_productomarca_form_dialog').modal();
			$('body').css('overflow-y','hidden');
		
		var punven = $("#cmb_puntoventa_id").val();
		 //alert(punven);
		
		
			$.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").val(),
					dat2:dat2 || $("#txt_fil_pro_dat2").val(),
					dat3:dat3 || $("#txt_fil_pro_dat3").val(),
					dat4:dat4 || $("#txt_fil_pro_dat4").val(),
					mar:mar || $("#txt_bus_pro_mar").val(),
					med:med || $("#txt_fil_pro_med").val(),
					mod:mod || $("#txt_fil_pro_mod").val(),
					mot:mot || $("#txt_fil_pro_mot").val(),
					inte:inte || $("#txt_fil_pro_int").val(),
					punven_id : punven,
					vista:'compra_form',
					tipart:'1'
				}),
				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);				
				}
			});
	
	}
		
 	
	
function agregar_producto(act,cat_id, cantidad,precom,mar_id, des, tipdes)
{

	$.ajax({
		type: "POST",
		url: "../ordencompra/ordencompra_reg.php",
		async:true,
		dataType: "json",                  
		data: ({
			action:	 act,
			cat_id:	 cat_id,
			ordcom_id: $('#hdd_ordcom_id').val(),
			cat_can: cantidad ,
			cat_precom: precom,
			mar_id : mar_id
			
		}),
		beforeSend: function() {

		},
		success: function(data){
			if(data.ordcom_est==1)
			{
				toastr["info"](data.ordcom_msj);
				ordencompra_detalle_tabla_editar(<?php echo $_POST['ordcom_id']?>);
			}else{
				toastr["danger"](data.ordcom_msj);
			}
		},
		complete: function(data)
		{
			
		}
	});  
}

	

function agregar_pedidocompra_editar(act,ordcomdet_id,can){
		$.ajax({
			type: "POST",
			url: "../ordencompra/ordencompra_reg.php",
			async:true,
			dataType: "json",                      
			data: ({
				action: act,
				can : can,
				ordcomdet_id : ordcomdet_id,
				vista:	'ordencompra_form'
			}),
			beforeSend: function() {
				
			},
			success: function(data){
				toastr["info"](data.ordcom_msj);
				
			},
			complete: function(){
				ordencompra_detalle_tabla_editar(<?php echo $_POST['ordcom_id']?>);
			}
		});
	}


function ordencompra_detalle_tabla()
	{
	
	$.ajax({
		type: "POST",
		url: "../ordencompra/ordencompra_tabladetalle_insertar.php",
		async:true,
		dataType: "html",                      
		data: ({
			vista : 'stockgeneral_form'
		}),
		beforeSend: function() {

			$('#div_ordencompra_detalle_tabla').addClass("ui-state-disabled");
        },
		success: function(html){
			$('#div_ordencompra_detalle_tabla').html(html);
		},
		complete: function(){
			$('#div_ordencompra_detalle_tabla').removeClass("ui-state-disabled");			
		}
	});    
	}	


function ordencompra_detalle_tabla_editar(ordcom_id)
	{
	
	$.ajax({
		type: "POST",
		url: "../ordencompra/ordencompra_tabladetalle_editar.php",
		async:true,
		dataType: "html",                      
		data: ({
			vista : 'ordencompra_form',
			ordcom_id : ordcom_id
		}),
		beforeSend: function() {

			$('#div_ordencompra_detalle_tabla').addClass("ui-state-disabled");
        },
		success: function(html){
			$('#div_ordencompra_detalle_tabla').html(html);
		},
		complete: function(){
			$('#div_ordencompra_detalle_tabla').removeClass("ui-state-disabled");			
		}
	});    
	}	

function txt_ordcom_numdoc()
 	{
 				$.ajax({
 					type: "POST",
 					url: "../venta/venta_txt_numdoc.php",
 					async:false,
 					dataType: "json",                      
 					data: ({
 						doc_id: '32',
 						punven_id: '<?php echo $punven_id; ?>'
 					}),
 					beforeSend: function() {
 						$('#txt_ordcom_numdoc').val('Cargando...');
 					},
 					success: function(data){			
 						$('#txt_ordcom_numdoc').val(data.numero);

 						if(data.msj!="")
 						{
							toastr["success"](data.msj);
 						}
 						else
 						{
 						}
 					},
 					complete: function(){
 							verificar_numdoc();							
 						}
 					});
 	}
		
function verificar_numdoc(){	
	$.ajax({
		type: "POST",
		url: "../venta/venta_ver_serie.php",
		async:false,
		dataType: "json",                      
		data: ({
			doc_id: $('#cmb_doc_id').val(),
			numdoc: $('#txt_ordcom_numdoc').val(),
			ven_est: $('#cmb_ven_est').val()
		}),
		beforeSend: function() {

		},
		success: function(data){			
			$('#hdd_ven_doc').val(data.valor);

			if(data.msj!="")
			{			
			toastr["info"](data.msj);					
			}
		}
	});
}
	
function cmb_empresa_id(empid){
	
	  	$.ajax({
			type: "POST",
			url: "../empresa/cmb_emp_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				emp_id:empid
			}),
			beforeSend: function() {
				$('#cmb_empresa_id').html('<option value="">Cargando...</option>');
			},
			success: function(html){	
			
				$('#cmb_empresa_id').html(html);
				//alert($('#cmb_empresa_id').val());
				
				
			}
		});		
  
  }
  
function proveedor_form(act,idf){
	$('#div_proveedor_form_dialog').modal();
		
	$.ajax({
		type: "POST",
		url: "../proveedor/proveedor_form.php",
		async:true,
		dataType: "html",                      
		data: ({
			action: act,
			pro_id:	idf,
			vista:	'compra'
		}),
		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_proveedor_form').html(div); 
		},
		success: function(html){ 	
			$('.div_proveedor_form').html(html); 				
		},
		complete: function(){
				
				
		}
	});
}

function proveedor_cargar_datos(idf){
		$.ajax({
			type: "POST",
			url: "../proveedor/proveedor_reg.php",
			async:false,
			dataType: "json",                      
			data: ({
				action: "obtener_datos",
				pro_id:	idf
			}),
			beforeSend: function() {						
			//$('#div_proveedor_form').html('Cargando....');
		},
		success: function(data){
			console.log(data);

			$('#hdd_ordcom_pro_id').val(idf);	
			$('#txt_ordcom_pro_nom').val(data.nombre);	
			$('#txt_ordcom_pro_doc').val(data.documento);			
			$('#txt_ordcom_pro_dir').val(data.direccion);
		}
	});		
	}
	
function limpiarCampos()
{
	
	$("#txt_bus_pro_cod").val('');
	$("#txt_fil_pro_dat1").val('');
	$("#txt_fil_pro_dat2").val('');
	$("#txt_fil_pro_dat3").val('');
	$("#txt_fil_pro_dat4").val('');

	$("#txt_bus_pro_cod").focus();
}

<?php if($_POST['action']=="insertar")
{
?>

	proveedor_cargar_datos(<?php echo $pro_id?>);
	cmb_empresa_id(<?php echo $emp_id?>);
	ordencompra_detalle_tabla();
	txt_ordcom_numdoc();

<?php 		
}else{
	?>
	cmb_empresa_id(<?php echo $emp_id?>);
	ordencompra_detalle_tabla_editar(<?php echo $_POST['ordcom_id']?>);
	<?php 
}
?>

		
			$( "#txt_ordcom_pro_nom" ).autocomplete({
			minLength: 1,
			source: "../proveedor/proveedor_complete_nom.php",
			select: function(event, ui){	 
				$("#hdd_ordcom_pro_id").val(ui.item.id);							
				$("#txt_ordcom_pro_doc").val(ui.item.documento);
				$("#txt_ordcom_pro_dir").val(ui.item.direccion); 
			//	verificar_duplicidad_compra()
				$("#hdd_ordcom_pro_id").change();
			}
			});
			
			$( "#txt_ordcom_pro_doc" ).autocomplete({
			minLength: 1,
			source: "../proveedor/proveedor_complete_doc.php",
			select: function(event, ui){	
			$("#hdd_ordcom_pro_id").val(ui.item.id);							
			$("#txt_ordcom_pro_nom").val(ui.item.nombre);
			$("#txt_ordcom_pro_dir").val(ui.item.direccion);
			$("#hdd_ordcom_pro_id").change();
			//	verificar_duplicidad_compra()		
			}
			});
	
	$('#txt_ordcom_numdoc,#txt_ordcom_lug').change(function(){
		$(this).val($(this).val().toUpperCase());
	});

		$("#cmb_doc_id").keydown(function(e){
			if (e.which == 13){$("#txt_ordcom_numdoc").focus();return false;}
		});
		
		$("#txt_ordcom_numdoc").keydown(function(e){
			if (e.which == 13){$("#cmb_punven_id").focus();return false;}
		});
		
		$("#txt_ordcom_pro_doc").keydown(function(e){
			if (e.which == 13){$("#txt_ordcom_pro_nom").focus();return false;}
		});

		$("#txt_ordcom_pro_nom").keydown(function(e){
			if (e.which == 13){$("#cmb_doc_id").focus();return false;}
		});

		$("#cmb_punven_id").keydown(function(e){
			if (e.which == 13){$("#txt_bus_pro_codbar").focus();return false;}
		});
		
		
		
		
		
	
	
		$( "#txt_fil_pro_dat1" ).keydown(function(e){
			if(e.which==32)
			{
				$( "#txt_fil_pro_dat2" ).focus();
				//producto_tabla();
				e.preventDefault();
			}
		});

		$( "#txt_fil_pro_dat2" ).keydown(function(e){
			if(e.which==32)
			{
				$( "#txt_fil_pro_dat3" ).focus();
				//producto_tabla();
				e.preventDefault();
			}
		});

		$( "#txt_fil_pro_dat3" ).keydown(function(e){
			if(e.which==32)
			{
				$( "#txt_fil_pro_dat4" ).focus();
				//producto_tabla();
				e.preventDefault();
			}
		});
		
		$( "#txt_fil_pro_dat1" ).keydown(function(e){
			if(e.which==13)
			{
				
				agregar_producto_lista();
				return false;
			
			}
		});
		
			$( "#txt_fil_pro_dat2" ).keydown(function(e){
			if(e.which==13)
			{
				
				agregar_producto_lista();
				return false;
			}
		});
		
		
			$( "#txt_fil_pro_dat3" ).keydown(function(e){
			if(e.which==13)
			{
				
				agregar_producto_lista();
				return false;
			
			}
		});
			$( "#txt_fil_pro_med" ).keydown(function(e){
			if(e.which==13)
			{
				
				agregar_producto_lista();
				return false;
			
			}
		});
		
		$( "#txt_fil_pro_mod" ).keydown(function(e){
			if(e.which==13)
			{
				
				agregar_producto_lista();
				return false;
			
			}
		});
			$( "#txt_fil_pro_mot" ).keydown(function(e){
			if(e.which==13)
			{
				
				agregar_producto_lista();
				return false;
			
			}
		});
		
		$( "#txt_fil_pro_int" ).keydown(function(e){
			if(e.which==13)
			{
				
				agregar_producto_lista();
				return false;
			
			}
		});
		
		$( "#txt_fil_pro_dat4" ).keydown(function(e){
			if(e.which==13)
			{
			agregar_producto_lista();
				return false;
			
			}
		});
		
		
		
		$("#txt_fil_pro_dat4").keydown(function(e){
			if(e.which==8)
			{
				if($("#txt_fil_pro_dat4").val()==""){
					$("#txt_fil_pro_dat3").focus();
				}	
					
			}
		});
		
		
		$("#txt_fil_pro_dat3").keydown(function(e){
			if(e.which==8)
			{
				if($("#txt_fil_pro_dat3").val()==""){
					$("#txt_fil_pro_dat2").focus();
				}	
					
			}
		});
		
		
		$("#txt_fil_pro_dat2").keydown(function(e){
			if(e.which==8)
			{
				if($("#txt_fil_pro_dat2").val()==""){
					$("#txt_fil_pro_dat1").focus();
				}	
					
			}
		});
		
	
	
	$("#txt_bus_pro_codbar").keydown(function(e){
		if (e.which == 13){			
			
			buscar_producto($("#txt_bus_pro_codbar").val());
			
			return false;
		}
	});
		
	$("#txt_bus_pro_mar").keydown(function(e){
		if (e.which == 13){			
			
			agregar_producto_lista('','','','');
			
			return false;
		}
	});
		
		$("#txt_bus_pro_cod").keydown(function(e){
			if (e.which == 13){
			
			agregar_producto_lista('','','','');
				return false;
			}
		});
		
		
		
		
		
		
		
		
		
		
	
	$('#save_form').on('click', function() {  

		var ok = true;
		
		if($("#hdd_ordcom_pro_id").val()==''){
			var ok = false;
			toastr["info"]('Seleccione un proveedor.');
		}else if($("#cmb_empresa_id").val()==''){
			var ok = false;
			toastr["info"]('Seleccione una empresa.');
		}
		
		if (ok ==true){
			$("#for_ordcom").submit();
		}	

	});	
			
			
			
	$('#for_ordcom').bootstrapValidator({
	     
	      framework: 'bootstrap',
	      message: 'Valor no valido',
	     /* feedbackIcons: {
	      	valid: 'glyphicon glyphicon-ok',
	      	invalid: 'glyphicon glyphicon-remove',
	      	validating: 'glyphicon glyphicon-refresh'
	      },*/
	      fields: {	      	
	      	txt_ordcom_fec: {
	      		group: '.col-lg-4',
	      		validators: { 
	      			date: {
	      				format: 'DD-MM-YYYY',
	      				message: 'Fecha no Valida'
	      			}
	      		}
	      	},
	      	cmb_doc_id: {
	      		group: '.col-lg-4',
	      		validators: {
	      			notEmpty: {
	      				message: 'Requerido *'
	      			}
	      		}
	      	},
	      	txt_ordcom_numdoc: {
	      		group: '.col-lg-4',
	      		validators: {
	      			notEmpty: {
	      				message: 'Requerido *'
	      			}
	      		}
	      	},
			cmb_punven_id: {
	      		group: '.col-lg-4',
	      		validators: {
	      			notEmpty: {
	      				message: 'Requerido *'
	      			}
	      		}
	      	},
			cmb_mone_id: {
	      		group: '.col-lg-4',
	      		validators: {
	      			notEmpty: {
	      				message: 'Requerido *'
	      			}
	      		}
	      	}
			
	      }
	  }).on('success.form.bv', function(e) 
	  {
	  	
	  	$.ajax({
	  		type: "POST",
	  		url: "../ordencompra/ordencompra_reg.php",
	  		async:true,
	  		dataType: "json",
	  		data: $("#for_ordcom").serialize(),
	  		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(data){
				
				if(data.ordcom_est==2){
					toastr["error"](data.ordcom_msj);
				}else{
					
					toastr["success"](data.ordcom_msj);
				}
				
				$('#div_ordencompra_form_dialog').modal('hide');
				
				<?php if($_POST['action']=="editar"){ ?>
					ordencompra_tabla();
					
				<?php } ?>
				
				<?php if($_POST['vista']=="stockgeneral_form"){ ?>
					abrirEnPestana('../../files/ordencompra/ordencompra_impcpe_doc.php?ordcomid='+data.ordcom_id);
				<?php } ?>
						
	  		},
	complete: function(){

	<?php if($_POST['vista']=="stockgeneral_form"){ ?>
	
	$('#div_ordencompraproducto_form_dialog').modal('hide');
	
		//$('#div_ordencompradetalle_form_dialog').modal('hide');
		//$("#contenido").load("../stockgeneral/stockgeneral_vista.php");
	<?php } ?>

		}
	});	 

});
			
			
			
			
			
			
			
			</script>