Skip to content

Commit

Permalink
Release 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
machadovilaca committed Jan 31, 2021
2 parents 47ebb02 + e5ea495 commit 5ba8720
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
20 changes: 15 additions & 5 deletions assets/js/charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import $ from "jquery";

let delta = 'M';
let graph_type = "sum_invoices";
let time = 7;
let time = 365;
let is_count = true;
let chart = null;
let prev_chart = null;
let pie_chart = null;

function lineChart(label_values, result){
if(chart != null){
if (chart != null) {
chart.destroy();
}

Expand All @@ -27,10 +29,14 @@ function lineChart(label_values, result){
}

function barChart(label_values, data){
if (prev_chart != null) {
prev_chart.destroy();
}

$("#progress").hide();
$("#prevision").show();

new Chart(document.getElementById("lineChartPrevisions"), {
prev_chart = new Chart(document.getElementById("lineChartPrevisions"), {
type: 'bar',
data: {
labels: label_values,
Expand All @@ -48,9 +54,13 @@ function barChart(label_values, data){
}

function pieChart(costs, earnings) {
if (pie_chart != null) {
pie_chart.destroy();
}

$("#pieChartError").hide();

new Chart(document.getElementById("pieChart"), {
pie_chart = new Chart(document.getElementById("pieChart"), {
type: 'doughnut',
responsive: true,
mantainAspectRatio: false,
Expand Down Expand Up @@ -160,7 +170,7 @@ function graphicTotals(data) {
gains = data.gains_values[index];
}
});

pieChart(costs, gains);
}

Expand Down
5 changes: 4 additions & 1 deletion lib/infin/companies.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ defmodule Infin.Companies do
"""
def get_company_by_nif!(nif), do: Repo.get_by!(Company, nif: nif)

def get_company_by_nif(nif), do: Repo.get_by(Company, nif: nif)
def get_company_by_nif(nif) do
query = from(c in Company, where: c.nif == ^nif, preload: :users)
Repo.one(query)
end

@doc """
Creates a company.
Expand Down
6 changes: 6 additions & 0 deletions lib/infin_web/controllers/budget_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ defmodule InfinWeb.BudgetController do

budget_params = Map.replace!(budget_params, "value", value)

if is_nil(budget_params["category_id"]) do
conn
|> put_flash(:error, "Please associate a category to the budget.")
|> redirect(to: Routes.budget_path(conn, :new))
end

budget_params =
Map.replace!(
budget_params,
Expand Down
20 changes: 20 additions & 0 deletions lib/infin_web/controllers/user_registration_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,33 @@ defmodule InfinWeb.UserRegistrationController do
alias Infin.Accounts
alias Infin.Accounts.User
alias InfinWeb.UserAuth
alias Infin.Companies

def new(conn, _params) do
changeset = Accounts.change_user_registration(%User{})
render(conn, "new.html", changeset: changeset)
end

def create(conn, %{"user" => user_params}) do
company = Companies.get_company_by_nif(user_params["company"]["nif"])
if (not is_nil(company)) and company.users == [] do
user_params = Map.put(user_params, "company_id", company.id)
case Accounts.add_user(user_params) do
{:ok, user} ->
{:ok, _} =
Accounts.deliver_user_confirmation_instructions(
user,
&Routes.user_confirmation_url(conn, :confirm, &1)
)

conn
|> put_flash(:info, "User created successfully.")
|> UserAuth.log_in_user(user)

{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
case Accounts.register_user(user_params) do
{:ok, user} ->
{:ok, _} =
Expand Down
2 changes: 1 addition & 1 deletion lib/infin_web/live/dashboard/graph.html.leex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<div class="column">
<div class="tile is-child box">
<div class="is-info is-light has-text-centered" style="height: 450px">
<p class="is-size-4">Year Costs and earnings</p>
<p class="is-size-4">Year Costs and Earnings</p>
<hr>
<div class="chart-container is-inline-block">
<p id="pieChartError"> No data available </p>
Expand Down

0 comments on commit 5ba8720

Please sign in to comment.