Class: Admin::QbSyncsController

Inherits:
ApplicationController
  • Object
show all
Includes:
Effective::CrudController
Defined in:
app/controllers/admin/qb_syncs_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



12
13
14
15
# File 'app/controllers/admin/qb_syncs_controller.rb', line 12

def index
  @datatable = EffectiveQbSyncDatatable.new(self)
  @page_title = 'Quickbooks Synchronizations'
end

#instructionsObject



40
41
42
# File 'app/controllers/admin/qb_syncs_controller.rb', line 40

def instructions
  @page_title = 'Quickbooks Setup Instructions'
end

#qwcObject



44
45
46
47
48
49
50
# File 'app/controllers/admin/qb_syncs_controller.rb', line 44

def qwc
  @filename = EffectiveQbSync.qwc_name.parameterize + '.qwc'

  data = render_to_string('effective/qb_web_connector/quickbooks', layout: false)

  send_data(data, filename: 'quickbooks.qwc', disposition: 'attachment')
end

#set_all_orders_finishedObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/admin/qb_syncs_controller.rb', line 52

def set_all_orders_finished
  Effective::QbTicket.transaction do
    begin
      Effective::QbTicket.set_orders_finished!

      flash[:success] = 'Successfully set all orders finished'
    rescue => e
      flash[:danger] = "Unable to set all orders finished: #{e.message}"
      raise ActiveRecord::Rollback
    end
  end

  redirect_to effective_qb_sync.admin_qb_syncs_path
end

#showObject



17
18
19
20
21
22
# File 'app/controllers/admin/qb_syncs_controller.rb', line 17

def show
  @qb_ticket = Effective::QbTicket.includes(:qb_requests, :qb_logs).find(params[:id])
  @page_title = "Quickbooks Sync ##{@qb_ticket.id}"

  @qb_order_items_form = Effective::QbOrderItemsForm.new(id: @qb_ticket.id, orders: @qb_ticket.orders)
end

#updateObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/admin/qb_syncs_controller.rb', line 24

def update
  @qb_ticket = Effective::QbTicket.includes(:qb_requests, :qb_logs).find(params[:id])
  @page_title = "Quickbooks Sync ##{@qb_ticket.id}"

  @qb_order_items_form = Effective::QbOrderItemsForm.new(id: @qb_ticket.id, orders: @qb_ticket.orders)
  @qb_order_items_form.qb_order_items_attributes = permitted_params[:qb_order_items_attributes].values

  if @qb_order_items_form.save
    flash[:success] = 'Successfully updated Quickbooks item names'
    redirect_to effective_qb_sync.admin_qb_sync_path(@qb_ticket)
  else
    flash.now[:danger] = 'Unable to update Quickbooks item names'
    render action: :show
  end
end