<?php
session_start(); 
require_once ("../../config/Cado.php");
$anio=date('Y');
$caj_id=1;
?>
<style type="text/css">
	.ui-autocomplete {
		z-index: 5000;
	}
	select{
		cursor:pointer;
	}
</style>
<div class="content-header" >
      <div class="container-fluid">
        <div class="row mb-2">
		 <div class="col-sm-6">
			<h1>
			Flujo de Caja
			<small>modulo</small>
			</h1>
		</div>	
		
		<div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
				<li class="breadcrumb-item" >Inicio</li>
				<li class="breadcrumb-item" >Caja</li>
				<li class="breadcrumb-item active">Flujo de Caja</li>
            </ol>
          </div>
		</div>
	</div>
</div>
<section class="content">
	<div class="container-fluid">
	<div class="row">
	    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="padding:0px;" >
		    <div class="card">
		        <div class="card-header">
				
					<span onClick="ingreso_form('insertar')" style="cursor:pointer" class="btn btn-primary" title="Registrar nuevo ingreso" > INGRESO</span>
					<span onClick="egreso_form('insertar')" style="cursor:pointer" class="btn btn-danger " title="Registrar nuevo egreso" > EGRESO</span>
					<span onClick="transferencia_form('insertar')" style="cursor:pointer" class="btn btn-success "> TRANSFERENCIA</span>
					<span id="btn_actualizar" style="cursor:pointer" class="btn btn-default  float-right">Actualizar</span>
							        
		        </div>
		    </div>
		</div>
	</div>
	</div>
</section>
	<div id="div_caja_filtro" > </div>
	<div id="div_ingreso_impresion"> </div>
	<!-- formulario para egresos -->
	<div class="modal fade" id="div_egreso_form_dialog" role="dialog" data-keyboard="false" data-backdrop="static" tabindex="-1"  style="padding:0px;">
			<div class="modal-dialog modal-lg"  role="document" >
			<div class="modal-content">
			<div class="modal-body div_egreso_form" style="padding:0%;" >
			</div>
			<br />
			<br />
			</div>
			</div>
			</div>
			
			<!-- formulario de ingresos -->
			<div class="modal fade" id="div_ingreso_form_dialog" role="dialog" data-keyboard="false" data-backdrop="static" tabindex="-1"  style="padding:0px;">
			<div class="modal-dialog modal-lg"  role="document" >
			<div class="modal-content">
			<div class="modal-body div_ingreso_form" style="padding:0%;" >
			</div>
			<br />
			<br />
			</div>
			</div>
			</div>
			
			
	<div id="div_egreso_impresion"> </div>
	
	<!-- Formulario de registros -->
	
	<div class="modal fade" id="div_transferencia_form_dialog" role="dialog" data-keyboard="false" data-backdrop="static" tabindex="-1"  style="padding:0px;">
			<div class="modal-dialog modal-lg"  role="document" >
			<div class="modal-content">
			<div class="modal-body div_transferencia_form" style="padding:0%;" >
			</div>
			<br />
			<br />
			</div>
			</div>
			</div>
			
<section class="content">
	<div class="container-fluid">
	<div class="row">
	    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="padding:0%;" >
		    <div class="card">
				<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" >
	
					
						
						<div class="box box-warning">
							<div class="box-header">
								<h3 class="box-title text-yellow">INGRESOS</h3>
							</div>
							
							<div id="div_ingreso_tabla">
								
							</div>
							
						</div>
						
						<div class="box box-danger">
							<div class="box-header">
								<h3 class="box-title text-red">EGRESOS</h3>
							</div>
							
							<div id="div_egreso_tabla">
							
							</div>
							
						</div>
						
						<div class="col-lg-6 col-md-6 col-xs-12" style="padding:0px;" >
							<div class="box box-primary">
								<div class="box-header">
									<h3 class="box-title text-primary">CONSULTA SALDO</h3>
								</div>
								
								<div id="div_saldo_tabla">
									
								</div>
								
							</div>
						</div>
						
						
					
			</div>
			</div>
			</div>
		</div>
	</div>
</section>

<script type="text/javascript">
	function flujocaja_filtro()
	{
		$.ajax({
			type: "POST",
			url: "../flujocaja/flujocaja_filtro.php",
			async:true,
			dataType: "html",                      
			data: ({
			}),
			beforeSend: function() {
				
			},
			success: function(html){
				$('#div_caja_filtro').html(html);
			},
			complete: function(){
				
			}
		});
	}
	function flujocaja_tabla()
	{
		if($('#cmb_fil_caj_id').val()>0)
		{
			ingreso_tabla();
			egreso_tabla();
			saldo_tabla();
		}
		else
		{
			$('#div_ingreso_tabla').html('');
			$('#div_egreso_tabla').html('');
			$('#div_saldo_tabla').html('');
			toastr["error"]('Seleccione una Caja para mostrar información.');
		}
	}
	function ingreso_tabla()
	{
		$.ajax({
			type: "POST",
			url: "../flujocaja/caja_tabla_ingreso.php",
			async:true,
			dataType: "html",                      
			data: $("#for_fil_caj").serialize(),
			beforeSend: function() {
				$('#div_ingreso_tabla').addClass("ui-state-disabled");
			},
			success: function(html){
				$('#div_ingreso_tabla').html(html);
			},
			complete: function(){
				saldo_tabla()		
				$('#div_ingreso_tabla').removeClass("ui-state-disabled");
			}
		});     
	}
	
	
	function egreso_tabla()
	{
		$.ajax({
			type: "POST",
			url: "../flujocaja/caja_tabla_egreso.php",
			async:true,
			dataType: "html",                      
			data: $("#for_fil_caj").serialize(),
			beforeSend: function() {
				$('#div_egreso_tabla').addClass("ui-state-disabled");
			},
			success: function(html){
				$('#div_egreso_tabla').html(html);
			},
			complete: function(){
				saldo_tabla()			
				$('#div_egreso_tabla').removeClass("ui-state-disabled");
			}
		});     
	}
	
	function saldo_tabla()
	{
		$.ajax({
			type: "POST",
			url: "../flujocaja/caja_tabla_saldo.php",
			async:true,
			dataType: "html",                      
			data: $("#for_fil_caj").serialize(),
			beforeSend: function() {
				$('#div_saldo_tabla').addClass("ui-state-disabled");
			},
			success: function(html){
				$('#div_saldo_tabla').html(html);
			},
			complete: function(){			
				$('#div_saldo_tabla').removeClass("ui-state-disabled");
			}
		});     
	}
	
	
	
	
	
	
	//// PROCESOS PARA EGRESOS
	
	
	function egreso_form(act,idf)
	{
		$('#div_egreso_form_dialog').modal(); 
		$.ajax({
			type: "POST",
			url: "../egreso/egreso_form.php",
			async:true,
			dataType: "html",                      
			data: ({
				action: act,
				egr_id:	idf,
				vista: 'egreso_tabla'
			}),
			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_egreso_form').html(div); 
				
			},
			success: function(html){
				$('.div_egreso_form').html(html);				
			}
		});
	}
	
	function egreso_eliminar(id)
	{      
		if(confirm("Realmente desea eliminar?")){
			$.ajax({
				type: "POST",
				url: "../egreso/egreso_reg.php",
				async:true,
				dataType: "html",
				data: ({
					action: "eliminar",
					egr_id:		id
				}),
				beforeSend: function() {
				},
				success: function(html){
					toastr["success"](html);
				},
				complete: function(){
					egreso_tabla();
				}
			});
		}
	}
	
	/// codigo para ingresos
	
	function ingreso_form(act,idf)
	{
		$('#div_ingreso_form_dialog').modal(); 
		$.ajax({
			type: "POST",
			url: "../ingreso/ingreso_form.php",
			async:true,
			dataType: "html",                      
			data: ({
				action: act,
				ing_id:	idf,
				vista: 'ingreso_tabla'
			}),
			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_ingreso_form').html(div);
			},
			success: function(html){
			$('.div_ingreso_form').html(html);				
			}
		});
	}
	function ingreso_eliminar(id)
	{      
		if(confirm("Realmente desea eliminar?")){
			$.ajax({
				type: "POST",
				url: "../ingreso/ingreso_reg.php",
				async:true,
				dataType: "html",
				data: ({
					action: "eliminar",
					ing_id:		id
				}),
				beforeSend: function() {
				},
				success: function(html){
					toastr["success"](html);	
				},
				complete: function(){
					ingreso_tabla();
				}
			});
		}
	}
	
	// codigo para transferencias
	
	
	function transferencia_form(act,idf){
		$('#div_transferencia_form_dialog').modal(); 
		$.ajax({
			type: "POST",
			url: "../transferencia/transferencia_form.php",
			async:true,
			dataType: "html",                      
			data: ({
				action: act,
				tra_id:	idf,
				vista: 'transferencia_tabla'
			}),
			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_transferencia_form').html(div); 
			},
			success: function(html){
				$('.div_transferencia_form').html(html);				
			}
		});
	}
	
	$(function() {
		
		
		$('#btn_actualizar').click(function() {
			$("#contenido").load("../flujocaja/flujocaja_vista.php");
		});
		setTitle("FLUJO DE CAJA - "+nombreEmpresa);	
		flujocaja_filtro();	
	});
</script> 