-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from DFID/Fix-DocumentType-Project-Document-Page
Fix document type project document page
- Loading branch information
Showing
11 changed files
with
241 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
module CommonHelpers | ||
|
||
#New One based on API Call | ||
def financial_year_wise_budgets(yearWiseBudgets,type) | ||
|
||
projectBudgets = [] | ||
|
||
yearWiseBudgets.each do |y| | ||
if y["quarter"]==1 | ||
p=[y["quarter"],y["budget"],y["year"],y["year"]-1] | ||
else | ||
p=[y["quarter"],y["budget"],y["year"],y["year"]] | ||
end | ||
|
||
projectBudgets << p | ||
end | ||
|
||
#project_budgets | ||
#project_budgets = year_wise_budgets.group_by{|b| b["year"]}.map{|year, budgets| | ||
#summedBudgets = budgets.reduce(0) {|memo, budget| memo + budget["budget"]} | ||
#[year, summedBudgets] | ||
#}.sort | ||
|
||
finYearWiseBudgets = projectBudgets.group_by{|b| b[3]}.map{|year, budgets| | ||
summedBudgets = budgets.reduce(0) {|memo, budget| memo + budget[1]} | ||
[year, summedBudgets] | ||
}.sort | ||
|
||
# determine what range to show | ||
#current_financial_year = first_day_of_financial_year(DateTime.now) | ||
currentFinancialYear = financial_year | ||
|
||
# if range is 6 or less just show it | ||
if (type=="C") then | ||
range = if finYearWiseBudgets.size < 7 then | ||
finYearWiseBudgets | ||
# if the last item in the list is less than or equal to | ||
# the current financial year get the last 6 | ||
elsif finYearWiseBudgets.last.first <= currentFinancialYear | ||
finYearWiseBudgets.last(6) | ||
# other wise show current FY - 3 years and cuurent FY + 3 years | ||
else | ||
index_of_now = finYearWiseBudgets.index { |i| i[0] == currentFinancialYear } | ||
|
||
if index_of_now.nil? then | ||
finYearWiseBudgets.last(6) | ||
else | ||
finYearWiseBudgets[[index_of_now-3,0].max..index_of_now+2] | ||
end | ||
end | ||
|
||
# finally convert the range into a label format | ||
range.each { |item| | ||
item[0] = financial_year_formatter(item[0]) | ||
} | ||
elsif (type=="P") then | ||
finYearWiseBudgets.each { |item| | ||
item[0] = financial_year_formatter(item[0]) | ||
} | ||
|
||
end | ||
|
||
end | ||
|
||
#New One based on API Call | ||
def financial_year_formatter(y) | ||
|
||
#date = if(d.kind_of?(String)) then | ||
#Date.parse d | ||
#else | ||
#d | ||
#end | ||
|
||
#if date.month < 4 | ||
#{}"FY#{(date.year-1).to_s[2..3]}/#{date.year.to_s[2..3]}" | ||
#else | ||
"FY#{y.to_s[2..3]}/#{(y+1).to_s[2..3]}" | ||
#end | ||
end | ||
|
||
def financial_year | ||
now = Time.new | ||
if(now.month < 4) | ||
now.year-1 | ||
else | ||
now.year | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.