<?php
include('../../../configuracion.php');
include('../../inc/formulario.php');
include('config.php');
$id = isset($_GET['id']) ? $_GET['id'] : NULL;
$datos = $db->row(TABLA,"*","id='{$id}'");



$lastpago = $db->row("socio_cuotas_pagos","*","socio='{$datos->id}' and tipo='{$datos->socio_tipo}'","fecha_vencimiento desc");
$fechater = date("Y-m-d",strtotime($lastpago->fecha_vencimiento));
$fechaactual = date("Y-m-d");

$cuotas_sinpagos = $db->results("socio_cuotas","*","fecha_vencimiento>'{$fechater}' AND fecha_vencimiento<'{$fechaactual}' AND tipo='{$datos->socio_tipo}'","fecha_cobro asc");
$cuotasvencidad = 0;
if(isset($cuotas_sinpagos)){
  $cuotasvencidad = count($cuotas_sinpagos);
}
$data = array("cuotas"=>@$cuotasvencidad);
$db->update("usuarios",$data,"id='{$weuser->id}'");





?>
<!doctype html>
<html class="fixed">
    
	<head>
		<?php include("../../inc/head.php")?>
		<!-- ESPACIO HEAD ADICIONALES -->

		<!-- FIN ESPACIO HEAD ADICIONALES -->
	</head>
	<body>
		<section class="body">
			<!-- start: header -->
			<?php include("../../inc/header.php")?>
			<!-- end: header -->
			<div class="inner-wrapper">
				<!-- start: sidebar -->
				<?php include("../../inc/side-left.php")?>
				<!-- end: sidebar -->
				
                    



                <div class="row">
							<div class="col">
								<section class="card">
									<header class="card-header">
										<div class="card-actions">
											<a href="#" class="card-action card-action-toggle" data-card-toggle></a>
											<a href="#" class="card-action card-action-dismiss" data-card-dismiss></a>
										</div>
						
										<h2 class="card-title">Detalle <?php echo $datos->nombre_completo?></h2>
									</header>
									<div class="card-body">
                                        
                                                    <div class="row justify-content-center">
                                                    <?php $contador = 0;?>
                                                    <?php foreach($cuotas_sinpagos as $cuo){?>
                                                    <div class="col-12 col-sm-4">
                                                    <div class="alert alert-danger" role="alert">
                                                        <div class="d-flex justify-content-between align-items-center">
                                                            <div class="text-5 fw-bold">Cuota</div>
                                                            <div class="text-3">VENCIDA el <?=date("Y/m/d",strtotime($cuo->fecha_vencimiento))?></div>
                                                            <?php if($contador==0){?>
                                                            <div><a href="<?=MAGO?>c/usuarios/pagar/<?=$datos->id?>&cuota=<?=$cuo->id?>" class="btn btn-primary text-light">PAGAR</a></div>
                                                            <?php }else{?>
                                                            <div><button type="button" class="btn  btn-light" disabled>PAGAR</button></div>
                                                            <?php }?>
                                                        </div>
                                                    </div>
                                                    </div>
                                                    <?php $contador++; }?>
                                                    
                                                    </div>


                                                    <div class="row row justify-content-center">
          
                                                        <div class="col-12 col-sm-8">

                                                            <h3 class="text-4 text-start">Movimientos</h3>
                                                            <ul class="list-group">
                                                                <?php $mispagos = $db->results("socio_cuotas_pagos","*","socio='{$datos->id}' and tipo='{$datos->socio_tipo}'","fecha_cobro desc","0,20"); ?>
                                                                <?php foreach($mispagos as $pp){?>
                                                                <li class="list-group-item d-flex justify-content-between align-items-center">
                                                                    Cuota <?=$pp->nombre?> ( <?=date("m/Y",strtotime($pp->fecha_cobro))?> )
                                                                    <button type="button" class="btn btn-link text-primary" data-bs-toggle="modal" data-bs-target="#pagoModal<?=$pp->id?>">Detalle <i class="bi bi-file-earmark-medical"></i></button>
                                                                </li>
                                                                <?php }?>
                                                                
                                                                </ul>

                                                              

                                                            
                                                        </div>
                                                        

                                                        </div>


									</div>
								</section>
							</div>
						</div>
						



                        <?php foreach($mispagos as $pp){?>
<!-- Modal -->
<div class="modal fade" id="pagoModal<?=$pp->id?>" tabindex="-1" aria-labelledby="pagoModal<?=$pp->id?>Label" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h1 class="modal-title fs-5" id="pagoModal<?=$pp->id?>Label">Comprobante de pago N°: 14113590</h1>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
      <table class="table">
            
            <tbody>
              <tr>
                <th scope="row" colspan="2">
                    <strong>Socio</strong><br>
                    <strong>Nombre:</strong> <?=$datos->nombre_completo?><br>

                    <strong>DNI:</strong> <?=$datos->rut?><br>

                    <strong>Fecha del comprobante:</strong> 3/2/2024 19:59:33
                </th>
              </tr>
              <tr>
                <th scope="row">
                  <strong>Detalle</strong>
                  <strong>Concepto:</strong> Cuota Activo Simple 2/2024
                </th>
                <td>$ 10500,00</td>
              </tr>
              <tr>
                <th scope="row" colspan="2">
                    <strong>Forma de pago</strong><br>
                    Tarjeta de Crédito<br>

                    <strong>Fecha de pago:</strong> 12/2/2024 20:35:51
                </th>
              </tr>
              <tr>
                <th scope="row" >
                  <strong>Monto total:</strong>


                </th>
                <td><strong>$ 10500,00</strong></td>
              </tr>
            </tbody>
          </table>
      </div>
      <div class="modal-footer">
        
        <button type="button" class="btn btn-light">IMPRIMIR</button>
        <button type="button" class="btn btn-primary" data-bs-dismiss="modal">OK</button>
      </div>
    </div>
  </div>
</div>
<?php }?>




                        <?php include("../../inc/publicado.php")?>


		
					

		<!-- NO TOCAR -->
		<?php include("../../inc/side-right.php")?>
		<?php include("../../inc/bottom.php")?>
		<!-- NO TOCAR -->

		
		<!-- ESPACIO JS ADICIONALES -->


    </body>
</html>