added tokens

This commit is contained in:
olegphenomenon 2022-02-09 16:18:25 +02:00
parent c2969fa877
commit 7e0c6b3afb
13 changed files with 94 additions and 62 deletions

View file

@ -41,21 +41,14 @@ class Invoice < ApplicationRecord
attribute :vat_rate, ::Type::VatRate.new
def set_invoice_number
# last_no = Invoice.order(number: :desc).limit(1).pick(:number)
# if last_no && last_no >= Setting.invoice_number_min.to_i
# self.number = last_no + 1
# else
# self.number = Setting.invoice_number_min.to_i
# end
# return if number <= Setting.invoice_number_max.to_i
# errors.add(:base, I18n.t('failed_to_generate_invoice_invoice_number_limit_reached'))
# logger.error('INVOICE NUMBER LIMIT REACHED, COULD NOT GENERATE INVOICE')
# throw(:abort)
result = EisBilling::GetInvoiceNumber.send_invoice
if JSON.parse(result.body)['code'] == '403'
errors.add(:base, I18n.t('cannot get access'))
logger.error('PROBLEM WITH TOKEN')
throw(:abort)
end
if JSON.parse(result.body)['error'] == 'out of range'
errors.add(:base, I18n.t('failed_to_generate_invoice_invoice_number_limit_reached'))
logger.error('INVOICE NUMBER LIMIT REACHED, COULD NOT GENERATE INVOICE')