wslでledger その10

# 概要
wsl(wsl2じゃない)でledgerやってみた。
練習問題、やってみた。

# 練習問題
elixirで損益計算書をtable表示せよ。

# サンプルコード

```
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 print(nil) do
        IO.puts "ok"
    end
    def print(l) do
		#IO.puts l
		l = String.trim l
		l = String.replace(l, "    ", "  ")
		l = String.replace(l, "-", "")
		s = String.split(l, "  ")
		#IO.puts Enum.at(s, 0)
        #IO.puts "#{Enum.at(s, 0)} !#{Enum.at(s, 1)} !#{Enum.at(s, 2)}<br>"
        cond do
		Enum.at(s, 1) == "Assets" ->
			Vs.set(0, Enum.at(s, 0))
		Enum.at(s, 1) == "パソコン" ->
			Vs.set(1, Enum.at(s, 0))
		Enum.at(s, 1) == "棚卸資産" ->
			Vs.set(2, Enum.at(s, 0))
		Enum.at(s, 1) == "現金" ->
			Vs.set(3, Enum.at(s, 0))
		Enum.at(s, 1) == "車" ->
			Vs.set(4, Enum.at(s, 0))
		Enum.at(s, 1) == "Equity" ->
			Vs.set(5, Enum.at(s, 0))
		Enum.at(s, 1) == "利益剰余金" ->
			Vs.set(6, Enum.at(s, 0))
		Enum.at(s, 1) == "資本金" ->
			Vs.set(7, Enum.at(s, 0))
		Enum.at(s, 1) == "Expenses" ->
			Vs.set(8, Enum.at(s, 0))
		Enum.at(s, 1) == "売上原価" ->
			Vs.set(9, Enum.at(s, 0))
		Enum.at(s, 1) == "支払利息" ->
			Vs.set(10, Enum.at(s, 0))
		Enum.at(s, 1) == "減価償却費" ->
			Vs.set(11, Enum.at(s, 0))
		Enum.at(s, 1) == "税金（費用）" ->
			Vs.set(12, Enum.at(s, 0))
		Enum.at(s, 1) == "Income:売上" ->
			Vs.set(13, Enum.at(s, 0))
		Enum.at(s, 1) == "Liabilities:借入金" ->
			Vs.set(14, Enum.at(s, 0))
		true ->
			Vs.set(15, Enum.at(s, 0))
		end
    end
    def main() do
        csv = """
               -1030  Assets
                -150    パソコン
                -150    棚卸資産
                -330    現金
                -400    車
                 300  Equity
                 100    利益剰余金
                 200    資本金
               -1270  Expenses
               -1000    売上原価
                 -20    支払利息
                -100    減価償却費
                -150    税金（費用）
                1600  Income:売上
                 400  Liabilities:借入金
--------------------
                   0
"""
        Enum.map(String.split(csv, "\n"), fn l ->
			print(l)
		end)
        {v13, _} = Integer.parse(Vs.get(13))  
        {v12, _} = Integer.parse(Vs.get(12))  
        {v11, _} = Integer.parse(Vs.get(11))  
        {v10, _} = Integer.parse(Vs.get(10))
        {v9, _} = Integer.parse(Vs.get(9))
        eig = v13 - v9
        kei = eig - v11 - v10
        tok = kei - v12
        IO.puts """
<!doctype html>
<html>
  <head>
    <style>
#sample2 th {
  color: #000;
  padding: 8px 15px;
  background: #eee;
  background:-moz-linear-gradient(#eee, #ddd 50%);
  background:-webkit-gradient(linear, 100% 0%, 100% 50%, from(#eee), to(#ddd));
  font-weight: bold;
  border-top:1px solid #aaa;
  border-bottom:1px solid #aaa;
  line-height: 120%;
  text-align: center;
  text-shadow:0 -1px 0 rgba(255,255,255,0.9);
  box-shadow:  2px 2px 1px rgba(0,0,0,0.1), 0px 1px 1px rgba(255,255,255,0.3) inset;
}
#sample2 th:first-child {
  border-left:1px solid #aaa;
  border-radius: 5px 0 0 0;	
  text-align: left;
}
#sample2 th:last-child {
  border-radius:0 5px 0 0;
  border-right:1px solid #aaa;
  box-shadow: 2px 2px 1px rgba(0,0,0,0.1);
  text-align: center;
}
#sample2 tr td {
  padding: 8px 15px;
  box-shadow: 2px 2px 1px rgba(0,0,0,0.1);
}
#sample2 tr td:first-child {
  border-left: 1px solid #aaa;
  text-align: left;
}
#sample2 tr td:last-child {
  border-right: 1px solid #aaa;
  box-shadow: 2px 2px 1px rgba(0,0,0,0.1);
  text-align: right;
}
#sample2 tr {
  background: #fff;
}
#sample2 tr:nth-child(2n+1) {
  background: #f5f5f5;
}
#sample2 tr:last-child td {
  border-bottom:1px solid #aaa;
  box-shadow: 2px 2px 1px rgba(0,0,0,0.1);
}
#sample2 tr:last-child td:first-child {
  border-radius: 0 0 0 5px;
}
#sample2 tr:last-child td:last-child {
  border-radius: 0 0 5px 0;
}
#sample2 tr:hover {
  background: #eee;
  cursor:pointer;
}
    </style>
  </head>
  <body>
    <h1>損益計算書</h1>
<table id="sample2">
  <tbody>
    <tr>
      <th>科目</th>
      <th>金額（千円）</th>
    </tr>
    <tr>
      <td>売上</td>
      <td>#{Vs.get(13)}</td>
    </tr>
    <tr>
      <td>売上原価</td>
      <td>#{Vs.get(9)}</td>
    </tr>
    <tr>
      <td>営業利益</td>
      <td>#{eig}</td>
    </tr>
    <tr>
      <td>減価償却費（車）</td>
      <td>#{Vs.get(11)}</td>
    </tr>
    <tr>
      <td>借入利息</td>
      <td>#{Vs.get(10)}</td>
    </tr>
    <tr>
      <td>経常利益</td>
      <td>#{kei}</td>
    </tr>
    <tr>
      <td>税金</td>
      <td>#{Vs.get(12)}</td>
    </tr>
    <tr>
      <td>当期利益</td>
      <td>#{tok}</td>
    </tr>
  </tbody>
</table>
  </body>
</html>
"""
	end
end
Vs.start_link
Main.main



```

# 実行結果

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/5907ef3f-3d35-3023-9389-6cb308652985.png)

# 成果物

https://paiza.io/projects/ixPHejwU01BwedsAWSfWiQ?language=elixir


以上。