Module: Backend::JournalsHelper

Defined in:
app/helpers/backend/journals_helper.rb

Overview

License

Ekylibre - Simple agricultural ERP Copyright (C) 2008-2011 Brice Texier, Thibaud Merigon

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <www.gnu.org/licenses/>.

Instance Method Summary collapse

Instance Method Details

#journal_entries_states_critObject

Create a widget to select states of entries (and entry items)


88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/helpers/backend/journals_helper.rb', line 88

def journal_entries_states_crit
  code = ''
  code << (:label, :journal_entries_states.tl)
  states = JournalEntry.states
  params[:states] = {} unless params[:states].is_a? Hash
  no_state = !states.detect { |x| params[:states].key?(x) }
  for state in states
    key = state.to_s
    name = "states[#{key}]"
    id = "states_#{key}"
    if active = (params[:states][key] == '1' || no_state)
      params[:states][key] = '1'
    else
      params[:states].delete(key)
    end
    code << ' ' << check_box_tag(name, '1', active, id: id)
    code << ' ' << (:label, JournalEntry.state_label(state), for: id)
  end
  code.html_safe
end

#journal_period_crit(*args) ⇒ Object

Create a widget with all the possible periods


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/helpers/backend/journals_helper.rb', line 34

def journal_period_crit(*args)
  options = (args[-1].is_a?(Hash) ? args.delete_at(-1) : {})
  name = args.shift || :period
  value = args.shift
  configuration = { custom: :interval }.merge(options)
  configuration[:id] ||= name.to_s.gsub(/\W+/, '_').gsub(/(^_|_$)/, '')
  value ||= params[name] || options[:default]
  list = []
  list << [:all_periods.tl, 'all']
  for year in FinancialYear.reorder(started_on: :desc)
    list << [year.code, year.started_on.to_s << '_' << year.stopped_on.to_s]
    list2 = []
    date = year.started_on
    while date < year.stopped_on && date < Time.zone.today
      date2 = date.end_of_month
      list2 << [:month_period.tl(year: date.year, month: 'date.month_names'.t[date.month], code: year.code), date.to_s << '_' << date2.to_s]
      date = date2 + 1
    end
    list += list2.reverse
  end
  code = ''
  code << (:label, options[:label] || :period.tl, for: configuration[:id]) + ' '
  fy = FinancialYear.current
  params[:period] = value ||= :all # (fy ? fy.started_on.to_s + "_" + fy.stopped_on.to_s : :all)
  custom_id = "#{configuration[:id]}_#{configuration[:custom]}"
  toggle_method = "toggle#{custom_id.camelcase}"
  if configuration[:custom]
    params[:started_on] = begin
                            params[:started_on].to_date
                          rescue
                            (fy ? fy.started_on : Time.zone.today)
                          end
    params[:stopped_on] = begin
                            params[:stopped_on].to_date
                          rescue
                            (fy ? fy.stopped_on : Time.zone.today)
                          end
    params[:stopped_on] = params[:started_on] if params[:started_on] > params[:stopped_on]
    list.insert(0, [configuration[:custom].tl, configuration[:custom]])
  end

  if replacement = options.delete(:include_blank)
    list.insert(0, [(replacement.is_a?(Symbol) ? tl(replacement) : replacement.to_s), ''])
  end

  code << select_tag(name, options_for_select(list, value), :id => configuration[:id], 'data-show-value' => "##{configuration[:id]}_")

  if configuration[:custom]
    code << ' ' << (:span, :manual_period.tl(start: date_field_tag(:started_on, params[:started_on], size: 10), finish: date_field_tag(:stopped_on, params[:stopped_on], size: 10)).html_safe, id: custom_id)
  end
  code.html_safe
end

#journal_view_tagObject

Show the 3 modes of view for a journal


25
26
27
28
29
30
31
# File 'app/helpers/backend/journals_helper.rb', line 25

def journal_view_tag
  code = (:dt, :view.tl)
  for mode in controller.journal_views
    code << (:dd, link_to(h("journal_view.#{mode}".tl(default: ["labels.#{mode}".to_sym, mode.to_s.humanize])), params.merge(view: mode)), (@journal_view == mode ? { class: :active } : nil)) # content_tag(:i) + " " +
  end
  (:dl, code, id: 'journal-views')
end

#journals_critObject

Create a widget to select some journals


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'app/helpers/backend/journals_helper.rb', line 110

def journals_crit
  code = ''
  field = :journals
  code << (:label, Backend::JournalsController.human_action_name(:index))
  journals = Journal.all
  params[field] = {} unless params[field].is_a? Hash
  no_journal = !journals.detect { |x| params[field].key?(x.id.to_s) }
  for journal in journals
    key = journal.id.to_s
    name = "#{field}[#{key}]"
    id = "#{field}_#{key}"
    if active = (params[field][key] == '1' || no_journal)
      params[field][key] = '1'
    else
      params[field].delete(key)
    end
    code << ' ' << check_box_tag(name, '1', active, id: id)
    code << ' ' << (:label, journal.name, for: id)
  end
  code.html_safe
end

#journals_tagObject


20
21
22
# File 'app/helpers/backend/journals_helper.rb', line 20

def journals_tag
  render partial: 'backend/journals/index'
end