Skip to content

Commit

Permalink
initialize tracking number in tracking number trail
Browse files Browse the repository at this point in the history
  • Loading branch information
hopgausi committed Feb 6, 2024
1 parent fff0b9d commit f161bd5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion bin/update_metadata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ rails db:migrate && (
rake db:seed:specific\[seed_test_results_recepient_types.rb\] &&
rake db:seed:specific\[seed_update_site_name.rb\] &&
rake db:seed:specific\[seed_update_sites.rb\] &&
rake db:seed:specific\[seed_name_mappings.rb\]
rake db:seed:specific\[seed_name_mappings.rb\] &&
rake db:seed:specific\[init_tracking_number.rb\]
)
14 changes: 14 additions & 0 deletions db/init_tracking_number.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
todate = Time.now.strftime('%Y%m%d')
last_tracking_number_trail = TrackingNumberTrail.last
puts last_tracking_number_trail
begin
file = JSON.parse(File.read("#{Rails.root}/public/tracker.json"))
value = file[todate]
if value.nil? && last_tracking_number_trail.nil?
TrackingNumberTrail.create(date: todate, current_value: 1)
elsif last_tracking_number_trail.nil?
TrackingNumberTrail.create(date: todate, current_value: value.to_i)
end
rescue StandardError => _e
TrackingNumberTrail.create(date: todate, current_value: 1) if last_tracking_number_trail.nil?
end
2 changes: 1 addition & 1 deletion lib/tracking_number_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def self.generate_tracking_number
day = Time.now.strftime('%d')
last_tracking_number_trail = TrackingNumberTrail.last
date = last_tracking_number_trail&.date || todate
current_value = last_tracking_number_trail&.current_value || 3500
current_value = last_tracking_number_trail&.current_value || 1
value = todate.to_i > date.to_i ? prepad_str(1, 3) : prepad_str(current_value.to_i + 1, 3)
tracking_number = "X#{site_code}#{year}#{get_month(month)}#{get_day(day)}NL#{value}"
TrackingNumberTrail.create(date: todate, current_value: value.to_i)
Expand Down

0 comments on commit f161bd5

Please sign in to comment.