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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'app/controllers/kaui/custom_fields_controller.rb', line 53
def create
@custom_field = Kaui::CustomField.new(params.require(:custom_field))
param_uuid = @custom_field.object_id
test_uuid = nil
case @custom_field.object_type.to_sym
when :ACCOUNT
begin
test_uuid = Kaui::Account.find_by_id_or_key(param_uuid, false, false, options_for_klient)
rescue StandardError
end
when :BUNDLE
begin
test_uuid = Kaui::Bundle.find_by_id_or_key(param_uuid, options_for_klient)
rescue StandardError
end
when :SUBSCRIPTION
begin
test_uuid = Kaui::Subscription.find_by_id(param_uuid, options_for_klient)
rescue StandardError
end
when :INVOICE
begin
test_uuid = Kaui::Invoice.find_by_id(param_uuid, false, 'NONE', options_for_klient)
rescue StandardError
end
when :PAYMENT
begin
test_uuid = Kaui::InvoicePayment.find_by_id(param_uuid, false, true, options_for_klient)
rescue StandardError
end
begin
test_uuid = Kaui::Payment.find_by_external_key(param_uuid, false, true, options_for_klient)
rescue StandardError
end
when :INVOICE_ITEM
begin
test_uuid = Kaui::Invoice.find_by_invoice_item_id(param_uuid, false, 'NONE', options_for_klient)
rescue StandardError
end
end
if test_uuid.blank?
flash[:error] = I18n.translate('object_invalid_dont_exist')
redirect_to custom_fields_path
return
end
model = case @custom_field.object_type.to_sym
when :ACCOUNT
Kaui::Account.new(account_id: @custom_field.object_id)
when :BUNDLE
Kaui::Bundle.new(bundle_id: @custom_field.object_id)
when :SUBSCRIPTION
Kaui::Subscription.new(subscription_id: @custom_field.object_id)
when :INVOICE
Kaui::Invoice.new(invoice_id: @custom_field.object_id)
when :PAYMENT
Kaui::Payment.new(payment_id: @custom_field.object_id)
when :INVOICE_ITEM
Kaui::InvoiceItem.new(invoice_item_id: @custom_field.object_id)
else
flash.now[:error] = I18n.translate('invalid_object_type', error: @custom_field.object_type)
render :new and return
end
model.add_custom_field(@custom_field, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
redirect_to custom_fields_path, notice: I18n.translate('custom_field_created_success')
end
|