From d8a9ba77c3acd72672404e12cb1be7577d80452f Mon Sep 17 00:00:00 2001
From: marwen blel
Date: Mon, 7 Nov 2011 11:34:15 +0100
Subject: [PATCH 1/2] fixing reports, cars filtering not completed
---
app/controllers/reports_controller.rb | 62 +++++++++------
app/models/journal.rb | 96 +++++++++++++++--------
app/models/newSQLTemplate.sql | 0
app/views/journals/_form.html.erb | 2 +-
app/views/reports/index.html.erb | 68 ++++++++--------
app/views/reports/ledger_balance.html.erb | 4 +-
config/locales/en.yml | 1 +
7 files changed, 141 insertions(+), 92 deletions(-)
create mode 100644 app/models/newSQLTemplate.sql
diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb
index df34d98..7eccdef 100644
--- a/app/controllers/reports_controller.rb
+++ b/app/controllers/reports_controller.rb
@@ -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
@@ -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]
@@ -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,
@@ -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
diff --git a/app/models/journal.rb b/app/models/journal.rb
index 145d4cf..ac10c7a 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -13,7 +13,7 @@ def to_s
end
def open?
- return (not self.closed)
+ return (not self.closed)
end
def editable?
@@ -21,10 +21,11 @@ def editable?
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
@@ -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,
@@ -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
@@ -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?
@@ -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?
@@ -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?
@@ -178,7 +194,7 @@ 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
@@ -186,11 +202,13 @@ def self.report_ledger_balance(periods_to_balance, periods_to_balance_previous,
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
@@ -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,
@@ -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_perations.car_id = #{car.id}"
+ end
sql +=" group by accounts.id "
end
unless _periods_to_result_last.blank?
@@ -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_perations.car_id = #{car.id}"
+ end
sql +=" group by accounts.id "
end
if show_only_active_accounts.blank?
@@ -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
@@ -316,4 +346,4 @@ def set_number
self.number = self.journal_type.get_next_number(self.company)
end
-end
+end
\ No newline at end of file
diff --git a/app/models/newSQLTemplate.sql b/app/models/newSQLTemplate.sql
new file mode 100644
index 0000000..e69de29
diff --git a/app/views/journals/_form.html.erb b/app/views/journals/_form.html.erb
index 53bfe4d..5c72ee7 100644
--- a/app/views/journals/_form.html.erb
+++ b/app/views/journals/_form.html.erb
@@ -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 %>
diff --git a/app/views/reports/index.html.erb b/app/views/reports/index.html.erb
index df9fe4b..a0ce0c8 100644
--- a/app/views/reports/index.html.erb
+++ b/app/views/reports/index.html.erb
@@ -18,15 +18,15 @@
<%= t(:from_period, :scope=>:reports) %>
- <%= select_tag :from_period_id,
- options_from_collection_for_select(@periods, "id", "to_s"),
+ <%= select_tag :from_period_id,
+ options_from_collection_for_select(@periods, "id", "to_s"),
:include_blank => true %>
|
<%= t(:to_period, :scope=>:reports) %>
|
- <%= select_tag :to_period_id,
+ <%= select_tag :to_period_id,
options_from_collection_for_select(@periods, "id", "to_s"),
:include_blank => true %>
|
@@ -34,7 +34,7 @@
<%= t(:result_from_period, :scope=>:reports) %>
- <%= select_tag :result_from_period_id,
+ <%= select_tag :result_from_period_id,
options_from_collection_for_select(@periods, "id", "to_s"),
:include_blank => true %>
|
@@ -44,7 +44,7 @@
<%= t(:unit, :scope=>:reports) %>
- <%= select_tag :unit_id,
+ <%= select_tag :unit_id,
options_from_collection_for_select(@units, "id", "to_s"),
:include_blank => true %>
|
@@ -52,16 +52,16 @@
<%= t(:project, :scope=>:reports) %>
- <%= select_tag :project_id,
+ <%= select_tag :project_id,
options_from_collection_for_select(@projects, "id", "to_s"),
:include_blank => true %>
|
- <%= t(:journal_type, :scope=>:reports) %>
+ <%= t(:car, :scope=>:reports) %>
|
- <%= select_tag :journal_type_id,
- options_from_collection_for_select(@journal_types, "id", "to_s"),
+ <%= select_tag :car_id,
+ options_from_collection_for_select(@cars, "id", "to_s"),
:include_blank => true %>
|
@@ -79,8 +79,12 @@
<%= check_box_tag :last_year_figures %>
+ <%= t(:journal_type, :scope=>:reports) %>
|
+ <%= select_tag :journal_type_id,
+ options_from_collection_for_select(@journal_types, "id", "to_s"),
+ :include_blank => true %>
|
@@ -100,15 +104,15 @@
<%= t(:from_account, :scope=>:reports) %>
- <%= select_tag :from_account_number,
- options_from_collection_for_select(@accounts, "number", "to_s"),
+ <%= select_tag :from_account_number,
+ options_from_collection_for_select(@accounts, "number", "to_s"),
:include_blank => true %>
|
<%= t(:to_account, :scope=>:reports) %>
|
- <%= select_tag :to_account_number,
+ <%= select_tag :to_account_number,
options_from_collection_for_select(@accounts, "number", "to_s"),
:include_blank => true %>
|
@@ -116,7 +120,7 @@
<%= t(:journal_type, :scope=>:reports) %>
- <%= select_tag :journal_type_id,
+ <%= select_tag :journal_type_id,
options_from_collection_for_select(@journal_types, "id", "to_s"),
:include_blank => true %>
|
@@ -126,7 +130,7 @@
<%= t(:from_period, :scope=>:reports) %>
- <%= select_tag :from_period_id,
+ <%= select_tag :from_period_id,
options_from_collection_for_select(@periods, "id", "to_s"),
:include_blank => true %>
|
@@ -134,7 +138,7 @@
<%= t(:to_period, :scope=>:reports) %>
- <%= select_tag :to_period_id,
+ <%= select_tag :to_period_id,
options_from_collection_for_select(@periods, "id", "to_s"),
:include_blank => true %>
|
@@ -197,7 +201,7 @@
<%= t(:ledger_from, :scope=>:reports) %>
- <%= select_tag :ledger_from_id,
+ <%= select_tag :ledger_from_id,
options_from_collection_for_select(@accounts, "id", "to_s"),
:include_blank => true %>
|
@@ -205,7 +209,7 @@
<%= t(:ledger_to, :scope=>:reports) %>
- <%= select_tag :ledger_to_id,
+ <%= select_tag :ledger_to_id,
options_from_collection_for_select(@accounts, "id", "to_s"),
:include_blank => true %>
|
@@ -215,7 +219,7 @@
<%= t(:from_period, :scope=>:reports) %>
- <%= select_tag :from_period_id,
+ <%= select_tag :from_period_id,
options_from_collection_for_select(@periods, "id", "to_s"),
:include_blank => true %>
|
@@ -223,7 +227,7 @@
<%= t(:to_period, :scope=>:reports) %>
- <%= select_tag :to_period_id,
+ <%= select_tag :to_period_id,
options_from_collection_for_select(@periods, "id", "to_s"),
:include_blank => true %>
|
@@ -231,7 +235,7 @@
<%= t(:result_from_period, :scope=>:reports) %>
- <%= select_tag :result_from_period_id,
+ <%= select_tag :result_from_period_id,
options_from_collection_for_select(@periods, "id", "to_s"),
:include_blank => true %>
|
@@ -270,7 +274,7 @@
<%= t(:from_account, :scope=>:reports) %>
- <%= select_tag :from_account_id,
+ <%= select_tag :from_account_id,
options_from_collection_for_select(@accounts, "id", "to_s"),
:include_blank => true %>
|
@@ -278,7 +282,7 @@
<%= t(:to_account, :scope=>:reports) %>
- <%= select_tag :to_account_id,
+ <%= select_tag :to_account_id,
options_from_collection_for_select(@accounts, "id", "to_s"),
:include_blank => true %>
|
@@ -288,7 +292,7 @@
<%= t(:from_period, :scope=>:reports) %>
- <%= select_tag :from_period_id,
+ <%= select_tag :from_period_id,
options_from_collection_for_select(@periods, "id", "to_s"),
:include_blank => true %>
|
@@ -296,7 +300,7 @@
<%= t(:to_period, :scope=>:reports) %>
- <%= select_tag :to_period_id,
+ <%= select_tag :to_period_id,
options_from_collection_for_select(@periods, "id", "to_s"),
:include_blank => true %>
|
@@ -304,7 +308,7 @@
<%= t(:journal_type, :scope=>:reports) %>
- <%= select_tag :journal_type_id,
+ <%= select_tag :journal_type_id,
options_from_collection_for_select(@journal_types, "id", "to_s"),
:include_blank => true %>
|
@@ -314,7 +318,7 @@
<%= t(:unit, :scope=>:reports) %>
- <%= select_tag :unit_id,
+ <%= select_tag :unit_id,
options_from_collection_for_select(@units, "id", "to_s"),
:include_blank => true %>
|
@@ -322,7 +326,7 @@
<%= t(:project, :scope=>:reports) %>
- <%= select_tag :project_id,
+ <%= select_tag :project_id,
options_from_collection_for_select(@projects, "id", "to_s"),
:include_blank => true %>
|
@@ -353,7 +357,7 @@
<%= t(:from_account, :scope=>:reports) %>
- <%= select_tag :from_account_id,
+ <%= select_tag :from_account_id,
options_from_collection_for_select(@accounts, "id", "to_s"),
:include_blank => true %>
|
@@ -361,7 +365,7 @@
<%= t(:to_account, :scope=>:reports) %>
- <%= select_tag :to_account_id,
+ <%= select_tag :to_account_id,
options_from_collection_for_select(@accounts, "id", "to_s"),
:include_blank => true %>
|
@@ -371,7 +375,7 @@
<%= t(:unit, :scope=>:reports) %>
- <%= select_tag :unit_id,
+ <%= select_tag :unit_id,
options_from_collection_for_select(@units, "id", "to_s"),
:include_blank => true %>
|
@@ -379,7 +383,7 @@
<%= t(:project, :scope=>:reports) %>
- <%= select_tag :project_id,
+ <%= select_tag :project_id,
options_from_collection_for_select(@projects, "id", "to_s"),
:include_blank => true %>
|
@@ -394,7 +398,7 @@
- <% end %>
+ <% end %>
diff --git a/app/views/reports/ledger_balance.html.erb b/app/views/reports/ledger_balance.html.erb
index 4a041b0..6c059cb 100644
--- a/app/views/reports/ledger_balance.html.erb
+++ b/app/views/reports/ledger_balance.html.erb
@@ -23,8 +23,8 @@
<% end %>
- <%= t(:account_name, :scope=>:reports) %> |
<%= t(:account_number, :scope=>:reports) %> |
+ <%= t(:account_name, :scope=>:reports) %> |
<%= t(:old_balance, :scope=>:reports) %> |
<%= t(:period, :scope=>:reports) %> |
<%= t(:new_balance, :scope=>:reports) %> |
@@ -38,8 +38,8 @@
<% @balance.each do |row| %>
- <%= row.account_name %> |
<%= row.account_number %> |
+ <%= row.account_name %> |
<%= number_with_precision(row.total_period_previous, :locale =>I18n.locale) %> |
<%= number_with_precision(row.total_period, :locale =>I18n.locale) %> |
<%= number_with_precision(row.balance_period, :locale =>I18n.locale) %> |
diff --git a/config/locales/en.yml b/config/locales/en.yml
index d980ed7..6a95cf5 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -440,6 +440,7 @@ en:
from_period: From Period
to_period: To Period
unit: Department
+ car: Car
show_only_active_accounts: Show Only Active Acount
last_year_figures: Last Year Figures
result_from_period: Results From
From 07431f2c9138efcdf04b9e4186300a22110b3286 Mon Sep 17 00:00:00 2001
From: marwen blel
Date: Mon, 7 Nov 2011 13:05:34 +0100
Subject: [PATCH 2/2] #reports#fixed spelling mistake on car filtering, waiting
for Arnt to validate
---
app/models/journal.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/models/journal.rb b/app/models/journal.rb
index ac10c7a..21d9a17 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -247,7 +247,7 @@ def self.report_ledger_balance(periods_to_balance, periods_to_balance_previous,
sql += " and journal_operations.project_id = #{project.id}"
end
unless car.blank?
- sql += " and journal_perations.car_id = #{car.id}"
+ sql += " and journal_operations.car_id = #{car.id}"
end
sql +=" group by accounts.id "
end
@@ -271,7 +271,7 @@ def self.report_ledger_balance(periods_to_balance, periods_to_balance_previous,
sql += " and journal_operations.project_id = #{project.id}"
end
unless car.blank?
- sql += " and journal_perations.car_id = #{car.id}"
+ sql += " and journal_operations.car_id = #{car.id}"
end
sql +=" group by accounts.id "
end