<?php
include "../../pidbco/pidbjoin.php";
include "../ses_write.php";

if(!isset($_SESSION))
{
    session_start();
}

if(isset($_POST['search_customer']))
{
	$searchcust  = $_POST['searchcust'];
	
	$qry = mysqli_query($con,"SELECT * FROM tele_calls_det WHERE `comp_name` LIKE  '%$searchcust%' OR `person_name` LIKE '%$searchcust%' OR `entered_loc`='%$searchcust%' OR `location`='%$searchcust%' OR `phone`='$searchcust' OR `phone2`='$searchcust' OR `email`='$searchcust' ");
    $num = mysqli_num_rows($qry);
    if($num > 0)
    {
    ?>	
   <div class="dataTables_wrapper" >
    <table class="table table-striped table-bordered table-hover table-responsive" id="dataTables-example">
      <thead>
        <tr>
        <th>Date</th>
        <th>Tele Caller</th>
        <th>Company</th>
        <th class="hidden-xs">Person</th>
        <th class="hidden-xs">Phone</th>
        <th class="hidden-xs">Last Follow Up</th>
        <th>Status</th>
        </tr>
      </thead>
    <tbody>
        <?php

        while($res = mysqli_fetch_object($qry))
        {
        	       $calid = $res->id;
                   $fw = $res->follow_up;
                   list($year,$month,$day) = explode('-', $fw);

                   $en = $res->entered_date;
                   list($eyear,$emonth,$eday) = explode('-', $en);
                   
				    $s="";
    if($res->status == 1)
    {
        $s = 'Interested';
    }
    elseif($res->status == 2)
    {

        $s = 'Not-Interested';
    }
    elseif($res->status == 3)
    {
        $s =  'Future';
    }
    elseif($res->status == 4)
    {
        $s = 'Visit Scheduled';
    }

                   $id_bdo = $res->bdo;
                   $stmt11 = mysqli_query($con,"SELECT id,emp_name FROM employee_registration WHERE id='$id_bdo'");
                   $stmt11_res = mysqli_fetch_object($stmt11);


                   ?>
                   <tr  <?php if($res->status == 4 && $res->executive_status == 2){ ?> class="odd gradeX danger" <?php }else{?> class="odd gradeX" <?php } ?>  style="cursor: pointer;" title="Edit" >
                       <td onclick="mylinkfunction();" ><a data-toggle="modal" data-target=".telecalls<?php echo $res->id; ?>" style="cursor: pointer;text-decoration: none;"><?php echo $eday.'-'.$emonth.'-'.$eyear; ?></a></td>
                       <td onclick="mylinkfunction();" ><a data-toggle="modal" data-target=".telecalls<?php echo $res->id; ?>" style="cursor: pointer;text-decoration: none;"><?php echo $stmt11_res->emp_name; ?></a>
                       	
                       	
                       	<div class="modal fade telecalls<?php echo $res->id; ?>" tabindex="-1" role="dialog" aria-hidden="true">
						<div class="modal-dialog">
							<div class="modal-content">
								<div class="modal-header">
									<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span></button>
									<h4 class="modal-title" id="myModalLabel">#<?php echo $res->id; ?>
									<small class="label label-success" style=" float: right; margin-right: 50px;" ><?php echo $en; ?>&nbsp; <?php echo $res->entered_time; ?></small>	
									</h4>
									
								 </div>
								 <div class="modal-body">
								 <table id="datatable-fixed-header" class="table table-striped table-bordered">
									<tr>
									  <td>Company</td>
									  <td><?php echo $res->comp_name; ?></td>
									</tr>
									<tr>
									  <td>Contact Person</td>
									  <td><?php echo $res->person_name; ?></td>
									</tr> 
									<tr>
										<td>Phone</td>
										<td><?php echo $res->phone; ?> , <?php echo $res->phone2; ?></td>
									</tr>
									
									<tr>
										<td>Email</td>
										<td><?php echo $res->email; ?></td>
									</tr>
									<tr>
										<td>Location</td>
										<td><?php echo $res->location; ?></td>
									</tr>
									
									
									<tr>
										<td>Telecaller</td>
										<td><?php echo $res->emp_name; ?></td>
								     </tr> 
									 <tr>
									   <td>Last Follow</td>
									   <td><?php echo $fw; ?></td>
									 </tr>
									 <tr>
									   <td>Status</td>
									   <td><?php echo $s; ?></td>
									 </tr>						 
						         </table>
						        <?php
						        $sql22="SELECT tele_bdo_id,entered_date,report FROM `tele_reports`  WHERE `telecall_id`='$calid' ";
                                $query22=mysqli_query($con, $sql22);
                                while($row22=mysqli_fetch_array($query22)){
	                                 $tele_bdo_id  = $row22['tele_bdo_id'];
	                                 $entered_date2 = $row22['entered_date'];
	                                 $report = $row22['report'];
	
	                                 $sql5 = "SELECT `emp_name` FROM `employee_registration` WHERE `id`='$tele_bdo_id' ";
	                                 $qry1 = mysqli_query($con, $sql5);
	                                 $res1 = mysqli_fetch_array($qry1);
	                                 $telecaller = $res1['emp_name']; 
						         ?>
						     <div style="margin-top: 20px;">
                               <span style="font-style: italic; "><small class="label label-danger"><i class="fa fa-clock-o"></i><?php echo $entered_date2; ?></small>&nbsp; <?php echo $telecaller; ?>&nbsp;<?php echo 'Says'.'&nbsp;'.$report; ?></span>
                               <br>
                             </div> 
						         <?php } ?>
	                     </div></div></div></div>
	                    
                       	
                       	
                       </td>
                       <td ><a data-toggle="modal" data-target=".telecalls<?php echo $res->id; ?>" style="cursor: pointer;text-decoration: none;"><?php echo $res->comp_name; ?> </a></td>
                       <td class="hidden-xs"><a data-toggle="modal" data-target=".telecalls<?php echo $res->id; ?>" style="cursor: pointer;text-decoration: none;"><?php echo $res->person_name; ?></a></td>
                       <td class="hidden-xs"><a data-toggle="modal" data-target=".telecalls<?php echo $res->id; ?>" style="cursor: pointer;text-decoration: none;"><?php echo $res->phone; ?></a></td>
                       <td class="hidden-xs"><a data-toggle="modal" data-target=".telecalls<?php echo $res->id; ?>" style="cursor: pointer;text-decoration: none;"><?php echo $day.'-'.$month.'-'.$year; ?></a></td>
                       <td class="center"><a data-toggle="modal" data-target=".telecalls<?php echo $res->id; ?>" style="cursor: pointer;text-decoration: none;"><?php if($res->status == 1){ echo 'Interested'; }elseif($res->status == 2){ echo 'Not-Interested'; }elseif($res->status == 3){ echo 'Future'; }elseif($res->status == 4){ echo 'Visit Scheduled'; } ?></a> </td>
                  
                   
                   </tr>
                   
                 															
                   
                   <?php } ?>
               </tbody>
           </table>
       </div>	

    <?php	
      } else {
    
	 ?><h4>No Data Found..!</h4><?php
    }
}
?>