<?php
$msg = '';

include("include/settings.php");
include("checksession.php");

$and = 'and';
$condition = '';


$memberdetailmaster = $mysqli->prepare("select * from cdi_usermaster where user_id=?");
$memberdetailmaster->bind_param("i", $_GET['userid']);
$memberdetailmaster->execute();
$memberdetailmaster = $memberdetailmaster->get_result();
$userrow = mysqli_fetch_object($memberdetailmaster);

$extension = $userrow->extension3;	

$userresulttotaldata = $mysqli->prepare("select count(*) from rishta_3cx_calls where agentextension='$extension' order by id desc");
$userresulttotaldata->execute();
$userresulttotaldata->bind_result($total_records);
$userresulttotaldata->fetch();
$userresulttotaldata->close();


$usermaster = $mysqli->prepare("select count(*) from cdi_usermaster where user_id=?");
$usermaster->bind_param("i", $_GET['userid']);
$usermaster->execute();
$usermaster->bind_result($membercount);
$usermaster->fetch();
$usermaster->close();

if ($membercount == 0) {
    header("location:home.php");
}

$duration='07:00';


//$usermaster = $mysqli->prepare("select * from rishta_new_api where (destination = '$extension') OR (source = '$extension') OR (dst_channel LIKE '%$extension%') ");

$usermaster = $mysqli->prepare("select * from  rishta_3cx_calls where (agentextension ='$extension') AND (callduration > '$duration')order by id desc limit 1000");
$usermaster->execute();
$userresult = $usermaster->get_result();





?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Dialer Report - Rishta Depot</title>
  
		
<?php include('./include/meta.php'); ?>

</head>

	
<?php include('./include/header.php'); ?>
  
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
	  <div class="container-full">
		<!-- Content Header (Page header) -->
		<div class="content-header">
			<div class="d-flex align-items-center">
				<div class="me-auto">
					<h4 class="page-title">Reports</h4>
					<div class="d-inline-block align-items-center">
						<nav>
							<ol class="breadcrumb">
								<li class="breadcrumb-item"><a href="#"><i class="mdi mdi-home-outline"></i></a></li>
								<li class="breadcrumb-item" aria-current="page"> Dialer Report</li>
								<li class="breadcrumb-item active" aria-current="page">Reports</li>
							</ol>
						</nav>
					</div>
				</div>
				
			</div>
		</div>

		<!-- Main content -->
		<section class="content">
		  <div class="row">
			<div class="col-12">
    
			 <div class="box">
				<div class="box-header with-border">
				  <h3 class="box-title">Dialer Report</h3>
				</div>
			 <form class="form">
					<div class="box-body">
				
						<div class="row">
						  <div class="col-md-6">
							<div class="form-group">
								<label class="form-label">Email Id</label>
							     <input type="text" id="txtEmailId" name="txtEmailId" class="form-control" value="<?php echo $userrow->user_email_id ?>"/>
                            <input type="hidden" id="txtHfEmailId" name="txtHfEmailId" class="form-control" value="<?php echo $userrow->user_email_id ?>"/>
                           
							 <input type="hidden" id="ddlUserIds" name="ddlUserIds" class="form-control" value="<?php echo $extension ?>"/>
							 
							    
							   
							</div>
						  </div>
						  <div class="col-md-6">
							<div class="form-group">
							    <label class="form-label">Phone Number</label>
								 <input type="text" id="txtSearch" name="txtSearch" class="form-control" placeholder="Phone Number" onchange="getLeads()"/>
						    <input type="hidden" id="ddlUserId" name="ddlUserId" class="form-control" value="<?php echo $userrow->extension3 ?>" onchange="getLeads()"/>
                   
							</div>
						  </div>
						</div>
						<div class="row">
					<div class="col-md-4">
    <div class="form-group">
      <input placeholder='Start Date' type="text" id="txtFromDate" name="txtFromDate" class="form-control" autocomplete='off' onchange="getLeads()"/>
                 
    </div>
  </div>
  <div class="col-md-4">
    <div class="form-group">
        <input placeholder='End Date' type="text" id="txtToDate" name="txtToDate" class="form-control" autocomplete='off' onchange="getLeads()"/>
                    
    </div>
						
						</div>
						<div class="box-footer">
								     <a href="dialers_report.php?userid=<?php echo $userrow->user_id  ?>" type="submit" class="btn btn-primary" >All Calls</a>
						    <a href="inbounds.php?userid=<?php echo $userrow->user_id  ?>" type="submit" class="btn btn-primary" >Inbound Call</a>
						     <a href="outbounds.php?userid=<?php echo $userrow->user_id  ?>" type="submit" class="btn btn-primary">Outbound Call</a>
						      <!--a href="freash.php?userid=<?//php// echo $userrow->user_id  ?>" type="submit" class="btn btn-primary" >Fresh</a-->
						         <a href="missed.php?userid=<?php echo $userrow->user_id  ?>" type="submit" class="btn btn-primary">Missed Call</a>
						         
						             <a href="7plus.php?userid=<?php echo $userrow->user_id  ?>" type="submit" class="btn btn-primary">7+ Call</a>
						</div>
					</div>
				</form>
				<!-- /.box-header -->
				<div class="box-body" id="ajaxcoursedata">
				      <h4 class="subheading">No. of Calls: <?php echo mysqli_num_rows($userresult) ?></h4>
					<div class="table-responsive">
					    	<?php
										if(mysqli_num_rows($userresult)>0)
										{
											?>
					  <table id="example1" class="table table-bordered table-striped">
						<thead>
						    <tr>
														<th>Sr.No</th>
														<th>Contact Number</th>
															<th>Call Type</th>
														<th>Duration</th>
														<th>Date</th>
														
													</tr>
						</thead>
						<tbody>
						  <?php
													$i=0;
													while($userrow=mysqli_fetch_object($userresult))
													{
														$i++;
														?>
															<tr class="text-center">
																<td><?php echo $i; ?></td>
																<td class="text-left"><?php echo $userrow->	contactnumber ?></td>
																
																	<td><?php echo $userrow->calltype ?></td>
																<td><?php echo $userrow->callduration ?></td>
																	<td><?php $dateString = "$userrow->calldatetime";
																
																$dateTime = DateTime::createFromFormat('m/d/Y H:i', $dateString);

// Format as "Month DD, YYYY HH:MM"
$formattedDate = $dateTime->format('F d, Y H:i');

echo $formattedDate;
																
																
																?></td>
																
															</tr>
														<?php
													}
													?>
						</tbody>

					  </table>
					  		<?php
										}
										else
										{
											?>
												<div class="alert alert-danger">
													<strong>Warning!</strong> You have no leads.
												</div>
											<?php
										}
									?>
					</div>
				</div>
				<!-- /.box-body -->
			  </div>
			  <!-- /.box -->


			  <!-- /.box -->          
			</div>
			<!-- /.col -->
		  </div>
		  <!-- /.row -->
		</section>
		<!-- /.content -->
	  
	  </div>
  </div>
  <!-- /.content-wrapper -->

<script>
    function getLeads() {

        var txtFromDate = $('#txtFromDate').val();
        var txtToDate = $('#txtToDate').val();
        var txtSearch = $('#txtSearch').val();

        var ddlUserId = $('#ddlUserId').val();

    


        $('#loading').css('display', '');
        $.ajax({
            url: '7plus_ajax.php',
            type: 'post',
            data: {
                ddlUserId: ddlUserId,

            
                txtFromDate: txtFromDate,
                txtToDate: txtToDate,
                txtSearch: txtSearch,
      
            },
            datatype: 'html',
            success: function (rsp) {
                $('#ajaxcoursedata').html(rsp);
                $('#loading').css('display', 'none');
            }
        });
    }
    
    
 function getLeadsPagination(page_skip) {
        var txtFromDate = $('#txtFromDate').val();
        var txtToDate = $('#txtToDate').val();
        var txtSearch = $('#txtSearch').val();
       
        var ddlUserId = $('#ddlUserId').val();

        $('#loading').css('display', '');
        $.ajax({
            url: '7plus_ajax.php',
            type: 'post',
            data: {"ddlUserId": ddlUserId, "txtFromDate": txtFromDate, "txtToDate": txtToDate, "txtSearch": txtSearch, "page_skip": page_skip},
            datatype: 'html',
            success: function (rsp) {
                $('#ajaxcoursedata').html(rsp);
                $('#loading').css('display', 'none');
            }
        });
    }


    function changeLeadAllocation(executive_id, lead_id) {
        $('#loading').css('display', '');
        $.ajax({
            url: 'allocate_lead.php',
            type: 'post',
            data: {"executive_id": executive_id, "lead_id": lead_id},
            datatype: 'html',
            success: function (rsp) {
                $('#loading').css('display', 'none');
            }
        });
    }

  
</script>
<!--COMBINED FILE-->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script>
 
     $(document).ready(function () {
        $("#txtFromDate,#txtToDate").datepicker({
        
			dateFormat: 'mm/dd/yy 00:00'
           
        });
    });
</script>

<!--COMBINED FILE-->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script>
 
     $(document).ready(function () {
        $("#txtFromDate,#txtToDate").datepicker({
        
			dateFormat: 'mm/dd/yy 00:00'
           
        });
    });
</script>

<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  
   	<script src="../../../lead-crm/src/new/js/vendors.min.js"></script>
	<script src="../../../lead-crm/src/js/pages/chat-popup.js"></script>
    <script src="../../../lead-crm/assets/icons/feather-icons/feather.min.js"></script>
	<script src="../../../lead-crm/assets/vendor_components/echarts/dist/echarts-en.min.js"></script>
	<script src="../../../lead-crm/assets/vendor_components/apexcharts-bundle/dist/apexcharts.js"></script>

		
	<script src="../../../lead-crm/assets/vendor_components/datatable/datatables.min.js"></script>
	

    <script src="../../../lead-crm/assets/vendor_components/Flot/jquery.flot.js"></script>
	<script src="../../../lead-crm/assets/vendor_components/Flot/jquery.flot.resize.js"></script>
	<script src="../../../lead-crm/assets/vendor_components/Flot/jquery.flot.pie.js"></script>
	<script src="../../../lead-crm/assets/vendor_components/Flot/jquery.flot.categories.js"></script>

	<script src="../../../lead-crm/assets/vendor_components/Flot/jquery.flot.js"></script> 
	<script src="../../../lead-crm/src/js/pages/sampledata1.js"></script>
	<script src="../../../lead-crm/src/js/pages/sampledata2.js"></script>    
	<script src="../../../lead-crm/assets/vendor_components/apexcharts-bundle/irregular-data-series.js"></script>
	<script src="../../../lead-crm/assets/vendor_components/jquery.peity/jquery.peity.js"></script>
	
	<!-- CRMi App -->
	<script src="../../../lead-crm/src/js/pages/reports.js"></script>
	<script src="../../../lead-crm/src/js/template.js"></script> 
 
	<!-- CRMi App -->
	<script src="../../../lead-crm/src/js/pages/analysis.js"></script>
	
	<!-- CRMi App -->
	<!--script src="../../../lead-crm/src/js/pages/dashboard.js"></script-->

	<script src="../../../lead-crm/src/js/pages/data-table.js"></script> 

	
	<!-- CRMi App -->
	
	<script src="../../../lead-crm/src/js/pages/widget1-flot-charts.js"></script>
	<script src="../../../lead-crm/src/js/pages/flot-chart.js"></script>
	<script src="../../../lead-crm/src/js/pages/flot-chart1.js"></script>

	
		<!-- Vendor JS -->
    <script src="../../../lead-crm/assets/vendor_components/raphael/raphael.min.js"></script>
	<script src="../../../lead-crm/assets/vendor_components/morris.js/morris.min.js"></script>

	<!-- CRMi App -->
	
	<script src="../../../lead-crm/src/js/pages/widget-morris-charts.js"></script>
	<script src="../../../lead-crm/assets/vendor_components/chartist-js-develop/chartist.js"></script>
	
	<!-- CRMi App -->

	<script src="../../../lead-crm/src/js/pages/widget-chartist1.js"></script>
	<script src="../../../lead-crm/assets/vendor_components/echarts/dist/echarts-en.min.js"></script>
	
	<!-- CRMi App -->
	<script src="../../../lead-crm/src/js/pages/echart-bar.js"></script>  
	<script src="../../../lead-crm/assets/vendor_components/Flot/jquery.flot.pie.js"></script>

