-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/creating budgets #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
elherzt
wants to merge
59
commits into
framallo:develop
Choose a base branch
from
elherzt:feature/creating-budgets
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
3188678
created budgets controller
elherzt e89751b
created budgeted scope for categories
elherzt 9e268eb
ignored database
elherzt 9cc502a
added link to budgets without correct url for now
elherzt df02d6d
created view with real data but without filters
elherzt 1a28679
added filter to splits active
elherzt 51f0582
deleted unnecesary variable
elherzt 7cee04a
moved class interval to a file into lib directory
elherzt 99ba96e
moved filter class to lib folder
elherzt 20128c2
required filter class in split model
elherzt 1f1a4ae
deleted code comented
elherzt 3968764
added filters to budgets view
elherzt 3535b0b
added intervals to budgets, only per month
elherzt 7711d67
change view of budgets
elherzt fe184c6
added name of the month in the view
elherzt e8f004b
added task to get category_id in transactions
elherzt ec80a03
refactored code in order to the change in transactions table
elherzt 65a853c
removed unnecesary code
elherzt 5883c87
added spent at table
elherzt 2d79a61
changed instance of filter
elherzt 2aefad4
removed commented code
elherzt 280227d
added period to budgets
elherzt f05188c
removed unnecesary code
elherzt d09b29d
fixed problem with dates
elherzt f583f87
refacored code
elherzt 431c977
changed interval to las day of month
elherzt 40e6778
added income and expenses budgets, also total values of budget
elherzt 311f561
refactored code
elherzt 222b9f4
fix error in the view
elherzt 729ab43
refactored code
elherzt 1c02e6d
added sql view budget_categories
elherzt e6eabbd
deleted budgets_helper
elherzt d967650
changed routes for budgets
elherzt e3dba8c
add BudgetCategory model into Category model
elherzt 495935b
removed views to budgets
elherzt 4f15800
added views to categories
elherzt 5a72a5a
deleted unnnecesary budgets controller
elherzt d6e85f3
added categories helper
elherzt ba6e407
added categories controller
elherzt 4036602
deleted duplicated code
elherzt 97fc795
fecator code
elherzt 67010b0
moved categories to pocketmoney namespce
elherzt 087af2d
deleted budgets table
elherzt b42f566
change route to categories.rb
elherzt 1be1df8
moved filter class
elherzt f7d44bc
renamed style file to budgets
elherzt e1c23ca
moved set_period method at application helper
elherzt 9ac4a78
deleted unnecesary code
elherzt 81a4ff0
deleted unnecesary code
elherzt eacb6fd
added draper gem
elherzt 9166583
generated decorator for categories
elherzt 856cf64
added collection decorated
elherzt fa98af4
created new partial to intervals
elherzt 0bcf160
added identation to sql view
elherzt a5b6475
decorated collection to budgets categories
elherzt da4550e
decorator to budgets category
elherzt 6aaa93b
removed code from categories_helper
elherzt e174d65
change code in views in order to use new decorator
elherzt 01f2e68
fix double substraction
elherzt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
|
|
||
| config/database.yml | ||
| config/config.yml | ||
| PocketMoneyDB.sql | ||
|
|
||
|
|
||
| **/.DS_Store | ||
This file contains hidden or 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 hidden or 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 hidden or 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,2 @@ | ||
| .budget | ||
| width: 700px |
This file contains hidden or 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,6 @@ | ||
| class CategoriesController < ApplicationController | ||
| def budgets | ||
| @budgets = BudgetCategoriesDecorator.new(Category::BudgetCategory.all) | ||
| @filter = Category.filter(params) | ||
| end | ||
| end | ||
This file contains hidden or 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,3 @@ | ||
| class BudgetCategoriesDecorator < Draper::Decorator | ||
| delegate_all | ||
| end |
This file contains hidden or 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,40 @@ | ||
| class BudgetCategoryDecorator < Draper::Decorator | ||
| delegate_all | ||
|
|
||
| def dates_intervals(from, to) | ||
| @@from = from | ||
| @@to = to+1 | ||
| end | ||
|
|
||
| def amount | ||
| amount = Category::BudgetCategory.interval(@@from, @@to) | ||
| amount = amount.sum_category(model.id) | ||
| amount < 0 ? amount*-1 : amount | ||
| end | ||
|
|
||
| def limit | ||
| (model.amount_day * ((@@to - @@from).to_i+1)).round(0) | ||
| end | ||
|
|
||
| def balance | ||
| (limit - amount).round(0) | ||
| end | ||
|
|
||
| def available | ||
| balance < 0 ? 0 : balance | ||
| end | ||
|
|
||
| def color | ||
| balance < 0 ? "danger" : "warning" | ||
| end | ||
|
|
||
| def spent_percentage | ||
| percentage = (amount * 100) / limit | ||
| percentage < 100 ? percentage : 100 | ||
| end | ||
|
|
||
| def available_percentage | ||
| 100 - spent_percentage | ||
| end | ||
|
|
||
| end |
This file contains hidden or 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 hidden or 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,7 @@ | ||
| module CategoriesHelper | ||
|
|
||
| def total_budget | ||
| Category::BudgetCategory.total_values(@filter.from, @filter.to+1.day) | ||
| end | ||
|
|
||
| end |
This file contains hidden or 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,8 +1,83 @@ | ||
| class Category < ActiveRecord::Base | ||
| include FilterInterval | ||
| class BudgetCategory < ActiveRecord::Base | ||
| self.table_name = "budget_categories" | ||
| self.primary_key = "id" | ||
| belongs_to :category, foreign_key: "id" | ||
| scope :incomes, -> { budgets.where(budget_type: 1)} | ||
| scope :expenses, -> { budgets.where(budget_type: 0)} | ||
| scope :sum_incomes, -> { where(budget_type: 1).sum(:amount) } | ||
| scope :sum_expenses, -> { where(budget_type: 0).sum(:amount) } | ||
| scope :interval, ->(from, to) { where("budget_categories.date >= ? AND budget_categories.date <= ?", from, to) } | ||
| scope :budgets, -> {select("id, amount_day, budget_type, name").order("name").uniq} | ||
| scope :sum_category, ->(id) { where(id: id).sum(:amount) } | ||
|
|
||
| def self.total_values(from, to) | ||
| @@days = (to - from).to_i | ||
| @@interval = interval(from, to) | ||
| @@spent = total_spent * -1 | ||
| @@entries = total_entries | ||
| Hash['saved', saved, 'beat', beat_budget, 'missing', missing_budget, 'deficit', deficit ] | ||
| end | ||
|
|
||
| private | ||
| def self.total_spent | ||
| @@interval.sum_expenses | ||
| end | ||
|
|
||
| def self.total_entries | ||
| @@interval.sum_incomes | ||
| end | ||
|
|
||
| def self.saved | ||
| @@entries > @@spent ? @@entries - @@spent : 0 | ||
| end | ||
|
|
||
| def self.beat_budget | ||
| value = income_vs_expense | ||
| value > 0 ? value : 0 | ||
| end | ||
|
|
||
| def self.missing_budget | ||
| value = income_vs_expense | ||
| value < 0 ? value : 0 | ||
| end | ||
|
|
||
| def self.deficit | ||
| @@entries - @@spent > 0 ? 0 : @@entries - @@spent | ||
| end | ||
|
|
||
| def self.income_vs_expense | ||
| incomes = @@entries - budget_entries | ||
| expenses = budget_expenses - @@spent | ||
| incomes + expenses | ||
| end | ||
|
|
||
| def self.budget_entries | ||
| ((incomes.map(&:amount_day).sum) * @@days).round(0) | ||
| end | ||
|
|
||
| def self.budget_expenses | ||
| ((expenses.map(&:amount_day).sum) * @@days).round(0) | ||
| end | ||
| end | ||
|
|
||
| ## Budget period | ||
| # 0 diario | ||
| # 1 Semanal | ||
| # 2 Mensual | ||
| # 3 Cuatrimestral | ||
| # 4 Anual | ||
| scope :active, -> { where(deleted:false) } | ||
| scope :transaction_ids, ->(ids) { joins(:splits => :transaction).where(transactions: {id: ids}) } | ||
| scope :transaction_totals, -> { joins(:splits => :transaction).merge(Transaction.total_amount) } | ||
| scope :group_by_name, -> { select('categories.name', 'categories.id').group('categories.name', 'categories.id') } | ||
|
|
||
| has_many :splits | ||
| has_one :budget_category, foreign_key: "id" | ||
|
|
||
| def self.filter(params) | ||
| Filter.new(params) | ||
| end | ||
|
|
||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this controller for?