<?php
$totalPageRecord = count($this->hfaInvoiceDetails);
$thePage = $this->page;
$thePageRecord = $this->pageRecord;
$theTotalRecord = $this->countHfaInvoiceDetail;
$theTotalPage = ceil($theTotalRecord / $thePageRecord);
$indexUrl = "/accounting/reconcilehfainvoices";
$sortBy = isset($this->sortBy) ? $this->sortBy : 'hfaInvoicePeriod';
$sortOrder = isset($this->sortOrder) ? $this->sortOrder : "desc";
$queryString = http_build_query(array(
    "sort_by" => $sortBy,
    "sort_order" => $sortOrder
));

if ($this->errorMsg != '') {
    ?>
    <div id="error" class="alertError"
    style="display: block; margin: 0 0 5px;">
    <?php echo $this->errorMsg; ?>
    </div>
    <?php
}
?>
<div id="hfa_success_message" class="alertConfirm" style="display:none"></div>
<div id="hfa_error_message" class="alertError" style="display:none"></div>
<script type="text/javascript" src="/oa/scripts/reconcileHfaInvoices.js"></script>
<div>
<form method="post" name="hfaInvoiceForm" id="hfaInvoiceForm">
    <div class="panelContent fullReport" style="clear: left">
        <table class="data">
            <thead>
                <tr>
                    <th align="center"><b>No.</b></th>
                    <th><?=$this->sortcolumnheader('', 'Invoice ID', 'invoiceId', $sortBy, $sortOrder, $thePageRecord);?></th>
                    <th><?=$this->sortcolumnheader('', 'HFA Invoice Period', 'hfaInvoicePeriod', $sortBy, $sortOrder, $thePageRecord);?></th>
                    <th><?=$this->sortcolumnheader('', 'Invoice Type', 'invoiceType', $sortBy, $sortOrder, $thePageRecord);?></th>
                    <th><?=$this->sortcolumnheader('', 'Frequency Type', 'frequencyType', $sortBy, $sortOrder, $thePageRecord);?></th>
                    <th><?=$this->sortcolumnheader('', 'Payment Status', 'paymentStatus', $sortBy, $sortOrder, $thePageRecord);?></th>
                    <th><?=$this->sortcolumnheader('', 'Received', 'received', $sortBy, $sortOrder, $thePageRecord);?></th>
                    <th align="center" tabindex="2"><b>Download Reports</b></th>
                    <th align="center" tabindex="3"><b></b></th>
                </tr>
            </thead>
            <tbody>
                <?php
                if (count($this->hfaInvoiceDetails) > 0) {
                    $count = 0;
                    foreach ($this->hfaInvoiceDetails as $hfaInvoiceDetail) {
                        $serialNo = ($this->page - 1) * $this->pageRecord + ($count + 1);
                        $key = $hfaInvoiceDetail->invoiceId;
                        ?>
                    <tr>
                        <td><?php echo $serialNo; ?></td>
                        <td><?php echo $hfaInvoiceDetail->invoiceId; ?></td>
                        <td id="hfaPeriodCode_<?php echo $key;?>"><?php echo $hfaInvoiceDetail->hfaPeriodCode; ?></td>
                        <td><?php echo $hfaInvoiceDetail->invoiceTypeTitle; ?></td>
                        <td><?php echo $hfaInvoiceDetail->frequencyType; ?></td>
                        <td id="payStatus_<?php echo $key;?>"><?php echo $hfaInvoiceDetail->paymentStatus; ?></td>
                        <td><?php echo $hfaInvoiceDetail->receivedDate; ?></td>
                        <td id="download_<?php echo $key;?>">
                            <a data-type="hfa_reconciliation" href="<?php echo "orchard_reconciled_results_".$hfaInvoiceDetail->hfaSourceFile; ?>" class="download_link" id="download_reconciliation_<?php echo $key; ?>" style="display:<?php echo $hfaInvoiceDetail->displayReconciliation;?>" >Download Reconciliation</a> &nbsp;
                            <a data-type="hfa_invoice" href="<?php echo $hfaInvoiceDetail->hfaSourceFile; ?>" class="download_link" id="download_invoice_<?php echo $key; ?>" ><?php echo $hfaInvoiceDetail->displayInvoiceLink;?> </a>
                            <input type="hidden" name="hfaSourceFile" id="hfaSourceFile_<?php echo $key; ?>" value="<?php echo $hfaInvoiceDetail->hfaSourceFile?>" />
                            <input type="hidden" name="md5" id="md5_<?php echo $key; ?>" value="<?php echo $hfaInvoiceDetail->md5; ?>" />
                        </td>
                        <td id="column_<?php echo $key;?>">
                        <?php
                        if (
                            $hfaInvoiceDetail->nonapprovableInvoice ||
                            !$this->canUserApprove
                            ) {
                            echo $hfaInvoiceDetail->statusMessage;
                         } else {
                         ?>
                            <input type="button" class="popupwindow_approve" id="<?php echo $hfaInvoiceDetail->invoiceId?>"
                                    value="Approve"><input type="button" class="popupwindow_void" id="<?php echo $hfaInvoiceDetail->invoiceId?>" value="Void">
                        <?php } ?>
                        </td>
                    </tr>
                    <?php
                            $count ++;
                    }
                } else {
                    ?>
                    <tr>
                        <td colspan="9" align="center">No Data Found.</td>
                    </tr>
    <?php
                }
                ?>
            </tbody>
        </table>
        <input type="hidden" name="page" id="page"
            value="<?php echo $this->page; ?>" /> <input type="hidden"
            name="pageRecord" id="pageRecord"
            value="<?php echo $this->pageRecord; ?>" />
    </div>
    <div>
        <table>
            <tbody>
                <tr class="overlay_form" id="overlay_approve_form" style="display:none">
                    <td>
                    <div class="overlay-shadow"></div>
                    <div class="overlay-modal">
                    <div><input type="button" class="float-right" value="X"></div>
                    <div class="overlay-modal-header"></div>
                    <div class="overlay-modal-body"><span style=""></span></div>
                    <div class="overlay-modal-footer"><input type="button" class="approve_no" value="">
                    <input type="button" class="approve_yes" value=""></div></div></td>
                </tr>
            <tr class="overlay_form" id="overlay_void_form" style="display:none">
                <td>
                <div class="overlay-shadow"></div>
                <div class="overlay-modal">
                <div><input type="button" class="float-right" value="X"></div>
                <div class="overlay-modal-header"></div>
                <div class="overlay-modal-body"><span style=""></span></div>
                <div class="overlay-modal-footer"><input type="button" class="void_no" value="">
                <input type="button" class="void_yes" value=""></div></div></td>
                <input type="hidden" name="hfa_invoice_id" id="hfa_invoice_id" value="" />
                <input type="hidden" name="status" id="status" value="" />
                <input type="hidden" name="sort_param" id="sort_param" value="<?php echo $queryString; ?>" />
                </tr>
            </tbody>
        </table>
    </div>
    <div id="divPagination">
<?php
if (count($this->hfaInvoiceDetails) > 0) {
    echo $this->paginationpanel($indexUrl, $thePage, $thePageRecord, $theTotalPage, $queryString, $theTotalRecord);
}

?>
    </div>
    </form>
</div>