api.array :time_entries, api_meta(:total_count => @entry_count, :offset => @offset, :limit => @limit, unseen_count: @unseen_count) do
  @entries.each do |time_entry|
    api.time_entry do
      api.id time_entry.id
      api.project(:id => time_entry.project_id, :name => time_entry.project.name) unless time_entry.project.nil?
      api.issue(:id => time_entry.issue_id, :subject => time_entry.issue.subject) unless time_entry.issue.nil?
      api.user(:id => time_entry.user_id, :name => time_entry.user.name) unless time_entry.user.nil?
      api.activity(:id => time_entry.activity_id, :name => time_entry.activity.name) unless time_entry.activity.nil?
      api.hours time_entry.hours.round(2).to_f if params[:spent_type].blank? || params[:spent_type] == "T"
      api.expense_amount time_entry.amount if params[:spent_type] == "E"
      api.wktime_currency time_entry.currency if params[:spent_type] == "E"
      api.comments time_entry.comments
      api.spent_on time_entry.spent_on
      api.created_on time_entry.created_on
      api.updated_on time_entry.updated_on
      api.log_type params[:spent_type]
      if time_entry.spent_for.present?
        spent_for = time_entry.spent_for.spent_for_type ? time_entry.project.id.to_s + "|" + time_entry.spent_for.spent_for_type.to_s + "_" + time_entry.spent_for.spent_for_id.to_s + "|" : nil
        api.spentFor(id: time_entry.spent_for.id, start_on: time_entry.spent_for.spent_on_time, end_on: time_entry.spent_for.end_on, spent_for: spent_for, clock_action: time_entry.spent_for.clock_action, s_longitude: time_entry.spent_for.s_longitude, s_latitude: time_entry.spent_for.s_latitude, e_longitude: time_entry.spent_for.e_longitude, e_latitude: time_entry.spent_for.e_latitude)
      end
    end
  end
end
api.headers do
  api.log_type_name getLogTypeName
end