<?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();





$usermaster = $mysqli->prepare("
SELECT 
rishta_leadmaster.*,

(
    SELECT COUNT(*)
    FROM rishta_leadmaster r2
    WHERE r2.video_calling='Yes'
    AND r2.lead_allocated_to = rishta_leadmaster.lead_allocated_to
) AS incount

FROM rishta_leadmaster

WHERE video_calling='Yes'

ORDER BY lead_created 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="">
   <style>

.report-card{
    background:#fff;
    border-radius:12px;
    overflow:hidden;
    border:1px solid #e5e7eb;
    box-shadow:0 2px 10px rgba(0,0,0,0.04);
}

.table-responsive{
    width:100%;
    overflow-x:auto;
}

.custom-report-table{
    width:100%;
    min-width:1200px;
    border-collapse:separate;
    border-spacing:0;
}

.custom-report-table thead th{
    background:#f8fafc;
    color:#111827;
    font-size:15px;
    font-weight:700;
    padding:18px 14px;
    border-bottom:1px solid #dbe1ea;
    border-right:1px solid #e5e7eb;
    text-align:center;
    white-space:nowrap;
}

.custom-report-table thead th:last-child{
    border-right:none;
}

.custom-report-table tbody td{
    padding:18px 14px;
    border-bottom:1px solid #edf1f5;
    border-right:1px solid #edf1f5;
    text-align:center;
    vertical-align:middle;
    font-size:14px;
    color:#111827;
    background:#fff;
}

.custom-report-table tbody tr:hover td{
    background:#f9fbff;
}

.custom-report-table tbody td:last-child{
    border-right:none;
}

.agent-link{
    color:#2563eb;
    font-weight:600;
    text-decoration:none;
}

.agent-link:hover{
    text-decoration:underline;
}

.country-pill{
    background:#f3f4f6;
    padding:7px 18px;
    border-radius:30px;
    display:inline-block;
    min-width:90px;
    font-weight:500;
}

/* KEEPING YOUR LEAD STATUS DESIGN */

.status-pill{
    padding:7px 18px;
    border-radius:30px;
    display:inline-block;
    font-size:12px;
    font-weight:700;
    min-width:110px;
}

.status-pill.high{
    background:#16a34a;
    color:#fff;
}

.status-pill.medium{
    background:#facc15;
    color:#000;
}

.status-pill.low{
    background:#dc2626;
    color:#fff;
}

.status-pill.paid{
    background:#6b7280;
    color:#fff;
}

.amount-box{
    background:#ecfdf3 !important;
    font-weight:700;
}

.count-badge{
    color:#00000;
    padding:7px 14px;
    border-radius:30px;
    font-size:13px;
    font-weight:700;
    display:inline-block;
    min-width:45px;
}


@media(max-width:768px){

    .custom-report-table thead th{
        font-size:13px;
        padding:14px 10px;
    }

    .custom-report-table tbody td{
        font-size:13px;
        padding:14px 10px;
    }

    .status-pill{
        min-width:auto;
        padding:6px 12px;
    }

    .country-pill{
        min-width:auto;
        padding:6px 12px;
    }
}

</style>

    <title>Video Calling Reports - 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">Video 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">Video 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)
										{
											?>
					 <div class="report-card">

<div class="table-responsive">

<table class="custom-report-table">

<thead>
<tr>

<th class="text-center">Video Call Date</th>
<th class="text-center">Contact Name</th>
<th class="text-center">Phone #</th>
<th class="text-center">Country</th>
<th class="text-center">Lead Status</th>
<th class="text-center">Amount</th>
<th class="text-center">Payment Date</th>
<th class="text-center">Quick Notes</th>
<th class="text-center">Next Call</th>
<th class="text-center">Count</th>

</tr>
</thead>

<tbody>

<?php
while($userrow=mysqli_fetch_object($userresult))
{
?>

<tr>

<td class="text-center">
<?php echo date('M d', strtotime($userrow->lead_created)); ?>
</td>

<td class="text-center">
<a class="agent-link"
href="edit-leads.php?leadid=<?php echo $userrow->lead_id; ?>">
<?php echo $userrow->contact_name; ?>
</a>
</td>

<td class="text-center">
<?php echo $userrow->contact_no; ?>
</td>

<td class="text-center">
<span class="country-pill">
<?php echo $userrow->country; ?>
</span>
</td>

<td class="text-center">

<?php
$status = strtolower($userrow->disposition);

if($status == 'interested' || $status == 'fully paid'){
echo '<span class="status-pill high">'.$userrow->disposition.'</span>';
}
elseif($status == 'follow up'){
echo '<span class="status-pill medium">'.$userrow->disposition.'</span>';
}
elseif($status == 'not interested'){
echo '<span class="status-pill low">'.$userrow->disposition.'</span>';
}
else{
echo '<span class="status-pill paid">'.$userrow->disposition.'</span>';
}
?>

</td>

<td class="text-center amount-box">
<?php echo $userrow->currency . ' ' . $userrow->amount; ?>
</td>

<td class="text-center">
<?php echo $userrow->lead_payment; ?>
</td>

<td class="text-center">
<?php echo substr($userrow->lead_remarks,0,60); ?>
</td>

<td class="text-center">
<?php echo $userrow->call_scheduling; ?>
</td>

<td class="text-center">
    <span class="count-badge">
        <?php echo $userrow->incount ?>
    </span>
</td>

</tr>

<?php
}
?>

</tbody>
</table>

</div>
</div>
					  <?php
										}
									?>
					</div>
				</div>
				<!-- /.box-body -->
			  </div>
			  <!-- /.box -->


			  <!-- /.box -->          
			</div>
			<!-- /.col -->
		  </div>
		  <!-- /.row -->
		</section>
		<!-- /.content -->
	  
	  </div>
  </div>
  <!-- /.content-wrapper -->
  <script>
    var page_skip = 1;
    function getLeads(page_no=null) {

        if((page_no != undefined) && (page_no != '') && (page_no != 0)) {
            page_skip = page_no;
        }

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

        $('#loading').css('display', '');

        $.ajax({
            url: 'video_report_ajax.php',
            type: 'post',
            data: {
                page_skip:page_skip,
                ddlUserId: ddlUserId,
                txtFromDate: txtFromDate,
                txtToDate: txtToDate,
            },
            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: 'video_report_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',
            // minDate: 0, // 0 days offset = today
        });
    });
</script>
	
<?php include('./include/footer.php'); ?>