Class: Comee::Core::ShipmentItemsController
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
#application_code, #authenticate, #current_application, #current_user, #render_content, #render_error, #skip_bullet
Instance Method Details
#filter ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'app/controllers/comee/core/shipment_items_controller.rb', line 15
def filter
shipment_item = ShipmentItem.includes(sales_order_item: [:customer_order_item, :unit, :product, sales_order: :client])
.ransack(params[:q]).result
options = {
include: [
"sales_order_item.sales_order.client",
"sales_order_item.sales_order.customer_order",
"sales_order_item.product",
"sales_order_item.unit",
"sales_order_item.customer_order_item"
]
}
render_content(shipment_item, options)
end
|
#filter_for_client ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
|
# File 'app/controllers/comee/core/shipment_items_controller.rb', line 30
def filter_for_client
shipment_items = ShipmentItem.joins(sales_order_item: :sales_order)
.where(
comee_core_sales_order_items: {
comee_core_sales_orders: {
client_id: params[:id]
}
}
)
render_content(shipment_items)
end
|
#filter_with_status ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'app/controllers/comee/core/shipment_items_controller.rb', line 42
def filter_with_status
items = ShipmentItem.includes(sales_order_item: %i[sales_order product unit])
.ransack(params[:q]).result
statuses = ItemStatus.where(shipment_item_id: items.map(&:id))
.select("MAX(id) AS max_id, shipment_item_id")
.group(:shipment_item_id)
.all
ids = statuses.map(&:max_id)
statuses = ItemStatus.where(id: ids).each_with_object({}) { |status, res| res[status.shipment_item_id] = status }
result = items.each_with_object([]) do |item, res|
status = statuses[item.id]
data = {
sales_order_no: item.sales_order_item.sales_order.order_number,
customer_item_no: item.sales_order_item.customer_item_no,
product_code: item.sales_order_item.product.code,
unit: item.sales_order_item.unit.code,
quantity: item.sales_order_item.quantity,
delivery_date: item.sales_order_item.delivery_date,
handover_date: item.sales_order_item.sales_order.handover_date,
status: status&.status
}
res << data.merge(status&.details)
end
render json: {success: true, data: result}
end
|
#index ⇒ Object
6
7
8
9
10
11
12
13
|
# File 'app/controllers/comee/core/shipment_items_controller.rb', line 6
def index
super do
[
ShipmentItem.includes(sales_order_item: [sales_order: :client]).all,
include: ["sales_order_item.sales_order.client"]
]
end
end
|