<?php

if($_SESSION["perfil"] == "Especial"){

  echo '<script>

    window.location = "inicio";

  </script>';

  return;


}

$data2 = json_decode($_SESSION['arregloC'],true);
//var_dump($data2);

?>
<div class="content-wrapper">
  <section class="content-header">
    <h1>Detalle de cobranza</h1>
    <ol class="breadcrumb">
      <li><a href=""><i class="fa fa-dashboard"></i>Inicio</a></li>
      <li class="active">Detalle de cobranza</li>
    </ol>
  </section>

  <section class="content">

    <div class="row">
      <div class="col-lg-12 col-xs-12">
        <div class="box box-success">
          <form role="form" method="post" class="" enctype="multipart/form-data">
            <div class="row pt-4 mt-4">
              <div class="col-md-12 pt-4 sc"> 

               

                <div class="form-group form-space col-md-12">
                  <div class="panel panel-success">
                    <div class="panel-heading">
                      <center>
                        <h3 class="panel-title">Datos del Cliente</h3>
                      </center>
                    </div>
                    <div class="panel-body" style="padding:0px">
                      <div class="form-row">
                        <div class="form-group col-md-4">
                          <label for="inputCity">Nombres y Apellidos:</label>
                          <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-child"></i></span>

                            <input type="hidden" class="form-control" id="idpersona" name="idpersona" >
                            <input type="hidden" class="form-control" id="IdUsuario" name="IdUsuario" value="<?php echo $_SESSION["id"]; ?>">
                            <input type="hidden" class="form-control" id="CodigoContrato" name="CodigoContrato" >
                            <input type="hidden" class="form-control" id="idservicios" name="idservicios" >
                            <input type="text" class="form-control" id="nuevoNombreCliente" name="nuevoNombreCliente" value="<?php echo $data2[0]["nombres"] ?>" required readonly>                           
                            
                            
                          </div>

                        </div>
                      </div>


                      <div class="form-row">
                        <div class="form-group col-md-2">
                          <label for="inputCity">Documento:</label>
                          <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-address-card"></i></span>
                            <input type="text" class="form-control" id="nuevoDocumento" name="nuevoDocumento" value="<?php echo $data2[0]["documento"] ?>" required readonly>
                          </div>
                        </div>

                        <div class="form-group col-md-2">
                          <label for="inputCity">Telefono:</label>
                          <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-volume-control-phone"></i></span>
                            <input type="text" class="form-control" id="nuevoTelefono" name="nuevoTelefono" value="<?php echo $data2[0]["telefono"] ?>" required readonly>
                          </div>
                        </div>                      
                        
                      </div>

                      <div class="form-group col-md-2">
                          <label for="inputCity">Código A:</label>
                          <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-key"></i></span>
                            <input type="text" class="form-control" id="nuevoCodigo" name="nuevoCodigo" value="<?php echo $data2[0]["codigoA"] ?>" readonly>

                            
                          </div>
                        </div>

                        <div class="form-group col-md-2">
                          <label for="inputCity">Código R:</label>
                          <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-key"></i></span>
                            <input type="text" class="form-control" id="nuevoCodigoR" name="nuevoCodigoR" value="<?php echo $data2[0]["codigoR"] ?>" readonly>

                            
                          </div>
                        </div>                    

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


                <div class="form-group form-space col-md-12">
                  <div class="panel panel-success">
                    <div class="panel-heading">
                      <center>
                        <h3 class="panel-title">Datos del Servicio</h3>
                      </center>
                    </div>
                    <div class="panel-body" style="padding:0px">
                      <div class="form-row">

                        <div class="form-group col-md-5">
                          <label for="inputCity">Servicio:</label>
                          <div class="input-group">

                            
                            <span class="input-group-addon"><i class="fa fa-users"></i></span>

                            <input type="hidden" class="form-control" id="idtipo_servicios" name="idtipo_servicios" required>

                            <input type="tex" class="form-control" id="idtipo_servicioss" name="idtipo_servicioss" value="<?php echo $data2[0]["descripcion"] ?>" readonly>

                          </div>

                        </div>
                      </div>


                      <div class="form-row">
                        <div class="form-group col-md-5">
                          <label for="inputCity">Descripcion:</label>
                          <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-audio-description"></i></span>
                           <input type="tex" class="form-control" id="idtipo_servicioss" name="idtipo_servicioss" value="<?php echo $data2[0]["servicio"] ?>" readonly>
                          </div>
                        </div>

                          

                                           
                        
                      </div>

                    </div>
                  </div>

                  


                <div class="form-row">
                <div class="box-body">

                <table class="detalle table table-bordered table-striped table-hover table-condensed">
         
        <thead>
         
         <tr>
           
           <th>#</th>
           <th>Servicio</th>
           <th>Concepto</th>
           <th>Mes de Pago</th>          
           <th>Fecha de cobro</th>
           <th>Cargo del mes</th> 
           <th></th>


         </tr> 

        </thead>

        <tbody id="cronogramapago">


         
            <?php 

              foreach ($data2 as $key => $value) {
                echo '<tr id="fila">
                        <td>'.($key+1).'</td>
                        <td>'.($value["descripcion"] ?? '').'</td>
                        <td>'.($value["servicio"] ?? '').'</td>
                        <td>'.($value["fechas_pagos"] ?? '').'</td>                        
                        <td>'.($value["fecha_cobro"] ?? '').'</td>
                        <td>'.number_format(floatval($value["valor_servicio"] ?? 0),2,'.',',').'</td>';
                        $estado_pago = isset($value["estado_pago"]) ? intval($value["estado_pago"]) : 0;
                        if($estado_pago == 0){
                          echo '<td><span class="badge bg-yellow">Pendiente</span></td>';
                        }else if($estado_pago == 1){
                          echo '<td><span class="badge bg-green">Pagado</span></td>';
                        }else if($estado_pago == 2){
                          echo '<td><span class="badge bg-red">Vencido</span></td>';
                        }
                        

                 echo '</tr>';
              }

              if ($data2[0]["recargo"] == 1){
                echo '<tr id="fila">
                        <td></td>
                        <td>Recargos</td>
                        <td></td>
                        <td></td>                        
                        <td>'.$data2[0]["fecha_cobro"].'</td>
                        <td>Q.5.00</td>
                        <td></td>';
                                             

                 echo '</tr>';
              }

            ?>

          
         
          
        </tbody >

        <tfoot>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th >TOTAL</th>
            <th><h4 id="total"><?php echo number_format($data2[0]["total"],2,'.',',') ?></h4><input type="hidden" name="total_horas" id="total_horas"></th>
            <th></th>                                   
                                    
                                     
        </tfoot>

       </table>

                </div>

                     

                </div>

                    
                  

                   

                  

                </div>    

              </div>


            </div>  
            <div class="box-footer">

             <a href="cobros" type="button" class="btn btn-danger"><i class="fa fa-arrow-circle-left"></i> Regresar</a>

          </div>
          </form>
        </div>
      </div>


      <?php
/*
        $crearCobros = new ControladorCobros();
        $crearCobros -> ctrCrearCobros();
*/
        ?>       
    </div>
  </section>

</div>


<!--=====================================
MODAL AGREGAR CLIENTE
======================================-->

<div id="modalAgregarPersona" class="modal fade" role="dialog">
  
<div class="modal-dialog modal-lg">
    <div class="modal-content">

      <form role="form" method="post">

        <!--=====================================
        CABEZA DEL MODAL
        ======================================-->

        <div class="modal-header" style="background:#3c8dbc; color:white">

          <button type="button" class="close" data-dismiss="modal">&times;</button>

          <h4 class="modal-title">Seleccionar cliente</h4>

        </div>

        <!--=====================================
        CUERPO DEL MODAL
        ======================================-->

       <div class="modal-body">

          <div class="box-body">

            <table class="table table-bordered table-striped dt-responsive tablas" width="100%">
         
        <thead>
         
         <tr>
           
           <th style="width:10px">#</th>
           <th>Documento</th>
           <th>Nombres</th>
           <th>Apellido Paterno</th>
           <th>Apellido Materno</th>
           <th>Sexo</th>          
                 
           <th>Seleccionar</th>

         </tr> 

        </thead>

        <tbody>
          <?php

          $item = null;
          $valor = null;

          $personas = ControladorPersonas::ctrMostrarPersonas($item, $valor);

          foreach ($personas as $key => $value) {
            

            echo '<tr>

                    <td>'.($key+1).'</td>

                    <td>'.($value["documento"] ?? '').'</td>

                    <td>'.($value["nombres"] ?? '').'</td>

                    <td>'.($value["apaterno"] ?? '').'</td>

                    <td>'.($value["amaterno"] ?? '').'</td>';

                    $sexo = $value["sexo"] ?? '';
                    $idpersona = $value["idpersona"] ?? '';
                    
                    if($sexo != "F"){

                        echo '<td><span class="badge bg-blue" idPersona="'.$idpersona.'" sexoPersona="M"><i class="fa fa-male"></i> M</span></td>';

                      }else{

                        echo '<td><span class="badge bg" style="background-color: #f94877;" idPersona="'.$idpersona.'" sexoPersona="F"><i class="fa fa-female"></i> F</span></td>';

                      }

                    

                    echo '<td>

                      <div class="btn-group">
                          
                        <button class="btn btn-success btnAgregarDatos" idPersonaServicio="'.$idpersona.'"><i class="fa fa-check"></i></button>

                      </div>  

                    </td>

                  </tr>';
          
            }

        ?>       
   
        </tbody>

       </table>
                  
            
  
          </div>

        </div>



        <!--=====================================
        PIE DEL MODAL
        ======================================-->

        <div class="modal-footer">

          <button type="button" class="btn btn-danger pull-right" data-dismiss="modal">Close</button>
          

        </div>

      </form>

      </div>

  </div>

</div>





