<?php
require_once ("../../config/Cado.php");
require_once ("cPuntoventa.php");
$oPuntoventa = new cPuntoventa();
require_once("../formatos/formato.php");


$emp_id = '';
if($_POST['action']=="editar")
{
	$dts=$oPuntoventa->mostrarUno($_POST['punven_id']);

	$dt = mysqli_fetch_array($dts);
	
	$punven_nom = $dt['tb_puntoventa_nom'];
	$punven_cod = $dt['tb_puntoventa_cod'];
	$alm_id = $dt['tb_almacen_id'];
	$caj_id = $dt['tb_caja_id'];
	$imp_id = $dt['tb_impresora_id'];
	$emp_id = $dt['tb_empresa_id'];
	$tippag = $dt['tb_puntoventa_tippag'];
	$pagmon = $dt['tb_puntoventa_mon'];
	$punven_alias = $dt['tb_puntoventa_alias'];
	$diaven = $dt['tb_puntoventa_diaven'];

	mysqli_free_result($dts);
}
?>

				<form role="form" id="for_punven" method="POST">

					<input name="action_puntoventa" id="action_puntoventa" type="hidden" value="<?php echo $_POST['action']?>">
					<input name="hdd_punven_id" id="hdd_punven_id" type="hidden" value="<?php echo $_POST['punven_id']?>">

					<div class="box-header">
						<h3 class="box-title">Información de Punto de Venta</h3>
					</div>
					<div class="box-body">

						<div class="form-group">
							<div class="row">        
							
							<div class="col-lg-3 col-sm-6 col-xs-12">
								<label for="txt_punven_cod">Codigo:</label>
								<input name="txt_punven_cod" type="text" id="txt_punven_cod" value="<?php echo $punven_cod?>"   class="form-control">
							</div>	
							
							<div class="col-lg-4 col-sm-6 col-xs-12">
								<label for="txt_punven_alias">Alias:</label>
								<input name="txt_punven_alias" type="text" id="txt_punven_alias" value="<?php echo $punven_alias?>"   class="form-control">
							</div>
							
							<div class="col-lg-5 col-sm-6 col-xs-12">
								<label for="txt_punven_nom">Nombre:</label>
								<input name="txt_punven_nom" type="text" id="txt_punven_nom" value="<?php echo $punven_nom?>"   class="form-control">
							</div>		

							<div class="col-lg-4 col-sm-6 col-xs-12">
								<label for="cmb_empresa_id">Empresa:</label>
								<select name="cmb_empresa_id" type="text" id="cmb_empresa_id" class="form-control">
								</select>
							</div>	

							<div class="col-lg-3 col-sm-6 col-6">
									<label>Tipo Pago:</label>
								<select name="cmb_tippag_id" id="cmb_tippag_id" class="form-control input-sm">
									<option value="0" <?php if($tippag=='0') echo 'selected'; ?> >--- Seleccionar ---</option>
									<option value="1" <?php if($tippag=='1') echo 'selected'; ?> >ALQUILER</option>
									<option value="2" <?php if($tippag=='2') echo 'selected'; ?> >PAGO COMPLETO</option>
								</select> 				
							</div>

							<div class="col-lg-3 col-sm-6 col-6">
								<label>Monto:</label>
								<input type="text" id="txt_con_mon" name="txt_con_mon"  autocomplete="off" 
								value="<?php echo formato_money($pagmon); ?>" class="form-control  input-sm" /> 
							</div>

							<div class="col-lg-2 col-sm-6 col-6">
								<label>Dia Ven.:</label>
								<input type="text" id="txt_con_diaven" autocomplete="off" name="txt_con_diaven" value="<?php echo $diaven; ?>" class="form-control  input-sm" /> 
							</div>

							
							</div>
						</div>
					</div>
				</form>
				<div class="box-footer float-right">
					<button type="button" data-dismiss="modal" class="btn btn-default cancel">Cancelar</button>
					<button class="btn btn-primary" id="save_form">Guardar</button>
				</div>

<script type="text/javascript">

	$('#txt_punven_nom,#txt_punven_alias').change(function(){
		$(this).val($(this).val().toUpperCase());
	});
	
	
	cmb_empresa_id(<?php echo $emp_id; ?>);
	
function cmb_empresa_id(emp_id)
{
		$.ajax({
			type: "POST",
			url: "../empresa/cmb_emp_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				emp_id:emp_id
			}),
			beforeSend: function() {
				$('#cmb_empresa_id').html('<option value="">Cargando...</option>');
			},
			success: function(html){		
				$('#cmb_empresa_id').html(html);
			}
		});		
}
	


	$("#save_form").click(function() {
		$("#for_punven").submit();
	});

	$(document).ready(function() {
		$('#for_punven').bootstrapValidator({
	      message: 'Valor no Valido',
	      feedbackIcons: {
	      	valid: 'glyphicon glyphicon-ok',
	      	invalid: 'glyphicon glyphicon-remove',
	      	validating: 'glyphicon glyphicon-refresh'
	      },
	      fields: { 
	      	txt_punven_nom: {
	      		group: '.col-lg-6',
	      		validators: {
	      			notEmpty: {
	      				message: 'Este campo es requerido'
	      			}
	      		}
	      	},
	      	cmb_alm_id: {
	      		group: '.col-lg-2',
	      		validators: {
	      			notEmpty: {
	      				message: 'Este campo es requerido'
	      			}
	      		}
	      	},
	      	cmb_caj_id: {
	      		group: '.col-lg-2',
	      		validators: {
	      			notEmpty: {
	      				message: 'Este campo es requerido'
	      			}
	      		}
	      	},
	      }
	  }).on('success.form.bv', function(e){
		  
	  	$.ajax({
	  		type: "POST",
	  		url: "../puntoventa/puntoventa_reg.php",
	  		async:true,
	  		dataType: "html",
	  		data: $("#for_punven").serialize(),
	  		beforeSend: function() {
					
				},
				success: function(html){						
					$('.modal').modal('hide');
					$('.in').removeClass('modal-backdrop');			
					toastr["success"](html);	
				},
				complete: function(){
					<?php
					if($_POST['vista']=="puntoventa_tabla")
					{
						echo $_POST['vista'].'()';
					}

					if($_POST['vista']=="cmb_punven_id")
					{
						echo $_POST['vista'].'()';
					}
					?>
				}
			});
	  });
	});
	
	
	$('#txt_punven_nom').focus();

	$('#txt_punven_nom').keydown(function(ev) {
		if(ev.keyCode==13){$('#save_form').focus(); return false;}
	});
		
	
</script>