Skip to content

Commit

Permalink
Add comparison with previous month
Browse files Browse the repository at this point in the history
  • Loading branch information
dhilst committed Nov 20, 2018
1 parent cc341c7 commit 28b915c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ $(document).on('ready turbolinks:load', function(){
}
}, 3000);
<% end %>
$('[data-toggle="tooltip"]').tooltip();
});
7 changes: 7 additions & 0 deletions app/controllers/transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ def groupby_filter
.group('categories.id')
.order('_debit')
@categorygroup = true
if @d.month == Time.zone.now.month
@prev_month_amount = current_user.transactions
.where('transactions.date between ? and ?', 1.month.ago.beginning_of_month, 1.month.ago)
.joins(:category)
.group('categories.name')
.sum(:amount)
end
@grouped = true
else
@transactions = @transactions.order('date, memo')
Expand Down
4 changes: 4 additions & 0 deletions app/views/transactions/_categorygroup.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<th scope="col">Categoria</th>
<th scope="col">Entrada</th>
<th scope="col">Saida</th>
<th scope="col" data-toggle="tooltip" data-placement="top" title="Comparação com mesmo dia do mes anterior: (<%= l(1.month.ago, format: '%d/%m') %>)">Mês Anterior</th>
</tr>
</thead>
<tbody>
Expand All @@ -26,6 +27,9 @@
<% end %>
</span>
</td>
<td>
<%= @prev_month_amount[t.category_name] if @prev_month_amount && @prev_month_amount[t.category_name] %>
</td>
</tr>
<% end %>
</tbody>
Expand Down
1 change: 0 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.boolean "admin", default: false
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["invitation_token"], name: "index_users_on_invitation_token", unique: true
Expand Down

0 comments on commit 28b915c

Please sign in to comment.