Class: Comee::Core::SalesOrdersController

Inherits:
ApplicationController show all
Includes:
Common
Defined in:
app/controllers/comee/core/sales_orders_controller.rb

Instance Method Summary collapse

Methods included from Common

#create

Methods included from Pagination

#default_per_page, #order_by, #order_direction, #page_no, #paginate, #paginate_offset, #per_page

Methods inherited from ApplicationController

#application_code, #authenticate, #current_application, #current_user, #render_content, #render_error, #skip_bullet

Instance Method Details

#acceptObject



120
121
122
123
124
125
# File 'app/controllers/comee/core/sales_orders_controller.rb', line 120

def accept
  order = @service.accept(params[:id])
  render_content(order)
rescue StandardError => e
  render json: {success: false, error: e.message}
end

#cancelObject



127
128
129
130
131
132
# File 'app/controllers/comee/core/sales_orders_controller.rb', line 127

def cancel
  order = @service.cancel(params[:id])
  render_content(order)
rescue StandardError => e
  render json: {success: false, error: e.message}
end

#confirmObject



113
114
115
116
117
118
# File 'app/controllers/comee/core/sales_orders_controller.rb', line 113

def confirm
  order = @service.confirm(params[:id])
  render_content(order)
rescue StandardError => e
  render json: {success: false, error: e.message}
end

#create_back_orderObject



141
142
143
144
145
146
147
148
149
# File 'app/controllers/comee/core/sales_orders_controller.rb', line 141

def create_back_order
  service = SalesOrderService.new
  result = service.create_back_orders(back_order_params[:payload])
  if result[:success]
    render json: {success: true}
  else
    render json: {success: false, error: result[:error]}
  end
end

#filterObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/controllers/comee/core/sales_orders_controller.rb', line 79

def filter
  data = SalesOrder.includes(
    :customer_order,
    :client,
    :customs_detail,
    shipment_address: :country,
    delivery_address: :country,
    invoice_address: :country,
    sales_order_items: %i[unit customer_order_item]
  ).ransack(params[:q]).result
  render_content(
    data,
    include: [
      "client",
      "customer_order",
      "sales_order_items.product",
      "sales_order_items.unit",
      "sales_order_items.customer_order_item",
      "shipment_address.country",
      "delivery_address.country",
      "invoice_address.country",
      "customs_detail",
      "fulfillment_center"
    ]
  )
end

#indexObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/comee/core/sales_orders_controller.rb', line 7

def index
  super do
    data = SalesOrder.includes(
      :customer_order,
      :client,
      :customs_detail,
      shipment_address: :country,
      delivery_address: :country,
      invoice_address: :country,
      sales_order_items: :unit
    ).order(created_at: :desc)
    [
      data,
      include: [
        "client",
        "customer_order",
        "sales_order_items",
        "sales_order_items.product",
        "sales_order_items.unit",
        "shipment_address.country",
        "delivery_address.country",
        "invoice_address.country",
        "customs_detail",
        "fulfillment_center"
      ]
    ]
  end
end

#revertObject



134
135
136
137
138
139
# File 'app/controllers/comee/core/sales_orders_controller.rb', line 134

def revert
  order = @service.revert(params[:id])
  render_content(order)
rescue StandardError => e
  render json: {success: false, error: e.message}
end

#showObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/comee/core/sales_orders_controller.rb', line 36

def show
  super do
    [
      SalesOrder.includes(
        :customer_order,
        :client,
        :customs_detail,
        shipment_address: :country,
        delivery_address: :country,
        invoice_address: :country,
        sales_order_items: :unit
      ).find(params[:id]),
      include: [
        "client",
        "customer_order",
        "sales_order_items",
        "sales_order_items.product",
        "sales_order_items.unit",
        "shipment_address.country",
        "delivery_address.country",
        "invoice_address.country",
        "customs_detail",
        "fulfillment_center"
      ]
    ]
  end
end

#submitObject



106
107
108
109
110
111
# File 'app/controllers/comee/core/sales_orders_controller.rb', line 106

def submit
  order = @service.submit(params[:id])
  render_content(order)
rescue StandardError => e
  render json: {success: false, error: e.message}
end

#updateObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/comee/core/sales_orders_controller.rb', line 64

def update
  super do
    {
      include: [
        "client",
        "customer_order",
        "sales_order_items",
        "sales_order_items.product",
        "sales_order_items.unit",
        "fulfillment_center"
      ]
    }
  end
end