Skip to content

Commit

Permalink
Merge pull request #11 from dhanasingh/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
suganya-thulasiraman committed Apr 17, 2015
2 parents 27b2fdd + c17554c commit 8c5cead
Show file tree
Hide file tree
Showing 28 changed files with 632 additions and 438 deletions.
18 changes: 7 additions & 11 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,12 @@ If an apache passenger module is used then make sure the following settings are
b) RailsAppSpawnerIdleTime 0
c) PassengerPreStart http://rails-app-url/

Release Notes for 1.7
Release Notes for 1.8
Features:
- Made compatible with Redmine 2.5.2

- Following permission changes were made:
- The user with 'Log spent time' or 'View spent time' permissions will be able to see the Time & Expense list page.
- The user with 'Edit time logs' permission is allowed to manage other member time/expense sheet.

- Following functionalities are available through REST api:
- List time/expense sheet of all user
- Delete entries in time/expense sheet
- Made compatible with Redmine 3.0.1.
- Implemented 'Save and Continue' button on time/expense sheet edit page.
Bugs:
- Hours summed up for different custom values
- "wktime/getstatus" loading over HTTP on site served over HTTPS.
- Users can delete submitted & approved timesheets.
- Email notification not sent due to upper case in file name.
- Pdf broken issue
98 changes: 40 additions & 58 deletions app/controllers/wkexpense_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class WkexpenseController < WktimeController

include WkexpenseHelper
include SortHelper
helper :sort
helper :sort


def getLabelforSpField
l(:field_amount)
Expand Down Expand Up @@ -57,72 +58,43 @@ def total_all(total)
total.nil? ? html_hours("%.2f" % 0.00) : html_hours("%.2f" % total)
end

def reportdetail
sort_init 'spent_on', 'desc'
sort_update 'spent_on' => ['spent_on', "#{WkExpenseEntry.table_name}.created_on"],
'user' => 'user_id',
'activity' => 'activity_id',
'project' => "#{Project.table_name}.name",
'issue' => 'issue_id',
'amount' => 'amount'

retrieve_date_range
@from = getStartDay(@from)
@to = getEndDay(@to)
wkexpense = WkExpenseEntry.visible.spent_between(@from, @to)
if @issue
wkexpense = wkexpense.on_issue(@issue)
elsif @project
wkexpense = wkexpense.on_project(@project, Setting.display_subprojects_issues?)
end
def reportdetail
@query = WkExpenseEntryQuery.build_from_params(params, :project => @project, :name => '_')
sort_init(@query.sort_criteria.empty? ? [['spent_on', 'desc']] : @query.sort_criteria)
sort_update(@query.sortable_columns)
scope = expense_entry_scope(:order => sort_clause).
includes(:project, :user, :issue).
preload(:issue => [:project, :tracker, :status, :assigned_to, :priority])
respond_to do |format|
format.html {
# Paginate results
@entry_count = wkexpense.count
@entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
@entries = wkexpense.all(
:include => [:project, :activity, :user, {:issue => :tracker}],
:order => sort_clause,
:limit => @entry_pages.items_per_page,
:offset => @entry_pages.current.offset
)
@total_amount = wkexpense.sum(:amount).to_f
@entry_count = scope.count
@entry_pages = Paginator.new @entry_count, per_page_option, params['page']
@entries = scope.offset(@entry_pages.offset).limit(@entry_pages.per_page).to_a
@total_hours = scope.sum(:amount).to_f
render :layout => !request.xhr?
}
format.api {
@entry_count = wkexpense.count
@entry_count = scope.count
@offset, @limit = api_offset_and_limit
@entries = wkexpense.all(
:include => [:project, :activity, :user, {:issue => :tracker}],
:order => sort_clause,
:limit => @limit,
:offset => @offset
)
@entries = scope.offset(@offset).limit(@limit).preload(:custom_values => :custom_field).to_a
}
format.atom {
entries = wkexpense.all(
:include => [:project, :activity, :user, {:issue => :tracker}],
:order => "#{WkExpenseEntry.table_name}.created_on DESC",
:limit => Setting.feeds_limit.to_i
)
render_feed(entries, :title => l(:label_spent_expense))
entries = scope.limit(Setting.feeds_limit.to_i).reorder("#{WkExpenseEntry.table_name}.created_on DESC").to_a
render_feed(entries, :title => l(:label_spent_time))
}
format.csv {
# Export all entries
@entries = wkexpense.all(
:include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
:order => sort_clause
)
send_data(entries_to_csv(@entries), :type => 'text/csv; header=present', :filename => 'wkexpense.csv')
@entries = scope.to_a
send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => 'expenselog.csv')
}
end

end

def report
retrieve_date_range
@report = WkexpenseHelper::WKExpenseReport.new(@project, @issue, params[:criteria], params[:columns], @from, @to)

def report
@query = WkExpenseEntryQuery.build_from_params(params, :project => @project, :name => '_')
scope = expense_entry_scope
@report = WkexpenseHelper::WKExpenseReport.new(@project, @issue, params[:criteria], params[:columns], scope)
respond_to do |format|
format.html { render :layout => !request.xhr? }
format.csv { send_data(report_to_csv(@report), :type => 'text/csv; header=present', :filename => 'wkexpense.csv') }
Expand Down Expand Up @@ -150,7 +122,7 @@ def getEntityNames

def findBySql(selectStr,sqlStr,wkSelectStr,wkSqlStr)
spField = getSpecificField()
result = WkExpenseEntry.find_by_sql("select count(*) as id from (" + selectStr + sqlStr + ") as v2")
result = WkExpenseEntry.find_by_sql("select count(*) as id from (" + selectStr + sqlStr + wkSqlStr + ") as v2")
@entry_count = result[0].id

setLimitAndOffset()
Expand All @@ -163,17 +135,18 @@ def findBySql(selectStr,sqlStr,wkSelectStr,wkSqlStr)

#@total_hours = TimeEntry.visible.sum(:hours, :include => [:user], :conditions => cond.conditions).to_f

result = WkExpenseEntry.find_by_sql("select sum(v2." + spField + ") as " + spField + " from (" + selectStr + sqlStr + ") as v2")
result = WkExpenseEntry.find_by_sql("select sum(v2." + spField + ") as " + spField + " from (" + selectStr + sqlStr + wkSqlStr +") as v2")
@total_hours = result[0].amount
end

def findWkTEByCond(cond)
@wktimes = Wkexpense.find(:all, :conditions => cond)
#@wktimes = Wkexpense.find(:all, :conditions => cond)
@wktimes = Wkexpense.where(cond)
end

def findEntriesByCond(cond)
WkExpenseEntry.find(:all, :conditions => cond,
:order => 'project_id, issue_id, activity_id, spent_on')
#WkExpenseEntry.find(:all, :conditions => cond, :order => 'project_id, issue_id, activity_id, spent_on')
WkExpenseEntry.where(cond).order('project_id, issue_id, activity_id, spent_on')
end

def setValueForSpField(teEntry,spValue,decimal_separator,entry)
Expand Down Expand Up @@ -216,7 +189,8 @@ def setEntityLabel
def setTEProjects(projects)
expense_project_ids = Setting.plugin_redmine_wktime['wkexpense_projects']
if(!expense_project_ids.blank? && expense_project_ids != [""])
expense_projects = Project.find_all_by_id(expense_project_ids)
#expense_projects = Project.find_all_by_id(expense_project_ids)
expense_projects = Project.find(expense_project_ids)
projects = projects & expense_projects
end
projects
Expand All @@ -227,7 +201,7 @@ def find_optional_project
@issue = Issue.find(params[:issue_id])
@project = @issue.project
elsif !params[:project_id].blank?
@project = Project.find(params[:project_id])
@project = Project.find(params[:project_id])
end
end

Expand All @@ -238,4 +212,12 @@ def validateEntry(stDate)
def getTEName
"expense"
end
# Returns the ExpenseEntry scope for index and report actions
def expense_entry_scope(options={})
scope = @query.results_scope(options)
if @issue
scope = scope.on_issue(@issue)
end
scope
end
end
Loading

0 comments on commit 8c5cead

Please sign in to comment.