{% extends "base.html" %}
{% load static %}
{% block titulo %}
  .::Recepcion de Dinero 
{% endblock titulo %}
{% block content1 %} 
      <script type="text/javascript">
        $("#navC").attr('class','dropdown active');
        $("#navSaldoR_alterna").attr('class','active');
      </script>
      <form action="">
        <!--<div class="row"><br><br><br><br></div>-->
        <div class="row">
          <div class="col-md-12 col-sm-12" >
              <div class="card">
                <div class="card-header bgm-bluegray text-center"> <h2>RECEPCIÓN DE DINERO</h2></div>
                <div class="card-body">
                   <div class="row" >
                    <h4 class="bg-success" align="center" id="ExitoMensaje">
                    </h4>
                  </div>
                  <div class="row">
                      <div class="col-md-2 col-md-offset-1 col-xs-4">
                        <button type="button" class="btn btn-info btn-block" id="btnRefrescar">Actualizar</button>
                      </div>
                  </div>
                  <div class="row">
                    <br>
                    <p class="bg-success">
                      &nbsp;
                      <div class="col-md-10 col-md-offset-1">
                          <div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                              <div class="modal-dialog">
                                <div class="modal-content">
                                  <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                    <h4 class="modal-title" id="myModalLabel">Detalles</h4>
                                  </div>
                                  <div class="modal-body">
                                    <p>
                                      <div class="col-md-12 col-sm-12" >
                                          <div class="panel panel-info">
                                            <div class="panel-heading" align="center"> <h5>Detalle de Saldo Recibido</h5></div>
                                            <div class="panel-body">
                                              <div class="row">
                                                <div class="col-md-12">
                                                  <p class="bg-success" align="center">
                                                    &nbsp;
                                                  </p>
                                                </div>
                                              </div>
                                              <p></p>
                              
                                              <div class="row">
                                                  <div class="col-md-4 col-md-offset-1" > 
                                                    <h5>Fecha</h5> 
                                                  </div>
                                                  <div class="col-md-4">
                                                    <input type="text" class="form-control" id="txtFecha" disabled="disabled">         
                                                  </div> 
                                              </div>
                                              <p></p>
                                              <div class="row">
                                                  <div class="col-md-4 col-md-offset-1" > 
                                                    <h5>comcepto</h5> 
                                                  </div>
                                                  <div class="col-md-6">
                                                    <input type="text" class="form-control" id="txtcon" disabled="disabled">         
                                                  </div> 
                                              </div>
                                              <p></p>
                                              <div class="row">
                                                  <div class="col-md-4 col-md-offset-1"> 
                                                    <h5>Monto</h5> 
                                                  </div>
                                                  <div class="col-md-6">
                                                    <input type="text" class="form-control" id="txtmonto" disabled="disabled">         
                                                  </div> 
                                              </div>
                                              <p></p>
                                              <div class="row">
                                                  <div class="col-md-4 col-md-offset-1"> 
                                                    <h5>moneda</h5> 
                                                  </div>
                                                  <div class="col-md-4">
                                                    <input type="text" class="form-control" id="txtmoneda" disabled="disabled">         
                                                  </div> 
                                              </div>
                                              <p></p>
                                              <div class="row">
                                                  <div class="col-md-4 col-md-offset-1" > 
                                                    <h5>Observaciones</h5> 
                                                  </div>
                                                  <div class="col-md-4">
                                                    <input type="text" class="form-control" id="txtObs" disabled="disabled">         
                                                  </div> 
                                              </div>
                                              <p></p>
                                              <div class="row">
                                                  <div class="col-md-4 col-md-offset-1" > 
                                                    <h5>Observaciones de Recepcion</h5> 
                                                  </div>
                                                  <div class="col-md-6">
                                                    <input type="text" class="form-control" id="txtObsRe">         
                                                  </div> 
                                              </div>
                                              <br>
                                              <div class="row">
                                                <div class="col-md-4 col-md-offset-4">
                                                  <button type="button" class="btn btn-default btn-block"id="recibido">Recibido?</button>
                                                </div>
                                              </div>
                                            </div>
                                          </div>
                                      </div>
                                    </p>
                                  </div>
                                  <div class="modal-footer">
                                    <hr>
                                    <button type="button" class="btn btn-primary" data-dismiss="modal">Cerrar</button>
                                  </div>

                                </div><!-- /.modal-content -->
                              </div><!-- /.modal-dialog -->
                          </div><!-- /.modal -->
                          <div id="myModal1" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                              <div class="modal-dialog">
                                <div class="modal-content">
                                  <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                    <h4 class="modal-title" id="myModalLabel">Detalles</h4>
                                  </div>
                                  <div class="modal-body">
                                    <p>
                                      <div class="col-md-12 col-sm-12" >
                                          <div class="panel panel-info">
                                            <div class="panel-body">
                                             
                                              <div id ="plantilla" style="font-family:'Lucida Console', Monaco, monospace;font-size:13px;">
                                                 <h5 align="center"><u><b>RECIBO DE INGRESO</b></u></h5>
                                                <table>
                                                  <tr nowrap>=====================================</tr>
                                                </table>
                                                <table>
                                                      <tr>
                                                        <th>Fecha&nbsp;</th>
                                                        <td id="f" colspan=3 nowrap></td>
                                                      </tr>
                                                </table>
                                                <br>
                                                <b>MONTO:</b>
                                                <p id="mon"></p>
                                                <b>CONCEPTO:</b>
                                                <p>Recepcion de Dinero de Caja Alterna: <span id="ca"></span></p>
                                                <br>
                                                <br>
                                                  <h5>____________________</h5>
                                                  <b>Recibi conforme: {{ nombre_usuario }}</b>
                                                 
                                              </div>
                      
                                            </div>
                                          </div>
                                      </div>
                                    </p>
                                  </div>
                                  <div class="modal-footer">
                                    <hr>
                                    <button type="button" class="btn btn-primary" data-dismiss="modal">Cerrar</button>
                                  </div>

                                </div><!-- /.modal-content -->
                              </div><!-- /.modal-dialog -->
                          </div>
                              <!--<input type="button" class="btn btn-default btn-block" data-toggle="modal" data-target="#myModal" value="Clientes">-->
                          
                          <div class="table-responsive">
                            <table class="table table-hover">
                                <thead>
                                  <tr>
                                    <th>Nro</th>
                                    <th>Caja Aterna</th>
                                    <th>Fecha</th>
                                    <th>Monto</th>
                                    <th>Moneda</th>
                                    <th>Observaciones</th>
                                  </tr>
                                </thead>
                                <tbody id="listaC">
                                    
                                </tbody>
                            </table>
                          </div>
                      </div>
                    </p>
                  </div>
                  <br>
                  <br>
                </div>
              </div>
          </div>
        </div>
      </form> 
                            <script type="text/JavaScript">
                              var dialog="";
                              var Aux="";
                              var filaI =0;
                              $(document).ready(function(){
                                $(document).on("click",".filaC",function(){
                                  var num = $(this).attr('id');
                                  filaI = num;
                                  //--------------
                                  $('#txtFecha').prop("value",Aux[filaI].fecha);
                                  $('#txtcon').prop("value",Aux[filaI].concepto);
                                  $('#txtmonto').prop("value",Aux[filaI].monto);
                                  $('#txtmoneda').prop("value",Aux[filaI].moneda);
                                  $('#txtObs').prop("value",Aux[filaI].obs);
                                  $("#f").text(Aux[filaI].fecha);
                                  $("#ca").text(Aux[filaI].CA);
                                  //$("#mon").text(Aux[filaI].monto);
                                  //$("#mone").text(Aux[filaI].moneda);
                                  $("#ob").text(Aux[filaI].obs);
                                  var mr='';
                                  if(Aux[filaI].moneda=="soles")
                                    {
                                      mr="S/. "
                                    }
                                  else
                                    {
                                      mr="$/. "
                                    }
                                  $("#mon").text(mr+Aux[filaI].monto);
                                });
                                ajax_SaldoRecibido();
                                $("#btnRefrescar").click(function(){
                                  ajax_SaldoRecibido();
                                });
                                //
                                function ajax_SaldoRecibido(){
                                  $.ajax({
                                    url:'/listaSaldoRecibidas_de_CajaAlterna_ajax/',
                                    type:'GET',
                                    dataType:'json',
                                    success: function(data){
                                      Aux= data;
                                      var html ="";
                                      for(var i=0;i<data.length;i++){
                                          html += '<tr class="filaC" data-toggle="modal" data-target="#myModal"' +' id="'+i+'"><th scope="row">'+(i+1)+'</td><td>'+data[i].CA+'</td><td>'+data[i].fecha+'</td><td>'+data[i].monto +'</td><td>'+data[i].moneda+'</td><td>'+data[i].obs+'</td></tr>';
                                      }                        
                                      $('#listaC').html(html);
                                    }
                                  });
                                }
                                //otra funcion
                                function ocultarmodal(){
                                  $('#myModal').modal('hide')
                                };
                                //otra funcion
                                              document.querySelector('#recibido').onclick = function(){
                                                
                                                  bootbox.confirm({
                                                    message: "¿Recepcionar?",
                                                    className: 'bb-alternate-modal',
                                                    buttons: {
                                                        confirm: {
                                                            label: '<i class="fa fa-check"></i> Aceptar',
                                                            className: 'btn-success'
                                                        },
                                                        cancel: {
                                                            label: '<i class="fa fa-times"></i> Cancelar',
                                                            className: 'btn-danger'
                                                        }
                                                    },
                                                    callback: function (result) {
                                                         if(result) {
                                                            dialog=bootbox.dialog({
                                                                message: '<p><i class="fa fa-spin fa-spinner"></i> Realizando Operación...</p>'
                                                            });

                                                            ajax_DineroRecibido(Aux[filaI].pk);
                                                            ocultarmodal();
                                                        }
                                                         
                                                    }
                                                });
 
                                              };
                                //otra funcion
                                function ajax_DineroRecibido(idC){//falta
                                  $.ajax({
                                    data:{'idS':idC,'obs':$("#txtObsRe").val()},
                                    url:'/DineroRecibido_deCajaAlterna_ajax/',
                                    //async:false,
                                    type:'GET',
                                    dataType:'text',
                                    success: function(data){
                                      if(data=='exito'){
                                        $("#ExitoMensaje").prop('class','bg-info');
                                        $("#ExitoMensaje").text("Recibido conformemnte!");
                                        $("#obsr").text($("#txtObsRe").val());
                                        $('#plantilla').printThis();
                                        
                                        bootbox.alert({ 
                                          message: "Operación exitosa. Dinero recepcionado",
                                          className: 'bb-alternate-modal'
                                        });

                                        dialog.modal('hide');
                                         ajax_SaldoRecibido();
                                       }
                                     else{
                                        $("#ExitoMensaje").prop('class','bg-danger');
                                        $("#ExitoMensaje").text(" la operacion fallo :(" + data);


                                        bootbox.alert({ 
                                          message: "La Operación falló",
                                          className: 'bb-alternate-modal'
                                        });

                                        dialog.modal('hide');
 
                                       }
                                    }
                                  });
                                };
                               
                               //-------------------
                              });
                          </script>
{% endblock content1 %}
