Skip to content

Commit

Permalink
Added counties form for ledgers
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikola Trandafilovic committed Nov 22, 2011
1 parent 900b39c commit 4113383
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 21 deletions.
26 changes: 26 additions & 0 deletions app/controllers/county_ledgers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class CountyLedgersController < ApplicationController
def new
@county_ledger = CountyLedger.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @county_ledger }
end
end

def create
@county_ledger = CountyLedger.new(params[:county_ledger])
respond_to do |format|

if @county_ledger.save!
format.html { redirect_to(ledger_path(@county_ledger.ledger)) }
format.xml { render :xml => @county_ledger} #, :status => :created, :location => @journal }
else
format.html { render :action => "new" }
format.xml { render :xml => @county_ledger.errors, :status => :unprocessable_entity }
end

end
end


end
21 changes: 12 additions & 9 deletions app/controllers/ledgers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def create
respond_to do |format|
if @ledger.save
format.json { render :json => @ledger.to_json(:include => {:unit => {}, :project => {} }) }
format.html { redirect_to @ledger.account, :notice => "Ledger created" }
format.html { redirect_to @ledger, :notice => "Ledger created" }
format.xml { head :ok }
else

Expand All @@ -62,7 +62,7 @@ def update
def new
@account = Account.find(params[:account_id])
@ledger = Ledger.new(:account => @account)
@ledger.county_ledgers.build
#~ @ledger.county_ledgers.build
# @ledger.address = Address.new
respond_to do |format|
#~ format.html { render :partial => "accounts/ledger_form", :locals => {:account => @account, :ledger => @ledger} }
Expand All @@ -73,14 +73,17 @@ def new

def show
respond_to do |format|
format.json { render :json => @ledger.to_json(:include => [:account,
:address,
:unit,
:project]
)
}
#~ format.json { render :json => @ledger.to_json(:include => [:account,
#~ :address,
#~ :unit,
#~ :project]
#~ )
#~ }
@account = @ledger.account
format.html { render :partial => "form", :locals => {:account => @account, :ledger => @ledger} }
#~ format.html { render :partial => "form", :locals => {:account => @account, :ledger => @ledger} }
format.html
format.xml { render :xml => @ledger, :status => :created, :location => @ledger }

end
end

Expand Down
2 changes: 2 additions & 0 deletions app/helpers/county_ledger_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CountyLedgerHelper
end
12 changes: 11 additions & 1 deletion app/models/ledger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Ledger < ActiveRecord::Base
belongs_to :address, :dependent => :destroy
has_many :paycheck_line_templates , :foreign_key => "employee_id"
has_many :county_ledgers
accepts_nested_attributes_for :county_ledgers, :allow_destroy => false
#~ accepts_nested_attributes_for :county_ledgers, :allow_destroy => false
validates :number, :uniqueness => {:scope => [:account_id]}, :presence => true

validates :name, :presence => true
Expand Down Expand Up @@ -44,5 +44,15 @@ def first_name
def last_name
self.name.split(' ',2)[1]
end


def county_at_date date
if !self.county_ledgers.blank?
self.county_ledgers.where('"from" <= ? ', date).first.county
else
[]
end
end


end
5 changes: 5 additions & 0 deletions app/views/accounts/_ledgers.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<h2><%= t(:ledger_accounts, :scope => :accounts) -%></h2>
<table id="ledger_table">
<tr>
<th></th>
<th><%= t(:number, :scope => :accounts) -%></th>
<th><%= t(:name, :scope => :accounts) -%></th>
<th><%= t(:id_number, :scope => :accounts) -%></th>
Expand All @@ -29,6 +30,10 @@

<% @account.ledgers.each do |ledger| %>
<tr class="ledger_item" id="ledger_id_<%= ledger.id %>">
<td>
<%=link_to t(:edit, :scope => :global), edit_ledger_path(ledger) %>
<%=link_to t(:show, :scope => :global), ledger_path(ledger) %>
</td>
<td><%= ledger.number -%></td>
<td><%= ledger.name -%></td>
<td><%= ledger.id_number -%></td>
Expand Down
36 changes: 36 additions & 0 deletions app/views/ledgers/_county_ledger_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<table>
<tr>
<th>t(:county, :scope => :counties</th>
<th>t(:from, :scope => :counties</th>
<th></th>
</tr>
<% if !@ledger.county_ledgers.blank? %>

<% @ledger.county_ledgers.order('"from" asc').each do |cl| %>
<tr>

<td> <%= cl.county.name %></td>
<td><%= cl.from %></td>
<td> </td><%= %>
<!--
link_to t(:destroy, :scope => :global), county_ledger_path, :confirm => 'Are you sure?', :method => :delete %></td>
-->
<% end %>
</tr>
<% end %>
<tr>
<%= form_for ([CountyLedger.new]) do |county_ledger| %>
<%= county_ledger.hidden_field :ledger_id, :value => @ledger.id %>
<td>
<%= county_ledger.select :county_id, County.all.collect {|p| [p.name, p.id]} %>
</td>
<td>
<%= county_ledger.text_field :from, :class=> :datepicker %>
</td>
<td>
<%= submit_tag t(:add_county, :scope => :conties ) %>
</td>

<% end %>
</tr>
</table>
13 changes: 2 additions & 11 deletions app/views/ledgers/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,6 @@
<%= f.text_field :work_stop, :class => :datepicker %>
</p>

<p>
<%= f.fields_for :county_ledgers do |county_ledger| %>

<%= county_ledger.label "county", t(:county, :scope => :accounts) -%>
<%= county_ledger.select :county_id, County.all.collect {|p| [p.name, p.id]} %>

<%= county_ledger.label :from %>
<%= county_ledger.text_field :from, :class=> :datepicker %>
<% end %>
</p>

<p>
<%= f.label :placement_top, t(:placement_top, :scope => :accounts) -%><br />
<%= f.check_box :placement_top %>
Expand Down Expand Up @@ -122,3 +111,5 @@
<%= submit_tag t(:add_ledger, :scope => :accounts) %>

<% end %>


36 changes: 36 additions & 0 deletions app/views/ledgers/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<h1><%= t(:showing_ledger, :scope => :ledgers) %> <%= @ledger %></h1>

<p>
<%= @ledger.number %>
</p>
<p>
<%= @ledger.name %>
</p>
<p>
<%= @ledger.account %>
</p>
<p>
<%= @ledger.email %>
</p>
<p>
<%= @ledger.address.street1 %>
</p>
<p>
<%= @ledger.mobile_number %>
</p>
<p>
<%= @ledger.customer_number %>
</p>
<p>
<%= @ledger.ledger_bank_number %>
</p>
<p>
</p>

<p>
<%= render :partial => "ledgers/county_ledger_form" %>
</p>


<%= link_to t(:edit, :scope => :global), edit_ledger_path(@ledger) %> |
<%= link_to t(:back, :scope => :global), edit_account_path(@ledger.account) %>
8 changes: 8 additions & 0 deletions test/functional/county_ledger_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'test_helper'

class CountyLedgerControllerTest < ActionController::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
4 changes: 4 additions & 0 deletions test/unit/helpers/county_ledger_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'test_helper'

class CountyLedgerHelperTest < ActionView::TestCase
end

0 comments on commit 4113383

Please sign in to comment.