class Tutors::InvoicesController

Public Instance Methods

create() click to toggle source

Method to build and create invoice for tutoring sessions and send mail regarding to invoice to payee.

# File app/controllers/tutors/invoices_controller.rb, line 20
def create
  @invoice = current_user.invoices.build invoice_params
  respond_to do |format|
    if @invoice.save
      @invoice.send_invoice_email
      format.js {}
    else
      format.js {render partial: 'form', replace: 'form#new_invoice'}
    end
  end
end
destroy() click to toggle source

Method to find and destroy the Invoice created by tutor.

# File app/controllers/tutors/invoices_controller.rb, line 46
def destroy
  invoice = Invoice.find(params[:id])
  tutoring_session = invoice.invoiceable
  if tutoring_session.tutor == current_user && !invoice.invoiceable.confirmed? && !invoice.paid
    invoice.destroy
    redirect_to [:tutor, tutoring_session]
  else
    if invoice.invoiceable.confirmed?
      flash[:notice] = "Invoice for confirmed sessions can not be deleted."
    else
      flash[:notice] = "Unable to remove this invoice. Please check if you have the rights to do so."
    end
    redirect_to [:tutor, tutoring_session]
  end
end
edit() click to toggle source

Method to edit the invoice created by tutor.

# File app/controllers/tutors/invoices_controller.rb, line 14
def edit
  @invoice = current_user.invoices.find(params[:id])
  render layout: false
end
new() click to toggle source

Method to build invoice.

# File app/controllers/tutors/invoices_controller.rb, line 8
def new
  @invoice = current_user.invoices.build(manually_billed: true)
  render layout: false
end
update() click to toggle source

Method to find and update invoice created by tutor.

# File app/controllers/tutors/invoices_controller.rb, line 33
def update
  @invoice = current_user.invoices.find(params[:id])
  respond_to do |format|
    if @invoice.update_attributes(invoice_params)
      InvoiceMailer.delay(queue: :mailer).update_email(@invoice) if @invoice.tutor.present?
      format.js { render 'create'}
    else
      format.js {render partial: 'form', replace: "form#edit_invoice_#{@invoice.id}"}
    end
  end
end