33 lines
956 B
Ruby
33 lines
956 B
Ruby
class Promoter::PayoutsController < ApplicationController
|
|
before_action :authenticate_user!
|
|
before_action :ensure_promoter
|
|
|
|
def index
|
|
@events = current_user.events.includes(:earnings).order(start_time: :desc)
|
|
end
|
|
|
|
def show
|
|
@event = current_user.events.find(params[:id])
|
|
@earnings = @event.earnings
|
|
end
|
|
|
|
def create
|
|
@event = current_user.events.find(params[:event_id] || params[:id])
|
|
|
|
if @event.can_request_payout?
|
|
PayoutService.new.process_event_payout(@event)
|
|
redirect_to promoter_payout_path(@event), notice: "Payout requested successfully. It will be processed shortly."
|
|
else
|
|
redirect_to promoter_payouts_path, alert: "Cannot request payout: #{@event.can_request_payout? ? '' : 'Event not eligible for payout.'}"
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def ensure_promoter
|
|
unless current_user.promoter?
|
|
redirect_to dashboard_path, alert: "Access denied. Promoter account required."
|
|
end
|
|
end
|
|
end
|