<?php
$msg = '';

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

$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");
}

$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->extension;



$usermaster = $mysqli->prepare("select * from rishta_new_api where (destination = '$extension') limit 100");

$usermaster->execute();
$userresult = $usermaster->get_result();
//$userrows=mysqli_fetch_object($userresult);


?>
<!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">Sales Target 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 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-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-custom" value="<?php echo $userrow->user_email_id ?>"/>
							</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()"/>
							</div>
						  </div>
						</div>
						<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 class="box-footer">
						     <a href="dialer-report.php?userid=<?php echo $userrow->user_id  ?>" type="submit" class="btn btn-primary" >All Calls</a>
						    <a href="inbound.php?userid=<?php echo $userrow->user_id  ?>" type="submit" class="btn btn-primary" >Inbound Call</a>
						     <a href="outbound.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>

						</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>Destination</th>
								<th>Source</th>
								<th>Status</th>
								<th>Duration</th>
								<th>Date</th>
								<th>DB Date</th>
							</tr>
						</thead>
						<tbody>
						     <?php
													$i=0;
													while($userrow=mysqli_fetch_object($userresult))
													{
														$i++;
														?>
						    <tr>
								                            	<td><?php echo $i; ?></td>
																<td class="text-left"><?php echo $userrow->destination ?></td>
																<td><?php echo $userrow->source ?></td>
																<td><?php echo $userrow->status ?></td>
																<td><?php echo $userrow->duration ?> sec</td>
																<td><?php echo $userrow->date ?></td>
																<td><?php echo $userrow->date_time ?></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 ddlLeadType = $('#ddlLeadType').val();
        var ddlUserId = $('#ddlUserId').val();

        var countryId = $('#countryId').val();
        var stateId = $('#stateId').val();
        var cityId = $('#cityId').val();
        var searchGender = $('#searchGender').val();
        var searchMemberStatus = $('#searchMemberStatus').val();
        var searchCaste = $('#searchCaste').val();
        var searchResidencyStatus = $('#searchResidencyStatus').val();

        var searchCurrency = $('#searchCurrency').val();
        var searchDisposition = $('#searchDisposition').val();

        var searchMinAge = $('#searchMinAge').val();
        var searchMaxAge = $('#searchMaxAge').val();

        var searchMinFootHeight = $('#searchMinFootHeight').val();
        var searchMinInchHeight = $('#searchMinInchHeight').val();

        var searchMaxFootHeight = $('#searchMaxFootHeight').val();
        var searchMaxInchHeight = $('#searchMaxInchHeight').val();

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

        $('#loading').css('display', '');
        $.ajax({
            url: 'outrange.php',
            type: 'post',
            data: {
                ddlUserId: ddlUserId,
                ddlLeadMasterType: 'rishta_lead',
                ddlLeadType: ddlLeadType,
                txtFromDate: txtFromDate,
                txtToDate: txtToDate,
                txtSearch: txtSearch,
                countryId: countryId,
                stateId: stateId,
                cityId: cityId,
                searchGender: searchGender,
                searchMemberStatus: searchMemberStatus,
                searchCaste: searchCaste,
                searchResidencyStatus: searchResidencyStatus,
                searchCurrency: searchCurrency,
                searchMinAge: searchMinAge,
                searchMaxAge: searchMaxAge,
                searchMinFootHeight: searchMinFootHeight,
                searchMinInchHeight: searchMinInchHeight,
                searchMaxFootHeight: searchMaxFootHeight,
                searchMaxInchHeight: searchMaxInchHeight,
                religion: religion,
            },
            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');
            }
        });
    }

    function getLeadsPagination(page_skip) {
        var txtFromDate = $('#txtFromDate').val();
        var txtToDate = $('#txtToDate').val();
        var txtSearch = $('#txtSearch').val();
        var ddlLeadType = $('#ddlLeadType').val();
        var ddlUserId = $('#ddlUserId').val();

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

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