<!DOCTYPE html>
<html lang="en">
                          
<?php $this->load->view("template/header"); ?>
<?php $this->load->view("template/nav"); ?>
        
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1 class="m-0">ReporteMincit</h1>
                </div>
                <!-- /.col -->
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                    <!-- <li class="breadcrumb-item"><a href="#" onclick="mySession()" class="nav-link">Cerrar Sesión</a></li> -->
                    </ol>
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </div>
        <!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->

    <!-- Main content -->
    <section class="content">
        <div class="container-fluid">
            <!-- Small boxes (Stat box) -->
            <div class="row">
            <div class="col-md-12">

            <!-- jquery validation -->
            <div class="card card-secondary">
                <div class="card-header">
                    <h3 class="card-title">Datos de  búsqueda </h3>
                </div>
                <!-- /.card-header -->

                <!-- form start -->
                <form id="quickForm"  autocomplete="off">
                    <div class="card-body">
                        <div class="row">
                            <div class="col-sm-2">
                                <div class="form-group">
                                    <label>Opción Busqueda</label>
                                    <select class="form-control" id="cmb_buscar_Seguimiento">
                                        <option value="0">--Seleccionar--</option>
                                        <option value="1">No. Documento</option>
                                        <option value="2">Placa Vehículo</option>
                                                                                   
                                    </select>
                                </div>
                            </div> 
                            <!-- /.col -->
                        
                            <div class="col-sm-2">
                                <div class="form-group">
                                    <label>Valor</label> 
                                    <input type="text" name="opt_valor_Seguimiento" class="form-control"  id="opt_valor_Seguimiento" placeholder="Digite Valor"> </input>
                                </div>
                            </div> 
                            <!-- /.col -->

                            <div class="col-sm-3">
                                <div class="form-group"> 
                                    </br>    
                                    <label></label>
                                    <button type="button" class="btn btn-primary col-md-4" id="btn_buscar_Seguimiento">Buscar</button>
                                </div>
                            </div> 
                            <!-- /.col -->
                        </div> 
                        <!-- /.row -->     
                    </div>
                    <!-- /.card-body --> 
                       

                    <div class="card-body">
                        <div id="example1_wrapper" class="dataTables_wrapper dt-bootstrap4">
                            <div class="row">
                                <div class="col-sm-12">
                                    <table id="example1" class="table table-bordered table-striped dataTable dtr-inline" role="grid" aria-describedby="example1_info">
                                        <thead>
                                        <tr role="row">
                                            <th class="sorting sorting_asc" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Rendering engine: activate to sort column descending" style="">#</th>
                                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" aria-label="Browser: activate to sort column ascending" style="">No.Dcto</th>
                                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" aria-label="Browser: activate to sort column ascending" style="">Dcto</th>
                                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" aria-label="Platform(s): activate to sort column ascending" style="width: 7%">Fecha</th>
                                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" aria-label="Engine version: activate to sort column ascending" style="">Hora</th>
											<th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style="">Id Ruta</th>
                                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style="">Ruta</th>
                                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style="">Punto Control</th>
                                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style="">Novedad</th>
                                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style="">Reporte</th>
                                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style="">Vehículo</th>
                                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style="">Detalle Seguimiento</th>
                                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style=""></th>
                                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style=""></th>
                                        </thead>
                                        <tbody>
                                                
                                        </tbody>
                                        <tfoot>
                                        <tr>
                                            <th rowspan="1" colspan="1" style="">#</th>
                                            <th rowspan="1" colspan="1" style="">No.Dcto</th>
                                            <th rowspan="1" colspan="1" style="">Dcto</th>
                                            <th rowspan="1" colspan="1" style="">Fecha</th>
                                            <th rowspan="1" colspan="1" style="">Hora</th>
											<th rowspan="1" colspan="1" style="">Id Ruta</th>
                                            <th rowspan="1" colspan="1" style="">Ruta</th>
                                            <th rowspan="1" colspan="1" style="">Punto Control</th>
                                            <th rowspan="1" colspan="1" style="">Novedad</th>
                                            <th rowspan="1" colspan="1" style="">Reporte</th>
                                            <th rowspan="1" colspan="1" style="">Vehículo</th>
                                            <th rowspan="1" colspan="1" style="">Detalle Seguimiento</th>
                                            <th rowspan="1" colspan="1" style=""></th>
                                            <th rowspan="1" colspan="1" style=""></th>
                                        </tr>
                                        </tfoot>
                                    </table>
                                </div>
                                <!-- /.col -->
                            </div>
                            <!-- /.row -->
                        </div>
                        <!-- /.example1 -->
                    </div>
                    <!-- /.card-body -->
                    
                    <div class="card-footer">
                        
                        <!--<button type="button" class="btn btn-secondary col-md-1 " id="btn_nuevo_Seguimiento"  >Nuevo </button>-->
                        
                    </div>
                    <!-- /.card footer -->
                </form>
                <!-- /.form -->
            </div> 
            <!-- /.card -->

                
            <!-- Main row -->
            <div class="row">
                <!-- Left col -->
                <section class="col-lg-7 connectedSortable">
                    <!-- Custom tabs (Charts with tabs)-->

                    <!-- /.card -->
                    </section>
                        <!-- /.Left col -->
                        <!-- right col (We are only adding the ID to make the widgets sortable)-->
                    <section class="col-lg-5 connectedSortable">

                </section>
                 <!-- right col -->
            </div>
            <!-- /.row (main row) -->
        </div>
        <!-- /.container-fluid -->
    </section>
    <!-- /.content -->
	
	<?php $this->load->view("template/footer"); ?>

</div>
<!-- /.content-wrapper -->

<?php $this->load->view("template/footer"); ?>


<!-- Control Sidebar -->
<aside class="control-sidebar control-sidebar-dark">
    <!-- Control sidebar content goes here -->
</aside>
<!-- /.control-sidebar -->

<!--Modal para enviar mensajes -->
<div class="modal fade " id="modal-correo"  tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-correo">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Enviar Correo de ReporteMincit</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true"></span>
                </button>
            </div>
			<div class="modal-body">
                <div class="card-body">
					<form>
						<div class="form-group">
                  			<label>Correo Electrónico</label> 
							<textarea class="form-control" type="email" name="email" id="email" rows="5" ></textarea>	
						</div>
              									
						<div class="form-group">
							<label>Mensaje</label>
							<textarea class="form-control" name="message" id="message" rows="8" ></textarea>
						</div>
					</form>
                </div>
                <!-- /.card-body -->
            </div>

            <div class="modal-footer justify-content-between">
                <button style="float: left"  type="button" class="btn btn-secondary col-md-1  " id="btn_cancelar_correo" data-dismiss="modal">Cancelar </button>
                <button style="float: right" type="button" class="btn btn-primary col-md-1 " id="btn_enviar_correo" >Enviar </button>
                
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal fade show -->

<!-- ======================================================================================================================================================================================================= -->
    <!-- jQuery -->
    
    <script src="<?php echo base_url() ?>assets/plugins/jquery/jquery.min.js"></script>
    <!-- jQuery UI 1.11.4 -->
    <script src="<?php echo base_url() ?>assets/plugins/jquery-ui/jquery-ui.min.js"></script>
    <!-- jQuery Mask -->
    <script src="<?php echo base_url() ?>assets/plugins/jquery-Mask/jquery.mask.min.js"></script>
    <!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
    <script>
        $.widget.bridge('uibutton', $.ui.button)
    </script>
    <!-- Bootstrap 4 -->
    <script src="<?php echo base_url() ?>assets/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
    <!-- ChartJS -->
    <script src="<?php echo base_url() ?>assets/plugins/chart.js/Chart.min.js"></script>
    <!-- Sparkline -->
    <!-- <script src="<?php echo base_url() ?>assets/plugins/sparklines/sparkline.js"></script> -->
    <!-- JQVMap  -->
    <script src="<?php echo base_url() ?>assets/plugins/jqvmap/jquery.vmap.min.js"></script>
    <script src="<?php echo base_url() ?>assets/plugins/jqvmap/maps/jquery.vmap.usa.js"></script>
    <!-- jQuery Knob Chart -->
    <script src="<?php echo base_url() ?>assets/plugins/jquery-knob/jquery.knob.min.js"></script>
    <!-- daterangepicker -->
    <script src="<?php echo base_url() ?>assets/plugins/moment/moment.min.js"></script>
    <script src="<?php echo base_url() ?>assets/plugins/daterangepicker/daterangepicker.js"></script>
    <!-- Tempusdominus Bootstrap 4 -->
    <script src="<?php echo base_url() ?>assets/plugins/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js"></script>
    <!-- Summernote -->
    <script src="<?php echo base_url() ?>assets/plugins/summernote/summernote-bs4.min.js"></script>
    <!-- overlayScrollbars -->
    <script src="<?php echo base_url() ?>assets/plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js"></script>
    <!-- AdminLTE App -->
    <script src="<?php echo base_url() ?>assets/dist/js/adminlte.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="<?php echo base_url() ?>assets/dist/js/demo.js"></script>
    <!-- AdminLTE dashboard demo (This is only for demo purposes) -->
     <!-- <script src="<?php echo base_url() ?>assets/dist/js/pages/dashboard.js"></script> -->
	<!-- SweetAlert -->
	<script src="<?php echo base_url() ?>assets/plugins/sweetalert2/sweetalert2.all.min.js"></script>
    <!-- AdminLTE Datatable components -->
    <script src="<?php echo base_url() ?>assets/plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="<?php echo base_url() ?>assets/plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
    <script src="<?php echo base_url() ?>assets/plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
    <script src="<?php echo base_url() ?>assets/plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
    <script src="<?php echo base_url() ?>assets/plugins/datatables-buttons/js/dataTables.buttons.min.js"></script>
    <script src="<?php echo base_url() ?>assets/plugins/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
    <script src="<?php echo base_url() ?>assets/plugins/jszip/jszip.min.js"></script>
    <script src="<?php echo base_url() ?>assets/plugins/pdfmake/pdfmake.min.js"></script>
    <script src="<?php echo base_url() ?>assets/plugins/pdfmake/vfs_fonts.js"></script>
    <script src="<?php echo base_url() ?>assets/plugins/datatables-buttons/js/buttons.html5.min.js"></script>
    <script src="<?php echo base_url() ?>assets/plugins/datatables-buttons/js/buttons.print.min.js"></script>
    <script src="<?php echo base_url() ?>assets/plugins/datatables-buttons/js/buttons.colVis.min.js"></script>

<!-- ======================================================================================================================================================================================================= -->

    <script>
		//Definir Variables
		var order_sel   = '';
		var placa_sel   = '';
		var cliente_sel = '';
		var cadena      = '';
		var idseg_sel   = '';

        //aca ya carga la data no necesito enviar nuevamente     
		var permisos      = <?php echo json_encode($permisos) ?>;
        var ReporteMincit = <?php echo json_encode($ReporteMincit) ?>;
		var horarios      = <?php echo json_encode($horarios) ?>;
		
		//Inicio Carga
		$(document).ready (function() {
            
		    $("#example1").DataTable({
                data: ReporteMincit,
				iDisplayLength: 30,
                destroy: true,
				searching: false,
				order: [[ 0, "desc" ]],
	            columns:
                [
                    {data : 'IdSeguimiento'},
                    {data : 'NumOrden'},
                    {data : 'TipoDoc'},
                    {data : 'FechaSeguimiento'},
                    {data : 'HoraSeguimiento'}, 
                    {data : 'IdRuta'},
                    {data : 'Ruta'},
                    {data : 'PtoControl'},
                    {data : 'Novedad'},
                    {data : 'TipoReporte'},
                    {data : 'IdVehiculo'},
                    {data : 'DetalleSeguimiento'},
                    {mRender: function (data, type, row) {
                        return '<a href="#" onclick="btn_abrir_correo('+ row[0]+')" data-id="' + row[0] + '" class="table-edit" ><i class="fas fa-envelope" title="Correo"></i></a>'
                    }},
					{mRender: function (data, type, row) {
											
						if(comparacion(row[0])){
						
							return '<span><i class="fas fa-circle" style="color:green"></i></span>';

						}else{

							return '<span><i class="fas fa-circle" style="color:red"></i></span>'
						
						}			
					}}
                ],
                responsive: true, "lengthChange": false, "autoWidth": false,
                buttons: ["copy", "csv", "excel", "pdf", "print"]
            }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');
			
	
		});

        //Boton de busqueda por los parametros.
        $("#btn_buscar_Seguimiento").click(function () 
        {             
            //Captura de valores 
            var BuscarDato = $('#cmb_buscar_Seguimiento').val();
            var Orden='';
            var Placa='';
           
            //Validacion
            if(BuscarDato == '0') {window.location.href="<?php echo base_url() ?>ReporteMincit/listReporteMincit";}
            if(BuscarDato == '1') {Orden=$('#opt_valor_Seguimiento').val();}
            if(BuscarDato == '2') {Placa=$('#opt_valor_Seguimiento').val();}
           
            //llamada a micro servicio de validacion
            $.ajax({
				
                url: '<?php echo base_url() ?>ReporteMincit/searchReporteMincit',//controlador
                type: "POST",//tipo de peticion POST o GET
                headers: {'X-Requested-With': 'XMLHttpRequest'},//Encabezados
                data: {'Orden': Orden, 'Placa': Placa}//formato json Data
                                       
            }).done(function(dato) 
            {        
                //convierto la respuesta json
                ReporteMincit=JSON.parse(dato);

                $("#example1").DataTable({
                data: ReporteMincit,
				iDisplayLength: 30,
                destroy: true,
				searching: false,
				order: [[ 2, "desc" ]],
                columns:
                [
                    {data : 'IdSeguimiento'},
                    {data : 'NumOrden'},
                    {data : 'TipoDoc'},
                    {data : 'FechaSeguimiento'},
                    {data : 'HoraSeguimiento'}, 
                    {data : 'IdRuta'},
                    {data : 'Ruta'},
                    {data : 'PtoControl'},
                    {data : 'Novedad'},
                    {data : 'TipoReporte'},
                    {data : 'IdVehiculo'},
                    {data : 'DetalleSeguimiento'},
                    {mRender: function (data, type, row) {
                        return '<a href="#" onclick="btn_abrir_correo('+ row[0]+')" data-id="' + row[0] + '" class="table-edit" ><i class="fas fa-envelope" title="Correo"></i></a>'
                    }},
					{mRender: function (data, type, row) {
											
						if(comparacion(row[0])){
						
							return '<span><i class="fas fa-exclamation-circle" style="color:green"></i></span>';

						}else{

							return '<span><i class="fas fa-minus-circle" style="color:red"></i></span>'
						
						}			
					}}
                ],
                responsive: true, "lengthChange": false, "autoWidth": false,
                buttons: ["copy", "csv", "excel", "pdf", "print"]
            }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');

            });
        });

        //Modal Abrir Correo
        function btn_abrir_correo(valor)
		{
			//Cargar Ventana Modal
			
			order_sel=getorden(valor);
			placa_sel=getplaca(valor);
			cliente_sel=getCliente(valor);
	
			//llamada a micro servicio de validacion
            $.ajax({
                url: '<?php echo base_url() ?>Habitaciones/searchHabitaciones',//controlador
                type: "POST",//tipo de peticion POST o GET
                headers: {'X-Requested-With': 'XMLHttpRequest'},//Encabezados
                data: {'Cliente': cliente_sel}//formato json Data
                                        
            }).done(function(dato) {
                        
                //convierto la respuesta json
                Habitaciones=JSON.parse(dato);
				
				for(i=0;i<Habitaciones.length;i++){
                    if(cadena.length>0){
						cadena=cadena+"; "+Habitaciones[i].CorreoElectronico;
					}else{
						cadena=Habitaciones[i].CorreoElectronico;
					}
            
					$('#email').val(cadena.trim());
                };
				$("#modal-correo").modal("show");
					
			});
		}

		//Enviar Correo ReporteMincit
		$("#btn_enviar_correo").click(function () 
		{ 
			var Subject="Seguimiento del vehiculo de placa "+placa_sel;
			var Email=$('#email').val();
			var Message=$('#message').val();

			$.ajax({

				url: '<?php echo base_url() ?>Reservas/enviarCorreo',//controlador
				type: "POST",//tipo de peticion POST o GET
				headers: {'X-Requested-With': 'XMLHttpRequest'},//Encabezados
				data: {'Subject': Subject, 'Email': Email, 'Message': Message,'NumOrder': order_sel,'IdVehiculo': placa_sel}//formato json Data   
						
			}).done(function(dato) {
				//convierto la respuesta json
				var obj = JSON.parse(dato); 
				if (obj.res == 'ok') {
					//llamamos al controlador  
					window.location.href="<?php echo base_url() ?>ReporteMincit/listReporteMincit/";
				}else{

					Swal.fire("error",obj.msg, "error");  
					
				}
			});			

		});

		//Validar Caracteres en el mensaje 
		$("#message").bind('keypress', function(event) 
		{
            var regex = new RegExp("^[a-zA-Z0-9- ]+$");
            var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
            if (!regex.test(key)) {
                event.preventDefault();
                return false;
            }
        });

		//cargar id Placa
		function getplaca(idseg){
          	var placa="";
          	for(i=0;i<ReporteMincit.length;i++){
            	if(idseg==ReporteMincit[i].IdSeguimiento){
               		placa=ReporteMincit[i].IdVehiculo;
            	} 
			}
        	 return placa;
		}

		//cargar id Compañia
		function getcompania(idseg){
          	var cia="";
          	for(i=0;i<ReporteMincit.length;i++){
            	if(idseg==ReporteMincit[i].IdSeguimiento){
               		cia=ReporteMincit[i].IdCia;			
            	} 
			}
			return cia;
		};

		//cargar id Orden
		function getorden(idseg){
          	var orden="";
          	for(i=0;i<ReporteMincit.length;i++){
            	if(idseg==ReporteMincit[i].IdSeguimiento){
               		orden=ReporteMincit[i].NumOrden;			
            	} 
			}
			return orden;
		};

		//cargar Cliente
		function getCliente(idseg)
		{	
          	var cliente="";
          	for(i=0;i<ReporteMincit.length;i++){
            	if(idseg==ReporteMincit[i].IdSeguimiento){
					cliente=ReporteMincit[i].IdCliente;
            	} 
			}
			return cliente;
		};

		//funcion comparacion
		function comparacion( dat1 ){
			var encontrado=false;
			orden=getorden(dat1);
			placa=getplaca(dat1);
			cia=getcompania(dat1);
						
			for(i=0;i<horarios.length;i++){
				
            	if((orden==horarios[i].NumOrden.toString()) && (placa==horarios[i].IdVehiculo) && (cia.toString()==horarios[i].IdCia)){
            		
					if(horarios[i].IdPunto = horarios[i].Item){
						
						if((horarios[i].Amarillo >= horaini) && (horaini <= horarios[i].HoraProg)){
							
							encontrado=true;

						}else if((horarios[i].Rojo >= horaini) && (horaini <= horarios[i].HoraProg)){

							encontrado=false;
						}
					}          	
				}         			
		  	}
		  
		  	return encontrado;
		};

		//Funcion para mensajes
		function MsgAlerta()
		{
			Swal.fire({
                title: "Información",
                html:" <p>No tiene permisos para esta acción. <br> Comunicate con el administrador.</p>",
                icon: "info"
			})
		};
      
    </script>

</body>

</html>
