<!doctype html>
<html lang="en"  class="w-[640px]">
   <head>
   <?php echo view('user/layout/head');?>
   </head>
   <style>
  .head {
    background: linear-gradient(180deg, rgba(179,137,34,1) 0%, rgba(140,98,10,1) 50%, rgba(179,137,34,1) 100%, rgba(14,72,62,1) 100%);
    color: #fff;
    border: 1px;
    }
   </style>
   <body class="section-overflow">
      <!--banner start -->
      <section class="banner-bg overall-bg ">
         <div class="container">
         <?php echo view('user/layout/header');?>
         </div>
         <section class="dash-wrap team-wrap">
         <?php  
              use App\Libraries\MyEncrypt;
              use App\Helpers\site_helper;
              use App\Helpers\form_helper;
              $this->db = db_connect();
              $this->session = session();
              $this->common_model = model('CommonModel');
              $id = 'NyYmemh5aXA=';                        
              $myencrypt = new MyEncrypt;
              $coinid = $myencrypt->decode($id);
              $user=$this->session->get('uusersid');
              $con = "uusersid = '".$user."'";
              $user_details = $this->common_model->GetRow('uusers',$con);

              $builder = $this->db->table('history'); // Replace with your actual table name

              $lastRecord = $builder
                  ->where('uusersid',$user)
                  ->where('type', 'activation')
                  ->orderBy('historyid', 'DESC') // Replace 'id' with your primary key or timestamp column
                  ->get(1) // Limit to 1 record
                  ->getRow();

                  // print_r($lastRecord);
                  // exit;
             ?>
            <div class="container">
               <div class="team-tab">
                  <ul class="nav nav-pills d-flex justify-content-center ps-0" id="pills-tab" role="tablist">
                     <li class="nav-item" role="presentation">
                        <button class="nav-link active" id="pills-dep1-tab " data-bs-toggle="pill" data-bs-target="#pills-dep1"
                           type="button" role="tab" aria-controls="pills-dep1" aria-selected="true">
                           <div class="make-list">
                              <div class="process">
                                 <span>Summary</span>
                              </div>
                           </div>
                        </button>
                     </li>
                     <li class="nav-item" role="presentation">
                        <button class="nav-link" id="pills-dep2-tab " data-bs-toggle="pill" data-bs-target="#pills-dep2"
                           type="button" role="tab" aria-controls="pills-dep2" aria-selected="true">
                           <div class="make-list">
                              <div class="process">
                                 <span>Team</span>
                              </div>
                           </div>
                        </button>
                     </li>
                  </ul>
                  <div class="tab-content" id="pills-tabContent">
                     <div class="tab-pane fade show active" id="pills-dep1" role="tabpanel" aria-labelledby="pills-dep1-tab">
                        <div class="main-profile">
                           <div class="team-profile d-flex align-items-center my-3 justify-content-center">
                              <div class="profile-img mx-2">
                                 <iconify-icon icon="pajamas:profile"></iconify-icon>
                              </div>
                              <div class="profile-content">
                                 <h3 class=" text-white"><?php echo $user_details->username ;?></h3>
                                 <?php 
                                 $coinid='1';
                                 $buy_bal=curbalance($this->session->get('uusersid'),$coinid);
                                 $bal=str_replace(",","", $buy_bal);

                                 $total_members = $inactive_direct + $active_direct;
                                 $tmembers = $inactive_indirect + $active_indirect;
                                 ?>
                                 <span class="text-white-50">Total Income <b class="text-white"><?php echo $bal;?> USDT</b></span>
                              </div>
                           </div>
                        </div>
                        <div class="team-profit-content">
                           <div class="row">
                              <div class="col-12">
                                 <h5 class="text-primary py-2 fs-4 text-center">Activate Profit</h5>
                              </div>
                              <div class="col-6">
                                 <div class="team-list">
                                    <p class="fw-light text-white-50 mb-0">Activate Profit Today</p>
                                    <h4 class="fw-bold text-white"><?php echo number_format($today_profit,2);?></h4>
                                 </div>
                              </div>
                              <div class="col-6">
                                 <div class="team-list">
                                    <p class="fw-light text-white-50 mb-0">Activate Total profit</p>
                                    <h4 class="fw-bold text-white"><?php echo number_format($total_profit,2);?></h4>
                                 </div>
                              </div>
                           </div>
                        </div>
                        <div class="team-profit-content">
                           <div class="row">
                              <div class="col-12">
                                 <h5 class="text-primary py-2 fs-4 text-center">Direct Sponsor</h5>
                              </div>
                              <div class="col-6">
                                 <div class="team-list">
                                    <p class="fw-light text-white-50 mb-0">Total Member(s)</p>
                                    <h4 class="fw-bold text-white"><?php echo $total_members;?></h4>
                                 </div>
                              </div>
                              <div class="col-6">
                                 <div class="team-list">
                                    <p class="fw-light text-white-50 mb-0">Activated</p>
                                    <h4 class="fw-bold text-white"><?php echo $active_direct;?></h4>
                                 </div>
                              </div>
                           </div>
                        </div>
                        <div class="team-profit-content">
                           <div class="row">
                              <div class="col-12">
                                 <h5 class="text-primary py-2 fs-4 text-center">Group Memebers </h5>
                              </div>
                              <div class="col-6">
                                 <div class="team-list">
                                    <p class="fw-light text-white-50 mb-0">Total</p>
                                    <h4 class="fw-bold text-white"><?php echo  $tmembers;?></h4>
                                 </div>
                              </div>
                              <div class="col-6">
                                 <div class="team-list">
                                    <p class="fw-light text-white-50 mb-0">Activated</p>
                                    <h4 class="fw-bold text-white"><?php echo $active_indirect;?></h4>
                                 </div>
                              </div>
                           </div>
                        </div>

                        <!-- <h4 class="text-primary">Member Level list</h4>
                        <h6 class="text-white-50">Total Members : <?php echo $tmembers;?></h6> -->

                     



                     </div>
                     <div class="tab-pane fade " id="pills-dep2" role="tabpanel" aria-labelledby="pills-dep2-tab">
                        <div class="search-bar ">
                           <form class="form-inline  ">
                              <input class="form-control my-3" type="search" id="myInput" placeholder="Search username...." aria-label="Search">
                           </form>
                        </div>
                        <div class="row">
                           <div class="col-lg-12">
                              <div class="faq_accordian mb-3">
                                 <div class="accordion">
                                    <div class="row">
                                       <div class="col-md-12">
                                          <div class="team-right accordion-toggle u">
                                             <div class="main-right-content">
                                                <h5 class="text-white mb-0 mysearch"><?php echo $user_details->username ;?> (you)</h5>
                                                <small class="text-white">revbot validity : <?php echo date('d M Y',strtotime($lastRecord->expiry_date)) ;?></small>
                                                <h6 class="text-white-50">Total Income <?php echo $bal;?> USDT</h6>
                                             </div>
                                             <ul class="mb-0 asset-user-static list-unstyled">
                                                <li>
                                                   <p class="text-white-50 mb-0">Today Profit:</p>
                                                   <b class="text-white"><?php echo number_format($today_profit,2);?></b>
                                                </li>
                                                <li>
                                                   <p class="text-white-50 mb-0">Total Profit:</p>
                                                   <b class="text-white"><?php echo number_format($total_profit,2);?></b>
                                                </li>
                                                <li>
                                                   <p class="text-white-50 mb-0">USDT balance :</p>
                                                   <b class="text-white"><?php echo $bal;?></b>
                                                </li>
                                             </ul>
                                          </div>
                                          <div class="team-right accordion-content">

                                          <?php
                                             if($direct_referrals) {
                                             foreach ($direct_referrals as $key => $sponser) 
                                             {
                                                
                                                $con = "uusersid = '".$sponser->uusersid."'";

                                                $userid = $sponser->uusersid;

                                                $udetails = $this->common_model->GetRow('uusers',$con);


                                                if($udetails->username == '')
                                                {
                                                   $name = "---";
                                                }
                                                else
                                                {
                                                   $name = $udetails->username;
                                                }

                                          
                                                $today_profif1 =$this->common_model->today_profit($user_details->uusersid);
                                                $total_profit1 = $this->common_model->total_profit($user_details->uusersid);


                                                $builder1 = $this->db->table('history'); // Replace with your actual table name

                                                $lastRecord1 = $builder1
                                                      ->where('uusersid',$user_details->uusersid)
                                                      ->where('type', 'activation')
                                                      ->orderBy('historyid', 'DESC') // Replace 'id' with your primary key or timestamp column
                                                      ->get(1) // Limit to 1 record
                                                      ->getRow();

                                              

                                                $coinid='1';
                                                $buy_bal=curbalance($userid,$coinid);
                                                $bal=str_replace(",","", $buy_bal);
                                                // $rank_name = $this->db->query('select * from rewardsettings where id = "'.$sponser->rank.'"')->getRow()->rank_name;
                                          ?>

                                             <div class="accordion-display-content">
                                                <div class="main-right-content">
                                                   <h5 class="text-white mb-0 mysearch"><?php echo ucfirst($name);?></h5>
                                                   <small class="text-white">revbot validity :- <span class="fw-bold"><?php echo date('d M Y',strtotime($lastRecord1->expiry_date)) ;?></span></small>
                                                   <h6 class="text-white-50">Total Income <?php echo $bal;?></h6>
                                                </div>
                                                <ul class="mb-0 asset-user-static list-unstyled">
                                                   <li>
                                                      <p class="text-white-50 mb-0">Today Profit:</p>
                                                      <b class="text-white"><?php echo number_format($today_profit1,2);?></b>
                                                   </li>
                                                   <li>
                                                      <p class="text-white-50 mb-0">Total Profit:</p>
                                                      <b class="text-white"><?php echo number_format($total_profit1,2);?></b>
                                                   </li>
                                                   <li>
                                                      <p class="text-white-50 mb-0">USDT balance :</p>
                                                      <b class="text-white"><?php echo $bal;?></b>
                                                   </li>
                                                </ul>
                                             </div>


                                             <?php } }else{ ?>

                                                <div class="accordion-display-content">
                                                <b class="text-white">No Records Found</b>
                                             </div>
                                                <?php } ?>
                                             
                                          </div>
                                       </div>
                                    </div>
                                 </div>
                              </div>
                           </div>
                        </div>
                     </div>
                     <!---banner end---->
                  </div>
               </div>
            </div>
         </section>
         <!--footer start -->
         <?php echo view('user/layout/footer');?>
         <!--footer end -->
      </section>
 
      <?php echo view('user/layout/footer-script');?>
      <script>
         AOS.init({
         });
      </script>

      <script>
      $(document).ready(function () {
      $("#myInput").on("keyup", function () {
         var value = $(this).val().toLowerCase();
         $(".accordion-display-content").filter(function () {
            $(this).toggle($(this).find(".mysearch").text().toLowerCase().indexOf(value) > -1);
         });
      });
      });
      </script>

   </body>
</html>

