<?php
if ($check_extras == 1) {
    $isReportShow = 'isSettledReportShow';
    $reportTable = 'settle-table';
    $title = __("LBL_SETTLED");
    $title_class = 'settle-report';
} elseif ($check_extras == 2) {
    $title = __("LBL_ADVANCED");
    $isReportShow = 'isAdvancedReportShow';
    $reportTable = 'advanced-table';
    $title_class = 'advanced-report';
}
?>
<h5 id="summaryHeader" style="text-align: left;"  <?php echo 'class="'.$title_class.'">'.$title; ?>
    <span class="showHideSpan" style=""> (<label <?php echo 'for="'. $isReportShow.'">'. __("LBL_HIDE_SHOW").' <input type="checkbox" value="1" name="isMealReportShow" id="'.$isReportShow.'"'; ?> checked="checked"></label>)</span>
</h5>
<table class="table printTable <?php echo $reportTable; ?>" id="exportTable" width="100%">
    <thead>
    <tr>
        <th><?php echo __("LBL_WHO_PAID"); ?></th>
        <th><?php echo __("LBL_PAID_TO"); ?></th>
        <th><?php echo __("LBL_HOW_MUCH"); ?>?</th>
        <th><?php echo __("LBL_WHEN"); ?></th>
    </tr>
    </thead>
    <tbody>
    <?php
    $personal_total_expense = 0;
    $total_expense = 0;
    $settled = 0;
    $advanced = 0;
    $finalExpenseList = array();
    foreach ($data['GroupExpense'] as $key => $value) {
        $extras_value = 0;
        if (isset($value['extras']) && !empty($value['extras'])) {
            $extrasArray = explode('|', $value['extras']);
            $extras_value = $extrasArray[0];
        }
        if ($value['what'] == 'Balance Expense' && empty($value['extras'])) {
            $extras_value = 1;
        }
        if ($extras_value == $check_extras ) {
            $finalExpenseList[$key]['participent_name'] = $value["participent_name"];
            $finalExpenseList[$key]['amount'] = $value["amount"];
            $finalExpenseList[$key]['what'] = $value["what"];
            $finalExpenseList[$key]['expense_date_new'] = $value["expense_date_new"];
            $finalExpenseList[$key]['involve_list'] = $value["involve_list"];
            $finalExpenseList[$key]['my_expense'] = '';
            $finalExpenseList[$key]['currency'] = $data['Expense']["currency"];
            ?>
            <tr>
                <td><?php echo $value["participent_name"]; ?></td>
                <td><?php echo $value["involve_list"]; ?></td>
                <td><?php
                    $total_expense = $total_expense + $value["amount"];
                    echo number_format($value["amount"], 2) . " " . $data['Expense']["currency"]; ?></td>
                <td><?php echo $value["expense_date_new"]; ?></td>
            </tr>
            <?php
        }
    }
    ?>
    </tbody>
    <tfoot>
    <tr style="background: transparent;">
        <td style="border:0px;"></td>
        <td align="right" style="font-weight: bold; border: 0px;"><?php echo __("LBL_TOTAL"); ?> : </td>
        <td align="left" style="border:0px;"><?php echo number_format($total_expense, 2) . " " . $data['Expense']["currency"]; ?></td>
        <td style="border:0px;"></td>
    </tr>
    </tfoot>
</table>
<script>
    $(document).ready(function(){
        var reportId = '<?php echo $isReportShow; ?>';
        var reportTable = '<?php echo $reportTable; ?>';
        var reportTitleClass = '<?php echo $title_class; ?>';
        $('#'+reportId).on('click', function () {
            if(this.checked) {
                $('.'+reportTable).show().removeClass('hideCell');
                $('.'+reportTitleClass).removeClass('hidden-print');
            } else {
                $('.'+reportTable).hide().addClass('hideCell');
               $('.'+reportTitleClass).addClass('hidden-print');
            }
        });
    });
</script>