Skip to content

Commit

Permalink
Merge branch 'release/v1.8.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
odinsride committed Aug 13, 2021
2 parents dc4d9b2 + a25e506 commit dfe1529
Show file tree
Hide file tree
Showing 21 changed files with 613 additions and 312 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased] changes

## [v1.8.3] - 2021-08-13

### New
- Added a Summary Mailer to allow emailing of the daily summary report

### Chores
- Update all dependencies

## [v1.8.2] - 2021-07-31

### Fixed
Expand Down Expand Up @@ -277,7 +285,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Account overview with list of all accounts and balances for each


[Unreleased]: https://github.com/odinsride/olubalance/compare/v1.8.2...develop
[Unreleased]: https://github.com/odinsride/olubalance/compare/v1.8.3...develop
[v1.8.3]: https://github.com/odinsride/olubalance/compare/v1.8.2...v1.8.3
[v1.8.2]: https://github.com/odinsride/olubalance/compare/v1.8.1...v1.8.2
[v1.8.1]: https://github.com/odinsride/olubalance/compare/v1.8.0...v1.8.1
[v1.8.0]: https://github.com/odinsride/olubalance/compare/v1.7.3...v1.8.0
Expand Down
26 changes: 14 additions & 12 deletions Gemfile.lock
Expand Up @@ -68,7 +68,7 @@ GEM
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.2)
aws-eventstream (1.1.1)
aws-partitions (1.482.0)
aws-partitions (1.487.0)
aws-sdk-core (3.119.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.239.0)
Expand All @@ -92,8 +92,9 @@ GEM
debug_inspector (>= 0.0.1)
builder (3.2.4)
byebug (11.1.3)
cable_ready (4.4.6)
cable_ready (4.5.0)
rails (>= 5.2)
thread-local (>= 1.1.0)
capybara (3.35.3)
addressable
mini_mime (>= 0.1.3)
Expand Down Expand Up @@ -135,7 +136,7 @@ GEM
figaro (1.2.0)
thor (>= 0.14.0, < 2)
foreman (0.87.2)
globalid (0.5.1)
globalid (0.5.2)
activesupport (>= 5.0)
hiredis (0.6.3)
i18n (1.8.10)
Expand All @@ -154,7 +155,7 @@ GEM
listen (3.6.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.10.0)
loofah (2.12.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
Expand All @@ -164,10 +165,10 @@ GEM
mini_magick (4.11.0)
mini_mime (1.1.0)
minitest (5.14.4)
nio4r (2.5.7)
nokogiri (1.11.7-x86_64-darwin)
nio4r (2.5.8)
nokogiri (1.12.3-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.11.7-x86_64-linux)
nokogiri (1.12.3-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
pagy (3.10.0)
Expand Down Expand Up @@ -254,16 +255,16 @@ GEM
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.10.2)
rubocop (1.18.4)
rubocop (1.19.0)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.8.0, < 2.0)
rubocop-ast (>= 1.9.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.8.0)
rubocop-ast (1.10.0)
parser (>= 3.0.1.1)
rubocop-rails (2.11.3)
activesupport (>= 4.2.0)
Expand Down Expand Up @@ -299,13 +300,14 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
stimulus_reflex (3.4.0)
cable_ready (>= 4.4)
stimulus_reflex (3.4.1)
cable_ready (>= 4.5)
nokogiri
rack
rails (>= 5.2)
redis
thor (1.1.0)
thread-local (1.1.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (2.0.0)
Expand Down
32 changes: 17 additions & 15 deletions app/controllers/summary_controller.rb
@@ -1,25 +1,27 @@
class SummaryController < ApplicationController
before_action :authenticate_user!
before_action :collect_summary_info
skip_forgery_protection

def index
@accounts = current_user.accounts.where(active: true).order('created_at ASC')

@accounts_checking = @accounts.where(account_type: :checking)
@accounts_savings = @accounts.where(account_type: :savings)
@accounts_credit = @accounts.where(account_type: :credit)

@checking_total = @accounts_checking.sum(:current_balance)
@savings_total = @accounts_savings.sum(:current_balance)
end

@credit_total = @accounts_credit.sum(:current_balance)
@credit_limit_total = @accounts_credit.sum(:credit_limit)
@credit_utilization_total = ((@credit_total.abs / @credit_limit_total) * 100).round(2)
def send_mail
puts "send_mail params"
puts params
SummaryMailer.with(summary: @summary, current_user: current_user, to: params[:summary_mail][:to]).new_summary_email.deliver_now
end

@accounts_checking = @accounts_checking.decorate
@accounts_savings = @accounts_savings.decorate
@accounts_credit = @accounts_credit.decorate
@accounts = @accounts.decorate
private

# Get the summary object (defined in facade)
def collect_summary_info
accounts = current_user.accounts.where(active: true).order('created_at ASC').decorate
@summary = Summary.new(accounts)
end

def summary_params
params.require(:summary_mail) \
.permit(:to)
end
end
2 changes: 1 addition & 1 deletion app/decorators/account_decorator.rb
Expand Up @@ -49,7 +49,7 @@ def account_name_balance

# Display the descriptive last updated at date for the account
def updated_at_display
updated_at.in_time_zone(current_user.timezone).strftime('%b %d, %Y @ %I:%M %p %Z')
updated_at.in_time_zone(User.new.decorate.h.controller.current_user.timezone).strftime('%b %d, %Y @ %I:%M %p %Z')
end

# Simple check if the account balance is negative
Expand Down
6 changes: 3 additions & 3 deletions app/decorators/transaction_decorator.rb
Expand Up @@ -65,12 +65,12 @@ def trx_date_decorated
end

def trx_date_display
trx_date.in_time_zone(current_user.timezone).strftime('%m/%d/%Y')
trx_date.in_time_zone(User.new.decorate.h.controller.current_user.timezone).strftime('%m/%d/%Y')
end

def trx_date_formatted
# trx_date.in_time_zone(current_user.timezone).strftime('%m/%d/%Y')
trx_date.in_time_zone(current_user.timezone).strftime('%Y-%m-%d')
trx_date.in_time_zone(User.new.decorate.h.controller.current_user.timezone).strftime('%Y-%m-%d')
end

def trx_date_form_value
Expand All @@ -79,7 +79,7 @@ def trx_date_form_value
end

def created_at_decorated
created_at.in_time_zone(current_user.timezone).strftime('%b %d, %Y @ %I:%M %p %Z')
created_at.in_time_zone(User.new.decorate.h.controller.current_user.timezone).strftime('%b %d, %Y @ %I:%M %p %Z')
end

def name_too_long
Expand Down
41 changes: 41 additions & 0 deletions app/facades/summary.rb
@@ -0,0 +1,41 @@
class Summary
def initialize(accounts)
@accounts = accounts
end

def accounts_checking
@accounts.where(account_type: :checking)
end

def accounts_savings
@accounts.where(account_type: :savings)
end

def accounts_credit
@accounts.where(account_type: :credit)
end

def checking_total
accounts_checking.sum(&:current_balance)
end

def savings_total
accounts_savings.sum(&:current_balance)
end

def credit_total
accounts_credit.sum(&:current_balance)
end

def credit_limit_total
accounts_credit.sum(&:credit_limit)
end

def credit_utilization_total
if credit_limit_total.positive?
((credit_total.abs / credit_limit_total) * 100).round(2)
else
0
end
end
end
11 changes: 11 additions & 0 deletions app/mailers/summary_mailer.rb
@@ -0,0 +1,11 @@
class SummaryMailer < ApplicationMailer
def new_summary_email
@summary = params[:summary]
@current_user = params[:current_user]
mail(to: params[:to], subject: "olubalance " + Time.now.strftime("%m/%d/%Y"))
end

def current_user
@current_user
end
end
2 changes: 1 addition & 1 deletion app/models/transaction.rb
Expand Up @@ -30,7 +30,7 @@ class Transaction < ApplicationRecord

scope :with_balance, -> { includes(:transaction_balance).references(:transaction_balance) }
scope :desc, -> { order('pending DESC, trx_date DESC, id DESC') }
scope :current_day, -> { where('created_at > ?', 18.hours.ago) }
scope :recent, -> { where('created_at > ?', 3.days.ago) }
scope :pending, -> { where(pending: true) }

scope :search, lambda { |query|
Expand Down

0 comments on commit dfe1529

Please sign in to comment.