Class: Comee::Core::SalesOrderItemsController

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

Instance Method Summary collapse

Methods included from Common

#create, #show, #update

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

#activateObject



82
83
84
85
86
# File 'app/controllers/comee/core/sales_order_items_controller.rb', line 82

def activate
  item = set_object
  item.update(canceled: false)
  render_content(item)
end

#cancelObject



64
65
66
67
68
# File 'app/controllers/comee/core/sales_order_items_controller.rb', line 64

def cancel
  item = set_object
  item.update!(canceled: true, quantity: 0)
  render_content(item)
end

#cancel_quantityObject



70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/comee/core/sales_order_items_controller.rb', line 70

def cancel_quantity
  item = set_object
  to_cancel = cancel_quantity_params[:quantity]
  raise(StandardError, "Quantity to cancel is greater than available quantity.") if to_cancel > item.quantity_remaining

  item.quantity_canceled += to_cancel
  item.save!
  render_content(item)
rescue StandardError => e
  render_error(e)
end

#destroyObject



88
89
90
91
# File 'app/controllers/comee/core/sales_order_items_controller.rb', line 88

def destroy
  Comee::Core::SalesOrderItem.destroy(params[:id])
  render json: {success: true}
end

#filterObject



18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/comee/core/sales_order_items_controller.rb', line 18

def filter
  data = SalesOrderItem.includes(
    :sales_order,
    :purchase_order_item,
    :customer_order_item,
    :source,
    :product,
    :unit
  ).ransack(params[:q]).result
  render_content(data)
end

#indexObject



6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/comee/core/sales_order_items_controller.rb', line 6

def index
  super do
    SalesOrderItem.includes(
      :sales_order,
      :customer_order_item,
      :source,
      :product,
      :unit
    ).where(sales_order_id: params[:id])
  end
end

#shipment_detailsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/comee/core/sales_order_items_controller.rb', line 30

def shipment_details
  details = SalesOrderItem.includes(
    shipment_items: [
      {shipment_instruction_items: :pod},
      :item_statuses
    ],
    # sales_order: :fulfillment_center,
    purchase_order_item: [{purchase_order: :supplier}]
  ).find(params[:id])
  render_content(
    details,
    {
      include: [
        "shipment_items.shipment_instruction_items.pod",
        "shipment_items.item_statuses",
        "purchase_order_item.purchase_order.supplier",
        "sales_order.fulfillment_center"
      ],
      serializer: SalesOrderItemDetailSerializer
    }
  )
end

#suggest_valuesObject



53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/comee/core/sales_order_items_controller.rb', line 53

def suggest_values
  service = CustomerOrderService.new
  result = service.suggest_values(
    params[:id],
    suggest_params[:from_id],
    suggest_params[:to_id],
    suggest_params[:quantity]
  )
  render json: {success: true, data: result}
end