import { ComboBox, HorizontalBox, ListView, VerticalBox, StandardListView, Button, GridBox } from "std-widgets.slint"; import { CapitalGains } from "./capital-gains.slint"; import { Cell, CurrencyCell, CurrencyIcon, ElidingText, HeaderCell, MonoTextCell, TableHeader } from "./common.slint"; import { Facade } from "./global.slint"; import { UiTaxReport } from "./structs.slint"; component MonoText inherits Text { font-family: "DejaVu Sans Mono"; } export component Reports inherits Rectangle { callback currency-filter-clicked(string); callback select-transaction(int); in property <[StandardListViewItem]> report-years: Facade.report-years; in property <[UiTaxReport]> reports: Facade.reports; property report: reports[year-list.current-item]; HorizontalBox { padding: 0; VerticalBox { padding: 0; year-list := StandardListView { model: root.report-years; current-item: 0; min-width: 80px; max-width: 150px; } HorizontalBox { horizontal-stretch: 1; Button { text: "Export All"; clicked => { Facade.export-all(); } } } } VerticalBox { horizontal-stretch: 10; padding: 0; HorizontalLayout { GridBox { width: 50%; padding: 3px; Row { Text { col: 1; text: "Short Term"; opacity: 0.8; horizontal-alignment: right; } Text { text: "Long Term"; opacity: 0.8; horizontal-alignment: right; } Text { text: "Total"; opacity: 0.8; horizontal-alignment: right; font-weight: 600; } } Row { Text { text: "Capital Gains"; opacity: 0.8; } MonoText { text: report.short-term-capital-gains; horizontal-alignment: right; } MonoText { text: report.long-term-capital-gains; horizontal-alignment: right; } MonoText { text: report.total-capital-gains; horizontal-alignment: right; font-weight: 600; } } Row { Text { text: "Capital Losses"; opacity: 0.8; } MonoText { text: report.short-term-capital-losses; horizontal-alignment: right; } MonoText { text: report.long-term-capital-losses; horizontal-alignment: right; } MonoText { text: report.total-capital-losses; horizontal-alignment: right; font-weight: 600; } } Row { Text { text: "Net Capital Gains"; opacity: 0.8; font-size: 15px; font-weight: 600; } MonoText { text: report.short-term-net-capital-gains; horizontal-alignment: right; font-size: 15px; font-weight: 600; } MonoText { text: report.long-term-net-capital-gains; horizontal-alignment: right; font-size: 15px; font-weight: 600; } MonoText { text: report.total-net-capital-gains; horizontal-alignment: right; font-size: 15px; font-weight: 600; } } } } HorizontalBox { padding-left: 0; report-combo := ComboBox { horizontal-stretch: 0; model: [ "Report Summary", "Capital Gains Report" ]; } Rectangle {} Button { text: "Export (CSV)"; enabled: { if (report-combo.current-index == 0) { report.currencies.length > 0 } else { report.gains.length > 0 } } clicked => { if (report-combo.current-index == 0) { Facade.export-summary(year-list.current-item); } else { Facade.export-capital-gains(year-list.current-item); } } } } Rectangle { VerticalLayout { spacing: 2px; visible: report-combo.current-index == 0; summary-header := TableHeader { horizontal-padding-left: -2px; Cell { padding-left: 7px; HeaderCell { text: "Currency"; } } HeaderCell { text: "Starting Balance"; horizontal-alignment: right; } HeaderCell { text: "Ending Balance"; horizontal-alignment: right; } HeaderCell { text: "Quantity Disposed"; horizontal-alignment: right; } HeaderCell { text: "Cost"; horizontal-alignment: right; } HeaderCell { text: "Fees"; horizontal-alignment: right; } HeaderCell { text: "Proceeds"; horizontal-alignment: right; } HeaderCell { text: "Capital P/L"; horizontal-alignment: right; } HeaderCell { text: "Income"; horizontal-alignment: right; } HeaderCell { text: "Total P/L"; horizontal-alignment: right; } } summary-view := ListView { for currency[index] in report.currencies: Rectangle { property even: mod(index, 2) == 0; background: touch.has-hover ? #4564 : even ? #ffffff06 : transparent; border-radius: self.height / 4; touch := TouchArea {} HorizontalLayout { padding-right: 17px; spacing: summary-header.item-spacing; CurrencyCell { cmc-id: currency.currency-cmc-id; currency: currency.currency; clicked => { root.currency-filter-clicked(currency.currency) } } MonoTextCell { text: currency.balance_start; } MonoTextCell { text: currency.balance_end; } MonoTextCell { text: currency.quantity_disposed; } MonoTextCell { text: currency.cost; } MonoTextCell { text: currency.fees; } MonoTextCell { text: currency.proceeds; } MonoTextCell { text: currency.capital_profit_loss; } MonoTextCell { text: currency.income; } MonoTextCell { text: currency.total_profit_loss; } } } } } CapitalGains { visible: report-combo.current-index == 1; gain-entries: report.gains; select-transaction(id) => { root.select-transaction(id) } } } } } }