<?php
  $ruta="../../";
  include_once($ruta."class/dominio.php");
  $dominio=new dominio;
  include_once($ruta."class/vadmejecutivo.php");
  $vadmejecutivo=new vadmejecutivo;
  include_once($ruta."class/recuperacion.php");
  $recuperacion=new recuperacion;
   include_once($ruta."class/recuperacionmov.php");
  $recuperacionmov=new recuperacionmov;
  include_once($ruta."class/persona.php");
  $persona=new persona;

  include_once($ruta."funciones/funciones.php");
  session_start(); 
  extract($_GET);
  $idrecuperacion=dcUrl($lblcode);
  $gr=$recuperacion->muestra($idrecuperacion);
  $eje=$vadmejecutivo->muestra($gr['idadmejecutivo']);
  $per=$persona->muestra($gr['idpersona']);
  $total=0;
  foreach($recuperacionmov->mostrarTodo("idrecuperacion=".$idrecuperacion) as $remov)
  {
      $total=$total+number_format($remov['monto'], 2, '.', '');
  }
  $totalsaldo=$gr['monto'] - $total;
?>
<!DOCTYPE html>
<html lang="es">
<head>
    <?php
      $hd_titulo="COBRO DE DEUDA";
      include_once($ruta."includes/head_basico.php");
      include_once($ruta."includes/head_tabla.php");
      include_once($ruta."includes/head_tablax.php");
    ?>

    <style type="text/css">   

.tb{
  font-weight: bold;
  color: #268E6A;
}
</style>
</head>
<body>
    <?php
      include_once($ruta."head.php");
    ?>
    <div id="main">
      <div class="wrapper">
        <?php
          $idmenu=1090;
          include_once($ruta."aside.php");
        ?>
        <section id="content">
          <!--breadcrumbs start-->
          <div id="breadcrumbs-wrapper">
            <div class="container">
          <!--    <div class="row"> -->
                <div class="row " style="background: #555555; text-align: center; color:white; font-size: 25px; border-radius: 5px;">
                    <?php echo $hd_titulo; ?>
            </div>
               <div class="col s12 m12 l12" style="text-align: right;">
                  
                </div>             
           <!-- </div>--> 
         </div>
          </div>
<div class="container">
  <div class="section">
    <div class="row">
      <div class='col s12 m12 l6'> 
              <fieldset class="informacion" style="background: #D1D1D1;">
                    <legend><div class="titulo">
                      <a href="../" class="btn-jh waves-effect waves-light blue lighten-1"><i class="fa fa-mail-reply-all"></i></a>
                      <strong>DEUDOR</strong> </div></legend>
                   
                    <div class="col s12 m12 l12">
                      <div class="col s12 m12 l12">Socio(a): <b><?php echo $per['nombre'].' '.$per['paterno'].' '.$per['materno'] ?></b></div>
                      <div class="col s12 m12 l12">Cernet: <b><?php echo $per['carnet'].' '.$per['expedido'] ?></b></div>
                    </div>
                    <div class="col s12 m12 l12">
                      <div class="col s12 m12 l12">Monto Inicio: <b><?php echo number_format($gr['monto'], 2, '.', '') ?></b></div>
                      <div class="col s12 m12 l12">Saldo: <b><?php echo number_format($totalsaldo, 2, '.', '') ?></b></div>                      
                      <div class="col s12 m12 l12">Asesor: <b><?php echo $eje['nombre'].' '.$eje['paterno'] ?></b></div>                      
                      
                    </div>
                      <div class="col s12 m12 l12" align="right">
                    <!--  <a href="#modal3" class="btn-jh green darken-2  indigo modal-trigger" onclick="cargaDato('<?php //echo $gr['idpersona'] ;?>');"><i class="fa fa-edit"></i> Editar</a>   -->                  
                      
                    </div>
                      
                  </fieldset>
                   <form class="col s12" id="idform" action="return false" onsubmit="return false" method="POST">
                  <fieldset class="informacion" style="background: #D1D1D1;">
                    <legend><div class="titulo">
                      <strong>COBRAR DEUDA</strong> </div></legend>
                   <input id="idrecuperacion" name="idrecuperacion" type="hidden" value="<?php echo $idrecuperacion ?>" class="validate">
                    <div class="col s12 m12 l12"  style="background: white;">
                      <div class="input-field col s12 m12 l12" >
                          <input id="idnrorecibo" name="idnrorecibo" type="number" value="0" class="validate">
                          <label for="idnrorecibo">Nro. recibo</label>
                        </div>
                      <div class="input-field col s12 m4 l4" >
                          <input id="idmontocobrado" name="idmontocobrado" type="number" value="0.00" class="validate">
                          <label for="idmontocobrado">Monto a cobrar</label>
                        </div>
                         <div class="input-field col s12 m4 l4" >
                          <input id="idinteres" name="idinteres" type="number" value="0.00" class="validate">
                          <label for="idinteres">Interes</label>
                        </div>
                        <div class="input-field col s12 m4 l4" >
                          <input id="idfecha" name="idfecha" type="date" value="<?php echo date('Y-m-d') ?>" class="validate">
                          <label for="idfecha">Fecha Registro</label>
                        </div>
                        <div class="input-field col s12 m12 l12">
                          <input id="iddescripcion" name="iddescripcion" value="COBRADO" type="text">
                        <label for="iddescripcion">Descripción</label>
                        
                       </div> 
                    </div>
                      <div class="col s12 m12 l12" align="right">
                        <?php
                          if (number_format($totalsaldo, 2, '.', '')>0) 
                          {
                            ?>
                              <a id="btnSave" class="btn waves-effect waves-light " style="background: #555555;"><i class="fa fa-save"></i> REGISTRAR COBRO</a> 
                          <?php
                          }else{
                            ?>
                              <p style="color: green; font-size: 18px;">MONTO CANCELADO</p> 
                          <?php
                          }
                         ?>
                                          
                      
                    </div>
                      
                  </fieldset>
                </form>
      </div>
      <div class='col s12 m12 l6'> 
        <fieldset class="informacion">
                      <legend><div class="titulo"><strong><i class="fa fa-money"></i> Cobros realizados</strong> </div></legend>
                      <div class="col s12 m12 l12">
                        <table id="example2" class="display" cellspacing="0" width="100%">
                          <thead>
                            <tr>
                              <th>Pago Nro.</th>
                              <th>fecha cobrado</th> 
                              <th>Nro. recibo</th> 
                              <th>Monto cobrado</th>
                              <th>Interes</th>
                              <th>Descripción</th>
                            </tr>
                          </thead>
                          
                          <tbody>
                            <?php
                            $contar=0;
                            $totalcobrado=0;
                            foreach($recuperacionmov->mostrarTodo("idrecuperacion=".$idrecuperacion) as $f)
                            {
                               $contar++;    
                              $estilo="background-color: #A4F3C6;";
                            ?>
                            <tr style="<?php echo $estilo ?>">
                            <td><?php echo $contar ?></td>
                              <td><?php echo $f['fecha'] ?></td>
                              <td><?php echo $f['nrorecibo'] ?></td>
                              <td><?php echo number_format($f['monto'], 2, '.', '') ?></td>
                              <td><?php echo $f['interes'] ?></td>
                              <td><?php echo $f['descripcion'] ?></td>
                            </tr>
                            <?php
                              $totalcobrado=$totalcobrado+number_format($f['monto'], 2, '.', '');
                              }
                            ?>
                          </tbody>
                           <tfoot>
                               <tr>
                                 <th></th>
                                  <th></th>
                                    <th>TOTAL:</th> 
                                    <th><?php echo number_format($totalcobrado, 2, '.', '') ?></th>
                                    <th></th>
                                    <th></th>
                               </tr>
                            </tfoot>
                        </table>
                      </div> 
                    </fieldset>
      </div>
    </div>
  </div>
</div>

 
        </section>
      </div>
    </div>
    <div id="idresultado"></div>
    <!-- end -->
    <!-- jQuery Library -->
    <?php
      include_once($ruta."includes/script_basico.php");
      include_once($ruta."includes/script_tabla.php");
      include_once($ruta."includes/script_tablax.php");
    ?>
    <script type="text/javascript">
      $(document).ready(function() {
      $('#example').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ]
      });
        $('#example1').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ]
      });
          $('#example2').DataTable( {
        dom: 'Bfrtip',
        "order": [[ 0, "desc" ]],
        buttons: [
            
        ]
      });
           $('#example3').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            
        ]
      });
    });
  
      $("#btnSave").click(function(){
        //$('#btnSave').attr("disabled",true);
        if (validar()) 
        {          
          swal({
            title: "¿Esta seguro?",
            text: "Registrar el cobro",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#2c2a6c",
            confirmButtonText: "Registrar",
            closeOnConfirm: false,
            showLoaderOnConfirm: true
          }, function () {
            var str = $( "#idform" ).serialize();
            $.ajax({
              url: "guardar.php",
              type: "POST",
              data: str,
              success: function(resp){
                setTimeout(function(){     
                  console.log(resp);
                  $('#idresultado').html(resp);  
                }, 1500); 
              }
            }); 
          });
        }else{
          swal("ERROR","Faltan datos","error");
        }
      });
      function validar(){
        retorno=true;
        monto=$('#idmontocobrado').val();
        if(monto==""){
          retorno=false;
        }
        return retorno;
      }
 

    </script>
</body>

</html>