Class: Backend::BaseController

Inherits:
BaseController show all
Includes:
Autocomplete, RestfullyManageable, Unrollable, Userstamp
Defined in:
app/controllers/backend/base_controller.rb

Direct Known Subclasses

AccountsController, ActivitiesController, ActivityBudgetsController, ActivityInspectionPointNaturesController, ActivityProductionsController, AffairsController, AnalysesController, AnalysisItemsController, AnimalGroupsController, AttachmentsController, BankStatementItemsController, BankStatementsController, BeehivesController, Calculators::BaseController, CampaignsController, CapIsletsController, CapLandParcelsController, CapStatementsController, CashTransfersController, CashesController, CatalogItemsController, CatalogsController, Cells::BaseController, CobblersController, CrumbsController, CultivableZonesController, CustomFieldChoicesController, CustomFieldsController, DashboardsController, DeliveriesController, DepositsController, DistrictsController, DocumentTemplatesController, DocumentsController, DraftJournalsController, EntitiesController, EntityAddressesController, EntityLinksController, EventParticipationsController, EventsController, ExportsController, FinancialYearsController, FixedAssetsController, GapsController, GeneralLedgersController, GeoreadingsController, GolumnsController, GuideAnalysesController, GuidesController, HelpsController, IdentifiersController, ImportsController, IncomingPaymentModesController, IncomingPaymentsController, InspectionsController, InterventionsController, InventoriesController, InventoryItemsController, InvitationsController, IssuesController, JanusesController, JournalEntriesController, JournalEntryItemsController, JournalsController, KujakusController, ListingNodeItemsController, ListingNodesController, ListingsController, LoanRepaymentsController, LoansController, ManureManagementPlansController, MapBackgroundsController, MapEditorsController, MyselvesController, NetServicesController, NotificationsController, ObservationsController, OutgoingPaymentModesController, OutgoingPaymentsController, ParcelItemsController, ParcelsController, PlantDensityAbaciController, PostalZonesController, PrescriptionsController, ProductLinkagesController, ProductLocalizationsController, ProductMembershipsController, ProductNatureCategoriesController, ProductNatureVariantsController, ProductNaturesController, ProductOwnershipsController, ProductPhasesController, ProductsController, PurchaseNaturesController, PurchasesController, RegistrationsController, RolesController, SaleCreditsController, SaleNaturesController, SalesController, SensorsController, SequencesController, SettingsController, SnippetsController, SubscriptionNaturesController, SubscriptionsController, SupervisionsController, SynchronizationsController, TargetDistributionsController, TasksController, TaxesController, TeamsController, TrackingsController, TrialBalancesController, UsersController, VisualsController, WineTanksController

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_theme

Class Method Summary collapse

Methods inherited from ApplicationController

#after_sign_in_path_for, #authorized?, human_action_name, #human_action_name

Class Method Details

.accounts_range_crit(variable, conditions = 'c') ⇒ Object

accountancy -> accounts_range_crit


255
256
257
258
259
260
261
# File 'app/controllers/backend/base_controller.rb', line 255

def accounts_range_crit(variable, conditions = 'c')
  variable = "params[:#{variable}]" unless variable.is_a? String
  code = ''
  # code << "ac, #{variable}[:accounts] = \n"
  code << "#{conditions}[0] += ' AND '+Account.range_condition(#{variable}[:accounts])\n"
  code.c
end

.crit_params(hash) ⇒ Object

accountancy -> crit_params


264
265
266
267
268
269
270
271
272
# File 'app/controllers/backend/base_controller.rb', line 264

def crit_params(hash)
  nh = {}
  keys = JournalEntry.state_machine.states.collect(&:name)
  keys += [:period, :started_at, :stopped_at, :accounts, :centralize]
  for k, v in hash
    nh[k] = hash[k] if k.to_s.match(/^(journal|level)_\d+$/) || keys.include?(k.to_sym)
  end
  nh
end

.journal_entries_states_crit(variable, conditions = 'c') ⇒ Object

accountancy -> journal_entries_states_crit


275
276
277
278
279
280
# File 'app/controllers/backend/base_controller.rb', line 275

def journal_entries_states_crit(variable, conditions = 'c')
  variable = "params[:#{variable}]" unless variable.is_a? String
  code = ''
  code << "#{conditions}[0] += ' AND '+JournalEntry.state_condition(#{variable}[:states])\n"
  code.c
end

.journal_period_crit(variable, conditions = 'c') ⇒ Object

accountancy -> journal_period_crit


283
284
285
286
287
288
# File 'app/controllers/backend/base_controller.rb', line 283

def journal_period_crit(variable, conditions = 'c')
  variable = "params[:#{variable}]" unless variable.is_a? String
  code = ''
  code << "#{conditions}[0] += ' AND '+JournalEntry.period_condition(#{variable}[:period], #{variable}[:started_on], #{variable}[:stopped_on])\n"
  code.c
end

.journals_crit(variable, conditions = 'c') ⇒ Object

accountancy -> journals_crit


291
292
293
294
295
296
# File 'app/controllers/backend/base_controller.rb', line 291

def journals_crit(variable, conditions = 'c')
  variable = "params[:#{variable}]" unless variable.is_a? String
  code = ''
  code << "#{conditions}[0] += ' AND '+JournalEntry.journal_condition(#{variable}[:journals])\n"
  code.c
end

.search_conditions(search = {}, options = {}) ⇒ Object

search is a hash like [columns…]


222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'app/controllers/backend/base_controller.rb', line 222

def search_conditions(search = {}, options = {})
  conditions = options[:conditions] || 'c'
  options[:except] ||= []
  options[:filters] ||= {}
  variable ||= options[:variable] || 'params[:q]'
  tables = search.keys.select { |t| !options[:except].include? t }
  code = "\n#{conditions} = ['1=1']\n"
  columns = search.collect do |table, filtered_columns|
    filtered_columns.collect do |column|
      ActiveRecord::Base.connection.quote_table_name(table.is_a?(Symbol) ? table.to_s.classify.constantize.table_name : table) +
        '.' +
        ActiveRecord::Base.connection.quote_column_name(column)
    end
  end.flatten
  code << "for kw in #{variable}.to_s.lower.split(/\\s+/)\n"
  code << "  kw = '%'+kw+'%'\n"
  filters = columns.collect do |x|
    'LOWER(CAST(' + x.to_s + ' AS VARCHAR)) LIKE ?'
  end
  values = '[' + (['kw'] * columns.size).join(', ') + ']'
  for k, v in options[:filters]
    filters << k
    v = '[' + v.join(', ') + ']' if v.is_a? Array
    values += '+' + v
  end
  code << "  #{conditions}[0] += ' AND (#{filters.join(' OR ')})'\n"
  code << "  #{conditions} += #{values}\n"
  code << "end\n"
  code << conditions.to_s
  code.c
end