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

<style>
.grid
{
    border: 1px solid #77d5f7;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    border-bottom-right-radius: 5px;
    border-bottom-left-radius: 5px;
}
.grid th 
{
    border-color: #77d5f7;
    background-color: #0a7db1;
    font-weight: normal;
    font-size: 11px;
    font-family: Verdana,Arial,sans-serif;
    height: 24px;
    padding: 0 2px;
}
.grid td 
{
    border-left: 0 none;
    border-right-color: #77d5f7;
    border-right-style: solid;
    border-right-width: 1px;
    border-bottom-color: #77d5f7;
    border-bottom-style: solid;
    border-bottom-width: 1px;
    padding: 0 2px;
    /*white-space: pre;*/
    height: 22px;
    /*border: 1px solid #77d5f7;*/
}
.grid td div
{
    overflow: hidden; white-space: nowrap; width: 150px; font-size: 10px;
}
.grid td label
{
    margin-right: 0;
}
</style>

<script>
mostrarCargaImg = function(){ $('#s_ImagenLoad')[0].style.display = 'inline'; }
ocultarCargaImg = function(){ $('#s_ImagenLoad')[0].style.display = 'none'; }

mostrarMensajeError = function( s_MensajeError )
{
    $( "#resultContent" ).html( '<div id="mensaje_error_content" class="error">' + s_MensajeError + '</div>' );
    setTimeout( function(){ $( "#mensaje_error_content" ).fadeOut( 800 ).fadeIn( 800 ).fadeOut( 500 ).fadeIn( 500 ).fadeOut( 300 ); }, 8000 );
}

addeditCaja = function( Tipo, IdCompania, IdSucursal, IdCaja )
{
    $( '#myIframe' ).attr( 'src', '<?=buildUrl( 'addemp/addeditCaja' )?>IdCompania/' +  IdCompania + "/IdSucursal/" + IdSucursal + "/TipoProc/" + Tipo + "/IdCaja/" + IdCaja );
    $( '#dialog' ).dialog( 'open' );
}

actualizaPagina = function()
{
    location.reload();
}
</script>

<div class="titleBody descripProy">
    <ul>
        <li>
            Editar Empresa
        </li>
    </ul>
</div>
<table class="cuerpo" width="99%" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td valign="top">
            <form id="form1" name="form1" method="POST" onsubmit=""  enctype="multipart/form-data">
                <input type="hidden" name="TypeProc" value="1">
                <input type="hidden" name="Control" value="1">
                <table class="" width="99%">
                    <tr>
                        <td valign="top">
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td>
                                        <table id="tabShowScan" cellpadding="0" cellspacing="0" class="mnuElement">
                                            <tr>
                                                <td class="mnuInactivoIzq"><img src="<?=Constantes::ROOT_DIR_IMG?>common/spacer.gif" width="0" /></td>
                                                <td class="mnuInactivoTxt" nowrap="nowrap" onclick="location.href='<?=buildUrl( 'addemp/edit', "block=001&i_Id=".$i_Id )?>';">General</td>
                                                <td class="mnuInactivoDer"><img src="<?=Constantes::ROOT_DIR_IMG?>common/spacer.gif" width="1" /></td>
                                                
                                                <td class="mnuInactivoIzq"><img src="<?=Constantes::ROOT_DIR_IMG?>common/spacer.gif" width="0" /></td>
                                                <td class="mnuInactivoTxt" nowrap="nowrap" onclick="location.href='<?=buildUrl( 'addemp/addProd', "block=001&i_Id=".$i_Id )?>';">Sucursal</td>
                                                <td class="mnuInactivoDer"><img src="<?=Constantes::ROOT_DIR_IMG?>common/spacer.gif" width="1" /></td>
                                                
                                                <td class="mnuInactivoIzq"><img src="<?=Constantes::ROOT_DIR_IMG?>common/spacer.gif" width="0" /></td>
                                                <td class="mnuInactivoTxt" nowrap="nowrap" onclick="location.href='<?=buildUrl( 'addemp/addCrianza', "block=001&i_Id=".$i_Id )?>';">Almac&eacute;n</td>
                                                <td class="mnuInactivoDer"><img src="<?=Constantes::ROOT_DIR_IMG?>common/spacer.gif" width="1" /></td>

                                                <td class="mnuInactivoIzq"><img src="<?=Constantes::ROOT_DIR_IMG?>common/spacer.gif" width="0" /></td>
                                                <td class="mnuInactivoTxt" nowrap="nowrap" onclick="location.href='<?=buildUrl( 'addemp/detPtoVta', "i_Id=".$i_Id )?>';">Punto de Venta</td>
                                                <td class="mnuInactivoDer"><img src="<?=Constantes::ROOT_DIR_IMG?>common/spacer.gif" width="1" /></td>

                                                <td class="mnuActivoIzq"><img src="<?=Constantes::ROOT_DIR_IMG?>common/spacer.gif" width="0" /></td>
                                                <td class="mnuActivoTxt" nowrap="nowrap" onclick="location.href='<?=buildUrl( 'addemp/addCaja', "block=001&i_Id=".$i_Id )?>';">Caja</td>
                                                <td class="mnuActivoDer"><img src="<?=Constantes::ROOT_DIR_IMG?>common/spacer.gif" width="1" /></td>

                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                
                                <tr>
                                    <td class="marco">
                                        <table class="" width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
                                            <tr>
                                                <td width="100%" valign="top">
                                                
                                                    <div style="padding:0px 0px 0px 0px;;width:100%">
                                                    
                                                        <?php include_partial( "infohead", array( "o_GSS_CompaniaBN" => $o_GSS_CompaniaBN ) ); ?>

                                                    </div>
                                                    <br>

<script>
    actualizarOperacionCaja = function( ElmValor )
    {
        blockContent( "content_opecaja" );
        var s_param = "tipo_proc=actualizar_operacion_caja&EstadoOperacionCaja=" + ElmValor + "&IdCompania=<?=$o_GSS_CompaniaBN->getIdCompania()?>";
        executeAjaxJson
        (
            "<?php echo buildUrl( 'addemp/request' ) ?>",
            s_param,
            function( o_json )
            {
                unBlockContent( 'content_opecaja' );
                if( o_json.error )
                {
                    mostrarMensajeError( o_json.mensaje_error );
                    return false;
                }
            }
        );
    }
</script>
<fieldset class="formGen" style="">
    <table class="marco" cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr>
            <td>
                <label> Empresa </label>
                <select class="combo" name="cboEmpresa">
                    <option value=""> - SELECCIONE - </option>
                    <?php foreach ( $a_GSS_CompaniaFiltro as $i_Key => $o_GSS_CompaniaBN ){ ?>
                        <option value="<?=$o_GSS_CompaniaBN->getIdCompania()?>" <?php if( $s_CompaniaFiltro == $o_GSS_CompaniaBN->getIdCompania() ){ echo "selected"; } ?> > <?=$o_GSS_CompaniaBN->getDescripcionCorta()?> </option>
                    <?php } ?>
                </select>

                <label> Caja </label>
                <select class="combo" name="cboCaja">
                    <option value=""> - SELECCIONE - </option>
                    <?php foreach ( $a_FCO_Caja as $i_Key => $o_FCO_CajaBN ){ ?>
                        <option value='<?=$o_FCO_CajaBN->getIdCaja()?>' <?php if( $s_CajaFiltro == $o_FCO_CajaBN->getIdCaja() ){ echo "selected"; } ?> > <?=$o_FCO_CajaBN->getDescripcion()?> </option>
                    <?php } ?>
                </select>

                <label> Usuario </label>
                <select class="combo" name="cboUsuario">
                    <option value=""> - SELECCIONE - </option>
                    <?php foreach ( $a_SEG_UsuarioFiltro as $i_Key => $o_SEG_UsuarioBN ){ ?>
                        <option value='<?=$o_SEG_UsuarioBN->getIdUsuario()?>' <?php if( $s_UsuarioFiltro == $o_SEG_UsuarioBN->getIdUsuario() ){ echo "selected"; } ?> > <?=$o_SEG_UsuarioBN->getIdUsuario()?> </option>
                    <?php } ?>
                </select>

                <input type="submit" class="button" value="Buscar">
                <input type="button" class="button" value="Limpiar" onclick="location.href='<?=buildUrl( 'addemp/detPtoVta', "i_Id=".$i_Id )?>';">
            </td>
            <td align="right" id="content_opecaja">
                <label for="OpeCierreCaja"> Operaciones con Cierre de Caja </label>
                <select class="combo" name="OpeCierreCaja" onchange="actualizarOperacionCaja( this.value );">
                    <option value=""> - SELECCIONE - </option>
                    <option value="1" <?php if( $o_GSS_CompaniaBN->getOpeCierreCaja() === 1 ){ echo "SELECTED"; } ?> > SI </option>
                    <option value="0" <?php if( $o_GSS_CompaniaBN->getOpeCierreCaja() === 0 ){ echo "SELECTED"; } ?>> NO </option>
                </select>
            </td>
        </tr>
    </table>
</fieldset>

<br>

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

<fieldset class="formGen" style="margin-top:0px">
    <legend class="fielsettex">Lista de Caja asociado</legend> 
    <div id="content_result_grid1">


                <?php foreach ( $a_GSS_Compania as $i_Key => $o_GSS_CompaniaBN ){ ?>
            <table class="grid" cellspacing="0" cellpadding="5" border="0" align="center" width="100%" style="border-bottom: 1px solid #999999;">
                <tr>
                    <th width="1%" align="center" class="header"> &nbsp; </th>
                    <th width="80%" align="left" colspan="2" class=""><b><?=$o_GSS_CompaniaBN->getDescripcionCorta()?></b></th>
                </tr>
                    <?php if( isset( $a_LstSucursal[$o_GSS_CompaniaBN->getIdCompania()] ) ){ ?>
                        <?php foreach ( $a_LstSucursal[$o_GSS_CompaniaBN->getIdCompania()] as $i_Key => $o_GSS_SucursalBN ){ ?>
                <tr>
                    <td class="row" align=""></td>
                    <td align="" colspan=""><?=$o_GSS_SucursalBN->getDescripcion()?></td>
                    <th align="center" style="padding: 5px; background-color:#c0ebff; "> <input type="button" class="button" value="Nuevo Caja" onclick="addeditCaja( 'nvo', <?=$o_GSS_CompaniaBN->getIdCompania()?>, <?=$o_GSS_SucursalBN->getIdSucursal()?>, '' );"> </th>
                </tr>

                <tr>
                    <td colspan="3" style="padding: 5px;">

                        <table class="grid" cellspacing="0" cellpadding="5" border="0" align="center" width="100%">
                            <tr>
                                <td align="center" width=""> Descripci&oacute;n Caja </td>
                                <td align="center" width=""> Estado </td>
                                <?php foreach ( $a_SEG_Usuario as $o_SEG_UsuarioBN ){ ?>
                                    <?php 
                                    //$o_SEG_UsuarioCompaniaFN = new SEG_UsuarioCompaniaFN();
                                    //$o_SEG_UsuarioCompaniaBN = $o_SEG_UsuarioCompaniaFN->selectByPK( $o_GSS_CompaniaBN->getIdCompania(), $o_SEG_UsuarioBN->getIdUsuario() );
                                    //if( !$o_SEG_UsuarioCompaniaBN ){ continue; }
                                    ?>
                                    <td align="center" title="<?=$o_SEG_UsuarioBN->getUsuarioNombre()?>"> <?=$o_SEG_UsuarioBN->getIdUsuario()?> </td>
                                <?php } ?>
                            </tr>
                            <?php if( isset( $a_LstCaja[$o_GSS_CompaniaBN->getIdCompania()][$o_GSS_SucursalBN->getIdSucursal()] ) ){ ?>
                                <?php foreach ( $a_LstCaja[$o_GSS_CompaniaBN->getIdCompania()][$o_GSS_SucursalBN->getIdSucursal()] as $i_Key => $o_LstCajaBN ){ ?>
                                <?php
                                ?>
                                <tr>
                                    <td align="" width="10%" nowrap="">
                                        <div style="width: 280px;">
                                            <div style="display: inline-block; width: 60%;" >
                                                <a href="javascript:void(0);" onclick="addeditCaja( 'upd', <?=$o_GSS_CompaniaBN->getIdCompania()?>, <?=$o_GSS_SucursalBN->getIdSucursal()?>, '<?=$o_LstCajaBN->getIdCaja()?>' );">
                                                <?=$o_LstCajaBN->getDescripcion()?>
                                                </a>
                                            </div>
                                        </div>
                                    </td>
                                    <td align="center"><?=$o_LstCajaBN->getEstadoDesc()?></label></td>
                                    <?php foreach ( $a_SEG_Usuario as $o_SEG_UsuarioBN ){ ?>
                                        <?php 
                                        $o_FCO_CajaUsuarioFN = new FCO_CajaUsuarioFN();
                                        $o_FCO_CajaUsuarioBN = $o_FCO_CajaUsuarioFN->selectByPK( $o_LstCajaBN->getIdCaja(), $o_SEG_UsuarioBN->getIdUsuario(), $o_GSS_CompaniaBN->getIdCompania(), $o_GSS_SucursalBN->getIdSucursal() );

                                        //$o_SEG_UsuarioCompaniaFN = new SEG_UsuarioCompaniaFN();
                                        //$o_SEG_UsuarioCompaniaBN = $o_SEG_UsuarioCompaniaFN->selectByPK( $o_GSS_CompaniaBN->getIdCompania(), $o_SEG_UsuarioBN->getIdUsuario() );
                                        //if( !$o_SEG_UsuarioCompaniaBN ){ continue; }
                                        $s_Id  = $o_SEG_UsuarioBN->getIdUsuario()."|@|".$o_GSS_CompaniaBN->getIdCompania()."|@|".$o_LstCajaBN->getIdCaja()."|@|".$o_GSS_SucursalBN->getIdSucursal();
                                        $s_Id2 = str_replace( array( "." ), array( "" ), $o_SEG_UsuarioBN->getIdUsuario() )."_".$o_GSS_CompaniaBN->getIdCompania()."_".$o_LstCajaBN->getIdCaja()."_".$o_GSS_SucursalBN->getIdSucursal();
                                        ?>
                                        <td align="center" id="<?=$s_Id2?>">
                                            <input type="checkbox" 
                                                id=""
                                                name=""
                                                <?php if( $o_FCO_CajaUsuarioBN ){ echo "CHECKED"; } ?>
                                                value="<?=$s_Id?>"
                                                onclick="asociarDocumento( this, '<?=$s_Id2?>' );"
                                                > 
                                        </td>
                                    <?php } ?>
                                </tr>
                                <?php } ?>
                            <?php } ?>
                        </table>


                    </td>
                </tr>

                    <?php } ?>
                <?php } ?>
            </table>
                <?php } ?>


    </div>
</fieldset>

<br>

                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <table width="100%" border="0" style="margin-top: 10px;">
                                            <tr>
                                                <td align="center" width="55%">
                                                    <input type="button" class="button" value="Cancelar" onclick="location.href='<?php echo buildUrl( 'addemp/list', '' ) ?>'">
                                                    <input type="button" class="button" value="Anterior" onclick="location.href='<?php echo buildUrl( 'addemp/addProd', 'i_Id='.$i_Id ) ?>'">
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </form>
        </td>
    </tr>
    
</table>

<script type="text/javascript">
//ejemplo de tabs con iframe
//https://stackoverflow.com/questions/9042065/how-to-use-iframe-instead-of-div-with-jquery-ui-tabs
//http://jsfiddle.net/fordlover49/XHD5N/
asociarDocumento = function( elm, id )
{
    pr( elm.value );

    blockContent( id );

    var s_param = "tipo_proc=actualizar_doc_caja&value=" + elm.value;

    var tipo = "";
    if( $( elm ).is( ':checked' ) ) 
    {
        s_param += "&tipo=save";
    }
    else
    {
        s_param += "&tipo=del";
    }
        
    executeAjaxJson
    (
        "<?php echo buildUrl( 'addemp/request' ) ?>",
        s_param,
        function( o_json )
        {
            pr( o_json );
            unBlockContent( id );
            if( o_json.error )
            {
                mostrarMensajeError( o_json.mensaje_error );
                return false;
            }
        }
    );
}
</script>

<?=crearFuentePopupIframe( array( "div_id"=>"dialog", "iframe_id"=>"myIframe", "popup_title"=>"Recibo", "modal"=>true ) )?>