<?php use_helper( 'UrlFunctions' ); ?>
<?php use_helper( 'IncludePartial' ); ?>
<?php use_helper( 'UtilFunctions' ); ?>

<style type="text/css">
    .ui-dialog .ui-dialog-titlebar-close
    {
        position: absolute;
        right: .3em;
        top: 50%;
        width: 20px;
        margin: -10px 0 0 0;
        padding: 1px;
        height: 20px;
        background-position: -96px -128px;
        /*background-image: url("images/ui-icons_056b93_256x240.png");*/
        background-image: url("<?=Constantes::ROOT_DIR_APP?>web/css/jquery/themes/start_1.12.1/images/ui-icons_056b93_256x240.png");
    }
</style>

<script type="text/javascript">
    changeIcon = function( elm, name )
    {
        var elms    = $( elm ).find( "svg" );
        var elm_sel = elms.first();
        if( $( "#" + name ).is( ":visible" ) )
        {
            $( elm_sel ).removeClass( "fa-angle-down" );
            $( elm_sel ).addClass( "fa-angle-right" );
        }
        else
        {
            $( elm_sel ).removeClass( "fa-angle-right" );
            $( elm_sel ).addClass( "fa-angle-down" );
        }
    }

    verResumenPDF = function()
    {
        window.open('<?=buildUrlComplet( 'tsr.php/caja/cierreCajaPDF' )?>FechaInicio/' + $( "#FechaDocumento1" ).val().trim() + '/FechaFin/' + $( "#FechaDocumento2" ).val().trim(), '_blank', '');
    }

    verReportePDF = function()
    {
        var params = $( 'form' ).serialize();
        window.open('<?=buildUrlComplet( 'tsr.php/caja/reporteBancosPDF' )?>?' + params, '_blank', '');
    }

    actualizarCambiosPorMoneda = function()
    {
        var IdMoneda = $( '#IdMoneda' ).val();

        $( '#IdBanco' )[0].options.length = 1;
        publicForSelectAjaxJSON( '<?php echo buildUrlComplet( 'tsr.php/caja/requestCaja' ) ?>', 'TipoProc=BuscarBancos&IdMoneda='+IdMoneda, 'IdBanco', resultCambio, false );
    }

    resultCambio = function()
    {
        pr( "termino carga de bancos" );
        pr( arguments );

        var IdMoneda = $( '#IdMoneda' ).val();

        //se actualiza combo cuenta por la moneda
        $( '#IdCuenta' )[0].options.length = 1;
        publicForSelectAjaxJSON( '<?php echo buildUrlComplet( 'tsr.php/caja/requestCaja' ) ?>', 'TipoProc=BuscarCuentaBancaria&IdBanco='+$('#IdBanco').val()+'&IdMoneda='+IdMoneda, 'IdCuenta', null, false );
    }

    verReporteAnticuamiento = function()
    {
        var params = $( 'form' ).serialize();
        window.open('<?=buildUrl( 'tsr/reporteAnticuaDet' )?>?' + params, '_blank', '');
    }

    verReporteMovimientoCtasPorCobrar = function()
    {
        var params = $( 'form' ).serialize();
        window.open('<?=buildUrl( 'tsr/repMovCtasxCobrar' )?>?' + params, '_blank', '');
    }

    verReporteDetalleCobranza = function()
    {
        var params = $( 'form' ).serialize();
        window.open('<?=buildUrl( 'tsr/repDetalleCobranza' )?>?' + params, '_blank', '');
    }
</script>

<div class="shadow-sm p-3 mb-2 bg-white rounded card card-body">
    <div class="row">
        <div class="col mb-1">
            <h4 class="text-info text-nowrap mb-0">Reportes - Cuentas por Cobrar</h4>
        </div>
        <div class="form-row mx-1">

        </div>
    </div>
</div>

<div id="content_alert" style=""></div>

<div class="card">
    <div class="card-header">
        <h5 class="mb-0"> Filtro <i class="fas fa-angle-right pull-right"></i></h5>
    </div>
    <div id="collapseThree" >
        <div class="card-body pb-1">
            <form class="" name="form1" id="form1" method="POST" action="">
                <div class="form-row mx-0">
                    <div class="col-md-3 mb-1">
                        <div class="col-auto">
                            <label class="sr-only" for="FechaDocumento1">Fecha Desde</label>
                            <div class="input-group mb-2">
                                <div class="input-group-prepend">
                                    <div class="input-group-text"><?=addImgButton( "calendar.png", array( "class"=>"", "height"=>24 ) )?></div>
                                </div>
                                <input type="text" class="form-control text-center" id="FechaDocumento1" name="FechaDocumento1" placeholder="FECHA DESDE" value="" autocomplete="off">
                                <script type="text/javascript">
                                    $( "#FechaDocumento1" ).datepicker( { dateFormat: "yy-mm-dd", changeYear:true, yearRange: "-2:+0", changeMonth: true, onClose: function (){ this.focus(); } } );
                                </script>
                            </div>
                        </div>
                        <div class="col-auto">
                            <label class="sr-only" for="FechaDocumento2">Fecha Hasta</label>
                            <div class="input-group mb-2">
                                <div class="input-group-prepend">
                                    <div class="input-group-text"><?=addImgButton( "calendar.png", array( "class"=>"", "height"=>24 ) )?></div>
                                </div>
                                <input type="text" class="form-control text-center" id="FechaDocumento2" name="FechaDocumento2" placeholder="FECHA HASTA" autocomplete="off">
                                <script type="text/javascript">
                                    $( "#FechaDocumento2" ).datepicker( { dateFormat: "yy-mm-dd", changeYear:true, yearRange: "-2:+0", changeMonth: true, onClose: function (){ this.focus(); } } );
                                </script>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-3 mb-1">
                        <select class="form-control" name="TipoDocCliente" id="TipoDocCliente">
                            <option value=""> - CLIENTE TIPO DOC - </option>
                            <?php foreach ( MST_PersonaMastBN::getArrayTipoDocumento() as $s_Key => $s_TipoDoc ){ ?>
                                <option value="<?=$s_Key?>" > <?=$s_Key?> </option>
                            <?php } ?>
                        </select>
                        <input type="text" class="form-control" name="NumTipoDocCliente" id="NumTipoDocCliente" placeholder="CLIENTE NUM DOCUMENTO">
                    </div>
                    <div class="col-md-3 mb-1">
                        <label class="col-form-label" for="NombreCliente">Cliente Nombre</label>
                        <input type="hidden" name="ClienteNumero" id="ClienteNumero" value="">
                        <input type="text" class="form-control" id="NombreCliente" name="NombreCliente" value="" autocomplete="off" required>
                        <script>
                            $( "#NombreCliente" ).autocomplete
                            (
                                {
                                    source: "<?=buildUrlComplet( 'vta.php/recephabit/requestUbicacion', "tipo_proc=Autocomplete" )?>",
                                    minLength: 2,
                                    select: function( event, ui )
                                    {
                                        $( "#ClienteNumero" ).val( ui.item.id );
                                        //$( "#TipoDocCliente" ).val( ui.item.tipo_doc );
                                        //$( "#NumDocuCliente" ).val( ui.item.num_doc );
                                        //blockContent( 'content_datos_cliente' );
                                        //buscarInfoCliente();
                                    }
                                }
                            );
                        </script>
                    </div>
                    <div class="col-md-3 mb-1">
                        <label class="col-form-label" for="IdTipoPago">Medio de Pago</label>
                        <select class="form-control" name="IdTipoPago" id="IdTipoPago">
                            <option value=""> - SELECCIONE - </option>
                            <?php foreach ( FCO_TipoPagoFN::selectActivos() as $o_FCO_TipoPagoBN ) { ?>
                                <option value="<?=$o_FCO_TipoPagoBN->getIdTipoPago()?>" > <?=$o_FCO_TipoPagoBN->getNombre()?> </option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="form-row mx-0">
                    <div class="col-md-3 mb-1">
                        <label class="col-form-label" for="ReciboNumero">Nro Operacion</label>
                        <input type="text" class="form-control" name="ReciboNumero" id="ReciboNumero" placeholder="NUMERO DE OPERACION" autocomplete="off">
                    </div>
                    <div class="col-md-3 mb-1">
                        <div class="row">
                            <div class="col">
                                <label class="col-form-label" for="ReciboNumero">Moneda</label>
                            </div>
                            <div class="col">
                                <label class="col-form-label" for="ReciboNumero">Banco</label>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col">
                                <select class="form-control" name="IdMoneda" id="IdMoneda" onchange="actualizarCambiosPorMoneda();">
                                    <option value=""> - SELECCIONE - </option>
                                    <?php foreach ( GSS_MonedaMastFN::selectAll() as $o_GSS_MonedaMastBN ){ ?>
                                        <option value="<?=$o_GSS_MonedaMastBN->getIdMoneda()?>" > <?=$o_GSS_MonedaMastBN->getDescripcion()?> </option>
                                    <?php } ?>
                                </select>
                            </div>
                            <div class="col">
                                <select class="form-control" name="IdBanco" id="IdBanco"
                                        onchange="$('#IdCuenta')[0].options.length = 1; publicForSelectAjaxJSON('<?php echo buildUrlComplet( 'tsr.php/caja/requestCaja' ) ?>', 'TipoProc=BuscarCuentaBancaria&IdBanco='+this.value+'&IdMoneda='+$('#IdMoneda').val(), 'IdCuenta');"
                                >
                                    <option value=""> - SELECCIONE - </option>
                                    <?php foreach ( GSS_BancoFN::selectActivoCuenta() as $o_GSS_BancoBN ){ ?>
                                        <option value="<?=$o_GSS_BancoBN->getIdBanco()?>" > <?=$o_GSS_BancoBN->getDescripcionLocal()?> </option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-3 mb-1">
                        <label class="col-form-label" for="IdCuenta">Cuenta Deposito</label>
                        <select class="form-control" name="IdCuenta" id="IdCuenta" onchange="">
                            <option value=""> - SELECCIONE - </option>
                        </select>
                    </div>
                    <div class="col-md-3 mb-1">
                        <label class="col-form-label" for="TipoSalida">Tipo Salida</label>
                        <select class="form-control" name="TipoSalida" id="TipoSalida">
                            <option value="HTML">  HTML </option>
                            <option value="EXCEL"> EXCEL </option>
                        </select>
                    </div>
                </div>
                <div class="text-center mt-2">

                    <div class="form-row mx-0">

                        <div class="col-md-2 mb-1">
                            <input type="reset" class="btn btn-danger btn-block" value="LIMPIAR"  >
                        </div>
                        <div class="col-md-2 mb-1">
                            <input type="button" class="btn btn-primary btn-block" value="RESUMEN CAJA" onclick="verResumenPDF();" >
                        </div>
                        <div class="col-md-2 mb-1">
                            <input type="button" class="btn btn-primary btn-block" value="REPORTE LIBRO CAJA Y BANCOS" onclick="verReportePDF();" >
                        </div>
                        <div class="col-md-2 mb-1">
                            <input type="button" class="btn btn-primary btn-block" value="SALDOS CTAS X COBRAR" onclick="verReporteAnticuamiento();" >  <!--REPORTE DE ANTICUAMIENTO - DETALLE-->
                        </div>
                        <div class="col-md-2 mb-1">
                            <input type="button" class="btn btn-primary btn-block" value="MOV CTAS X COBRAR" onclick="verReporteMovimientoCtasPorCobrar();" >
                        </div>
                        <div class="col-md-2 mb-1">
                            <input type="button" class="btn btn-primary btn-block" value="DETALLE DE COBRANZA" onclick="verReporteDetalleCobranza();" >
                        </div>

                    </div>
                </div>
            </form>
        </div>
    </div>
</div>


<?php //include_partial( "gridRecibo" ); ?>

<script>

    $( "#FechaDocumento1" ).val( "<?=date( "Y-m-" )?>01" );
    /*
    $( document ).bind
    (
        'keyup',
        function( e )
        {
            if( e.which === 13 ) //ENTER
            {

            }
            if( e.which == 107 || e.which == 27 || e.which == 109 ) //tecla + | ESC | -
            {

            }
        }
    );
    */
</script>
