<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()
{
	mostrarCargaImg();
	var strFormSerialize = $( 'form' ).serialize();
    executeAjaxJson( 
                        "<?php echo buildUrl( 'tipoitem/saveAddEdit', "block=001" ) ?>", 
                        strFormSerialize,
                        function( o_json )
                        {
                            console.log( o_json );
                            ocultarCargaImg();
                            if( o_json.error )
                            {
                                mostrarMensajeError( o_json.mensaje_error );
                                return false;
                            }
                            //return false;
                            switch ( o_json.type_sub )
                            {
                                case "0":
                                    location.href = "<?=buildUrl( 'tipoitem/addedit', "block=001&s_TipoProc=upd&i_Id=")?>" + o_json.id;
                                break;
                                case "1":
                                    location.href = "<?=buildUrl( 'tipoitem/list', "block=001")?>";
                                break;
                            }
                        } 
                   );
}
</script>

<?php if( $o_ALM_ItemTipoBN->getIdItemTipo() ){ $s_Disabled = "disabled"; }else{ $s_Disabled = ""; } ?>
<input type="hidden" name="i_Id" id="i_Id" value="<?=$o_ALM_ItemTipoBN->getIdItemTipo()?>">
<div id="resultContent" style=""></div>

<div class="card">
    <div class="container">
                <div class="form-row mx-0">
                    <div class="col-md-6 mb-1">
                        <label class="col-form-label" for="IdItemTipo">Codigo</label>
                        <input type="text" class="form-control" name="IdItemTipo" id="IdItemTipo" placeholder="" value="<?=$o_ALM_ItemTipoBN->getIdItemTipo();?>" onblur="this.value=this.value.toUpperCase();" >
                	</div>
                    <div class="col-md-6 mb-1">
                        <label class="col-form-label" for="CodigoSunat">Codigo Sunat</label>
                        <input type="text" class="form-control" name="CodigoSunat" id="CodigoSunat" placeholder="" value="<?=$o_ALM_ItemTipoBN->getCodigoSunat();?>" onblur="this.value=this.value.toUpperCase();" >
                	</div>
            </div>
            <div class="form-row mx-0">
                <div class="col-md-6 mb-1">
                    <label class="col-form-label" for="DescripcionLocal">Descripcion</label>
                    <input type="text" class="form-control" name="DescripcionLocal" id="DescripcionLocal" placeholder="" value="<?=$o_ALM_ItemTipoBN->getDescripcionLocal();?>" onblur="this.value=this.value.toUpperCase();" required>
                </div>
                <div class="col-md-6 mb-1">
                    <label class="col-form-label" for="Estado">Estado</label>
                    <select class="form-control form-control-sm custom-select my-0 mr-sm-2" name="Estado" id="Estado" required>
                        <option value=""> - Seleccione - </option>
                        <option value="A" <?php if( $o_ALM_ItemTipoBN->getEstado()=="A" ){ echo "SELECTED"; } ?>> ACTIVO </option>
                        <option value="I" <?php if( $o_ALM_ItemTipoBN->getEstado()=="I" ){ echo "SELECTED"; } ?>> INACTIVO </option>
                    </select>
                </div>
            </div>
            
            <div class="form-group col-14"><hr style="border-top: 1px solid #8c8b8b;"></div>
            
            <div class="form-row mx-0">
                <div class="col-md-6 mb-1">
                    <label class="col-form-label" for="VerDiaSemanaFlag">Mostrar Dia Semana</label>
                    <select class="form-control form-control-sm custom-select my-0 mr-sm-2" name="VerDiaSemanaFlag" id="VerDiaSemanaFlag" required>
                        <option value=""> - Seleccione - </option>
                        <option value="S" <?php if( $o_ALM_ItemTipoBN->getVerDiaSemanaFlag()=="S" ){ echo "SELECTED"; } ?>> SI </option>
                        <option value="N" <?php if( $o_ALM_ItemTipoBN->getVerDiaSemanaFlag()=="N" ){ echo "SELECTED"; } ?>> NO </option>
                    </select>
                </div>
                <div class="col-md-6 mb-1">
                    <label class="col-form-label" for="DescripcionIngles">&nbsp;</label>
                    <div class="custom-control custom-checkbox mr-sm-2">
                    	<input type="checkbox" class="custom-control-input" id="TransacciondelSistemaFlag" name="TransacciondelSistemaFlag" <?php if( $o_ALM_ItemTipoBN->getTransacciondelSistemaFlag() ){ echo "checked"; } ?> >
                    	<label class="custom-control-label text-body" for="TransacciondelSistemaFlag">Movimiento en Kardex</label>
                    </div>
            	</div>
            </div>
             <div class="form-group col-14"><hr style="border-top: 1px solid #8c8b8b;"></div>
             <div class="form-row mx-0">
                <div class="col-md-6 mb-1">
                    <label class="col-form-label" for="IngenieriaFlag">Es Para Configuiracion - [Pack][Promo]</label>
                    <select class="form-control form-control-sm custom-select my-0 mr-sm-2" name="IngenieriaFlag" id="IngenieriaFlag" required>
                        <!-- <option value=""> - Seleccione - </option> -->
                        <option value="1" <?php if( $o_ALM_ItemTipoBN->getIngenieriaFlag()=="1" ){ echo "SELECTED"; } ?> > SI </option>
                        <option value="0" <?php if( $o_ALM_ItemTipoBN->getIngenieriaFlag()=="0" ){ echo "SELECTED"; } ?> > NO </option>
                    </select>
                </div>
                <div class="col-md-6 mb-1">
                    <label class="col-form-label" for="DescripcionIngles">Prefijo</label>
                    <input type="text" class="form-control" name="DescripcionIngles" id="DescripcionIngles" placeholder="" value="<?=$o_ALM_ItemTipoBN->getDescripcionIngles();?>" onblur="this.value=this.value.toUpperCase();" >
            	</div>
            </div>
            
            <?php if( $o_ALM_ItemTipoBN->getIdItemTipo() ){ ?>
            <br>
            <button type="button" class="btn btn-primary btn-lg btn-block" id="btnAudi">Auditoria</button>
            
                    <script>
                    $( "#btnAudi" )
                    .click
                    (
                        function()
                        {
                            $( '#myIframe' ).attr( 'src', '<?=buildUrl( 'tipoitem/audi', 'block=001&i_Id='.$o_ALM_ItemTipoBN->getIdItemTipo() )?>' );
                            $( '#dialog' ).dialog( 'open' );
                        }
                    )
                    </script>
            <br>
            <?php } ?>
            <div class="form-group col-14"><hr style="border-top: 1px solid #8c8b8b;"></div>
        
    </div>
</div>
                                                    
<div id="dialog"><iframe id="myIframe" src="" frameborder="0" height="100%" width="100%"></iframe></div>
<script>
    objMainTab.modalUIDialog( "#dialog", { title : "Auditoria", width : 425, height  : 230 } );
</script>
                                                    
<script>
$.validator.setDefaults
(
    {
        submitHandler: function( form ) 
        {
            ejecutarGuardar();
        }
    }
);
$( "#form1" ).validate();
</script>