|
|
|
@ -2,12 +2,31 @@ require_dependency 'xls_report/xls_views' |
|
|
|
|
|
|
|
|
|
class CostEntryTable < XlsViews |
|
|
|
|
def generate |
|
|
|
|
spreadsheet = SpreadsheetBuilder.new(cost_type_label(@unit_id)) |
|
|
|
|
spreadsheet = SpreadsheetBuilder.new(l(:label_money)) |
|
|
|
|
default_query = @query.serialize |
|
|
|
|
|
|
|
|
|
available_cost_type_tabs(options[:cost_types]).each_with_index do |ary, idx| |
|
|
|
|
@query = CostQuery.deserialize(default_query) |
|
|
|
|
@unit_id = ary.first |
|
|
|
|
name = ary.last |
|
|
|
|
|
|
|
|
|
if @unit_id != 0 |
|
|
|
|
@query.filter :cost_type_id, :operator => '=', :value => @unit_id.to_s |
|
|
|
|
@cost_type = CostType.find(unit_id) if unit_id > 0 |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
spreadsheet.worksheet(idx, name) |
|
|
|
|
build_spreadsheet(spreadsheet) |
|
|
|
|
end |
|
|
|
|
spreadsheet |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def build_spreadsheet(spreadsheet) |
|
|
|
|
spreadsheet.add_title("#{@project.name + " >> " if @project}#{l(:cost_reports_title)} (#{format_date(Date.today)})") |
|
|
|
|
|
|
|
|
|
list = [:spent_on, :user_id, :activity_id, :issue_id, :comments, :project_id] |
|
|
|
|
headers = list.collect {|field| label_for(field) } |
|
|
|
|
headers << (cost_type.try(:unit_plural) || l(:units)) |
|
|
|
|
headers << (cost_type.try(:unit_plural) || (@unit_id == -1 ? l(:caption_labor) : l(:units))) |
|
|
|
|
headers << l(:field_costs) |
|
|
|
|
spreadsheet.add_headers(headers) |
|
|
|
|
|
|
|
|
@ -16,7 +35,8 @@ class CostEntryTable < XlsViews |
|
|
|
|
|
|
|
|
|
query.each_direct_result do |result| |
|
|
|
|
row = list.collect {|field| show_field field, result.fields[field.to_s] } |
|
|
|
|
row << show_result(result, result.fields['cost_type_id'].to_i, true) |
|
|
|
|
current_cost_type_id = result.fields['cost_type_id'].to_i |
|
|
|
|
row << show_result(result, current_cost_type_id, current_cost_type_id != @unit_id) |
|
|
|
|
row << show_result(result, 0) # currency |
|
|
|
|
spreadsheet.add_row(row) |
|
|
|
|
end |
|
|
|
|