ptrans_controller.ex 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. defmodule GiomWeb.PtransController do
  2. use GiomWeb, :controller
  3. alias Giom.Accounting
  4. alias Giom.Accounting.Ptrans
  5. def index(conn, _params) do
  6. ptrans = Accounting.list_ptrans()
  7. render(conn, "index.html", ptrans: ptrans)
  8. end
  9. def new(conn, _params) do
  10. changeset = Accounting.change_ptrans(%Ptrans{})
  11. render(conn, "new.html", changeset: changeset)
  12. end
  13. def create(conn, %{"ptrans" => ptrans_params}) do
  14. case Accounting.create_ptrans(ptrans_params) do
  15. {:ok, ptrans} ->
  16. conn
  17. |> put_flash(:info, "Ptrans created successfully.")
  18. |> redirect(to: ptrans_path(conn, :show, ptrans))
  19. {:error, %Ecto.Changeset{} = changeset} ->
  20. render(conn, "new.html", changeset: changeset)
  21. end
  22. end
  23. def show(conn, %{"id" => id}) do
  24. ptrans = Accounting.get_ptrans!(id)
  25. render(conn, "show.html", ptrans: ptrans)
  26. end
  27. def edit(conn, %{"id" => id}) do
  28. ptrans = Accounting.get_ptrans!(id)
  29. changeset = Accounting.change_ptrans(ptrans)
  30. render(conn, "edit.html", ptrans: ptrans, changeset: changeset)
  31. end
  32. def update(conn, %{"id" => id, "ptrans" => ptrans_params}) do
  33. ptrans = Accounting.get_ptrans!(id)
  34. case Accounting.update_ptrans(ptrans, ptrans_params) do
  35. {:ok, ptrans} ->
  36. conn
  37. |> put_flash(:info, "Ptrans updated successfully.")
  38. |> redirect(to: ptrans_path(conn, :show, ptrans))
  39. {:error, %Ecto.Changeset{} = changeset} ->
  40. render(conn, "edit.html", ptrans: ptrans, changeset: changeset)
  41. end
  42. end
  43. def delete(conn, %{"id" => id}) do
  44. ptrans = Accounting.get_ptrans!(id)
  45. {:ok, _ptrans} = Accounting.delete_ptrans(ptrans)
  46. conn
  47. |> put_flash(:info, "Ptrans deleted successfully.")
  48. |> redirect(to: ptrans_path(conn, :index))
  49. end
  50. end