<!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>JOB SHEET OVERVIEW LIST</h1>
                <div class="details-box">
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
        <?php
        if ($file_id != '') {
            $condition .= 't.file_id ="' . $file_id . '"';


            $model_Registration = Registration::model()->findAll(array('condition' => $condition));
            $customer_id = $model_Registration[0]->customer_id;
            $model_Customer = Customers::model()->find(array('condition' => 'id ="' . $customer_id . '"'));

            //contract
            $model_Contract = Contract::model()->findAll(array('condition' => 'customer_id="' . $customer_id . '"', 'order' => 'id desc'));
            $contract_id = $model_Contract[0]->id;
            if (!empty($model_Contract)) {
                $model_Contract_Items = ContractItem::model()->findAll(array('condition' => 'contract_id="' . $contract_id . '"'));
            }

            //material request
//                $condition = 'file_id="' . $file_id . '" AND material_status="N"';
            $model_Material = MaterialRequest::model()->findAll(array('condition' => $condition));

//                $condition = 'file_id="' . $file_id . '" AND material_status="Y"';
//                $model_Material_Used = MaterialRequest::model()->findAll(array('condition' => $condition));
            //Invoice
            $model_Invoice = RegistrationInvoice::model()->find(array('condition' => 'file_id="' . $file_id . '"'));

            //payment
            $condition = 'file_id="' . $file_id . '" AND invoice_id !="0"';
            $model_payment = RegistrationPaymentReceipt::model()->findAll(array('condition' => $condition,));

            //communication
            $model_Communication = Communication::model()->findAll(array('condition' => 'file_id="' . $file_id . '"'));
        }
        ?>
        <div class="col-5">
            <div class="table-responsive">
                <table class="table table-bordered">
                    <tr>
                        <th>Customer Name </th>
                        <td><?php echo $model_Customer->customer_name; ?></td>
                    </tr>
                    <tr>
                        <th>Email</th>
                        <td><?php echo $model_Customer->customer_email_id; ?></td>
                    </tr>
                    <tr>
                        <th>Phone No </th>
                        <td><?php echo $model_Customer->customer_phone_no; ?></td>
                    </tr>
                    <tr>
                        <th>Location</th>
                        <td><?php echo $model_Customer->customer_location; ?></td>
                    </tr>
                    <tr>
                        <th>City</th>
                        <td><?php echo $model_Customer->customer_city; ?></td>
                    </tr>
                    <tr>
                        <th>Address</th>
                        <td><?php echo $model_Customer->customer_address; ?></td>
                    </tr>
                    <tr>
                        <th>Country </th>
                        <td><?php echo $model_Customer->country->country_name; ?></td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="col-6 offset-1">
            <div class="table-responsive">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th class="text-bold">Date</th>
                            <th class="text-bold">Problem</th>

                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        if (!empty($model_Registration)) {
                            foreach ($model_Registration as $row) {
                                ?>
                                <tr>
                                    <td width="150px"><?php echo date('d/m/Y h:i:s', strtotime($row->date)); ?></td>
                                    <td class="text-green"><?php echo $row->problem; ?></td>

                                </tr>
                                <?php
                            }
                        } else {
                            ?>
                            <tr>
                                <td colspan="2">
                                    No data available
                                </td>
                            </tr>
                        <?php } ?>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="clearfix"></div>

        <br>
        <div class="table-responsive shadow-1">
            <table id="tbl_project_table" class="table table-fixed table-primary table-bordered reportTable details">
                <thead>
                    <tr>
                        <td class="Table-Title" colspan="7">
                            Contract
                        </td>
                    </tr>
                    <tr>
                        <th>No</th>
                        <th>Product</th>
                        <th>Description</th>
                        <th class="text-right">Quantity</th>
                        <th class="text-right">Unit</th>
                        <th class="text-right">Rate</th>
                        <th class="text-right">Net Amount</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $i = 1;
                    $total = 0.00;
                    if (!empty($model_Contract_Items)) {
                        foreach ($model_Contract_Items as $row) {
                            $total += $row->net_amount;
                            ?>
                            <tr>
                                <td>  <?php echo $i++; ?></td>
                                <td>  <?php echo $row->serviceitem->part_number; ?></td>
                                <td>  <?php echo $row->description; ?> </td>
                                <td class="text-right">  <?php echo $row->quantity; ?> </td>
                                <td class="text-right">  <?php
                                    if ($row->unit == 0)
                                        echo 'Null';
                                    else
                                        echo $row->unit;
                                    ?> </td>
                                <td class="text-right">  <?php
                                    $rate = $row->rate;
                                    echo number_format((float) $rate, 2, '.', '');
                                    ?> </td>
                                <td class="text-right">  <?php echo $row->net_amount; ?> </td>
                            </tr>
                        <?php } ?>
                        <tr>
                            <td class="text-right" colspan="5">
                                <h4>Total</h4>
                            </td>
                            <td class="text-right" colspan="2">
                                <h4> <?php echo number_format((float) $total, 2, '.', ''); ?></h4>
                            </td>
                        </tr>
                    </tbody>
                    <?php
                } else {
                    ?>
                    <tr>
                        <td class="dataTables_empty text-center" colspan="7">No data available</td>
                    </tr>
                    <?php
                }
                ?>
            </table>
        </div>
        <br>
        <div class="table-responsive shadow-1">
            <table id="tbl_project_table" class="table table-fixed table-primary table-bordered reportTable details ">
                <thead>
                    <tr>
                        <td class="Table-Title" colspan="10">
                            Material Details
                        </td>
                    </tr>
                    <tr>
                        <th>No</th>
                        <th>Item</th>
                        <th>Description</th>
                        <th class="text-right">Quantity Requested</th>
                        <th class="text-right">Quantity Delivered</th>
                        <th class="text-right">Quantity Balance</th>
                        <th>Unit</th>
                        <th>Status</th>
                        <th>Approved By</th>
                        <th>Notes</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $i = 1;

                    if (!empty($model_Material)) {
                        foreach ($model_Material as $row) {
                            $balance_Qnty = ($row->quantity_request) - ($row->quantity_delivered);
                            ?>
                            <tr>
                                <td>  <?php echo $i++; ?></td>
                                <td>  <?php echo $row->item; ?></td>
                                <td>  <?php echo $row->description; ?> </td>
                                <td class="text-right">  <?php echo $row->quantity_request; ?> </td>
                                <td class="text-right">  <?php echo $row->quantity_delivered; ?> </td>
                                <td class="text-right">  <?php echo number_format((float) $balance_Qnty, 2, '.', ''); ?> </td>
                                <td>
                                    <?php
                                    if ($row->unit == 0) {
                                        echo 'Null';
                                    } else {
                                        echo $row->unit;
                                    }
                                    ?>
                                </td>
                                <td>
                                    <?php
                                    if ($row->status == 'L')
                                        echo 'Low';
                                    elseif ($row->status == 'N')
                                        echo 'Normal';
                                    else
                                        echo 'Critical';
                                    ?>
                                </td>
                                <td>  <?php echo $row->customer->customer_name; ?> </td>
                                <td>  <?php echo $row->approval_note; ?> </td>
                            </tr>
                            <?php
                        }
                        ?>
                    <?php }else {
                        ?>
                        <tr>
                            <td class="dataTables_empty text-center" colspan="8">No data available</td>
                        </tr>
                        <?php
                    }
                    ?>
                </tbody>
            </table>
        </div>
        <br>



        <!--INVOICE-->
        <div class="clearfix"></div>
        <div class="col-12">
            <table class="table table-bordered">
                <tr>
                    <td colspan="4" class="Table-Title">INVOICE</td>
                </tr>
                <tr>
                    <th>Invoice No</th>
                    <td><?php echo $model_Invoice->id; ?></td>
                    <th>Invoice Date</th>
                    <td><?php echo date('d/m/Y', strtotime($model_Invoice->invoice_date)); ?></td>
                </tr>
                <tr>
                    <th>Contract No</th>
                    <td><?php echo $model_Invoice->contract_no; ?></td>
                    <th>Currency</th>
                    <td><?php echo $model_Invoice->currencyname->currency; ?></td>
                </tr>
                <tr>
                    <th>Exchange Rate</th>
                    <td colspan="3"><?php echo $model_Invoice->exchange_rate; ?></td>
                </tr>
            </table>
        </div>
        <br>
        <div class="col-12">
            <?php
            $invoice_id = $model_Invoice->id;
            $condition = 't.file_id ="' . $file_id . '" AND t.invoice_id ="' . $invoice_id . '"';
            $model_invoice_item = InvoiceItems::model()->findAll(array('condition' => $condition));
            ?>
            <table id="tbl_project_table" class="table table-fixed table-primary table-bordered reportTable details">
                <thead>
                    <tr>
                        <th>Item</th>
                        <th>Description</th>
                        <th class="text-right">Quantity</th>
                        <th class="text-right">Unint</th>
                        <th class="text-right">Cost</th>
                    </tr>
                <tbody>
                    <?php
                    if (!empty($model_invoice_item)) {
                        $total = 0;
                        foreach ($model_invoice_item as $row) {
                            $total += $row->cost;
                            ?>
                            <tr>
                                <td><?php echo $row->item; ?></td>
                                <td><?php echo $row->description; ?></td>
                                <td class="text-right"><?php echo $row->quantity_request; ?></td>
                                <td class="text-right"><?php echo $row->unit; ?></td>
                                <td class="text-right"><?php echo $row->cost; ?></td>
                            </tr>
                            <?php
                        }
                        ?>
                        <tr>
                            <td class="text-right" colspan="4"><h4>Total</h4></td>
                            <td class="text-right"><h4> <?php echo number_format((float) $total, 2, '.', ''); ?></h4></td>
                        </tr>
                        <?php
                    } else {
                        ?>
                        <tr>
                            <td class="dataTables_empty text-center" colspan="5">No data available</td>
                        </tr>
                        <?php
                    }
                    ?>
                </tbody>
                </thead>
            </table>
        </div>
        <div class="clearfix"></div>
        <br>

        <div class="col-12">
            <div class="table-responsive shadow-1">
                <table id="tbl_project_table" class="table table-fixed table-primary table-bordered dataTable details ">
                    <thead>
                        <tr>
                            <td class="Table-Title" colspan="4">
                               Receipt 
                            </td>
                        </tr>
                        <tr>
                            <th>Receipt No</th>
                            <th>Invoice ID</th>
                            <th>Payment Date</th>
                            <th class="text-right">Paid Amount</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $total = 0;
                        if (!empty($model_payment)) {
                            foreach ($model_payment as $row) {
                                $total += $row->paid_amount;
                                ?>
                                <tr>
                                    <td><?php echo $row->id; ?></td>
                                    <td><?php echo $row->invoice_id; ?></td>
                                    <td><?php echo date('d/m/Y', strtotime($row->payment_date)); ?></td>
                                    <td class="text-right"><?php echo $row->paid_amount; ?></td>
                                </tr>
                                <?php
                            }
                            ?>
                            <tr>
                                <td class="text-right" colspan="3">
                                    <h4>Total</h4>
                                </td>
                                <td class="text-right">
                                    <h4> <?php echo number_format((float) $total, 2, '.', ''); ?></h4>
                                </td>
                            </tr>
                            <?php
                        } else {
                            ?>
                            <tr>
                                <td class="dataTables_empty text-center" colspan="4">No data available</td>
                            </tr>
                            <?php
                        }
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
        <br>
        <div class="col-12">
            <div class="table-responsive shadow-1">
                <table id="tbl_project_table" class="table table-fixed table-primary table-bordered dataTable details">
                    <thead>
                        <tr>
                            <td class="Table-Title" colspan="4">
                                Communication
                            </td>
                        </tr>
                        <tr>
                            <th>No</th>
                            <th>To</th>
                            <th>Message Date</th>
                            <th>Message</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $i = 1;
                        if (!empty($model_Communication)) {
                            foreach ($model_Communication as $row) {
                                ?>
                                <tr>
                                    <td><?php echo $i++; ?></td>
                                    <td><?php echo $row->userto->first_name . ' ' . $row->userto->last_name; ?></td>
                                    <td><?php echo date('d/m/Y', strtotime($row->msg_date)); ?></td>
                                    <td><?php echo $row->message; ?></td>
                                </tr>
                                <?php
                            }
                        } else {
                            ?>
                            <tr>
                                <td class="dataTables_empty text-center" colspan="4">No data available</td>
                            </tr>
                            <?php
                        }
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="clearfix"></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>
