Sha256: 788415ea7e363873e6c036f539a49ab1568a06ed0b1c2b7beabaa8a0e3663010

Contents?: true

Size: 1.21 KB

Versions: 14

Compression:

Stored size: 1.21 KB

Contents

<% @query = query do %>
  select
    month as "Month",
    income as "Income",
    expenses as "Expenses",
    rate as "Savings Rate",
    rate_12 as "Prev Year",
    rate_24 as "Two Years"
  from (
       select
         month,
         income,
         expenses,
         rate,
         lead(rate, 12) over() as rate_12,
         lead(rate, 24) over() as rate_24
       from (
         select
           month,
           income,
           expenses,
           income - expenses as savings, 
           round(case when income = 0 then null else (income - expenses) / income * 100 end, 2) as rate
         from (
           select
             date_trunc('month', xtn_date)::date as month, 
             0 - sum(case when account ~ 'Income' then amount else 0 end) as income,
             sum(case when account ~ 'Expenses' then amount else 0 end) as expenses
           from 
             ledger
           group by 
             date_trunc('month', xtn_date)::date
         ) x 
         order by 
           month desc
       ) x
  ) x
  where
      month <= :to
      and month >= :from
<% end %>
<div class="page-header">
  <h1>Savings Rate</h1>
</div>
<div class="row">
  <div class="span16">
    <%= table @query %>
  </div>
</div>

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ledger_web-1.5.2 lib/ledger_web/reports/savings_rate.erb
ledger_web-1.5.1 lib/ledger_web/reports/savings_rate.erb
ledger_web-1.5.0 lib/ledger_web/reports/savings_rate.erb
ledger_web-1.4.11 lib/ledger_web/reports/savings_rate.erb
ledger_web-1.4.10 lib/ledger_web/reports/savings_rate.erb
ledger_web-1.4.9 lib/ledger_web/reports/savings_rate.erb
ledger_web-1.4.8 lib/ledger_web/reports/savings_rate.erb
ledger_web-1.4.7 lib/ledger_web/reports/savings_rate.erb
ledger_web-1.4.6 lib/ledger_web/reports/savings_rate.erb
ledger_web-1.4.4 lib/ledger_web/reports/savings_rate.erb
ledger_web-1.4.3 lib/ledger_web/reports/savings_rate.erb
ledger_web-1.4.2 lib/ledger_web/reports/savings_rate.erb
ledger_web-1.4.1 lib/ledger_web/reports/savings_rate.erb
ledger_web-1.4 lib/ledger_web/reports/savings_rate.erb