<?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";

$modelPurchaseOrder=PurchasingOrder::model()->with('vendor')->findAll(array('condition'=>'order_date >= "'.$from_date.'" AND order_date <= "'.$to_date.'"','order'=>'vendor_name'))
?>
<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($modelPurchaseOrder)){
                $total_order_value = 0;
                $i=0;
                $str_vendor_id="";
                $vendor_total=0;
                foreach ($modelPurchaseOrder as $eachItem) {
                    $total_amount = $eachItem['stock_grand_total'] * $eachItem['exchange_rate'];
                    
                    
                    
                    if ($str_vendor_id!=$eachItem['vendor_id']){
                        if($str_vendor_id!=""){
                         ?>
                       <tr>
                             <td class="text-right" colspan="2"><b>Total</b></td>
                            <td class="text-right"><b>AED <?php echo Yii::app()->numberFormatter->formatCurrency($vendor_total,''); ?></b></td>
                        </tr>    
                       <?php
                        }
                       $vendor_total=0;
                         $str_vendor_id = $eachItem['vendor_id'];
                    }
                    else{
                      
                    }
                    $vendor_total+=$total_amount;
                    ?>
                        <tr>
                            <td><?php echo ($i+1); ?></td>
                            <td class="text-left"><?php echo $eachItem['vendor']['vendor_name']; ?></td>
                            <td class="text-right"><?php echo Yii::app()->numberFormatter->formatCurrency($total_amount,""); ?></td>
                        </tr>
                    <?php
                    $total_order_value+=$total_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_order_value,''); ?></b></td>
                    </tr>
                <?php
            }
            else{
                ?>
                    <tr>
                        <td colspan="3" class="text-center">No data found</td>
                    </tr>
                <?php
            }
            
            ?>
           
        </table>
    </div>