Guest User

Untitled

a guest
Jun 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1.  
  2. class PublicController < ApplicationController
  3.  
  4. layout "public"
  5. before_filter :find_cart
  6. before_filter :find_user
  7.  
  8. def index
  9. end
  10. def show_calendar
  11. @month = params[:month] ||= ::Time.now.month
  12. @year = params[:year] ||= ::Time.now.year
  13. @month_var = month_vars(@month.to_i, @year)
  14. @property = Property.find(params[:property_id])
  15. @properties = Property.find(:all, :conditions => ["user_id = ?",@user_id])
  16. @rooms = Room.find(:all, :conditions => ["user_id = ? && property_id = ?",@user_id, params[:property_id]])
  17.  
  18. @calendar = Contract.get_calendar_data(@rooms, @month, @year, @month_var["end"].to_i)
  19. render(:layout => false)
  20. end
  21.  
  22. def choose_calendar
  23. @properties = Property.find(:all, :conditions => ["user_id = ?",@user_id])
  24. render(:layout => false)
  25. end
  26.  
  27. def choose_calendar_by_year
  28. @rooms = Room.find(:all, :conditions => ["user_id = ?",@user_id])
  29. render(:layout => false)
  30. end
  31.  
  32. def show_calendar_by_year
  33. @year = params[:year] || ::Date.today.year
  34. @room = Room.find(:first, :conditions => ["user_id = ? && id = ?",@user_id, params[:room_id]])
  35. @calendar = Contract.get_calendar_data_by_year(@room, @year)
  36. render(:layout => false)
  37. end
  38.  
  39. def calendar
  40. @property_id = params[:property_id]
  41. @month = params[:month] ||= ::Time.now.month
  42. @year = params[:year] ||= ::Time.now.year
  43. end
  44.  
  45. def calendar_by_year
  46. @room = Room.find(:first, :conditions => ["user_id = ? && id = ?",@user_id, params[:room_id]])
  47. @year = params[:year] ||= ::Time.now.year
  48. end
  49.  
  50. def show_form
  51. end
  52.  
  53. def show_rooms
  54.  
  55. @arrival = ::DateTime.strptime(params[:arrival], @user.datestring)
  56. @departure = ::DateTime.strptime(params[:departure], @user.datestring)
  57. @free_rooms = Public.get_free_rooms(@user, @arrival, @departure, params[:adults], params[:children])
  58. if @free_rooms == false
  59. redirect_to(:action=> 'show_form')
  60. flash[:notice] = 'Seleccione fechas de llegada y salida correctas.'
  61. elsif @free_rooms.length == 0
  62. redirect_to(:action=> 'show_form')
  63. flash[:notice] = 'No hay Unidades disponibles.'
  64. else
  65. @adults = params[:adults]
  66. @children = params[:children]
  67. end
  68. end
  69.  
  70. def add_to_cart
  71. @room = Room.find(params[:room_id])
  72. @arrival = ::DateTime.strptime(params[:arrival], @user.datestring)
  73. @departure = ::DateTime.strptime(params[:departure], @user.datestring)
  74. @addons = Addon.find(:all, :conditions => ["user_id = ? && room_id = ? && force_cart = ?", @user_id, params[:room_id], true])
  75. if @cart.add_line(@addons, @room, params[:total], @arrival, @departure, params[:adults], params[:children]) == false
  76. flash[:notice] = 'Unidades listas en el carrito.'
  77. end
  78. redirect_to(:action=> 'display_cart')
  79. end
  80.  
  81. def display_cart
  82.  
  83. end
  84.  
  85. def empty_cart
  86. @cart.empty!
  87. redirect_to(:action=> 'display_cart')
  88. end
  89.  
  90. def delete_cart_item
  91. @cart.change_total(@cart.items[params[:cart_item_id].to_i].total)
  92. @cart.items.delete_at(params[:cart_item_id].to_i)
  93. flash[:notice] = 'Cart item deleted.'
  94. redirect_to(:action=> 'display_cart')
  95. end
  96.  
  97. def checkout
  98. @items = @cart.items
  99. if @items.empty?
  100. redirect_to(:action=> 'display_cart')
  101. end
  102. end
  103.  
  104. def save_booking
  105.  
  106.  
  107. @items = @cart.items
  108. @customer = Customer.new(params[:customer])
  109. @customer.user_id = @user_id
  110. @customer.save
  111. @items.each do |item|
  112. @contract = Contract.new(params[:contract])
  113. @contract.room_id = item.room.id
  114. @contract.total = item.total
  115. @contract.arrival = item.arrival
  116. @contract.departure = item.departure
  117. @contract.adults = item.adults
  118. @contract.children = item.children
  119. @contract.customer_id = @customer.id
  120. @contract.pending = 1
  121. @contract.unconfirmed = 1
  122. @contract.user_id = @user_id
  123. @contract.addons << item.addons
  124. if @contract.is_possible
  125. @contract.save
  126. end
  127. end
  128. @cart.empty!
  129. end
  130.  
  131. private
  132.  
  133. def find_cart
  134. @cart = (session[:cart] ||= Cart.new)
  135. end
  136.  
  137. def find_user
  138. if params[:user_id]
  139. session[:puID] = params[:user_id]
  140. end
  141. @user_id = session[:puID]
  142. @user = User.find(@user_id)
  143. Locale.set @user.language
  144. end
  145. end
Add Comment
Please, Sign In to add comment