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

<style type="text/css">
body
{
    padding: 1px;
}
</style>

<script type="text/javascript">
showAlertBootStrap = function( elm_id_content, class_default, message_alert )
{
    var html_alert = '<div class="alert ' + class_default + ' alert-dismissible fade show" role="alert"> ' +
            '' + message_alert +
            '<button type="button" class="close" data-dismiss="alert" aria-label="Close">' +
                '<span aria-hidden="true">&times;</span>' +
            '</button>' +
        '</div>';
    $( "#" + elm_id_content ).append( html_alert );
}
</script>

<script type="text/javascript">
nuevoComprobante = function( tipo_documento )
{
    x = confirm( "Esta seguro de generar un nuevo Comprobante?" );
    if( x )
    {
        var strFormSerialize = 'idubicacion=<?=$s_IdUbicacion?>&idubicaclienteh=<?=$i_IdUbicaClienteH?>&tipo_proc=nuevo_comprobante&tipo_documento=' + tipo_documento ;
        executeAjaxJson
        ( 
            "<?php echo buildUrl( 'recephabit/requestUbicacion' ) ?>", 
            strFormSerialize,
            function( o_json )
            {
                console.log( o_json );
                if( o_json.error )
                {
                    showAlertBootStrap( 'content_alert', 'alert-danger', o_json.mensaje_error );
                    return false;
                }
                location.reload()
            } 
        );
    }
}
terminarServicioUbicacion = function( idestado )
{
    x = confirm( "Esta seguro de cambiar el Estado?" );

    if( x )
    {
        blockContent( 'content_nav_menu' );
        blockContent( 'content_comprobantes' );

        var strFormSerialize = 'idubicacion=<?=$s_IdUbicacion?>&idubicaclienteh=<?=$i_IdUbicaClienteH?>&tipo_proc=cerrar_ubicacion&id_estado=' + idestado ;
        executeAjaxJson
        ( 
            "<?php echo buildUrl( 'recephabit/requestUbicacion' ) ?>", 
            strFormSerialize,
            function( o_json )
            {
                unBlockContent( 'content_nav_menu' );
                unBlockContent( 'content_comprobantes' );

                console.log( o_json );
                if( o_json.error )
                {
                    showAlertBootStrap( 'content_alert', 'alert-danger', o_json.mensaje_error );
                    return false;
                }
                parent.buscarHabitaciones();
                parent.buscarSaunas();
                parent.ocultarModal();
            } 
        );
    }
}

cambiarEstadoProceso = function()
{
    x = confirm( "Esta seguro de cambiar el Estado?" );
    if( x )
    {
        //blockContent( 'content_nav_menu' );
        //blockContent( 'content_comprobantes' );

        var strFormSerialize = 'idubicacion=<?=$s_IdUbicacion?>&idubicaclienteh=<?=$i_IdUbicaClienteH?>&tipo_proc=cerrar_ubicacion_estado_proceso';
        executeAjaxJson
        ( 
            "<?php echo buildUrl( 'recephabit/requestUbicacion' ) ?>", 
            strFormSerialize,
            function( o_json )
            {
                //unBlockContent( 'content_nav_menu' );
                //unBlockContent( 'content_comprobantes' );

                console.log( o_json );
                if( o_json.error )
                {
                    showAlertBootStrap( 'content_alert', 'alert-danger', o_json.mensaje_error );
                    return false;
                }
                location.reload();
            } 
        );
    }
}
</script>

<!--<div class="dropdown-divider"></div>
                    <a class="dropdown-item" href="javascript:void(0);" onclick="terminarServicioUbicacion('1');">ESTADO LIMPIEZA</a>-->
<!--<div class="dropdown-divider"></div>
                    <a class="dropdown-item" href="javascript:void(0);" onclick="terminarServicioUbicacion('4');">ESTADO DISPONIBLE</a>-->

<nav class="navbar navbar-expand-lg fixed-top sticky-top navbar-light bg-light" id="content_nav_menu">
    <a class="navbar-brand mr-5 h1 text-info" href="javascript:void(0);"> <?=$o_SRV_UbicacionClienteHBN->getObjectUbicacion()->getNombre()?> - Comprobantes [ <?=$EstadoDesc?> ] </a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item dropdown active">
                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    Opciones
                </a>
                <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                    <?php if( $o_SRV_UbicacionClienteHBN->getEstadoProceso() == SRV_UbicacionClienteHBN::ESTADO_PENDIENTE ){ ?>
                    <a class="dropdown-item" href="javascript:void(0);" onclick="nuevoComprobante('BV');">NUEVO COMPROBANTE - BOLETA</a>
                    <a class="dropdown-item" href="javascript:void(0);" onclick="nuevoComprobante('FC');">NUEVO COMPROBANTE - FACTURA</a>

                    <div class="dropdown-divider"></div>
                    <a class="dropdown-item" href="javascript:void(0);" onclick="cambiarEstadoProceso();">TERMINAR ORDEN</a>                    
                    <?php } ?>
                    <?php if( $o_SRV_UbicacionClienteHBN->getEstadoProceso() == SRV_UbicacionClienteHBN::ESTADO_TERMINADO ){ ?>
                        <?php if( $o_SRV_UbicacionClienteHBN->getObjectUbicacion()->getObjectTipoUbicacion()->getIdTipoUbicacion() == 2 ){ ?>
                        <a class="dropdown-item" href="javascript:void(0);" onclick="terminarServicioUbicacion('2');">ESTADO SUCIO</a>
                        <?php } ?>
                        <?php if( $o_SRV_UbicacionClienteHBN->getObjectUbicacion()->getObjectTipoUbicacion()->getIdTipoUbicacion() == 3 ){ ?>
                        <a class="dropdown-item" href="javascript:void(0);" onclick="terminarServicioUbicacion('4');">ESTADO DISPONIBLE</a>
                        <?php } ?>
                    <?php } ?>

                </div>
            </li>
        </ul>
        <form class="form-inline my-2 my-lg-0">
            &nbsp;
            <!--
            <input class="form-control mr-sm-2" type="search" placeholder="Buscar" aria-label="Buscar">
            <button class="btn btn-outline-success my-2 my-sm-0" type="button">Buscar</button>-->
        </form>
    </div>
</nav>



<!--
<style type="text/css">
.dropdown-submenu 
{
    position: relative;
}
.dropdown-submenu a::after 
{
    transform: rotate(-90deg);
    position: absolute;
    right: 6px;
    top: .8em;
}
.dropdown-submenu .dropdown-menu 
{
    top: 0;
    left: 100%;
    margin-left: .1rem;
    margin-right: .1rem;
}
</style>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarTogglerDemo01">
    <a class="navbar-brand" href="#">Hidden brand</a>
    <ul class="navbar-nav mr-auto mt-2 mt-lg-0">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown link
        </a>
        <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
          <li><a class="dropdown-item" href="#">Action</a></li>
          <li><a class="dropdown-item" href="#">Another action</a></li>
          <li class="dropdown-submenu"><a class="dropdown-item dropdown-toggle" href="#">Submenu</a>
            <ul class="dropdown-menu">
              <li><a class="dropdown-item" href="#">Submenu action</a></li>
              <li><a class="dropdown-item" href="#">Another submenu action</a></li>
              <li class="dropdown-submenu"><a class="dropdown-item dropdown-toggle" href="#">Subsubmenu</a>
                <ul class="dropdown-menu">
                  <li><a class="dropdown-item" href="#">Subsubmenu action</a></li>
                  <li><a class="dropdown-item" href="#">Another subsubmenu action</a></li>
                </ul>
              </li>
              <li class="dropdown-submenu"><a class="dropdown-item dropdown-toggle" href="#">Second subsubmenu</a>
                <ul class="dropdown-menu">
                  <li><a class="dropdown-item" href="#">Subsubmenu action</a></li>
                  <li><a class="dropdown-item" href="#">Another subsubmenu action</a></li>
                </ul>
              </li>
            </ul>
          </li>
        </ul>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>
<script type="text/javascript">
$('.dropdown-menu a.dropdown-toggle').on
(
    'click', 
    function( e ) 
    {
        if ( !$( this ).next().hasClass( 'show' ) ) 
        {
            $( this ).parents( '.dropdown-menu' ).first().find( '.show' ).removeClass( "show" );
        }

        var $subMenu = $( this ).next( ".dropdown-menu" );
        $subMenu.toggleClass( 'show' );

        $( this ).parents( 'li.nav-item.dropdown.show' ).on
        (
            'hidden.bs.dropdown', 
            function( e ) 
            {
                $( '.dropdown-submenu .show' ).removeClass( "show" );
            }
        );
        return false;
    }
);
</script>
-->

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

<div class="card p-3 mb-2" id="content_comprobantes">

    <div>

        <?php foreach ( $a_SRV_UbicacionClienteDet as $o_SRV_UbicacionClienteDetBN ) { ?>

        <div class="card mr-2 mb-2" style="width: 18rem; float: left;">
            <div class="card-header">
                <?=VTA_DocumentoBN::getArrayEstados( $o_SRV_UbicacionClienteDetBN->getEstado() )?>
            </div>
            <div class="card-body">
                <h5 class="card-title"><?=$o_SRV_UbicacionClienteDetBN->getDocumentoSerie()."-".$o_SRV_UbicacionClienteDetBN->getDocumentoNumero()?></h5>
                <p class="card-text">
                    <?=$o_SRV_UbicacionClienteDetBN->getNombreCompleto()?><br>
                    Total S/. <?=$o_SRV_UbicacionClienteDetBN->getMontoTotal()?>
                </p>
                <a href="javascript:void(0);" class="btn btn-primary"
                    onclick="buscarComprobante( '<?=$o_SRV_UbicacionClienteDetBN->getIdTipoDocumento()?>_<?=$o_SRV_UbicacionClienteDetBN->getIdCompania()?>_<?=$o_SRV_UbicacionClienteDetBN->getNumeroDocumento()?>' );" 
                    >
                    Ingresar
                </a>
                <!--<a href="javascript:void(0);" class="btn btn-primary">Anular</a>-->
            </div>
        </div>

        <?php } ?>

    </div>
</div>


<script type="text/javascript">
buscarComprobante = function( id_comprobante )
{
    pr( id_comprobante );
    location.href = "<?=buildUrl( 'pro/detailVta', "s_TipoProc/upd/url_return/recephabit_comprobantesCliente/param_return/idhabitacion_$s_IdUbicacion/i_Id/")?>" + id_comprobante;
}
</script>

<script type="text/javascript">
parent.actualizarTotales();
</script>

