SU2-33 | Фикс критических и серьёзных ошибок, удаление/перезагрузка организации, пагинация, favicon
This commit is contained in:
@@ -6,11 +6,12 @@ class FileProcessorJob
|
||||
include Sidekiq::Job
|
||||
|
||||
def perform(inn, report_id)
|
||||
raise ArgumentError, "Некорректный ИНН: #{inn}" unless inn.to_s.match?(/\A\d{10}(\d{2})?\z/)
|
||||
|
||||
report = Report.find(report_id)
|
||||
Rails.logger.info "=== Начало загрузки для ИНН: #{inn} ==="
|
||||
|
||||
# Временная папка
|
||||
temp_dir = Rails.root.join('tmp', 'reports', inn)
|
||||
temp_dir = Rails.root.join('tmp', 'reports', inn.to_s.gsub(/[^0-9]/, ''))
|
||||
FileUtils.mkdir_p(temp_dir)
|
||||
|
||||
download_inn(inn, temp_dir.to_s)
|
||||
@@ -26,7 +27,9 @@ class FileProcessorJob
|
||||
)
|
||||
|
||||
# Создаём YearlyFile и прикрепляем xlsx
|
||||
yearly_file = organization.yearly_files.build(year: 0)
|
||||
year_from_filename = File.basename(file_path, '.*').split('_')[2].to_i
|
||||
year_from_filename = 0 unless (2000..2099).cover?(year_from_filename)
|
||||
yearly_file = organization.yearly_files.build(year: year_from_filename)
|
||||
yearly_file.file.attach(
|
||||
io: File.open(file_path),
|
||||
filename: File.basename(file_path)
|
||||
@@ -57,18 +60,28 @@ class FileProcessorJob
|
||||
'Accept-Language' => 'en-US,en;q=0.9',
|
||||
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
|
||||
}
|
||||
content = HTTParty.get(url, headers: headers).body
|
||||
json_need ? JSON.parse(content) : content
|
||||
response = HTTParty.get(url, headers: headers, timeout: 30)
|
||||
raise "HTTP #{response.code} при запросе #{url}" unless response.success?
|
||||
|
||||
json_need ? JSON.parse(response.body) : response.body
|
||||
end
|
||||
|
||||
def download_inn(inn, output)
|
||||
url = "https://bo.nalog.gov.ru/advanced-search/organizations/search?query=#{inn}&page=0&size=20"
|
||||
content = get_content(url, true)
|
||||
id = content['content'][0]['id']
|
||||
org_entry = content.dig('content', 0) or raise "Организация с ИНН #{inn} не найдена"
|
||||
id = org_entry['id']
|
||||
|
||||
url = "https://bo.nalog.gov.ru/nbo/organizations/#{id}/bfo/"
|
||||
content = get_content(url, true)
|
||||
periods_and_details_ids = content.map { |item| [item['period'], item['typeCorrections'][0]['correction']['id']] }
|
||||
raise "Нет отчётности для организации #{id}" if content.blank?
|
||||
|
||||
periods_and_details_ids = content.filter_map do |item|
|
||||
details_id = item.dig('typeCorrections', 0, 'correction', 'id')
|
||||
next if details_id.nil?
|
||||
|
||||
[item['period'], details_id]
|
||||
end
|
||||
|
||||
periods_and_details_ids.each do |period, details_id|
|
||||
url = "https://bo.nalog.gov.ru/download/bfo/#{id}?auditReport=false&balance=true"\
|
||||
|
||||
Reference in New Issue
Block a user