Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
613 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.