<?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_new_api where source = cdi_usermaster.extension) as incount,(select count(*) from rishta_new_api where destination = cdi_usermaster.extension) as outcount,(select DISTINCT count(destination) from rishta_new_api where source = cdi_usermaster.extension OR destination = cdi_usermaster.extension) as freash
,(select count(*) from rishta_new_api where source = cdi_usermaster.extension OR destination = cdi_usermaster.extension AND duration > '$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>Indian 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">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">Indian Calling 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">Indian Calling Report</h3>
				</div>
				<form action="#" method="post" enctype="multipart/form-data">
					<div class="box-body">
					           <?php
                    if (trim($msg) != null) {
                        ?>
                        <div class='row'>
                            <div class='col-md-12'>
                                <div class="alert alert-success errormessage" id="errormessage">
                                    <strong><?php echo $msg ?></strong>
                                </div>
                            </div>
                        </div>
                        <?php
                    }
                    ?>
					
						<div class="row">
						  <div class="col-md-4">
							<div class="form-group">
							 <input placeholder='Start Date' type="date" 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="date" 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 class="table table-bordered table-striped">
						<thead>
							<tr>
								<th>Sr.No</th>
								<th>Agent Name</th>
								<th>Inbound</th>
								<th>Outbound</th>
								<th>Fresh</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="dialer-report.php?userid=<?php echo $userrow->user_id ?>"><?php echo $userrow->	user_full_name ?></a></td>
												
																<td class="text-left"><?php echo $userrow-> incount ?></td>
																<td class="text-left"><?php echo  $userrow-> outcount ?></td>
																	<td class="text-left"><?php echo  $userrow-> freash ?></td>
																		<td class="text-left"><?php echo  $userrow-> more ?></td>
																
																
																
															</tr>
																<?php
														}
													?>
						</tbody>
			
					  </table>
					    <div align="center">
                                    <nav>
                                        <ul class="pagination">
                                            <?php
                                            $total = ceil($total_records/ 10);
                                            for ($i = 1; $i <= $total; $i++) {
                                                ?>
                                                <li><a onclick='getLeadsPagination(<?php echo $i ?>)' href="javascript:void(0)" class="pagelink <?php if ($i == 1) {
                                                        echo "active";
                                                    } ?>"><?php echo $i ?></a></li>
                                                <?php
                                            }
                                            ?>
                                        </ul>
                                    </nav>
                                </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: '1_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: '1_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');
            }
        });
    }

  

    $(document).ready(function () {
        $("#txtFromDate,#txtToDate").datepicker({
            dateFormat: 'yy-mm-dd',
			//dateFormat: 'mm/dd/yy'
            // minDate: 0, // 0 days offset = today
        });
    });
</script>
  
	
<?php include('./include/footer.php'); ?>
