defmodule App.Workers.YufigFile do
require Logger
def generate() do
entry = app.Transactions.related_rev_entry("202009172909000003")
mapping = yufig_entry(entry)
template = read_file()
template
|> :bbmustache.render(mapping, key_type: :binary)
|> PdfGenerator.generate_binary!()
|> (&File.write("#{set_pdf_path(entry)}.pdf", &1)).()
end
defp yufig_entry(entry) do
%{
"checker" => entry.checker || "N/A",
"date" => to_string(Timex.today()),
"drawer" => entry.ben_name || "N/A",
}
end
defp read_file() do
set_template_path()
|> File.read!()
end
defp set_template_path(), do: "lib/cts_web/templates/outward/yufig_file.html.eex"
defp set_pdf_path(entry), do: "D:/download/#{set_pdf_name(entry)}"
defp set_pdf_name(entry) do
[entry.destin_ba_code, entry.checker, to_string(Timex.today())]
|> Enum.join("_")
end
end
Source code is usually not bundled within realeses.
If you need to access the template during application runtime you should move it to priv
and use either Application.app_dir(:app_name, "priv/path/to/file")
or Path.join(:code.priv_dir(:app_name), "path/to/file")
.
1 Like
thanks it has worked