<% content_for :title do %> <%= t("reports.print.document_title") %> - <%= @start_date.strftime("%B %d, %Y") %> to <%= @end_date.strftime("%B %d, %Y") %> <% end %>
<%# Header %>

<%= t("reports.print.title") %>

<%= @start_date.strftime("%B %d, %Y") %> – <%= @end_date.strftime("%B %d, %Y") %>

<%= Current.family.name %> · <%= t("reports.print.generated_on", date: Time.current.strftime("%B %d, %Y")) %>

<%# Summary %>

<%= t("reports.print.summary.title") %>

<%= t("reports.print.summary.income") %> <%= @summary_metrics[:current_income].format %> <% if @summary_metrics[:income_change] && @summary_metrics[:income_change] != 0 %> "> <%= t("reports.print.summary.vs_prior", percent: (@summary_metrics[:income_change] >= 0 ? "+#{@summary_metrics[:income_change]}" : @summary_metrics[:income_change].to_s)) %> <% end %> <% if has_sparkline_data?(@trends_data) %> <% end %>
<%= t("reports.print.summary.expenses") %> <%= @summary_metrics[:current_expenses].format %> <% if @summary_metrics[:expense_change] && @summary_metrics[:expense_change] != 0 %> "> <%= t("reports.print.summary.vs_prior", percent: (@summary_metrics[:expense_change] >= 0 ? "+#{@summary_metrics[:expense_change]}" : @summary_metrics[:expense_change].to_s)) %> <% end %> <% if has_sparkline_data?(@trends_data) %> <% end %>
<%= t("reports.print.summary.net_savings") %> "><%= @summary_metrics[:net_savings].format %> <% # Calculate savings rate savings_rate = @summary_metrics[:current_income].amount > 0 ? ((@summary_metrics[:net_savings].amount / @summary_metrics[:current_income].amount) * 100).round(0) : 0 %> <% if savings_rate != 0 %> <%= t("reports.print.summary.of_income", percent: savings_rate) %> <% end %> <% if has_sparkline_data?(@trends_data) %> " stroke-width="1.5" /> <% end %>
<% if @summary_metrics[:budget_percent] %>
<%= t("reports.print.summary.budget") %> <%= @summary_metrics[:budget_percent] %>% <%= t("reports.print.summary.used") %>
<% end %>
<%# Net Worth %> <% if @has_accounts %>

<%= t("reports.print.net_worth.title") %>

<%= t("reports.print.net_worth.current_balance") %> "> <%= @net_worth_metrics[:current_net_worth].format %> <% if @net_worth_metrics[:trend] %> <%= @net_worth_metrics[:trend].value >= 0 ? "+" : "" %><%= @net_worth_metrics[:trend].value.format %> (<%= @net_worth_metrics[:trend].percent_formatted %>) <%= t("reports.print.net_worth.this_period") %> <% end %> <% if has_sparkline_data?(@trends_data) %> " stroke-width="1.5" /> <% end %>

<%= t("reports.print.net_worth.assets") %> <%= @net_worth_metrics[:total_assets].format %>

<% if @net_worth_metrics[:asset_groups].any? %> <% @net_worth_metrics[:asset_groups].each do |group| %> <% end %>
<%= group[:name] %> <%= group[:total].format %>
<% end %>

<%= t("reports.print.net_worth.liabilities") %> <%= @net_worth_metrics[:total_liabilities].format %>

<% if @net_worth_metrics[:liability_groups].any? %> <% @net_worth_metrics[:liability_groups].each do |group| %> <% end %>
<%= group[:name] %> <%= group[:total].format %>
<% else %>

<%= t("reports.print.net_worth.no_liabilities") %>

<% end %>
<% end %> <%# Monthly Trends %> <% if has_sparkline_data?(@trends_data) %>

<%= t("reports.print.trends.title") %>

<% @trends_data.each do |trend| %> "> <% end %> <% total_income = @trends_data.sum { |t| t[:income].to_d } total_expenses = @trends_data.sum { |t| t[:expenses].to_d } total_net = @trends_data.sum { |t| t[:net].to_d } trends_count = @trends_data.length avg_income = trends_count > 0 ? (total_income / trends_count) : 0 avg_expenses = trends_count > 0 ? (total_expenses / trends_count) : 0 avg_net = trends_count > 0 ? (total_net / trends_count) : 0 overall_savings_rate = total_income > 0 ? ((total_net / total_income) * 100).round(0) : 0 %>
<%= t("reports.print.trends.month") %> <%= t("reports.print.trends.income") %> <%= t("reports.print.trends.expenses") %> <%= t("reports.print.trends.net") %> <%= t("reports.print.trends.savings_rate") %>
<%= trend[:month] %><%= trend[:is_current_month] ? " *" : "" %> <%= Money.new(trend[:income], Current.family.currency).format %> <%= Money.new(trend[:expenses], Current.family.currency).format %> "><%= Money.new(trend[:net], Current.family.currency).format %> <% month_savings_rate = trend[:income] > 0 ? ((trend[:net].to_f / trend[:income].to_f) * 100).round(0) : 0 %> <%= month_savings_rate %>%
<%= t("reports.print.trends.average") %> <%= Money.new(avg_income, Current.family.currency).format %> <%= Money.new(avg_expenses, Current.family.currency).format %> "><%= Money.new(avg_net, Current.family.currency).format %> <%= overall_savings_rate %>%
<% if @trends_data.any? { |t| t[:is_current_month] } %>

<%= t("reports.print.trends.current_month_note") %>

<% end %>
<% end %> <%# Investments %> <% if @investment_metrics[:has_investments] %>

<%= t("reports.print.investments.title") %>

<%= t("reports.print.investments.portfolio_value") %> <%= format_money(@investment_metrics[:portfolio_value]) %> <% if has_sparkline_data?(@trends_data) %> <% end %>
<% if @investment_metrics[:unrealized_trend] %>
<%= t("reports.print.investments.total_return") %> <%= @investment_metrics[:unrealized_trend].value >= 0 ? "+" : "" %><%= format_money(Money.new(@investment_metrics[:unrealized_trend].value, Current.family.currency)) %> <%= @investment_metrics[:unrealized_trend].percent_formatted %>
<% end %>
<%= t("reports.print.investments.contributions") %> <%= format_money(@investment_metrics[:period_contributions]) %> <%= t("reports.print.investments.this_period") %>
<%= t("reports.print.investments.withdrawals") %> <%= format_money(@investment_metrics[:period_withdrawals]) %> <%= t("reports.print.investments.this_period") %>
<% if @investment_metrics[:top_holdings].any? %>

<%= t("reports.print.investments.top_holdings") %>

<% @investment_metrics[:top_holdings].each do |holding| %> <% end %>
<%= t("reports.print.investments.holding") %> <%= t("reports.print.investments.weight") %> <%= t("reports.print.investments.value") %> <%= t("reports.print.investments.return") %>
<%= holding.ticker %> <%= truncate(holding.name, length: 25) %> <%= number_to_percentage(holding.weight || 0, precision: 1) %> <%= format_money(holding.amount_money) %> <% if holding.trend %> <%= holding.trend.percent_formatted %> <% else %> <% end %>
<% end %>
<% end %> <%# Spending by Category %> <% if @transactions.any? %>

<%= t("reports.print.spending.title") %>

<% income_groups = @transactions.select { |g| g[:type] == "income" } expense_groups = @transactions.select { |g| g[:type] == "expense" } income_total = income_groups.sum { |g| g[:total] } expense_total = expense_groups.sum { |g| g[:total] } %>
<% if income_groups.any? %>

<%= t("reports.print.spending.income") %> <%= Money.new(income_total, Current.family.currency).format %>

<% income_groups.first(8).each do |group| %> <% percentage = income_total.zero? ? 0 : (group[:total].to_f / income_total * 100).round(0) %> <% end %> <% if income_groups.length > 8 %> <% end %>
<%= t("reports.print.spending.category") %> <%= t("reports.print.spending.amount") %> <%= t("reports.print.spending.percent") %>
<%= group[:category_name] %> <%= Money.new(group[:total], Current.family.currency).format %> <%= percentage %>%
<%= t("reports.print.spending.more_categories", count: income_groups.length - 8) %>
<% end %> <% if expense_groups.any? %>

<%= t("reports.print.spending.expenses") %> <%= Money.new(expense_total, Current.family.currency).format %>

<% expense_groups.first(8).each do |group| %> <% percentage = expense_total.zero? ? 0 : (group[:total].to_f / expense_total * 100).round(0) %> <% end %> <% if expense_groups.length > 8 %> <% end %>
<%= t("reports.print.spending.category") %> <%= t("reports.print.spending.amount") %> <%= t("reports.print.spending.percent") %>
<%= group[:category_name] %> <%= Money.new(group[:total], Current.family.currency).format %> <%= percentage %>%
<%= t("reports.print.spending.more_categories", count: expense_groups.length - 8) %>
<% end %>
<% end %>