<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( 'tipodocumentoalmacen/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( 'tipodocumentoalmacen/addedit', "block=001&s_TipoProc=upd&i_Id=")?>" + o_json.id;
                                break;
                                case "1":
                                    location.href = "<?=buildUrl( 'tipodocumentoalmacen/list', "block=001")?>";
                                break;
                            }
                        } 
                   );
}
</script>
<?php if($o_ALM_TipoDocumentoBN->getIdTipoDocumento() ){ $s_Disabled = "disabled"; }else{ $s_Disabled = ""; } ?>
<input type="hidden" name="i_Id" id="i_Id" value="<?=$o_ALM_TipoDocumentoBN->getIdTipoDocumento()?>">
<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="IdTipoDocumento">Codigo</label>
                    <input class="form-control" <?=$s_Disabled?> type="text" name="IdTipoDocumento" id="IdTipoDocumento" size="15" maxlength="2" value="<?=$o_ALM_TipoDocumentoBN->getIdTipoDocumento();?>"  onblur="this.value=this.value.toUpperCase();"/>&nbsp;(Ingresar sólo 2 caracteres)
            	</div>
                <div class="col-md-6 mb-1">
                    <label class="col-form-label" for="CodigoDescripcionSunat">Descripcion</label>
                    <input class="form-control" type="text" name="Descripcion" id="Descripcion" size="45" maxlength="200" value="<?=utf8_encode( $o_ALM_TipoDocumentoBN->getDescripcion() );?>"/>
            	</div>
            </div>
            <div class="form-row mx-2">
                <div class="form-check form-check-inline">
                	<br>
                    <input type="checkbox" class="form-check-input" id="EsFiscalFlag" name="EsFiscalFlag"  value="S" <?php if( $o_ALM_TipoDocumentoBN->getEsFiscalFlag()=="S" ){ echo "CHECKED"; } ?> onclick="validarDocumentoFiscal();" >
                    <label class="col-form-label" for="EsFiscalFlag">Es del tipo Fiscal</label>
                </div>
            </div>
            <div class="form-row mx-2">
                <div class="form-check form-check-inline">
                	<br>
                    <input type="checkbox" class="form-check-input" id="TransaccionSistemaFlag" name="TransaccionSistemaFlag"  value="S" >
                    <label class="col-form-label" for="TransaccionSistemaFlag">Transaccion del sistema</label>
                </div>
                
            </div>
            
            <div class="form-row mx-0">
                <div class="col-md-6 mb-1">
                    <label class="col-form-label" for="CodigoSunat">Codigo Sunat</label>
                    <input class="form-control" type="text" name="CodigoSunat" id="CodigoSunat" size="15" maxlength="10" value="<?=$o_ALM_TipoDocumentoBN->getCodigoSunat();?>"/>
                </div>
                <div class="col-md-6 mb-1">
                    <label class="col-form-label" for="Estado">Estado</label>
                    <select class="form-control" name="Estado" id="Estado" >
                    	<option value=""> - Seleccione - </option>
                        <option value="A" <?php if( $o_ALM_TipoDocumentoBN->getEstado()=="A" ){ echo "SELECTED"; } ?>> ACTIVO </option>
                        <option value="I" <?php if( $o_ALM_TipoDocumentoBN->getEstado()=="I" ){ echo "SELECTED"; } ?>> INACTIVO </option>
                    </select>
                </div>
            </div>
             
            
            <?php if( $o_ALM_TipoDocumentoBN->getIdTipoDocumento() ){ ?>
            <br>
            
            <button type="button" class="btn btn-primary btn-lg btn-block" id="btnAudi">Auditoria</button>
            
                   <script>
                    $( "#btnAudi" )
                    .click
                    (
                        function()
                        {
                            $( '#myIframe' ).attr( 'src', '<?=buildUrl( 'tipodocumentoalmacen/audi', 'block=001&i_Id='.$o_ALM_TipoDocumentoBN->getIdTipoDocumento() )?>' );
                            $( '#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>
validarDocumentoFiscal = function()
{
    $( "#CodigoSunat" ).removeClass( "required" );
    if ( $( '#EsFiscalFlag' ).is( ':checked' ) ) 
    {
        $( "#CodigoSunat" ).addClass( "required" );
    }
}

$.validator.setDefaults
(
    {
        submitHandler: function( form ) 
        {
            ejecutarGuardar();
        }
    }
);
$( "#form1" ).validate();

validarDocumentoFiscal();
</script>