2009-01-15 12:14:01 +01:00
|
|
|
class HomeController < ApplicationController
|
|
|
|
def index
|
|
|
|
# unaccepted tasks
|
2017-10-20 00:59:56 +02:00
|
|
|
@unaccepted_tasks = Task.order(:due_date).unaccepted_tasks_for(current_user)
|
2009-01-15 12:14:01 +01:00
|
|
|
# task in next week
|
2017-10-20 00:59:56 +02:00
|
|
|
@next_tasks = Task.order(:due_date).next_assigned_tasks_for(current_user)
|
2009-01-15 12:14:01 +01:00
|
|
|
# count tasks with no responsible person
|
|
|
|
# tasks for groups the current user is not a member are ignored
|
2017-10-20 01:01:12 +02:00
|
|
|
@unassigned_tasks = Task.order(:due_date).next_unassigned_tasks_for(current_user)
|
2009-01-15 12:14:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def profile
|
|
|
|
end
|
|
|
|
|
2019-11-11 12:09:18 +01:00
|
|
|
def reference_calculator
|
|
|
|
if current_user.ordergroup
|
|
|
|
@types = FinancialTransactionType.with_name_short.order(:name)
|
|
|
|
@bank_accounts = @types.includes(:bank_account).map(&:bank_account).uniq.compact
|
2020-08-01 17:37:43 +02:00
|
|
|
@bank_accounts = [BankAccount.last] if @bank_accounts.empty?
|
2019-11-11 12:09:18 +01:00
|
|
|
else
|
|
|
|
redirect_to root_url, alert: I18n.t('group_orders.errors.no_member')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-15 12:14:01 +01:00
|
|
|
def update_profile
|
2022-10-13 18:25:52 +02:00
|
|
|
if @current_user.update(user_params)
|
|
|
|
@current_user.ordergroup.update(ordergroup_params) if ordergroup_params
|
2013-06-14 02:39:25 +02:00
|
|
|
session[:locale] = @current_user.locale
|
2013-02-04 02:12:24 +01:00
|
|
|
redirect_to my_profile_url, notice: I18n.t('home.changes_saved')
|
2009-01-15 12:14:01 +01:00
|
|
|
else
|
2012-11-12 09:03:23 +01:00
|
|
|
render :profile
|
2009-01-15 12:14:01 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def ordergroup
|
|
|
|
@user = @current_user
|
2009-02-01 20:56:23 +01:00
|
|
|
@ordergroup = @user.ordergroup
|
2009-01-15 12:14:01 +01:00
|
|
|
|
2009-08-04 13:05:37 +02:00
|
|
|
unless @ordergroup.nil?
|
|
|
|
|
2020-08-12 13:38:18 +02:00
|
|
|
@ordergroup = Ordergroup.include_transaction_class_sum.find(@ordergroup.id)
|
2017-03-04 14:15:39 +01:00
|
|
|
|
2009-08-04 13:05:37 +02:00
|
|
|
if params['sort']
|
|
|
|
sort = case params['sort']
|
2021-03-01 15:27:26 +01:00
|
|
|
when "date" then "created_on"
|
|
|
|
when "note" then "note"
|
|
|
|
when "amount" then "amount"
|
|
|
|
when "date_reverse" then "created_on DESC"
|
|
|
|
when "note_reverse" then "note DESC"
|
|
|
|
when "amount_reverse" then "amount DESC"
|
|
|
|
end
|
2009-01-15 12:14:01 +01:00
|
|
|
else
|
|
|
|
sort = "created_on DESC"
|
|
|
|
end
|
|
|
|
|
2019-11-01 19:30:23 +01:00
|
|
|
@financial_transactions = @ordergroup.financial_transactions.visible.page(params[:page]).per(@per_page).order(sort)
|
2020-02-25 00:37:17 +01:00
|
|
|
@financial_transactions = @financial_transactions.where('financial_transactions.note LIKE ?', "%#{params[:query]}%") if params[:query].present?
|
2009-01-15 12:14:01 +01:00
|
|
|
|
2009-08-04 13:05:37 +02:00
|
|
|
else
|
2014-12-16 21:09:04 +01:00
|
|
|
redirect_to root_path, alert: I18n.t('home.no_ordergroups')
|
2009-01-15 12:14:01 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-04 13:05:37 +02:00
|
|
|
# cancel personal memberships direct from the myProfile-page
|
2009-01-15 12:14:01 +01:00
|
|
|
def cancel_membership
|
2014-12-16 21:09:04 +01:00
|
|
|
if params[:membership_id]
|
|
|
|
membership = @current_user.memberships.find!(params[:membership_id])
|
2009-01-15 12:14:01 +01:00
|
|
|
else
|
2014-12-16 21:09:04 +01:00
|
|
|
membership = @current_user.memberships.find_by_group_id!(params[:group_id])
|
2009-01-15 12:14:01 +01:00
|
|
|
end
|
2014-12-16 21:09:04 +01:00
|
|
|
membership.destroy
|
|
|
|
redirect_to my_profile_path, notice: I18n.t('home.ordergroup_cancelled', :group => membership.group.name)
|
2009-01-15 12:14:01 +01:00
|
|
|
end
|
|
|
|
|
2014-12-10 21:27:53 +01:00
|
|
|
protected
|
|
|
|
|
|
|
|
def user_params
|
|
|
|
params
|
|
|
|
.require(:user)
|
|
|
|
.permit(:first_name, :last_name, :email, :phone,
|
|
|
|
:password, :password_confirmation).merge(params[:user].slice(:settings_attributes))
|
|
|
|
end
|
|
|
|
|
|
|
|
def ordergroup_params
|
2015-01-16 20:25:58 +01:00
|
|
|
if params[:user][:ordergroup]
|
|
|
|
params.require(:user).require(:ordergroup).permit(:contact_address)
|
|
|
|
end
|
2014-12-10 21:27:53 +01:00
|
|
|
end
|
2009-01-15 12:14:01 +01:00
|
|
|
end
|