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
|
# File 'app/controllers/api/partner/v1/bills_controller.rb', line 29
def export
permitted_parameters = params.require(:reservation).permit(:month, :year, :type, emails: [])
emails = (permitted_parameters[:emails].presence || []).to_set.add(current_staff.email).to_a
messages = []
if permitted_parameters[:month].blank? || permitted_parameters[:year].blank?
messages << I18n.t('partner.errors.bills.export.month_year_blank')
end
emails.each do |email|
unless ::EmailValidator.valid?(email)
messages << I18n.t('partner.errors.bills.export.e_mail_invalid',
email: email)
end
end
if permitted_parameters[:month] > Time.current.month && permitted_parameters[:year] >= Time.current.year
messages << I18n.t('partner.errors.bills.export.month_year_less_than_current')
end
return render json: { status: 'failed', message: messages } if messages.present?
start_date = DateTime.new(permitted_parameters[:year], permitted_parameters[:month]).beginning_of_month
end_date = start_date.end_of_month
data_type = permitted_parameters.require(:type)
restaurants.each do |restaurant|
NotificationWorkers::ReservationReport.fix_queue_perform_async(
:restaurant_managers,
{
emails: emails,
restaurant_id: restaurant.id,
start_date: start_date,
end_date: end_date,
data_type: data_type,
date_type: :date,
report_type: :billing,
},
)
end
render json: { status: 'success', message: I18n.t('partner.errors.bills.export.send_email_billing') }
end
|