Skip to content

Commit 3a58dc9

Browse files
committed
add totals on incoming and outgoing
1 parent 5e300c0 commit 3a58dc9

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

app/controllers/pages_controller.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
# frozen_string_literal: true
2-
1+
# app/controllers/pages_controller.rb
32
class PagesController < ApplicationController
43
def landing
54
query = TransactionsQuery.new(current_user)
65
@transactions = ActiveRecord::Base.connection.exec_query(query.query.order(query.arel_table[:time].desc).take(10).project(Arel.star).to_sql)
76
@requests = current_user.incoming_requests.open.includes(:creditor).take(10)
7+
@total_incoming_amount = current_user.incoming_requests.open.sum(:amount)
88
@outgoing_requests = current_user.outgoing_requests.open.includes(:debtor).take(10)
9+
@total_outgoing_amount = current_user.outgoing_requests.open.sum(:amount)
910
@notifications = current_user.notifications.unread
1011
end
1112

app/views/pages/_outgoing_requests.html.erb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<%= render 'shared/dashboard_card',
22
card_title: "Outgoing requests",
33
view_all_path: user_requests_path(current_user) do %>
4-
<ul role="list" class="divide-y divide-gray-200">
4+
<ul role="list">
55
<% if @outgoing_requests.any? %>
66
<% @outgoing_requests.each do |r| %>
77
<li class="py-3 sm:py-4">
@@ -20,6 +20,12 @@
2020
</div>
2121
</li>
2222
<% end %>
23+
<li class="py-4 border-t-2 border-gray-900 mt-2">
24+
<div class="flex items-center justify-between font-bold text-gray-900">
25+
<span>Total</span>
26+
<span><%= euro_from_cents @total_outgoing_amount %></span>
27+
</div>
28+
</li>
2329
<% else %>
2430
None!
2531
<% end %>

app/views/pages/_requests.html.erb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<%= render 'shared/dashboard_card',
22
card_title: "Requests",
33
view_all_path: user_requests_path(current_user) do %>
4-
<ul role="list" class="divide-y divide-gray-200">
4+
<ul role="list">
55
<% if @requests.any? %>
66
<% @requests.each do |r| %>
77
<li class="py-3 sm:py-4">
@@ -34,6 +34,12 @@
3434
</div>
3535
</li>
3636
<% end %>
37+
<li class="py-4 border-t-2 border-gray-900 mt-2">
38+
<div class="flex items-center justify-between font-bold text-gray-900">
39+
<span>Total</span>
40+
<span><%= euro_from_cents @total_incoming_amount %></span>
41+
</div>
42+
</li>
3743
<% else %>
3844
None!
3945
<% end %>

0 commit comments

Comments
 (0)