{% extends 'base.html' %}
{% load static %}

{% block title %}
  All Transactions
{% endblock %}

 {% block extra_css %}
  <link rel="stylesheet" href="{% static 'CSS/transaction_list.css' %}">
    
 {% endblock %}

{% block head %}
  Transactions
{% endblock %}

{% block header %}
  {% if not user.is_staff %}
    All Transactions From users
  {% else %}
    All Transactions According To relevant Transaction
  {% endif %}
{% endblock %}

{% block content %}
  <div class="transaction_list_container">
    {% if not user.is_staff %}
      <h2>This is The all Transactions</h2>
    {% else %}
      <hr />
    {% endif %}

    {% if user.is_staff %}
      <table cellpadding="5" class="table table-bordered table-striped" border="1" style="border-collapse: collapse; width:80%;">
        <h2>ALL ADDITION TRANSACTION</h2>
        <thead style=" background:#7b7de7; font-weight:bold; color: black;">
          <tr>
            <th>User</th>
            <th>Car_Id</th>
            <th>Transaction Type</th>
            <th>Soda Amount</th>
            <th>Water Amount</th>
            <th>Status</th>
            <th>Confirmed By</th>
            <th>Created On</th>
            <th>View transaction</th>
          </tr>
        </thead>
        <tbody style=" font-weight:bold;">
          {% for t in transactions %}
            {% if t.get_transaction_type_display == 'Add' %}
              {% if t.get_status_display == 'Confirmed' %}
                <tr>
                  <td>{{ t.user.username|capfirst }}</td>
                  <td>{{ t.car_id }}</td>
                  <td>{{ t.get_transaction_type_display }}</td>
                  <td>{{ t.soda_amount }}</td>
                  <td>{{ t.water_amount }}</td>
                  <td>{{ t.get_status_display }}</td>

                  <td>
                    {% if t.confirmed_by %}
                      {{ t.confirmed_by.username }}
                    {% else %}

                    {% endif %}
                  </td>
                  <td>{{ t.created_at }}</td>
                  <td>
                    <a href="{% url 'transaction_data' t.id %}">Data</a>
                  </td>
                </tr>
              {% else %}

              {% endif %}
            {% else %}

            {% endif %}
          {% empty %}
            <tr>
              <td colspan="12" class="text-center">No transactions found.</td>
            </tr>
          {% endfor %}
        </tbody>
      </table>
      <h2>ALL TAKEOUT TRANSACTION</h2>
      <table cellpadding="2" class="table table-bordered table-striped" border="1" style="border-collapse: collapse; width:80%;">
        <thead style=" background:#7b7de7; font-weight:bold; color: black;">
          <tr>
            <th>User</th>
            <th>Car_Id</th>
            <th>Soda Amount</th>
            <th>Water Amount</th>
            <th>Status</th>

            <th>Start--Destination</th>

            <th>Confirmed By</th>
            <th>Created On</th>
            <th>View transaction</th>
          </tr>
        </thead>
        <tbody style="font-weight:bold; color: rgb(255, 255, 255);">
          {% for t in transactions %}
            {% if t.get_transaction_type_display != 'Add' %}
              <tr>
                <td>{{ t.user.username|capfirst }}</td>
                <td>{{ t.car_id }}</td>
                <td>{{ t.soda_amount }}</td>
                <td>{{ t.water_amount }}</td>
                <td>{{ t.get_status_display }}</td>
                <td>{{ t.tripstatics.start }}--{{ t.tripstatics.destination }}</td>

                <td>
                  {% if t.confirmed_by %}
                    {{ t.confirmed_by.username }}
                  {% else %}

                  {% endif %}
                </td>
                <td>{{ t.created_on }} at {{ t.created_at }}</td>
                <td>
                  <a href="{% url 'transaction_data' t.id %}">Data</a>
                </td>
              </tr>
            {% endif %}
          {% empty %}
            <tr>
              <td colspan="12" class="text-center">No transactions found.</td>
            </tr>
          {% endfor %}
        </tbody>
      </table>
    {% else %}
      <table cellpadding="2" class="table table-bordered table-striped" border="1" style="border-collapse: collapse; width:80%;">
        <thead style="background:#7b7de7; font-weight:bold; color: black;">
          <tr>
            <th>User</th>
            <th>Car_Id</th>

            <th>Soda Amount</th>
            <th>Water Amount</th>
            {% if user.is_staff %}
              <th>Transaction Type</th>
              <th>Status</th>
            {% endif %}
            <th>Start</th>
            <th>Destination</th>
            <th>Confirmed By</th>
            <th>Created On</th>
            <th>View transaction</th>
          </tr>
        </thead>
        <tbody style="font-weight:bold;">
          {% for t in transactions %}
            {% if t.get_transaction_type_display != 'Add' %}
              {% if t.get_status_display != 'Declined' %}
                <tr>
                  <td>{{ t.user.username }}</td>
                  <td>{{ t.car_id }}</td>
                  <td>{{ t.soda_amount }}</td>
                  <td>{{ t.water_amount }}</td>

                  {% if user.is_staff %}
                    <td>{{ t.get_transaction_type_display }}</td>
                    <td>{{ t.get_status_display }}</td>
                  {% endif %}
                  <td>{{ t.tripstatics.start }}</td>
                  <td>{{ t.tripstatics.destination }}</td>

                  <td>
                    {% if t.confirmed_by %}
                      {{ t.confirmed_by.username }}
                    {% else %}

                    {% endif %}
                  </td>
                  <td>{{ t.created_on }}</td>
                  <td>
                    <a href="{% url 'transaction_data' t.id %}">Data</a>
                  </td>
                </tr>
              {% else %}

              {% endif %}
            {% endif %}
          {% empty %}
            <tr>
              <td colspan="12" class="text-center">No transactions found.</td>
            </tr>
          {% endfor %}
        </tbody>
      </table>
    {% endif %}
  </div>
{% endblock %}
