<?php
#var_dump($_SESSION['user_system']);
?>
<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( 'tipoordencompra/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( 'tipoordencompra/addedit', "block=001&s_TipoProc=upd&i_Id=")?>" + o_json.id;
							break;
							case "1":
								location.href = "<?=buildUrl( 'tipoordencompra/list', "block=001")?>";
							break;
						}
					} 
			   );
}
</script>
                <?php if( $o_COM_OrdenItemClasificacionBN->getIdOrdenClasificacion() ){ $s_Disabled = "disabled"; }else{ $s_Disabled = ""; } ?>
                <input type="hidden" name="i_Id" id="i_Id" value="<?=$o_COM_OrdenItemClasificacionBN->getIdOrdenClasificacion()?>">
                <div id="resultContent" style=""></div>
                <table width="100%">
                    <tr>
                        <td width="100%" valign="top" >
                            <fieldset class="formGen" style="margin-top:0px">
                                <table border="0" cellspacing="6" cellpadding="0" style="margin-left: 20px;" width="100%">
                                    <!--
                                    <tr>
                                        <td nowrap="nowrap" width="30%" class="cabecera"><label class="label req" for="IdCompania" >Empresa</label></td>
                                        <td nowrap="nowrap">
                                            <select <?=$s_Disabled?> class="combo required" id="IdCompania" name="IdCompania" id="IdCompania" name="IdCompania" onchange="$( '#IdAlmacen' )[0].options.length=1; publicForSelectAjaxJSON( '<?php echo buildUrl( 'tipoordencompra/request', 'block=001' ) ?>', $( 'form' ).serialize() + '&TipoProc=IdAlmacen', 'IdAlmacen' );" >
                                                <option value=""> - Seleccione - </option>
                                                <?php foreach ( $a_GSS_Compania as $i_Key => $o_a_GSS_CompaniaBN ){ ?>
                                                <option value="<?=$o_a_GSS_CompaniaBN->getIdCompania()?>" <?php if( $o_a_GSS_CompaniaBN->getIdCompania()==$o_COM_OrdenItemClasificacionBN->getIdCompania() ){ echo "SELECTED"; } ?> > <?=$o_a_GSS_CompaniaBN->getDescripcionCorta()?> </option>
                                                <?php } ?>
                                            </select>
                                        </td>
                                        <td nowrap="nowrap" width="20%" class="cabecera">&nbsp;</td>
                                    </tr>
                                    -->
                                    <input type="hidden" name="IdCompania" id="IdCompania" value="<?=myUser::getUser()->getIdBusiness()?>" />
                                    <tr>
                                        <td nowrap="nowrap" width="10%" class="cabecera"><label class="label req" for="IdOrdenClasificacion" >Código</label></td>
                                        <td nowrap="nowrap">
                                            <input class="text required" <?=$s_Disabled?> type="text" name="IdOrdenClasificacion" id="IdOrdenClasificacion" size="15" maxlength="10" value="<?=$o_COM_OrdenItemClasificacionBN->getIdOrdenClasificacion();?>"  onblur="this.value=this.value.toUpperCase();"/>
                                        </td>
                                        <td nowrap="nowrap" width="8%" class="cabecera">&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td nowrap="nowrap" class="cabecera"><label class="label req" for="CodigoSunat" >C&oacute;digo Sunat</label></td>
                                        <td nowrap="nowrap">
                                            <input class="text required" type="text" name="CodigoSunat" id="CodigoSunat" size="10" maxlength="15" value="<?=$o_COM_OrdenItemClasificacionBN->getCodigoSunat();?>"/>
                                        </td>
                                        <td nowrap="nowrap" class="cabecera">&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td nowrap="nowrap" class="cabecera"><label class="label req" for="Descripcion" >Descripci&oacute;n</label></td>
                                        <td nowrap="nowrap">
                                            <input class="text required" type="text" name="Descripcion" id="Descripcion" size="45" maxlength="200" value="<?=$o_COM_OrdenItemClasificacionBN->getDescripcion();?>"/>
                                        </td>
                                        <td nowrap="nowrap" class="cabecera">&nbsp;</td>
                                    </tr>
									<!--<tr>
                                        <td nowrap="nowrap" width="20%" class="cabecera"><label class="label req" for="IdAlmacen" >Almacén</label></td>
                                        <td nowrap="nowrap" width="20%">
                                            <select class="combo" id="IdAlmacen" name="IdAlmacen">
                                                <option value=""> - Seleccione - </option>
                                                    <?php foreach ( $a_ALM_AlmacenMast as $i_Key => $o_ALM_AlmacenMastBN ){ ?>
                                                     <option value="<?=$o_ALM_AlmacenMastBN->getIdAlmacen()?>" <?php if( $o_ALM_AlmacenMastBN->getIdAlmacen()==$o_ALM_ItemTipoBN->getIdAlmacen() ){ echo "SELECTED"; } ?>> <?=$o_ALM_AlmacenMastBN->getDescripcionLocal()?> </option>
                                                <?php } ?>
                                            </select>
                                        </td>
                                        <td nowrap="nowrap" class="cabecera">&nbsp;</td>
                                    </tr>-->
                                    <tr>
                                        <td nowrap="nowrap" class="cabecera"><label class="label req" for="IdItemTipo" >Tipo de Item</label></td>
                                        <td nowrap="nowrap">
                                            <select class="combo required" id="IdItemTipo" name="IdItemTipo">
                                                <option value=""> - Seleccione - </option>
                                                <?php foreach ( $a_ALM_ItemTipo as $i_Key => $o_ALM_ItemTipoBN ){ ?>
                                                <option value="<?=$o_ALM_ItemTipoBN->getIdItemTipo()?>" <?php if( $o_ALM_ItemTipoBN->getIdItemTipo()==$o_COM_OrdenItemClasificacionBN->getIdItemTipo() ){ echo "SELECTED"; } ?> > <?=$o_ALM_ItemTipoBN->getDescripcionLocal()?> </option>
                                                <?php } ?>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td nowrap="nowrap" class="cabecera"><label class="label req" for="Estado" >Estado</label></td>
                                        <td nowrap="nowrap">
                                            <select class="combo required" id="Estado" name="Estado" >
                                                <option value=""> - Seleccione - </option>
                                                <option value="A" <?php if( $o_COM_OrdenItemClasificacionBN->getEstado()=="A" ){ echo "SELECTED"; } ?>> ACTIVO </option>
                                                <option value="I" <?php if( $o_COM_OrdenItemClasificacionBN->getEstado()=="I" ){ echo "SELECTED"; } ?>> INACTIVO </option>
                                            </select>
                                        </td>
                                        <td nowrap="nowrap" class="cabecera">&nbsp;</td>
                                    </tr>
                                    <?php if( $o_COM_OrdenItemClasificacionBN->getIdOrdenClasificacion() ){ ?>
                                    <tr>
                                        <td colspan="3">
                                            <input type="button" class="button" value="Auditoria" id="btnAudi">
                                            <script>
                                            $( "#btnAudi" )
                                            .click
                                            (
                                                function()
                                                {
                                                    $( '#myIframe' ).attr( 'src', '<?=buildUrl( 'tipoordencompra/audi', 'block=001&i_Id='.$o_COM_OrdenItemClasificacionBN->getIdOrdenClasificacion() )?>' );
                                                    $( '#dialog' ).dialog( 'open' );
                                                }
                                            )
                                            </script>
                                        </td>
                                    </tr>
                                    <?php } ?>
                                </table>
                            </fieldset>
                        </td>
                    </tr>
                </table>
                                                    
<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();

$( document ).ready(function() {
    if($("#IdCompania").val() != ''){
        $( '#IdAlmacen' )[0].options.length=1; 
        publicForSelectAjaxJSON( "<?php echo buildUrl( 'tipoordencompra/request', 'block=001' ) ?>", $( 'form' ).serialize() + '&TipoProc=IdAlmacen', 'IdAlmacen' );
    }
});    

</script>