Class: BookingsController

Inherits:
AuthorizedController show all
Defined in:
app/controllers/bookings_controller.rb

Instance Method Summary collapse

Methods inherited from AuthorizedController

#set_locale

Instance Method Details

#copyObject



57
58
59
60
61
62
63
# File 'app/controllers/bookings_controller.rb', line 57

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

  @booking = original_booking.dup

  render 'edit'
end

#createObject



48
49
50
51
52
53
54
55
# File 'app/controllers/bookings_controller.rb', line 48

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

#indexObject

Actions



7
8
9
10
# File 'app/controllers/bookings_controller.rb', line 7

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

#newObject



12
13
14
15
16
# File 'app/controllers/bookings_controller.rb', line 12

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

#selectObject



42
43
44
45
46
# File 'app/controllers/bookings_controller.rb', line 42

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

#select_bookingObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/bookings_controller.rb', line 18

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

#select_booking_templateObject



31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/bookings_controller.rb', line 31

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