mirror of
https://github.com/internetee/registry.git
synced 2025-07-03 09:43:36 +02:00
Story#105855968 - Prepare xml for Directo
This commit is contained in:
parent
ca3e28f841
commit
e954c212c7
7 changed files with 96 additions and 21 deletions
1
Gemfile
1
Gemfile
|
@ -9,6 +9,7 @@ source 'https://rubygems.org'
|
||||||
|
|
||||||
# core
|
# core
|
||||||
gem 'rails', '4.2.4' # when update, all initializers eis_custom files needs check/update
|
gem 'rails', '4.2.4' # when update, all initializers eis_custom files needs check/update
|
||||||
|
gem 'rails-i18n', github: 'svenfuchs/rails-i18n', branch: 'rails-4-x'
|
||||||
gem 'iso8601', '0.8.6' # for dates and times
|
gem 'iso8601', '0.8.6' # for dates and times
|
||||||
gem 'hashie-forbidden_attributes', '0.1.1'
|
gem 'hashie-forbidden_attributes', '0.1.1'
|
||||||
gem 'SyslogLogger', '2.0', require: 'syslog/logger'
|
gem 'SyslogLogger', '2.0', require: 'syslog/logger'
|
||||||
|
|
10
Gemfile.lock
10
Gemfile.lock
|
@ -45,6 +45,15 @@ GIT
|
||||||
bundler (~> 1.2)
|
bundler (~> 1.2)
|
||||||
thor (~> 0.18)
|
thor (~> 0.18)
|
||||||
|
|
||||||
|
GIT
|
||||||
|
remote: https://github.com/svenfuchs/rails-i18n.git
|
||||||
|
revision: 4913b54a5d7026066ceb12a4523476a1411e86bb
|
||||||
|
branch: rails-4-x
|
||||||
|
specs:
|
||||||
|
rails-i18n (4.0.8)
|
||||||
|
i18n (~> 0.7)
|
||||||
|
railties (~> 4.0)
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
|
@ -626,6 +635,7 @@ DEPENDENCIES
|
||||||
que_mailer!
|
que_mailer!
|
||||||
railroady (= 1.3.0)
|
railroady (= 1.3.0)
|
||||||
rails (= 4.2.4)
|
rails (= 4.2.4)
|
||||||
|
rails-i18n!
|
||||||
rails-settings-cached (= 0.4.1)
|
rails-settings-cached (= 0.4.1)
|
||||||
rake
|
rake
|
||||||
ransack (= 1.5.1)
|
ransack (= 1.5.1)
|
||||||
|
|
|
@ -10,6 +10,10 @@ class Counter
|
||||||
@value.to_s
|
@value.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def now
|
||||||
|
@value
|
||||||
|
end
|
||||||
|
|
||||||
# pre-increment ".+" when x not present
|
# pre-increment ".+" when x not present
|
||||||
def next(x = 1)
|
def next(x = 1)
|
||||||
@value += x
|
@value += x
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
class Directo < ActiveRecord::Base
|
class Directo < ActiveRecord::Base
|
||||||
|
DOMAIN_TO_PRODUCT = {"ee" => "01EE", "com.ee" => "02COM", "pri.ee" => "03PRI", "fie.ee"=>"04FIE", "med.ee" => "05MED"}.freeze
|
||||||
belongs_to :item, polymorphic: true
|
belongs_to :item, polymorphic: true
|
||||||
|
|
||||||
def self.send_receipts
|
def self.send_receipts
|
||||||
|
@ -49,36 +50,84 @@ class Directo < ActiveRecord::Base
|
||||||
|
|
||||||
|
|
||||||
def self.send_monthly_invoices
|
def self.send_monthly_invoices
|
||||||
product_ids = {"ee" => "01EE", "com.ee" => "02COM", "pri.ee" => "03PRI", "fie.ee"=>"04FIE", "med.ee" => "05MED"}
|
I18n.locale = :et
|
||||||
month = Time.now - 1.month
|
month = Time.now - 1.month
|
||||||
invoices_until = month.end_of_month
|
invoices_until = month.end_of_month
|
||||||
# pochemu registrar has_many :accounts
|
date_format = "%Y-%m-%d"
|
||||||
|
|
||||||
activity_scope = AccountActivity.where(activity_type: [CREATE, RENEW])
|
Registrar.find_each do |registrar|
|
||||||
Registrar.joins(:account).find_each do |registrar|
|
|
||||||
next unless registrar.cash_account
|
next unless registrar.cash_account
|
||||||
counter = Counter.new
|
counter = Counter.new(1)
|
||||||
|
items = {}
|
||||||
|
registrar_activities = AccountActivity.where(account_id: registrar.account_ids).where("created_at BETWEEN ? AND ?",month.beginning_of_month, month.end_of_month)
|
||||||
|
|
||||||
|
# adding domains items
|
||||||
|
registrar_activities.where(activity_type: [AccountActivity::CREATE, AccountActivity::RENEW]).each do |activity|
|
||||||
|
pricelist = load_activity_pricelist(activity)
|
||||||
|
next unless pricelist
|
||||||
|
|
||||||
|
pricelist.years_amount.times do |i|
|
||||||
|
year = i+1
|
||||||
|
hash = {
|
||||||
|
"ProductID" => DOMAIN_TO_PRODUCT[pricelist.category],
|
||||||
|
"Unit" => "tk",
|
||||||
|
"ProductName" => ".#{pricelist.category} registreerimine: #{pricelist.years_amount} aasta",
|
||||||
|
"UnitPriceWoVAT" => pricelist.price_decimal/pricelist.years_amount
|
||||||
|
}
|
||||||
|
hash["StartDate"] = (activity.created_at + year.year).strftime(date_format) if year > 1
|
||||||
|
hash["EndDate"] = (activity.created_at + year.year + 1).strftime(date_format) if year > 1
|
||||||
|
|
||||||
|
if items.has_key?(hash)
|
||||||
|
items[hash]["Quantity"] += 1
|
||||||
|
else
|
||||||
|
items[hash] = {"RN"=>counter.next, "RR" => counter.now - i, "Quantity"=> 1}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
#adding prepaiments
|
||||||
|
registrar_activities.where(activity_type: [AccountActivity::ADD_CREDIT]).each do |activity|
|
||||||
|
hash = {"ProductID" => Setting.directo_receipt_product_name, "Unit" => "tk", "ProductName" => "Domeenide ettemaks", "UnitPriceWoVAT"=>activity.sum}
|
||||||
|
items[hash] = {"RN"=>counter.next, "RR" => counter.now, "Quantity"=> -1}
|
||||||
|
end
|
||||||
|
|
||||||
|
# generating XML
|
||||||
|
if items.any?
|
||||||
builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
|
builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
|
||||||
activity_scope.where(account_id: registrar.cash_account)
|
|
||||||
|
|
||||||
xml.invoices{
|
xml.invoices{
|
||||||
xml.invoice("Number"=>"13980",
|
xml.invoice("Number" =>"13980",
|
||||||
"InvoiceDate"=>invoices_until.strftime("%Y-%m-%d"),
|
"InvoiceDate" =>invoices_until.strftime(date_format),
|
||||||
"PaymentTerm"=>"E",
|
"PaymentTerm" =>"E",
|
||||||
"CustomerCode"=>registrar.directo_handle,
|
"CustomerCode"=>registrar.directo_handle,
|
||||||
"Language"=>"",
|
"Language" =>"",
|
||||||
"Currency"=>"EUR",
|
"Currency" =>registrar_activities.first.currency,
|
||||||
"SalesAgent"=>Setting.directo_sales_agent){
|
"SalesAgent" =>Setting.directo_sales_agent){
|
||||||
xml.line("RN" => counter.next, "RR"=>1, "ProductName"=> "Domeenide registreerimine - Juuli 2015")
|
xml.line("RN" => 1, "RR"=>1, "ProductName"=> "Domeenide registreerimine - #{I18n.l(invoices_until, format: "%B %Y").titleize}")
|
||||||
activity_scope.where(account_id: registrar.account_ids).each do |activity|
|
items.each do |line, val|
|
||||||
xml.line("RN"=>counter.next, "RR"=>"2", "ProductID"=>"01EE", "Quantity"=>"1911", "Unit"=>"tk", "ProductName"=>".ee registreerimine: 1 aasta", "UnitPriceWoVAT"=>"9.00")
|
xml.line(val.merge(line))
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
puts builder.to_xml
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.load_activity_pricelist activity
|
||||||
|
@pricelists ||= {}
|
||||||
|
return @pricelists[activity.log_pricelist_id] if @pricelists.has_key?(activity.log_pricelist_id)
|
||||||
|
|
||||||
|
pricelist = Pricelist.find_by(id: activity.log_pricelist_id) || PricelistVersion.find_by(item_id: activity.log_pricelist_id).try(:reify)
|
||||||
|
unless pricelist
|
||||||
|
@pricelists[activity.log_pricelist_id] = nil
|
||||||
|
Rails.logger.info("[DIRECTO] AccountActivity #{activity.id} cannot be sent as pricelist wasn't found #{activity.log_pricelist_id}")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
@pricelists[activity.log_pricelist_id] = pricelist.version_at(activity.created_at) || pricelist
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
|
@ -452,6 +452,7 @@ class Domain < ActiveRecord::Base
|
||||||
period_i ||= period
|
period_i ||= period
|
||||||
unit ||= period_unit
|
unit ||= period_unit
|
||||||
|
|
||||||
|
# TODO: test if name.scan(/\.(.+)\z/).first.first is faster
|
||||||
zone = name.split('.').drop(1).join('.')
|
zone = name.split('.').drop(1).join('.')
|
||||||
|
|
||||||
p = period_i / 365 if unit == 'd'
|
p = period_i / 365 if unit == 'd'
|
||||||
|
|
|
@ -8,6 +8,8 @@ class Pricelist < ActiveRecord::Base
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scope :valid_at, ->(time){ where("valid_from IS NULL OR valid_from <= ?", time).where("valid_to IS NULL OR valid_to >= ?", time) }
|
||||||
|
|
||||||
monetize :price_cents
|
monetize :price_cents
|
||||||
|
|
||||||
validates :price_cents, :price_currency, :price,
|
validates :price_cents, :price_currency, :price,
|
||||||
|
@ -27,6 +29,14 @@ class Pricelist < ActiveRecord::Base
|
||||||
"#{operation_category} #{category}"
|
"#{operation_category} #{category}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def years_amount
|
||||||
|
duration.to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
def price_decimal
|
||||||
|
price_cents / BigDecimal.new('100')
|
||||||
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def pricelist_for(zone, operation, period)
|
def pricelist_for(zone, operation, period)
|
||||||
lists = valid.where(category: zone, operation_category: operation, duration: period)
|
lists = valid.where(category: zone, operation_category: operation, duration: period)
|
||||||
|
|
|
@ -5,7 +5,7 @@ rescue ActiveRecord::NoDatabaseError => e
|
||||||
Rails.logger.info "Init settings didn't find database: #{e}"
|
Rails.logger.info "Init settings didn't find database: #{e}"
|
||||||
end
|
end
|
||||||
|
|
||||||
if con.present? && con.table_exists?('settings')
|
if false && con.present? && con.table_exists?('settings')
|
||||||
Setting.save_default(:admin_contacts_min_count, 1)
|
Setting.save_default(:admin_contacts_min_count, 1)
|
||||||
Setting.save_default(:admin_contacts_max_count, 10)
|
Setting.save_default(:admin_contacts_max_count, 10)
|
||||||
Setting.save_default(:tech_contacts_min_count, 1)
|
Setting.save_default(:tech_contacts_min_count, 1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue