<?php
//ini_set("display_errors",1);
session_start();
date_default_timezone_set('America/Lima');
require_once ("../../config/Cado.php");
require_once ("../ingreso/cIngreso.php");
$oIngreso = new cIngreso();
require_once ("../usuario/cUsuario.php");
$oUsuario = new cUsuario();
require_once("../formatos/formato.php");
if($_POST['action']=="insertar"){
	$fec=date('d-m-Y');
	$est='1';
	
	$caj_id=$_SESSION['caja_id'];
	$mon_id=1;
	$ven_id=0;
	$tra_id=0;
	
}

if($_POST['action']=="editar"){
	
	ECHO $_POST['ing_id'];
	
	$dts= $oIngreso->mostrarUno($_POST['ing_id']);
	$numros = mysqli_num_rows($dts);
	echo $numros;
	$dt = mysqli_fetch_array($dts);
	$fecreg		=mostrarFechaHora($dt['tb_ingreso_fecreg']);
	$fecmod		=mostrarFechaHora($dt['tb_ingreso_fecmod']);
	$usureg		=$dt['tb_ingreso_usureg'];
	$usumod		=$dt['tb_ingreso_usumod'];
	$fec		=mostrarFecha($dt['tb_ingreso_fec']);
	$doc_id 	=$dt['tb_documento_id'];
	$numdoc		=$dt['tb_ingreso_numdoc'];
	$det		=$dt['tb_ingreso_det'];
	$cue_id		=$dt['tb_cuenta_id'];
	$subcue_id	=$dt['tb_subcuenta_id'];
	$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'];
	$imp		=$dt['tb_ingreso_imp'];
	$caj_id		=$dt['tb_caja_id'];		
	$mon_id		=$dt['tb_moneda_id'];
	$ven_id		=$dt['tb_venta_id'];
	mysqli_free_result($dts);
	
}

if($usureg>0)
{
	$dts=$oUsuario->mostrarUno($usureg);
	$dt = mysqli_fetch_array($dts);
	$usugru		=$dt['tb_usuariogrupo_id'];
	$usugru_nom	=$dt['tb_usuariogrupo_nom'];
	$usu_nom	=$dt['tb_usuario_nom'];
	$apepat		=$dt['tb_usuario_apepat'];
	$apemat		=$dt['tb_usuario_apemat'];
	$ema		=$dt['tb_usuario_ema'];
	
	mysqli_free_result($dts);
	
	$usuario_reg="$usu_nom $apepat $apemat";
}
if($usumod>0)
{
	$dts=$oUsuario->mostrarUno($usumod);
	$dt = mysqli_fetch_array($dts);
	$usugru		=$dt['tb_usuariogrupo_id'];
	$usugru_nom	=$dt['tb_usuariogrupo_nom'];
	$usu_nom	=$dt['tb_usuario_nom'];
	$apepat		=$dt['tb_usuario_apepat'];
	$apemat		=$dt['tb_usuario_apemat'];
	$ema		=$dt['tb_usuario_ema'];
	
	mysqli_free_result($dts);
	
	$usuario_mod="$usu_nom $apepat $apemat";
}
?>
<script type="text/javascript">
	
	$('#txt_ing_fec').datepicker({
		format: 'dd-mm-yyyy',
		autoclose:true,
		endDate: '+0d'
	}).on('hide', function () {
		$("#cmb_caja_id").focus();return false;
	});
	
$(function() {
	
	
$('#for_cajges').bootstrapValidator({ 
	     
	      message: 'Valor no valido',
	      feedbackIcons: {
	      	valid: 'glyphicon glyphicon-ok',
	      	invalid: 'glyphicon glyphicon-remove',
	      	validating: 'glyphicon glyphicon-refresh'
	      },
	      fields: {	      	
	      	
            }
        }).on('success.form.bv', function(e) { 
        	
        	$.ajax({
        		type: "POST",
        		url: "../cajagestion/cajagestion_reg.php",
        		async:true,
        		dataType: "json",
        		data: $("#for_cajges").serialize(),
        		beforeSend: function(){
        			
        		},
        		success: function(data){
        			//$('.modal').modal('hide');
					//$('.in').removeClass('modal-backdrop');		
					toastr["success"](data.cajges_msj);
        			$('#div_cajagestion_form_dialog').modal("hide"); 
        			/* ingreso_impresion(data.ing_id); */
        		},
        		complete: function(){
        		location.reload();
					
        		}
        	});
        });
       
	   
 
    $("#txt_cajges_efe").keydown(function(e){
        	if (e.which == 13){$("#txt_cajges_tra").focus();return false;
        }
    });
	
        $("#txt_cajges_tra").keydown(function(e){
        	if (e.which == 13){$("#txt_cajges_yap").focus();return false;
        }
    });
        $("#txt_cajges_yap").keydown(function(e){
        	if (e.which == 13){$("#txt_cajges_pli").focus();return false;
        }
    });
	
	$("#btn_ing_guardar").click(function(){
		
		$("#for_cajges").submit();
		
	});
		
		
		
		
		
		
	$("#txt_cajges_pli").keydown(function(e){
        	if (e.which == 13){$("#btn_cajges_guardar").focus();return false;
    }
   
    });
	
    });
</script>
<div class="col-12 col-lg-12 col-md-12 col-sm-12" >
<form  role="form" id="for_cajges" method="POST">
	<input type="hidden" id="action" name="action" value="<?php echo $_POST['action']?>">
	<input type="hidden" id="hdd_cajges_id" name="hdd_cajges_id" value="<?php echo $_POST['cajges_id']?>">
	<input type="hidden" id="hdd_cajges_tip" name="hdd_cajges_tip" value="<?php echo $_POST['tip']?>">
	
	<div class="box-header">
	<h3 class="box-title">Información de la Caja</h3>
	</div>
					
	<div class="row">
		
		
		<div class="col-lg-12 col-sm-12 col-12 ">
			<label for="txt_cajges_efe">Efectivo:</label>
			<input name="txt_cajges_efe" type="text" id="txt_cajges_efe"    value="<?php echo $numdoc?>" class="form-control" autocomplete="off">
		</div> 
		
		<div class="col-lg-12 col-sm-12 col-12">
			<label for="txt_cajges_tra">Tranferencia:</label>
			<input name="txt_cajges_tra" type="text" id="txt_cajges_tra"  value="<?php echo $numdoc?>" class="form-control" autocomplete="off">
		</div> 
		
		<div class="col-lg-12 col-sm-12 col-12">
			<label for="txt_cajges_yap">Yape:</label>
			<input name="txt_cajges_yap" type="text" id="txt_cajges_yap"  value="<?php echo $numdoc?>" class="form-control" autocomplete="off">
		</div> 
		
		<div class="col-lg-12 col-sm-12 col-12">
			<label for="txt_cajges_pli">Plin:</label>
			<input name="txt_cajges_pli" type="text" id="txt_cajges_pli"  value="<?php echo $numdoc?>" class="form-control" autocomplete="off" >
		</div> 
	
	
		<div class="col-lg-8 col-sm-4 col-6">
			<?php 
			if($_POST['action']=="insertar"){?>
			<label for="chk_imprimir">Responsable</label><br>
			<span class="badge badge-success"><?php echo $_SESSION['usuario_nombre']?></span>
			<?php } 
			if($_POST['action']=="editar"){?>  <br>
			<span title="REGISTRADO POR" class="badge badge-success"><i class="fa fa-plus"></i> <?php echo $usuario_reg.' - '.$fecreg; ?></span>
			<span title="EDITADO POR" class="badge badge-info"><i class="fa fa-pencil"></i> <?php echo $usuario_mod.' - '.$fecmod; ?></span>
			<?php } ?>			
		</div> 	
	</div> 
</form>
  
<div class="modal-footer float-right">	
		
			<button type="button" class="btn btn-default" id="" data-dismiss="modal">Cancelar</button>
			<button type="button" class="btn btn-primary " id="btn_ing_guardar">Guardar</button>
				
			
	
</div>
</div>