Skip to content

Commit

Permalink
Merge branch 'master' of github.com:dodo-as/dodo
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikola Trandafilovic committed Nov 11, 2011
2 parents 1b7fb16 + 2970a98 commit 58869ed
Show file tree
Hide file tree
Showing 31 changed files with 530 additions and 238 deletions.
25 changes: 16 additions & 9 deletions app/controllers/admin/counties_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class Admin::CountiesController < Admin::BaseController
# GET /counties.xml
def index
@counties = County.where(:is_visible => true)

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @counties }
Expand All @@ -18,7 +17,10 @@ def index
# GET /counties/1.xml
def show
@county = County.find(params[:id])

@county_tax_zone = CountyTaxZone.where(:county_id => @county.id)[0]
unless @county_tax_zone.nil?
@tax_zone = @county_tax_zone.tax_zone
end
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @county }
Expand All @@ -29,7 +31,6 @@ def show
# GET /counties/new.xml
def new
@county = County.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @county }
Expand All @@ -39,13 +40,20 @@ def new
# GET /counties/1/edit
def edit
@county = County.find(params[:id])
@county_tax_zone = CountyTaxZone.where(:county_id => @county.id)[0]
unless @county_tax_zone.nil?
@from = @county_tax_zone.from
@tax_zone = @county_tax_zone.tax_zone
unless @tax_zone.nil?
@number = @tax_zone.number
end
end
end

# POST /counties
# POST /counties.xml
def create
@county = County.new(params[:county])

respond_to do |format|
if @county.save
format.html { redirect_to([:admin, @county], :notice => 'County was successfully created.') }
Expand All @@ -60,10 +68,10 @@ def create
# PUT /counties/1
# PUT /counties/1.xml
def update
@county = County.find(params[:id])

@county = County.find(params[:id])
county_tax_zone = CountyTaxZone.where(:county_id => @county.id)[0]
respond_to do |format|
if @county.update_attributes(params[:county])
if county_tax_zone.update_attributes(params[:county]["county_tax_zone"]) and county_tax_zone.update_attributes(params[:county]["tax_zone"])
format.html { redirect_to([:admin, @county], :notice => 'County was successfully updated.') }
format.xml { head :ok }
else
Expand All @@ -78,8 +86,7 @@ def update
def destroy
@county = County.find(params[:id])
@county.is_visible = false
state = @county.save
puts "woops", @county, @county.is_visible, state
state = @county.save
respond_to do |format|
format.html { redirect_to(admin_counties_url) }
format.xml { head :ok }
Expand Down
12 changes: 11 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

class ApplicationController < ActionController::Base
before_filter :set_locale_now, :authenticate_user!, :init_auth
before_filter :deactivated, :except => [:sign_out]
before_filter :company_required, :if => proc { current_user }

helper :all # include all helpers, all the time

attr_accessor :me
Expand All @@ -20,11 +20,21 @@ class ApplicationController < ActionController::Base
# filter_parameter_logging :password

protected




def set_locale_now
I18n.locale = session[:locale] = params[:locale] || session[:locale] || I18n.default_locale
end


def deactivated
if self.class != Devise::SessionsController && current_user && !current_user.active
return redirect_to destroy_user_session_path
end
end

def init_auth
company_id = session[:company_id]
Authorization.current_user = current_user
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/assignments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
class AssignmentsController < ApplicationController

attr_accessor :assignment
around_filter Log.log(:assignment), :only => [:update, :create]

def new
@assignment = Assignment.new
@other_info = {:comp => nil, :num => nil}
Expand Down
74 changes: 49 additions & 25 deletions app/controllers/journals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def show
# GET /journals/new.xml
def new
@journal = Journal.new :journal_type_id => params[:journal_type_id]
@append = false
if !@journal.journal_type
raise "No journal type specified"
end
Expand All @@ -50,6 +51,7 @@ def new

# GET /journals/1/edit
def edit
@append = @journal.period.append_only?
end

# POST /journals
Expand All @@ -64,10 +66,14 @@ def create
@journal.company = @me.current_company
params[:journal_operations].each do
|key, value|
value.delete(:old)
op = JournalOperation.new(value)
op.company = @me.current_company
@journal.journal_operations.push op
if op.amount != 0.0 && op.amount != nil
op.company = @me.current_company
@journal.journal_operations.push op
end
end

@journal.save!

cnt = @journal.journal_type.counter(@me.current_company)
Expand All @@ -93,34 +99,52 @@ def update
respond_to do |format|
Journal.transaction do
begin
append = @journal.period.append_only?

@journal.journal_operations.each do
|op|
if op.closed_operation then
op.closed_operation.journal_operations.each do
|op2|
op2.closed_operation = nil
op2.save
if append
params[:journal_operations].each do
|key, value|
if !value[:old]
op = JournalOperation.new(value)
if op.amount != 0.0 && op.amount != nil
op.company = @me.current_company
@journal.journal_operations.push op
end
end
end
@journal.save!
else
@journal.journal_operations.each do
|op|
if op.closed_operation then
op.closed_operation.journal_operations.each do
|op2|
op2.closed_operation = nil
op2.save
end
end
end
end

@journal.update_attributes(params[:journal]) or raise ActiveRecord::Rollback
@journal.journal_operations.clear
params[:journal_operations].each do
|key, value|
op = JournalOperation.new(value)
op.company = @me.current_company
@journal.journal_operations.push op
end
@journal.save!

@journal.update_attributes(params[:journal]) or raise ActiveRecord::Rollback
@journal.journal_operations.clear
params[:journal_operations].each do
|key, value|
value.delete(:old)
op = JournalOperation.new(value)
if op.amount != 0.0 && op.amount != nil
op.company = @me.current_company
@journal.journal_operations.push op
end
end
@journal.save!

cnt = @journal.journal_type.counter(@me.current_company)
if cnt.adjust_outside_of_sequence
cnt.counter = @journal.number+1
cnt.save
cnt = @journal.journal_type.counter(@me.current_company)
if cnt.adjust_outside_of_sequence
cnt.counter = @journal.number+1
cnt.save
end
end

flash[:notice] = 'Journal was successfully updated.'
format.html { redirect_to(@journal) }
format.xml { head :ok }
Expand Down
15 changes: 11 additions & 4 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,26 +167,30 @@ def ledger_balance
end

def ledger_journal

accounts = nil
periods = nil
journal_operations = nil
params[:offset] ||= 0

@journal_operations = []
@count = 0;
where = nil
#if specified accounts range is taken between from_account_number and to_account_number
if !params[:from_account_number].blank? && !params[:to_account_number].blank?
where = ["number BETWEEN ? AND ?", params[:from_account_number], params[:to_account_number]]
elsif !params[:from_account_number].blank?
#from_account specified but not to_account
where = ["number >= ?", params[:from_account_number]]
elsif !params[:to_account_number].blank?
#to_account specified but not from_account
where = ["number <= ?", params[:to_account_number]]
end

if where.nil?
#if no accounts specified
where = ["is_result_account = ?"]
else
else
#if one of the accounts at least is specified
where[0] += " AND is_result_account = ?"
end
where << false
Expand Down Expand Up @@ -236,6 +240,9 @@ def ledger_journal
where[0] += " AND unit_id = ?"
where << params[:unit_id]
end
unless params[:car_id].blank?
where[0] += " AND car_id = ?"
end

@journal_operations = JournalOperation.joins(:journal).joins(:account).where(where).order(
"account_id, journals.period_id, journal_operations.created_at").includes(
Expand Down
13 changes: 5 additions & 8 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
class UsersController < ApplicationController

filter_resource_access


attr_accessor :user
around_filter Log.log(:user), :only => [:update, :create]
def new
@user = User.new
@user = User.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @journal }
end
end
end

def create
Expand Down Expand Up @@ -43,8 +45,6 @@ def index
end

def update
@user = User.find(params[:id])

respond_to do |format|
# don't update password if blank
if params[:user][:password].blank?
Expand All @@ -63,16 +63,13 @@ def update
end

def show
@user = User.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @user }
end
end

def edit
@user = User.find(params[:id])
3.times { @user.assignments.build }
end
end
2 changes: 2 additions & 0 deletions app/models/county.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class County < ActiveRecord::Base
has_many :county_tax_zones
accepts_nested_attributes_for :county_tax_zones, :allow_destroy => false
validates_presence_of :name, :allow_nil => false
end
1 change: 1 addition & 0 deletions app/models/county_tax_zone.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class CountyTaxZone < ActiveRecord::Base
belongs_to :county
belongs_to :tax_zone
end
4 changes: 2 additions & 2 deletions app/models/journal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def self.report_ledger_balance(periods_to_balance, periods_to_balance_previous,
inner join journal_operations on journals.id = journal_operations.journal_id
inner join accounts on journal_operations.account_id = accounts.id
where journals.company_id = #{company.id}
and periods.id in (#{_periods_to_balance})
and periods.id in (#{_periods_to_balance})
and accounts.is_result_account = false"
unless unit.blank?
sql += " and journal_operations.unit_id = #{unit.id}"
Expand All @@ -98,7 +98,7 @@ def self.report_ledger_balance(periods_to_balance, periods_to_balance_previous,
inner join journal_operations on journals.id = journal_operations.journal_id
inner join accounts on journal_operations.account_id = accounts.id
where journals.company_id = #{company.id}
and periods.id in (#{_periods_to_balance_last})
and periods.id in (#{_periods_to_balance_last})
and accounts.is_result_account = false"
unless unit.blank?
sql += " and journal_operations.unit_id = #{unit.id}"
Expand Down
4 changes: 4 additions & 0 deletions app/models/period.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def elevate_status
end
self.status += 1
end

def append_only?
return self.status == STATUSE_NAMES['Locked']
end

def to_s
sprintf("%d %.2d", self.year, self.nr)
Expand Down
2 changes: 2 additions & 0 deletions app/models/tax_zone.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class TaxZone < ActiveRecord::Base
has_many :tax_zone_taxes
has_many :county_tax_zones
accepts_nested_attributes_for :county_tax_zones, :allow_destroy => false
end
1 change: 0 additions & 1 deletion app/models/tax_zone_tax.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
class TaxZoneTax < ActiveRecord::Base
belongs_to :tax_zone

end
8 changes: 7 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ class User < ActiveRecord::Base
has_many :assignments, :include => [:company, :role], :order => "companies.name"
accepts_nested_attributes_for :assignments, :allow_destroy => true,
:reject_if => proc { |attrs| attrs["company_id"].blank? || attrs["role_id"].blank? }


def log_include
[:assignments]
end

# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable, :timeoutable and :activatable, :registerable
devise :database_authenticatable, :recoverable, :rememberable,
Expand All @@ -33,7 +38,8 @@ def role_symbols
end

def open_periods(company = self.current_company)
Period.where(:company_id => company.id, :status => Period::STATUSE_NAMES['Open'])

Period.where(:company_id => company.id, :status => [1,2,3])
end

# declarative_auth wants a login attribute for the introspection ui
Expand Down
Loading

0 comments on commit 58869ed

Please sign in to comment.