<?php

include 'load.php';
  
?>

<!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">
    <title>Home | Recharge and Billing System | ORMS | Dashbaord</title>

	<?php
	require_once 'headercss.php';
	?>
	
</head>
<body>

    <?php
	require_once 'preloader.php';
	?>

   
    <!--**********************************
        Main wrapper start
    ***********************************-->
    <div id="main-wrapper">

        <?php

		require_once 'header.php';

		?>

        <!--**********************************
            Sidebar start
        ***********************************-->
        <div class="deznav">
            <div class="deznav-scroll">
<?php

require_once 'sidebarmenu.php';

?>
            </div>
        </div>
        <!--**********************************
            Sidebar end
        ***********************************-->
<?php

require_once 'coutquery.php';

?>	

		<!--**********************************
            Content body start
        ***********************************-->
        <div class="content-body">
            <div class="container-fluid">
				<!-- row -->
				<div class="row">
				<div class="col-xl-12 col-xxl-12 col-sm-12">
				<div class="alert alert-danger bg-danger text-white" role="alert">
				<strong>Alert!</strong> ඔබගේ ගිනුම තහවුරු කිරීම අසම්පුර්නයි.<a href="identity_verify.php" class="btn btn-success float-right" style="background-color:#0847cb;font-weight:bold;font-size:18px;color:#ffffff;padding:4px 4px;">සම්පුර්න කරන්න</a>
				</div>
				</div>
				</div>    
                <div class="row">
					<div class="col-xl-12 col-xxl-12 col-sm-12">
					<div class="row">
					<div class="col-xl-4 col-xxl-4 col-sm-6">
						<div class="widget-stat card" style="background-color: #000000;">
							<div class="card-body">
								<div class="media">
									<span class="mr-3">
									<i class="fa fa-briefcase" aria-hidden="true" style="color:#2ac20b;"></i>
									</span>
									<div class="media-body text-white">
										<p class="mb-1">Total Packages</p>
										<h3 class="text-white"><?php echo $total_pkgs ?></h3>
										<div class="progress mb-2 bg-white">
                                            <div class="progress-bar progress-animated bg-light" style="width: 100%"></div>
                                        </div>
									</div>
								</div>
							</div>
						</div>
                    </div>
					<div class="col-xl-4 col-xxl-4 col-sm-6">
						<div class="widget-stat card" style="background-color: #000000;">
							<div class="card-body">
								<div class="media">
									<span class="mr-3">
									<i class="fa fa-phone-square" aria-hidden="true" style="color:#2ac20b;"></i>
									</span>
									<div class="media-body text-white">
										<p class="mb-1">Total Reloads</p>
										<h3 class="text-white"><?php echo $total_reload ?></h3>
										<div class="progress mb-2 bg-white">
                                            <div class="progress-bar progress-animated bg-light" style="width: 100%"></div>
                                        </div>
									</div>
								</div>
							</div>
						</div>
                    </div>
					<div class="col-xl-4 col-xxl-4 col-sm-6">
						<div class="widget-stat card" style="background-color: #000000;">
							<div class="card-body">
								<div class="media">
									<span class="mr-3">
									<i class="fa fa-user-circle-o" aria-hidden="true" style="color:#2ac20b;"></i>
									</span>
									<div class="media-body text-white">
										<p class="mb-1">Total Resellers</p>
										<h3 class="text-white"><?php echo $total_register ?></h3>
										<div class="progress mb-2 bg-white">
                                            <div class="progress-bar progress-animated bg-light" style="width: 30%"></div>
                                        </div>
									</div>
								</div>
							</div>
						</div>
                    </div>
					<div class="col-xl-4 col-xxl-4 col-sm-6">
						<div class="widget-stat card" style="background-color: #000000;">
							<div class="card-body">
								<div class="media">
									<span class="mr-3">
									<i class="fa fa-money" aria-hidden="true" style="color:#2ac20b;"></i>
									</span>
									<div class="media-body text-white">
										<p class="mb-1">Total Trasactions</p>
										<h3 class="text-white"><?php
$payment_count=mysqli_query($conn,"SELECT SUM(price) price
FROM slips
WHERE user_id='$_SESSION[reid]'
ORDER BY id");
$payment_resalt=mysqli_fetch_assoc($payment_count);
echo 'Rs. '.number_format((float)$payment_resalt['price'],2);
?></h3>
										<div class="progress mb-2 bg-white">
                                            <div class="progress-bar progress-animated bg-light" style="width: 30%"></div>
                                        </div>
									</div>
								</div>
							</div>
						</div>
                    </div>
					<div class="col-xl-4 col-xxl-4 col-sm-6">
						<div class="widget-stat card" style="background-color: #000000;">
							<div class="card-body">
								<div class="media">
									<span class="mr-3">
									<i class="fa fa-calendar" aria-hidden="true" style="color:#2ac20b;"></i>
									</span>
									<div class="media-body text-white">
										<p class="mb-1">Total Daily Reload Amount</p>
										<h3 class="text-white"><?php
$month=date("Y-m-01");
$payment_count=mysqli_query($conn,"SELECT SUM(amount) amount
FROM ormsreload
WHERE userid='$_SESSION[reid]' and add_date='$month'
ORDER BY rid");
$payment_resalt=mysqli_fetch_assoc($payment_count);
echo 'Rs. '.number_format((float)$payment_resalt['amount'],2);
?></h3>
										<div class="progress mb-2 bg-white">
                                            <div class="progress-bar progress-animated bg-light" style="width: 30%"></div>
                                        </div>
									</div>
								</div>
							</div>
						</div>
                    </div>
					<div class="col-xl-4 col-xxl-4 col-sm-6">
						<div class="widget-stat card" style="background-color: #000000;">
							<div class="card-body">
								<div class="media">
									<span class="mr-3">
									<i class="fa fa-dollar" aria-hidden="true" style="color:#2ac20b;"></i>
									</span>
									<div class="media-body text-white">
										<p class="mb-1">Total Reload Amount</p>
										<h3 class="text-white"><?php
$payment_count=mysqli_query($conn,"SELECT SUM(amount) amount
FROM ormsreload
WHERE userid='$_SESSION[reid]'
ORDER BY rid");
$payment_resalt=mysqli_fetch_assoc($payment_count);
echo 'Rs. '.number_format((float)$payment_resalt['amount'],2);
?></h3>
										<div class="progress mb-2 bg-white">
                                            <div class="progress-bar progress-animated bg-light" style="width: 30%"></div>
                                        </div>
									</div>
								</div>
							</div>
						</div>
                    </div>
					</div>
                    </div>	
			<div class="col-md-6">
				<div class="card">
					<div class="card-header text-center bg-primay" style="background-color: #2ac20b;">
						<h4 style="color: #fff">RELATIONSHIP MANAGER</h4>
					</div>
					<div class="card-body" style="font-size: 18px">
						<p><i class="fa fa-user pr-3"></i><?php echo $user_resalt['fname'];?> <?php echo $user_resalt['lname'];?></p>
						<p><i class="fa fa-envelope pr-3"></i><a href="mailto:<?php echo $user_resalt['email'];?>"><?php echo $user_resalt['email'];?></a></p>
						<p><i class="fa fa-phone-square pr-3"></i><a href="tel:<?php echo $user_resalt['mobilenumber'];?>"><?php echo $user_resalt['mobilenumber'];?></a></p>
						<p><i class="fa fa-percent pr-3"></i><a href="comission_rates.php" style="color: #6c757d;cursor: pointer;">Commission Rates</a></p>
					</div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="card">
					<div class="card-header text-center bg-primay" style="background-color: #2ac20b;">
						<h4 style="color: #fff">CREDIT SUMMARY</h4>
					</div>
					<div class="card-body" style="font-size: 18px">
						<p><i class="fa fa-money pr-3"></i> Purchased : <?php
$payment_count=mysqli_query($conn,"SELECT SUM(price) price,user_id
FROM slips where user_id='".$customer."'
ORDER BY id");
$payment_resalt=mysqli_fetch_assoc($payment_count);
echo 'Rs. '.number_format((float)$payment_resalt['price'],2);
?></p>
						<p><i class="fa fa-repeat pr-3"></i> Utilized : <?php
$payment_count=mysqli_query($conn,"SELECT SUM(amount) amount,userid
FROM ormsreload where userid='".$customer."'
ORDER BY rid");
$payment_resalt=mysqli_fetch_assoc($payment_count);
echo 'Rs. '.number_format((float)$payment_resalt['amount'],2);
?></p>
						<!-- <p>Short: 0.00</p> -->
						<p>&nbsp;</p>
						<p>&nbsp;</p>
					</div>
				</div>
			</div>
			
            </div>
			<div class="row mb-3">
			<div class="col-md-12">
				<div class="card">
					<div class="card-header text-center" style="background-color: #2ac20b;">
						<h4 style="color: #fff">MY DAILY RELOADS</h4>
					</div>
					<div class="card-body">
					<div class="table-responsive">
                <table id="example3" class="table table-bordered">
                    <thead>
                        <tr>
                            <th>ID</th>                     
                            <th>Status</th>
                            <th>Customer</th>
                            <th>Provider</th>
                            <th>Number</th>
                            <th>Amount</th>
                            <th>Close Balance</th>
                            <th>Open Balance</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
    <?php
	date_default_timezone_set("Asia/Colombo");
	$current_date = date('Y-m-d', time());
    $stmt = $DB_con->prepare("SELECT ormsreload.*, ormsservices.sname, ormsservices.scode,ormsreload.add_date FROM ormsreload LEFT JOIN ormsservices ON ormsreload.provider=ormsservices.scode  WHERE ormsreload.customer='".$customer."' and ormsreload.add_date='2022-08-30' ORDER BY ormsreload.rid");

    $stmt->execute();

    $ob= $user_resalt['balance'];

    if($stmt->rowCount() > 0)

    {

    while($row=$stmt->fetch(PDO::FETCH_ASSOC))

    {

    extract($row);

    $cb =$ob-$row['amount'];

    ?>
                        <tr>
                            <td><?php echo $row['rid']; ?></td>

                            <td>
                            <?php 

                            if($row['status'] == "0"){

                            echo '<button class="btn btn-primary btn-sm">Pending</button>';

                            }else if($row['status'] == "1"){

                            echo '<button class="btn btn-success btn-sm">Active</button>';

                            }

                            ?>
                            </td>
                            <td><p><strong><?php echo $row['customer']; ?></strong></p></td>
                            <td><p><strong><?php echo $row['sname']; ?></strong></p></td>
                            <td><p><strong><?php echo $row['number']; ?></strong></p></td>
                            <td><p><strong>Rs.<?php echo $row['amount']; ?></strong></p></td>
                            <td><p><strong>Rs.<?php echo $cb; ?></strong></p></td>
                            <td><p><strong>Rs.<?php echo $ob; ?></strong></p></td>
                            <td><?php echo $row['add_date']; ?></td>                                            
                        </tr>

        <?php  

            $ob= $cb;
        ?>
    <?php } 

    }
    ?>
                    </tbody>
                </table>
            </div>
					</div>
				</div>
			</div>
		</div>
		<div class="row mb-3">
			<div class="col-md-12">
				<div class="card">
					<div class="card-header text-center" style="background-color: #2ac20b;">
						<h4 style="color: #fff">TOTAL DAILY RELOADS</h4>
					</div>
					<div class="card-body">
						<div class="table-responsive">
                <table id="example3" class="table table-bordered">
                    <thead>
                        <tr>
                            <th>ID</th>                     
                            <th>Status</th>
                            <th>Customer</th>
                            <th>Provider</th>
                            <th>Number</th>
                            <th>Amount</th>
                            <th>Close Balance</th>
                            <th>Open Balance</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
    <?php
	date_default_timezone_set("Asia/Colombo");
	$current_date = date('Y-m-d', time());
    $stmt = $DB_con->prepare("SELECT ormsreload.*, ormsservices.sname, ormsservices.scode,ormsreload.add_date FROM ormsreload LEFT JOIN ormsservices ON ormsreload.provider=ormsservices.scode  WHERE ormsreload.add_date='2022-08-30' ORDER BY ormsreload.rid");

    $stmt->execute();

    $ob= $user_resalt['balance'];

    if($stmt->rowCount() > 0)

    {

    while($row=$stmt->fetch(PDO::FETCH_ASSOC))

    {

    extract($row);

    $cb =$ob-$row['amount'];

    ?>
                        <tr>
                            <td><?php echo $row['rid']; ?></td>

                            <td>
                            <?php 

                            if($row['status'] == "0"){

                            echo '<button class="btn btn-primary btn-sm">Pending</button>';

                            }else if($row['status'] == "1"){

                            echo '<button class="btn btn-success btn-sm">Active</button>';

                            }

                            ?>
                            </td>
                            <td><p><strong><?php echo $row['customer']; ?></strong></p></td>
                            <td><p><strong><?php echo $row['sname']; ?></strong></p></td>
                            <td><p><strong><?php echo $row['number']; ?></strong></p></td>
                            <td><p><strong>Rs.<?php echo $row['amount']; ?></strong></p></td>
                            <td><p><strong>Rs.<?php echo $cb; ?></strong></p></td>
                            <td><p><strong>Rs.<?php echo $ob; ?></strong></p></td>
                            <td><?php echo $row['add_date']; ?></td>                                            
                        </tr>

        <?php  

            $ob= $cb;
        ?>
    <?php } 

    }
    ?>
                    </tbody>
                </table>
            </div>
					</div>
				</div>
			</div>
		</div>
		<div class="row mb-3">
			<div class="col-md-12">
				<div class="card">
					<div class="card-header text-center" style="background-color: #2ac20b;">
						<h4 style="color: #fff">OTHER DAILY RELOADS</h4>
					</div>
					<div class="card-body">
					<div class="table-responsive">
                <table id="example3" class="table table-bordered">
                    <thead>
                        <tr>
                            <th>ID</th>                     
                            <th>Status</th>
                            <th>Customer</th>
                            <th>Provider</th>
                            <th>Number</th>
                            <th>Amount</th>
                            <th>Close Balance</th>
                            <th>Open Balance</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
    <?php
	date_default_timezone_set("Asia/Colombo");
    $stmt = $DB_con->prepare("SELECT ormsreload.*, ormsservices.sname, ormsservices.scode,ormsreload.add_date FROM ormsreload LEFT JOIN ormsservices ON ormsreload.provider=ormsservices.scode ORDER BY ormsreload.rid");

    $stmt->execute();

    $ob= $user_resalt['balance'];

    if($stmt->rowCount() > 0)

    {

    while($row=$stmt->fetch(PDO::FETCH_ASSOC))

    {

    extract($row);

    $cb =$ob-$row['amount'];

    ?>
                        <tr>
                            <td><?php echo $row['rid']; ?></td>

                            <td>
                            <?php 

                            if($row['status'] == "0"){

                            echo '<button class="btn btn-primary btn-sm">Pending</button>';

                            }else if($row['status'] == "1"){

                            echo '<button class="btn btn-success btn-sm">Active</button>';

                            }

                            ?>
                            </td>
                            <td><p><strong><?php echo $row['customer']; ?></strong></p></td>
                            <td><p><strong><?php echo $row['sname']; ?></strong></p></td>
                            <td><p><strong><?php echo $row['number']; ?></strong></p></td>
                            <td><p><strong>Rs.<?php echo $row['amount']; ?></strong></p></td>
                            <td><p><strong>Rs.<?php echo $cb; ?></strong></p></td>
                            <td><p><strong>Rs.<?php echo $ob; ?></strong></p></td>
                            <td><?php echo $row['add_date']; ?></td>                                            
                        </tr>

        <?php  

            $ob= $cb;
        ?>
    <?php } 

    }
    ?>
                    </tbody>
                </table>
            </div>
					</div>
				</div>
			</div>
		</div>
        </div>
		</div>
        <!--**********************************
            Content body end
        ***********************************-->

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

		<!--**********************************
           Support ticket button start
        ***********************************-->

        <!--**********************************
           Support ticket button end
        ***********************************-->

    </div>
    <!--**********************************
        Main wrapper end
    ***********************************-->

    <?php
	require_once 'footerjs.php';
	?>
    
</body>
</html>