<?php
session_start();
error_reporting(0);
include('config.php');
if(strlen($_SESSION['alogin'])==0)
{
  header('location:index.php');
}
else
{
  $trade_id=$_GET['id'];

  define("PATH_TO_SCRIPTS", "mt5_api/");

  include PATH_TO_SCRIPTS . "mt5_api.php";

define('T_QUOTES', 'EURUSD,GBPUSD,USDJPY,AUDUSD,USDCAD'); //symbols list for publication

define("MT5_SERVER_IP", "31.42.176.73");

define("MT5_SERVER_PORT", "443");

define("MT5_SERVER_WEB_LOGIN", "77090");

define("MT5_SERVER_WEB_PASSWORD", "pfx@1234#"); 
/*
gateway login details 
198.24.167.20:441
---- abfx admin 
198.24.167.26:443
1000
abfx@1107
-->
login 1320
password : afx@2020
*/

define("MT5_CRYPT_PROTOCOL", true); // enable crypt protocol

define("IS_WRITE_DEBUG_LOG", true); // Write all in logs

define("MT5_CONNECTION_TIMEOUT", 3);

define("PATH_TO_LOGS", "./logs"); // Write all in logs

define("AGENT", "WebAPITesterArt");

$api = new MTWebAPI(AGENT, PATH_TO_LOGS, MT5_CRYPT_PROTOCOL);

$api->SetLoggerWriteDebug(IS_WRITE_DEBUG_LOG);

// mt5 manager  connection

if (($error_code = $api->Connect(MT5_SERVER_IP, MT5_SERVER_PORT, MT5_CONNECTION_TIMEOUT, MT5_SERVER_WEB_LOGIN, MT5_SERVER_WEB_PASSWORD)) != MTRetCode::MT_RET_OK) 
{
    /*
    echo "<script>alert('Invalid Details');</script>";
    */

  }
  else
  {
    /*
    echo "success";
    */
  }
// close history Get total
  $login=$trade_id;
  $from='March 30,2020';
  $to='March 31,2040';

  if (($error_code = $api->HistoryGetTotal($login, $from, $to, $total)) != MTRetCode::MT_RET_OK) 
  {
   return $error_code->HistoryGetTotal($login, $from, $to, $total);
    //--- request to the server
     //--- get total
   $total = $error_code->Total;
 }
 else
 {
  $closed_order_history=$total; 
}
// History Get Page
$login=$trade_id;
$offset='0';
$total=$closed_order_history;
$from='March 30,2020';
$to='March 22,2030';

if (($error_code = $api->HistoryGetPage($login, $from, $to, $offset, $total, $orders)) != MTRetCode::MT_RET_OK) 
{
 return $error_code->HistoryGetPage($login, $from, $to, $offset, $total, $orders);
    //--- request to the server
     //--- get object from json
 $orders = $error_code->GetArrayFromJson();
}
else
{
$result1=$orders;   //Prints [1,2,3]
}

}
?>      
<?php include('header.php');?>
<body>
  <!-- Preloader End Here -->
  <div id="wrapper" class="wrapper bg-ash">
   <?php include('main_header.php');?>
   <!-- Page Area Start Here -->
   <div class="dashboard-page-one">
    <?php include('side_header.php');?>

    <!-- Sidebar Area End Here -->
    <div class="dashboard-content-one">
      <!-- Breadcubs Area End Here --><br>
      <div class="row gutters-20">
        <div class="col-xl-12 col-sm-12 col-12">
          <div class="dashboard-summery-one mg-b-20">
            <div class="row align-items-center">
              <div class="col-6">
                <button type="button" class="btn-fill-lmd radius-30 text-light shadow-dark-pastel-green bg-dark-pastel-green">IB Account Commission Details</button>
              </div>
              <div class="col-6">
                <div class="item-content">
                  <a href="ib_withdrawal.php" class="btn-fill-lmd radius-30 text-light shadow-dodger-blue bg-orange-peel">Get Back</a>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- [ breadcrumb ] end -->
      <div class="container">
        <div class="row">
          <div class="col-md-6" style="margin-top: 10px;background-color: white;">
            <div class="table-responsive" style="margin-top: 0px;box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.08), 0 6px 20px 0 rgba(0, 0, 0, 0) !important;padding: 15px;">
               <h3 style="padding-top: 20px;color: red;">Current IB Commission</h3>
              <table class="table table-sm mb-0" style="margin-top: -17px;">
                <tbody>
                  <tr>
                    <td><b>Account Type</b></td>
                    <td> : &nbsp; <?php echo $_GET['type'];?></td>
                  </tr>
                  <tr>
                    <td><b>Account Type Commission</b></td>
                    <td> : &nbsp; $ <?php echo $_GET['ib_commission'];?></td>
                  </tr>
                  <tr>
                    <td><b>Leverage</b></td>
                    <td> : &nbsp; <?php echo $_GET['leverage'];?></td>
                  </tr>

                  <?php
                  $id=$_GET['id'];
                  $sql = "SELECT sum(volume) as volume from ib1_commission where login=:id AND status=0";
                  $query = $conn -> prepare($sql);
                  $query -> bindParam(':id',$id, PDO::PARAM_STR);
                  $query->execute();
                  $results=$query->fetchAll(PDO::FETCH_OBJ);
                  $cnt=1;
                  if($query->rowCount() > 0)
                  {
                    foreach($results as $result)
                    {
                      ?>
                      <tr>
                        <td><b>Lot Size Completed </b></td>
                        <td> : &nbsp; 
                          <?php
                          $a=$result->volume;
                          echo $volume=$a/2;
                          ?>
                        </td>
                      </tr>
                      <tr>
                        <td><b>Commission Generated </b></td>
                        <td> : &nbsp;
                          <?php
                          $volume=$result->volume;
                          $commission=$_GET['ib_commission'];
                          $total_commission=$volume*$commission;
                          $total_commission1= $total_commission/2;
                          echo '$'.' '.$total_commission1;
                          ?>
                        </td>
                      </tr>
                       <?php }}?>
                    </tr><br>
                  </tbody>
                </table><br>
              </div>
         </div><br><br>
          <div class="col-md-6" style="margin-top: 10px;background-color: white;">
            <div class="table-responsive" style="margin-top: 0px;box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.08), 0 6px 20px 0 rgba(0, 0, 0, 0) !important;padding: 15px;">
               <h3 style="padding-top: 20px;color: red;">Total IB Commission</h3>
              <table class="table table-sm mb-0" style="margin-top: -17px;">
                <tbody>
                  <tr>
                    <td><b>Account Type</b></td>
                    <td> : &nbsp; <?php echo $_GET['type'];?></td>
                  </tr>
                  <tr>
                    <td><b>Account Type Commission</b></td>
                    <td> : &nbsp; $ <?php echo $_GET['ib_commission'];?></td>
                  </tr>
                  <tr>
                    <td><b>Leverage</b></td>
                    <td> : &nbsp; <?php echo $_GET['leverage'];?></td>
                  </tr>

                  <?php
                  $id=$_GET['id'];
                  $sql = "SELECT sum(volume) as volume from ib1_commission where login=:id";
                  $query = $conn -> prepare($sql);
                  $query -> bindParam(':id',$id, PDO::PARAM_STR);
                  $query->execute();
                  $results=$query->fetchAll(PDO::FETCH_OBJ);
                  $cnt=1;
                  if($query->rowCount() > 0)
                  {
                    foreach($results as $result)
                    {
                      ?>
                      <tr>
                        <td><b>Lot Size Completed </b></td>
                        <td> : &nbsp; 
                          <?php
                          $a=$result->volume;
                          echo $volume=$a/2;
                          ?>
                        </td>
                      </tr>
                      <tr>
                        <td><b>Commission Generated </b></td>
                        <td> : &nbsp;
                          <?php
                          $volume=$result->volume;
                          $commission=$_GET['ib_commission'];
                          $total_commission=$volume*$commission;
                          echo '$'.' '.$total_commission;
                          ?>
                        </td>
                      </tr>
                       <?php }}?>
                    </tr><br>
                  </tbody>
                </table><br>
              </div>
         </div>
       </div>
        <div class="row">
          <div class="col-md-12" style="margin-top: 10px;background-color: white;">
                <div style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.08), 0 6px 20px 0 rgba(0, 0, 0, 0) !important;background-color:white;color:black;">
                        <h4 style="padding:15px;color: red;">
                          Internal Transfer IB Commission History
                        </h4>
                      </div>
                      <div class="table-responsive pt-3">
                        <table id="example" class="table table-striped mb-0">
                     <thead>
                        <th>IB Amount</th>
                        <th>Trade ID</th>
                          <th>Transfer To</th>
                          <th>Transfer Date</th>
                        </thead>
                        <?php
                          $eid=$_GET["id"];
                          $sql = "SELECT * from  ib_internal where trade_id=:eid";
                          $query = $conn -> prepare($sql);
                          $query->bindParam(':eid',$eid,PDO::PARAM_STR);
                          $query->execute();
                          $results=$query->fetchAll(PDO::FETCH_OBJ);
                          $cnt=1;
                          if($query->rowCount() > 0)
                          {
                            foreach($results as $result)
                            {
                              ?>
                          <tr>
                            <td>
                              <div>
                                $ <?php echo htmlentities($result->ib_amount);?>
                              </div>
                            </td>
                            <td>
                              <div>
                                <?php echo htmlentities($result->trade_id);?>
                              </div>
                            </td>
                            <td>
                              <div class="amount">
                                <?php echo htmlentities($result->transfer_to);?>
                              </div>
                            </td>
                            <td>
                              <div>
                                <?php echo htmlentities($result->transfer_date);?>
                              </div>
                            </td>
                            

                          </tr>
                          <?php }}?>
                  </table>
                </div><br>
         </div>
     
       </div><br><br><br><br>
       
     </div>
   </div>
 </div>
 <?php include('footer.php');?>
