<?php include "top.php"; ?>
<!DOCTYPE html>
<html>
<head>
	<?php include('include/head.php'); ?>
	<title>DeskApp Dashboard</title>
</head>
<body>
	<?php include('include/header.php'); ?>
	<?php include('include/sidebar.php'); ?>
	<?
				$csadded=$_SESSION['murgibhai'];
				$action=$_REQUEST['action'];
				$lread=$_SESSION['lread'];
	$comid=$_SESSION['compids'];
				if($action=='search'){
				$userdet=$_POST['userdet'];
				$names=$userdet;
				if($lread=='admin'){
					$q="SELECT * FROM adduser WHERE is_cable=1 AND custid = '$names'";
				}else{

					$q="SELECT * FROM adduser WHERE is_cable=1 AND com_id='$comid' AND custid = '$names'";
				}
				
				}

				$getlog=f(q("SELECT * FROM tbl_login WHERE l_uid='$csadded'"));
				$ltype=$getlog['l_type'];

$getcust=f(q($q));
if($getcust['name']!=''){

		$pdues=$getcust['prevdue'];

}else{



}

$getcom=f(q("SELECT * FROM tbl_company WHERE c_id='$getcust[com_id]'"));


		?>
	<div class="main-container">
		<div class="pd-ltr-20 customscroll customscroll-10-p height-100-p xs-pd-20-10" >
			<? if($ltype=='1' OR $ltype==2){ ?>
			<div class="row clearfix progress-box" style="margin-bottom: 0px;">
			<div class="col-lg-9 col-md-9 col-sm-12 mb-30">
					<div class="bg-white pd-20 box-shadow border-radius-5 height-100-p">
							Customer Name: <?php echo $getcust['name']?> <br>
							Address: <?php echo $getcust['address']?> <br>
							Phone: <?php echo $getcust['phone']?> <br>
							Area: <?php echo $getcust['area_name']?> <br>
							A/C No: <?php echo $getcust['custid']?> <br>
							Company No: <?php echo $getcom['c_name']?> <br>
							

					</div>
			</div>	
			<div class="col-lg-3 col-md-3 col-sm-12 mb-30">
					<div class="bg-white pd-20 box-shadow border-radius-5 height-100-p">
					<a class="btn btn-danger" href="generatebill.php?custid=<?=$getcust['id']?>"><i class="fa fa-cog"></i> Generate Bill</a><br><br>
					<form action="customer_bill_history_report.php" target="_blank" method="POST">
						<input type="hidden" name="search" value="<?=$getcust['custid']?>" >
						<button type="submit" class="btn btn-warning">Bill History</button>
					</form><br>
					
					<!-- <a class="btn btn-danger" href="generatebill.php?custid=<?=$getcust['id']?>"><i class="fa fa-cog"></i> Bill Generate Report</a> -->
					<a class="btn btn-warning" href="datecust.php?custid=<?=$getcust['id']?>"><i class="fa fa-cog"></i> Payment History</a>		


					</div>
			</div>
				<div class="col-lg-3 col-md-6 col-sm-12 mb-30">
					<div class="bg-white pd-20 box-shadow border-radius-5 height-100-p">
						<div class="project-info clearfix">
							<div class="project-info-left">
								<div class="icon box-shadow bg-blue text-white">
									<i class="fa fa-briefcase"></i>
								</div>
							</div>
							<?
							
								$sqli=f(q("SELECT `bl_payamt`,bl_month,bl_year FROM `cbill` WHERE bl_cid='$getcust[id]' ORDER BY blid DESC LIMIT 1"));

							
				            
				            ?>
							<div class="project-info-right">
								<span class="no text-blue weight-500 font-24">&#8377;<?=round($sqli['bl_payamt'],2)?></span>
								<p class="weight-400 font-18">Last Payment <br> (<?php echo $sqli['bl_month']?>,<?php echo $sqli['bl_year']?>)</p>
							</div>
						</div>
						<div class="project-info-progress">
							<div class="row clearfix">
								<!-- <div class="col-sm-6 text-muted weight-500">Target</div>
								<div class="col-sm-6 text-right weight-500 font-14 text-muted">40</div> -->
							</div>
							<!-- <div class="progress" style="height: 10px;">
								<div class="progress-bar bg-blue progress-bar-striped progress-bar-animated" role="progressbar" style="width: 40%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
							</div> -->
						</div>
					</div>
				</div>
				<?
							
							$sqli=f(q("SELECT `bl_remarks` FROM `cbill` WHERE bl_cid='$getcust[id]' ORDER BY blid DESC LIMIT 1"));


						
						?>

				<div class="col-lg-3 col-md-6 col-sm-12 mb-30">
					<div class="bg-white pd-20 box-shadow border-radius-5 height-100-p">
						<div class="project-info clearfix">
							<div class="project-info-left">
								<div class="icon box-shadow bg-light-green text-white">
									<i class="fa fa-handshake-o"></i>
								</div>
							</div>
							<div class="project-info-right">
								<span class="no text-light-green weight-500 font-24">Remarks</span>
								<p class="weight-400 font-18"><?php echo $sqli['bl_remarks']?></p>
							</div>
						</div>
						<div class="project-info-progress">
							<!-- <div class="row clearfix">
								<div class="col-sm-6 text-muted weight-500">Target</div>
								<div class="col-sm-6 text-right weight-500 font-14 text-muted">50</div>
							</div>
							<div class="progress" style="height: 10px;">
								<div class="progress-bar bg-light-green progress-bar-striped progress-bar-animated" role="progressbar" style="width: 50%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
							</div> -->
						</div>
					</div>
				</div>
				<?



	$sqli=f(q("SELECT SUM(`bl_payamt`) as tpay, SUM(bl_amt) as tbill FROM `cbill` WHERE bl_cid='$getcust[id]'"));
	$tt=floatval($sqli['tbill'])+floatval($pdues);
	$ty=$sqli['tpay'];
	if($ty==''){

		$ty=0;
	}

	$totaldue=floatval($tt)-floatval($ty);


				
				?>
				<div class="col-lg-3 col-md-6 col-sm-12 mb-30">
					<div class="bg-white pd-20 box-shadow border-radius-5 height-100-p">
						<div class="project-info clearfix">
							<div class="project-info-left">
								<div class="icon box-shadow bg-light-green text-white">
									<i class="fa fa-handshake-o"></i>
								</div>
							</div>
							<div class="project-info-right">
								<span class="no text-light-green weight-500 font-24">&#8377;<?=round($totaldue,2)?></span>
								<p class="weight-400 font-18">Total Due</p>
							</div>
						</div>
						<div class="project-info-progress">
							<!-- <div class="row clearfix">
								<div class="col-sm-6 text-muted weight-500">Target</div>
								<div class="col-sm-6 text-right weight-500 font-14 text-muted">50</div>
							</div>
							<div class="progress" style="height: 10px;">
								<div class="progress-bar bg-light-green progress-bar-striped progress-bar-animated" role="progressbar" style="width: 50%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
							</div> -->
						</div>
					</div>
				</div>
				<?php
				$dte=date("Y-m-d");
                $sqli=f(q("SELECT SUM(`bl_payamt`) as paytoday FROM `cbill` WHERE bl_cid='$getcust[id]' AND bl_paydt='$dte'"));
                ?>
				<div class="col-lg-3 col-md-6 col-sm-12 mb-30">
					<div class="bg-white pd-20 box-shadow border-radius-5 height-100-p">
						<div class="project-info clearfix">
							<div class="project-info-left">
								<div class="icon box-shadow bg-light-orange text-white">
									<i class="fa fa-list-alt"></i>
								</div>
							</div>
							<div class="project-info-right">
								<span class="no text-light-orange weight-500 font-24">&#8377; <?=round($sqli['paytoday'],2)?></span>
								<a href="cablecust.php"><p class="weight-400 font-18">Payment Done Today</p></a>
							</div>
						</div>
						<div class="project-info-progress">
							<!-- <div class="row clearfix">
								<div class="col-sm-6 text-muted weight-500">Review</div>
								<div class="col-sm-6 text-right weight-500 font-14 text-muted">Good</div>
							</div>
							<div class="progress" style="height: 10px;">
								<div class="progress-bar bg-light-orange progress-bar-striped progress-bar-animated" role="progressbar" style="width: 80%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
							</div> -->
						</div>
					</div>
				</div>
				<?
                $sqli=f(q("SELECT COUNT(1) AS Internet FROM adduser WHERE is_cable='0'"));
                ?>
				<!-- <div class="col-lg-3 col-md-6 col-sm-12 mb-30">
					<div class="bg-white pd-20 box-shadow border-radius-5 margin-5 height-100-p">
						<div class="project-info clearfix">
							<div class="project-info-left">
								<div class="icon box-shadow bg-light-purple text-white">
									<i class="fa fa-podcast"></i>
								</div>
							</div>
							<div class="project-info-right">
								<span class="no text-light-purple weight-500 font-24"><?=$sqli['Internet']?></span>
								<a href="internetcust.php"><p class="weight-400 font-18">Total Internet Customer</p></a>
							</div>
						</div>
						<div class="project-info-progress">
							
						</div>
					</div>
				</div> -->
				
				<?
                $sqlri=f(q("SELECT COUNT(*) as cnts FROM tbl_ticket WHERE custid='$getcust[id]'"));
                ?>
				<div class="col-lg-3 col-md-6 col-sm-12 mb-30">
					<div class="bg-white pd-20 box-shadow border-radius-5 margin-5 height-100-p">
						<div class="project-info clearfix">
							<div class="project-info-left">
								<div class="icon box-shadow bg-light-orange text-white">
									<i class="fa fa-bullhorn"></i>
								</div>
							</div>
							<div class="project-info-right">
								<span class="no text-light-orange weight-500 font-24"><?=$sqlri['cnts']?></span>
								<a href="#"><p class="weight-400 font-18">Total Complaints</p></a>
							</div>
						</div>
						<div class="project-info-progress">
							<!-- <div class="row clearfix">
								<div class="col-sm-6 text-muted weight-500">Review</div>
								<div class="col-sm-6 text-right weight-500 font-14 text-muted">Average</div>
							</div>
							<div class="progress" style="height: 10px;">
								<div class="progress-bar bg-light-purple progress-bar-striped progress-bar-animated" role="progressbar" style="width: 75%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
							</div> -->
						</div>
					</div>
				</div>
				<?php
                $sqlrb=f(q("SELECT COUNT(*) as cnts FROM tbl_ticket WHERE custid='$getcust[id]' AND stat='SOLVED'"));
                ?>
				<div class="col-lg-3 col-md-6 col-sm-12 mb-30">
					<div class="bg-white pd-20 box-shadow border-radius-5 margin-5 height-100-p">
						<div class="project-info clearfix">
							<div class="project-info-left">
								<div class="icon box-shadow bg-light-purple text-white">
									<i class="fa fa-bell"></i>
								</div>
							</div>
							<div class="project-info-right">
								<span class="no text-light-orange weight-500 font-24"><?=$sqlrb['cnts']?></span>
								<a href="#"><p class="weight-400 font-18">Solved Complaints</p></a>
							</div>
						</div>
						<div class="project-info-progress">
							<!-- <div class="row clearfix">
								<div class="col-sm-6 text-muted weight-500">Review</div>
								<div class="col-sm-6 text-right weight-500 font-14 text-muted">Average</div>
							</div>
							<div class="progress" style="height: 10px;">
								<div class="progress-bar bg-light-purple progress-bar-striped progress-bar-animated" role="progressbar" style="width: 75%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
							</div> -->
						</div>
					</div>
				</div>
				<?php
                $sqlrpe=f(q("SELECT COUNT(*) as cnts FROM tbl_ticket WHERE custid='$getcust[id]' AND stat='PENDING'"));
                ?>
				<div class="col-lg-3 col-md-6 col-sm-12 mb-30">
					<div class="bg-white pd-20 box-shadow border-radius-5 margin-5 height-100-p">
						<div class="project-info clearfix">
							<div class="project-info-left">
								<div class="icon box-shadow bg-light-purple text-white">
									<i class="fa fa-bell"></i>
								</div>
							</div>
							<div class="project-info-right">
								<span class="no text-light-orange weight-500 font-24"><?=$sqlrpe['cnts']?></span>
								<a href="#"><p class="weight-400 font-18">Pending Complaints</p></a>
							</div>
						</div>
						<div class="project-info-progress">
							
						</div>
					</div>
				</div>
				<?

            $date7 = (date("Y-m-d", strtotime("-7 day")));
            $date6 = (date("Y-m-d", strtotime("-6 day")));
            $date5 = (date("Y-m-d", strtotime("-5 day")));
            $date4 = (date("Y-m-d", strtotime("-4 day")));
            $date3 = (date("Y-m-d", strtotime("-3 day")));
            $date2 = (date("Y-m-d", strtotime("-2 day")));
            $date1 = (date("Y-m-d", strtotime("-1 day")));
            $date =  date("Y-m-d");



            
            	//echo "SELECT SUM(cstotal) AS tots FROM tbl_cash_sales WHERE csdate='$date30' AND csac='SALES AC'";
            
            
            $totq7=f(q("SELECT SUM(bl_payamt) AS tots FROM cbill WHERE bl_paydt='$date7' AND bl_stat='1' AND bl_tp='1'"));
            $totq6=f(q("SELECT SUM(bl_payamt) AS tots FROM cbill WHERE bl_paydt='$date6' AND bl_stat='1' AND bl_tp='1'"));
            $totq5=f(q("SELECT SUM(bl_payamt) AS tots FROM cbill WHERE bl_paydt='$date5' AND bl_stat='1' AND bl_tp='1'"));
            $totq4=f(q("SELECT SUM(bl_payamt) AS tots FROM cbill WHERE bl_paydt='$date4' AND bl_stat='1' AND bl_tp='1'"));
            $totq3=f(q("SELECT SUM(bl_payamt) AS tots FROM cbill WHERE bl_paydt='$date3' AND bl_stat='1' AND bl_tp='1'"));
            $totq2=f(q("SELECT SUM(bl_payamt) AS tots FROM cbill WHERE bl_paydt='$date2' AND bl_stat='1' AND bl_tp='1'"));
            $totq1=f(q("SELECT SUM(bl_payamt) AS tots FROM cbill WHERE bl_paydt='$date1' AND bl_stat='1' AND bl_tp='1'"));
            $totq=f(q("SELECT SUM(bl_payamt) AS tots FROM cbill WHERE bl_paydt='$date' AND bl_stat='1' AND bl_tp='1'"));
            
           
            $tot7=$totq7['tots'];
            $tot6=$totq6['tots'];
            $tot5=$totq5['tots'];
            $tot4=$totq4['tots'];
            $tot3=$totq3['tots'];
            $tot2=$totq2['tots'];
            $tot1=$totq1['tots'];
            $tot=$totq['tots'];
				$i=0;
				$payq=mysqli_query($con,"SELECT * FROM cbill WHERE bl_cid='$getcust[id]' AND bl_payamt<>0 ORDER BY blid DESC LIMIT 7");
				while($arrp=mysqli_fetch_array($payq)){

					if($i==0){

						$tot=$arrp['bl_payamt'];
						$date=$arrp['bl_paydt'];
					}elseif($i==1){

						$tot1=$arrp['bl_payamt'];
						$date1=$arrp['bl_paydt'];

					}elseif($i==2){

						$tot2=$arrp['bl_payamt'];
						$date2=$arrp['bl_paydt'];

					}elseif($i==3){

						$tot3=$arrp['bl_payamt'];
						$date3=$arrp['bl_paydt'];

					}elseif($i==4){

						$tot4=$arrp['bl_payamt'];
						$date4=$arrp['bl_paydt'];

					}elseif($i==5){

						$tot5=$arrp['bl_payamt'];
						$date5=$arrp['bl_paydt'];

					}elseif($i==6){

						$tot6=$arrp['bl_payamt'];
						$date6=$arrp['bl_paydt'];

					}elseif($i==7){

						$tot7=$arrp['bl_payamt'];
						$date7=$arrp['bl_paydt'];

					}


					$i++;
				}





             if($tot==''){

            	$tot=0;
            }if($tot1==''){

            	$tot1=0;
            }if($tot2==''){

            	$tot2=0;
            }if($tot3==''){

            	$tot3=0;
            }if($tot4==''){

            	$tot4=0;
            }if($tot5==''){

            	$tot5=0;
            }if($tot6==''){

            	$tot6=0;
            }if($tot7==''){

            	$tot7=0;
            }





				?>


			</div>
			<div class="row clearfix">
				<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 mb-30">
						<div class="bg-white pd-20 box-shadow border-radius-5 height-100-p">
							<div id="chart4"></div>
						</div>
				</div>
				

			</div>

		<? } ?>

		<? if($ltype=='3'){ ?>
			<div class="row clearfix progress-box" style="margin-bottom: 0px;">
				<div class="col-lg-3 col-md-6 col-sm-12 mb-30">
					<div class="bg-white pd-20 box-shadow border-radius-5 height-100-p">
						<div class="project-info clearfix">
							<div class="project-info-left">
								<div class="icon box-shadow bg-blue text-white">
									<i class="fa fa-briefcase"></i>
								</div>
							</div>
							<?
							$getcust=f(q("SELECT * FROM adduser WHERE id='$getlog[user_id]'"));


				            $sqli=f(q("SELECT SUM(bl_payamt) as totalpayment FROM `cbill` WHERE bl_cid='$getcust[id]'"));
				            ?>
							<div class="project-info-right">
								<span class="no text-blue weight-500 font-24">&#8377;<?=round($sqli['totalpayment'],2)?></span>
								<p class="weight-400 font-18">Total Payment</p>
							</div>
						</div>
						<div class="project-info-progress">
							<div class="row clearfix">
								<!-- <div class="col-sm-6 text-muted weight-500">Target</div>
								<div class="col-sm-6 text-right weight-500 font-14 text-muted">40</div> -->
							</div>
							<!-- <div class="progress" style="height: 10px;">
								<div class="progress-bar bg-blue progress-bar-striped progress-bar-animated" role="progressbar" style="width: 40%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
							</div> -->
						</div>
					</div>
				</div>
				<?
				$sqli=f(q("SELECT SUM(`bl_due`) as totaldue FROM `cbill` WHERE bl_cid='$getcust[id]'"));
				?>
				<div class="col-lg-3 col-md-6 col-sm-12 mb-30">
					<div class="bg-white pd-20 box-shadow border-radius-5 height-100-p">
						<div class="project-info clearfix">
							<div class="project-info-left">
								<div class="icon box-shadow bg-light-green text-white">
									<i class="fa fa-handshake-o"></i>
								</div>
							</div>
							<div class="project-info-right">
								<span class="no text-light-green weight-500 font-24">&#8377;<?=round($sqli['totaldue'],2)?></span>
								<p class="weight-400 font-18">Total Due</p>
							</div>
						</div>
						<div class="project-info-progress">
							<!-- <div class="row clearfix">
								<div class="col-sm-6 text-muted weight-500">Target</div>
								<div class="col-sm-6 text-right weight-500 font-14 text-muted">50</div>
							</div>
							<div class="progress" style="height: 10px;">
								<div class="progress-bar bg-light-green progress-bar-striped progress-bar-animated" role="progressbar" style="width: 50%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
							</div> -->
						</div>
					</div>
				</div>
				
				
				

			</div>




		<? } ?>
			
			<?php include('include/footer.php'); ?>
		</div>
	</div>
	<?php include('include/script.php'); ?>
	<script src="src/plugins/highcharts-6.0.7/code/highcharts.js"></script>
	<script src="https://code.highcharts.com/highcharts-3d.js"></script>
	<script src="src/plugins/highcharts-6.0.7/code/highcharts-more.js"></script>

	<script type="text/javascript">
		
		Highcharts.chart('chart4', {
			chart: {
				type: 'column'
			},
			title: {
				text: 'Last 7 Payments Chart'
			},
			subtitle: {
				text: 'Source: Cableapp CRM'
			},
			xAxis: {
				categories: [
				'<?=$date?>',
				'<?=$date1?>',
				'<?=$date2?>',
				'<?=$date3?>',
				'<?=$date4?>',
				'<?=$date5?>',
				'<?=$date6?>',
				'<?=$date7?>'
				],
				crosshair: true
			},
			yAxis: {
				min: 0,
				title: {
					text: 'Price (Rs)'
				}
			},
			tooltip: {
				headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
				pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
				'<td style="padding:0"><b>{point.y:.1f} Rs</b></td></tr>',
				footerFormat: '</table>',
				shared: true,
				useHTML: true
			},
			plotOptions: {
				column: {
					pointPadding: 0.2,
					borderWidth: 0
				}
			},
			series: [{
				name: 'Cable Payment',
				data: [<?=$tot?>, <?=$tot1?>, <?=$tot2?>, <?=$tot3?>, <?=$tot4?>, <?=$tot5?>, <?=$tot6?>, <?=$tot7?>]

			}]
		});





		
	</script>
</body>
</html>