<?php
$msg = '';

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

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

$usermaster = $mysqli->prepare("select * from cdi_usermaster where user_type='sales_exec' order by user_creationdate desc");
$usermaster->execute();
$userresult = $usermaster->get_result();


//$query = "select count(*) from rishta_3cx_calls where calltype='Inbound'  ";
//$query = "SELECT rishta_3cx_calls.*, cdi_usermaster.extension3,cdi_usermaster.user_full_name FROM rishta_3cx_calls LEFT JOIN cdi_usermaster ON rishta_3cx_calls.agentextension=cdi_usermaster.extension3 where calltype='Inbound'  ";
//$userresulttotaldata = "SELECT cdi_usermaster.*, rishta_3cx_calls.agentextension,count(rishta_3cx_calls.calltype) FROM cdi_usermaster LEFT JOIN rishta_3cx_calls ON cdi_usermaster.extension3 = rishta_3cx_calls.agentextension where calltype='Inbound'  ";

$userresulttotaldata = "select count(*) from rishta_3cx_calls JOIN cdi_usermaster ON cdi_usermaster.extension3 = rishta_3cx_calls.agentextension where calltype='Inbound' order by id desc ";

$usermaster = $mysqli->prepare($userresulttotaldata);
$usermaster->execute();
$usermaster->bind_result($ins);
$usermaster->fetch();
$usermaster->close();

$userresulttotaldata = "select count(*) from rishta_3cx_calls JOIN cdi_usermaster ON cdi_usermaster.extension3 = rishta_3cx_calls.agentextension where calltype='Outbound' order by id desc ";

$usermaster = $mysqli->prepare($userresulttotaldata);
$usermaster->execute();
//$userresult = $usermaster->get_result();
$usermaster->bind_result($outs);
$usermaster->fetch();
$usermaster->close();

$duration='07:00';


$usermaster = $mysqli->prepare("select *,(select count(*) from rishta_3cx_calls where agentextension = cdi_usermaster.extension3 AND calltype='Inbound') as incount,(select count(*) from rishta_3cx_calls where agentextension = cdi_usermaster.extension3 AND calltype='Outbound') as outcount,(select count(*) from rishta_3cx_calls where agentextension = cdi_usermaster.extension3 AND calltype='Missed') as misscall,(select count(*) from rishta_3cx_calls where agentextension = cdi_usermaster.extension3 AND calltype='Notanswered') as notanswered,(select count(contactnumber) from rishta_3cx_calls where agentextension = cdi_usermaster.extension3 AND calltype='Outbound' OR calltype='Inbound') as freash
,(select count(*) from rishta_3cx_calls where agentextension = cdi_usermaster.extension3 AND callduration > '$duration') as more from cdi_usermaster order by user_id desc");
$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>3cx Calling 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">Data Tables</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">Tables</li>
								<li class="breadcrumb-item active" aria-current="page">Data Tables</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">3cx Calling Report</h3>
				</div>
				<form class="form">
					<div class="box-body">
						<div class="row">
						</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>
					</div>
				</form>
				<!-- /.box-header -->
				<div class="box-body" id="ajaxcoursedata">
					<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>Agent Name</th>
								<th>Inbound</th>
								<th>Outbound</th>
								<th>Not Answered</th>
								<th>Missed Calls</th>
								<!--th>Freash</th-->
								<th>7+</th>
							</tr>
						</thead>
						<tbody>
		        <?php
													$i=0;
													while($userrow=mysqli_fetch_object($userresult))
													{
														$i++;
														?>
													
															<tr class="text-center">
																<td><?php echo $i; ?></td>
															
																	    <td><a href="dialers_report.php?userid=<?php echo $userrow->user_id ?>"><?php echo $userrow->	user_full_name ?></a></td>
												
												<td class="text-left"><a href="inbounds.php?userid=<?php echo $userrow->user_id  ?>" ><?php echo $userrow-> incount ?></a>
			  <td class="text-left">			     <a href="outbounds.php?userid=<?php echo $userrow->user_id  ?>" ><?php echo  $userrow-> outcount ?></a></td>
						    
			  <td class="text-left">			         <a href="noanswer.php?userid=<?php echo $userrow->user_id  ?>"><?php echo  $userrow-> notanswered ?></a></td>
              <td class="text-left">                  <a href="missed.php?userid=<?php echo $userrow->user_id  ?>"><?php echo  $userrow-> misscall ?></a></td>
						         
						         
              <td class="text-left">		             <a href="7plus.php?userid=<?php echo $userrow->user_id  ?>"><?php echo  $userrow-> more ?></a></td>
					
            
																
																
																
															</tr>
																<?php
														}
													?>
						</tbody>
						<!--tfoot>
							<tr>
								<th>Sr. No</th>
								<th>User Name	</th>
								<th>Email Id</th>
								<th>Status</th>
								<th>Add	</th>
								<th>Target Report</th>
								<th>Dialer Report	</th>
								<th>3cx Report</th>
							</tr>
						</tfoot-->
					  </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: '3cx_total_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: '3cx_total_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>

<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>
