lib/budgetcrmod/account_choices.rb in budgetcrmod-0.3.0 vs lib/budgetcrmod/account_choices.rb in budgetcrmod-0.4.0
- old
+ new
@@ -5,19 +5,29 @@
# and the other can be either physical or a virtual account of the users choice,
# e.g. Food or Petrol or Energy, or maybe WeeklyBudget and LongTermBudget etc.
def external_account
return @external_account if @external_account
ext_account = false
+ unless @runner
+ raise "No runner for " + data_line
+ end
Dir.chdir(@runner.root_folder) do
chosen = false
Hash.phoenix('account_choices.rb') do |choices_hash|
- if choices_hash[data_line]
+ if choices_hash[signature]
+ chosen = choices_hash[signature][:external_account]
+ elsif choices_hash[data_line]
#choices_hash[data_line][:external_account] =
#choices_hash[data_line][:external_account].to_sym #fixes earlier bug
#choices_hash[data_line][:sub_account] =
#choices_hash[data_line][:sub_account].to_sym #fixes earlier bug
chosen = choices_hash[data_line][:external_account]
+ choices_hash[signature] = choices_hash[data_line]
+ choices_hash.delete(data_line)
+ elsif choices_hash[old_data_line]
+ chosen = choices_hash[old_data_line][:external_account]
+ choices_hash[signature] = choices_hash[old_data_line]
end
end
return @external_account = chosen if chosen
chosen = false
sym = nil
@@ -27,13 +37,15 @@
#choices = account_arr.size.times.map{|i| [i,account_arr[i][:name]]}
choices = account_hash.map{|k,v| [v[:sym], k]}.to_h
puts Terminal.default_colour
puts
puts "-" * data_line.size
- puts data_line
+ puts signature.inspect
puts "-" * data_line.size
puts
+ puts "Account: " + account
+ puts
puts choices.inspect
puts
puts "Please choose from the above external accounts for this transaction."
puts "If you wish to add a new account type 0. To quit type q"
puts "To start again for this transaction, type z"
@@ -115,11 +127,11 @@
end
end
end
next if not chosen
Hash.phoenix('account_choices.rb') do |choices_hash|
- choices_hash[data_line] = {external_account: ext_account, sub_account: chosen}
+ choices_hash[signature] = {external_account: ext_account, sub_account: chosen}
end
end #while not chosen
end
ext_account
@@ -132,12 +144,13 @@
# on the users preferred way of organising things.
# The sub_accounts are primarily a labelling exercise, but done
# well can be very helpful in showing a breakdown of expenditure.
def sub_account
return @sub_account if @sub_account
+ puts "SIGNATURE ", signature.inspect
Dir.chdir(@runner.root_folder) do
external_account until (
- choices = Hash.phoenix('account_choices.rb'){|choices_hash| choices_hash[data_line]}
+ choices = Hash.phoenix('account_choices.rb'){|choices_hash| choices_hash[signature]}
p [choices, data_line]
) and choices[:sub_account]
@sub_account = choices[:sub_account]
end
end