<!doctype html>
<html lang="en" translate="no" class="w-[640px] mx-auto md:w-full">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>trading-record</title>
<?php echo view('user/layout/head');?>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.13.3/themes/base/jquery-ui.css">
</head>
<style>

.pagination {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}
    .pagination-btn {
    background: #007bff;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    margin: 0 5px;
}

.pagination-btn:disabled {
    background: #6c757d;
    cursor: not-allowed;
}
#pageInfo {
    align-self: center;
    margin: 0 10px;
}
</style>
<body class="reg-overflow">

<section class=" dash-banner-bg banner-bg">
<div class="container">
<!---header start---->
<?php echo view('user/layout/header');?>
<!---header end---->
<?php
$this->db = db_connect();
$this->session = session();
$this->common_model = model('CommonModel');
$user=$this->session->get('uusersid');
?>
<!---banner start---->
<div class="dash-wrap">
  <div class="title text-center py-2">
    <h2 class="text-primary ">Profit Records : <?php echo $datee;?></h2>
  </div>
  <div id="myItems">
  <?php 
                                       if(!empty($sell)) { 
                                       
                                       foreach ($sell as $key => $value) {
                                       if($value->avg_price > 0){ 
                                           $get_gas=0;
                                           if($value->order_id!='')
                                           {
                                            $description="fuel fee deduction for order no ".$value->order_id;
                                           
                                            $get_gas_fee=$this->db->query("select * from history where description like '%$description%' and uusersid='".$user."' and type in('deducted_gaswallet','fuel')")->getRow();
                                            //$query = $this->db->getLastQuery();
//echo (string)$query;

                                            if($get_gas_fee)
                                            {
                                                $get_gas=$get_gas_fee->amount;
                                            }
                                           }
                                           
                                          
                                       ?>
<div class="trade-record">
  <div class="record-sub-heading d-flex align-items-center">
    <iconify-icon icon="simple-icons:binance" class="text-primary me-2"></iconify-icon>
    <h3 class="text-white fw-normal">Order number : <?php if($value->order_id){ echo $value->order_id; }else{ echo '---'; }?> </h3>
  </div>

  <div class="trade-record-content d-flex">
  <ul class="list-unstyled trade-record-list trade-record-list-one text-start">
    <li>Exchange</li>
  
    <li>Profit</li>
    <li>Gas Fee</li>
    <li>Date and Time</li>
  </ul>

  <ul class="list-unstyled trade-record-list text-end">
    <li class="text-primary"><?php echo strtoupper($value->pair);?></li>
  
    <li class="text-success"><?php echo $value->comm_price;?></li>
    <li><?php echo $get_gas;?></li>
    <li><?php  if($value->time){echo date('Y-m-d H:i:s',(substr($value->time,0,-3)));}else{ echo '---' ;} ?></li>
  </ul>

</div>
</div>



<!---banner end---->



<?php } }
        }
        ?>
</div>

<div class="pagination">
                            <button id="prevPage" class="pagination-btn" onclick="changePage('prev')">« Previous</button>
                            <span id="pageInfo"></span>
                            <button id="nextPage" class="pagination-btn" onclick="changePage('next')">Next »</button>
                        </div>
                   </div>

</div>

 
<?php echo view('user/layout/footer');?>


</div>
</section>
<?php echo view('user/layout/footer-script');?>
<script src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script src="https://code.jquery.com/ui/1.13.3/jquery-ui.js"></script>

<script>
    let currentPage = 1;
const itemsPerPage = 5; // Number of items per page
let totalPages =1;


document.addEventListener('DOMContentLoaded', function() {
loadPage(currentPage);
});



function loadPage(page)
{
   
    var uusersid='<?php echo $this->session->get('uusersid');?>';
    $.ajax({
        'method': 'POST',
        'url': '<?php echo base_url();?>/profit_records/<?php echo $datee;?>',
         data:{'uusersid':uusersid,"page":page,"itemsPerPage":itemsPerPage},
        success:function(data)
        {
          
            var data= JSON.parse(data);
            // console.log(data.totalPages);
            // console.log(page);
            const myItems = document.getElementById('myItems');
            myItems.innerHTML = '';

            if (data.items.length === 0) {
                myItems.innerHTML = `<div class="faq_accordian mb-3">
                        <div class="accordion" style="margin:10px;text-align:center;color:red;"> No Records Found</div></div>`;
            }
            else
            {

            data.items.forEach(item => {
                myItems.innerHTML += `<div class="trade-record">
   <div class="record-sub-heading d-flex align-items-center">
      <iconify-icon icon="simple-icons:binance" class="text-primary me-2"></iconify-icon>
      <h3 class="text-white fw-normal">Order number :  ${item.orderNumber} </h3>
   </div>
   <div class="trade-record-content d-flex">
      <ul class="list-unstyled trade-record-list trade-record-list-one text-start">
         <li>Exchange</li>
         <li>Profit amount</li>
         <li>Fuel fee</li>
         <li>Time</li>
      </ul>
      <ul class="list-unstyled trade-record-list text-end">
         <li class="text-primary">${item.exchange}</li>
         <li class="text-success">${item.profit}</li>
         <li>${item.gas_fee}</li>
         <li>${item.dateTime}</li>
      </ul>
   </div>
</div>`; });
            }
       
        totalPages=data.totalPages;
    
        //document.getElementById('total_count').innerHTML=data.totalitems;
         document.getElementById('prevPage').disabled = !data.hasPrev;
            document.getElementById('nextPage').disabled = !data.hasNext;
            document.getElementById('pageInfo').innerText = `Page ${page} of ${data.totalPages}`;
        }
      })


      
}
         
function changePage(direction) {
   
   if (direction === 'prev' && currentPage > 1) {
       currentPage--;
   } else if (direction === 'next' && currentPage < totalPages) {
       currentPage++;
   }
   
   loadPage(currentPage);
}
</script>

</body>
</html>
