<?php
include getcwd() . "/codes/patient-details-by-get-id.php";
include getcwd() . "/codes/search-patient-by-post-uid.php";
include getcwd() . "/codes/get-payment-details-by-payment-id.php";
?>

<!-- Main Content -->
<div class="container">

  <div class="row">
    <!-- Widget Item -->

    <div class="col-md-12">
      <div class="widget-area-2 proclinic-box-shadow">
        <h3 class="widget-title">Patient Details
          <span class="badge badge-danger pull-right"><?php echo $patient['patientUId']; ?></span>
          <span class="badge badge-warning pull-right"><?php echo $patient['patientFileNo']; ?></span>
        </h3>
        <div class="row justify-content-center">
          <div class="col-md-4">
            <div class="table-responsive">
              <table class="table table-bordered">
                <tbody>
                <tr>
                  <td><strong>Name</strong></td>
                  <td><?php echo $patient['patientName']; ?></td>
                </tr>
                <tr>
                  <td><strong>Date Of Birth</strong></td>
                  <td><?php echo $patient['patientDob']; ?></td>
                </tr>
                <tr>
                  <td><strong>Gender</strong></td>
                  <td><?php echo $patient['patientGender']; ?></td>
                </tr>
                <tr>
                  <td><strong>Patient Type</strong></td>
                  <td><?php echo $patient['patientTypeName']; ?></td>
                </tr>
                <tr>
                  <td><strong>Address</strong></td>
                  <td><?php echo $patient['patientAddress']; ?> </td>
                </tr>
                <tr>
                  <td><strong>Phone </strong></td>
                  <td><?php echo $patient['patientPhone']; ?></td>
                </tr>
                <tr>
                  <td><strong>Email</strong></td>
                  <td><?php echo $patient['patientEmail']; ?></td>
                </tr>
                <tr>
                  <td><strong></strong></td>
                  <td><img
                        src="<?php echo path(); ?>functions/lib.barcode.php?text=<?php echo $patient['patientUId']; ?>"/>
                  </td>
                </tr>


                </tbody>
              </table>
            </div>
            <!--Export links-->
            <nav aria-label="Page navigation example">
              <ul class="pagination justify-content-center export-pagination">
                <li class="page-item">
                  <a class="page-link" href="<?php echo path(); ?>edit-patient/<?php echo $patient['patientId']; ?>"><span class="ti-pencil-alt"></span> Edit</a>
                </li>
              </ul>
            </nav>
            <!-- /Export links-->
          </div>
          <div class="col-md-8">
            <!-- Widget Item -->
            <div class="table-responsive">
              <table id="tableId" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>#</th>
                  <th>Date</th>
                  <th>Service</th>
                  <th>Type</th>
                  <th>Amount</th>
                  <th>Payment Type</th>
                  <th>Receipt</th>
                </tr>
                </thead>
                <tbody>

                <?php
                $serial_no = 0;
                $visits = $conn->query("
                            SELECT udut_payments.*,
                                   udut_payments_status.*,
                                   udut_services_types.*,
                                   udut_services.*,
                                   udut_payments_types.*
                            FROM udut_payments
                            JOIN udut_payments_status
                            ON udut_payments.paymentStatusId = udut_payments_status.paymentStatusId
                            JOIN udut_payments_types
                            ON udut_payments.paymentTypeId = udut_payments_types.paymentTypeId
                            JOIN udut_services
                            ON udut_payments.serviceId = udut_services.serviceId                      
                            JOIN udut_services_types
                            ON udut_payments.typeId = udut_services_types.typeId
                            
                            WHERE udut_payments.userId = '" . $_SESSION['YUZA_ID'] . "' AND udut_payments.patientId = '".$patient['patientId']."'
                      ") or die("Problem fetching visits details ".$conn->error);

                while ($visit =  $visits->fetch_array()) {
                    $serial_no += 1;
                    print("
                       
                          <tr>
                            <td>".$serial_no."</td>
                            <td>".$visit['paymentDateAdded']."</td>
                            <td>".$visit['serviceName']."</td>
                            <td>".$visit['typeName']."</td>
                            <td>".$visit['typeAmount']."</td>
                            <td>".$visit['paymentTypeName']."</td>
                            <td>
                              <a class=\"btn btn-outline-success\" href=\"" . path() . "print-receipt/" . $patient["patientId"] . "/".$visit["paymentId"]."\"><span
                                    class=\"ti-printer\"></span> print</a>
                            </td>
                          </tr>

                        ");
                }
                ?>

                </tbody>
              </table>

              <br>
              <!--Export links-->
              <nav aria-label="Page navigation example">
                <ul class="pagination justify-content-center export-pagination">
                  <li class="page-item">
                    <a class="page-link" href="#"><span class="ti-money"></span> Refund</a>
                  </li>
                  <li class="page-item">
                    <a class="page-link" href="#"><span class="ti-printer"></span> Excel</a>
                  </li>
                  <li class="page-item">
                    <a class="page-link" href="#"><span class="ti-file"></span> PDF</a>
                  </li>
                  <li class="page-item">
                    <a class="page-link"
                       href="<?php echo path(); ?>add-service/<?php echo $patient['patientId']; ?>"><span
                          class="ti-plus"></span> Add Service</a>
                  </li>
                </ul>
              </nav>
              <!-- /Export links-->
            </div>
            <!-- /Widget Item -->
          </div>
        </div>
        <hr>
      </div>
    </div>
    <!-- /Widget Item -->


    <!-- /Widget Item -->
  </div>
</div>
<!-- /Main Content -->
