Class: Backend::EquipmentsController

Inherits:
MattersController show all
Defined in:
app/controllers/backend/equipments_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_theme

Class Method Summary collapse

Methods inherited from ProductsController

#edit_many, list_conditions, #take, #update_many

Methods inherited from BaseController

account_lettering_states_crit, accounts_range_crit, amount_range_crit, crit_params, journal_entries_states_crit, journal_letter_crit, journal_period_crit, journals_crit, search_conditions

Methods inherited from ApplicationController

#after_sign_in_path_for, #authorized?, human_action_name, #human_action_name, #session_controller?

Class Method Details

.equipments_conditionsObject

params:

:q Text search
:s State search
:period Two Dates with _ separator
:variant_id
:activity_id

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/backend/equipments_controller.rb', line 27

def self.equipments_conditions
  code = ''
  code = search_conditions(products: %i[name work_number number description uuid],
                           product_nature_variants: [:name]) + " ||= []\n"
  code << "  if params[:variant_id].to_i > 0\n"
  code << "    c[0] << \" AND \#{ProductNatureVariant.table_name}.id = ?\"\n"
  code << "    c << params[:variant_id].to_i\n"
  code << "  end\n"

  # filter by activity_id
  code << "  if params[:activity_id].to_i > 0\n"
  code << "    c[0] << \" AND \#{Equipment.table_name}.id IN (SELECT target_id FROM target_distributions WHERE activity_id = ?)\"\n"
  code << "    c << params[:activity_id].to_i\n"
  code << "  end\n"

  code << "c\n"
  code.c
end