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, ActivitySeasonsController, AffairsController, AnalysesController, AnalysisItemsController, AttachmentsController, Backend::BankReconciliation::GapsController, Backend::BankReconciliation::ItemsController, Backend::BankReconciliation::LettersController, BankStatementItemsController, BankStatementsController, BeehivesController, Calculators::BaseController, CampaignsController, CapIsletsController, CapLandParcelsController, CapStatementsController, CashTransfersController, CashesController, CatalogItemsController, CatalogsController, Cells::BaseController, CobblersController, Cobbles::BaseController, CompaniesController, ContractsController, CrumbsController, CultivableZonesController, CustomFieldChoicesController, CustomFieldsController, DashboardsController, DebtTransfersController, DeliveriesController, DepositsController, DistrictsController, DocumentTemplatesController, DocumentsController, DraftJournalsController, EntitiesController, EntityAddressesController, EntityLinksController, EventParticipationsController, EventsController, ExportsController, FinancialYearExchangesController, FinancialYearsController, FixedAssetDepreciationsController, FixedAssetsController, GapsController, GeneralLedgersController, GeoreadingsController, GolumnsController, GuideAnalysesController, GuidesController, HelpsController, IdentifiersController, ImportsController, IncomingPaymentModesController, IncomingPaymentsController, InspectionsController, IntegrationsController, InterventionParticipationsController, Interventions::CostsController, InterventionsController, InventoriesController, InventoryItemsController, InvitationsController, IssuesController, JanusesController, JournalEntriesController, JournalEntryItemsController, JournalsController, KujakusController, LabelsController, ListingNodeItemsController, ListingNodesController, ListingsController, LoanRepaymentsController, LoansController, ManureManagementPlansController, MapEditorShapesController, MapEditorsController, MapLayersController, MasterProductionNaturesController, MyselvesController, NamingFormatsController, NetServicesController, NotificationsController, ObservationsController, OutgoingPaymentListsController, OutgoingPaymentModesController, OutgoingPaymentsController, ParcelsController, PayslipNaturesController, PayslipsController, PlantCountingsController, PlantDensityAbaciController, PlantDensityAbacusItemsController, PostalZonesController, PreferencesController, PrescriptionsController, ProductLinkagesController, ProductLocalizationsController, ProductMembershipsController, ProductNatureCategoriesController, ProductNatureVariantComponentsController, ProductNatureVariantsController, ProductNaturesController, ProductOwnershipsController, ProductPhasesController, Products::IndicatorsController, Products::InterventionsController, Products::SearchProductsController, Products::SearchVariantsController, ProductsController, ProjectBudgetsController, PurchaseInvoicesController, PurchaseNaturesController, PurchaseOrdersController, PurchaseProcess::ReconciliationController, Purchases::ReconcilationStatesController, PurchasesController, QuickAffairsController, RegistrationsController, RegularizationsController, RolesController, SaleCreditsController, SaleNaturesController, SalesController, SensorsController, SequencesController, ServicesController, SettingsController, SnippetsController, SubscriptionNaturesController, SubscriptionsController, SupervisionsController, SynchronizationsController, TasksController, TaxDeclarationsController, TaxesController, TeamsController, ToursController, TrackingsController, TrialBalancesController, UnreceivedPurchaseOrdersController, Users::WiceGridPreferencesController, UsersController, Variants::FixedAssetsController, VisualizationsController, 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, #session_controller?

Class Method Details

.account_lettering_states_crit(variable, _conditions = 'c', _table_name = nil) ⇒ Object


325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'app/controllers/backend/base_controller.rb', line 325

def (variable, _conditions = 'c', _table_name = nil)
  variable = "params[:#{variable}]" unless variable.is_a? String
  code = ''
  code << "unless #{variable}[:account_lettering_state].blank?\n"
  code << "  conditions = ['1=1'] \n"
  code << "  account_lettering_states = #{variable}[:account_lettering_state].map{ |s| s.split(',') }.flatten.compact \n"
  code << "  account_lettering_states.each_with_index do |current_lettering_state, index|\n"
  code << "    if index == 0\n"
  code << "      conditions[0] << ' AND('\n"
  code << "      if current_lettering_state == 'lettered'\n"
  code << "        conditions[0] << '(#{JournalEntryItem.table_name}.letter IS NOT NULL AND #{JournalEntryItem.table_name}.letter NOT ILIKE ?)'\n"
  code << "        conditions << '%*'\n"
  code << "      end\n"

  code << "      if current_lettering_state == 'unlettered'\n"
  code << "        conditions[0] << '#{JournalEntryItem.table_name}.letter IS NULL'\n"
  code << "      end\n"

  code << "      if current_lettering_state == 'partially_lettered'\n"
  code << "        conditions[0] << '(#{JournalEntryItem.table_name}.letter IS NOT NULL AND #{JournalEntryItem.table_name}.letter ILIKE ?)'\n"
  code << "        conditions << '%*'\n"
  code << "      end\n"
  code << "    else\n"
  code << "      if current_lettering_state == 'lettered'\n"
  code << "        conditions[0] << ' OR (#{JournalEntryItem.table_name}.letter IS NOT NULL AND #{JournalEntryItem.table_name}.letter NOT ILIKE ?)'\n"
  code << "        conditions << '%*'\n"
  code << "      end\n"

  code << "      if current_lettering_state == 'unlettered'\n"
  code << "        conditions[0] << ' OR #{JournalEntryItem.table_name}.letter IS NULL'\n"
  code << "      end\n"

  code << "      if current_lettering_state == 'partially_lettered'\n"
  code << "        conditions[0] << ' OR (#{JournalEntryItem.table_name}.letter IS NOT NULL AND #{JournalEntryItem.table_name}.letter ILIKE ?)'\n"
  code << "        conditions << '%*'\n"
  code << "      end\n"
  code << "    end\n"
  code << "  end\n"
  code << "  conditions[0] << ')'\n"
  code << journal_period_crit('params', 'conditions')
  code << "  subquery = #{JournalEntryItem}.joins(:entry).select(:account_id).where(conditions).to_sql\n"
  code << "  c[0] << ' AND accounts.id IN (' \n"
  code << "  c[0] << subquery \n"
  code << "  c[0] << ')' \n"
  code << "end\n"
  code.c
end

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

accountancy -> accounts_range_crit


374
375
376
377
378
379
380
# File 'app/controllers/backend/base_controller.rb', line 374

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

.amount_range_crit(variable, _conditions = 'c') ⇒ Object


458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
# File 'app/controllers/backend/base_controller.rb', line 458

def amount_range_crit(variable, _conditions = 'c')
  variable = "params[:#{variable}]" unless variable.is_a? String
  code = ''
  code << "unless #{variable}[:minimum_amount].blank? && #{variable}[:maximum_amount].blank?\n"
  code << "  if #{variable}[:minimum_amount].blank?\n"
  code << "    c[0] << ' AND (#{JournalEntryItem.table_name}.absolute_credit <= ' + params[:maximum_amount] + ' AND #{JournalEntryItem.table_name}.absolute_debit <= ' + params[:maximum_amount] + ')'\n"
  code << "  end\n"

  code << "  if #{variable}[:maximum_amount].blank?\n"
  code << "    c[0] << ' AND (#{JournalEntryItem.table_name}.absolute_credit >= ' + params[:minimum_amount] + ' OR #{JournalEntryItem.table_name}.absolute_debit >= ' + params[:minimum_amount] + ')'\n"
  code << "  end\n"

  code << "  if !#{variable}[:minimum_amount].blank? && !#{variable}[:maximum_amount].blank?\n"
  code << "    c[0] << ' AND ((#{JournalEntryItem.table_name}.absolute_credit >= ' + params[:minimum_amount] + ' AND #{JournalEntryItem.table_name}.absolute_credit <= ' + params[:maximum_amount] + ') OR (#{JournalEntryItem.table_name}.absolute_debit >= ' + params[:minimum_amount] + ' AND #{JournalEntryItem.table_name}.absolute_debit <= ' + params[:maximum_amount] +'))'\n"
  code << "  end\n"

  code << "end\n"

  code.c
end

.crit_params(hash) ⇒ Object

accountancy -> crit_params


383
384
385
386
387
388
389
390
391
# File 'app/controllers/backend/base_controller.rb', line 383

def crit_params(hash)
  nh = {}
  keys = JournalEntry.state_machine.states.collect(&:name)
  keys += %i[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


394
395
396
397
398
399
# File 'app/controllers/backend/base_controller.rb', line 394

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_letter_crit(variable, _conditions = 'c', _table_name = nil) ⇒ Object


417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
# File 'app/controllers/backend/base_controller.rb', line 417

def journal_letter_crit(variable, _conditions = 'c', _table_name = nil)
  variable = "params[:#{variable}]" unless variable.is_a? String
  code = ''
  code << "unless #{variable}[:lettering_state].blank?\n"
  code << "  #{variable}[:lettering_state].each_with_index do |current_lettering_state, index|\n"
  code << "    if index == 0\n"
  code << "      c[0] << ' AND('\n"
  code << "      if current_lettering_state == 'lettered'\n"
  code << "        c[0] << '(#{JournalEntryItem.table_name}.letter IS NOT NULL AND #{JournalEntryItem.table_name}.letter NOT ILIKE ?)'\n"
  code << "        c << '%*'\n"
  code << "      end\n"

  code << "      if current_lettering_state == 'unlettered'\n"
  code << "        c[0] << '#{JournalEntryItem.table_name}.letter IS NULL'\n"
  code << "      end\n"

  code << "      if current_lettering_state == 'partially_lettered'\n"
  code << "        c[0] << '(#{JournalEntryItem.table_name}.letter IS NOT NULL AND #{JournalEntryItem.table_name}.letter ILIKE ?)'\n"
  code << "        c << '%*'\n"
  code << "      end\n"
  code << "    else\n"
  code << "      if current_lettering_state == 'lettered'\n"
  code << "        c[0] << ' OR (#{JournalEntryItem.table_name}.letter IS NOT NULL AND #{JournalEntryItem.table_name}.letter NOT ILIKE ?)'\n"
  code << "        c << '%*'\n"
  code << "      end\n"

  code << "      if current_lettering_state == 'unlettered'\n"
  code << "        c[0] << ' OR #{JournalEntryItem.table_name}.letter IS NULL'\n"
  code << "      end\n"

  code << "      if current_lettering_state == 'partially_lettered'\n"
  code << "        c[0] << ' OR (#{JournalEntryItem.table_name}.letter IS NOT NULL AND #{JournalEntryItem.table_name}.letter ILIKE ?)'\n"
  code << "        c << '%*'\n"
  code << "      end\n"
  code << "    end\n"
  code << "  end\n"
  code << "  c[0] << ')'\n"
  code << "end\n"
  code.c
end

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

accountancy -> journal_period_crit


402
403
404
405
406
407
# File 'app/controllers/backend/base_controller.rb', line 402

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


410
411
412
413
414
415
# File 'app/controllers/backend/base_controller.rb', line 410

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…]


284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'app/controllers/backend/base_controller.rb', line 284

def search_conditions(search = {}, options = {})
  conditions = options[:conditions] || 'c'
  options[:except] ||= []
  options[:filters] ||= {}
  variable ||= options[:variable] || 'params[:q]'
  tables = search.keys.reject { |t| options[:except].include? t }
  code = "\n#{conditions} = ['1=1']\n"
  columns = search.collect do |table, filtered_columns|
    filtered_columns.collect do |column|
      (table.is_a?(Symbol) ? table.to_s.classify.constantize.table_name : table).to_s +
        '.' +
        column.to_s
    end
  end.flatten
  code << "#{variable}.to_s.lower.split(/\\s+/).each do |kw|\n"
  code << "  kw = '%'+kw+'%'\n"
  filters = columns.collect do |x|
    'unaccent(' + x.to_s + '::VARCHAR) ILIKE unaccent(?)'
  end
  exp_count = columns.size
  if options[:expressions]
    filters += options[:expressions].collect do |x|
      'unaccent(' + x.to_s + ') ILIKE unaccent(?)'
    end
    exp_count += options[:expressions].count
  end
  values = '[' + (['kw'] * exp_count).join(', ') + ']'
  options[:filters].each do |k, v|
    filters << k
    v = '[' + v.join(', ') + ']' if v.is_a? Array
    values += '+' + v
  end
  if filters.any?
    code << "  #{conditions}[0] += \" AND (#{filters.join(' OR ')})\"\n"
    code << "  #{conditions} += #{values}\n"
  end
  code << "end\n"
  code << conditions.to_s
  code.c
end