概要
wsl(wsl2じゃない)でledgerやってみた。
練習問題、やってみた。
練習問題
弥生会計のエクスポートしたcsvを、elixirでledgerが読めるように変換せよ。
サンプルコード
defmodule Vs do
use Agent
def start_link() do
Agent.start_link(fn ->
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
end, name: __MODULE__)
end
def get(p) do
Agent.get(__MODULE__, fn v ->
Enum.at(v, p)
end)
end
def set(p, x) do
Agent.update(__MODULE__, fn v ->
List.update_at(v, p, fn _ ->
x
end)
end)
end
end
defmodule Main do
def main() do
csv = """
"2000",139,"","H.21/01/23","普通預金","みずほ銀行","","対象外",842,0,"受取利息","","","非課売上",842,0,"","","",0,"","","0","0","no"
"2000",142,"","H.21/01/31","普通預金","みずほ銀行","","対象外",388500,0,"売上高","","","課税売上込",388500,0,"商品販売","","",0,"","","0","0","no"
"2000",225,"","H.21/02/14","水道光熱費","","","課対仕入込",2046,0,"現金","","","対象外",2046,0,"電気料金","","",0,"","","0","0","no"
"2000",226,"","H.21/02/15","通信費","","","課対仕入込",1501,0,"現金","","","対象外",1501,0,"電話料金","","",0,"","","0","0","no"
"2000",227,"","H.21/02/16","水道光熱費","","","課対仕入込",1058,0,"現金","","","対象外",1058,0,"水道料金","","",0,"","","0","0","no"
"2000",87,"","H.21/02/17","消耗品費","","","課対仕入込",980,0,"現金","","","対象外",980,0,"事務商品購入","","",0,"","","0","0","no"
"2000",112,"","H.21/02/22","旅費交通費","","","課対仕入込",4730,0,"現金","","","対象外",4730,0,"通勤定期代","","",0,"","","0","0","no"
"""
Enum.map(String.split(csv, "\n"), fn l ->
print(l)
end)
end
def print(nil) do
IO.puts "ok"
end
def print("") do
end
def print(l) do
l = String.replace(l, "H.", "20")
l = String.replace(l, "\"", "")
s = String.split(l, ",")
#IO.puts Enum.at(s, 4)
cond do
Enum.at(s, 4) == "普通預金" ->
Vs.set(0, "Assets:" <> Enum.at(s, 4))
Vs.set(2, "-")
Enum.at(s, 4) == "水道光熱費" ->
Vs.set(0, "Expenses:" <> Enum.at(s, 4))
Vs.set(2, "")
Enum.at(s, 4) == "通信費" ->
Vs.set(0, "Expenses:" <> Enum.at(s, 4))
Vs.set(2, "")
Enum.at(s, 4) == "消耗品費" ->
Vs.set(0, "Expenses:" <> Enum.at(s, 4))
Vs.set(2, "")
Enum.at(s, 4) == "旅費交通費" ->
Vs.set(0, "Expenses:" <> Enum.at(s, 4))
Vs.set(2, "")
true ->
Vs.set(0, "ok0")
end
cond do
Enum.at(s, 10) == "受取利息" ->
Vs.set(1, "Income:" <> Enum.at(s, 10))
Enum.at(s, 10) == "売上高" ->
Vs.set(1, "Income:" <> Enum.at(s, 10))
Enum.at(s, 10) == "現金" ->
Vs.set(1, "Assets:" <> Enum.at(s, 10))
true ->
Vs.set(1, "ok1")
end
IO.puts "#{Enum.at(s, 3)} #{Enum.at(s, 16)}\n #{Vs.get(0)} #{Vs.get(2)}#{Enum.at(s, 8)} JPY\n #{Vs.get(1)}"
end
end
Vs.start_link
Main.main
実行結果
2021/01/23
Assets:普通預金 -842 JPY
Income:受取利息
2021/01/31 商品販売
Assets:普通預金 -388500 JPY
Income:売上高
2021/02/14 電気料金
Expenses:水道光熱費 2046 JPY
Assets:現金
2021/02/15 電話料金
Expenses:通信費 1501 JPY
Assets:現金
2021/02/16 水道料金
Expenses:水道光熱費 1058 JPY
Assets:現金
2021/02/17 事務商品購入
Expenses:消耗品費 980 JPY
Assets:現金
2021/02/22 通勤定期代
Expenses:旅費交通費 4730 JPY
Assets:現金
成果物
以上。