um-cseg/chez-betty

View on GitHub
chezbetty/templates/terminal/purchase_complete.jinja2

Summary

Maintainability
Test Coverage
<table class="table table-bordered" id="purchase-complete-table">
  <thead>
    <tr>
      <th class="item-title">{{ _('Item') }}</th>
      <th class="item-quantity" style="width: 15%;">{{ _('Quantity') }}</th>
      <th class="item-price" style="width: 15%;">{{ _('Item Price') }}</th>
      <th class="item-total" style="width: 15%;">{{ _('Total Price') }}</th>
    </tr>
  </thead>

  <tbody>
  {% for item in order['items'] %}
    <tr class="purchase-item">
      <td class="item-title">{{ item.name }}</td>
      <td class="item-quantity">{{ item.quantity }}</td>
      <td class="item-price">{{ item.price|format_currency|safe }}</td>
      <td class="item-total">{{ item.total_price|format_currency|safe }}</td>
    </tr>
  {% endfor %}
  </tbody>

  <tfoot>
    {% if order['discount'] %}
    {% set subtotal = transaction.amount / (1-transaction.discount) %}
    <tr>
      <td colspan="3"><b>{{ _('Subtotal') }}</b></td>
      <td id="purchase-subtotal">{{ subtotal|format_currency|safe }}</td>
    </tr>
    <tr>
      <td><b>{{ _('Discounts/Fees') }}</b></td>
      {% if order['discount'] < 0 %}
      {# This is a fee #}
      <td id="purchase-fee-percent" colspan="2">
        {{ '{:.3}'.format(order['discount']*-100) }}%
      </td>
      <td id="purchase-fee">
        {{ (subtotal * order['discount'] * -1)|format_currency|safe }}
      </td>
      {% else %}
      {# This is an actual discount #}
      <td id="purchase-discount-percent" colspan="2">
        ({{ '{:.2}'.format(order['discount']*100) }}%)
      </td>
      <td id="purchase-discount">
        ({{ (subtotal * order['discount'])|format_currency|safe }})
      </td>
      {% endif %}
    </tr>
    {% endif %}
    <tr>
      <td colspan="3">
        <b>{{ _('Total') }}</b>
        {% if account_type == "user" %}
        {{ _('(Paid with your user account)') }}
        {% elif account_type == "pool" %}
        {{ _('(Paid with %(pool_name)s Pool)')|format(pool_name=pool.name) }}
        {% endif %}
        <button type="button" id="purchase-delete-{{ event.id }}" class="btn btn-primary btn-sm btn-delete-purchase" style="float:right;">{{ _('Mistake? Undo this Purchase') }}</button>
      </td>
      <td id="purchase-total">{{ order['total']|format_currency|safe }}</td>
    </tr>
  </tfoot>
</table>