Skip to content

Commit

Permalink
Fix snail issue for all enterprise fees
Browse files Browse the repository at this point in the history
  • Loading branch information
vjain98 committed Oct 16, 2022
1 parent bf74612 commit 776b84f
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions app/controllers/admin/enterprise_fees_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Admin
class EnterpriseFeesController < Admin::ResourceController
before_action :load_enterprise_fee_set, only: :index
before_action :load_data
before_action :check_enterprise_fee_input, only: [:bulk_update]

def index
@include_calculators = params[:include_calculators].present?
Expand Down Expand Up @@ -35,13 +36,6 @@ def for_order_cycle
end

def bulk_update
@flat_percent_value = enterprise_fee_bulk_params.dig('collection_attributes', '0', 'calculator_attributes', 'preferred_flat_percent')

unless @flat_percent_value.nil? || Float(@flat_percent_value, exception: false)
flash[:error] = I18n.t(:calculator_preferred_value_error)
return redirect_to redirect_path
end

@enterprise_fee_set = Sets::EnterpriseFeeSet.new(enterprise_fee_bulk_params)

if @enterprise_fee_set.save
Expand Down Expand Up @@ -105,5 +99,25 @@ def enterprise_fee_bulk_params
]
)
end

def check_enterprise_fee_input
enterprise_fee_bulk_params['collection_attributes'].each do |_, fee_row|
enterprise_fees = fee_row['calculator_attributes']&.slice(
:preferred_flat_percent, :preferred_amount,
:preferred_first_item, :preferred_additional_item,
:preferred_minimal_amount, :preferred_normal_amount,
:preferred_discount_amount, :preferred_per_unit
)

next unless enterprise_fees

enterprise_fees.each do |_, enterprise_amount|
unless enterprise_amount.nil? || Float(enterprise_amount, exception: false)
flash[:error] = I18n.t(:calculator_preferred_value_error)
return redirect_to redirect_path
end
end
end
end
end
end

0 comments on commit 776b84f

Please sign in to comment.