<?php 
ob_start();
session_start();
include 'config/config.php';
include 'config/function.php';
if($_SESSION['member_user_id']=='')
{
    header("Location:Login");
    exit();
}

?>
<html lang="en">

<head>
    <title>Dashboard : <?php echo get_company(); ?> </title>
   
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="author" content="Phoenixcoded">
    <!-- Favicon icon -->
    <link rel="icon" href="assets/images/favicon.ico" type="image/x-icon">

    <!-- vendor css -->
    <link rel="stylesheet" href="assets/css/style.css">
    
    

</head>
<body class="">
	<!-- [ Pre-loader ] start -->
	<div class="loader-bg">
		<div class="loader-track">
			<div class="loader-fill"></div>
		</div>
	</div>
	<!-- [ Pre-loader ] End -->
	<!-- [ Header ]  -->
<?php include 'inc/vertical.php'; ?>

<!-- [ Main Content ] start -->
<div class="pcoded-main-container">
    <div class="pcoded-content">
        <!-- [ breadcrumb ] start -->
        <div class="page-header">
            <div class="page-block">
                <div class="row align-items-center">
                    <div class="col-md-12">
                        <div class="page-header-title">
                            <h5 class="m-b-10">Dashboard Analytics</h5>
                            <h6><?php echo $member_user_id=$_SESSION['member_user_id']; ?> (<?php echo $_SESSION['member_name'] ?>)</h6>
                        </div>
                       
                    </div>
                </div>
            </div>
        </div>
        <!-- [ breadcrumb ] end -->
        <!-- [ Main Content ] start -->
        <div class="row">
            <!-- table card-1 start -->
            <div class="col-md-12 col-xl-6">
                <div class="card flat-card">
                    <div class="row-table">
                        <div class="col-sm-6 card-body br">
                            <a href="ActiveCustomer">
                            <div class="row">
                                <div class="col-sm-3">
                                    <i class="icon feather icon-eye text-c-green mb-1 d-block"></i>
                                </div>
                                <?php
                                $strC="Select count(member_user_id) as cnt from tbl_memberreg where sponcer_id='$member_user_id' and is_customer=1";
                                $customer=get_value($strC);
                                ?>
                                <div class="col-sm-9 text-md-center">
                                    <h5><?php echo $customer; ?></h5>
                                    <span>Customer</span>
                                </div>
                            </div></a>
                        </div>
                        <div class="col-sm-6 card-body">
                            <div class="row">
                                <div class="col-sm-3">
                                    <i class="icon feather icon-music text-c-red mb-1 d-block"></i>
                                </div>
                                 <?php
                                $strC="Select left_member from tbl_memberreg where member_user_id='$member_user_id' ";
                                $left_member=get_value($strC);
                                ?>
                                <div class="col-sm-9 text-md-center">
                                    <h5><?php echo $left_member; ?></h5>
                                    <span>Left Team</span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row-table">
                        <div class="col-sm-6 card-body br">
                            <div class="row">
                                <div class="col-sm-3">
                                    <i class="icon feather icon-file-text text-c-blue mb-1 d-block"></i>
                                </div>
                                  <?php
                                $strC="Select right_member from tbl_memberreg where member_user_id='$member_user_id' ";
                                $right_member=get_value($strC);
                                ?>
                                <div class="col-sm-9 text-md-center">
                                    <h5><?php echo $right_member; ?></h5>
                                    <span>Right Team</span>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-6 card-body">
                            <div class="row">
                                <div class="col-sm-3">
                                    <i class="icon feather icon-mail text-c-yellow mb-1 d-block"></i>
                                </div>
                                <div class="col-sm-9 text-md-center">
                                    <h5><?php echo $right_member+$left_member ?></h5>
                                    <span>Total Team</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- table card-1 end -->
            <!-- table card-2 start -->
            <div class="col-md-12 col-xl-6">
                <div class="card flat-card">
                    <div class="row-table">
                        <div class="col-sm-6 card-body br">
                            <div class="row">
                                <div class="col-sm-3">
                                    <i class="icon feather icon-share-2 text-c-blue mb-1 d-block"></i>
                                </div>
                                  <?php
                                $strC="Select  direct_business from tbl_memberreg where member_user_id='$member_user_id' ";
                                $direct_business=get_value($strC);
                                ?>
                                <div class="col-sm-9 text-md-center">
                                    <h5><?php echo $direct_business; ?></h5>
                                    <span>Direct Business</span>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-6 card-body">
                            <div class="row">
                                <div class="col-sm-3">
                                    <i class="icon feather icon-wifi text-c-blue mb-1 d-block"></i>
                                </div>
                                 <?php
                                $strC="Select  left_business from tbl_memberreg where member_user_id='$member_user_id' ";
                                $left_business=get_value($strC);
                                ?>
                                <div class="col-sm-9 text-md-center">
                                    <h5><?php echo $left_business; ?></h5>
                                    <span>Left Business</span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row-table">
                        <div class="col-sm-6 card-body br">
                            <div class="row">
                                <div class="col-sm-3">
                                    <i class="icon feather icon-rotate-ccw text-c-blue mb-1 d-block"></i>
                                </div>
                                 <?php
                                $strC="Select  right_business from tbl_memberreg where member_user_id='$member_user_id' ";
                                $right_business=get_value($strC);
                                ?>
                                <div class="col-sm-9 text-md-center">
                                    <h5><?php echo $right_business; ?></h5>
                                    <span>Right Business</span>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-6 card-body">
                            <div class="row">
                                <div class="col-sm-3">
                                    <i class="icon feather icon-shopping-cart text-c-blue mb-1 d-blockz"></i>
                                </div>
                                 <?php
                                $strC="Select  paid_business from tbl_memberreg where member_user_id='$member_user_id' ";
                                $paid_business=get_value($strC);
                                ?>
                                <div class="col-sm-9 text-md-center">
                                    <h5><?php echo $paid_business; ?></h5>
                                    <span>Matching Business</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
               
            </div>
            <div class="col-md-12 col-xl-4">
                <div class="card flat-card widget-primary-card">
                    <div class="row-table">
                        <div class="col-sm-3 card-body">
                            <i class="feather icon-star-on"></i>
                        </div>
                        <?php
                                $strC="SELECT IFNULL(sum(income_amt),0) as income_id FROM tbl_member_income_dtails WHERE member_user_id='$member_user_id' and income_type='DIRECT INCOME'";
                                $DirectIncome=get_value($strC);
                                ?>
                        <div class="col-sm-9">
                            <h4><?php echo $DirectIncome; ?></h4>
                            <h6>Direct Income</h6>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-12 col-xl-4">
                 <!-- widget-success-card start -->
                <div class="card flat-card widget-purple-card">
                    <div class="row-table">
                        <div class="col-sm-3 card-body">
                            <i class="fas fa-trophy"></i>
                        </div>
                         <?php
                                $strC="SELECT IFNULL(sum(income_amt),0) as income_id FROM tbl_member_income_dtails WHERE member_user_id='$member_user_id' and income_type='BINARY INCOME'";
                                $MatchingIncome=get_value($strC);
                                ?>
                        <div class="col-sm-9">
                            <h4><?php echo $MatchingIncome; ?></h4>
                            <h6>Binary Income</h6>
                        </div>
                    </div>
                </div>
                <!-- widget-success-card end -->
            </div>
            <div class="col-md-12 col-xl-4">
                 <!-- widget-success-card start -->
                <div class="card flat-card widget-purple-card">
                    <div class="row-table">
                        <div class="col-sm-3 card-body">
                            <i class="fas fa-trophy"></i>
                        </div>
                         <?php
                                $strC="SELECT IFNULL(sum(income_amt),0) as income_id FROM tbl_member_income_dtails WHERE member_user_id='$member_user_id' and paid_status=0";
                                $UnpaidIncome=get_value($strC);
                                ?>
                        <div class="col-sm-9">
                            <h4><?php echo $UnpaidIncome; ?></h4>
                            <h6>Unpaid Income</h6>
                        </div>
                    </div>
                </div>
                <!-- widget-success-card end -->
            </div>
           <!-- prject ,team member start -->
            <div class="col-xl-12 col-md-12">
                <div class="card table-card">
                     <?php
                    $strC="SELECT calculate_date FROM tbl_member_income_dtails order by calculate_date desc limit 0,1";
                     $calculate_date=get_value($strC);
                     $last_closing=date("Y-m-d",strtotime($calculate_date));
                    ?>
                    <div class="card-header">
                        <h5>Current Income as on <?php echo date("d-M-Y",strtotime($calculate_date)); ?> </h5>
                    </div>
                    <div class="card-body p-0">
                        <div class="table-responsive">
                            <table class="table table-hover mb-0">
                                <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>Income Amt</th>
                                        <th>Income Type</th>
                                        <th>Income From</th>
                                        <th>Business/Per(%)</th>
                                    </tr>
                                </thead>
                                <tbody>
                                   <?php
                                   $cnt=1;$total=0;
                                   $strI="Select * from tbl_member_income_dtails where member_user_id='$member_user_id' and calculate_date='$last_closing'";
                                   $resI=mysqli_query($connection,$strI) or die(mysqli_error($connection));
                                   while($rowI=mysqli_fetch_array($resI))
                                   {
                                       $total=$total+$rowI['income_amt'];
                                   ?>
                                    <tr>
                                        <td><?php echo $cnt++; ?></td>
                                        <td><?php echo $rowI['income_amt']; ?></td>
                                        <td><?php echo $rowI['income_type']; ?></td>
                                         <td><?php echo $rowI['income_member_user_id']; ?></td>
                                          <td><?php echo $rowI['matching_business']; ?>/(<?php echo $rowI['income_per']; ?>)</td>
                                    </tr>
                                    <?php } ?>
                                    <tr>
                                        <td><b>Total Income</b></td>
                                        <td><b><?php echo $total; ?></b></td>
                                        <td></td><td></td><td></td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        
        </div>
        <!-- [ Main Content ] end -->
    </div>
</div>

    <!-- Required Js -->
    <script src="assets/js/vendor-all.min.js"></script>
    <script src="assets/js/plugins/bootstrap.min.js"></script>
    <script src="assets/js/pcoded.min.js"></script>

<!-- Apex Chart -->
<script src="assets/js/plugins/apexcharts.min.js"></script>


<!-- custom-chart js -->
<script src="assets/js/pages/dashboard-main.js"></script>
</body>

</html>
