<?php 
$from_date= str_replace('/', '-',$from_date);
$from_date= date("Y-m-d", strtotime($from_date));
$to_date= str_replace('/', '-',$to_date);
$to_date= date("Y-m-d", strtotime($to_date));
//$current_date="2021-02-23";

$SQL = 'SELECT SUM(`exchange_rate` *`grand_total` ) FROM `erp_invoice` WHERE `invoice_date` >= "'.$from_date.'" AND invoice_date <= "'.$to_date.'"';
//echo $SQL;
$today_invoice_value = Yii::app()->db->createCommand($SQL)->queryScalar();	

$SQL = 'SELECT H.voucher_date,L.description AS ledger,S.description AS subledger,(I.amount) AS amount from erp_finance_voucher_head H INNER JOIN erp_finance_voucher_items I ON H.id=I.header_id INNER JOIN erp_finance_legder L ON L.id=I.ledger_id '
        . 'INNER JOIN erp_finance_subledger S ON S.id=I.subledger_id where H.voucher_date>="'.$from_date.'" AND H.voucher_date<="'.$to_date.'" AND H.voucher_type IN(1) AND I.amount>0';
$arr_receipt = Yii::app()->db->createCommand($SQL)->queryAll();	
?>
<div class="popup_inner_element">
        <table class="table table-hover table-bordered personal-task">
            <thead>
                <tr>
                    <th>S.No</th>
                    <th>Date</th> 
                    <th>Account</th> 
                    <th>Subledger</th> 
                    <th class="text-right">Amount</th>
                </tr>
            </thead>
            <tbody>
            
            <?php
            
            
            if(!empty($arr_receipt)){
                $total_invoice = 0;
                foreach ($arr_receipt as $i=>$value) {
                    ?>
                        <tr>
                            <td><?php echo ($i+1); ?></td>
                            <td><?php echo date('d-m-Y',strtotime($value['voucher_date'])); ?></td>                            
                            <td class="text-left"><?php echo $value['ledger']; ?></td>
                            <td class="text-left"><?php echo $value['subledger']; ?></td>
                            <td class="text-right"><?php echo Yii::app()->numberFormatter->formatCurrency($value['amount'],""); ?></td>
                        </tr>
                    <?php
                    $total_invoice+=$value['amount'];
                    $i++;   
                }
                ?>
                    <tr>
                        <td class="text-right" colspan="4"><b>Total Amount</b></td>
                        <td class="text-right"><b>AED <?php echo Yii::app()->numberFormatter->formatCurrency($total_invoice,''); ?></b></td>
                    </tr>
                <?php
            }
            else{
                ?>
                    <tr>
                        <td colspan="5" class="text-center">No data found</td>
                    </tr>
                <?php
            }
            
            ?>
            </tbody>
        </table>
    </div>