{#  DrCr: Web-based double-entry bookkeeping framework
    Copyright (C) 2022–2024  Lee Yingtong Li (RunasSudo)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
#}

{% extends 'base_tailwind.html' %}
{% block title %}CGT assets{% endblock %}

{% block content %}
	<h1 class="text-3xl text-gray-900">
		CGT assets
	</h1>
	
	<table class="min-w-full">
		<thead>
			<tr>
				<th></th>
				<th></th>
				<th></th>
				<th class="py-0.5 px-1 text-gray-900 font-semibold text-start border-l border-gray-300" colspan="2">Acquisition</th>
				<th class="py-0.5 px-1 text-gray-900 font-semibold text-start border-l border-gray-300" colspan="2">Adjustment</th>
				<th class="print:hidden"></th>
				<th class="py-0.5 px-1 text-gray-900 font-semibold text-start border-l border-gray-300" colspan="2">Disposal</th>
				<th class="border-l border-gray-300"></th>
			</tr>
			<tr>
				<th class="py-0.5 text-gray-900 font-semibold text-start">Account</th>
				<th class="py-0.5 text-gray-900 font-semibold text-start">Asset</th>
				<th class="py-0.5 px-1 text-gray-900 font-semibold text-end">Units</th>
				<th class="py-0.5 px-1 text-gray-900 font-semibold text-start border-l border-gray-300">Date</th>
				<th class="py-0.5 px-1 text-gray-900 font-semibold text-end">Value</th>
				<th class="py-0.5 px-1 text-gray-900 font-semibold text-end border-l border-gray-300">b/f&nbsp;</th>
				<th class="py-0.5 px-1 text-gray-900 font-semibold text-end">{{ eofy_date.year }}</th>
				<th class="print:hidden"></th>
				<th class="py-0.5 px-1 text-gray-900 font-semibold text-start border-l border-gray-300">Date</th>
				<th class="py-0.5 px-1 text-gray-900 font-semibold text-end">Value</th>
				<th class="py-0.5 pl-1 text-gray-900 font-semibold text-end border-l border-gray-300">Gain&nbsp;</th>
			</tr>
		</thead>
		<tbody>
			{% for asset in assets %}
				<tr class="border-t border-gray-300">
					<td class="py-0.5 pr-1 text-gray-900">
						<a href="{{ url_for('account_transactions', account=asset.account, commodity_detail=1) }}" class="hover:text-blue-700 hover:underline">{{ asset.account }}</a>
					</td>
					<td class="py-0.5 px-1 text-gray-900">{{ asset.commodity_name() }}</td>
					<td class="py-0.5 px-1 text-gray-900 text-end">{{ asset.format('hide') }}</td>
					<td class="py-0.5 px-1 text-gray-900 border-l border-gray-300">{{ asset.acquisition_date.strftime('%Y-%m-%d') }}</td>
					<td class="py-0.5 px-1 text-gray-900 text-end">{{ asset.as_cost().format() }}</td>
					<td class="py-0.5 px-1 text-gray-900 text-end border-l border-gray-300">{{ asset.cost_adjustment_brought_forward().format_accounting(link=url_for('cgt_adjustments', account=asset.account, commodity=asset.commodity, quantity=asset.quantity, acquisition_date=asset.acquisition_date.strftime('%Y-%m-%d'))) if asset.cost_adjustment_brought_forward().quantity != 0 }}</td>
					<td class="py-0.5 px-1 text-gray-900 text-end">{{ asset.cost_adjustment_current_period().format_accounting(link=url_for('cgt_adjustments', account=asset.account, commodity=asset.commodity, quantity=asset.quantity, acquisition_date=asset.acquisition_date.strftime('%Y-%m-%d'))) if asset.cost_adjustment_current_period().quantity != 0 }}</td>
					<td class="py-0.5 px-1 text-gray-900 text-center print:hidden">
						<a href="{{ url_for('cgt_adjustment_new', account=asset.account, asset=asset.quantity_string(), acquisition_date=asset.acquisition_date.strftime('%Y-%m-%d')) }}" class="text-gray-500 hover:text-gray-700">
							<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4">
								<path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" />
							</svg>
						</a>
					</td>
					<td class="py-0.5 px-1 text-gray-900 border-l border-gray-300">{{ asset.disposal_date.strftime('%Y-%m-%d') if asset.disposal_date else '' }}</td>
					<td class="py-0.5 px-1 text-gray-900 text-end">{{ asset.disposal_value.format() if asset.disposal_value else '' }}</td>
					<td class="py-0.5 pl-1 text-gray-900 text-end border-l border-gray-300">{% if asset.disposal_date %}{{ asset.gain().format_accounting() }}{% endif %}</td>
				</tr>
			{% endfor %}
		</tbody>
	</table>
{% endblock %}