<?php
header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=BalanceTransactions_userID_".$user_id."-" . date('Ymd') . ".xls");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Expires: 0");
ini_set('zlib.output_compression', 'Off');
header('X-Accel-Buffering: no');
ini_set('max_execution_time',20000);
ini_set('proxy_read_timeout',0);
set_time_limit(0);
ob_implicit_flush(true);
ob_end_flush();
$output = "";
$output .='
<table class="table table-striped" id="table2excel">
    <thead>
    <tr>
        <th style="font-weight: bold">ID</th>
        <th style="font-weight: bold">Type</th>
        <th style="font-weight: bold">Amount USD</th>
        <th style="font-weight: bold">Amount EGP</th>
        <th style="font-weight: bold">EGP currency rate</th>
        <th style="font-weight: bold">SAR currency rate</th>
        <th style="font-weight: bold">AED currency rate</th>
        <th style="font-weight: bold">KWD currency rate</th>
        <th style="font-weight: bold">balanceType</th>
        <th style="font-weight: bold">sourceType</th>
        <th style="font-weight: bold">sourceID</th>
        <th style="font-weight: bold">Pending Balance After</th>
        <th style="font-weight: bold">Confirmed Balance After</th>
        <th style="font-weight: bold">Is Reverted</th>
        <th style="font-weight: bold">Created At</th>
    </tr>
    </thead>
    <tbody>
	' ;
  foreach ($balance_transactions as $key=>$item) {
      flush();
      ob_flush();
      sleep(0.01);
        $output .="<tr>
            <td>".$item['id']."</td>
            <td>".$item['transaction_type']."</td>
            <td>".$item['amount']."</td>
            <td>".($item['amount']*$item['currencyRateEGP'])."</td>
            <td>".$item['currencyRateEGP']."</td>
            <td>".$item['currencyRateSAR']."</td>
            <td>".$item['currencyRateAED']."</td>
            <td>".$item['currencyRateKWD']."</td>
            <td>".$item['balance_type']."</td>
            <td>".$item['source_type']."</td>
            <td>".$item['source_id']."</td>
            <td>".$item['pending_balance_after']."</td>
            <td>".$item['confirmed_balance_after']."</td>
            <td>".$item['is_reverted']."</td>
            <td>".$item['created_at']."</td>
        </tr>";
 }


$output .=" </tbody> </table> ";
echo $output;
die;