Sha256: 39f24f5aa569ed2ed2c844c5d4ed6a5508f9259748540a29aefbbee83ea8d358

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

class BookingsController < AuthorizedController
  # Scopes
  has_scope :by_value_period, :using => [:from, :to], :default => proc { |c| c.session[:has_scope] }
  has_scope :by_text

  # Actions
  def index
    @bookings = apply_scopes(Booking).accessible_by(current_ability, :list).includes(:credit_account, :debit_account).paginate(:page => params[:page], :per_page => params[:per_page])
    index!
  end

  def new
    @booking = Booking.new(:value_date => Date.today)
    @booking_templates = BookingTemplate.where("NOT(code LIKE '%:%')").paginate(:page => params[:page])
    new!
  end

  def select_booking
    @booking = Booking.find(params[:id]).dup

    # Clear reference
    @booking.reference  = nil
    # Increment code
    @booking.code       = (Booking.maximum(:code) || 0) + 1
    # Take value date from form
    @booking.value_date = params[:booking][:value_date]

    render :action => 'simple_edit'
  end

  def select_booking_template
    @booking_template = BookingTemplate.find(params[:id])

    booking_params = params[:booking] || {}
    booking_params[:value_date] ||= Date.today
    booking_params[:code]       ||= (Booking.maximum(:code) || 0) + 1
    @booking = @booking_template.build_booking(booking_params)

    render :action => 'simple_edit'
  end

  def select
    @booking = Booking.new(params[:booking])
    @booking_templates = BookingTemplate.where("NOT(code LIKE '%:%')").paginate(:page => params[:page])
    @bookings = Booking.where("title LIKE ?", '%' + @booking.title + '%').order('value_date DESC').paginate(:page => params[:page])
  end

  def create
    @booking = Booking.new(params[:booking])

    create! do |success, failure|
      success.html {redirect_to new_booking_path(:notice => render_to_string(:partial => 'layouts/flash_new', :locals => {:object => @booking}))}
      failure.html {render 'edit'}
    end
  end

  def copy
    original_booking = Booking.find(params[:id])

    @booking = original_booking.dup

    render 'edit'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bookyt-0.0.1 app/controllers/bookings_controller.rb