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

<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 ); }, 4000 );
    }
</script>
<script>
    ejecutarGuardar = function()
    {
        blockContent( 'content_form' );
        var strFormSerialize = $( 'form' ).serialize();
        executeAjaxJson
        (
            "<?php echo buildUrl( 'rangocantidades/saveDetailV3' ) ?>",
            strFormSerialize,
            function( o_json )
            {
                unBlockContent( 'content_buttons' );
                if( o_json.error )
                {
                    showAlertBootStrap( 'content_alert', 'alert-danger', o_json.mensaje_error );
                    return false;
                }

                location.reload();
            }
        );

        return false;
    }

    Delete = function( Id )
    {
        blockContent( 'content_form' );
        var strFormSerialize = $( 'form' ).serialize();
        executeAjaxJson
        (
            "<?php echo buildUrl( 'rangocantidades/DeleteDetail' ).  "ID/"  ?>" + Id,
            strFormSerialize,
            function( o_json )
            {
                unBlockContent( 'content_buttons' );
                if( o_json.error )
                {
                    showAlertBootStrap( 'content_alert', 'alert-danger', o_json.mensaje_error );
                    return false;
                }

                location.reload();
            }
        );
    }

    ActualizarDet = function( IdDet )
    {
        pr( 'content_det_' + IdDet );
        blockContent( 'content_det_' + IdDet );
        var strFormSerialize = $( '#content_det_' + IdDet ).find( "input, select" ).serialize();
        pr( strFormSerialize );
        executeAjaxJson
        (
            "<?php echo buildUrl( 'rangocantidades/saveDetailV3' )?>",
            strFormSerialize,
            function( o_json )
            {
                unBlockContent( 'content_det_' + IdDet );
                if( o_json.error )
                {
                    showAlertBootStrap( 'content_alert', 'alert-danger', o_json.mensaje_error );
                    return false;
                }

            }
        );
    }

</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"><?=$s_Titulo?></h4>
        </div>
        <div class="form-row mx-1">
            <button type="button" class="btn btn-primary btn-sm" onclick="location.href='<?=buildUrl( "rangocantidades/list" )?>';" >ir Listado</button>
        </div>
    </div>
</div>

<form id="form1" name="form1" method="POST" onsubmit="return ejecutarGuardar();"  enctype="multipart/form-data">
    <input type="hidden" name="TipoProc" id="TipoProc" value="nvo">
    <input type="hidden" name="TypeSub" id="TypeSub" value="0">
    <input type="hidden" name="i_Id" id="i_Id" value="<?= $i_Id ?>">
    <input type="hidden" name="Estado" id="Estado" value="A">

    <ul class="nav nav-tabs m-1" id="myTab" role="tablist" style="margin-bottom: 0px !important;">
    	<li class="nav-item">
    		<a class="nav-link" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true" onclick="location.href='<?=buildUrl( 'rangocantidades/addedit', "s_TipoProc=$s_TipoProc&i_Id=".$i_Id )?>';">General</a>
    	</li>
    	</li>
    	<li class="nav-item">
    		<a class="nav-link active" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false" onclick="location.href='<?=buildUrl( 'rangocantidades/detailV3', "s_TipoProc=$s_TipoProc&i_Id=".$i_Id )?>';">Detalle</a>
    	</li>
    </ul>

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

    <div class="card p-2" id="content_form">
        <div class="container">

            <div class="card" id="content_datos_cliente">
                <h5 class="card-header">DESCRIPCION</h5>
                <div class="card-body" style="padding: 10px;">
                    <div class="table-responsive" id="content_form">
                        <table class="table table-borderless" style="margin-bottom: 0px; line-height: 0.5; padding: .50rem; ">
                            <tbody>
                            <tr>
                                <th class="text-nowrap" style="color: #fc6d00;"> <?=$o_MST_RangoBN->getDescripcion()?> </th>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

            <div class="dropdown-divider"></div>

            <div class="card" id="content_datos_cliente">
                <h5 class="card-header">NUEVO REGISTRO</h5>
                <div class="card-body" style="padding: 10px;">
                    <div class="form-row mx-0">
                        <div class="col-md-5 mb-1">
                            <label class="col-form-label" for="Minimo">Minimo</label>
                            <input type="text" class="form-control" name="Minimo" id="Minimo" value="" required>
                        </div>
                        <div class="col-md-5 mb-1">
                            <label class="col-form-label" for="Maximo">Maximo</label>
                            <input type="text" class="form-control" name="Maximo" id="Maximo" value="" required>
                        </div>
                        <div class="col-md-2 mt-1">
                            <button type="submit" class="btn btn-primary btn-block" onclick="">AGREGAR</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>

<br>

<div class="card p-2" id="content_form">
    <div class="container">
        <div class="card" id="content_datos_cliente">
            <h5 class="card-header">DETALLES</h5>
            <div class="card-body" style="padding: 10px;">

                <?php foreach ( $a_Detalles as $i_Key => $Data ) {?>

                <div class="card p-2" id="content_form">
                    <div class="form-row mx-0" id="content_det_<?=$Data->getIdRangoDetalle();?>">
                        <input type="hidden" name="IdDet" id="IdDet" value="<?=$Data->getIdRangoDetalle();?>">
                        <input type="hidden" name="TipoProc" id="TipoProc" value="upd">
                        <input type="hidden" name="Estado" id="Estado" value="A">
                        <div class="col-md-2 mb-1">
                            <label class="col-form-label" for="Minimo">&nbsp;</label>
                            <input type="text" class="form-control text-center"  value="<?=$i_Key+1?>" disabled>
                        </div>
                        <div class="col-md-4 mb-1">
                            <label class="col-form-label" for="Minimo">Minimo</label>
                            <input type="text" class="form-control text-center" name="Minimo" id="Minimo_<?=$i_Key?>"  value="<?=$Data->getMinimo();?>" required>
                        </div>
                        <div class="col-md-4 mb-1">
                            <label class="col-form-label" for="Maximo">Maximo</label>
                            <input type="text" class="form-control text-center" name="Maximo" id="Maximo_<?=$i_Key?>"  value="<?=$Data->getMaximo();?>" required>
                        </div>
                        <div class="col-md-2 mt-1">
                            <button type="button" class="btn btn-danger btn-block" onclick="Delete( <?=$Data->getIdRangoDetalle();?> );">ELIMINAR</button>
                            <button type="button" class="btn btn-primary btn-block" onclick="ActualizarDet( <?= $Data->getIdRangoDetalle(); ?> );">ACTUALIZAR</button>
                        </div>
                    </div>
                </div>

                <div class="dropdown-divider"></div>

                <?php }?>

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

<div id="dialog" style="display:none;"><iframe id="myIframe" src="" frameborder="0" height="100%" width="100%"></iframe></div>
<script>
    objMainTab.modalUIDialog( "#dialog", { title : "Auditoria", width : 425, height  : 230 } );
</script>
                                                    
<script>

</script>