I’m trying to add a new value to data tables in a dictionary, but when I run this.
using DataFrames
general_ledger=Dict(
"dividends" => DataFrame(
date=Vector{String}(),
debit=Vector{Int64}(),
credit=Vector{Int64}()),
"expenses" => DataFrame(
date=Vector{String}(),
debit=Vector{Int64}(),
credit=Vector{Int64}()),
"assets" => DataFrame(
date=Vector{String}(),
debit=Vector{Int64}(),
credit=Vector{Int64}()),
"liabilities" => DataFrame(
date=Vector{String}(),
debit=Vector{Int64}(),
credit=Vector{Int64}()),
"equity" => DataFrame(
date=Vector{String}(),
debit=Vector{Int64}(),
credit=Vector{Int64}()),
"revenue" => DataFrame(
date=Vector{String}(),
debit=Vector{Int64}(),
credit=Vector{Int64}()),
)
function ledgertransaction!(
ledger,
ledger_name,
date,
credit_account,
credit_amount,
debit_account,
debit_amount
)
if length(date) == 0
return (false,"Error -- no date entered")
elseif !( credit_account in names(ledger) )
return (false, "Error -- credit account not found.")
elseif !( debit_account in names(ledger) )
return (false, "Error -- debit account not found")
elseif credit_amount-debit_amount != 0
return (false,"Error -- credit and debit must match." )
elseif credit_account == debit_account
return (false, "Error -- credit and debit must be different accounts")
else
default_values=Dict("date"=>"",credit_account=>0,debit_account=>0)
spec = Dict(
"date" => date,
credit_account => credit_amount,
debit_account => debit_amount)
row = merge(default_values, spec)
push!(ledger,row)
return (true, "there are no errors")
end
end
function add2ledger!(
journal_entry,
general_ledger,
ledger_name,
date,
credit_account,
credit_amount,
debit_account,
debit_amount
)
if !( ledger_name in keys(general_ledger) )
return (false, "Error -- "*ledger_name*" not found")
else
ledger=general_ledger[ledger_name]
return ledgertransaction!(ledger,ledger_name,date,credit_account,credit_amount,debit_account,debit_amount)
end
end
#when I try to execute the code,
add2ledger!(journal_entry,general_ledger,"expenses","12 Jun 2021","debit",100,"credit",100)
I get
(false, Error–credit account not found)