<?php use_helper('UrlFunctions'); ?>
<?php
//error_reporting(E_ALL);
//ini_set('display_errors','On'); //PARA PRODUCCION "Off"
$s_Param = '';
if( isset( $id ) )
{
    $s_Param = 'id='.$id;
}
?>
<?php
$s_User = myUser::getUser()->getUserId();
if( isset( $TypeProcess ) )
{
    switch ( $TypeProcess )
    {
        case "Anular":
            $o_Cr_cliente_fileDP = new Cr_cliente_fileDP();
            $o_Cr_cliente_fileDP->setIdClienteFile( ( int ) $i_IdTipoFile );
            //$o_Cr_cliente_fileDP->setEliminado( 1 );
            //$o_Cr_cliente_fileDP->setUsuarioEliminado( $s_User );
            //$o_Cr_cliente_fileDP->setFechaEliminado( date( "Y-m-d H:i:s" ) );
            $o_Cr_cliente_fileDP->setEstado( "I" );
            $b_Result = $o_Cr_cliente_fileDP->update();
        break;
        case "Eliminar":
            $o_Cr_cliente_fileDP = new Cr_cliente_fileDP();
            $o_Cr_cliente_fileDP->setIdClienteFile( ( int ) $i_IdTipoFile );
            $o_Cr_cliente_fileDP->setEliminado( 1 );
            $o_Cr_cliente_fileDP->setUsuarioEliminado( $s_User );
            $o_Cr_cliente_fileDP->setFechaEliminado( date( "Y-m-d H:i:s" ) );
            //$o_Cr_cliente_fileDP->setEstado( "I" );
            $b_Result = $o_Cr_cliente_fileDP->update();
        break;
    }
    if( $b_Result )
    {
        ?>
        <script>
        location.href = "<?php echo buildUrl('cli/datDoc', $s_Param) ?>";
        </script>
        <?php
    }
}
?>
<script type="text/javascript">
abrirVentanaAdicionar = function()
{
    objMainTab.modalDialog( '<?php echo buildUrl('cli/datDocAddDoc', $s_Param."&tipo=1") ?>', {height:300} );
};
abrirVentanaVer = function( i_IdTipoFile, i_Tipo )
{
    objMainTab.modalDialog( '<?php echo buildUrl('cli/datDocVer', $s_Param) ?>/i_IdTipoFile/' + i_IdTipoFile + "/i_Tipo/" + i_Tipo, { width:920, height:430 } );
};
abrirVentanaAnul = function( i_IdTipoFile )
{
    location.href = "<?php echo buildUrl( 'cli/datDoc', $s_Param ) ?>/i_IdTipoFile/" + i_IdTipoFile + "/TypeProcess/Anular";
};
abrirVentanaEli = function( i_IdTipoFile )
{
    location.href = "<?php echo buildUrl( 'cli/datDoc', $s_Param ) ?>/i_IdTipoFile/" + i_IdTipoFile + "/TypeProcess/Eliminar";
};
recargarApp = function()
{
    location.href = "<?php echo buildUrl( 'cli/datDoc', $s_Param ) ?>";
};
</script>
<script type="text/javascript">
validatePass = function()
{
	valid.onSubmit = false;
};

concatValueStr = function( s_Cadena )
{
    var cadenaFormulario = $('form1').serialize();
    cadenaFormulario = cadenaFormulario + "&" + s_Cadena;
    location.href = "<?php echo buildUrl('cli/datDoc', "") ?>?" + cadenaFormulario;
}

buscarLista = function()
{
    concatValueStr( '' );
}

limpiarForm = function()
{
    $( 'Tipo' ).value = "";
    $( 'Estado' ).value = "";
    $( 'txtFechaInicial' ).value = "";
    $( 'txtFechaFinal' ).value = "";
}
</script>
<img src="/images/common/spacer.gif" width="10">
<table class="cuerpo" width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
    <td height="0">
      <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
          <td class="titleBody">
            <li>Cliente</li>
            <span class="subtitle"><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:::&nbsp;Documentos</I></span></td>
          <td align="right" valign="baseline">&nbsp;</td>
        </tr>
      </table>
    </td>
  </tr>
	<tr>
		<td valign="top">
			 <form id="form1" name="form1" method="GET">
				<input type="hidden" name="control" value="1">
				<input type="hidden" name="id" value="<?php echo $id ?>">
                <input type="hidden" name="TypeProcess" value=""/>
                        <table id="tabShowScan" cellpadding="0" cellspacing="0" class="" style="margin-top: 5px;">
                            <tr>
                              <td class="mnuInactivoIzq" type='maintTabguiaGeneral'><img src="/images/common/spacer.gif" width="7"></td>
                              <td class="mnuInactivoTxt" type='maintTabguiaGeneral' nowrap onclick="location.href='<?php echo buildUrl('cli/edit', $s_Param) ?>';">Datos Generales</td>
                              <td class="mnuInactivoDer" type='maintTabguiaGeneral'><img src="/images/common/spacer.gif" width="8"></td>
                              <?php if( isset( $id ) && $id != "" ){ ?>
                              

                              <td class="mnuActivoIzq" type='maintTabguiaGeneral'><img src="/images/common/spacer.gif" width="7"></td>
                              <td class="mnuActivoTxt" type='maintTabguiaGeneral' nowrap onclick="location.href='<?php echo buildUrl('cli/datDoc', $s_Param) ?>';">Documentos</td>
                              <td class="mnuActivoDer" type='maintTabguiaGeneral'><img src="/images/common/spacer.gif" width="8"></td>

                              <td><img src="/images/common/spacer.gif" width="8"></td>
			          <td class="mnuInactivoIzq" type='maintTabguiaGeneral'><img src="/images/common/spacer.gif" width="7"></td>
			          <td class="mnuInactivoTxt" type='maintTabguiaGeneral' nowrap onclick="location.href='<?php echo buildUrl('cli/datInfocorp', $s_Param) ?>';">Infocorp</td>
			          <td class="mnuInactivoDer" type='maintTabguiaGeneral'><img src="/images/common/spacer.gif" width="8"></td>
                              <?php } ?>
                            </tr>
                        </table>

                        <table width="100%" cellspacing="2" cellpadding="2" border="0" class="marco marcoForm">
                            <tr>
                                <td nowrap="nowrap">
                                    <fieldset>

                                        <table width="100%" cellspacing="1" cellpadding="2" border="0" >
                                            <tr>
                                                <td align="right"><input type="button" align="right" value="Adicionar Documento" class="button" id="" onclick="abrirVentanaAdicionar();"></td>
                                            </tr>
                                        </table>

                                        <table class="SubCabecera" width="100%" border="0" cellpadding="0" cellspacing="0">
                                            <tr>
                                                <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                                <td><label class="label" for="Tipo">Tipo</label></td>
                                                <td>
                                                    <select name="Tipo" id="Tipo" >
                                                        <option value=""> - SELECCIONE - </option>
                                                        <?php
                                                        $o_Cr_tipo_fileFN = new Cr_tipo_fileFN();
                                                        $o_Cr_tipo_fileFN->setView( 'cliente' );
                                                        $a_Cr_tipo_file = $o_Cr_tipo_fileFN->select();
                                                        ?>
                                                        <?php foreach ( $a_Cr_tipo_file as $i_Key => $o_Cr_tipo_fileBN ){ ?>
                                                        <option value="<?php echo $o_Cr_tipo_fileBN->getIdtipofile() ?>" <?php if( $Tipo==$o_Cr_tipo_fileBN->getIdtipofile() ){ echo "SELECTED"; } ?>> <?php echo $o_Cr_tipo_fileBN->getDescripcion() ?> </option>
                                                        <?php } ?>
                                                    </select>
                                                </td>
                                                <td><label class="label" for="Estado">Estado</label></td>
                                                <td>
                                                    <select name="Estado" id="Estado" >
                                                        <option value=""> - SELECCIONE - </option>
                                                        <option value="A" <?php if( $Estado=="A"){ echo "SELECTED"; } ?>>ACTIVO</option>
                                                        <option value="I" <?php if( $Estado=="I"){ echo "SELECTED"; } ?>>ANULADO</option>
                                                    </select>
                                                </td>
                                                <td>
                                                    <input class="text" type="text" ondblclick="this.value=''" size="8" maxlength="10" name="txtFechaInicial" id="txtFechaInicial" value="<?php echo $txtFechaInicial ?>" /><button type="button" onclick="return false" id="btnFechaInicial">...</button>
                                                    <script type="text/javascript">
                                                    document.getElementById( "txtFechaInicial" ).disabled = false;
                                                    Calendar.setup( { inputField : "txtFechaInicial", ifFormat : "%Y-%m-%d", daFormat : "%Y-%m-%d", button   : "btnFechaInicial" } );
                                                    </script>
                                                </td>
                                                <td><label class="label" for="txtFechaFinal">Fecha Final</label></td>
                                                <td>
                                                    <input class="text" type="text" ondblclick="this.value=''" size="8" maxlength="10" name="txtFechaFinal" id="txtFechaFinal" value="<?php echo $txtFechaFinal ?>" /><button type="button" onclick="return false" id="btnFechaFinal">...</button>
                                                    <script type="text/javascript">
                                                    document.getElementById( "txtFechaFinal" ).disabled = false;
                                                    Calendar.setup( { inputField : "txtFechaFinal", ifFormat : "%Y-%m-%d", daFormat : "%Y-%m-%d", button   : "btnFechaFinal" } );
                                                    </script>
                                                </td>
                                                <td>
                                                    <input type="button" class="button" value="Buscar" onclick="buscarLista();"/>
                                                    <input type="button" class="button" value="Limpiar" onclick="limpiarForm();"/>
                                                </td>
                                            </tr>
                                        </table>
                                        
                                            <?php
                                            $o_class = new Cr_cliente_fileFN();
                                            $o_class->setIdCliente( $id );
                                            $o_class->setEliminado( -1 );
                                            
                                            if( isset( $Estado ) && $Estado != "" ){ $o_class->setEstado( $Estado ); }
                                            if( isset( $Tipo ) && $Tipo != "" ){ $o_class->setIdtipofile( $Tipo ); }
                                            if( isset( $txtFechaInicial ) && $txtFechaInicial != "" ){ $o_class->addCondition( Cr_cliente_fileFN::FechaRegistro, ">=", $txtFechaInicial ); }
                                            if( isset( $txtFechaFinal ) && $txtFechaFinal != "" ){ $o_class->addCondition( Cr_cliente_fileFN::FechaRegistro, "<=", $txtFechaFinal ); }
                                            
$tamanioPag = 10;
if( !isset( $page ) ) $page = 1;
$limitInf = ( $page - 1 ) * $tamanioPag;

$a_ObjectBean = $o_class->select( $limitInf, $tamanioPag );
$i_NumReg     = $o_class->selectNumRows();

$o_navigation = new navigation();
$o_navigation->setPaginaActual( $page );
$o_navigation->setTamanioPagina( $tamanioPag );
$o_navigation->setTotalRegistros( $i_NumReg );
                                            
                                            ?>

<table class="marco" border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td height="17" align="right" class="pager">
            <div id="contenedor">
                <?php echo $o_navigation->ContruirHTMLNavigation( 'contenedor', $strConcat ); ?>
            </div>
        </td>
    </tr>
    <tr>
        <td>
            	                        <table class="grid" width="100%" border="0" cellpadding="2" cellspacing="0">
                                            <tr>
                                                <th width="5%" nowrap="nowrap">Nro</th>
                                                <th width="10%" nowrap="nowrap">Num Documento</th>
                        						<th width="5%" nowrap="nowrap">Tipo</th>
                        						<th width="5%" nowrap="nowrap">Estado</th>
                        						<th width="10%" nowrap="nowrap">Fecha de Registro</th>
                        						<th width="10%" nowrap="nowrap">Usr Registro</th>
                                                <th width="10%" nowrap="nowrap">Opciones</th>
                                            </tr>

                                            <?php if( $a_ObjectBean ){ ?>
                                                <?php foreach ( $a_ObjectBean as $i_Key => $o_Cr_cliente_fileBN ){ ?>
                                                    <?php
                                                    $i_IdClienteFile = $o_Cr_cliente_fileBN->getIdClienteFile();
                                                    $i_IdTipoFile = $o_Cr_cliente_fileBN->getIdClienteFile();
                                                    $i_IdTipoFile2 = $o_Cr_cliente_fileBN->getIdTipoFile();
                                                    $o_Cr_tipo_fileFN = new Cr_tipo_fileFN();
                                                    $o_Cr_tipo_fileBN = $o_Cr_tipo_fileFN->selectByPK( $i_IdTipoFile2 );
                                                    if( $o_Cr_tipo_fileBN )
                                                    {
                                                        $s_Descripcion = $o_Cr_tipo_fileBN->getDescripcion();
                                                    }
                                                    $s_EstadoDes = $o_Cr_cliente_fileBN->getEstado()=="A"?"Activo":"Anulado";
                                                    ?>
                                                <tr>
                                                    <td style="text-align: center;"><?php echo $i_Key + 1 ?></td>
                                                    <td style="text-align: center;"><?php echo $o_Cr_cliente_fileBN->getFileNumero() ?></td>
                                                    <td style="text-align: center;"><?php echo $s_Descripcion ?></td>
                                                    <td style="text-align: center;"><?php echo $s_EstadoDes ?></td>
                                                    <td style="text-align: center;"><?php echo $o_Cr_cliente_fileBN->getFechaRegistro() ?></td>
                                                    <td style="text-align: center;"><?php echo $o_Cr_cliente_fileBN->getUsuarioRegistro() ?></td>
                                                    <td style="text-align: center;">
														<?php
														$s_DirImages = "/images/uploadFiles/";
														$s_NombreFile = $o_Cr_cliente_fileBN->getNombreFile();
														$s_Destino = $s_DirImages.$s_NombreFile
														?>
                                                        <a class="button" target="_blank"  value="Ver" href="<?php echo $s_Destino;?>" >&nbsp;Ver&nbsp;</a> <!--onclick="abrirVentanaVer( '<?php echo $i_IdClienteFile ?>', '1' );"-->
														<!-- <input type="button" class="button" value="Ver" onclick="abrirVentanaVer( '<?php echo $i_IdClienteFile ?>', '1' );"/>&nbsp;-->
                                                        <input type="button" class="button" value="Anular" onclick="abrirVentanaAnul( '<?php echo $i_IdClienteFile ?>' );"/>&nbsp;
                                                        <?php if(myUser::getUser()->getRoleId() == "sys.gen"){?><input type="button" class="button" value="Eliminar" onclick="abrirVentanaEli( '<?php echo $i_IdClienteFile ?>' );"/>&nbsp;<?php }?>
                                                    </td>
                                                </tr>
                                                <?php } ?>
                                            <?php } ?>
                                        </table>
                                        
            
        </td>
    </tr>
    <tr>
          <td style="background-color:#005ea8; color:#FFFFFF">Total registros: <?=count($a_ObjectBean)?></td>
    </tr>
    
</table>
                                        
                                        
                                    </fieldset>

                                </td>
                            </tr>
                        </table>




				<table hspace="2px" class="marco" width="96%" cellpadding="0" cellspacing="0">
					<tr>
						<td valign="top" colspan="2">

                            <table style="pad">
                            </table>

								<table width="100%" border="0" cellpadding="0" cellspacing="0" style="background: #fff">
									<tr>
										<td height="0" width="100%">


											   <table width="100%" border="0" cellspacing="0" cellpadding="0">
													<tr>
														<td><img src="/images/common/spacer.gif" width="10"></td>
													</tr>
													<tr>
													    <td align="center">
															<input type="hidden" name="typeSubmit" id="typeSubmit">
															<input class="button" type="button" value="Anterior" onclick="location.href='<?php echo buildUrl('cli/edit', $s_Param) ?>'"/>
															<!--<input class="button" type="submit" value="Grabar" onclick="$('typeSubmit').value='ok';">-->
															<!--<input class="button" type="submit" value="Grabar y Siguiente" onclick="$('typeSubmit').value='next';">-->
															<!--<input class="button" type="button" value="Siguiente" onclick="location.href='<?php echo buildUrl('cli/datDocPe', $s_Param) ?>'"/>-->
															<input class="button" type="button" value="Cancelar" onclick="location.href='<?php echo buildUrl('cli/list', $s_Param."&block=001" ) ?>'"/>
													    </td>
													</tr>
													<tr>
														<td height="10">&nbsp;</td>
													</tr>
												</table>

										</td>
									</tr>
								</table>

						</td>
					</tr>
				</table>
			</form>
				<script type="text/javascript">
					var valid = new Validation( 'form1', { immediate : true } );
				</script>
		</td>
	</tr>
</table>