Class: InvoiceBar::ReceiptsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- InvoiceBar::ReceiptsController
- Defined in:
- app/controllers/invoice_bar/receipts_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /receipts/1 POST /receipts/1.json.
-
#destroy ⇒ Object
DELETE /receipts/1 DELETE /receipts/1.json.
-
#edit ⇒ Object
GET /receipts/1/edit.
- #expence ⇒ Object
- #filter ⇒ Object
- #from_template ⇒ Object
- #income ⇒ Object
-
#index ⇒ Object
GET /receipts GET /receipts.json.
-
#new ⇒ Object
GET /receipts/new.
-
#show ⇒ Object
GET /receipts/1 GET /receipts/1.json GET /receipts/1.pdf.
-
#update ⇒ Object
PATCH/PUT /receipts/1 PATCH/PUT /receipts/1.json.
Instance Method Details
#create ⇒ Object
POST /receipts/1 POST /receipts/1.json
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/controllers/invoice_bar/receipts_controller.rb', line 65 def create flash[:notice], flash[:alert] = nil, nil @receipt = Receipt.new(receipt_params) apply_templates if params[:fill_in] fill_in_contact if params[:fill_in_contact] if params[:tax_id] if (@receipt.load_contact_from_tax_id(@receipt.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] || params[:fill_in_contact] || params[:tax_id] respond_on_new @receipt else @receipt.user_name = current_user.name @receipt.user_tax_id = current_user.tax_id @receipt.user_tax_id2 = current_user.tax_id2 @receipt.user_address = current_user.address.copy( addressable_type: "InvoiceBar::Receipt#user_address" ) current_user.receipts << @receipt respond_on_create @receipt end end |
#destroy ⇒ Object
DELETE /receipts/1 DELETE /receipts/1.json
125 126 127 128 |
# File 'app/controllers/invoice_bar/receipts_controller.rb', line 125 def destroy @receipt.destroy respond_on_destroy @receipt, receipts_url end |
#edit ⇒ Object
GET /receipts/1/edit
96 97 98 |
# File 'app/controllers/invoice_bar/receipts_controller.rb', line 96 def edit respond_on_edit @receipt end |
#expence ⇒ Object
130 131 132 133 134 135 136 |
# File 'app/controllers/invoice_bar/receipts_controller.rb', line 130 def expence @section = :expence @receipts = current_user.receipts.expense @receipts = filter_params(@receipts) render action: 'index' end |
#filter ⇒ Object
146 147 148 149 150 151 |
# File 'app/controllers/invoice_bar/receipts_controller.rb', line 146 def filter @receipts = current_user.receipts.limit(nil) @receipts = filter_params(@receipts) render action: 'index' end |
#from_template ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/invoice_bar/receipts_controller.rb', line 50 def from_template @template = current_user.receipt_templates.find(params[:id]) @receipt = Receipt.from_template(@template) @receipt.user_name = current_user.name @receipt.user_tax_id = current_user.tax_id @receipt.user_tax_id2 = current_user.tax_id2 @receipt.user_address = current_user.address.copy( addressable_type: "InvoiceBar::Receipt#user_address" ) respond_on_new @receipt end |
#income ⇒ Object
138 139 140 141 142 143 144 |
# File 'app/controllers/invoice_bar/receipts_controller.rb', line 138 def income @section = :income @receipts = current_user.receipts.income @receipts = filter_params(@receipts) render action: 'index' end |
#index ⇒ Object
GET /receipts GET /receipts.json
11 12 13 14 |
# File 'app/controllers/invoice_bar/receipts_controller.rb', line 11 def index @receipts = current_user.receipts.page(params[:page]) respond_on_index @receipts end |
#new ⇒ Object
GET /receipts/new
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/invoice_bar/receipts_controller.rb', line 34 def new # Set the number of the document next_income_in_line = current_user.receipts.income.size + 1 next_expense_in_line = current_user.receipts.expense.size + 1 @next_income = ::InvoiceBar::Generators.income_receipt_number(next_income_in_line) @next_expense = ::InvoiceBar::Generators.expense_receipt_number(next_expense_in_line) @receipt = Receipt.new @receipt.number = @next_income @receipt.items.build @receipt.build_address @receipt.issue_date = Date.today respond_on_new @receipt end |
#show ⇒ Object
GET /receipts/1 GET /receipts/1.json GET /receipts/1.pdf
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/invoice_bar/receipts_controller.rb', line 19 def show @address = @receipt.address @account = current_user.accounts.find(@receipt.account_id) respond_to do |format| format.html { render :show } format.json { render json: @receipt } format.pdf { @pdf = ReceiptPDF.new(@receipt).render send_data @pdf, type: 'application/pdf', disposition: 'inline' } end end |
#update ⇒ Object
PATCH/PUT /receipts/1 PATCH/PUT /receipts/1.json
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'app/controllers/invoice_bar/receipts_controller.rb', line 102 def update flash[:notice], flash[:alert] = nil, nil apply_templates if params[:fill_in] fill_in_contact if params[:fill_in_contact] if params[:tax_id] if (@receipt.load_contact_from_tax_id(@receipt.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] || params[:fill_in_contact] || params[:tax_id] respond_on_edit @receipt else respond_on_update @receipt, receipt_params end end |