<!DOCTYPE html>
<html>

<head>
    <title>Print Bill</title>

    <style>
        body {
            font-family: 'Times New Roman', Times, serif;
            font-size: 13px;
        }

        @media print {
            @page {
                size: landscape
            }
        }

        .page {
            width: 100%;
            margin: 0 auto;
        }

        .header {
            width: 100%;
            display: inline-block;
        }

        .header img {
            width: 80px;
        }

        .header h1 {
            margin: 0;
            padding: 0;
            text-transform: uppercase;
            font-size: 30px;
        }

        .header p {
            margin: 0;
            padding: 0;
        }

        .header .title {
            margin-top: 10px;
            margin-bottom: 10px;
            text-align: center;
        }

        .header .title span {
            background-color: #000;
            color: #fff;
            border: 1px solid #000;
            border-radius: 5px;
            font-family: monospace;
            font-size: 16px;
            font-weight: bold;
            padding: 5px 10px;
            text-transform: uppercase;
        }

        .table {
            width: 100%;
            border-collapse: collapse;
        }

        .info {
            margin-bottom: 20px;
        }

        .info tbody td {
            color: #000;
            vertical-align: middle;
            font-weight: bold;
            padding: 3px 0;
            font-size: 12px;
        }

        .details thead th {
            color: #000;
            padding: 1px;
            vertical-align: middle;
            border: 1px solid #000;
            width: max-content;
            font-size: 10px;
        }

        .details tbody td {
            color: #000;
            padding: 1px;
            vertical-align: middle;
            border: 1px solid #000;
            font-size: 10px;
        }

        .details tfoot td {
            color: #000;
            padding: 1px;
            vertical-align: middle;
            border: 1px solid #000;
            font-size: 10px;
        }


        .summary {
            width: 50%;
            margin: 20px auto;
            float: right;
        }

        .summary tbody td {
            color: #000;
            padding: 3px;
            vertical-align: middle;
            border: 1px solid #000;
            font-weight: bold;
            text-align: left;
            font-size: 10px;
        }
        .sign {
            width: 100%;
            margin-top: 30px;
        }
    </style>
</head>

<body>
    <div class="page">
        <div class="header">
            <table class="table">
                <tbody>
                    <tr>
                        <td rowspan="2" width="20%" align="right">
                            <?php if ($this->global_setting->brand_logo) { ?>
                                <img src="<?php echo UPLOAD_PATH; ?>logo/<?php echo $this->global_setting->brand_logo; ?>" alt="logo">
                            <?php } else { ?>
                                <img src="<?php echo IMG_URL; ?>logo.png" alt="logo">
                            <?php } ?>
                        </td>
                        <td width="60%" align="center">
                            <h1><?php echo $this->global_setting->brand_title; ?></h1>
                            <p><?php echo $this->global_setting->address; ?></p>
                            <p><?php echo $this->global_setting->phone; ?></p>
                        </td>
                        <td width="20%"></td>
                    </tr>
                    <tr>
                        <td>
                            <div class="title" align="center">
                                <span>Investigation Payment Voucher</span>
                            </div>
                        </td>
                        <td></td>
                    </tr>
                </tbody>
            </table>
        </div>
        <!-- Header End -->
        <div class="body">
            <table class="table info">
                <tbody>
                    <tr>
                        <td>
                            Payment Invoice ID: <?php echo $patient->custom_invoice_id; ?>
                        </td>
                        <td colspan="2" align="right" style="font-weight: normal;">
                            Print Time: <?php echo date('M d, Y h:i A'); ?>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            ID: <?php echo $patient->reference_id; ?>
                        </td>
                        <td>
                            <?php
                            if ($patient->commission_type == 'mbbs') {
                                echo 'Doctor:';
                            } elseif ($patient->commission_type == 'vd') {
                                echo 'SD Name:';
                            } elseif ($patient->commission_type == 'emp') {
                                echo 'Employee Name:';
                            } else {
                                echo 'Corporate:';
                            }
                            ?>
                            <?php echo $patient->reference; ?>
                        </td>
                        <td align="right">
                            Payment Date: <?php echo date('M d, Y h:i A', strtotime($patient->date)); ?>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            Address: <?php echo $patient->address; ?>
                        </td>
                        <td align="right">
                            Prepared By: <?php echo $patient->created_by; ?>
                        </td>
                    </tr>
                </tbody>
            </table>

            <!-- Datails -->
            <table class="table details">
                <thead>
                    <tr>
                        <th>Invoice No</th>
                        <th>Bill Date</th>
                        <th>Patient Name</th>
                        <th>Patient ID</th>
                        <th>Total</th>
                        <th>Discount</th>
                        <?php foreach ($departments as $dept) { ?>
                            <th><?php echo $dept->name; ?></th>
                        <?php } ?>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td><?php echo $patient->bill_invoice; ?></td>
                        <td><?php echo date('M d, Y h:ia', strtotime($patient->bill_date)); ?></td>
                        <td><?php echo $patient->patient_name; ?></td>
                        <td><?php echo $patient->patient_unique_id; ?></td>
                        <td><?php echo number_format($patient->total_bill, 2); ?></td>
                        <td><?php echo number_format($patient->discount, 2); ?></td>
                        <?php foreach ($departments as $dept) {
                            $test_amount = $this->payment->get_investigation_by_department_bill($patient->invoice_id, $dept->id); ?>
                            <td><?php echo number_format(($test_amount->total_rate ?? 0), 2); ?></td>
                        <?php } ?>
                    </tr>
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="3" align="right"><strong>Total:</strong></td>
                        <td><?php echo $patient->total_bill; ?></td>
                        <td><?php echo $patient->discount; ?></td>
                        <?php foreach ($departments as $dept) {
                            $test_amount = $this->payment->get_investigation_by_department_bill($patient->invoice_id, $dept->id); ?>
                            <td><?php echo number_format($test_amount->total_rate ?? 0, 2); ?></td>
                        <?php } ?>
                    </tr>
                    <tr>
                        <td colspan="3" align="right"><strong>Commission:</strong></td>
                        <td><?php echo number_format($patient->commission_amount, 2); ?></td>
                        <td><?php echo number_format($patient->discount, 2); ?></td>
                        <?php foreach ($departments as $dept) {
                            $test_amount = $this->payment->get_investigation_by_department_bill($patient->invoice_id, $dept->id); ?>
                            <td>
                                <?php
                                if ($patient->commission_type == 'mbbs') {
                                    echo number_format(($test_amount->total_rate ?? 0) - ($test_amount->total_mbbs ?? 0), 2);
                                } elseif ($patient->commission_type == 'vd') {
                                    echo number_format(($test_amount->total_rate ?? 0) - ($test_amount->total_vd ?? 0), 2);
                                } elseif ($patient->commission_type == 'emp') {
                                    echo number_format(($test_amount->total_rate ?? 0) - ($test_amount->total_emp ?? 0), 2);
                                } else {
                                    echo number_format(($test_amount->total_rate ?? 0) - ($test_amount->total_corporate ?? 0), 2);
                                }
                                ?>
                            </td>
                        <?php } ?>
                    </tr>
                </tfoot>
            </table>
            <!-- Summary -->
            <table class="table summary">
                <tbody>
                    <tr>
                        <td>Commission</td>
                        <td><?php echo number_format($patient->commission_amount, 2); ?></td>
                    </tr>
                    <tr>
                        <td>Discount</td>
                        <td><?php echo number_format($patient->discount, 2); ?></td>
                    </tr>
                    <tr>
                        <td>Paid</td>
                        <td><?php echo number_format($patient->payable_amount, 2); ?></td>
                    </tr>
                </tbody>
            </table>
            <table class="sign">
                <tr>
                    <td width="30%">Signature</td>
                    <td width="70%">Mobile:</td>
                </tr>
            </table>
        </div>
    </div>
</body>

</html>