mirror of
https://github.com/internetee/registry.git
synced 2025-07-30 22:46:22 +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
|
sync_with_directo
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# rubocop:enable Metrics/MethodLength
|
# rubocop:enable Metrics/MethodLength
|
||||||
|
|
||||||
def send_email_to_registrar(invoice:, registrar:)
|
def send_email_to_registrar(invoice:, registrar:)
|
||||||
|
@ -52,7 +53,7 @@ class SendMonthlyInvoicesJob < ApplicationJob
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_invoice(summary, registrar)
|
def create_invoice(summary, registrar)
|
||||||
invoice = registrar.init_monthly_invoice(summary)
|
invoice = registrar.init_monthly_invoice(normalize(summary))
|
||||||
invoice.number = assign_monthly_number
|
invoice.number = assign_monthly_number
|
||||||
return unless invoice.save!
|
return unless invoice.save!
|
||||||
|
|
||||||
|
@ -108,4 +109,37 @@ class SendMonthlyInvoicesJob < ApplicationJob
|
||||||
|
|
||||||
Setting.directo_monthly_number_last = num.to_i
|
Setting.directo_monthly_number_last = num.to_i
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -17,14 +17,11 @@ module Registrar::BookKeeping
|
||||||
return unless activities.any?
|
return unless activities.any?
|
||||||
|
|
||||||
invoice = {
|
invoice = {
|
||||||
'number': 1,
|
'number': 1, 'customer': compose_directo_customer,
|
||||||
'customer': compose_directo_customer,
|
|
||||||
'language': language == 'en' ? 'ENG' : '', 'currency': activities.first.currency,
|
'language': language == 'en' ? 'ENG' : '', 'currency': activities.first.currency,
|
||||||
'date': month.end_of_month.strftime('%Y-%m-%d')
|
'date': month.end_of_month.strftime('%Y-%m-%d')
|
||||||
}.as_json
|
}.as_json
|
||||||
|
|
||||||
invoice['invoice_lines'] = prepare_invoice_lines(month: month, activities: activities)
|
invoice['invoice_lines'] = prepare_invoice_lines(month: month, activities: activities)
|
||||||
|
|
||||||
invoice
|
invoice
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -92,7 +89,7 @@ module Registrar::BookKeeping
|
||||||
def add_product_timeframe(line:, activity:, duration:)
|
def add_product_timeframe(line:, activity:, duration:)
|
||||||
create_time = activity.created_at
|
create_time = activity.created_at
|
||||||
line['start_date'] = (create_time + (duration - 1).year).end_of_month.strftime('%Y-%m-%d')
|
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
|
end
|
||||||
|
|
||||||
def description_in_language(price:, yearly:)
|
def description_in_language(price:, yearly:)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue