Class: InvoiceBar::ReceiptTemplatesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/invoice_bar/receipt_templates_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /receipt_templates/1 POST /receipt_templates/1.json



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/invoice_bar/receipt_templates_controller.rb', line 37

def create
  flash[:notice], flash[:alert] = nil, nil

  @receipt_template = ReceiptTemplate.new(receipt_template_params)

  fill_in_contact if params[:fill_in_contact]

  if params[:tax_id]
    if (@receipt_template.load_contact_from_tax_id(@receipt_template.contact_tax_id))
      flash[:notice] = I18n.t('messages.tax_id_loaded')
    else
      flash[:alert] = I18n.t('messages.cannot_load_tax_id')
    end
  end

  if params[:fill_in_contact] || params[:tax_id]
    respond_on_new @receipt_template
  else
    current_user.receipt_templates << @receipt_template
    respond_on_create @receipt_template
  end
end

#destroyObject

DELETE /receipt_templates/1 DELETE /receipt_templates/1.json



88
89
90
91
# File 'app/controllers/invoice_bar/receipt_templates_controller.rb', line 88

def destroy
  @receipt_template.destroy
  respond_on_destroy @receipt_template, receipt_templates_url
end

#editObject

GET /invoice_receipts/1/edit



61
62
63
64
# File 'app/controllers/invoice_bar/receipt_templates_controller.rb', line 61

def edit
  @receipt_template.build_address unless @receipt_template.address
  respond_on_edit @receipt_template
end

#indexObject

GET /receipt_templates GET /receipt_templates.json



10
11
12
13
# File 'app/controllers/invoice_bar/receipt_templates_controller.rb', line 10

def index
  @receipt_templates = current_user.receipt_templates.page(params[:page])
  respond_on_index @receipt_templates
end

#newObject

GET /receipt_templates/new



28
29
30
31
32
33
# File 'app/controllers/invoice_bar/receipt_templates_controller.rb', line 28

def new
  @receipt_template = ReceiptTemplate.new
  @receipt_template.items.build
  @receipt_template.build_address
  respond_on_new @receipt_template
end

#showObject

GET /receipt_templates/1 GET /receipt_templates/1.json



17
18
19
20
21
22
23
24
25
# File 'app/controllers/invoice_bar/receipt_templates_controller.rb', line 17

def show
  @address = @receipt_template.address

  unless @receipt_template. or current_user.accounts
    @account = current_user.accounts.find(@receipt_template.)
  end

  respond_on_show @receipt_template
end

#updateObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/controllers/invoice_bar/receipt_templates_controller.rb', line 66

def update
  flash[:notice], flash[:alert] = nil, nil

  fill_in_contact if params[:fill_in_contact]

  if params[:tax_id]
    if (@receipt_template.load_contact_from_tax_id(@receipt_template.contact_tax_id))
      flash[:notice] = I18n.t('messages.tax_id_loaded')
    else
      flash[:alert] = I18n.t('messages.cannot_load_tax_id')
    end
  end

  if params[:fill_in_contact] || params[:tax_id]
    respond_on_edit @receipt_template
  else
    respond_on_update @receipt_template, receipt_template_params
  end
end