module TrainersHelper

	def plans_by_trainer(trainer)
		plans = Plan.where(trainer_id: trainer.id).where("finish >= ? ", Time.zone.now.to_date)
		return plans.count
	end

	def trainer_plans(trainer, presencial=false)
		plans = User.where(presencial: presencial).includes(:plans).where("plans.trainer_id" => trainer.id)
		return plans.count
	end

	def appointments_by_trainer(trainer)
		today = Time.zone.now.to_date
		if trainer.role == "trainer"
			appointments = Appointment.where(trainer_id: trainer.id)
		else
			appointments = Appointment.all
		end
		return appointments.where("date >= ? AND date <= ?", Time.current.beginning_of_day, Time.current.end_of_day)
	end

end