Class: ComptaEditMovements
- Inherits:
-
View
- Object
- View
- ComptaEditMovements
- Defined in:
- lib/africompta/views/compta/edit_movements.rb
Instance Method Summary collapse
- #layout ⇒ Object
- #rpc_button_delete(session, data) ⇒ Object
- #rpc_button_edit(session, data) ⇒ Object
- #rpc_button_new(session, data) ⇒ Object
- #rpc_button_new_mov(session, data) ⇒ Object
- #rpc_button_save(session, data) ⇒ Object
- #rpc_list_choice_account_archive(session, data) ⇒ Object
- #rpc_list_choice_account_src(session, data) ⇒ Object
- #rpc_list_choice_movement_list(session, data) ⇒ Object
- #rpc_table_movement_list(session, data) ⇒ Object
- #rpc_update(session) ⇒ Object
- #rpc_update_view(session) ⇒ Object
-
#to_money(str) ⇒ Object
Delete all non-number characters, but also accept european 10,5 == 10.5.
- #update_accounts ⇒ Object
- #update_list(archive = nil, account = nil) ⇒ Object
Instance Method Details
#layout ⇒ Object
3 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 |
# File 'lib/africompta/views/compta/edit_movements.rb', line 3 def layout @rpc_update = true @order = 100 @functions_need = [:accounting] gui_hbox do gui_vbox :nogroup do show_entity_account :account_archive, :drop, :callback => true show_entity_account :account_src, :drop, :width => 400, :callback => true show_table :movement_list, :headings => [:Date, :Description, :Account, :Sub, :Total], :widths => [80, 300, 200, 75, 75], :height => 400, :columns => [:align_right, 0, :align_right, :align_right], :callback => :edit, :edit => [0, 1, 3] :edit, :delete, :new end gui_window :movement_edit do show_entity_account :account_dst, :drop, :width => 400 show_str :desc, :width => 300 show_int :value show_date :date :save, :new_mov, :close end end end |
#rpc_button_delete(session, data) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/africompta/views/compta/edit_movements.rb', line 76 def (session, data) if (mov = Movements.match_by_id(data._movement_list.first._element_id)).class == Movement mov.delete update_list(data._account_archive, data._account_src) end end |
#rpc_button_edit(session, data) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/africompta/views/compta/edit_movements.rb', line 59 def (session, data) if (mov = Movements.match_by_id(data._movement_list.first._element_id)).class == Movement other = mov.get_other_account(data._account_src).id reply(:window_show, :movement_edit) + reply(:update, :desc => mov.desc, :value => (mov.value*1000).to_i, :date => mov.date.to_web, :account_dst => [other]) + reply_show_hide(:save, :new_mov) end end |
#rpc_button_new(session, data) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/africompta/views/compta/edit_movements.rb', line 69 def (session, data) reply(:window_show, :movement_edit) + reply(:empty, %w( desc value )) + reply(:update, :date => Date.today.to_web) + reply_show_hide(:new_mov, :save) end |
#rpc_button_new_mov(session, data) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/africompta/views/compta/edit_movements.rb', line 31 def (session, data) if (acc_src = data._account_src).class == Account && (acc_dst = data._account_dst).class == Account value = to_money(data._value) Movements.create(data._desc, Date.from_web(data._date), value / 1000.0, acc_src, acc_dst) reply(:window_hide) + update_list(data._account_archive, data._account_src) end end |
#rpc_button_save(session, data) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/africompta/views/compta/edit_movements.rb', line 42 def (session, data) if (mov = Movements.match_by_id(data._movement_list.first._element_id)).class == Movement value = to_money(data._value) mov.desc, mov.value, mov.date = data._desc, value / 1000.0, Date.from_web(data._date) old = mov.get_other_account(data._account_src) dputs(3) { "Old account: #{old.get_path} - new account: #{data._account_dst.get_path}" } if old != data._account_dst mov.move_from_to(old, data._account_dst) end reply(:window_hide) + update_list(data._account_archive, data._account_src) end end |
#rpc_list_choice_account_archive(session, data) ⇒ Object
141 142 143 144 |
# File 'lib/africompta/views/compta/edit_movements.rb', line 141 def rpc_list_choice_account_archive(session, data) return if data._account_archive == [] update_list(data._account_archive) end |
#rpc_list_choice_account_src(session, data) ⇒ Object
136 137 138 139 |
# File 'lib/africompta/views/compta/edit_movements.rb', line 136 def rpc_list_choice_account_src(session, data) return if data._account_src == [] update_list(data._account_archive, data._account_src) end |
#rpc_list_choice_movement_list(session, data) ⇒ Object
146 147 148 149 150 151 |
# File 'lib/africompta/views/compta/edit_movements.rb', line 146 def rpc_list_choice_movement_list(session, data) if (mov = data._movement_list).class == Movement reply(:update, :desc => mov.desc, :value => (mov.value * 1000).to_i, :date => mov.date.to_web) end end |
#rpc_table_movement_list(session, data) ⇒ Object
153 154 155 156 157 158 159 160 161 |
# File 'lib/africompta/views/compta/edit_movements.rb', line 153 def rpc_table_movement_list(session, data) ml = data._movement_list.first dst = Accounts.get_by_path(ml._Account) (session, data.merge('value' => ml._Sub, 'desc' => ml._Description, 'date' => ml._Date, 'account_dst' => dst)) #if (mov = Movements.match_by_id(data._movement_list.first)).class == Movement # rpc_button_edit(session, data) #end end |
#rpc_update(session) ⇒ Object
132 133 134 |
# File 'lib/africompta/views/compta/edit_movements.rb', line 132 def rpc_update(session) reply(:update, :date => Date.today.to_web) end |
#rpc_update_view(session) ⇒ Object
126 127 128 129 130 |
# File 'lib/africompta/views/compta/edit_movements.rb', line 126 def rpc_update_view(session) super(session) + update_list + update_accounts end |
#to_money(str) ⇒ Object
Delete all non-number characters, but also accept european 10,5 == 10.5
165 166 167 |
# File 'lib/africompta/views/compta/edit_movements.rb', line 165 def to_money(str) return str.delete('^0123456789.,-').gsub(/,/, '.').to_f end |
#update_accounts ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/africompta/views/compta/edit_movements.rb', line 109 def update_accounts() if AccountRoot.actual reply(:empty_nonlists, [:account_archive, :account_src, :account_dst]) + reply(:update_silent, :account_archive => [[AccountRoot.actual.id, 'Actual']].concat( if archive = AccountRoot.archive archive.accounts.collect { |a| [a.id, a.path] }.sort_by { |a| a[1] } else [] end)) + update_list(AccountRoot.actual, AccountRoot.actual) + reply(:update, :account_src => AccountRoot.actual.listp_path, :account_dst => AccountRoot.actual.listp_path) end end |
#update_list(archive = nil, account = nil) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/africompta/views/compta/edit_movements.rb', line 83 def update_list(archive = nil, account = nil) if !(archive && account) return reply(:empty_nonlists, [:movement_list, :account_src]) + if archive reply(:update_silent, account_src: archive.listp_path) + reply(:update_silent, account_dst: archive.listp_path) else [] end end total = account.movements.inject(0.0) { |sum, m| sum + (m.get_value(account) * 1000).round }.to_i reply(:empty_nonlists, :movement_list) + reply(:update, :movement_list => account.movements.collect { |m| value = (m.get_value(account) * 1000).to_i total_old = total total -= value other = m.get_other_account(account).get_path m.date ||= Date.today [m.id, [m.date.to_web, m.desc, other, value.separator, total_old.separator]] }) end |