Class: SpreeCmCommissioner::Guest
- Inherits:
-
Base
- Object
- Spree::Base
- Base
- SpreeCmCommissioner::Guest
show all
- Includes:
- KycBitwise
- Defined in:
- app/models/spree_cm_commissioner/guest.rb
Constant Summary
Constants included
from KycBitwise
KycBitwise::BIT_FIELDS, KycBitwise::ORDERED_BIT_FIELDS
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from KycBitwise
#available_social_contact_platforms, #kyc?, #kyc_fields, #kyc_value_enabled?, #unordered_kyc_fields
Class Method Details
.csv_importable_columns ⇒ Object
53
54
55
56
57
58
59
|
# File 'app/models/spree_cm_commissioner/guest.rb', line 53
def self.csv_importable_columns
i[
first_name last_name phone_number age dob gender address other_occupation
entry_type nationality_id other_organization expectation emergency_contact bib_number
preferred_telegram_user_id seat_number
]
end
|
Instance Method Details
#allowed_checkout? ⇒ Boolean
no validation for each field as we allow user to save data to model partially.
62
63
64
|
# File 'app/models/spree_cm_commissioner/guest.rb', line 62
def allowed_checkout?
kyc_fields.all? { |field| allowed_checkout_for?(field) }
end
|
#allowed_checkout_for?(field) ⇒ Boolean
rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'app/models/spree_cm_commissioner/guest.rb', line 66
def allowed_checkout_for?(field)
return first_name.present? && last_name.present? if field == :guest_name
return gender.present? if field == :guest_gender
return dob.present? if field == :guest_dob
return occupation.present? || other_occupation.present? if field == :guest_occupation
return nationality.present? if field == :guest_nationality
return age.present? if field == :guest_age
return emergency_contact.present? if field == :guest_emergency_contact
return other_organization.present? if field == :guest_organization
return expectation.present? if field == :guest_expectation
return social_contact_platform.present? && social_contact.present? if field == :guest_social_contact
return upload_later? || (id_card.present? && id_card.allowed_checkout?) if field == :guest_id_card
return address.present? if field == :guest_address
return phone_number.present? if field == :guest_phone_number
false
end
|
#assign_seat_number ⇒ Object
123
124
125
126
127
|
# File 'app/models/spree_cm_commissioner/guest.rb', line 123
def assign_seat_number
return if seat_number.present?
assign_seat_number!
end
|
#assign_seat_number! ⇒ Object
129
130
131
132
133
134
|
# File 'app/models/spree_cm_commissioner/guest.rb', line 129
def assign_seat_number!
index = bib_number - 1
positions = line_item.variant.seat_number_positions || []
self.seat_number = (positions[index] if index >= 0 && index < positions.size)
end
|
#bib_display_prefix? ⇒ Boolean
182
183
184
|
# File 'app/models/spree_cm_commissioner/guest.rb', line 182
def bib_display_prefix?
line_item.variant.bib_display_prefix?
end
|
#bib_required? ⇒ Boolean
178
179
180
|
# File 'app/models/spree_cm_commissioner/guest.rb', line 178
def bib_required?
line_item.variant.bib_prefix.present?
end
|
#current_age ⇒ Object
172
173
174
175
176
|
# File 'app/models/spree_cm_commissioner/guest.rb', line 172
def current_age
return nil if dob.nil?
((Time.zone.now - dob.to_time) / 1.year.seconds).floor
end
|
bib_number: 345, bib_prefix: 5KM, bib_zerofill: 5 => return 5KM00345 bib_number: 345, bib_prefix: 5KM, bib_zerofill: 2 => return 5KM345
208
209
210
211
212
213
214
215
216
217
218
219
|
# File 'app/models/spree_cm_commissioner/guest.rb', line 208
def formatted_bib_number
return nil if bib_prefix.blank?
return nil if bib_number.blank?
filled_bib_number = bib_number.to_s.rjust(line_item.variant.bib_zerofill.to_i, '0')
if bib_display_prefix?
"#{bib_prefix}#{filled_bib_number}"
else
filled_bib_number
end
end
|
#full_name ⇒ Object
136
137
138
|
# File 'app/models/spree_cm_commissioner/guest.rb', line 136
def full_name
[first_name, last_name].compact_blank.join(' ')
end
|
#generate_bib ⇒ Object
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
# File 'app/models/spree_cm_commissioner/guest.rb', line 186
def generate_bib
return if bib_prefix.present?
return unless bib_required?
return if event_id.blank?
self.bib_prefix = line_item.variant.bib_prefix
last_bib_number = event.guests
.where(bib_prefix: bib_prefix)
.maximum(:bib_number) || 0
self.bib_number = last_bib_number + 1
self.bib_index = "#{event_id}-#{bib_prefix}-#{bib_number}"
end
|
#generate_bib! ⇒ Object
201
202
203
204
|
# File 'app/models/spree_cm_commissioner/guest.rb', line 201
def generate_bib!
generate_bib
save!
end
|
#generate_png_qr(size = 120) ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'app/models/spree_cm_commissioner/guest.rb', line 152
def generate_png_qr(size = 120)
qrcode = RQRCode::QRCode.new(qr_data)
qrcode.as_png(
bit_depth: 1,
border_modules: 1,
color_mode: ChunkyPNG::COLOR_GRAYSCALE,
color: 'black',
file: nil,
fill: 'white',
module_px_size: 4,
resize_exactly_to: false,
resize_gte_to: false,
size: size
)
end
|
#generate_svg_qr ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
|
# File 'app/models/spree_cm_commissioner/guest.rb', line 140
def generate_svg_qr
qrcode = RQRCode::QRCode.new(qr_data)
qrcode.as_svg(
color: '000',
shape_rendering: 'crispEdges',
module_size: 5,
standalone: true,
use_path: true,
viewbox: '0 0 20 10'
)
end
|
#qr_data ⇒ Object
168
169
170
|
# File 'app/models/spree_cm_commissioner/guest.rb', line 168
def qr_data
token
end
|
#require_kyc_field? ⇒ Boolean
rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'app/models/spree_cm_commissioner/guest.rb', line 84
def require_kyc_field?
kyc_fields.any? do |field|
case field
when :guest_name
first_name.blank? || last_name.blank?
when :guest_gender
gender.blank?
when :guest_dob
dob.blank?
when :guest_age
age.blank?
when :guest_occupation
occupation.blank? && other_occupation.blank?
when :guest_nationality
nationality.blank?
when :guest_emergency_contact
emergency_contact.blank?
when :guest_organization
other_organization.blank?
when :guest_expectation
expectation.blank?
when :guest_social_contact
social_contact_platform.blank? || social_contact.blank?
when :guest_id_card
id_card.blank?
when :guest_address
address.blank?
when :guest_phone_number
phone_number.blank?
else
false
end
end
end
|
#set_event_id ⇒ Object
119
120
121
|
# File 'app/models/spree_cm_commissioner/guest.rb', line 119
def set_event_id
self.event_id ||= line_item.associated_event&.id if line_item.present?
end
|