Class: Dorsale::BillingMachine::QuotationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/dorsale/billing_machine/quotations_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#scope

Instance Method Details

#copyObject



92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/dorsale/billing_machine/quotations_controller.rb', line 92

def copy
  authorize @quotation, :copy?

  @original  = @quotation
  @quotation = Dorsale::BillingMachine::Quotation::Copy.(@original)

  flash[:notice] = t("messages.quotations.copy_ok")

  redirect_to dorsale.edit_billing_machine_quotation_path(@quotation)
end

#createObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/dorsale/billing_machine/quotations_controller.rb', line 35

def create
  # callback in BillingMachine::ApplicationController
  @quotation ||= scope.new(quotation_params_for_create)

  authorize @quotation, :create?

  if @quotation.save
    Dorsale::BillingMachine::PdfFileGenerator.(@quotation)
    flash[:notice] = t("messages.quotations.create_ok")
    redirect_to default_back_url
  else
    render :edit
  end
end

#create_invoiceObject



103
104
105
106
107
108
109
110
# File 'app/controllers/dorsale/billing_machine/quotations_controller.rb', line 103

def create_invoice
  authorize @quotation, :read?
  authorize ::Dorsale::BillingMachine::Invoice, :create?

  @invoice = Dorsale::BillingMachine::Quotation::ToInvoice.(@quotation)

  render "dorsale/billing_machine/invoices/new"
end

#destroyObject



79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/dorsale/billing_machine/quotations_controller.rb', line 79

def destroy
  # callback in BillingMachine::ApplicationController
  authorize @quotation, :delete?

  if @quotation.destroy
    flash[:notice] = t("messages.quotations.update_ok")
  else
    flash[:alert] = t("messages.quotations.update_error")
  end

  redirect_to url_for(action: :index, id: nil)
end

#editObject



56
57
58
59
60
61
62
63
64
# File 'app/controllers/dorsale/billing_machine/quotations_controller.rb', line 56

def edit
  # callback in BillingMachine::ApplicationController
  authorize @quotation, :update?
  if ::Dorsale::BillingMachine.vat_mode == :single
    @quotation.lines.build(vat_rate: @quotation.vat_rate) if @quotation.lines.empty?
  else
    @quotation.lines.build if @quotation.lines.empty?
  end
end

#indexObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/dorsale/billing_machine/quotations_controller.rb', line 11

def index
  # callback in BillingMachine::ApplicationController
  authorize model, :list?

  @quotations ||= scope.all.preload(:customer)
  @filters    ||= ::Dorsale::BillingMachine::SmallData::FilterForQuotations.new(cookies)

  @quotations = @filters.apply(@quotations)
  @quotations_without_pagination = @quotations # All filtered quotations (not paginated)
  @quotations = @quotations.page(params[:page]).per(50)

  @statistics = ::Dorsale::BillingMachine::Invoice::Statistics.new(@quotations_without_pagination)
end

#newObject



25
26
27
28
29
30
31
32
33
# File 'app/controllers/dorsale/billing_machine/quotations_controller.rb', line 25

def new
  # callback in BillingMachine::ApplicationController
  @quotation ||= scope.new

  @quotation.lines.build               if @quotation.lines.empty?
  @quotation.id_card = @id_cards.first if @id_cards.one?

  authorize @quotation, :create?
end

#showObject



50
51
52
53
54
# File 'app/controllers/dorsale/billing_machine/quotations_controller.rb', line 50

def show
  # callback in BillingMachine::ApplicationController
  authorize @quotation, :read?
  authorize @quotation, :download? if request.format.pdf?
end

#updateObject



66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/dorsale/billing_machine/quotations_controller.rb', line 66

def update
  # callback in BillingMachine::ApplicationController
  authorize @quotation, :update?

  if @quotation.update(quotation_params_for_update)
    Dorsale::BillingMachine::PdfFileGenerator.(@quotation)
    flash[:notice] = t("messages.quotations.update_ok")
    redirect_to default_back_url
  else
    render :edit
  end
end