Class ContractController
In: app/controllers/contract_controller.rb
Parent: ApplicationController

************************************************************************/

  • SOLUNAS BOOKING ENGINE */
  • ====================== */
  • */
  • Copyright © 2006 by Marc Isemann */
  • sourceforge.net/projects/solunas */
  • */
  • This program is free software. You can redistribute it and/or modify */
  • it under the terms of the GNU General Public License as published by */
  • the Free Software Foundation; either version 2 of the License. */

************************************************************************/

Methods

Public Instance methods

[Source]

     # File app/controllers/contract_controller.rb, line 179
179:   def calendar
180:   end

Choose month and year to show overwiew of availability

[Source]

     # File app/controllers/contract_controller.rb, line 150
150:   def choose_calendar
151:     @properties = Property.find(:all, :conditions => ["user_id = ?",session[:user_id]])
152:     render(:layout => false)
153:   end

[Source]

     # File app/controllers/contract_controller.rb, line 155
155:   def choose_calendar_by_year
156:     @rooms = Room.find(:all, :conditions => ["user_id = ?",session[:user_id]])
157:     render(:layout => false)
158:   end

Confirm a contract.

[Source]

     # File app/controllers/contract_controller.rb, line 118
118:   def confirm
119:     @contract = Contract.find(params[:id])
120:     @contract.pending = 0
121:     if @contract.update
122:       flash[:notice] = 'Contract was successfully confirmed.'
123:       redirect_to :action => 'list_pending'
124:     else
125:       flash[:notice] = 'Contract was <b>not</b> successfully confirmed.'
126:       redirect_to :action => 'list_pending'
127:     end
128:   end

[Source]

     # File app/controllers/contract_controller.rb, line 130
130:   def confirm_public
131:     @contract = Contract.find(params[:id])
132:     @contract.unconfirmed = 0
133:     if @contract.update
134:       flash[:notice] = 'Contract was successfully confirmed.'
135:       redirect_to :action => 'list_unconfirmed'
136:     else
137:       flash[:notice] = 'Contract was <b>not</b> successfully confirmed.'
138:       redirect_to :action => 'list_unconfirmed'
139:     end
140:   end

Create new contract and save into database

[Source]

    # File app/controllers/contract_controller.rb, line 77
77:   def create
78:     @contract = Contract.new(params[:contract])
79:     @contract.user_id = session[:user_id]
80:     @contract.customer_id = params[:customer_id]
81:     @contract.pending = 1
82: 
83:     if  (@contract.is_possible  && @contract.save)
84:       flash[:notice] = 'Contract was successfully created.'
85:       redirect_to :action => 'list'
86:     else
87:       flash[:notice] = 'Please check data!'
88:       redirect_to(:action => 'new', :id => params[:customer_id])
89:     end
90:   end

Destroy existing contract

[Source]

     # File app/controllers/contract_controller.rb, line 144
144:   def destroy
145:     Contract.find(params[:id]).destroy
146:     redirect_to :action => 'list'
147:   end

Edit existing contracts

[Source]

    # File app/controllers/contract_controller.rb, line 93
93:   def edit
94:     @contract = Contract.find(params[:id])
95:     @addons = @addons = Addon.find(:all, :conditions => ["user_id = ? && room_id = ?", session[:user_id], @contract.room_id])
96:     @rooms = Room.find(:all, :conditions => ["user_id = ?",session[:user_id]])
97:   end

Index page: List all contracts

[Source]

    # File app/controllers/contract_controller.rb, line 21
21:   def index
22:     list
23:     render :action => 'list'
24:   end

List all contracts

[Source]

    # File app/controllers/contract_controller.rb, line 30
30:   def list
31:     if params[:search]
32:       @contract_pages, @contracts = paginate :contract, :per_page => 10,
33:       :conditions => ["user_id = ? && id = ?",session[:user_id], params[:search]]
34:     elsif params[:customer_id]
35:       @contract_pages, @contracts = paginate :contract, :per_page => 10,
36:       :conditions => ["user_id = ? && customer_id = ?",session[:user_id], params[:customer_id]]
37:       @customer_id = params[:customer_id]
38:     else
39:       @contract_pages, @contracts = paginate :contract, :per_page => 10,
40:       :conditions => ["user_id = ?",session[:user_id]]
41:     end
42:   end

List all pending contracts

[Source]

    # File app/controllers/contract_controller.rb, line 45
45:   def list_pending
46:     @contract_pages, @contracts = paginate :contract, :per_page => 10,
47:     :conditions => ["user_id = ? && pending = 1",session[:user_id]]
48:   end

List all unconfirmed contracts

[Source]

    # File app/controllers/contract_controller.rb, line 51
51:   def list_unconfirmed
52:     @contract_pages, @contracts = paginate :contract, :per_page => 10,
53:     :conditions => ["user_id = ? && unconfirmed = 1",session[:user_id]]
54:   end

Create new contract. If no customer is selected, redirect to customer page

[Source]

    # File app/controllers/contract_controller.rb, line 65
65:   def new
66:     @contract = Contract.new
67:     if(params[:id])
68:       @customers = Customer.find(:first, :conditions => ["user_id = ? and id = ?",session[:user_id], params[:id]])
69:     else
70:       flash[:notice] = 'Choose Customer first.'
71:       redirect_to(:controller => "customer", :action => "search")
72:     end
73:     @rooms = Room.find(:all, :conditions => ["user_id = ?",session[:user_id]])
74:   end

[Source]

    # File app/controllers/contract_controller.rb, line 26
26:   def search
27:   end

Show one contract in detail. ID is needed

[Source]

    # File app/controllers/contract_controller.rb, line 58
58:   def show
59:     @contract = Contract.find(params[:id])
60:     @addons = @contract.addons
61: 
62:   end

Show calendar

[Source]

     # File app/controllers/contract_controller.rb, line 161
161:   def show_calendar
162:     @year = params[:year] || ::Date.today.year
163:     @month = params[:month] || ::Date.today.month
164:     @month_var = month_vars(@month.to_i, @year)
165:     @properties = Property.find(:all, :conditions => ["user_id = ?",session[:user_id]])
166:     @rooms = Room.find(:all, :conditions => ["user_id = ? && property_id = ?",session[:user_id], params[:property_id]])
167:     @property = Property.find(params[:property_id])
168:     @calendar = Contract.get_calendar_data(@rooms, @month, @year, @month_var["end"].to_i)
169:     render(:layout => false)
170:   end

[Source]

     # File app/controllers/contract_controller.rb, line 172
172:   def show_calendar_by_year
173:     @year = params[:year] || ::Date.today.year
174:     @room = Room.find(:first, :conditions => ["user_id = ? && id = ?",session[:user_id], params[:room_id]])
175:     @calendar = Contract.get_calendar_data_by_year(@room, @year)
176:     render(:layout => false)
177:   end

Update existing contracts in database

[Source]

     # File app/controllers/contract_controller.rb, line 100
100:   def update
101:     @contract = Contract.find(params[:id])
102:     @contract.user_id = session[:user_id]
103:     @contract.customer_id = params[:customer_id]
104:     if @params[:addon_ids]
105:       @contract.addons = Addon.find(@params[:addon_ids])
106:     else
107:       @contract.addons = []
108:     end
109:     if @contract.update_attributes(params[:contract])
110:       flash[:notice] = 'Contract was successfully updated.'
111:       redirect_to :action => 'show', :id => @contract
112:     else
113:       render :action => 'edit'
114:     end
115:   end

[Validate]