<?php
require_once('header.php'); ?>

<section class="content-header">
    <div class="row">
        <div class="col-md-12">
<div class="col-md-12">
<center><img src="<?=$logo?>" style="width: 100px;"></center>
	</div>
	    </div>
    </div>
</section>
<style>
    .Head{
       color:red;
       font-weight:bold;
    }
</style>
<?php
$condition='';

/* if($clientType=="Admin"){ $condition=""; }else { $condition=" and client_id=$clientId"; }
*/
// $statement = $pdo->prepare("SELECT * FROM `tbl_user` WHERE role!='Admin'");
$statement = $pdo->prepare("SELECT * FROM `tbl_client_new`");
$statement->execute();
$total_client = $statement->rowCount();

$statement = $pdo->prepare("SELECT * FROM pincode");
$statement->execute();
$total_pincode = $statement->rowCount();

$statement = $pdo->prepare("SELECT * FROM courier_company");
$statement->execute();
$total_courier_company = $statement->rowCount();

$statement = $pdo->prepare("SELECT * FROM `pickup_entry` WHERE status_code=1 $condition");
$statement->execute();
$total_pending_pickup_entry = $statement->rowCount();

$statement = $pdo->prepare("SELECT * FROM `pickup_entry` WHERE status_code=2 $condition");
$statement->execute();
$total_piked_pickup_entry = $statement->rowCount();

$statement = $pdo->prepare("SELECT * FROM `pickup_entry` WHERE status_code=3 $condition");
$statement->execute();
$total_manifest_pickup_entry = $statement->rowCount();

$statement = $pdo->prepare("SELECT * FROM `pickup_entry` WHERE status_code=4 $condition");
$statement->execute();
$total_intransit_pickup_entry = $statement->rowCount();

$statement = $pdo->prepare("SELECT * FROM `pickup_entry` WHERE status_code=5 $condition");
$statement->execute();
$total_received_at_destination_pickup_entry = $statement->rowCount();

$statement = $pdo->prepare("SELECT * FROM `pickup_entry` WHERE status_code=6 $condition");
$statement->execute();
$total_out_for_delivery_pickup_entry = $statement->rowCount();

$statement = $pdo->prepare("SELECT * FROM `pickup_entry` WHERE status_code=7 $condition");
$statement->execute();
$total_delivery_pickup_entry = $statement->rowCount();

$statement = $pdo->prepare("SELECT * FROM `pickup_entry` WHERE status_code=8 $condition");
$statement->execute();
$total_undelivery_pickup_entry = $statement->rowCount();


$statement = $pdo->prepare("SELECT * FROM manifest");
$statement->execute();
$total_manifest = $statement->rowCount();

$statement = $pdo->prepare("SELECT a.*,c.company_name,(SELECT COUNT(id) from tbl_awb WHERE courier_id=a.courier_id and status=0) as available,(SELECT COUNT(id) from tbl_awb WHERE courier_id=a.courier_id and status=1) as not_available FROM tbl_awb a inner join courier_company c on a.courier_id=c.id GROUP BY a.courier_id");
$statement->execute();
$awb_3pl_courier = $statement->fetchAll(PDO::FETCH_ASSOC);
$total_3pl_courier_count = $statement->rowCount();

$statement = $pdo->prepare("SELECT * FROM `pickup_entry` WHERE 3pl_awb=''");
$statement->execute();
$total_empty_3pl_count = $statement->rowCount();

$statement = $pdo->prepare("SELECT * FROM `pickup_entry` WHERE 3pl_awb!=''");
$statement->execute();
$total_filled_3pl_count = $statement->rowCount();

?>
<section class="content">
	<div class="row">
	    
    <section class="content-header" style="padding-bottom:20px">
        <!--<a id="btnSync1" href="apis/auth.php" class="btn btn-success" target="_blank">Manual Sync 1</a>-->
        <!--<a id="btnSync2" href="apis/getdatas_bygst.php" class="btn btn-warning disabled" target="_blank" aria-disabled="true">Manual Sync 2</a>-->
    </section>

	<?php if($session_id ==1 || $allPermissions['client']['read']=="1"){ ?>
	<a href="user.php"><div class="col-md-4 col-sm-6 col-xs-12">
			<div class="info-box">
				<span class="info-box-icon bg-aqua"><i class="fa fa-users"></i></span>
				<div class="info-box-content">
					<span class="info-box-text">Clients</span>
					<span class="info-box-number"><?php echo $total_client; ?></span>
				</div>
			</div>
		</div></a><?php } ?>
		<?php if($session_id ==1 || $allPermissions['pincode']['read']=="1"){ ?>
			<a href="pincode.php"><div class="col-md-4 col-sm-6 col-xs-12">
			<div class="info-box">
				<span class="info-box-icon bg-aqua"><i class="fa fa-map-marker"></i></span>
				<div class="info-box-content">
					<span class="info-box-text">Total Pincode</span>
					<span class="info-box-number"><?php echo $total_pincode; ?></span>
				</div>
			</div>
		</div>
			</a>
		<?php } ?>	
			<?php if($session_id ==1 || $allPermissions['company']['read']=="1"){ ?>
			<a href="courier_company.php"><div class="col-md-4 col-sm-6 col-xs-12">
			<div class="info-box">
				<span class="info-box-icon bg-aqua"><i class="fa fa-building"></i></span>
				<div class="info-box-content">
					<span class="info-box-text">Courier Company</span>
					<span class="info-box-number"><?php echo $total_courier_company; ?></span>
				</div>
			</div>
		</div>
		</a><?php }?>
		<?php if($session_id ==1){ ?>
		<a href="view-pickup-entry.php?status=1"><div class="col-md-4 col-sm-6 col-xs-12">
			<div class="info-box">
				<span class="info-box-icon bg-green"><i class="fa fa-question-circle"></i></span>
				<div class="info-box-content">
					<span class="info-box-text">Pending Pickup-Entry</span>
					<span class="info-box-number"><?php echo $total_pending_pickup_entry; ?></span>
				</div>
			</div>
		</div>
		</a><a href="view-pickup-entry.php?status=2"><div class="col-md-4 col-sm-6 col-xs-12">
			<div class="info-box">
				<span class="info-box-icon bg-green"><i class="fa fa-thumbs-up"></i></span>
				<div class="info-box-content">
					<span class="info-box-text">Picked Pickup-Entry</span>
					<span class="info-box-number"><?php echo $total_piked_pickup_entry; ?></span>
				</div>
			</div>
		</div>
		</a>
		<a href="view-pickup-entry.php?status=3"><div class="col-md-4 col-sm-6 col-xs-12">
			<div class="info-box">
				<span class="info-box-icon bg-green"><i class="fa fa-barcode"></i></span>
				<div class="info-box-content">
					<span class="info-box-text">Manifest Pickup Entry</span>
					<span class="info-box-number"><?php echo $total_manifest_pickup_entry; ?></span>
				</div>
			</div>
		</div>
		</a>
		
		<a href="view-pickup-entry.php?status=4"><div class="col-md-4 col-sm-6 col-xs-12">
			<div class="info-box">
				<span class="info-box-icon bg-orange"><i class="fa fa-truck"></i></span>
				<div class="info-box-content">
					<span class="info-box-text">InTransit</span>
					<span class="info-box-number"><?php echo $total_intransit_pickup_entry; ?></span>
				</div>
			</div>
		</div>
		</a>
		<a href="view-pickup-entry.php?status=5"><div class="col-md-4 col-sm-6 col-xs-12">
			<div class="info-box">
				<span class="info-box-icon bg-orange"><i class="fa fa-university"></i></span>
				<div class="info-box-content">
					<span class="info-box-text">Received At Destination</span>
					<span class="info-box-number"><?php echo $total_received_at_destination_pickup_entry; ?></span>
				</div>
			</div>
		</div>
		</a>
		<a href="view-pickup-entry.php?status=6"><div class="col-md-4 col-sm-6 col-xs-12">
			<div class="info-box">
				<span class="info-box-icon bg-orange"><i class="fa fa-motorcycle"></i></span>
				<div class="info-box-content">
					<span class="info-box-text">Out For Delivery</span>
					<span class="info-box-number"><?php echo $total_out_for_delivery_pickup_entry; ?></span>
				</div>
			</div>
		</div>
		</a>
		<a href="view-pickup-entry.php?status=7"><div class="col-md-4 col-sm-6 col-xs-12">
			<div class="info-box">
				<span class="info-box-icon bg-blue"><i class="fa fa-cubes"></i></span>
				<div class="info-box-content">
					<span class="info-box-text">Delivery</span>
					<span class="info-box-number"><?php echo $total_delivery_pickup_entry; ?></span>
				</div>
			</div>
		</div>
		</a>
		<a href="view-pickup-entry.php?status=8"><div class="col-md-4 col-sm-6 col-xs-12">
			<div class="info-box">
				<span class="info-box-icon bg-blue"><i class="fa fa-recycle"></i></span>
				<div class="info-box-content">
					<span class="info-box-text">Un-Delivery</span>
					<span class="info-box-number"><?php echo $total_undelivery_pickup_entry; ?></span>
				</div>
			</div>
		</div>
		</a>
		<?php }?>
		
		<?php if($session_id ==1 ){ ?>
		<a href="manifest.php"><div class="col-md-4 col-sm-6 col-xs-12">
			<div class="info-box">
				<span class="info-box-icon bg-blue"><i class="fa fa-barcode"></i></span>
				<div class="info-box-content">
					<span class="info-box-text">Manifest</span>
					<span class="info-box-number"><?php echo $total_manifest; ?></span>
				</div>
			</div>
		</div></a><?php }?>
		
		<?php if($session_id ==1 ){ ?>
		<center><a href="awbList.php"><div class="col-md-8 col-sm-6 col-xs-12">
		<div class="info-box">
				<span class="info-box-icon bg-red"><i class="fa fa-building"></i></span>
				<div class="info-box-content">
				    <table width="100%">
				        <tr >
				            <td class="Head"><span class='info-box-text'>Courier Company Name</span></td>
				            <td class="Head"><span class='info-box-text'>Available 3PL Count</span></td>
				            <td class="Head"><span class='info-box-text'>Used 3PL Count</span></td>
				        </tr>
				        <?php
				        foreach($awb_3pl_courier as $row)
				        {
				            echo "<tr><td><span class='info-box-text'><i class='fa fa-building'></i> &ensp;".$row['company_name']."</span></td><td>".$row['available']."</td><td>".$row['not_available']."</td></tr>";
				        }
				        ?>
				    </table>
				</div>
			</div>
		</div></a></center><?php }?>
		<?php if($session_id ==1 ){ ?>
		<a href="#"><div class="col-md-4 col-sm-6 col-xs-12">
			<div class="info-box">
				<span class="info-box-icon bg-orange"><i class="fa fa-list"></i></span>
				<div class="info-box-content">
					<span class="info-box-text">Updated 3PL Count</span>
					<span class="info-box-number"><?php echo $total_filled_3pl_count; ?></span>
				</div>
			</div>
		</div></a>
		<a href="#"><div class="col-md-4 col-sm-6 col-xs-12">
			<div class="info-box">
				<span class="info-box-icon bg-orange"><i class="fa fa-question-circle"></i></span>
				<div class="info-box-content">
					<span class="info-box-text">Un-Filled 3PL Count</span>
					<span class="info-box-number"><?php echo $total_empty_3pl_count; ?></span>
				</div>
			</div>
		</div></a>
		
		<?php }?>
	
		
	</div>
</section>
<script type="text/javascript">
// Load google charts
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);

// Draw the chart and set the chart values
function drawChart() {
  var data = google.visualization.arrayToDataTable([
  ['Task', 'Hours per Day'],
  ['South', 8],
  ['Blr', 2],
  ['Karnataka', 4],
  ['North', 2],
  ['West', 8],
  ['East', 8]
]);
 var data1 = google.visualization.arrayToDataTable([
  ['Task', 'Hours per Day'],
  ['South', 3],
  ['Blr', 5],
  ['Karnataka', 4],
  ['North', 7],
  ['West', 3],
  ['East', 6]
]);
 var data2 = google.visualization.arrayToDataTable([
  ['Task', 'Hours per Day'],
  ['Delivery', 8],
  ['In Transit', 2],
  ['Out For Delivery', 4],
]);
 var data3 = google.visualization.arrayToDataTable([
  ['Task', 'Hours per Day'],
  ['24 Hours', 8],
  ['48 Hours', 2],
  ['72 Hours', 4],
  ['96 Hours', 2],
  ['120 Hours', 8],

]);

  // Optional; add a title and set the width and height of the chart
  var options = {'title':'Zone Distributors', 'width':550, 'height':400};
   var options1 = {'title':'RTO %', 'width':550, 'height':400};
    var options2 = {'title':'Total Summery', 'width':550, 'height':400};
     var options3 = {'title':'DELIVERY TAT', 'width':550, 'height':400};

  // Display the chart inside the <div> element with id="piechart"
  var chart = new google.visualization.PieChart(document.getElementById('piechart'));
  chart.draw(data, options);
  var chart = new google.visualization.PieChart(document.getElementById('piechart1'));
  chart.draw(data1, options1);
  var chart = new google.visualization.PieChart(document.getElementById('piechart2'));
  chart.draw(data2, options2);
  var chart = new google.visualization.PieChart(document.getElementById('piechart3'));
  chart.draw(data3, options3);
}
</script>

<?php require_once('footer.php'); ?>

<script>
    document.getElementById('btnSync1').addEventListener('click', function () {
        const btn2 = document.getElementById('btnSync2');
        btn2.classList.remove('disabled');
        btn2.removeAttribute('aria-disabled');
    });

    document.getElementById('btnSync2').addEventListener('click', function (e) {
        if (this.classList.contains('disabled')) {
            e.preventDefault();
            alert('Please click Manual Sync 1 first.');
        }
    });
</script>