Module: EasyInvoices::Base

Defined in:
lib/easy_invoices/base.rb

Constant Summary collapse

DIGIT_RUBLEJ =
{ always_show_fraction: true, fraction_formatter: '%d', integrals_delimiter: ' ' }

Instance Method Summary collapse

Instance Method Details

#generate_act(options = {}) ⇒ Object



6
7
8
# File 'lib/easy_invoices/base.rb', line 6

def generate_act(options = {})
  generate_with(:act, options)
end

#generate_invoice(options = {}) ⇒ Object



10
11
12
# File 'lib/easy_invoices/base.rb', line 10

def generate_invoice(options = {})
  generate_with(:invoice, options)
end

#generate_with(kind, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/easy_invoices/base.rb', line 14

def generate_with(kind, options = {})
  begin
    check_easy_invoices_options(kind)
    check_document_data_method_existing
    generate_params_hash(kind, options)
    calculate_act_total_sum
    file = "EasyInvoices::#{kind.to_s.classify}".constantize.generate(@params_hash, options[:file_name])
    options[:success_callback].call(file) if options.dig(:success_callback)
    return { result: :success, file: file }
  rescue => e
    puts e.message
    options[:error_callback].call(file) if options.dig(:error_callback)
    return { result: :error, error_message: e.message }
  end
end