<?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 S.description AS subledger,SUM(amount) AS amount FROM `erp_finance_voucher_head` H INNER JOIN erp_finance_voucher_items V ON V.header_id=H.id INNER JOIN erp_finance_subledger S ON S.id=V.subledger_id  WHERE V.ledger_id=20 AND H.voucher_date <= "'.$to_date.'" AND H.is_posted="Y" group by V.subledger_id Order By S.description';
$account_payable=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>Supplier</th> 
                    <th class="text-right">Amount</th>
                </tr>
            </thead>
            <tbody>
            
            <?php
            
            
            if(!empty($account_payable)){
                $total_payable = 0;
                $i=0;
                foreach ($account_payable as $value) {
                    if($value['amount']!=0)
                    {
                    ?>
                        <tr>
                            <td><?php echo ($i+1); ?></td>
                            <td class="text-left"><?php echo $value['subledger']; ?></td>
                            <td class="text-right"><?php echo Yii::app()->numberFormatter->formatCurrency(-1*$value['amount'],""); ?></td>
                        </tr>
                    <?php
                    $total_payable+=-1*$value['amount'];
                    $i++;   
                    }
                }
                ?>
                    <tr>
                        <td class="text-right" colspan="2"><b>Total Amount</b></td>
                        <td class="text-right"><b>AED <?php echo Yii::app()->numberFormatter->formatCurrency($total_payable,''); ?></b></td>
                    </tr>
                <?php
            }
            else{
                ?>
                    <tr>
                        <td colspan="3" class="text-center">No data found</td>
                    </tr>
                <?php
            }
            
            ?>
            </tbody>
        </table>
    </div>