<?php use_helper('UrlFunctions'); ?>
<?php
$s_Param = '';
if( isset( $id ) )
{
    $s_Param = "id={$id}&idPr={$idPr}";
}
?>
<?php
$s_User = myUser::getUser()->getUserId();
if( isset( $TypeProcess ) )
{
    switch ( $TypeProcess )
    {
        case "Entregar":
            $o_Cr_prestamo_fileDP = new Cr_prestamo_fileDP();
            $o_Cr_prestamo_fileDP->setIdPrestamoFile( ( int ) $i_IdPr );
            $o_Cr_prestamo_fileDP->setEstado( "E" );
            $b_Result = $o_Cr_prestamo_fileDP->update();
        break;
    }
    if( $b_Result )
    {
        ?>
        <script>
        location.href = "<?php echo buildUrl('cli/datDocPeAd', $s_Param) ?>";
        </script>
        <?php
    }
}
?>
<script type="text/javascript">
abrirVentanaAdicionar = function()
{
    objMainTab.modalDialog( '<?php echo buildUrl('cli/datDocAddDoc', $s_Param."&tipo=2") ?>', {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:800, height:400 } );
};
abrirVentanaAnul = function( i_IdPr )
{
    location.href = "<?php echo buildUrl( 'cli/datDocPeAd', $s_Param ) ?>/i_IdPr/" + i_IdPr + "/TypeProcess/Entregar";
};
recargarApp = function()
{
    location.reload();
};
</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/datDocPeAd', $s_Param ) ?>?" + cadenaFormulario;
}

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

limpiarForm = function()
{
    $( 'Tipo' ).value = "";
    $( 'Estado' ).value = "";
    $( 'txtFechaInicial' ).value = "";
    $( 'txtFechaFinal' ).value = "";
}
</script>
<?php
$o_ClienteBean = new ClienteBean();
$o_ClienteBean->setIdCliente($id);
$o_class = new ClienteBL();
$a_ObjectBean = $o_class->busquedaCliente($o_ClienteBean);
if( $a_ObjectBean )
{
    $o_ClienteBean = $a_ObjectBean[0];
}

$o_PrestamoBean = new PrestamoBean();
$o_PrestamoBean->setIdPrestamo( $idPr );
$o_class = new PrestamoBL();
$a_ObjectBeanTemp = $o_class->busquedaPrestamo( $o_PrestamoBean );
$o_ObjectBean = $a_ObjectBeanTemp[0];
//echo "<pre>"; print_r( $o_ObjectBean ); echo "<pre>";
?>
<table class="cuerpo" width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td valign="top">
			 <form id="form1" name="form1" method="GET">
				<input type="hidden" name="control" value="1">
				
                <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/datPer', $s_Param) ?>';">Datos Personales</td>
                              <td class="mnuInactivoDer" type='maintTabguiaGeneral'><img src="/images/common/spacer.gif" width="8"></td>
                              <?php if( isset( $id ) && $id != "" ){ ?>
                              <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/datEval', $s_Param) ?>';">Datos de Evaluaci&oacute;n</td>
                              <td class="mnuInactivoDer" type='maintTabguiaGeneral'><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/datDoc', $s_Param) ?>';">Documentos</td>
                              <td class="mnuInactivoDer" type='maintTabguiaGeneral'><img src="/images/common/spacer.gif" width="8"></td>

                              <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/datDocPe', $s_Param) ?>';">Documentos de Prestamos</td>
                              <td class="mnuActivoDer" 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="5" cellpadding="5" border="0" >
                                            <tr>
                                                <!--<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>-->
                                                <td><label class="label req"><?php echo $o_ClienteBean->getNombreCompleto() ?> [ DNI: <?php echo $o_ClienteBean->getDni() ?> ]</label></td>
                                                <!--<td><label class="label req"></label></td>-->
                                            </tr>
                                        </table>
                                        <fieldset style="border: 1px solid #000000; margin-bottom: 10px; margin-top: 5px;">
                                            <table width="" cellspacing="5" cellpadding="5" border="0" >
                                                <tr>
                                                    <!--<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>-->
                                                    <td><label class="label req">Documentos de Prestamos &nbsp;&nbsp;&nbsp; >></label></td>
                                                    <td><label class="label req">Prestamo: <?php echo $idPr ?></label></td>
                                                    <td><input type="button" class="button" value="Volver al Listado" onclick="location.href='<?php echo buildUrl('cli/datDocPe', $s_Param) ?>';"/></td>
                                                </tr>
                                            </table>
                                        </fieldset>
                                        
                                        <fieldset style="border: 1px solid #000000; margin-bottom: 10px; margin-top: 5px;">
                                            <table width="" cellspacing="5" cellpadding="5" border="0" >
                                                <tr>
                                                    <td><label class="label req">Monto</label></td>
                                                    <td><label class="label">S/.&nbsp;<?=number_format($o_ObjectBean->getMontoTotal(),2)?></label></td>
                                                    <td><label class="label req">Interes</label></td>
                                                    <td><label class="label"><label class="label">S/.&nbsp;<?=$o_ObjectBean->getInteresPorcentaje()?></label></label></td>
                                                    <td><label class="label req">Estado</label></td>
                                                    <td><label class="label"><?if($o_ObjectBean->getEstado()=='P'){echo "Pendiente";} elseif($o_ObjectBean->getEstado()=='C') {echo "Cancelado";} elseif($o_ObjectBean->getEstado()=='M') {echo "Moroso";}elseif($o_ObjectBean->getEstado()=='I') {echo "Incompleto";}?></label></td>
                                                </tr>
                                                <tr>
                                                    <td><label class="label req">Fecha de Inicio</label></td>
                                                    <td><label class="label"><label class="label"><?=$o_ObjectBean->getFechaInicio()?></label></td>
                                                    <td><label class="label req">Fecha de Fin</label></td>
                                                    <td><label class="label"><label class="label"><?=$o_ObjectBean->getFechaVencimiento()?></label></td>
                                                    <td>&nbsp;</td>
                                                    <td>&nbsp;</td>
                                                </tr>
                                            </table>
                                        </fieldset>
                                        
                                        <table class="SubCabecera" width="100%" border="0" cellpadding="0" cellspacing="0" style="margin-bottom: 10px; margin-top: 5px;">
                                            <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( 'prestamo' );
                                                        $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="P" <?php if( $Estado=="P"){ echo "SELECTED"; } ?>>PENDIENTE</option>
                                                        <option value="E" <?php if( $Estado=="E"){ echo "SELECTED"; } ?>>ENTREGADO</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_prestamo_fileFN();
$o_class->setIdCliente( $id );
$o_class->setIdPrestamo( $idPr );

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><label class="label req">Listado de Documentos ( <?php echo $i_NumReg ?> ) </label></td>
        <td align="right"><input type="button" align="right" value="Adicionar Documento" class="button" id="" onclick="abrirVentanaAdicionar();"></td>
    </tr>
    <tr>
        <td height="17" align="right" class="pager" colspan="2">
            <div id="contenedor">
                <?php echo $o_navigation->ContruirHTMLNavigation( 'contenedor', $strConcat ); ?>
            </div>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            	                        <table class="grid" width="100%" border="0" cellpadding="2" cellspacing="0">
                                            <tr height="35">
                                                <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_IdPrestamoFile = $o_Cr_cliente_fileBN->getIdPrestamoFile();
                                                    $i_IdTipoFile = $o_Cr_cliente_fileBN->getIdtipofile();
                                                    $o_Cr_tipo_fileFN = new Cr_tipo_fileFN();
                                                    $o_Cr_tipo_fileBN = $o_Cr_tipo_fileFN->selectByPK( $i_IdTipoFile );
                                                    if( $o_Cr_tipo_fileBN )
                                                    {
                                                        $s_Descripcion = $o_Cr_tipo_fileBN->getDescripcion();
                                                    }
                                                    $s_EstadoDes = $o_Cr_cliente_fileBN->getEstado()=="P"?"Pendiente":"Entregado";
                                                    ?>
                                                <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 if( $o_Cr_cliente_fileBN->getEstado() == "P" ){ ?>
                                                        <input type="button" class="button" value="Entregar" onclick="abrirVentanaAnul( '<?php echo $i_IdPrestamoFile ?>' );"/>&nbsp;
                                                        <?php } ?>
                                                        <input type="button" class="button" value="Ver" onclick="abrirVentanaVer( '<?php echo $i_IdPrestamoFile ?>', '2' );"/>&nbsp;
                                                    </td>
                                                </tr>
                                                <?php } ?>
                                            <?php } ?>
                                        </table>
                                        
            
        </td>
    </tr>
    <tr>
          <td colspan="2" 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/datDocPe', $s_Param) ?>'"/>
													    </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>