class WorkAccountsController < ApplicationController def index list render :action => 'list' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :method => :post, :only => [ :destroy, :create, :update ], :redirect_to => { :action => :list } def list @work_accounts = WorkAccount.paginate :page => params[:page], :order => 'name' end def show @work_account = WorkAccount.find(params[:id]) works = @work_account.works.select{|w|w.user_id == current_user.id} @backlog_totals = works.to_summarized_hash {|work| [work.task && work.task.backlog, work.hours]} @task_totals = works.to_summarized_hash {|work| [work.task, work.hours]} @task_totals_per_backlog = @task_totals.to_a.to_grouped_hash {|task, hours| [task && task.backlog, [task, hours]]} @total_hours = works.inject(BigDecimal('0')) {|total, work| total += work.hours} @works_without_backlog = works.select {|w| w.task_id.nil?} end def new @work_account = WorkAccount.new end def create @work_account = WorkAccount.new(params[:work_account]) if @work_account.save flash[:notice] = 'WorkAccount was successfully created.' redirect_to :action => 'list' else render :action => 'new' end end def edit @work_account = WorkAccount.find(params[:id]) end def update @work_account = WorkAccount.find(params[:id]) if @work_account.update_attributes(params[:work_account]) flash[:notice] = 'WorkAccount was successfully updated.' back_or_redirect_to :action => 'show', :id => @work_account else render :action => 'edit' end end def destroy WorkAccount.find(params[:id]).destroy redirect_to :action => 'list' end def works work_account = WorkAccount.find(params[:id]) @report_filter = WorksReportFilter.new(params[:report_filter]) @report_filter.title = "#{l :hours} for #{work_account.name} #{@report_filter.start_on && @report_filter.start_on.strftime('%Y-%m-%d - ')}#{@report_filter.end_on && @report_filter.end_on.strftime('%Y-%m-%d')}" @works = Work.paginate :conditions => ["completed_at BETWEEN ? AND ? AND work_account_id = ? #{@report_filter.invoice.nil? ? '' : 'AND invoice = ?'} #{@report_filter.user_id.nil? ? '' : 'AND user_id = ?'}", @report_filter.start_on, @report_filter.end_on + 1, work_account.id, @report_filter.invoice, @report_filter.user_id].compact, :page => params[:page], :per_page => @report_filter.page_size, :order => 'started_on, start_time, completed_at' @users = User.find(:all) if params[:export] == 'excel' render :template => '/works/list_excel', :layout => false else render :template => '/works/list' end end end