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
94
95
96
97
98
99
100
101
|
# File 'app/grids/dashboard/v2/package_detail_column.rb', line 12
def self.package_details(reservation, grid)
property = reservation.property
prepaid = if property&.is_prepayment
amount = ActionController::Base.helpers.humanized_money_with_symbol(reservation.paid_amount)
text = I18n.t('reservation.prepayment', amount: amount)
prepayment_html(text)
elsif reservation.charged_amount.present?
text = nil
if reservation.cc_provider.present?
text = I18n.t('reservation.prepayment', amount: reservation.format_charged_amount)
elsif reservation.promptpay_provider.present?
amount = "QR Code #{reservation.format_charged_amount}"
text = I18n.t('reservation.prepayment', amount: amount)
elsif reservation.true_wallet_provider.present?
amount = "TrueMoney wallet #{reservation.format_charged_amount}"
text = I18n.t('reservation.prepayment', amount: amount)
elsif reservation.shopee_pay_provider.present?
amount = "Shopee Pay #{reservation.format_charged_amount}"
text = I18n.t('reservation.prepayment', amount: amount)
elsif reservation.alipay_provider.present?
amount = "Alipay #{reservation.format_charged_amount}"
text = I18n.t('reservation.prepayment', amount: amount)
elsif reservation.wechat_pay_provider.present?
amount = "WeChat Pay #{reservation.format_charged_amount}"
text = I18n.t('reservation.prepayment', amount: amount)
elsif reservation.vendor_payment.present?
format_charged_amount = if reservation.package? && reservation.package_obj.amount.present?
HhMoney.from_amount(reservation.package_obj.amount,
reservation.restaurant.currency_code).default_format
else
reservation.charged_amount_in_baht
end
amount = "#{reservation.payment_type_provider&.split('_')&.join(' ')&.titleize} #{format_charged_amount}"
text = I18n.t('reservation.prepayment', amount: amount)
end
prepayment_html(text)
end
due_amount_display = if reservation.decorate.due_amount.positive?
due_amount_money = reservation.decorate.due_amount
amount = HhMoney.from_amount(due_amount_money.amount,
due_amount_money.currency).default_format
text = I18n.t('reservation.due_amount', amount: amount)
due_amount_html(text)
end
vouchers = reservation.reservation_vouchers
voucher_detail = if vouchers.present?
amount = HhMoney.new(vouchers.sum(&:amount_cents), vouchers.first.amount.currency.to_s)
"<div class='ba br2 pa2 dib bg-purple white b--white'>
Voucher: #{amount}
</div>"
end
blogger_info = if property&.covered_by_hh?
text = I18n.t('reservation.covered_by_hh_info')
"<div class='ba br2 pa2 dib bg-dark-red white b--white'>
#{text}
</div>"
end
if reservation.package_obj.nil?
grid.raw "<div>No package #{prepaid}</div>"
else
details = reservation.package_obj.formatted_packages.map do |package|
dynamic_package_short = reservation.package_obj.try(:dynamic_type_short) || reservation.package_obj.type_short
content = I18n.t("views.booking.package_data.#{dynamic_package_short}", name: package[:name],
net_price: package[:net_price], quantity: package[:quantity])
if package['dynamic_pricing_title'].present?
content += "<div class='b dark-red'>— #{package['dynamic_pricing_title']}</div>"
end
"<li>#{content}</li>"
end.join('</br>')
html = <<-HTML
<div class="pv2">
<p class="dib bg-#{reservation.package_obj.type_short} ph3 pv2 b ba b--#{reservation.package_obj.type_short} br2 black">
#{reservation.package_obj.type}
</p>
<ul class="ma0 pl3">
#{details}
</ul>
#{prepaid}
#{due_amount_display}
#{voucher_detail}
#{blogger_info}
</div>
HTML
grid.raw html
end
end
|