<?php
require_once("class/class.php"); 
if(isset($_SESSION['acceso'])) { 
    if ($_SESSION['acceso'] == "administradorG" || $_SESSION["acceso"]=="administradorS" || $_SESSION["acceso"]=="secretaria") {

$tra = new Login();
$ses = $tra->ExpiraSession(); 

if(isset($_POST["proceso"]) and $_POST["proceso"]=="save")
{
$reg = $tra->RegistrarTipoCambio();
exit;
}
elseif(isset($_POST["proceso"]) and $_POST["proceso"]=="update")
{
$reg = $tra->ActualizarTipoCambio();
exit;
}          
?>
<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="author" content="Ing. Ruben Chirinos">
    <link rel="icon" type="image/png" sizes="16x16" href="assets/images/favicon.png">
    <title>Gestión de Cambios - Auditoría Exacta</title>

    <link href="assets/plugins/bower_components/sidebar-nav/dist/sidebar-nav.min.css" rel="stylesheet">
    <link href="assets/plugins/datatables/dataTables.bootstrap4.css" rel="stylesheet">
    <link rel="stylesheet" href="assets/css/sweetalert.css">
    <link href="assets/css/animate.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">
    <link href="assets/css/default.css" id="theme" rel="stylesheet">
</head>

<body onLoad="muestraReloj()" class="fix-header">
    <div class="preloader">
        <svg class="circular" viewBox="25 25 50 50">
            <circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10" />
        </svg>
    </div>

    <div id="main-wrapper" data-layout="vertical" data-navbarbg="skin6" data-sidebartype="full" data-boxed-layout="full" data-header-position="fixed" data-sidebar-position="fixed" class="mini-sidebar"> 

        <div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header bg-warning">
                        <h4 class="modal-title text-white" id="myModalLabel"><i class="fa fa-align-justify"></i> Detalle de Cambio</h4>
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><img src="assets/images/close.png"/></button>
                    </div>
                    <div class="modal-body"><div id="muestracambiomodal"></div></div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-dark" data-dismiss="modal"><span class="fa fa-times-circle"></span> Cerrar</button>
                    </div>
                </div>
            </div>
        </div>

        <?php include('menu.php'); ?>

        <div class="page-wrapper">
            <div class="page-breadcrumb border-bottom">
                <div class="row">
                    <div class="col-lg-3 col-md-4 col-xs-12 align-self-center">
                        <h5 class="font-medium text-uppercase mb-0"><i class="fa fa-tasks"></i> Tipos de Cambio</h5>
                    </div>
                </div>
            </div>

            <div class="page-content container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header bg-warning">
                                <h4 class="card-title text-white"><i class="fa fa-tasks"></i> Gestión de Cambios por Hora</h4>
                            </div>

                            <div id="save"></div>
                            
                            <div class="card-body">
                                <div class="row">
                                    <div class="col-md-5">
                                        <h4 class="card-subtitle m-0 text-dark"><i class="font-20 fa fa-save"></i> Registro de Tasa</h4><hr>

                                        <form class="form form-material" method="post" action="#" name="savecambio" id="savecambio"> 
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group has-feedback">
                                                        <label class="control-label">Descripción: <span class="symbol required"></span></label>
                                                        <input type="hidden" name="proceso" id="proceso" value="save"/>
                                                        <input type="hidden" name="codcambio" id="codcambio">
                                                        <input type="text" class="form-control" name="descripcioncambio" id="descripcioncambio" onKeyUp="this.value=this.value.toUpperCase();" placeholder="Ej: DOLAR AM" required=""/> 
                                                        <i class="fa fa-pencil form-control-feedback"></i> 
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group has-feedback">
                                                        <label class="control-label">Monto Tasa: <span class="symbol required"></span></label>
                                                        <input type="text" class="form-control" name="montocambio" id="montocambio" placeholder="0.000" required=""/> 
                                                        <i class="fa fa-tint form-control-feedback"></i> 
                                                    </div>
                                                </div>
                                            </div>

                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group has-feedback">
                                                        <label class="control-label">Moneda: <span class="symbol required"></span></label>
                                                        <select name="codmoneda" id="codmoneda" class='form-control' required="">
                                                            <option value="">-- SELECCIONE --</option>
                                                            <?php
                                                            $moneda = new Login();
                                                            $monedas = $moneda->ListarTipoMoneda();
                                                            if($monedas){
                                                                foreach($monedas as $m){
                                                                    echo "<option value='".$m['codmoneda']."'>".$m['moneda']."</option>";
                                                                }
                                                            }
                                                            ?>
                                                        </select> 
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group has-feedback">
                                                        <label class="control-label">Fecha y Hora Real: <span class="symbol required"></span></label>
                                                        <input type="text" class="form-control" name="fechacambio" id="fechacambio" value="<?php echo date("Y-m-d H:i:s"); ?>" readonly="" required=""/> 
                                                        <i class="fa fa-calendar form-control-feedback"></i> 
                                                    </div>
                                                </div>
                                            </div>

                                            <div class="text-right">
                                                <button type="submit" class="btn btn-warning"><span class="fa fa-save"></span> Guardar</button>
                                                <button class="btn btn-dark" type="button" onclick="
                                                    document.getElementById('proceso').value = 'save';
                                                    document.getElementById('codcambio').value = '';
                                                    document.getElementById('fechacambio').value = '<?php echo date("Y-m-d H:i:s"); ?>';
                                                    $('#savecambio')[0].reset();
                                                "><span class="fa fa-trash-o"></span> Limpiar</button>
                                            </div>
                                        </form>
                                    </div>

                                    <div class="col-md-7">
                                        <h4 class="card-subtitle m-0 text-dark"><i class="font-20 fa fa-tasks"></i> Control de Cambios</h4><hr>
                                        <div id="cambios"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <footer class="footer text-center"><i class="fa fa-copyright"></i> <span class="current-year"></span>.</footer>
        </div>
    </div>

    <script src="assets/script/jquery.min.js"></script> 
    <script src="assets/js/bootstrap.js"></script>
    <script src="assets/js/app.min.js"></script>
    <script src="assets/js/waves.js"></script>
    <script src="assets/js/sweetalert-dev.js"></script>
    <script src="assets/js/custom.js"></script>
    <script type="text/javascript" src="assets/script/script2.js"></script>
    <script type="text/javascript" src="assets/script/validation.min.js"></script>
    <script type="text/javascript" src="assets/script/script.js"></script>

    <script type="text/jscript">
        $('#cambios').load("consultas?CargaCambios=si");
    </script>
</body>
</html>
<?php } else { echo "<script>location.href='panel';</script>"; } } else { echo "<script>location.href='logout';</script>"; } ?>