{% extends "base.html" %}

{% comment %}
# This file is part of k4ever, a point-of-sale system
#   Contact............  <k4ever@lists.someserver.de>
#   Website............  http://k4ever.someserver.de/
#   Bug tracker........  http://k4ever.someserver.de/report
#
# Licensed under GNU Affero General Public License v3 or later
{% endcomment %}

{% block "content" %}
	<ul id="tab" class="nav nav-tabs">
		<li class="active"><a href="#payments" data-toggle="tab">Konten Ein- und Auszahlungen</a></li>
		<li><a href="#transactions" data-toggle="tab">Überweisungen</a></li>
		<li class="dropdown">
			<a href="#" class="dropdown-toggle" data-toggle="dropdown">Historien <b class="caret"></b></a>
			<ul class="dropdown-menu">
				<li><a href="#payment-history" data-toggle="tab">Ein- und Auszahlungen</a></li>
				<li><a href="#transaction-history" data-toggle="tab">Überweisungen</a></li>
			</ul>
		</li>
	</ul>

	<div class="tab-content">
		<div class="tab-pane active" id="payments">
			<h2>Konten Ein- und Auszahlungen</h2>
			{% if transacted %}
				<div class="alert {% if error %}alert-error{% else %}alert-success{% endif %}">
					{% if error %}
						<h4 class="alert-heading">Beim Aufladen ist ein Fehler aufgetreten.</h4>
					{% else %}
						{% if payout %}
							<h4 class="alert-heading">Du hast Geld abgehoben.</h4>
						{% else %}						
							<h4 class="alert-heading">Du hast Geld aufgeladen.</h4>
						{% endif %}
					{% endif %}
				</div>
			{% endif %}
			<form method="post" action="/transaction/#payments" class="form-horizontal">
				{% csrf_token %}
				<input type="hidden" name="_formtype" value="normal" />
				{% include "form.html" with form=form %}
				<div class="control-group">
					<div class="controls">
						<input type="submit" class="btn btn-primary" value="Einzahlen" />
					</div>
				</div>
			</form>

			<h3>Kontodaten:</h3>
			<div class="row-fluid">
				<div class="span6">
					{% include "treasurer.html" %}
				</div>
			</div>
		</div>

		<div class="tab-pane" id="transactions">
			<h2>Geld überweisen</h2>
			{% if transacted %}
				<div class="alert {% if error %}alert-error{% else %}alert-success{% endif %}">
					{% if error %}
						<h4 class="alert-heading">Beim Überweisen ist ein Fehler aufgetreten.</h4>
					{% else %}
						<h4 class="alert-heading">Du hast Geld aufgeladen.</h4>
					{% endif %}
				</div>
			{% endif %}
			<form method="post" action="/transaction/#transactions" class="form-horizontal">
				{% csrf_token %}
				<input type="hidden" name="_formtype" value="virtual" />
				{% include "form.html" with form=vform %}
				<div class="control-group">
					<div class="controls">
						<input type="submit" class="btn btn-primary" value="Überweisen" />
					</div>
				</div>
			</form>
		</div>

		<div class="tab-pane" id="payment-history">
			<h2>Vergangene Ein- und Auszahlungen</h2>
			<table class="table table-striped table-condensed">
				<thead>
					<tr>
						<th>Datum</th>
						<th>Uhrzeit</th>
						<th>Betrag</th>
						<th>Typ</th>
						<th>Status</th>
					</tr>
				</thead>

				<tbody>
					{% for transaction in history %}
						<tr>
							<td>{{ transaction.dateTime|date:"j. F Y" }}</td>
							<td>{{ transaction.dateTime|date:"H:i" }} Uhr</td>
							<td>{{ transaction.amount|floatformat:2 }}€</td>
							<td>{{ transaction.transactionType }}</td>
							<td>
								{% if not transaction.transactionType.needsCheck or transaction.checked %}
									<span class="icon approved" title="Zahlung eingegangen">Zahlung eingegangen</span>
								{% else %}
									<span class="icon pending" title="Zahlungsbestätigung steht noch aus">Zahlungsbestätigung steht noch aus</span>
								{% endif %}
							</td>
						</tr>
					{% endfor %}
				</tbody>

				<tfoot>
					<tr>
						<th>Datum</th>
						<th>Uhrzeit</th>
						<th>Betrag</th>
						<th>Typ</th>
						<th>Status</th>
					</tr>
				</tfoot>
			</table>
		</div>

		<div class="tab-pane" id="transaction-history">
			<h2>Vergangene Überweisungen</h2>
			<table class="table table-striped table-condensed">
				<thead>
					<tr>
						<th>Datum</th>
						<th>Uhrzeit</th>
						<th>Betrag</th>
						<th>Sender</th>
						<th>Typ</th>
						<th>Recipient</th>
						<th>Comment</th>
					</tr>
				</thead>

				<tbody>
					{% for transaction in vhistory %}
						<tr>
							<td>{{ transaction.dateTime|date:"j. F Y" }}</td>
							<td>{{ transaction.dateTime|date:"H:i" }} Uhr</td>
							<td>{{ transaction.amount|floatformat:2 }}€</td>
							<td>{{ transaction.user }}</td>
							<td>
								{% if user.username|stringformat:"s" == transaction.user|stringformat:"s" %}
									<span class="icon cashOut" title="Zahlung abgebucht">Zahlung abgebucht</span>
								{% else %}
									<span class="icon cashIn" title="Zahlung eingegangen">Zahlung eingegangen</span>
								{% endif %}
							</td>
							<td>{{ transaction.recipient }}</td>
							<td>{{ transaction.comment }}</td>
						</tr>
					{% endfor %}
				</tbody>

				<tfoot>
					<tr>
						<th>Datum</th>
						<th>Uhrzeit</th>
						<th>Betrag</th>
						<th>Sender</th>
						<th>Typ</th>
						<th>Recipient</th>
						<th>Comment</th>
					</tr>
				</tfoot>
			</table>
		</div>
	</div>
{% endblock %}
