Please check the following complete example:
using DataFrames, DecFP
starting_balance=starting_balance=Dict(
"debit"=>Dict(
"drawings"=>Dict(), #debit normal ledgers
"expenses"=>Dict(),
"assets"=>Dict()),
"credit"=>Dict(
"liabilities"=>Dict(),
"equity"=>Dict(),
"revenue"=>Dict(),
"retained"=> Dict( #Closing Accounts - No Balance Until Temp Accounts Closed
"Retained Earnings"=>DataFrame(
date=Vector{String}(),
memo=Vector{String}(),
debit=Vector{Dec64}(),
credit=Vector{Dec64}(),
balance=Vector{Dec64}()),
"Gross Income"=>DataFrame(
date=Vector{String}(),
memo=Vector{String}(),
debit=Vector{Dec64}(),
credit=Vector{Dec64}(),
balance=Vector{Dec64}()),
"Gross Expenses"=>DataFrame(
date=Vector{String}(),
memo=Vector{String}(),
debit=Vector{Dec64}(),
credit=Vector{Dec64}(),
balance=Vector{Dec64}()),
"Net Income"=>DataFrame(
date=Vector{String}(),
memo=Vector{String}(),
debit=Vector{Dec64}(),
credit=Vector{Dec64}(),
balance=Vector{Dec64}()),
"Total Drawings"=>DataFrame(
date=Vector{String}(),
memo=Vector{String}(),
debit=Vector{Dec64}(),
credit=Vector{Dec64}(),
balance=Vector{Dec64}())))
)
function transaction(memo, date,
debit_ledger_entries=[], debit_account_entries=[],
debit_amount_entries=[], credit_ledger_entries=[],
credit_account_entries=[], credit_amount_entries=[],
general_ledger=general_ledger)
if length(credit_ledger_entries) != length(credit_account_entries)
return "Error--there must be the same number of credit legders and accounts"
end
if length(credit_account_entries) != length(credit_amount_entries)
return "Error-- each account needs a value and vice versa"
end
if length(debit_ledger_entries) != length(debit_account_entries)
return "Error--there must be the same number of debit legders and accounts"
end
if length(debit_account_entries) != length(debit_amount_entries)
return "Error-- each debit account needs a value and vice versa"
end
if (round(Dec64(sum(debit_amount_entries)),digits=2)
-round(Dec64(sum(credit_amount_entries)),digits=2))!=0
return "Error-total credits does not match total debits"
end
journal_entry=DataFrame(Date=[date],
DebitedAccounts=[""],
CreditedAccounts=[""],
Debits=Vector{Dec64}([0.00]),
Credits=Vector{Dec64}([0.00]),
Balance=Vector{Dec64}([0.00]))
i=1
while i <= length(debit_amount_entries)
if !haskey(general_ledger["debit"], debit_ledger_entries[i]) ||
!haskey(general_ledger["credit"], debit_ledger_entries[i])
return "Error -- "*debit_ledger_entries[i]*" not found"
end
if !haskey(general_ledger["debit"][debit_ledger_entries[i]], credit_account_entries[i]) ||
!haskey(general_ledger["credit"][debit_ledger_entries[i]], credit_account_entries[i])
return "Error -- "*debit_account_entries[i]*" not found in"*debit_ledger_entries[i]*"."
end
debit_amount_entries[i]=round(Dec64(debit_amount_entries[i]),digits=2)
i+=1
end
i=1
while i <= length(credit_amount_entries)
if !haskey(general_ledger["debit"], credit_ledger_entries[i]) ||
!haskey(general_ledger["credit"], credit_ledger_entries[i])
return "Error -- "*credit_ledger_entries[i]*" not found"
end
if !haskey(general_ledger["debit"][credit_ledger_entries[i]], credit_account_entries[i]) ||
!haskey(general_ledger["credit"][credit_ledger_entries[i]], credit_account_entries[i])
return "Error -- "*credit_account_entries[i]*" not found in"*credit_ledger_entries[i]*"."
end
credit_amount_entries[i]=round(Dec64(credit_amount_entries[i]),digits=2)
i+=1
end
i=1
while i <= length(debit_ledger_entries)
debit_ledger_name=debit_ledger_entries[i]
debit_amount = round(debit_amount_entries[i];digits=2)
debit_account=debit_account_entries[i]
calc_debit_balance!(
general_ledger,
journal_entry,
date,
debit_ledger_name,
debit_account,
debit_amount,
memo)
i+=1
end
i=1
while i <= length(credit_ledger_entries)
credit_ledger_name=credit_ledger_entries[i]
credit_account=credit_account_entries[i]
credit_amount=floor(credit_amount_entries[i];digits=2)
calc_credit_balance!(
general_ledger,
journal_entry,
date,
credit_ledger_name,
credit_account,
credit_amount,
memo)
i+=1
end
push!(journal_entry,["","Total","Transaction",
round(sum(journal_entry.Debits); digits=2),
round(sum(journal_entry.Credits); digits=2),0])
return (journal_entry, memo)
end;
transaction("Weird Example", "Jan 2 2021",
["retained"], ["Gross Income"], [100.00], ["retained"],
["Net Income"], [100.00], starting_balance)
Fixing the questionable logic changed the message to
"Error -- retained not found"
I believe this is intended. I’ll now debug the problem.