Guest User

Untitled

a guest
Jun 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. # add this to /config/initializers/global_named_scopes.rb
  2. class ActiveRecord::Base
  3. named_scope :conditions, lambda { |*args| { :conditions => args} }
  4. end
  5.  
  6.  
  7.  
  8. scope = ProjectTotalView.scoped({})
  9.  
  10. unless @current_user.has_access_to_all_projects?
  11. scope = scope.scoped({
  12. :joins => 'INNER JOIN project_people_access_vw s ON (
  13. s.fin_project_id = project_totals_vw.fin_project_id AND
  14. s.cost_centre_code = project_totals_vw.cost_centre_code)',
  15. :conditions => ['s.person_id = ? and s.access_type = ?', @current_user.emplid, ProjectAccess::ACCESS_STD]
  16. })
  17. end
  18.  
  19. #Only this years projects
  20. scope = scope.conditions 'year = ? ', Time.now.strftime('%Y')
  21.  
  22. # Only Active projects by default
  23. scope = scope.conditions "project_status_code = 'A'" unless ns['closed']
  24.  
  25. # only Active Cost Centres by default
  26. scope = scope.conditions "cost_centre_status_code = 'A'" unless ns['closed_cost_centres']
  27.  
  28. scope = scope.scoped({:select => 'bla', :joins => {:abc}, :order => 'abc desc'}
Add Comment
Please, Sign In to add comment