Skip to content

Commit

Permalink
add account attributes and overdraft
Browse files Browse the repository at this point in the history
  • Loading branch information
ishmael committed Nov 23, 2010
1 parent a727ad8 commit 4f5da39
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 18 deletions.
3 changes: 3 additions & 0 deletions app/controllers/bankaccounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def show
# GET /bankaccounts/new.xml
def new
@bankaccount = Bankaccount.new
#overdraft = @bankaccount.account_attributes.build
#overdraft.attribute_type = 0

#@bankaccount.user_id = @current_user.id
add_breadcrumb I18n.t('layout.bankaccounts.newaccount'),new_bankaccount_path
respond_to do |format|
Expand Down
4 changes: 4 additions & 0 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ class Account < ActiveRecord::Base
has_many :users , :through => :accounts_users
has_many :movements, :dependent => :destroy
has_many :shared_account_invitations, :dependent => :destroy
has_many :account_attributes, :dependent => :destroy
accepts_nested_attributes_for :account_attributes
validates_presence_of :name, :number,:bank
money :balance, :currency => :currency,:precision => 2
money :overdraft, :currency => :currency,:precision => 2


def self.find_accounts_with_balance(*args)
with_scope(:find => {:select => "accounts.*, accounts_users.allow_insert,accounts_users.allow_edit,accounts_users.allow_delete,accounts_users.owner",:order => "accounts.name asc"}) do
Expand Down
3 changes: 3 additions & 0 deletions app/models/account_attribute.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class AccountAttribute < ActiveRecord::Base
belongs_to :account
end
10 changes: 6 additions & 4 deletions app/views/bankaccounts/_form.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
<dd><%= form.text_field :number , :class => 'txt'%></dd>
<dt><%= form.label :bank,I18n.t('layout.bankaccounts.accountbank') %></dt>
<dd><%= form.text_field :bank , :class => 'txt'%></dd>
<% if @bankaccount.new_record? %>
<dt><%= form.label :balance,I18n.t('layout.bankaccounts.accountbalance') %></dt>
<dd><%= form.text_field :balance , :class => 'txt'%></dd>
<% end %>
<dt><%= form.label :locale,I18n.t('layout.application.currency') %></dt>
<dd><div id="currency_container"></div><%= form.select(:currency, [['Euro', 'EUR'], ['Dollar', 'USD'], ['Pound', 'GBP']] ,{},{:id => "account_currency"} )%></dd>
<dt><%= form.label :color,I18n.t('layout.application.color') %></dt>
<dd><%= form.hidden_field :color ,:id => "color_value"%> <div id="color_container"></div></dd>
<% if @bankaccount.new_record? %>
<dt><%= form.label :balance,I18n.t('layout.bankaccounts.accountbalance') %></dt>
<dd><%= form.text_field :balance , :class => 'txt'%></dd>
<% end %>
<dt><%= form.label :overdraft,I18n.t('layout.bankaccounts.overdraft') %></dt>
<dd><%= form.text_field :overdraft , :class => 'txt'%></dd>
4 changes: 2 additions & 2 deletions app/views/bankaccounts/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="box box-first box-50 altbox">
<% form_for(@bankaccount ,:html =>{:class => 'basic'}) do |f| %>
<% form_for(@bankaccount ,:html =>{:class => 'basic'}) do |f| %>
<div class="header cr-top">
<h3><%= I18n.t('layout.bankaccounts.name') %></h3>
<%= f.submit I18n.t('layout.application.update'),:class => 'phosney-button phosney-header-button' %>
Expand All @@ -12,5 +12,5 @@
</div>

</div>
<% end %>
<% end %>
</div>
2 changes: 1 addition & 1 deletion app/views/movements/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</div>
<% end %>
</div>
<div class="box box-50 cr-all box-last"><!-- .altbox for alternative box's color -->
<div class="box box-50 cr-all box-last map_show">
<div class="header cr-top">
<h3><%= I18n.t('layout.movements.map') %></h3>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/movements/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
<% end %>
</div>
<div class="box box-50 cr-all box-last">
<div class="box box-50 cr-all box-last map_show">
<div class="header cr-top">
<h3><%= I18n.t('layout.movements.map') %></h3>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/movements/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</div>
</div>
<% if (not @movement.lng.blank?) and (not @movement.lat.blank?) %>
<div class="box box-50 cr-all box-last">
<div class="box box-50 cr-all box-last map_show">
<div class="header cr-top">
<h3><%= I18n.t('layout.movements.map') %></h3>
</div>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ en:
total: "Total"
notice_message: "The account with the name <strong>%s</strong>, number <strong>%s</strong> from <strong>%s</strong> was sucessfully saved."
delete_message: "The account with the name <strong>%s</strong>, number <strong>%s</strong> from <strong>%s</strong> was sucessfully deleted."
overdraft: "Overdraft amount"
loanaccounts:
name: "Loans"
title: "Loan"
Expand Down
1 change: 1 addition & 0 deletions config/locales/pt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pt:
total: "Total"
notice_message: "A conta bancária <strong>%s</strong> com o número <strong>%s</strong> do banco <strong>%s</strong> foi gravada com sucesso."
delete_message: "A conta bancária <strong>%s</strong> foi apagada com sucesso."
overdraft: "Valor a descoberto permitido"
loanaccounts:
name: "Empréstimos"
title: "Empréstimo"
Expand Down
19 changes: 19 additions & 0 deletions db/migrate/20101111224638_create_account_attributes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class CreateAccountAttributes < ActiveRecord::Migration
class AccountAttribute < ActiveRecord::Base
end

def self.up
create_table :account_attributes do |t|
t.integer :account_id,:null => false
t.integer :attribute_type, :null => false
t.string :value, :null => false
t.timestamps
end
execute "ALTER TABLE account_attributes ADD CONSTRAINT account_attributes_account_id_fkey FOREIGN KEY (account_id) REFERENCES accounts (id);"
end

def self.down
execute "ALTER TABLE account_attributes DROP CONSTRAINT account_attributes_account_id_fkey;"
drop_table :account_attributes
end
end
10 changes: 10 additions & 0 deletions db/migrate/20101123104749_add_overdraft_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class AddOverdraftAccount < ActiveRecord::Migration
def self.up
add_column :accounts, :overdraft_in_cents, :integer, :default => 0
Account.update_all("overdraft_in_cents = 0")
end

def self.down
remove_column :accounts, :overdraft_in_cents
end
end
23 changes: 14 additions & 9 deletions public/stylesheets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ body{
/*background:none repeat scroll 0 0 #DDDD00;*/
background:url("/images/background.gif") ;
padding-bottom:10px;
font: 75%/1.5 "myriad pro", helvetica, arial, sans-serif;
font: 75%/1.5 "myriad pro", helvetica, arial, sans-serif !important;
}

.left{ float:left; }
Expand Down Expand Up @@ -122,11 +122,16 @@ STRUCTURE */
border-bottom-style:none;
width: 400px;
}
/*
#map_show {
margin:0px;

.map_show {
vertical-align:top;

}

.map_show div.basic {
padding-bottom:5px ;
}
*

/*
CORNERS
* -moz-border-radius-topleft / -webkit-border-top-left-radius
Expand Down Expand Up @@ -352,7 +357,7 @@ a.yuimenuitemlabel {
.box .yui-navset .yui-nav {
border-bottom:0 none !important;

margin-top:4px;
margin-top:2px;
margin-right:5px;
float:right;
}
Expand Down Expand Up @@ -383,12 +388,12 @@ a.yuimenuitemlabel {
border-radius: 5px;
border: 1px solid;
margin: 10px auto 0 auto;
padding: 8px 10px 0 10px;
padding: 4px 10px 4px 10px;
width:980px;
}
.msg p {margin: 0 0 8px 0; padding-left: 25px;}
.msg p {margin: 0; padding-left: 25px;}
.msg p strong {font-weight:bold;}
.msg div {margin: 0 0 8px 0; padding-left: 25px;}
.msg div {margin: 0 ; padding-left: 25px;}
.msg-breadcrumb {
background:url("http://yui.yahooapis.com/2.8.0r4/build/assets/skins/sam/sprite.png") repeat-x scroll 0 0 transparent;
border:0 !important;
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/account_attributes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

# one:
# column: value
#
# two:
# column: value
8 changes: 8 additions & 0 deletions test/unit/account_attribute_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'test_helper'

class AccountAttributeTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end

0 comments on commit 4f5da39

Please sign in to comment.