
<!DOCTYPE html>
<html lang="en">

<head>
<?php

include "header.php";
$email = $user->getEmail();

$qq = mysqli_query($link, "SELECT * FROM trade WHERE email = '$email' ORDER BY id DESC ");
    if (mysqli_num_rows($qq) > 0) {
        while ($tr = mysqli_fetch_assoc($qq)) {
            $status = $tr['status'];
            $trade_type = $tr['trade_type'];
            $amount = $tr['amount'];
            $symbol = $tr['symbol'];
            $units = $tr['units'];
            $trade_interval = $tr['trade_interval'];
            $market = $tr['market'];
            $profit = $tr['profit'];
            $trade_exp = $tr['trade_exp'];
            $trade_set = $tr['trade_set'];
            $win_loss = $tr['win_loss'];
            $tid = $tr['id'];
            $credited = $tr['credited'];

            $current_time = date('Y-m-d H:i:s');

            if ($trade_exp == $current_time || $current_time >= $trade_exp) {
                //the status
                if ($win_loss == 1) {
                    $status = 3;
                }elseif ($win_loss == 0) {
                    $status = 2;
                }
                //profit
                if ($win_loss == 1) {
                    $profit = (90/100)*$amount;
                }elseif ($win_loss == 0) {
                    $profit = 0;
                }
                $update = mysqli_query($link, "UPDATE trade SET status = '$status', profit = '$profit', credited = 1 WHERE id = '$tid' ");
                //credit user profit
                if ($update && $credited == 0) {
                    switch ($user->getAccounttype()) {
                        case 'live':
                            $col = 'balance';
                            break;
                        case 'demo':
                            $col = 'demo_balance';
                            break;
                        default:
                            break;
                    }
                    $upuser = mysqli_query($link, "UPDATE user SET $col = $col + '$profit' WHERE email = '$email' " );
                }
            }else{

            }
        }
    }
?>

</head>

<body>
    
    <nav class="navbar navbar-expand-md navbar-light custom__nav">

        <div class="custom__sidebar__icon d-none d-md-block">
            <i class=" far fa-bars"></i>
        </div>

        <a class="navbar-brand custom__brand" href="index.php"><?php echo $site_name ?>
        </a>

        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#mobilenav"
            aria-controls="mobilenav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navbarText">
            <ul class="navbar-nav mr-auto">
                <div class="d-md-none">
                    <li class="nav-item active">
                        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Features</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Pricing</a>
                    </li>
                </div>
            </ul>
            <span class="navbar-text d-flex">

                <div class="notif__class mr-3">
                                        <span class="sup__color"></span>
                                        <i class="far fa-bells"></i>
                </div>

                <div class="mr-3"><img class="navatar__class"
                        src="<?php echo $user->getProfile_pic()  ?>" width="25px" alt=""></div>

                <div><?php echo $user->getFullname()  ?></div>
            </span>
        </div>
    </nav>

    <div class="wrapper">

<nav id="sidebar" class="d-none d-md-block">

   <?php

    include "sidebar.php";

   ?>
        </div>

    </nav>

    <!-- Page Content -->
    <div id="content">
        <!-- We'll fill this with dummy content -->
        <?php

            include "sidebar_mobile.php";

            ?>
        
        </div>


            <div class="container-fluid">
                <div class="custom__content_wrapper">

                    <div class="custom__content__title">
                        <h5>Transactions</h5>
                    </div>

                    <div class="custom__card__wrapper mb-3">
                        <!-- TradingView Widget BEGIN -->
<div class="tradingview-widget-container">
  <div class="tradingview-widget-container__widget"></div>
  <div class="tradingview-widget-copyright"><a href="https://www.tradingview.com/" rel="noopener nofollow" target="_blank"><span class="blue-text">Track all markets on TradingView</span></a></div>
  <script type="text/javascript" src="https://s3.tradingview.com/external-embedding/embed-widget-ticker-tape.js" async>
  {
  "symbols": [
    {
      "proName": "FOREXCOM:SPXUSD",
      "title": "S&P 500"
    },
    {
      "proName": "FOREXCOM:NSXUSD",
      "title": "US 100"
    },
    {
      "proName": "FX_IDC:EURUSD",
      "title": "EUR/USD"
    },
    {
      "proName": "BITSTAMP:BTCUSD",
      "title": "Bitcoin"
    },
    {
      "proName": "BITSTAMP:ETHUSD",
      "title": "Ethereum"
    }
  ],
  "showSymbolLogo": true,
  "colorTheme": "light",
  "isTransparent": false,
  "displayMode": "adaptive",
  "locale": "en"
}
  </script>
</div>
<!-- TradingView Widget END -->
                    </div>


                    <div class="row">
                        
                        <div class="col-12 col-md-6 col-lg-3 mb-3">
                            <div class="custom__card__wrapper">
                                <div class="custom__dash__block">
                                    <div class="d-flex justify-content-between">
                                        <div class="">
                                            <div class="custom__dash__currency custom__red">
                                                $<?php echo $user->getInvested() ?>
                                            </div>
                                            <div class="custom__dash__desc">Total Funds Deposited</div>
                                        </div>
                                        <div class="">
                                            <i class="fa-2x custom__dash__icon fad fa-chart-bar"></i>
                                        </div>
                                    </div>

                                    
                                    
                                </div>
                            </div>
                        </div>

                        
                        <div class="col-12 col-md-6 col-lg-3 mb-3">
                            <div class="custom__card__wrapper">
                                <div class="custom__dash__block">
                                    <div class="d-flex justify-content-between">
                                        <div class="">
                                            <div class="custom__dash__currency custom__lemon">
                                                $<?php echo $user->getProfit() ?>
                                            </div>
                                            <div class="custom__dash__desc">Account Profit</div>
                                        </div>
                                        <div class="">
                                            <i class="fa-2x custom__dash__icon fad fa-chart-bar"></i>
                                        </div>
                                    </div>

                                    
                                  
                                </div>
                            </div>
                        </div>

                        
                        <div class="col-12 col-md-6 col-lg-3 mb-3">
                            <div class="custom__card__wrapper">
                                <div class="custom__dash__block">
                                    <div class="d-flex justify-content-between">
                                        <div class="">
                                            <div class="custom__dash__currency custom__blue">
                                                $<?php echo $user->getBalance() ?>
                                            </div>
                                            <div class="custom__dash__desc">Account Withdrawable</div>
                                        </div>
                                        <div class="">
                                            <i class="fa-2x custom__dash__icon fad fa-analytics"></i>
                                        </div>
                                    </div>

                                    
                                    
                                </div>
                            </div>
                        </div>

                        
                        <div class="col-12 col-md-6 col-lg-3 mb-3">
                            <div class="custom__card__wrapper">
                                <div class="custom__dash__block">
                                    <div class="d-flex justify-content-between">
                                        <div class="">
                                            <div class="custom__dash__currency custom__green">
                                                $<?php echo $user->getWithdrawn() ?>
                                            </div>
                                            <div class="custom__dash__desc">Total Funds Withdrawn</div>
                                        </div>
                                        <div class="">
                                            <i class="fa-2x custom__dash__icon fad fa-chart-bar"></i>
                                        </div>
                                    </div>

                                    
                                    
                                </div>
                            </div>
                        </div>
                    </div>


                    
<div class="custom__card__wrapper mb-3">

    <div class="card">
        <h5 class="card-header">Transactions</h5>
        <div class="card-body">
            <h5 class="card-title">Account Statement</h5>
            <p>Contact us at <?php echo $site_email ?> for complaints on transactions</p>

           <table class="table table-striped table-custom">
                            <thead class="th-text-md">
                                <tr>
                                    <th><i class="fa fa-clock"></i></th>
                                    <th><span>Trade Type</span></th>
                                    <th><span>Amount</span></th>
                                    <th><span>Symbol</span></th>
                                    <th><span>Units</span></th>
                                    <th><span>Trade Interval</span></th>
                                    <th><span>Market</span></th>
                                    <th><span>Trade Profit</span></th>
                                    <th><span>Status</span></th>
                                </tr>
                            </thead>
                            <tbody class="tb-text-md">
                                <?php  
// status = 1; trade on going
// status = 2; trade loss
// status = 3; trade win
                                    $qq = mysqli_query($link, "SELECT * FROM trade WHERE email = '$email' ORDER BY id DESC ");
                                    if (mysqli_num_rows($qq) > 0) {
                                        while ($tr = mysqli_fetch_assoc($qq)) {
                                            $status = $tr['status'];
                                            $trade_type = $tr['trade_type'];
                                            $amount = $tr['amount'];
                                            $symbol = $tr['symbol'];
                                            $units = $tr['units'];
                                            $trade_interval = $tr['trade_interval'];
                                            $market = $tr['market'];
                                            $profit = $tr['profit'];
                                            $trade_exp = $tr['trade_exp'];
                                            $trade_set = $tr['trade_set'];
                                            $win_loss = $tr['win_loss'];
                                            $tid = $tr['id'];
                                            $credited = $tr['credited'];

                                            $current_time = date('Y-m-d H:i:s');

                                            if ($trade_exp == $current_time || $current_time >= $trade_exp) {
                                                //the status
                                                if ($win_loss == 1) {
                                                    $status = 3;
                                                }elseif ($win_loss == 0) {
                                                    $status = 2;
                                                }
                                                //profit
                                                if ($win_loss == 1) {
                                                    $profit = (90/100)*$amount;
                                                    $uprofit = ((90/100)*$amount) + $amount;
                                                }elseif ($win_loss == 0) {
                                                    $profit = 0;
                                                    $uprofit = 0;
                                                }
                                                $update = mysqli_query($link, "UPDATE trade SET status = '$status', profit = '$profit', credited = 1 WHERE id = '$tid' ");
                                                //credit user profit
                                                if ($update && $credited == 0) {
                                                    switch ($account_type) {
                                                        case 'live':
                                                            $col = 'balance';
                                                            break;
                                                        case 'demo':
                                                            $col = 'demo_balance';
                                                            break;
                                                        default:
                                                            break;
                                                    }
                                                    $upuser = mysqli_query($link, "UPDATE user SET $col = $col + '$uprofit' WHERE email = '$email' " );
                                                    echo "<script>window.location.href = 'index.php' </script>";
                                                }
                                            }else{

                                            }


                                    switch ($status) {
                                        case '1':
                                            $t_txtcolor = 'warning';
                                            $p_txtcolor = 'warning';
                                            $s_txtcolor = 'warning';
                                            break;
                                        case '2':
                                            $t_txtcolor = 'danger';
                                            $p_txtcolor = 'danger';
                                            $s_txtcolor = 'danger';
                                            break;
                                        case '3':
                                            $t_txtcolor = 'success';
                                            $p_txtcolor = 'success';
                                            $s_txtcolor = 'success';
                                            break;
                                        default:
                                            # code...
                                            break;
                                    }

                                      
                                ?>

                                <tr>
                                    <td>
                                        <span class='text-<?php echo $t_txtcolor ?>'><?php echo $trade_set ?></span>
                                    </td>
                                    <td>
                                        <?php echo $trade_type ?>
                                        <?php  
                                            if ($status == 1) {
                                        ?>
                                        <i class="fa fa-spin fa-spinner"></i>
                                    <?php } ?>
                                    </td>
                                    <td class="text-success">$<?php echo $amount ?></td>
                                    <td><?php echo $symbol ?></td>
                                    <td><?php echo $units ?></td>
                                    <td><?php echo $market ?></td>
                                    <td><?php echo $trade_interval ?></td>
                                    <td>
                                        <span class='text-<?php echo $p_txtcolor ?>'>
                                            <?php  
                                                if ($status == 1) {
                                            ?>
                                            Trade Ongoing
                                             <?php } ?>

                                             <?php  
                                                if ($status == 2) {
                                                    echo "+".$profit;
                                                }
                                             ?>

                                             <?php  
                                                if ($status == 3) {
                                                    echo "+".$profit;
                                                }
                                             ?>

                                        </span>
                                    </td>

                                    <td>
                                        <span class='text-<?php echo $s_txtcolor ?>'>
                                            <?php  
                                                if ($status == 1) {
                                            ?>
                                            Trade Ongoing
                                             <?php } ?>

                                             <?php  
                                                if ($status == 2) {
                                                    echo "Loss";
                                                }
                                             ?>

                                             <?php  
                                                if ($status == 3) {
                                                    echo "Win";
                                                }
                                             ?>
                                        </span>
                                    </td>
                                </tr>
                                
      
                                
                                <?php 
                                      }
                                  }
                                 ?>
                            </tbody>
                        </table>

        </div>
    </div>

</div>


                </div>
            </div>

        </div><!-- Content -->

    </div><!-- Wrapper Ends -->
    <?php

        include "footer.php";

       ?>
</body>

</html>