<!DOCTYPE html>
<html>

    <head>
        <title>Enquiry List</title>
    </head>

    <body>
        <div class="heading">
            <div class="logo col-6">
                <img src="images/pdf/logo.png">
            </div>
            <div class="companay_name col-6 text-right">
                <?php
                
                $model_Company = MasCompany::model()->find();
                
                ?>
                
                <h3><?php echo $model_Company->company_name; ?></h3>
                <p><?php echo $model_Company->company_address; ?>
                <?php echo ', '.$model_Company->company_location; ?>
                <?php echo ', '.$model_Company->country->country_name; ?></p>
                <p><?php echo 'Phone : '. $model_Company->company_phone_no; ?></p>
                <p><?php echo 'Email : '.$model_Company->company_email_id; ?></p>
            </div>
        </div>
        <div class="clearfix"></div>
        <div class="title">
            <div class="col-6">
                <div style="height: 10px;"></div>
            </div>
            <div class="col-6 text-right">
                <h1>MATERIAL INVOICE LIST</h1>
                <div class="details-box">
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
        <div class="table-body">
            <table id="tbl_enquiry_table" class="table table-fixed table-primary dataTable">
                <thead>
                    <tr>
                        <th>No</th>
                        <th>File No</th>
                        <th>Customer Name</th>
                        <th>Invoice Date</th>
                        <th>Payment Terms</th>
                        <th class="text-right">Grand Total</th>

                    </tr>
                </thead>
                <tbody>
                    <?php
                    $condition = '1=1';
                    if ($customer_id != '') {
                        $condition .= ' AND t.customer_id ="' . $customer_id . '"';
                    }
                    if ($invoice_start_date != '') {
                        $invoice_start_date = str_replace('/', '-', $invoice_start_date);
                        $invoice_start_date = date('Y-m-d', strtotime($invoice_start_date));
                        $condition .= ' AND t.invoice_date >="' . $invoice_start_date . '"';
                    }
                    if ($invoice_end_date != '') {
                        $invoice_end_date = str_replace('/', '-', $invoice_end_date);
                        $invoice_end_date = date('Y-m-d', strtotime($invoice_end_date));
                        $condition .= ' AND t.invoice_date <="' . $invoice_end_date . '"';
                    }
                    if ($invoice_no != '') {
                        $condition .= ' AND t.file_id ="' . $invoice_no . '"';
                    }
                    if ($payment_terms != '') {
                        $condition .= ' AND t.payment_terms ="' . $payment_terms . '"';
                    }


                    $model_registration_invoice = RegistrationInvoice::model()->findAll(array('condition' => $condition));
                    foreach ($model_registration_invoice as $i => $model) {
                        $total += $model->grand_total;
                        ?>
                    <tr>
                       <td><?php echo $i + 1; ?></td>
                        <td><?php echo $model->file_id; ?></td>
                        <td><?php echo $model->customers->customer_name; ?></td>
                        <td><?php  echo date('d/m/Y', strtotime($model->invoice_date)); ?></td>
                        <td><?php echo $model->paymentname->payment_term; ?></td>
                        <td class="text-right"><?php echo $model->grand_total; ?></td>
                    </tr>
                <?php } ?>   
                    <tr>
                        <td colspan="5" class="text-right">
                            <h2>Total  </h2>
                        </td>
                        <td  class="text-right">
                            <h2><?php echo $total; ?></h2>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>

    <htmlpagefooter name="myfooter">
        <div style="border-top: 1px dotted #000000; font-size: 12px; text-align: center; padding-top: 10px; ">
            <div style="text-align:center;width:100%">This report is auto generated by Bluesky project on <?php
                date_default_timezone_set("Asia/Dubai");
                echo date('d/m/Y') . " " . date("h:i:sa");
                ?> </div>
            <div style="text-align:center;width:100%">Page {PAGENO} of {nb} </div>
        </div>
    </htmlpagefooter>
    <sethtmlpagefooter name="myfooter" page="all" value="on" />

</body>

</html>
