<style type="text/css">
::-webkit-scrollbar {
    display: none;
}
#dynamic-content-container{background: #fff;}
    .navbar-default.navbar-static-side{display: none !important;}
    #page-wrapper{margin: 0px !important; padding: 0 !important;}
    .row.border-bottom{display: none !important;}
    .footer.fixed{display: none;}
    .ibox-content{padding: 0 !important;}
    body {
    -webkit-print-color-adjust:exact;
    background: #fff;
    }

</style>

<table style="width: 100%; background: #fff;">
    <tr>
        <td><img style="width: 100%; height: 200px;" src="<?= get_branch_image('report'); ?>"></td>
    </tr>
</table>

<h2 class="text-center font-bold" style="margin: 10px 0 20px;"><?= print_lang($app_lang,'receipts_approved_view_title'); ?></h2>

<table class="table table-bordered">
    <thead>
        <tr>
            <th class="text-center"><?= print_lang($app_lang,'receipts_approved_view_thead_sr'); ?></th>
            <th class="text-center"><?= print_lang($app_lang,'receipts_approved_view_thead_date'); ?></th>
            <th class="text-center"><?= print_lang($app_lang,'receipts_approved_view_thead_client'); ?></th>
            <th class="text-center"><?= print_lang($app_lang,'receipts_approved_view_thead_details'); ?></th>
            <th class="text-center"><?= print_lang($app_lang,'receipts_approved_view_thead_amount'); ?></th>
            <th class="text-center"><?= print_lang($app_lang,'receipts_approved_view_thead_rate'); ?></th>
            <th class="text-center"><?= print_lang($app_lang,'receipts_approved_view_thead_ex_amount'); ?></th>
            <th class="text-center"><?= print_lang($app_lang,'receipts_approved_view_thead_db_account'); ?></th>
            <th class="text-center"><?= print_lang($app_lang,'receipts_approved_view_thead_requested_by'); ?></th>
            <th class="text-center"><?= print_lang($app_lang,'receipts_approved_view_submitted_date'); ?></th>
            <th class="text-center"><?= print_lang($app_lang,'receipts_approved_view_approved_date'); ?></th>
            <th class="text-center"><?= print_lang($app_lang,'receipts_approved_view_thead_approved_by'); ?></th>
        </tr>
    </thead>
    <tbody>
        <?php $i = 1; $total = array(); $total_ex = array();  foreach($pageData as $row){
            $currency_show = array_key_exists($row['currency'], $currencies) ? $currencies[$row['currency']]['symbol'] : NULL;
            $currency_exchange_show = array_key_exists($row['exchange_currency'], $currencies) ? $currencies[$row['exchange_currency']]['symbol'] : NULL;
            $amount = $row['amount'];
            $amount_ex = $row['exchange_amount'];
            if(!empty($search_convert_currency))
            {
                $convert_currency_record = fetch_table_where('currency','uid',$search_convert_currency,true);
                $currency_show = $convert_currency_record['symbol'];
                $amount_currency_equalance = $row['currency_usd_equalance'];
                $convert_currency_equalance = $convert_currency_record['usd_equalance'];
                if($row['currency'] == $search_convert_currency)
                {
                    $amount_currency_equalance = 1;
                    $convert_currency_equalance = 1;
                }
                $amount = amount_conversion($row['amount'], $amount_currency_equalance, $convert_currency_equalance);
            }
        ?>
            <tr class="text-center">
                <td><?= $i++; ?></td>
                <td><?= display_true_date($row['created_at']); ?></td>
                <td><?= array_key_exists($row['client'], $clients) ? $clients[$row['client']]['name'] : NULL; ?></td>
                <td><?= 'Receipt #'.$row['invoice'].' '.ucfirst($row['details']); ?></td>
                <td><?= $currency_show.' '.amount_number_format($amount); $total[] = $amount; ?></td>
                <td><?= amount_number_format($row['rate']); ?></td>
                <td><?= $currency_exchange_show.' '.amount_number_format($amount_ex); $total_ex[] = $amount_ex; ?></td>
                <td><?php echo array_key_exists($row['debit_account'], $accounts) ? $accounts[$row['debit_account']]['name'] : NULL;?></td>
                
                <?php

                    if($row['user_type'] == 'marketer')
                    {
                        $requested_by = array_key_exists($row['marketer'], $marketers) ? $marketers[$row['marketer']]['name'].' (marketer)' : NULL;
                    }
                    else
                    {
                        $requested_by = array_key_exists($row['sales_man'], $sales_man) ? $sales_man[$row['sales_man']]['name'].' (sales man)' : NULL;
                    }

                ?>
                <td><?= $requested_by; ?></td>
                
                <td><?= display_true_date($row['submitted_date']); ?><br><?php echo date('H:i:s',strtotime($row['submitted_date'])); ?></td>
                <td><?= display_true_date($row['approved_date']); ?><br><?php echo date('H:i:s',strtotime($row['approved_date'])); ?></td>
                <td><?= array_key_exists($row['approved_by'], $users) ? $users[$row['approved_by']]['name'] : NULL; ?></td>
            </tr>
        <?php } ?>
            <tr class="text-center">
                <td></td>
                <td><strong><?= print_lang($app_lang,'total'); ?></strong></td>
                <td></td>
                <td></td>
                <td><strong><?= amount_number_format(array_sum($total));?></strong></td>
                <td></td>
                <td><strong><?= amount_number_format(array_sum($total_ex));?></strong></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
    </tbody>
</table>    