| 1 |
<script lang="ts"> |
| 2 |
import { parseChartData } from "../../charts"; |
| 3 |
import ChartSwitcher from "../../charts/ChartSwitcher.svelte"; |
| 4 |
import { chartContext } from "../../charts/context"; |
| 5 |
import { urlForAccount } from "../../helpers"; |
| 6 |
import { _ } from "../../i18n"; |
| 7 |
import { is_non_empty } from "../../lib/array"; |
| 8 |
import { intervalLabel } from "../../lib/interval"; |
| 9 |
import { interval } from "../../stores"; |
| 10 |
import IntervalTreeTable from "../../tree-table/IntervalTreeTable.svelte"; |
| 11 |
import type { AccountReportProps } from "."; |
| 12 |
|
| 13 |
let { |
| 14 |
account, |
| 15 |
report_type, |
| 16 |
charts, |
| 17 |
journal, |
| 18 |
interval_balances, |
| 19 |
dates, |
| 20 |
budgets, |
| 21 |
}: AccountReportProps = $props(); |
| 22 |
|
| 23 |
let accumulate = $derived(report_type === "balances"); |
| 24 |
|
| 25 |
let chartData = $derived( |
| 26 |
parseChartData(charts, $chartContext).unwrap_or(null), |
| 27 |
); |
| 28 |
let interval_label = $derived(intervalLabel($interval).toLowerCase()); |
| 29 |
</script> |
| 30 |
|
| 31 |
{#if chartData} |
| 32 |
<ChartSwitcher charts={chartData} /> |
| 33 |
{/if} |
| 34 |
|
| 35 |
<div class="droptarget" data-account-name={account}> |
| 36 |
<div class="headerline"> |
| 37 |
<h3> |
| 38 |
{#if report_type !== "journal"} |
| 39 |
<a |
| 40 |
href={$urlForAccount(account)} |
| 41 |
title={_("Journal of all entries for this Account and Sub-Accounts")} |
| 42 |
> |
| 43 |
{_("Account Journal")} |
| 44 |
</a> |
| 45 |
{:else} |
| 46 |
{_("Account Journal")} |
| 47 |
{/if} |
| 48 |
</h3> |
| 49 |
<h3> |
| 50 |
{#if report_type !== "changes"} |
| 51 |
<a href={$urlForAccount(account, { r: "changes" })}> |
| 52 |
{_("Changes")} ({interval_label}) |
| 53 |
</a> |
| 54 |
{:else} |
| 55 |
{_("Changes")} ({interval_label}) |
| 56 |
{/if} |
| 57 |
</h3> |
| 58 |
<h3> |
| 59 |
{#if report_type !== "balances"} |
| 60 |
<a href={$urlForAccount(account, { r: "balances" })}> |
| 61 |
{_("Balances")} ({interval_label}) |
| 62 |
</a> |
| 63 |
{:else} |
| 64 |
{_("Balances")} ({interval_label}) |
| 65 |
{/if} |
| 66 |
</h3> |
| 67 |
</div> |
| 68 |
{#if report_type === "journal"} |
| 69 |
<!-- eslint-disable-next-line svelte/no-at-html-tags --> |
| 70 |
{@html journal} |
| 71 |
{:else if interval_balances && is_non_empty(interval_balances) && budgets && dates} |
| 72 |
<IntervalTreeTable |
| 73 |
trees={interval_balances} |
| 74 |
{dates} |
| 75 |
{budgets} |
| 76 |
{accumulate} |
| 77 |
/> |
| 78 |
{/if} |
| 79 |
</div> |