Class: ReportComptaExecutive

Inherits:
View
  • Object
show all
Includes:
PrintButton
Defined in:
lib/africompta/views/report/compta_executive.rb

Instance Method Summary collapse

Instance Method Details

#button_account(session, name, data) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/africompta/views/report/compta_executive.rb', line 95

def (session, name, data)
  return if data._reports == []

  case name
    when /add_win/
      data._reports.accounts = data._reports.accounts +
          [ReportAccounts.create(data)]
      update_report(data._reports) +
          reply(:window_hide)
    when /add/
      reply(:window_show, :win_account) +
           +
          update_root +
          reply(:update, :level => "1") +
          reply_show_hide(:account_add_win, :account_save_win)
    when /del/
      return if data._accounts == []
      data._reports.accounts = data._reports.accounts.reject { |a|
        a == data._accounts
      }
      update_report(data._reports)
    when /edit/
      return if data._accounts == []
      reply(:window_show, :win_account) +
          update_root(data._accounts.root) +
          (data._accounts.root, data._accounts.) +
          reply(:update, :level => data._accounts.level) +
          reply_show_hide(:account_save_win, :account_add_win)
    when /save_win/
      data._accounts.data_set_hash(data)
      update_report(data._reports) +
          reply(:window_hide)
    when /up/
      accs = data._reports.accounts
      if (index = accs.index(data._accounts)) > 0
        accs[index - 1], accs[index] = accs[index], accs[index - 1]
      end
      data._reports.accounts = accs
      update_report(data._reports, data._accounts)
    when /down/
      accs = data._reports.accounts
      if (index = accs.index(data._accounts)) < accs.length - 1
        accs[index + 1], accs[index] = accs[index], accs[index + 1]
      end
      data._reports.accounts = accs
      update_report(data._reports, data._accounts)
  end
end

#button_report(session, name, data) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/africompta/views/report/compta_executive.rb', line 144

def button_report(session, name, data)
  case name
    when /add_win/
      if data._report_name.to_s.length > 0
        Reports.create(:name => data._report_name, :accounts => [])
      end
      reply(:window_hide) +
          update_reports
    when /add/
      reply(:window_show, :win_report) +
          reply(:empty, :report_name)
    when /del/
      data._reports != [] and data._reports.delete
      rpc_update(session)
  end
end

#layoutObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/africompta/views/report/compta_executive.rb', line 4

def layout
  @order = 20
  @update = true
  @functions_need = [:accounting]

  gui_hboxg do
    gui_vbox :nogroup do
      gui_vboxg :nogroup do
        show_entity_report_all :reports, :single, :name, :callback => true,
                               :flexheight => 1
        show_button :report_add, :report_delete
      end
      gui_vbox :nogroup do
        show_date :start
        show_int :months
        show_print :print
      end
    end
    gui_vboxg :nogroup do
      show_str :name
      show_entity_reportAccount :accounts, :single,
                                :flexheight => 1, :width => 300
      show_button :account_add, :account_del, :account_edit
      show_button :account_up, :account_down
    end

    gui_window :win_account do
      gui_vbox :nogroup do
         :root, :drop, :width => 400,
                            :callback => true
         :account, :drop
        show_int :level
        show_button :account_add_win, :account_save_win, :close
      end
    end

    gui_window :win_report do
      show_str :report_name
      show_button :report_add_win, :close
    end

    gui_window :progress do
      show_html :progress_txt
      show_button :report_cancel
    end

    window_print_status
  end
end

#rpc_button(session, name, data) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/africompta/views/report/compta_executive.rb', line 161

def rpc_button(session, name, data)
  case name
    when /^account_(.*)/
      (session, $~[1], data)
    when /^report_(.*)/
      button_report(session, $~[1], data)
    when /print/
      if data._reports.class == Report
        start_thread(session, data)
        reply(:auto_update, -1) +
            reply(:update, progress_txt: 'Starting checking') +
            reply(:window_show, :progress) +
            rpc_print(session, :print, data)
      end
    when /close/
      reply(:window_hide)
    when /report_cancel/
      dputs(2){ "Killing thread #{session.s_data._report_ce_thread}"}
      if thr = session.s_data._report_ce_thread
        thr.kill
      end
      reply(:window_hide) +
          reply(:auto_update, 0)
  end
end

#rpc_button_report_add(session, data) ⇒ Object



54
55
56
# File 'lib/africompta/views/report/compta_executive.rb', line 54

def rpc_button_report_add(session, data)
  reply(:window_show, :print_status)
end

#rpc_list_choice_reports(session, data) ⇒ Object



211
212
213
214
215
# File 'lib/africompta/views/report/compta_executive.rb', line 211

def rpc_list_choice_reports(session, data)
  return if data._reports == []
  reply(:empty, :accounts) +
      update_report(data._reports)
end

#rpc_list_choice_root(session, data) ⇒ Object



217
218
219
220
# File 'lib/africompta/views/report/compta_executive.rb', line 217

def rpc_list_choice_root(session, data)
  return if data._root == []
  (data._root)
end

#rpc_update(session) ⇒ Object



85
86
87
88
89
90
91
92
93
# File 'lib/africompta/views/report/compta_executive.rb', line 85

def rpc_update(session)
  td = Date.today
  # Start in beginning of semester
  start = Date.new(td.year, (td.month / 7.0).floor * 6 + 1)
  update_reports +
      reply(:update, :start => start.to_web) +
      reply(:update, :months => 6) +
      reply_print(session)
end

#rpc_update_with_values(session, data) ⇒ Object



198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/africompta/views/report/compta_executive.rb', line 198

def rpc_update_with_values(session, data)
  report = data._reports
  if report_ce = session.s_data._report_ce
    return reply(:window_hide) +
        reply(:auto_update, 0) +
        send_printer_reply(session, :print, data, report_ce)
  else
    return reply(:update, :progress_txt =>
                            "Accounts done: #{(report.print_accounts * 100).floor}%<br>" +
                                "Calculating: #{report.}")
  end
end

#start_thread(session, data) ⇒ Object



187
188
189
190
191
192
193
194
195
196
# File 'lib/africompta/views/report/compta_executive.rb', line 187

def start_thread(session, data)
  session.s_data._report_ce = nil
  session.s_data._report_ce_thread = Thread.start {
    System.rescue_all do
      session.s_data._report_ce = data._reports.print_pdf_monthly(
          Date.from_web(data._start), data._months.to_i)
    end
    dputs(2){ 'Thread finished'}
  }
end

#update_account(root = AccountRoot.actual, account = nil) ⇒ Object



58
59
60
61
62
# File 'lib/africompta/views/report/compta_executive.rb', line 58

def (root = AccountRoot.actual,  = nil)
  reply(:empty, :account) +
      reply(:update, :account => root.listp_path) +
      reply(:update, :account => [(.class == Account) ? .id : 0])
end

#update_report(report, account = nil) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/africompta/views/report/compta_executive.rb', line 77

def update_report(report,  = nil)
  reply(:empty, :accounts) +
      reply(:update, :name => report.name) +
      reply(:update, :accounts => report.listp_accounts) +
      reply(:update, :accounts => (.class == ReportAccount) ?
                       [.id] : nil)
end

#update_reportsObject



72
73
74
75
# File 'lib/africompta/views/report/compta_executive.rb', line 72

def update_reports
  reply(:empty, :reports) +
      reply(:update, :reports => Reports.listp_name)
end

#update_root(root = AccountRoot.actual) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/africompta/views/report/compta_executive.rb', line 64

def update_root(root = AccountRoot.actual)
  roots = [[AccountRoot.actual.id, 'Actual']]
  archive = AccountRoot.archive and roots.concat(archive.listp_path(1)[1..-1])
  reply(:empty, :root) +
      reply(:update_silent, :root =>
                              roots.concat([(root.class == Account) ? root.id : 0]))
end