mirror of
https://github.com/internetee/registry.git
synced 2025-07-30 06:26:15 +02:00
Corrected monthly invoices for sending to omniva
This commit is contained in:
parent
0a20f567c2
commit
80c4057b8f
2 changed files with 37 additions and 6 deletions
|
@ -39,6 +39,7 @@ class SendMonthlyInvoicesJob < ApplicationJob
|
|||
sync_with_directo
|
||||
end
|
||||
end
|
||||
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
def send_email_to_registrar(invoice:, registrar:)
|
||||
|
@ -52,7 +53,7 @@ class SendMonthlyInvoicesJob < ApplicationJob
|
|||
end
|
||||
|
||||
def create_invoice(summary, registrar)
|
||||
invoice = registrar.init_monthly_invoice(summary)
|
||||
invoice = registrar.init_monthly_invoice(normalize(summary))
|
||||
invoice.number = assign_monthly_number
|
||||
return unless invoice.save!
|
||||
|
||||
|
@ -108,4 +109,37 @@ class SendMonthlyInvoicesJob < ApplicationJob
|
|||
|
||||
Setting.directo_monthly_number_last = num.to_i
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def normalize(summary, lines: [])
|
||||
sum = summary.dup
|
||||
line_map = Hash.new 0
|
||||
sum['invoice_lines'].each { |l| line_map[l] += 1 }
|
||||
|
||||
line_map.each_key do |count|
|
||||
count['quantity'] = line_map[count] unless count['unit'].nil?
|
||||
regex = /Domeenide ettemaks|Domains prepayment/
|
||||
count['quantity'] = -1 if count['description'].match?(regex)
|
||||
lines << count
|
||||
end
|
||||
|
||||
sum['invoice_lines'] = summarize_lines(lines)
|
||||
sum
|
||||
end
|
||||
|
||||
def summarize_lines(invoice_lines, lines: [])
|
||||
line_map = Hash.new 0
|
||||
invoice_lines.each do |l|
|
||||
hash = l.with_indifferent_access.except(:start_date, :end_date)
|
||||
line_map[hash] += 1
|
||||
end
|
||||
|
||||
line_map.each_key do |count|
|
||||
count['price'] = (line_map[count] * count['price'].to_f).round(3) unless count['price'].nil?
|
||||
lines << count
|
||||
end
|
||||
|
||||
lines
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,14 +17,11 @@ module Registrar::BookKeeping
|
|||
return unless activities.any?
|
||||
|
||||
invoice = {
|
||||
'number': 1,
|
||||
'customer': compose_directo_customer,
|
||||
'number': 1, 'customer': compose_directo_customer,
|
||||
'language': language == 'en' ? 'ENG' : '', 'currency': activities.first.currency,
|
||||
'date': month.end_of_month.strftime('%Y-%m-%d')
|
||||
}.as_json
|
||||
|
||||
invoice['invoice_lines'] = prepare_invoice_lines(month: month, activities: activities)
|
||||
|
||||
invoice
|
||||
end
|
||||
|
||||
|
@ -92,7 +89,7 @@ module Registrar::BookKeeping
|
|||
def add_product_timeframe(line:, activity:, duration:)
|
||||
create_time = activity.created_at
|
||||
line['start_date'] = (create_time + (duration - 1).year).end_of_month.strftime('%Y-%m-%d')
|
||||
line['end_date'] = (create_time + (duration - 1).year + 1).end_of_month.strftime('%Y-%m-%d')
|
||||
line['end_date'] = (create_time + duration.year).end_of_month.strftime('%Y-%m-%d')
|
||||
end
|
||||
|
||||
def description_in_language(price:, yearly:)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue