4
5
6
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
35
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'app/serializers/api/v5/reservations/common_fields_serializer.rb', line 4
def packages(reservation)
return [] if reservation.blank?
if reservation.package_obj.present? && reservation.package_obj.formatted_packages.present?
arr_packages = reservation.package_obj&.formatted_packages&.map do |formatted_package|
= reservation..select do |section, |
package = section.&.package&.presence || HhPackage::Package::Ayce.new
restaurant_package = HhPackage::RestaurantPackage.find_by(id: formatted_package['restaurant_package_id'])
package == restaurant_package&.package
end.map do |section, |
= section..group(:package_menu_id)
= .map do ||
box = []
box_quantity = 0
if .subsections.present?
section..select { |m| m[:package_menu_id] == [:package_menu_id] }.map do ||
box_quantity += 1
subsections = .subsections.map do |subsection|
= subsection..map do ||
{
id: .id,
name: ..name,
quantity: .quantity,
price: ..price.amount.to_i,
}
end
{
id: subsection.id,
name: subsection..name,
menus: ,
}
end
box << { box: subsections }
end
end
{
id: .id,
name: ..name,
quantity: .subsections.present? ? box_quantity : .quantity,
price: ..price.amount.to_i,
subsections: box,
}
end
{ name: section..name, id: section.id, menus: }
end
package = HhPackage::RestaurantPackage.find_by(id: formatted_package['restaurant_package_id'])&.package
if package.nil?
{ name: '', amount: '', net_price: '', quantity: 1 }
else
is_accept_many_quantity =
HhPackage::Pricing::ACCEPT_MANY_QUANTITIES.include?(package.dynamic_price_pricing_model.to_sym)
support_dynamic_pricing_feature = reservation.booking_channel.support_dynamic_pricing
rules = package.dynamic_pricings_as_json(for_rules_attribute: true,
support_dynamic_pricing_feature: support_dynamic_pricing_feature,
time_zone: reservation.restaurant&.time_zone)
price_finder =
HhPackage::ReservationPackages::PriceFinder.new(use_dynamic_pricing: support_dynamic_pricing_feature)
formatted_package.slice(:name, :amount, :kids_amount, :net_price, :quantity, :id).merge(
hh_menu_package_id: (package),
is_add_on: package.respond_to?(:is_add_on) ? package.is_add_on? : false,
pricing_type: package.dynamic_price_pricing_model,
sections: ,
kids_price_rate: 0, kids_price_v2: price_finder.kids_price_list(package),
use_kids_price: price_finder.use_kids_price?(package),
rules: rules,
skip_time_selection: package.skip_time_selection,
is_accept_many_quantity: is_accept_many_quantity,
custom_net_price: package.fetch_package_attr&.custom_net_price,
comemore_payless: price_finder.valid_come_more_pay_less?(package, reservation.date),
pricing_groups: formatted_package['pricing_groups'].presence&.first || {},
selected_special_menus: (
reservation., formatted_package['restaurant_package_id']
),
charge_policy: package.charge_policy,
)
end
end
arr_packages.all? { |pkg| pkg[:name].blank? } ? [] : arr_packages
else
[]
end
end
|