@include('header')

@if (!$is_remote)
	@include('navigator_menu_principal')
@endif

<div class="container">
	
	<div class="row">
		<div class="col-md-8 h3">Documentación para producción de informes</div>
		@if (!$is_remote)
		<div class="col-md-4 text-right">
			<!-- opcion de dar por finalizada manualmente la gestión sin el informe está en gestión, la tarea en proceso o rechazada y la contraparte no terminó de cargar -->
			<button type="button" class="btn btn-fidelitas btn-primary endgestion" data-contraparte="{{$report->contraparte}}" data-informe="{{$report->informe}}" data-toggle="modal" data-target="#modalDocumento"><i class="fa fa-flag"></i> Finalizar la gestión TEST</button>

			@if ( ($report->estado_tarea == 'E' || $report->estado_tarea == 'R') && $report->estado_informe == 'P' && $report->fin_pedido_doc == 0 )
				<button type="button" class="btn btn-fidelitas btn-primary endgestion" data-contraparte="{{$report->contraparte}}" data-informe="{{$report->informe}}" data-toggle="modal" data-target="#modalDocumento"><i class="fa fa-flag"></i> Finalizar la gestión</button>
			@endif
			<button type="button" class="btn btn-fidelitas btn-primary" onclick="location.href='/led/led-informes-activos'"><i class="fa fa-reply"></i> Volver a informes</button>
		</div>
		@endif
	</div>

	<div class="row">
		<div class="col-md-4 form-group">
			<label for="nombre_cliente">Cliente</label>
			<input name="nombre_cliente" id="nombre_cliente" value="{{$report->nombre_cliente}}" class="form-control" readonly="readonly">
		</div>
		<div class="col-md-4 form-group">
			<label for="nombre_tipo_informe">Tipo de informe</label>
			<input name="nombre_tipo_informe" id="nombre_tipo_informe" value="{{$report->nombre_tipo_informe}}" class="form-control" readonly="readonly">
		</div>
		<div class="col-md-2 form-group">
			<label for="fecha_comprometida">Fecha compr.</label>
			<input name="fecha_comprometida" id="fecha_comprometida" value="{{$report->fecha_comprometida}}" class="form-control" readonly="readonly">
		</div>
		<div class="col-md-2 form-group">
			<label for="nombre_estado">Estado</label>
			<input name="nombre_estado" id="nombre_estado" value="{{$report->nombre_estado}}" class="form-control" readonly="readonly">
		</div>
	</div>

	<div class="row">
		<div class="col-md-4 form-group">
			<label for="nombre_persona">Sujeto informado</label>
			<input name="nombre_persona" id="nombre_persona" value="{{$report->nombre_persona}}" class="form-control" readonly="readonly">
		</div>
		<div class="col-md-2 form-group">
			<label for="identificacion">Identificación</label>
			<input name="identificacion" id="identificacion" value="{{$report->abreviatura}} {{$report->identificacion}}" class="form-control" readonly="readonly">
		</div>
		<div class="col-md-2 form-group">
			<label for="country_name">País</label>
			<input name="country_name" id="country_name" value="{{$report->country_name}}" class="form-control" readonly="readonly">
		</div>

		<div class="col-md-2 form-group">
			<label for="fecha_limite_doc">Límite carga</label>
			<input name="fecha_limite_doc" id="fecha_limite_doc" value="{{$report->fecha_limite_doc}}" class="form-control" readonly="readonly">
		</div>
		<div class="col-md-1 form-group">
			<label for="cumplimiento">% Cumpl.</label>
			<input name="cumplimiento" id="cumplimiento" value="{{number_format($report->cumplimiento, 0, '.', '')}}" class="form-control" readonly="readonly">
		</div>
		<div class="col-md-1 form-group">
			<label for="cumplimiento">% Verif.</label>
			<input name="verificacion" id="verificacion" value="{{number_format($report->verificacion, 0, '.', '')}}" class="form-control" readonly="readonly">
		</div>
	</div>

	{{-- <div class="row">
		<div class="col-md-12 form-group">
			<label for="historial"><input type="Checkbox" value="1" name="historial" id="historial">&nbsp;Ver log del informe</label>
			<textarea name="historial_informe" class="form-control" id="historial_informe" rows="6" disabled="disabled" style="display: none;">{{$report->historial_informe}}</textarea>
		</div>
	</div>
	@if (!empty($gestion))
	<div class="row">
		<div class="col-md-12 form-group">
			<label for="historial_2"><input type="Checkbox" value="1" name="historial_2" id="historial_2">&nbsp;Ver log de la gestión de documentación</label>
			<textarea name="historial_gestion" class="form-control" id="historial_gestion" rows="6" disabled="disabled" style="display: none;">{{$gestion->historial_informe}}</textarea>
		</div>
	</div>
	<div class="row">
		<div class="col-md-12 form-group">
			<label for="notas_gestion"><input type="Checkbox" value="1" name="notas_gestion" id="notas_gestion">&nbsp;Ver notas de la gestión de documentación</label>
			<textarea name="gestion_notas" class="form-control" id="gestion_notas" rows="6" disabled="disabled" style="display: none;">{{$gestion->objeto_informe}}</textarea>
		</div>
	</div>
	@endif --}}

	<div class="row">
		<div class="col-md-4 form-group"><label for="historial"><input type="Checkbox" value="1" name="historial" id="historial">&nbsp;Ver log del informe</label></div>
		@if (!empty($gestion))
		<div class="col-md-4 form-group"><label for="historial_2"><input type="Checkbox" value="1" name="historial_2" id="historial_2">&nbsp;Ver log de la gestión de documentación</label></div>
		<div class="col-md-4 form-group"><label for="notas_gestion"><input type="Checkbox" value="1" name="notas_gestion" id="notas_gestion">&nbsp;Ver notas de la gestión de documentación</label></div>
		@endif
	</div>

	<textarea name="historial_informe" class="form-control col-md-12" id="historial_informe" rows="6" disabled="disabled" style="display: none;">{{$report->historial_informe}}</textarea>
	@if (!empty($gestion))
	<textarea name="historial_gestion" class="form-control col-md-12" id="historial_gestion" rows="6" disabled="disabled" style="display: none;">{{$gestion->historial_informe}}</textarea>
	<textarea name="gestion_notas" class="form-control col-md-12" id="gestion_notas" rows="6" disabled="disabled" style="display: none;">{{$gestion->objeto_informe}}</textarea>
	@endif

	<br />

    <table class="table table-hover table-condensed table-striped" id="tablaDocumentos">
      <thead>
        <tr>
          <th class="text-center">Estado</th>
          <th class="hidden">CumpN</th>
          <th class="text-left">Documento</th>
          <!-- <th class="text-center">Creación</th>
          <th class="hidden">Created</th> -->
          <th class="text-center">Vigencia</th>
          <th class="hidden">Vig</th>
          <th class="text-center">Tolerancia</th>
          <th class="hidden">Toler</th>
          <th class="text-center nowrap">F. Carga</th>
          <th class="hidden">Carga</th>
          <th class="text-center">Archivo</th>
        </tr>
      </thead>
      <tbody>
        <?php $n = -1; ?>
        @foreach($docs as $k => $documento)
          @if($documento->estado_doc == 'N' || $documento->estado_doc == 'I' || $documento->estado_doc == 'R' || $documento->estado_doc == 'V')
            <?php $n++; ?>
            <tr>
              <td class="text-center">
                <i class="fa fa-{{$documento->icon_estado}} {{$documento->class_estado}} fa-2x" title="{{$documento->estado_documento}}"></i>
              </td>
              <td class="hidden">@if($documento->estado_doc == 'N') @if ($documento->estado_documento !="No solicitado") 1 @else 99 @endif @elseif($documento->estado_doc == 'R') 2 @elseif($documento->estado_doc == 'I') 3 @else 4 @endif</td>
              <td>
                @if ($documento->estado_documento!="No solicitado")
                <a href="#" class="doc" data-doc-id="{{$documento->doc_id}}" data-tipo-doc="{{$documento->nombre_tipo_doc}}" data-toggle="modal" data-target="#modalDocumento">
                  {{$documento->nombre_tipo_doc}}
                </a>
                &nbsp;&nbsp;<a href="#" class="doctable" data-doc-id="{{$documento->doc_id}}" data-tipo-doc="{{$documento->nombre_tipo_doc}}" data-toggle="modal" data-target="#modalDocumento"><i class="fa fa-table"></i></a>
                @else
                  <a>{{$documento->nombre_tipo_doc}}</a>
                @endif 
              </td>

              {{-- <td class="text-center">{{$documento->created_dmy}}</td>
              <td class="hidden">{{$documento->created}}</td> --}}

              <td class="text-center">{{$documento->fecha_vigencia_dmy}}</td>
              <td class="hidden">{{$documento->fecha_vigencia}}</td>

              <td class="text-center">{{$documento->vencimiento_carga_dmy}}</td>
              <td class="hidden">{{$documento->vencimiento_carga}}</td>

              <td class="text-center">{{$documento->ingresado_dmy}}</td>
              <td class="hidden">{{$documento->ingresado}}</td>

              <td class="text-center">
                @if($documento->estado_doc != 'N')
                  @if($files[$n]['exists'] == true)
                    <a href="{{$files[$n]['url']}}?t={{time()}}" target="_blank"><img src="/img/pdf.png" border="0"></a>
                  @endif
                @endif
              </td>
            </tr>
          @endif
        @endforeach
      </tbody>
      <tfoot></tfoot>
    </table>


</div>

<div id="modalDocumento" class="modal fade">
    <div class="modal-dialog" style="width:970px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title" id="doc_title"></h3>
            </div>
            <div class="modal-body" id="doc_data"></div>
        </div>
    </div>
</div>


<script language="javascript" type="text/javascript">

	$(document).ready(function() {

		$('.doc').on('click', function() {
			$('#doc_title').html( $(this).data('tipoDoc') );
			var doc_id = $(this).data('docId');

			$.ajax({
						method : 'post',
						async : true,
						url : '/led/led-informes-doc-detail',
						data : { '_token' : '{{csrf_token()}}' , 'doc_id' : doc_id , 'plain' : true , 'table' : false },
						beforeSend : function() {
												$('#doc_data').html('');
						},
						success : function(data) {
												$('#doc_data').html(data);
						},
			});

	    });

		$('.doctable').on('click', function() {
			$('#doc_title').html( $(this).data('tipoDoc') );
			var doc_id = $(this).data('docId');

			$.ajax({
						method : 'post',
						async : true,
						url : '/led/led-informes-doc-detail',
						data : { '_token' : '{{csrf_token()}}' , 'doc_id' : doc_id , 'plain' : true , 'table' : true },
						beforeSend : function() {
												$('#doc_data').html('');
						},
						success : function(data) {
												$('#doc_data').html(data);
						},
			});

	    });



		$('#historial').on('click', function() {
			$('#historial_informe').slideToggle(200);
		});
		$('#historial_2').on('click', function() {
			$('#historial_gestion').slideToggle(200);
		});
		$('#notas_gestion').on('click', function() {
			$('#gestion_notas').slideToggle(200);
		});

		$('.endgestion').on('click', function() {

			$.ajax({
						method : 'post',
						url : '/led/led-informes-fin-gestion-confirm',
						data : { '_token' : '{{csrf_token()}}' , 'contraparte' : $(this).data('contraparte') , 'informe' : $(this).data('informe') },
						beforeSend : function() {
							$('#doc_title').html('');
							$('#doc_data').html('');
						},
						success : function(data) {
							$('#doc_title').html('Finalización de la gestión de documentación');
							$('#doc_data').html(data);
						},


			});

		});

	    $('#tablaDocumentos').DataTable( {
	                              "dom": "<'container'f><t><'container'p>",
	                                  "ordering": true,
	                                  "paging" : true,
	                                  "columns": [ null, null, null, null, null, null, null, null, null, { "orderable": false } ],
	                                  "columnDefs": [ { 'orderData':[1], 'targets': [0] }, { 'orderData':[4], 'targets': [3] }, { 'orderData':[6], 'targets': [5] }, { 'orderData':[8], 'targets': [7] }, { 'orderData':[10], 'targets': [9] }, ],
	                                  "order": [[ 0, "asc" ]],
	                                  "info": true,
	                              "lengthMenu": [ [10, 20, 50, 100, -1], [10, 20, 50, 100,"Todos"] ],
	                                  "language": {
	                                        "oPaginate": {
	                                            "sFirst": "Primera",
	                                            "sPrevious": "Anterior",
	                                            "sNext": "Siguiente",
	                                            "sLast": "Ultima"},

	                                        "sSearch":        "Buscar",
	                                        "zeroRecords": "No hay registros disponibles",
	                                        "info": "<b>Total:</b> _TOTAL_ registros",
	                                        "infoEmpty": "No se encontraron resultados",
	                                        "infoFiltered": "(filtrados de _MAX_ total de registros)",
	                                        "zeroRecords": "No se encontraron resultados",
	                                        "info": "<b>Total:</b> _TOTAL_ registros",
	                                        "infoEmpty": "No hay registros disponibles",
	                                        "infoFiltered": "(filtrados de _MAX_ total de registros)",},
	                                  "pageLength": 20,
		});



	});

</script>


<style type="text/css" media="screen">
	.form-group {
		margin-bottom: 2px;
	}	
</style>

@include('footer')
