Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Liljencrantz committed Nov 8, 2011
2 parents 4e71060 + 99583fe commit d7f6b04
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 104 deletions.
62 changes: 38 additions & 24 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
class ReportsController < ApplicationController

def index
@periods = Period.with_permissions_to(:index).order('year, nr')
@periods = Period.with_permissions_to(:index).order('year, nr').reverse
@units = Unit.with_permissions_to(:index)
@projects = Project.with_permissions_to(:index)
@cars = Car.with_permissions_to(:index)
@journal_types = JournalType.with_permissions_to(:index).order('name')
@accounts = Account.with_permissions_to(:index).order('number')
end
Expand All @@ -18,6 +19,7 @@ def ledger_balance

@unit = Unit.find(params[:unit_id]) unless params[:unit_id].blank?
@project = Project.find(params[:project_id]) unless params[:project_id].blank?
@car = Car.find(params[:car_id]) unless params[:car_id].blank?
@journal_type = JournalType.find(params[:journal_type_id]) unless params[:journal_type_id].blank?

@show_only_active_accounts = params[:show_only_active_accounts]
Expand Down Expand Up @@ -116,28 +118,40 @@ def ledger_balance
@last_period_to_result_last = periods_to_result_last.last
end

puts "========== periods to balance "
periods_to_balance.each do |p|
puts "year " + p.year.to_s
puts "nr " + p.nr.to_s
end
puts "========== periods to balance previous "
periods_to_balance_previous.each do |p|
puts "year " + p.year.to_s
puts "nr " + p.nr.to_s
end

puts "========== periods to balance last "
periods_to_balance_last.each do |p|
puts "year " + p.year.to_s
puts "nr " + p.nr.to_s
end

puts "========== periods to balance last previous"
periods_to_balance_last_previous.each do |p|
puts "year " + p.year.to_s
puts "nr " + p.nr.to_s
end
# puts "========== periods to balance "
# periods_to_balance.each do |p|
# puts "year " + p.year.to_s
# puts "nr " + p.nr.to_s
# end
# puts "========== periods to balance previous "
# periods_to_balance_previous.each do |p|
# puts "year " + p.year.to_s
# puts "nr " + p.nr.to_s
# end
#
# puts "========== periods to balance last "
# periods_to_balance_last.each do |p|
# puts "year " + p.year.to_s
# puts "nr " + p.nr.to_s
# end
#
# puts "========== periods to balance last previous"
# periods_to_balance_last_previous.each do |p|
# puts "year " + p.year.to_s
# puts "nr " + p.nr.to_s
# end
#
# puts "========== periods to result"
# periods_to_result.each do |p|
# puts "year " + p.year.to_s
# puts "nr " + p.nr.to_s
# end
#
# puts "========== periods to result last"
# periods_to_result_last.each do |p|
# puts "year " + p.year.to_s
# puts "nr " + p.nr.to_s
# end

@balance, @total_balance, @result, @total_result =
Journal.report_ledger_balance(periods_to_balance,
Expand All @@ -147,7 +161,7 @@ def ledger_balance
periods_to_result,
periods_to_result_last,
current_user.current_company,
@unit, @project, @show_last_period,
@unit, @project,@car,
@show_only_active_accounts)

end
Expand Down
96 changes: 63 additions & 33 deletions app/models/journal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ def to_s
end

def open?
return (not self.closed)
return (not self.closed)
end

def editable?
return (self.period.open? and self.open? and self.bill_id.nil?)
end

def self.report_ledger_balance(periods_to_balance, periods_to_balance_previous,
periods_to_balance_last, periods_to_balance_last_previous,
periods_to_result, periods_to_result_last,
company, unit, project, show_last_period, show_only_active_accounts)
periods_to_balance_last, periods_to_balance_last_previous,
periods_to_result, periods_to_result_last,
company, unit, project,car, show_only_active_accounts)

#preparing periods to string fromat for sql query.
unless periods_to_balance.blank?
_periods_to_balance = periods_to_balance.collect { |p| p.id }.join(",")
end
Expand All @@ -40,12 +41,15 @@ def self.report_ledger_balance(periods_to_balance, periods_to_balance_previous,
end

unless periods_to_result.blank?
_periods_to_result = periods_to_result.collect { |p| p.id }.join(",")
_periods_to_result = periods_to_result.collect { |p| p.id }.join(",")
end
unless periods_to_result_last.blank?
_periods_to_result_last = periods_to_result_last.collect { |p| p.id }.join(",")
_periods_to_result_last = periods_to_result_last.collect { |p| p.id }.join(",")
end

###############################
##### calculating balance #####
###############################
sql = "select id as account_id,
max(account_number) as account_number,
max(account_name) as account_name,
Expand All @@ -70,13 +74,16 @@ def self.report_ledger_balance(periods_to_balance, periods_to_balance_previous,
where journals.company_id = #{company.id}
and periods.id in (#{_periods_to_balance})
and accounts.is_result_account = false"
unless unit.blank?
sql += " and journal_operations.unit_id = #{unit.id}"
end
unless project.blank?
sql += " and journal_operations.project_id = #{project.id}"
end
sql +=" group by accounts.id "
unless unit.blank?
sql += " and journal_operations.unit_id = #{unit.id}"
end
unless project.blank?
sql += " and journal_operations.project_id = #{project.id}"
end
unless car.blank?
sql += " and journal_operations.car_id = #{car.id}"
end
sql +=" group by accounts.id "
end
unless _periods_to_balance_last.blank?
sql += " -- last period, account balance
Expand All @@ -98,7 +105,10 @@ def self.report_ledger_balance(periods_to_balance, periods_to_balance_previous,
end
unless project.blank?
sql += " and journal_operations.project_id = #{project.id}"
end
end
unless car.blank?
sql += " and journal_operations.car_id = #{car.id}"
end
sql +=" group by accounts.id "
end
unless _periods_to_balance_previous.blank?
Expand All @@ -121,7 +131,10 @@ def self.report_ledger_balance(periods_to_balance, periods_to_balance_previous,
end
unless project.blank?
sql += " and journal_operations.project_id = #{project.id}"
end
end
unless car.blank?
sql += " and journal_operations.car_id = #{car.id}"
end
sql +=" group by accounts.id "
end
unless _periods_to_balance_last_previous.blank?
Expand All @@ -144,7 +157,10 @@ def self.report_ledger_balance(periods_to_balance, periods_to_balance_previous,
end
unless project.blank?
sql += " and journal_operations.project_id = #{project.id}"
end
end
unless car.blank?
sql+= " and journal_operations.car_id = #{car.id}"
end
sql +=" group by accounts.id "
end
if show_only_active_accounts.blank?
Expand Down Expand Up @@ -178,19 +194,21 @@ def self.report_ledger_balance(periods_to_balance, periods_to_balance_previous,
total_accounts_2000 = 0

balance.each do |row|
row["balance_period"] = row.total_last_period.to_f + row.total_period_previous.to_f
row["balance_period"] = row.total_period.to_f + row.total_period_previous.to_f
row["balance_last_period"] = row.total_last_period.to_f + row.total_last_period_previous.to_f
total_period_previous += row["total_period_previous"].to_f
total_period += row["total_period"].to_f
total_balance_period += row["balance_period"]
total_last_period_previous += row["total_last_period_previous"].to_f
total_last_period += row["total_last_period"].to_f
total_balance_last_period += row["balance_last_period"]
total_accounts_1000 += row["balance_period"] if row["account_number"][0,1] == '1'
total_accounts_2000 += row["balance_period"] if row["account_number"][0,1] == '2'
case row["account_number"].to_i
when 1000..1999 then total_accounts_1000 += row["balance_period"]
when 2000..2999 then total_accounts_2000 += row["balance_period"]
end
end
total_balance = Hash.new
total_balance["total_period_previos"]=total_period_previous
total_balance["total_period_previous"]=total_period_previous
total_balance["total_period"]=total_period
total_balance["total_balance_period"] = total_balance_period
total_balance["total_last_period_previous"] = total_last_period_previous
Expand All @@ -199,6 +217,10 @@ def self.report_ledger_balance(periods_to_balance, periods_to_balance_previous,
total_balance["total_accounts_1000"] = total_accounts_1000
total_balance["total_accounts_2000"] = total_accounts_2000


###############################
##### calculating result ######
###############################
sql = "
-- accounts results
select id as account_id,
Expand All @@ -223,7 +245,10 @@ def self.report_ledger_balance(periods_to_balance, periods_to_balance_previous,
end
unless project.blank?
sql += " and journal_operations.project_id = #{project.id}"
end
end
unless car.blank?
sql += " and journal_operations.car_id = #{car.id}"
end
sql +=" group by accounts.id "
end
unless _periods_to_result_last.blank?
Expand All @@ -244,7 +269,10 @@ def self.report_ledger_balance(periods_to_balance, periods_to_balance_previous,
end
unless project.blank?
sql += " and journal_operations.project_id = #{project.id}"
end
end
unless car.blank?
sql += " and journal_operations.car_id = #{car.id}"
end
sql +=" group by accounts.id "
end
if show_only_active_accounts.blank?
Expand Down Expand Up @@ -279,16 +307,18 @@ def self.report_ledger_balance(periods_to_balance, periods_to_balance_previous,
result.each do |row|
total_period += row["total_period"].to_f
total_last_period += row["total_last_period"].to_f
puts "account number = "+row["account_number"]
puts "account number first digit = "+row["account_number"][0,1]
puts "amount = "+row["total_last_period"]
total_accounts_3000 += row["total_period"].to_f if row["account_number"][0,1] == '3'
total_accounts_4000 += row["total_period"].to_f if row["account_number"][0,1] == '4'
total_accounts_5000 += row["total_period"].to_f if row["account_number"][0,1] == '5'
total_accounts_6000 += row["total_period"].to_f if row["account_number"][0,1] == '6'
total_accounts_7000 += row["total_period"].to_f if row["account_number"][0,1] == '7'
total_accounts_8000 += row["total_period"].to_f if row["account_number"][0,1] == '8'
total_accounts_9000 += row["total_period"].to_f if row["account_number"][0,1] == '9'
# puts "account number = "+row["account_number"]
# puts "account number first digit = "+row["account_number"][0,1]
# puts "amount = "+row["total_last_period"]
case row["account_number"].to_i
when 3000..3999 then total_accounts_3000 += row["total_period"].to_f
when 4000..4999 then total_accounts_4000 += row["total_period"].to_f
when 5000..5999 then total_accounts_4000 += row["total_period"].to_f
when 6000..6999 then total_accounts_4000 += row["total_period"].to_f
when 7000..7999 then total_accounts_4000 += row["total_period"].to_f
when 8000..8999 then total_accounts_4000 += row["total_period"].to_f
when 9000..9999 then total_accounts_4000 += row["total_period"].to_f
end
end
total_result = Hash.new
total_result["total_period"]=total_period
Expand Down Expand Up @@ -316,4 +346,4 @@ def set_number
self.number = self.journal_type.get_next_number(self.company)
end

end
end
Empty file added app/models/newSQLTemplate.sql
Empty file.
4 changes: 2 additions & 2 deletions app/views/assignments/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

<%= fields_for Company.new do |c| %>
<p>
<%= c.label :name, t(:name, :scope => :company) %><br />
<%= c.label :name, t(:name, :scope => :companies) %><br />
<%= c.text_field :name %>
</p>
<p>
<%= c.label :organization_number, t(:organization_number, :scope => :company) %><br />
<%= c.label :organization_number, t(:organization_number, :scope => :companies) %><br />
<%= c.text_field :organization_number %>
</p>
<% end %>
Expand Down
8 changes: 4 additions & 4 deletions app/views/journals/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<%= if @readonly then
@journal.period
else
f.select :period_id, @me.open_periods.collect {|p| [ p, p.id ] }
f.select :period_id, @me.open_periods.reverse.collect {|p| [ p, p.id ] }
end %>
</p>
<p>
Expand Down Expand Up @@ -112,9 +112,9 @@
</th>
</tr>
<tr>
<td><%= f.select :default_unit, Unit.where(:company_id => current_user.current_company.id).map { |p| [p.name, p.id] } %>
<td><%= f.select :default_car, Car.where(:company_id => current_user.current_company.id).map { |p| [p.name, p.id] } %>
<td><%= f.select :default_project, Project.where(:company_id => current_user.current_company.id).map { |p| [p.name, p.id] } %>
<td><%= f.select :default_unit, Unit.where(:company_id => current_user.current_company.id).map { |p| [p.name, p.id]} , {:include_blank => t(:select_unit, :scope => :journals)} %>
<td><%= f.select :default_car, Car.where(:company_id => current_user.current_company.id).map { |p| [p.name, p.id] } , {:include_blank => t(:select_car, :scope => :journals)}%>
<td><%= f.select :default_project, Project.where(:company_id => current_user.current_company.id).map { |p| [p.name, p.id] } , {:include_blank => t(:select_project, :scope => :journals)}%>
</tr>
</table>
</p>
Expand Down
Loading

0 comments on commit d7f6b04

Please sign in to comment.