stocktrans_controller.ex 1.9 KB

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