diff --git a/app/controllers/concerns/deliverable.rb b/app/controllers/concerns/deliverable.rb
index 0ceae00674..d7ef4fb3c9 100644
--- a/app/controllers/concerns/deliverable.rb
+++ b/app/controllers/concerns/deliverable.rb
@@ -7,7 +7,7 @@ module Deliverable
def new
authorize! :manage, @invoice
- @recipient = @invoice.buyer.billing_email
+ @recipient = @invoice.registrar.billing_email
end
def create
diff --git a/app/models/ability.rb b/app/models/ability.rb
index 50e87c98eb..20f4e78bfb 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -69,7 +69,7 @@ def epp # Registrar/api_user dynamic role
end
def billing # Registrar/api_user dynamic role
- can(:manage, Invoice) { |i| i.buyer_id == @user.registrar_id }
+ can(:manage, Invoice) { |i| i.registrar == @user.registrar }
can :manage, :deposit
can :read, AccountActivity
can :manage, :balance_auto_reload
diff --git a/app/models/address.rb b/app/models/address.rb
new file mode 100644
index 0000000000..3e0a147cea
--- /dev/null
+++ b/app/models/address.rb
@@ -0,0 +1,36 @@
+class Address
+ attr_reader :parts
+
+ def initialize(parts)
+ @parts = parts
+ end
+
+ def street
+ parts[:street]
+ end
+
+ def zip
+ parts[:zip]
+ end
+
+ def city
+ parts[:city]
+ end
+
+ def state
+ parts[:state]
+ end
+
+ def country
+ parts[:country]
+ end
+
+ def ==(other)
+ parts == other.parts
+ end
+
+ def to_s
+ ordered_parts = [street, city, state, zip, country]
+ ordered_parts.reject(&:blank?).compact.join(', ')
+ end
+end
\ No newline at end of file
diff --git a/app/models/bank_account.rb b/app/models/bank_account.rb
new file mode 100644
index 0000000000..42d41387f4
--- /dev/null
+++ b/app/models/bank_account.rb
@@ -0,0 +1,7 @@
+class BankAccount
+ include ActiveModel::Model
+
+ attr_accessor :iban
+ attr_accessor :swift
+ attr_accessor :bank_name
+end
\ No newline at end of file
diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb
index eb8c846220..77503df834 100644
--- a/app/models/bank_transaction.rb
+++ b/app/models/bank_transaction.rb
@@ -31,7 +31,7 @@ def invoice
end
def registrar
- @registrar ||= Invoice.find_by(reference_no: reference_no)&.buyer
+ @registrar ||= Invoice.find_by(reference_no: reference_no)&.registrar
end
@@ -75,7 +75,7 @@ def bind_invoice(invoice_no)
return
end
- create_activity(invoice.buyer, invoice)
+ create_activity(invoice.registrar, invoice)
end
def create_activity(registrar, invoice)
diff --git a/app/models/company.rb b/app/models/company.rb
new file mode 100644
index 0000000000..6b30acfd88
--- /dev/null
+++ b/app/models/company.rb
@@ -0,0 +1,11 @@
+class Company
+ include ActiveModel::Model
+
+ attr_accessor :name
+ attr_accessor :registration_number
+ attr_accessor :vat_number
+ attr_accessor :address
+ attr_accessor :email
+ attr_accessor :phone
+ attr_accessor :website
+end
\ No newline at end of file
diff --git a/app/models/directo.rb b/app/models/directo.rb
index f062912f91..2784f67718 100644
--- a/app/models/directo.rb
+++ b/app/models/directo.rb
@@ -29,7 +29,7 @@ def self.send_receipts
"InvoiceDate" => invoice.issue_date.strftime("%Y-%m-%d"),
"PaymentTerm" => Setting.directo_receipt_payment_term,
"Currency" => invoice.currency,
- "CustomerCode"=> invoice.buyer.accounting_customer_code
+ "CustomerCode"=> invoice.registrar.accounting_customer_code
){
xml.line(
"ProductID" => Setting.directo_receipt_product_name,
diff --git a/app/models/invoice.rb b/app/models/invoice.rb
index a36825848d..6ccd445f51 100644
--- a/app/models/invoice.rb
+++ b/app/models/invoice.rb
@@ -1,10 +1,17 @@
class Invoice < ActiveRecord::Base
+ class Buyer < Company; end
+
+ class Seller < Company
+ attr_accessor :contact_person
+ attr_accessor :bank_account
+ end
+
include Versions
include Concerns::Invoice::Cancellable
include Concerns::Invoice::Payable
belongs_to :seller, class_name: 'Registrar'
- belongs_to :buyer, class_name: 'Registrar'
+ belongs_to :registrar
has_one :account_activity
has_many :items, class_name: 'InvoiceItem', dependent: :destroy
has_many :directo_records, as: :item, class_name: 'Directo'
@@ -26,12 +33,10 @@ class Invoice < ActiveRecord::Base
scope :overdue, -> { unpaid.non_cancelled.where('due_date < ?', Time.zone.today) }
- validates :due_date, :currency, :seller_name,
- :seller_iban, :buyer_name, :items, presence: true
+ validates :items, presence: true
before_create :set_invoice_number
before_create :calculate_total, unless: :total?
- before_create :apply_default_buyer_vat_no, unless: :buyer_vat_no?
attribute :vat_rate, ::Type::VATRate.new
@@ -56,19 +61,19 @@ def to_s
end
def seller_address
- [seller_street, seller_city, seller_state, seller_zip].reject(&:blank?).compact.join(', ')
+ [seller_address_street, seller_address_city, seller_address_state, seller_address_zip].reject(&:blank?).compact.join(', ')
end
def buyer_address
- [buyer_street, buyer_city, buyer_state, buyer_zip].reject(&:blank?).compact.join(', ')
+ [buyer_address_street, buyer_address_city, buyer_address_state, buyer_address_zip].reject(&:blank?).compact.join(', ')
end
def seller_country
- Country.new(seller_country_code)
+ Country.new(seller_address_country_code)
end
def buyer_country
- Country.new(buyer_country_code)
+ Country.new(buyer_address_country_code)
end
# order is used for directo/banklink description
@@ -103,12 +108,34 @@ def to_e_invoice
generator.generate
end
- private
+ def seller
+ bank_account = BankAccount.new(iban: seller_iban,
+ swift: seller_swift,
+ bank_name: seller_bank)
+
+ Seller.new(name: seller_name,
+ registration_number: seller_reg_no,
+ vat_number: seller_vat_no,
+ address: seller_address,
+ email: seller_email,
+ phone: seller_phone,
+ website: seller_url,
+ contact_person: seller_contact_name,
+ bank_account: bank_account)
+ end
- def apply_default_buyer_vat_no
- self.buyer_vat_no = buyer.vat_no
+ def buyer
+ Buyer.new(name: buyer_name,
+ registration_number: buyer_reg_no,
+ vat_number: buyer_vat_no,
+ address: buyer_address,
+ email: buyer_email,
+ phone: buyer_phone,
+ website: buyer_url)
end
+ private
+
def calculate_total
self.total = subtotal + vat_amount
end
diff --git a/app/models/invoice/e_invoice_generator.rb b/app/models/invoice/e_invoice_generator.rb
index 8ade3ae7f6..c7f388ad15 100644
--- a/app/models/invoice/e_invoice_generator.rb
+++ b/app/models/invoice/e_invoice_generator.rb
@@ -8,9 +8,9 @@ def initialize(invoice)
def generate
seller = EInvoice::Seller.new
- seller.name = invoice.seller_name
- seller.registration_number = invoice.seller_reg_no
- seller.vat_number = invoice.seller_vat_no
+ seller.name = invoice.seller.name
+ seller.registration_number = invoice.seller.registration_number
+ seller.vat_number = invoice.seller.vat_number
seller_legal_address = EInvoice::Address.new
seller_legal_address.line1 = invoice.seller_street
@@ -21,10 +21,10 @@ def generate
seller.legal_address = seller_legal_address
buyer = EInvoice::Buyer.new
- buyer.name = invoice.buyer_name
- buyer.registration_number = invoice.buyer_reg_no
- buyer.vat_number = invoice.buyer_vat_no
- buyer.email = invoice.buyer.billing_email
+ buyer.name = invoice.buyer.name
+ buyer.registration_number = invoice.buyer.registration_number
+ buyer.vat_number = invoice.buyer.vat_number
+ buyer.email = invoice.registrar.billing_email
buyer_bank_account = EInvoice::BankAccount.new
buyer_bank_account.number = invoice.buyer.e_invoice_iban
@@ -62,9 +62,9 @@ def generate
i.recipient_id_code = invoice.buyer_reg_no
i.reference_number = invoice.reference_no
i.due_date = invoice.due_date
- i.beneficiary_name = invoice.seller_name
- i.beneficiary_account_number = invoice.seller_iban
- i.payer_name = invoice.buyer_name
+ i.beneficiary_name = invoice.seller.name
+ i.beneficiary_account_number = invoice.seller.bank_account.iban
+ i.payer_name = invoice.buyer.name
i.subtotal = invoice.subtotal
i.vat_amount = invoice.vat_amount
i.total = invoice.total
diff --git a/app/models/registrar.rb b/app/models/registrar.rb
index 5c457a6ab0..b3125139e0 100644
--- a/app/models/registrar.rb
+++ b/app/models/registrar.rb
@@ -5,7 +5,7 @@ class Registrar < ActiveRecord::Base
has_many :contacts, dependent: :restrict_with_error
has_many :api_users, dependent: :restrict_with_error
has_many :notifications
- has_many :invoices, foreign_key: 'buyer_id'
+ has_many :invoices
has_many :accounts, dependent: :destroy
has_many :nameservers, through: :domains
has_many :whois_records
@@ -64,23 +64,15 @@ def issue_prepayment_invoice(amount, description = nil)
seller_bank: Setting.registry_bank,
seller_swift: Setting.registry_swift,
seller_vat_no: Setting.registry_vat_no,
- seller_country_code: Setting.registry_country_code,
- seller_state: Setting.registry_state,
- seller_street: Setting.registry_street,
- seller_city: Setting.registry_city,
- seller_zip: Setting.registry_zip,
+ seller_address: Registry.current.billing_address,
seller_phone: Setting.registry_phone,
seller_url: Setting.registry_url,
seller_email: Setting.registry_email,
seller_contact_name: Setting.registry_invoice_contact,
- buyer: self,
buyer_name: name,
buyer_reg_no: reg_no,
- buyer_country_code: address_country_code,
- buyer_state: address_state,
- buyer_street: address_street,
- buyer_city: address_city,
- buyer_zip: address_zip,
+ buyer_vat_no: vat_no,
+ buyer_address: billing_address,
buyer_phone: phone,
buyer_url: website,
buyer_email: email,
@@ -107,18 +99,10 @@ def debit!(args)
cash_account.account_activities.create!(args)
end
- def address
- [address_street, address_city, address_state, address_zip].reject(&:blank?).compact.join(', ')
- end
-
def to_s
name
end
- def country
- Country.new(address_country_code)
- end
-
def code=(code)
self[:code] = code.gsub(/[ :]/, '').upcase if new_record? && code.present?
end
@@ -153,7 +137,7 @@ def vat_country=(country)
end
def vat_country
- country
+ Country.new(address_country_code)
end
def vat_liable_locally?(registry = Registry.current)
@@ -169,6 +153,18 @@ def e_invoice_iban
iban
end
+ def address
+ Address.new(street: address_street,
+ zip: address_zip,
+ city: address_city,
+ state: address_state,
+ country: Country.new(address_country_code).to_s)
+ end
+
+ def billing_address
+ address
+ end
+
private
def set_defaults
diff --git a/app/models/registry.rb b/app/models/registry.rb
index 38037c01ba..ef10cabc2e 100644
--- a/app/models/registry.rb
+++ b/app/models/registry.rb
@@ -10,4 +10,18 @@ def self.current
new(vat_rate: vat_rate, vat_country: vat_country)
end
+
+ def billing_address
+ address
+ end
+
+ private
+
+ def address
+ Address.new(street: Setting.registry_street,
+ zip: Setting.registry_zip,
+ city: Setting.registry_city,
+ state: Setting.registry_state,
+ country: Country.new(Setting.registry_country_code))
+ end
end
\ No newline at end of file
diff --git a/app/views/admin/base/_menu.haml b/app/views/admin/base/_menu.haml
index d99a1598cf..8dcde897b4 100644
--- a/app/views/admin/base/_menu.haml
+++ b/app/views/admin/base/_menu.haml
@@ -22,7 +22,7 @@
- if can? :view, Billing::Price
%li= link_to t('.prices'), admin_prices_path
%li= link_to t(:bank_statements), admin_bank_statements_path
- %li= link_to t(:invoices), admin_invoices_path
+ %li= link_to t('.invoices'), admin_invoices_path
%li= link_to t(:account_activities), admin_account_activities_path(created_after: 'today')
%li.divider
%li.dropdown-header= t('.archive')
diff --git a/app/views/admin/invoices/_invoice.html.erb b/app/views/admin/invoices/_invoice.html.erb
new file mode 100644
index 0000000000..b35b7b72b9
--- /dev/null
+++ b/app/views/admin/invoices/_invoice.html.erb
@@ -0,0 +1,28 @@
+
+ <%= link_to invoice, admin_invoice_path(invoice) %>
+ <%= link_to invoice.registrar, admin_registrar_path(invoice.registrar) %>
+
+ <% if invoice.cancelled? %>
+
+ <%= t(:cancelled) %>
+
+ <% else %>
+
+ <%= l invoice.due_date %>
+
+ <% end %>
+
+ <% if invoice.paid? %>
+
+ <%= l invoice.receipt_date %>
+
+ <% elsif invoice.cancelled? %>
+
+ <%= t(:cancelled) %>
+
+ <% else %>
+
+ <%= t(:unpaid) %>
+
+ <% end %>
+
\ No newline at end of file
diff --git a/app/views/admin/invoices/index.haml b/app/views/admin/invoices/index.haml
deleted file mode 100644
index 903eaf819e..0000000000
--- a/app/views/admin/invoices/index.haml
+++ /dev/null
@@ -1,36 +0,0 @@
-- content_for :actions do
- = link_to(t(:add), new_admin_invoice_path, class: 'btn btn-primary')
-= render 'shared/title', name: t(:invoices)
-.row
- .col-md-12
- .table-responsive
- %table.table.table-hover.table-bordered.table-condensed
- %thead
- %tr
- %th{class: 'col-xs-3'}
- = sort_link(@q, :number)
- %th{class: 'col-xs-3'}
- = sort_link(@q, :buyer_name, "Buyer")
- %th{class: 'col-xs-3'}
- = sort_link(@q, :sort_due_date, "Due date")
- %th{class: 'col-xs-3'}
- = sort_link(@q, :sort_receipt_date, "Receipt date")
- %tbody
- - @invoices.each do |invoice|
- %tr
- %td= link_to(invoice, [:admin, invoice])
- %td= link_to(invoice.buyer_name, admin_registrar_path(invoice.buyer_id))
- - if invoice.cancelled?
- %td.text-grey= t(:cancelled)
- - else
- %td= l invoice.due_date
-
- - if invoice.paid?
- %td= l invoice.receipt_date
- - elsif invoice.cancelled?
- %td.text-grey= t(:cancelled)
- - else
- %td.text-danger= t(:unpaid)
-.row
- .col-md-12
- = paginate @invoices
diff --git a/app/views/admin/invoices/index.html.erb b/app/views/admin/invoices/index.html.erb
new file mode 100644
index 0000000000..344f38d481
--- /dev/null
+++ b/app/views/admin/invoices/index.html.erb
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+ <%= sort_link @q, :number %>
+
+ <%= sort_link @q, :buyer_name, Registrar.model_name.human %>
+
+
+ <%= sort_link @q, :sort_due_date,
+ Invoice.human_attribute_name(:due_date) %>
+
+
+ <%= sort_link @q, :sort_receipt_date,
+ Invoice.human_attribute_name(:receipt_date) %>
+
+
+
+
+ <%= render @invoices %>
+
+
+
+
+
+
+
+
+ <%= paginate @invoices %>
+
+
\ No newline at end of file
diff --git a/app/views/admin/invoices/show.haml b/app/views/admin/invoices/show.haml
deleted file mode 100644
index e3627c1589..0000000000
--- a/app/views/admin/invoices/show.haml
+++ /dev/null
@@ -1,23 +0,0 @@
-.row
- .col-sm-4
- %h1.text-center-xs
- = @invoice
- .col-sm-8
- %h1.text-right.text-center-xs
- - if @invoice.unpaid?
- = link_to(t(:payment_received), new_admin_bank_statement_path(invoice_id: @invoice.id), class: 'btn btn-default')
- = link_to(t('.download_btn'), download_admin_invoice_path(@invoice), class: 'btn btn-default')
- = link_to(t('.deliver_btn'), new_admin_invoice_delivery_path(@invoice), class: 'btn btn-default')
- - if @invoice.cancellable?
- = link_to(t(:cancel), cancel_admin_invoice_path(@invoice), method: :patch, class: 'btn btn-warning')
- = link_to(t(:back), admin_invoices_path, class: 'btn btn-default')
-%hr
-= render 'shared/full_errors', object: @invoice
-
-.row
- .col-md-6= render 'registrar/invoices/partials/details'
-.row
- .col-md-6= render 'registrar/invoices/partials/seller'
- .col-md-6= render 'registrar/invoices/partials/buyer'
-.row
- .col-md-12= render 'registrar/invoices/partials/items'
diff --git a/app/views/admin/invoices/show.html.erb b/app/views/admin/invoices/show.html.erb
new file mode 100644
index 0000000000..6d24a803c8
--- /dev/null
+++ b/app/views/admin/invoices/show.html.erb
@@ -0,0 +1,50 @@
+
+ <%= link_to t('admin.invoices.index.header'), admin_invoices_path %>
+ <%= @invoice %>
+
+
+
+
+
+
+ <%= render 'invoices/show/details' %>
+
+
+
+
+
+ <%= render 'invoices/show/seller', seller: @invoice.seller %>
+
+
+
+ <%= render 'invoices/show/buyer', buyer: @invoice.buyer %>
+
+
+
+
+
+ <%= render 'invoices/show/items' %>
+
+
\ No newline at end of file
diff --git a/app/views/admin/registrars/show/_contacts.html.erb b/app/views/admin/registrars/show/_contacts.html.erb
index f467e6a512..7163dc6b61 100644
--- a/app/views/admin/registrars/show/_contacts.html.erb
+++ b/app/views/admin/registrars/show/_contacts.html.erb
@@ -6,7 +6,7 @@
<%= Registrar.human_attribute_name :country %>
- <%= @registrar.country %>
+ <%= @registrar.address.country %>
<%= Registrar.human_attribute_name :address %>
<%= @registrar.address %>
diff --git a/app/views/invoice/pdf.haml b/app/views/invoice/pdf.haml
index 19778ec434..b33b7034d4 100644
--- a/app/views/invoice/pdf.haml
+++ b/app/views/invoice/pdf.haml
@@ -148,14 +148,14 @@
Details
%hr
%dl.dl-horizontal
- %dt= t(:issue_date)
+ %dt= Invoice.human_attribute_name :issue_date
%dd= l @invoice.issue_date
- if @invoice.cancelled?
%dt= Invoice.human_attribute_name :cancelled_at
%dd= l @invoice.cancelled_at
- %dt= t(:due_date)
+ %dt= Invoice.human_attribute_name :due_date
- if @invoice.cancelled?
%dd= t(:cancelled)
- else
@@ -169,13 +169,13 @@
- else
%dd{class: 'text-danger'}= t(:unpaid)
- %dt= t(:issuer)
- %dd= @invoice.seller_contact_name
+ %dt= Invoice::Seller.human_attribute_name :contact_person
+ %dd= @invoice.seller.contact_person
- %dt= t(:payment_term)
+ %dt= Invoice.human_attribute_name :payment_term
%dd Prepayment
- %dt= t(:invoice_number)
+ %dt= Invoice.human_attribute_name :number
%dd= @invoice.number
- if @invoice.description.present?
@@ -186,34 +186,29 @@
%dd= @invoice.reference_no
.col-md-6.right
- %h4= t(:client)
+ %h4= t('.buyer')
%hr
%dl.dl-horizontal
- %dt= t(:name)
- %dd= @invoice.buyer_name
+ %dt= Invoice::Buyer.human_attribute_name :name
+ %dd= @invoice.buyer.name
- %dt= t(:reg_no)
- %dd= @invoice.buyer_reg_no
+ %dt= Invoice::Buyer.human_attribute_name :registration_number
+ %dd= @invoice.buyer.registration_number
- - if @invoice.buyer_address.present?
- %dt= t(:address)
- %dd= @invoice.buyer_address
+ %dt= Invoice::Buyer.human_attribute_name :address
+ %dd= @invoice.buyer.address
- - if @invoice.buyer_country.present?
- %dt= t(:country)
- %dd= @invoice.buyer_country
+ - if @invoice.buyer.email.present?
+ %dt= Invoice::Buyer.human_attribute_name :email
+ %dd= @invoice.buyer.email
- - if @invoice.buyer_phone.present?
- %dt= t(:phone)
- %dd= @invoice.buyer_phone
+ - if @invoice.buyer.phone.present?
+ %dt= Invoice::Buyer.human_attribute_name :phone
+ %dd= @invoice.buyer.phone
- - if @invoice.buyer_phone.present?
- %dt= t(:url)
- %dd= @invoice.buyer_url
-
- - if @invoice.buyer_email.present?
- %dt= t(:email)
- %dd= @invoice.buyer_email
+ - if @invoice.buyer.website.present?
+ %dt= Invoice::Buyer.human_attribute_name :website
+ %dd= @invoice.buyer.website
.clear
.row.pull-down
@@ -222,11 +217,11 @@
%table.table.table-hover.table-condensed
%thead
%tr
- %th{class: 'col-xs-4'}= t(:description)
- %th{class: 'col-xs-2'}= t(:unit)
+ %th{class: 'col-xs-4'}= InvoiceItem.human_attribute_name :description
+ %th{class: 'col-xs-2'}= InvoiceItem.human_attribute_name :unit
%th{class: 'col-xs-1'}= InvoiceItem.human_attribute_name :quantity
- %th{class: 'col-xs-3'}= t(:price)
- %th{class: 'col-xs-2'}= t(:total)
+ %th{class: 'col-xs-3'}= InvoiceItem.human_attribute_name :price
+ %th{class: 'col-xs-2'}= InvoiceItem.human_attribute_name :total
%tbody
- @invoice.each do |invoice_item|
%tr
@@ -246,40 +241,38 @@
%td= number_to_currency @invoice.vat_amount
%tr
%th.no-border{colspan: 3}
- %th= t(:total)
+ %th= Invoice.human_attribute_name :total
%td= number_to_currency @invoice.total
#footer
%hr
.row
.col-md-3.left
- = @invoice.seller_name
- %br
- = @invoice.seller_address
+ = @invoice.seller.name
%br
- = @invoice.seller_country
+ = @invoice.seller.address
%br
- = "#{t('reg_no')} #{@invoice.seller_reg_no}"
+ = "#{Invoice::Seller.human_attribute_name :registration_number} #{@invoice.seller.registration_number}"
%br
- = "#{Registrar.human_attribute_name :vat_no} #{@invoice.seller_vat_no}"
+ = "#{Invoice::Seller.human_attribute_name :vat_number} #{@invoice.seller.vat_number}"
.col-md-3.left
- = @invoice.seller_phone
+ = @invoice.seller.phone
%br
- = @invoice.seller_email
+ = @invoice.seller.email
%br
- = @invoice.seller_url
+ = @invoice.seller.website
.col-md-3.text-right.left
- = t(:bank)
+ = BankAccount.human_attribute_name :bank_name
%br
- = t(:iban)
+ = BankAccount.human_attribute_name :iban
%br
- = t(:swift)
+ = BankAccount.human_attribute_name :swift
.col-md-3.left
- = @invoice.seller_bank
+ = @invoice.seller.bank_account.bank_name
%br
- = @invoice.seller_iban
+ = @invoice.seller.bank_account.iban
%br
- = @invoice.seller_swift
+ = @invoice.seller.bank_account.swift
diff --git a/app/views/invoices/show/_buyer.html.erb b/app/views/invoices/show/_buyer.html.erb
new file mode 100644
index 0000000000..b45c5a33bb
--- /dev/null
+++ b/app/views/invoices/show/_buyer.html.erb
@@ -0,0 +1,23 @@
+<%= t '.header' %>
+
+
+
+
+ <%= Invoice::Buyer.human_attribute_name :name %>
+ <%= buyer.name %>
+
+ <%= Invoice::Buyer.human_attribute_name :registration_number %>
+ <%= buyer.registration_number %>
+
+ <%= Invoice::Buyer.human_attribute_name :address %>
+ <%= buyer.address %>
+
+ <%= Invoice::Buyer.human_attribute_name :phone %>
+ <%= buyer.phone %>
+
+ <%= Invoice::Buyer.human_attribute_name :website %>
+ <%= buyer.website %>
+
+ <%= Invoice::Buyer.human_attribute_name :email %>
+ <%= buyer.email %>
+
\ No newline at end of file
diff --git a/app/views/invoices/show/_details.html.erb b/app/views/invoices/show/_details.html.erb
new file mode 100644
index 0000000000..119bc58a4c
--- /dev/null
+++ b/app/views/invoices/show/_details.html.erb
@@ -0,0 +1,71 @@
+<%= t '.header' %>
+
+
+ <%= Invoice.human_attribute_name :issue_date %>
+ <%= l @invoice.issue_date %>
+
+ <% if @invoice.cancelled? %>
+
+ <%= Invoice.human_attribute_name :cancelled_at %>
+
+
+ <%= l @invoice.cancelled_at %>
+
+ <% end %>
+
+
+ <%= Invoice.human_attribute_name :due_date %>
+
+
+ <% if @invoice.cancelled? %>
+
+ <%= t(:cancelled) %>
+
+ <% else %>
+
+ <%= l @invoice.due_date %>
+
+ <% end %>
+
+
+ <%= Invoice.human_attribute_name :receipt_date %>
+
+
+ <% if @invoice.paid? %>
+
+ <%= l @invoice.receipt_date %>
+
+ <% elsif @invoice.cancelled? %>
+
+ <%= t(:cancelled) %>
+
+ <% else %>
+
+ <%= t(:unpaid) %>
+
+ <% end %>
+
+ <%= Invoice.human_attribute_name :payment_term %>
+
+ Prepayment
+
+ <%= Invoice.human_attribute_name :number %>
+
+
+ <%= @invoice.number %>
+
+ <% if @invoice.description.present? %>
+
+ <%= t(:description) %>
+
+
+ <%= @invoice.description %>
+
+ <% end %>
+
+ <%= Invoice.human_attribute_name :reference_no %>
+
+
+ <%= @invoice.reference_no %>
+
+
diff --git a/app/views/invoices/show/_invoice_item.erb b/app/views/invoices/show/_invoice_item.erb
new file mode 100644
index 0000000000..cda8186d24
--- /dev/null
+++ b/app/views/invoices/show/_invoice_item.erb
@@ -0,0 +1,7 @@
+
+ <%= invoice_item.description %>
+ <%= invoice_item.unit %>
+ <%= invoice_item.quantity %>
+ <%= number_to_currency invoice_item.price %>
+ <%= number_to_currency invoice_item.item_sum_without_vat %>
+
\ No newline at end of file
diff --git a/app/views/invoices/show/_items.html.erb b/app/views/invoices/show/_items.html.erb
new file mode 100644
index 0000000000..06babb4d38
--- /dev/null
+++ b/app/views/invoices/show/_items.html.erb
@@ -0,0 +1,39 @@
+<%= t '.header' %>
+
+
+
+
+
+ <%= InvoiceItem.human_attribute_name :description %>
+ <%= InvoiceItem.human_attribute_name :unit %>
+ <%= InvoiceItem.human_attribute_name :quantity %>
+ <%= InvoiceItem.human_attribute_name :price %>
+ <%= InvoiceItem.human_attribute_name :total %>
+
+
+
+
+ <%= render collection: @invoice.items, partial: 'invoices/show/invoice_item' %>
+
+
+
+
+
+ <%= Invoice.human_attribute_name :subtotal %>
+ <%= number_to_currency @invoice.subtotal %>
+
+
+
+
+ <%= "VAT #{number_to_percentage(@invoice.vat_rate, precision: 1)}" %>
+ <%= number_to_currency @invoice.vat_amount %>
+
+
+
+
+ <%= Invoice.human_attribute_name :total %>
+ <%= number_to_currency @invoice.total %>
+
+
+
+
\ No newline at end of file
diff --git a/app/views/invoices/show/_seller.html.erb b/app/views/invoices/show/_seller.html.erb
new file mode 100644
index 0000000000..fd6039ab33
--- /dev/null
+++ b/app/views/invoices/show/_seller.html.erb
@@ -0,0 +1,38 @@
+<%= t '.header' %>
+
+
+
+
+ <%= Invoice::Seller.human_attribute_name :name %>
+ <%= seller.name %>
+
+ <%= Invoice::Seller.human_attribute_name :registration_number %>
+ <%= seller.registration_number %>
+
+ <%= Invoice::Seller.human_attribute_name :vat_number %>
+ <%= seller.vat_number %>
+
+ <%= BankAccount.human_attribute_name :iban %>
+ <%= seller.bank_account.iban %>
+
+ <%= BankAccount.human_attribute_name :bank_name %>
+ <%= seller.bank_account.bank_name %>
+
+ <%= BankAccount.human_attribute_name :swift %>
+ <%= seller.bank_account.swift %>
+
+ <%= Invoice::Seller.human_attribute_name :address %>
+ <%= seller.address %>
+
+ <%= Invoice::Seller.human_attribute_name :email %>
+ <%= seller.email %>
+
+ <%= Invoice::Seller.human_attribute_name :phone %>
+ <%= seller.phone %>
+
+ <%= Invoice::Seller.human_attribute_name :website %>
+ <%= seller.website %>
+
+ <%= Invoice::Seller.human_attribute_name :contact_person %>
+ <%= seller.contact_person %>
+
\ No newline at end of file
diff --git a/app/views/registrar/invoices/partials/_banklinks.haml b/app/views/registrar/invoices/_banklinks.haml
similarity index 100%
rename from app/views/registrar/invoices/partials/_banklinks.haml
rename to app/views/registrar/invoices/_banklinks.haml
diff --git a/app/views/registrar/invoices/_invoice.html.erb b/app/views/registrar/invoices/_invoice.html.erb
new file mode 100644
index 0000000000..e294657860
--- /dev/null
+++ b/app/views/registrar/invoices/_invoice.html.erb
@@ -0,0 +1,20 @@
+
+ <%= link_to invoice, registrar_invoice_path(invoice) %>
+
+ <% if invoice.paid? %>
+
+ <%= l invoice.receipt_date %>
+
+ <% elsif invoice.cancelled? %>
+
+ <%= t(:cancelled) %>
+
+ <% else %>
+
+ <%= t(:unpaid) %>
+
+ <% end %>
+
+ <%= l invoice.due_date %>
+ <%= number_to_currency invoice.total %>
+
\ No newline at end of file
diff --git a/app/views/registrar/invoices/_search_form.html.erb b/app/views/registrar/invoices/_search_form.html.erb
new file mode 100644
index 0000000000..89a59547bb
--- /dev/null
+++ b/app/views/registrar/invoices/_search_form.html.erb
@@ -0,0 +1,50 @@
+<%= search_form_for @q, url: [:registrar, :invoices], html: { style: 'margin-bottom: 0;' } do |f| %>
+
+
+
+ <%= f.label t(:minimum_invoice_no) %>
+ <%= f.search_field :number_gteq, class: 'form-control', placeholder: t(:minimum_invoice_no), autocomplete: 'off' %>
+
+
+
+
+ <%= f.label t(:maximum_invoice_no) %>
+ <%= f.search_field :number_lteq, class: 'form-control', placeholder: t(:maximum_invoice_no), autocomplete: 'off' %>
+
+
+
+
+ <%= f.label t(:due_date_from) %>
+ <%= f.search_field :due_date_gteq, value: params[:q][:due_date_gteq], class: 'form-control js-datepicker', placeholder: t(:due_date_from) %>
+
+
+
+
+ <%= f.label t(:due_date_until) %>
+ <%= f.search_field :due_date_lteq, value: params[:q][:due_date_lteq], class: 'form-control js-datepicker', placeholder: t(:due_date_until) %>
+
+
+
+
+
+
+ <%= f.label t(:minimum_total) %>
+ <%= f.search_field :total_gteq, class: 'form-control', placeholder: t(:minimum_total), autocomplete: 'off' %>
+
+
+
+
+ <%= f.label t(:maximum_total) %>
+ <%= f.search_field :total_lteq, class: 'form-control', placeholder: t(:maximum_total), autocomplete: 'off' %>
+
+
+
+
+
+
+
+
+ <%= link_to t('.reset_btn'), registrar_invoices_path, class: 'btn btn-default' %>
+
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/registrar/invoices/index.haml b/app/views/registrar/invoices/index.haml
deleted file mode 100644
index 9ed8b91d54..0000000000
--- a/app/views/registrar/invoices/index.haml
+++ /dev/null
@@ -1,73 +0,0 @@
-- content_for :actions do
- = link_to(t(:add_deposit), new_registrar_deposit_path, class: 'btn btn-primary')
- = link_to(t(:account_activity), registrar_account_activities_path, class: 'btn btn-default')
-= render 'shared/title', name: t(:your_account)
-
-= t(:your_current_account_balance_is,
- balance: currency(current_registrar_user.registrar.cash_account.balance),
- currency: current_registrar_user.registrar.cash_account.currency)
-
-%h1= t(:invoices)
-.row
- .col-md-12
- %hr
- = search_form_for @q, url: [:registrar, :invoices], html: { style: 'margin-bottom: 0;' } do |f|
- .row
- .col-md-3
- .form-group
- = f.label t(:minimum_invoice_no)
- = f.search_field :number_gteq, class: 'form-control', placeholder: t(:minimum_invoice_no), autocomplete: 'off'
- .col-md-3
- .form-group
- = f.label t(:maximum_invoice_no)
- = f.search_field :number_lteq, class: 'form-control', placeholder: t(:maximum_invoice_no), autocomplete: 'off'
- .col-md-3
- .form-group
- = f.label t(:due_date_from)
- = f.search_field :due_date_gteq, value: params[:q][:due_date_gteq], class: 'form-control js-datepicker', placeholder: t(:due_date_from)
- .col-md-3
- .form-group
- = f.label t(:due_date_until)
- = f.search_field :due_date_lteq, value: params[:q][:due_date_lteq], class: 'form-control js-datepicker', placeholder: t(:due_date_until)
- .row
- .col-md-3
- .form-group
- = f.label t(:minimum_total)
- = f.search_field :total_gteq, class: 'form-control', placeholder: t(:minimum_total), autocomplete: 'off'
- .col-md-3
- .form-group
- = f.label t(:maximum_total)
- = f.search_field :total_lteq, class: 'form-control', placeholder: t(:maximum_total), autocomplete: 'off'
- .col-md-3{style: 'padding-top: 25px;'}
- %button.btn.btn-default
-
- %span.glyphicon.glyphicon-search
-
- = link_to(t('.reset_btn'), registrar_invoices_path, class: 'btn btn-default')
-%hr
-.row
- .col-md-12
- .table-responsive
- %table.table.table-hover.table-condensed
- %thead
- %tr
- %th{class: 'col-xs-3'}= t(:invoice)
- %th{class: 'col-xs-3'}= Invoice.human_attribute_name :receipt_date
- %th{class: 'col-xs-3'}= t(:due_date)
- %th{class: 'col-xs-3'}= t(:total)
- %tbody
- - @invoices.each do |invoice|
- %tr.invoice
- %td= link_to(invoice, [:registrar, invoice])
- - if invoice.paid?
- %td= l invoice.receipt_date
- - elsif invoice.cancelled?
- %td.text-grey= t(:cancelled)
- - else
- %td{class: 'text-danger'}= t(:unpaid)
-
- %td= l invoice.due_date
- %td= currency(invoice.total)
-.row
- .col-md-12
- = paginate @invoices
diff --git a/app/views/registrar/invoices/index.html.erb b/app/views/registrar/invoices/index.html.erb
new file mode 100644
index 0000000000..c54df7a288
--- /dev/null
+++ b/app/views/registrar/invoices/index.html.erb
@@ -0,0 +1,53 @@
+
+
+
+ <%= t(:your_current_account_balance_is,
+ balance: currency(current_registrar_user.registrar.cash_account.balance),
+ currency: current_registrar_user.registrar.cash_account.currency) %>
+
+
+
+
+
+ <%= render 'search_form' %>
+
+
+
+
+
+
+
+
+
+ <%= Invoice.human_attribute_name :number %>
+ <%= Invoice.human_attribute_name :receipt_date %>
+ <%= Invoice.human_attribute_name :due_date %>
+ <%= Invoice.human_attribute_name :total %>
+
+
+
+
+ <%= render @invoices %>
+
+
+
+
+
+
+
+
+ <%= paginate @invoices %>
+
+
\ No newline at end of file
diff --git a/app/views/registrar/invoices/partials/_buyer.haml b/app/views/registrar/invoices/partials/_buyer.haml
deleted file mode 100644
index 30824ff010..0000000000
--- a/app/views/registrar/invoices/partials/_buyer.haml
+++ /dev/null
@@ -1,23 +0,0 @@
-%h4= t(:buyer)
-%hr
-%dl.dl-horizontal
- %dt= t(:name)
- %dd= @invoice.buyer_name
-
- %dt= t(:reg_no)
- %dd= @invoice.buyer_reg_no
-
- %dt= t(:address)
- %dd= @invoice.buyer_address
-
- %dt= t(:country)
- %dd= @invoice.buyer_country
-
- %dt= t(:phone)
- %dd= @invoice.buyer_phone
-
- %dt= t(:url)
- %dd= @invoice.buyer_url
-
- %dt= t(:email)
- %dd= @invoice.buyer_email
diff --git a/app/views/registrar/invoices/partials/_details.haml b/app/views/registrar/invoices/partials/_details.haml
deleted file mode 100644
index c5e6193a49..0000000000
--- a/app/views/registrar/invoices/partials/_details.haml
+++ /dev/null
@@ -1,36 +0,0 @@
-%h4= t(:details)
-%hr
-%dl.dl-horizontal
- %dt= t(:issue_date)
- %dd= l @invoice.issue_date
-
- - if @invoice.cancelled?
- %dt= Invoice.human_attribute_name :cancelled_at
- %dd= l @invoice.cancelled_at
-
- %dt= t(:due_date)
- - if @invoice.cancelled?
- %dd.text-grey= t(:cancelled)
- - else
- %dd= l @invoice.due_date
-
- %dt= Invoice.human_attribute_name :receipt_date
- - if @invoice.paid?
- %dd= l @invoice.receipt_date
- - elsif @invoice.cancelled?
- %dd.text-grey= t(:cancelled)
- - else
- %dd{class: 'text-danger'}= t(:unpaid)
-
- %dt= t(:payment_term)
- %dd Prepayment
-
- %dt= t(:invoice_number)
- %dd= @invoice.number
-
- - if @invoice.description.present?
- %dt= t(:description)
- %dd=@invoice.description
-
- %dt= Invoice.human_attribute_name :reference_no
- %dd= @invoice.reference_no
diff --git a/app/views/registrar/invoices/partials/_items.haml b/app/views/registrar/invoices/partials/_items.haml
deleted file mode 100644
index 26985b1c1b..0000000000
--- a/app/views/registrar/invoices/partials/_items.haml
+++ /dev/null
@@ -1,32 +0,0 @@
-%h4= t(:items)
-%hr
-.table-responsive
- %table.table.table-hover.table-condensed
- %thead
- %tr
- %th{class: 'col-xs-4'}= t(:description)
- %th{class: 'col-xs-2'}= t(:unit)
- %th{class: 'col-xs-2'}= InvoiceItem.human_attribute_name :quantity
- %th{class: 'col-xs-2'}= t(:price)
- %th{class: 'col-xs-2'}= t(:total)
- %tbody
- - @invoice.each do |invoice_item|
- %tr
- %td= invoice_item.description
- %td= invoice_item.unit
- %td= invoice_item.quantity
- %td= currency(invoice_item.price)
- %td= currency(invoice_item.item_sum_without_vat)
- %tfoot
- %tr
- %th{colspan: 3}
- %th= Invoice.human_attribute_name :subtotal
- %td= number_to_currency @invoice.subtotal
- %tr
- %th.no-border{colspan: 3}
- %th= "VAT #{number_to_percentage(@invoice.vat_rate, precision: 1)}"
- %td= number_to_currency @invoice.vat_amount
- %tr
- %th.no-border{colspan: 3}
- %th= t(:total)
- %td= number_to_currency @invoice.total
diff --git a/app/views/registrar/invoices/partials/_seller.haml b/app/views/registrar/invoices/partials/_seller.haml
deleted file mode 100644
index 30f27bcef9..0000000000
--- a/app/views/registrar/invoices/partials/_seller.haml
+++ /dev/null
@@ -1,38 +0,0 @@
-%h4= t(:seller)
-%hr
-%dl.dl-horizontal
- %dt= t(:name)
- %dd= @invoice.seller_name
-
- %dt= Registrar.human_attribute_name :reg_no
- %dd= @invoice.seller_reg_no
-
- %dt= t(:iban)
- %dd= @invoice.seller_iban
-
- %dt= t(:bank)
- %dd= @invoice.seller_bank
-
- %dt= t(:swift)
- %dd= @invoice.seller_swift
-
- %dt= Registrar.human_attribute_name :vat_no
- %dd= @invoice.seller_vat_no
-
- %dt= t(:address)
- %dd= @invoice.seller_address
-
- %dt= t(:country)
- %dd= @invoice.seller_country
-
- %dt= t(:phone)
- %dd= @invoice.seller_phone
-
- %dt= t(:url)
- %dd= @invoice.seller_url
-
- %dt= t(:email)
- %dd= @invoice.seller_email
-
- %dt= t(:issuer)
- %dd= @invoice.seller_contact_name
diff --git a/app/views/registrar/invoices/show.haml b/app/views/registrar/invoices/show.haml
deleted file mode 100644
index 66a025eaf9..0000000000
--- a/app/views/registrar/invoices/show.haml
+++ /dev/null
@@ -1,20 +0,0 @@
-- content_for :actions do
- = link_to(t('.download_btn'), download_registrar_invoice_path(@invoice), class: 'btn btn-default')
- = link_to(t('.deliver_btn'), new_registrar_invoice_delivery_path(@invoice), class: 'btn btn-default')
- - if @invoice.cancellable?
- = link_to(t(:cancel), cancel_registrar_invoice_path(@invoice), method: :patch, class: 'btn btn-warning')
- = link_to(t(:back), registrar_invoices_path, class: 'btn btn-default')
-= render 'shared/title', name: @invoice.to_s
-= render 'shared/full_errors', object: @invoice
-
-.row
- .col-md-6= render 'registrar/invoices/partials/details'
-.row
- .col-md-6= render 'registrar/invoices/partials/seller'
- .col-md-6= render 'registrar/invoices/partials/buyer'
-.row
- .col-md-12= render 'registrar/invoices/partials/items'
-
-- if @invoice.payable?
- .row.semifooter
- .col-md-6-offset-6.text-right= render 'registrar/invoices/partials/banklinks', locals: { payment_channels: PaymentOrders::PAYMENT_METHODS }
diff --git a/app/views/registrar/invoices/show.html.erb b/app/views/registrar/invoices/show.html.erb
new file mode 100644
index 0000000000..6ebd111cd6
--- /dev/null
+++ b/app/views/registrar/invoices/show.html.erb
@@ -0,0 +1,55 @@
+
+ <%= link_to t('admin.invoices.index.header'), registrar_invoices_path %>
+ <%= @invoice %>
+
+
+
+
+
+
+ <%= render 'invoices/show/details' %>
+
+
+
+
+
+ <%= render 'invoices/show/seller', seller: @invoice.seller %>
+
+
+
+ <%= render 'invoices/show/buyer', buyer: @invoice.buyer %>
+
+
+
+
+
+ <%= render 'invoices/show/items' %>
+
+
+
+<% if @invoice.payable? %>
+
+<% end %>
\ No newline at end of file
diff --git a/config/locales/admin/invoices.en.yml b/config/locales/admin/invoices.en.yml
index 6ec73ca9c6..b464201127 100644
--- a/config/locales/admin/invoices.en.yml
+++ b/config/locales/admin/invoices.en.yml
@@ -3,10 +3,13 @@ en:
invoices:
index:
header: Invoices
+ new_btn: New invoice
show:
download_btn: Download
deliver_btn: Send
+ cancel_btn: Cancel
+ mark_as_paid_btn: Mark as paid
cancel:
cancelled: Invoice has been cancelled
\ No newline at end of file
diff --git a/config/locales/admin/menu.en.yml b/config/locales/admin/menu.en.yml
index 2c31a51937..d2fd1a05cd 100644
--- a/config/locales/admin/menu.en.yml
+++ b/config/locales/admin/menu.en.yml
@@ -7,6 +7,7 @@ en:
api_users: API users
admin_users: Admin users
prices: Prices
+ invoices: Invoices
archive: Archive
domain_history: Domain history
contact_history: Contact history
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 8beb4bed23..ec0c63ad69 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -289,7 +289,6 @@ en:
failed_to_update_contact: 'Failed to update contact'
contact_updated: 'Contact updated'
search: 'Search'
- reg_no: 'Reg. no'
status: 'Status'
contact: 'Contact'
starting_balance: 'Starting balance'
@@ -388,7 +387,6 @@ en:
crt_revoked: 'CRT (revoked)'
contact_org_error: 'Parameter value policy error. Org must be blank'
contact_fax_error: 'Parameter value policy error. Fax must be blank'
- invoices: 'Invoices'
no_such_user: 'No such user'
phone_no: 'Phone number'
confirmation_sms_was_sent_to_your_phone_verification_code_is: 'Confirmation sms was sent to your phone. Verification code is %{code}.'
@@ -483,22 +481,12 @@ en:
add_deposit: 'Add deposit'
please_pay_the_following_invoice: 'Please pay the following invoice'
invoice_no: 'Invoice no. %{no}'
- invoice_number: Invoice no.
- seller: 'Seller'
unpaid: 'Unpaid'
your_current_account_balance_is: 'Your current account balance is %{balance} %{currency}'
billing: 'Billing'
your_account: 'Your account'
- issue_date: 'Issue date'
- due_date: 'Due date'
- payment_term: 'Payment term'
iban: 'IBAN'
- bank: 'Bank'
- swift: 'Swift'
issuer: 'Issuer'
- items: 'Items'
- buyer: 'Buyer'
- unit: 'Unit'
price: 'Price'
total: 'Total'
paid_at: 'Paid at'
@@ -524,7 +512,6 @@ en:
document_no: 'Document no'
import_file: 'Import file'
bind_invoices: 'Bind invoices'
- url: 'URL'
binded: 'Binded'
not_binded: 'Not binded'
binded_invoice: 'Binded invoice'
@@ -556,13 +543,11 @@ en:
registrant_head_title: 'EIS Registrant'
registrant_head_title_sufix: ' - EIS Registrant'
bind_manually: 'Bind manually'
- client: 'Client'
you_have_a_new_invoice: 'You have a new invoice.'
sincerely: 'Sincerely'
expiry: 'Expiry'
failed_to_create_crt_csr_already_signed: 'Failed to create certificate: CSR is already signed'
certificates: 'Certificates'
- cancel: 'Cancel'
cancelled: 'Cancelled'
cannot_bind_cancelled_invoice: 'Cannot bind cancelled invoice'
minimum_invoice_no: 'Miminum invoice no'
@@ -635,7 +620,6 @@ en:
reserved_pw: 'Reserved pw'
no_transfers_found: 'No transfers found'
parameter_value_range_error: 'Parameter value range error: %{key}'
- payment_received: 'Payment received'
api_user_not_found: 'API user not found'
notes: Notes
active_price_for_this_operation_is: 'Active price for this operation is %{price}'
@@ -692,3 +676,6 @@ en:
ipv6: IPv6
reference_no: Reference number
iban: IBAN
+ reg_no: Registration number
+ vat_number: VAT number
+ swift: SWIFT
diff --git a/config/locales/invoices.en.yml b/config/locales/invoices.en.yml
new file mode 100644
index 0000000000..33e4d420ae
--- /dev/null
+++ b/config/locales/invoices.en.yml
@@ -0,0 +1,19 @@
+en:
+ invoice:
+ pdf:
+ seller: Seller
+ buyer: Buyer
+
+ invoices:
+ show:
+ details:
+ header: Details
+
+ seller:
+ header: Seller
+
+ buyer:
+ header: Buyer
+
+ items:
+ header: Items
\ No newline at end of file
diff --git a/config/locales/registrar/invoices.en.yml b/config/locales/registrar/invoices.en.yml
index dfa7657540..839b58e621 100644
--- a/config/locales/registrar/invoices.en.yml
+++ b/config/locales/registrar/invoices.en.yml
@@ -10,11 +10,14 @@ en:
index:
header: Invoices
+
+ search_form:
reset_btn: Reset
show:
download_btn: Download
deliver_btn: Send
+ cancel_btn: Cancel
cancel:
cancelled: Invoice has been cancelled
\ No newline at end of file
diff --git a/db/migrate/20190508101415_add_invoices_buyer_id_fk.rb b/db/migrate/20190508101415_add_invoices_buyer_id_fk.rb
new file mode 100644
index 0000000000..7d5744185a
--- /dev/null
+++ b/db/migrate/20190508101415_add_invoices_buyer_id_fk.rb
@@ -0,0 +1,5 @@
+class AddInvoicesBuyerIdFk < ActiveRecord::Migration
+ def change
+ add_foreign_key :invoices, :registrars, column: :buyer_id
+ end
+end
\ No newline at end of file
diff --git a/db/migrate/20190508101552_rename_invoices_buyer_id_to_registrar_id.rb b/db/migrate/20190508101552_rename_invoices_buyer_id_to_registrar_id.rb
new file mode 100644
index 0000000000..fa10eaccb5
--- /dev/null
+++ b/db/migrate/20190508101552_rename_invoices_buyer_id_to_registrar_id.rb
@@ -0,0 +1,5 @@
+class RenameInvoicesBuyerIdToRegistrarId < ActiveRecord::Migration
+ def change
+ rename_column :invoices, :buyer_id, :registrar_id
+ end
+end
\ No newline at end of file
diff --git a/db/migrate/20190508101809_change_invoices_registrar_id_to_not_null.rb b/db/migrate/20190508101809_change_invoices_registrar_id_to_not_null.rb
new file mode 100644
index 0000000000..96d6b66079
--- /dev/null
+++ b/db/migrate/20190508101809_change_invoices_registrar_id_to_not_null.rb
@@ -0,0 +1,5 @@
+class ChangeInvoicesRegistrarIdToNotNull < ActiveRecord::Migration
+ def change
+ change_column_null :invoices, :registrar_id, false
+ end
+end
\ No newline at end of file
diff --git a/db/migrate/20190617113614_prefix_invoices_seller_address_parts.rb b/db/migrate/20190617113614_prefix_invoices_seller_address_parts.rb
new file mode 100644
index 0000000000..42f0618099
--- /dev/null
+++ b/db/migrate/20190617113614_prefix_invoices_seller_address_parts.rb
@@ -0,0 +1,9 @@
+class PrefixInvoicesSellerAddressParts < ActiveRecord::Migration
+ def change
+ rename_column :invoices, :seller_street, :seller_address_street
+ rename_column :invoices, :seller_zip, :seller_address_zip
+ rename_column :invoices, :seller_city, :seller_address_city
+ rename_column :invoices, :seller_state, :seller_address_state
+ rename_column :invoices, :seller_country_code, :seller_address_country_code
+ end
+end
\ No newline at end of file
diff --git a/db/migrate/20190617114000_prefix_invoices_buyer_address_parts.rb b/db/migrate/20190617114000_prefix_invoices_buyer_address_parts.rb
new file mode 100644
index 0000000000..07e2811e5b
--- /dev/null
+++ b/db/migrate/20190617114000_prefix_invoices_buyer_address_parts.rb
@@ -0,0 +1,9 @@
+class PrefixInvoicesBuyerAddressParts < ActiveRecord::Migration
+ def change
+ rename_column :invoices, :buyer_street, :buyer_address_street
+ rename_column :invoices, :buyer_zip, :buyer_address_zip
+ rename_column :invoices, :buyer_city, :buyer_address_city
+ rename_column :invoices, :buyer_state, :buyer_address_state
+ rename_column :invoices, :buyer_country_code, :buyer_address_country_code
+ end
+end
\ No newline at end of file
diff --git a/db/structure.sql b/db/structure.sql
index 83716ff1e9..aacea3c4d0 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -943,23 +943,23 @@ CREATE TABLE public.invoices (
seller_bank character varying,
seller_swift character varying,
seller_vat_no character varying,
- seller_country_code character varying,
- seller_state character varying,
- seller_street character varying,
- seller_city character varying,
- seller_zip character varying,
+ seller_address_country_code character varying,
+ seller_address_state character varying,
+ seller_address_street character varying,
+ seller_address_city character varying,
+ seller_address_zip character varying,
seller_phone character varying,
seller_url character varying,
seller_email character varying,
seller_contact_name character varying,
- buyer_id integer,
+ registrar_id integer NOT NULL,
buyer_name character varying NOT NULL,
buyer_reg_no character varying,
- buyer_country_code character varying,
- buyer_state character varying,
- buyer_street character varying,
- buyer_city character varying,
- buyer_zip character varying,
+ buyer_address_country_code character varying,
+ buyer_address_state character varying,
+ buyer_address_street character varying,
+ buyer_address_city character varying,
+ buyer_address_zip character varying,
buyer_phone character varying,
buyer_url character varying,
buyer_email character varying,
@@ -3395,14 +3395,14 @@ CREATE INDEX index_invoice_items_on_invoice_id ON public.invoice_items USING btr
--
--- Name: index_invoices_on_buyer_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
+-- Name: index_invoices_on_registrar_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
-CREATE INDEX index_invoices_on_buyer_id ON public.invoices USING btree (buyer_id);
+CREATE INDEX index_invoices_on_registrar_id ON public.invoices USING btree (registrar_id);
--
--- Name: index_invoices_on_seller_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
+-- Name: index_invoices_on_seller_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX index_invoices_on_seller_id ON public.invoices USING btree (seller_id);
@@ -3766,7 +3766,7 @@ CREATE INDEX index_users_on_registrar_id ON public.users USING btree (registrar_
--
--- Name: index_versions_on_item_type_and_item_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
+-- Name: index_versions_on_item_type_and_item_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX index_versions_on_item_type_and_item_id ON public.versions USING btree (item_type, item_id);
@@ -3861,6 +3861,14 @@ ALTER TABLE ONLY public.domains
ADD CONSTRAINT domains_registrar_id_fk FOREIGN KEY (registrar_id) REFERENCES public.registrars(id);
+--
+-- Name: fk_rails_242b91538b; Type: FK CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.invoices
+ ADD CONSTRAINT fk_rails_242b91538b FOREIGN KEY (registrar_id) REFERENCES public.registrars(id);
+
+
--
-- Name: fk_rails_59c422f73d; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@@ -4745,6 +4753,14 @@ INSERT INTO schema_migrations (version) VALUES ('20190426174225');
INSERT INTO schema_migrations (version) VALUES ('20190506100655');
+INSERT INTO schema_migrations (version) VALUES ('20190506102959');
+
+INSERT INTO schema_migrations (version) VALUES ('20190508101415');
+
+INSERT INTO schema_migrations (version) VALUES ('20190508101552');
+
+INSERT INTO schema_migrations (version) VALUES ('20190508101809');
+
INSERT INTO schema_migrations (version) VALUES ('20190510090240');
INSERT INTO schema_migrations (version) VALUES ('20190510102549');
@@ -4755,6 +4771,10 @@ INSERT INTO schema_migrations (version) VALUES ('20190516161439');
INSERT INTO schema_migrations (version) VALUES ('20190520093231');
+INSERT INTO schema_migrations (version) VALUES ('20190617113614');
+
+INSERT INTO schema_migrations (version) VALUES ('20190617114000');
+
INSERT INTO schema_migrations (version) VALUES ('20190617120112');
INSERT INTO schema_migrations (version) VALUES ('20190617121716');
diff --git a/test/fixtures/invoices.yml b/test/fixtures/invoices.yml
index 9957f787ae..57b5766ce1 100644
--- a/test/fixtures/invoices.yml
+++ b/test/fixtures/invoices.yml
@@ -4,7 +4,7 @@ one:
currency: EUR
seller_name: John Doe
seller_iban: 1234
- buyer: bestnames
+ registrar: bestnames
buyer_name: Jane Doe
vat_rate: 0.1
total: 16.50
@@ -18,7 +18,7 @@ for_payments_test:
currency: EUR
seller_name: John Doe
seller_iban: 1234
- buyer: bestnames
+ registrar: bestnames
buyer_name: Jane Doe
vat_rate: 0.1
reference_no: 13
diff --git a/test/models/address_test.rb b/test/models/address_test.rb
new file mode 100644
index 0000000000..faeab3f2b2
--- /dev/null
+++ b/test/models/address_test.rb
@@ -0,0 +1,37 @@
+require 'test_helper'
+
+class AddressTest < ActiveSupport::TestCase
+ setup do
+ @address = Address.new(street: 'Main Street', zip: '1234', city: 'NY', state: 'NY State',
+ country: 'Germany')
+ end
+
+ def test_returns_street
+ assert_equal 'Main Street', @address.street
+ end
+
+ def test_returns_postal_code
+ assert_equal '1234', @address.zip
+ end
+
+ def test_returns_city
+ assert_equal 'NY', @address.city
+ end
+
+ def test_returns_state
+ assert_equal 'NY State', @address.state
+ end
+
+ def test_returns_country
+ assert_equal 'Germany', @address.country
+ end
+
+ def test_equality
+ assert_not_equal Address.new(street: 'one'), Address.new(street: 'two')
+ assert_equal Address.new(street: 'one'), Address.new(street: 'one')
+ end
+
+ def test_to_s
+ assert_equal 'Main Street, NY, NY State, 1234, Germany', @address.to_s
+ end
+end
\ No newline at end of file
diff --git a/test/models/invoice_test.rb b/test/models/invoice_test.rb
index 6e69711398..5d8e6d450b 100644
--- a/test/models/invoice_test.rb
+++ b/test/models/invoice_test.rb
@@ -70,22 +70,6 @@ def test_calculates_total
end
end
- def test_valid_without_buyer_vat_no
- @invoice.buyer_vat_no = ''
- assert @invoice.valid?
- end
-
- def test_buyer_vat_no_is_taken_from_registrar_by_default
- registrar = registrars(:bestnames)
- registrar.vat_no = 'US1234'
- invoice = @invoice.dup
- invoice.buyer_vat_no = nil
- invoice.buyer = registrar
- invoice.items = @invoice.items
- invoice.save!
- assert_equal 'US1234', invoice.buyer_vat_no
- end
-
def test_invalid_without_invoice_items
@invoice.items.clear
assert @invoice.invalid?
@@ -103,9 +87,56 @@ def test_iterates_over_invoice_items
assert_equal 1, iteration_count
end
+ def test_returns_seller
+ invoice = Invoice.new(seller_name: 'seller name',
+ seller_reg_no: 'seller reg number',
+ seller_vat_no: 'seller vat number',
+ seller_address: 'seller address',
+ seller_email: 'seller email',
+ seller_phone: 'seller phone',
+ seller_url: 'seller website',
+ seller_contact_name: 'seller contact person',
+ seller_iban: 'seller iban',
+ seller_swift: 'seller swift',
+ seller_bank: 'seller bank')
+
+ assert_equal 'seller name', invoice.seller.name
+ assert_equal 'seller reg number', invoice.seller.registration_number
+ assert_equal 'seller vat number', invoice.seller.vat_number
+ assert_equal 'seller address', invoice.seller.address
+ assert_equal 'seller email', invoice.seller.email
+ assert_equal 'seller phone', invoice.seller.phone
+ assert_equal 'seller website', invoice.seller.website
+ assert_equal 'seller contact person', invoice.seller.contact_person
+
+ assert_equal 'seller iban', invoice.seller.bank_account.iban
+ assert_equal 'seller swift', invoice.seller.bank_account.swift
+ assert_equal 'seller bank', invoice.seller.bank_account.bank_name
+ end
+
+ def test_returns_buyer
+ invoice = Invoice.new(buyer_name: 'buyer name',
+ buyer_reg_no: 'buyer reg number',
+ buyer_vat_no: 'buyer vat number',
+ buyer_address: 'buyer address',
+ buyer_email: 'buyer email',
+ buyer_phone: 'buyer phone',
+ buyer_url: 'buyer website')
+
+ assert_equal 'buyer name', invoice.buyer.name
+ assert_equal 'buyer reg number', invoice.buyer.registration_number
+ assert_equal 'buyer vat number', invoice.buyer.vat_number
+ assert_equal 'buyer address', invoice.buyer.address
+ assert_equal 'buyer email', invoice.buyer.email
+ assert_equal 'buyer phone', invoice.buyer.phone
+ assert_equal 'buyer website', invoice.buyer.website
+ end
+
def test_returns_combined_seller_address
- invoice = Invoice.new(seller_street: 'street', seller_city: 'city', seller_state: 'state',
- seller_zip: nil)
+ invoice = Invoice.new(seller_address_street: 'street',
+ seller_address_zip: nil,
+ seller_address_city: 'city',
+ seller_address_state: 'state')
assert_equal 'street, city, state', invoice.seller_address
end
end
\ No newline at end of file
diff --git a/test/models/registrar_test.rb b/test/models/registrar_test.rb
index e8eae1f348..c36b415150 100644
--- a/test/models/registrar_test.rb
+++ b/test/models/registrar_test.rb
@@ -111,10 +111,26 @@ def test_invalid_without_address_country_code
assert registrar.invalid?
end
- def test_full_address
- registrar = Registrar.new(address_street: 'Main Street 1', address_zip: '1234',
- address_city: 'NY', address_state: 'NY State')
- assert_equal 'Main Street 1, NY, NY State, 1234', registrar.address
+ def test_returns_address
+ registrar = Registrar.new(street: 'Main Street 1',
+ zip: '1234',
+ city: 'NY',
+ state: 'NY State',
+ country_code: 'DE')
+
+ assert_equal Address.new(street: 'Main Street 1', zip: '1234', city: 'NY', state: 'NY State',
+ country: 'Germany'), registrar.address
+ end
+
+ def test_returns_billing_address
+ registrar = Registrar.new(street: 'Main Street 1',
+ zip: '1234',
+ city: 'NY',
+ state: 'NY State',
+ country_code: 'DE')
+
+ assert_equal Address.new(street: 'Main Street 1', zip: '1234', city: 'NY', state: 'NY State',
+ country: 'Germany'), registrar.billing_address
end
def test_invalid_with_vat_rate_when_registrar_is_vat_liable_locally
diff --git a/test/models/registry_test.rb b/test/models/registry_test.rb
index 5ec10ec9e4..a04f6c85f3 100644
--- a/test/models/registry_test.rb
+++ b/test/models/registry_test.rb
@@ -9,4 +9,19 @@ def test_returns_current_registry
assert_equal 20, registry.vat_rate
assert_equal Country.new(:us), registry.vat_country
end
+
+ def test_returns_billing_address
+ Setting.registry_street = 'Main Street'
+ Setting.registry_zip = '1234'
+ Setting.registry_city = 'NY'
+ Setting.registry_state = 'NY State'
+ Setting.registry_country_code = 'US'
+
+ registry = Registry.current
+ assert_equal Address.new(street: 'Main Street',
+ zip: '1234',
+ city: 'NY',
+ state: 'NY State',
+ country: Country.new('US')), registry.billing_address
+ end
end
\ No newline at end of file
diff --git a/test/system/admin_area/invoices_test.rb b/test/system/admin_area/invoices_test.rb
index 8fef3cddb3..b0a5ea317a 100644
--- a/test/system/admin_area/invoices_test.rb
+++ b/test/system/admin_area/invoices_test.rb
@@ -23,7 +23,7 @@ def test_cancels_an_invoice
end
def test_invoice_delivery_form_is_pre_populated_with_billing_email_of_a_registrar
- assert_equal 'billing@bestnames.test', @invoice.buyer.billing_email
+ assert_equal 'billing@bestnames.test', @invoice.registrar.billing_email
visit new_admin_invoice_delivery_url(@invoice)
assert_field 'Recipient', with: 'billing@bestnames.test'
end
diff --git a/test/system/registrar_area/invoices_test.rb b/test/system/registrar_area/invoices_test.rb
index 02df5da825..dafb6232c8 100644
--- a/test/system/registrar_area/invoices_test.rb
+++ b/test/system/registrar_area/invoices_test.rb
@@ -23,7 +23,7 @@ def test_cancels_an_invoice
end
def test_invoice_delivery_form_is_pre_populated_with_billing_email_of_a_registrar
- assert_equal 'billing@bestnames.test', @invoice.buyer.billing_email
+ assert_equal 'billing@bestnames.test', @invoice.registrar.billing_email
visit new_registrar_invoice_delivery_url(@invoice)
assert_field 'Recipient', with: 'billing@bestnames.test'
end