From 68dd6604e79aff2c248176c4206fb900dd402f6a Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 6 May 2019 17:37:22 +0300 Subject: [PATCH] Refactor invoices - Combine invoice seller and buyer address parts - Convert HAML to ERB - Extract translations - Extract partials - Improve database structure Closes #1189, #1188 --- app/controllers/concerns/deliverable.rb | 2 +- app/models/ability.rb | 2 +- app/models/address.rb | 36 ++++++++ app/models/bank_account.rb | 7 ++ app/models/bank_transaction.rb | 4 +- app/models/company.rb | 11 +++ app/models/directo.rb | 2 +- app/models/invoice.rb | 59 ++++++++----- app/models/registrar.rb | 37 ++++---- app/models/registry.rb | 14 +++ app/views/admin/base/_menu.haml | 2 +- app/views/admin/invoices/_invoice.html.erb | 28 ++++++ app/views/admin/invoices/index.haml | 36 -------- app/views/admin/invoices/index.html.erb | 45 ++++++++++ app/views/admin/invoices/show.haml | 23 ----- app/views/admin/invoices/show.html.erb | 40 +++++++++ app/views/admin/registrars/_contacts.html.erb | 4 +- app/views/invoice/pdf.haml | 87 +++++++++---------- app/views/invoices/show/_buyer.html.erb | 23 +++++ app/views/invoices/show/_details.html.erb | 73 ++++++++++++++++ app/views/invoices/show/_invoice_item.erb | 7 ++ app/views/invoices/show/_items.html.erb | 41 +++++++++ app/views/invoices/show/_seller.html.erb | 38 ++++++++ .../invoices/{partials => }/_banklinks.haml | 0 .../registrar/invoices/_invoice.html.erb | 20 +++++ .../registrar/invoices/_search_form.html.erb | 50 +++++++++++ app/views/registrar/invoices/index.haml | 73 ---------------- app/views/registrar/invoices/index.html.erb | 53 +++++++++++ .../registrar/invoices/partials/_buyer.haml | 23 ----- .../registrar/invoices/partials/_details.haml | 36 -------- .../registrar/invoices/partials/_items.haml | 32 ------- .../registrar/invoices/partials/_seller.haml | 38 -------- app/views/registrar/invoices/show.haml | 20 ----- app/views/registrar/invoices/show.html.erb | 35 ++++++++ config/locales/admin/invoices.en.yml | 1 + config/locales/admin/menu.en.yml | 1 + config/locales/en.yml | 18 +--- config/locales/invoices.en.yml | 16 ++++ config/locales/registrar/invoices.en.yml | 2 + ...190508091835_add_invoices_buyer_address.rb | 5 ++ ...20190508101415_add_invoices_buyer_id_fk.rb | 5 ++ ...ename_invoices_buyer_id_to_registrar_id.rb | 5 ++ ...hange_invoices_registrar_id_to_not_null.rb | 5 ++ ...90508122705_add_invoices_seller_address.rb | 5 ++ db/structure.sql | 32 +++++-- .../populate_invoice_parties_addresses.rake | 28 ++++++ test/fixtures/invoices.yml | 8 +- test/models/address_test.rb | 37 ++++++++ test/models/invoice_test.rb | 51 +++++++++-- test/models/registrar_test.rb | 22 +++++ test/models/registry_test.rb | 16 +++- test/system/admin_area/invoices_test.rb | 2 +- test/system/registrar_area/invoices_test.rb | 2 +- ...populate_invoice_parties_addresses_test.rb | 59 +++++++++++++ 54 files changed, 913 insertions(+), 408 deletions(-) create mode 100644 app/models/address.rb create mode 100644 app/models/bank_account.rb create mode 100644 app/models/company.rb create mode 100644 app/views/admin/invoices/_invoice.html.erb delete mode 100644 app/views/admin/invoices/index.haml create mode 100644 app/views/admin/invoices/index.html.erb delete mode 100644 app/views/admin/invoices/show.haml create mode 100644 app/views/admin/invoices/show.html.erb create mode 100644 app/views/invoices/show/_buyer.html.erb create mode 100644 app/views/invoices/show/_details.html.erb create mode 100644 app/views/invoices/show/_invoice_item.erb create mode 100644 app/views/invoices/show/_items.html.erb create mode 100644 app/views/invoices/show/_seller.html.erb rename app/views/registrar/invoices/{partials => }/_banklinks.haml (100%) create mode 100644 app/views/registrar/invoices/_invoice.html.erb create mode 100644 app/views/registrar/invoices/_search_form.html.erb delete mode 100644 app/views/registrar/invoices/index.haml create mode 100644 app/views/registrar/invoices/index.html.erb delete mode 100644 app/views/registrar/invoices/partials/_buyer.haml delete mode 100644 app/views/registrar/invoices/partials/_details.haml delete mode 100644 app/views/registrar/invoices/partials/_items.haml delete mode 100644 app/views/registrar/invoices/partials/_seller.haml delete mode 100644 app/views/registrar/invoices/show.haml create mode 100644 app/views/registrar/invoices/show.html.erb create mode 100644 config/locales/invoices.en.yml create mode 100644 db/migrate/20190508091835_add_invoices_buyer_address.rb create mode 100644 db/migrate/20190508101415_add_invoices_buyer_id_fk.rb create mode 100644 db/migrate/20190508101552_rename_invoices_buyer_id_to_registrar_id.rb create mode 100644 db/migrate/20190508101809_change_invoices_registrar_id_to_not_null.rb create mode 100644 db/migrate/20190508122705_add_invoices_seller_address.rb create mode 100644 lib/tasks/data_migrations/populate_invoice_parties_addresses.rake create mode 100644 test/models/address_test.rb create mode 100644 test/tasks/data_migrations/populate_invoice_parties_addresses_test.rb 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 8ca94d89b7..75e63b7e1f 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 end 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 aa43482624..b9bb2b5c6a 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 7e4dfe3924..ea765de4c4 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' @@ -34,7 +41,7 @@ class Invoice < ActiveRecord::Base before_create :set_invoice_number before_create :apply_default_vat_rate, unless: :vat_rate? before_create :calculate_total, unless: :total? - before_create :apply_default_buyer_vat_no, unless: :buyer_vat_no? + before_create :apply_default_vat_no, unless: :buyer_vat_no? attribute :vat_rate, ::Type::VATRate.new attr_readonly :vat_rate @@ -59,22 +66,6 @@ def to_s I18n.t('invoice_no', no: number) end - def seller_address - [seller_street, seller_city, seller_state, seller_zip].reject(&:blank?).compact.join(', ') - end - - def buyer_address - [buyer_street, buyer_city, buyer_state, buyer_zip].reject(&:blank?).compact.join(', ') - end - - def seller_country - Country.new(seller_country_code) - end - - def buyer_country - Country.new(buyer_country_code) - end - # order is used for directo/banklink description def order "Order nr. #{number}" @@ -103,14 +94,40 @@ def as_pdf generator.as_pdf end + 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 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 apply_default_vat_rate - self.vat_rate = buyer.effective_vat_rate + self.vat_rate = registrar.effective_vat_rate end - def apply_default_buyer_vat_no - self.buyer_vat_no = buyer.vat_no + def apply_default_vat_no + self.buyer_vat_no = registrar.vat_no end def calculate_total diff --git a/app/models/registrar.rb b/app/models/registrar.rb index d1da1c3173..84ae39fad0 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 @@ -61,23 +61,14 @@ 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.instance.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: country_code, - buyer_state: state, - buyer_street: street, - buyer_city: city, - buyer_zip: zip, + buyer_address: billing_address, buyer_phone: phone, buyer_url: website, buyer_email: email, @@ -103,18 +94,10 @@ def debit!(args) cash_account.account_activities.create!(args) end - def address - [street, city, state, zip].reject(&:blank?).compact.join(', ') - end - def to_s name end - def country - Country.new(country_code) - end - def code=(code) self[:code] = code.gsub(/[ :]/, '').upcase if new_record? && code.present? end @@ -157,6 +140,18 @@ def notify(action) notifications.create!(text: text) end + def address + Address.new(street: street, + zip: zip, + city: city, + state: state, + country: Country.new(country_code).to_s) + end + + def billing_address + address + end + private def set_defaults @@ -168,7 +163,7 @@ def forbid_special_code end def home_vat_payer? - country == Registry.instance.legal_address_country + Country.new(country_code) == Registry.instance.legal_address_country end def foreign_vat_payer? diff --git a/app/models/registry.rb b/app/models/registry.rb index 5e5c8cd937..a4b3816b43 100644 --- a/app/models/registry.rb +++ b/app/models/registry.rb @@ -8,4 +8,18 @@ def vat_rate def legal_address_country Country.new(Setting.registry_country_code) 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 diff --git a/app/views/admin/base/_menu.haml b/app/views/admin/base/_menu.haml index 6c8e152018..ad7abdac07 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 @@ + + +
+
+
+ + + + + + + + + + + <%= render @invoices %> + +
<%= 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) %> +
+
+
+
+ +
+
+ <%= 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..0d7b3c30b8 --- /dev/null +++ b/app/views/admin/invoices/show.html.erb @@ -0,0 +1,40 @@ +
+
+

+ <%= @invoice %> +

+
+
+

+ <% if @invoice.unpaid? %> + <%= link_to(t(:payment_received), new_admin_bank_statement_path(invoice_id: @invoice.id), class: 'btn btn-default') %> + <% end %> + <%= 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') %> + <% end %> + <%= link_to(t(:back), admin_invoices_path, class: 'btn btn-default') %> +

+
+
+
+<%= render 'shared/full_errors', object: @invoice %> +
+
+ <%= render 'invoices/show/details' %> +
+
+
+
+ <%= render 'invoices/show/seller', seller: @invoice.seller %> +
+
+ <%= render 'invoices/show/buyer', buyer: @invoice.buyer %> +
+
+
+
+ <%= render 'invoices/show/items' %> +
+
diff --git a/app/views/admin/registrars/_contacts.html.erb b/app/views/admin/registrars/_contacts.html.erb index 7599c68c3f..01f385f07b 100644 --- a/app/views/admin/registrars/_contacts.html.erb +++ b/app/views/admin/registrars/_contacts.html.erb @@ -6,7 +6,7 @@
<%= t(:country) %>
-
<%= @registrar.country %>
+
<%= @registrar.address.country %>
<%= t(:address) %>
<%= @registrar.address %>
@@ -18,4 +18,4 @@
<%= @registrar.email %>
- + \ No newline at end of file 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..e42abbed98 --- /dev/null +++ b/app/views/invoices/show/_details.html.erb @@ -0,0 +1,73 @@ +

+ <%= t(:details) %> +

+
+
+
<%= 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..2a47a5b6d4 --- /dev/null +++ b/app/views/invoices/show/_items.html.erb @@ -0,0 +1,41 @@ +

+ <%= t '.header' %> +

+
+
+ + + + + + + + + + + + + <%= render collection: @invoice.items, partial: 'invoices/show/invoice_item' %> + + + + + + + + + + + + + + + + + + + + + +
<%= 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 %>
<%= 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' %> +
+
+ +
+
+
+ + + + + + + + + + + + <%= render @invoices %> + +
<%= Invoice.human_attribute_name :number %><%= Invoice.human_attribute_name :receipt_date %><%= Invoice.human_attribute_name :due_date %><%= Invoice.human_attribute_name :total %>
+
+
+
+ +
+
+ <%= 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..e437449ad7 --- /dev/null +++ b/app/views/registrar/invoices/show.html.erb @@ -0,0 +1,35 @@ +<% 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') %> + <% end %> + <%= link_to(t(:back), registrar_invoices_path, class: 'btn btn-default') %> +<% end %> +<%= render 'shared/title', name: @invoice.to_s %> +<%= render 'shared/full_errors', object: @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? %> +
+
+ <%= render 'banklinks', locals: { payment_channels: PaymentOrders::PAYMENT_METHODS } %> +
+
+<% end %> diff --git a/config/locales/admin/invoices.en.yml b/config/locales/admin/invoices.en.yml index 6ec73ca9c6..b2a5dd4a9a 100644 --- a/config/locales/admin/invoices.en.yml +++ b/config/locales/admin/invoices.en.yml @@ -3,6 +3,7 @@ en: invoices: index: header: Invoices + new_btn: New invoice show: download_btn: Download 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 5033588f62..1c010f0735 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' @@ -390,7 +389,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}.' @@ -485,22 +483,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' @@ -526,7 +514,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' @@ -558,7 +545,6 @@ 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' @@ -694,3 +680,7 @@ en: ipv4: IPv4 ipv6: IPv6 reference_no: Reference number + reg_no: Registration number + iban: IBAN + 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..04e3ee4b11 --- /dev/null +++ b/config/locales/invoices.en.yml @@ -0,0 +1,16 @@ +en: + invoice: + pdf: + seller: Seller + buyer: Buyer + + invoices: + show: + 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..449ea01d3f 100644 --- a/config/locales/registrar/invoices.en.yml +++ b/config/locales/registrar/invoices.en.yml @@ -10,6 +10,8 @@ en: index: header: Invoices + + search_form: reset_btn: Reset show: diff --git a/db/migrate/20190508091835_add_invoices_buyer_address.rb b/db/migrate/20190508091835_add_invoices_buyer_address.rb new file mode 100644 index 0000000000..19291b48a7 --- /dev/null +++ b/db/migrate/20190508091835_add_invoices_buyer_address.rb @@ -0,0 +1,5 @@ +class AddInvoicesBuyerAddress < ActiveRecord::Migration + def change + add_column :invoices, :buyer_address, :string, null: false, default: '' + end +end \ 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/20190508122705_add_invoices_seller_address.rb b/db/migrate/20190508122705_add_invoices_seller_address.rb new file mode 100644 index 0000000000..c90de917ae --- /dev/null +++ b/db/migrate/20190508122705_add_invoices_seller_address.rb @@ -0,0 +1,5 @@ +class AddInvoicesSellerAddress < ActiveRecord::Migration + def change + add_column :invoices, :seller_address, :string, null: false, default: '' + end +end \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index cc0931e586..890d15284c 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1064,7 +1064,7 @@ CREATE TABLE public.invoices ( 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, @@ -1082,7 +1082,9 @@ CREATE TABLE public.invoices ( total numeric(10,2) NOT NULL, in_directo boolean DEFAULT false, buyer_vat_no character varying, - issue_date date NOT NULL + issue_date date NOT NULL, + buyer_address character varying DEFAULT ''::character varying NOT NULL, + seller_address character varying DEFAULT ''::character varying NOT NULL ); @@ -3610,14 +3612,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); @@ -4069,6 +4071,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: - -- @@ -4945,3 +4955,15 @@ INSERT INTO schema_migrations (version) VALUES ('20190328151838'); INSERT INTO schema_migrations (version) VALUES ('20190415120246'); +INSERT INTO schema_migrations (version) VALUES ('20190506102959'); + +INSERT INTO schema_migrations (version) VALUES ('20190508091835'); + +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 ('20190508122705'); + diff --git a/lib/tasks/data_migrations/populate_invoice_parties_addresses.rake b/lib/tasks/data_migrations/populate_invoice_parties_addresses.rake new file mode 100644 index 0000000000..1283999cbb --- /dev/null +++ b/lib/tasks/data_migrations/populate_invoice_parties_addresses.rake @@ -0,0 +1,28 @@ +namespace :data_migrations do + task populate_invoice_parties_addresses: :environment do + processed_invoice_count = 0 + + Invoice.transaction do + Invoice.all.each do |invoice| + seller_address = Address.new(street: invoice.seller_street, + zip: invoice.seller_zip, + city: invoice.seller_city, + state: invoice.seller_state, + country: Country.new(invoice.seller_country_code)) + + buyer_address = Address.new(street: invoice.buyer_street, + zip: invoice.buyer_zip, + city: invoice.buyer_city, + state: invoice.buyer_state, + country: Country.new(invoice.buyer_country_code)) + + invoice.update_columns(seller_address: seller_address.to_s, + buyer_address: buyer_address.to_s) + + processed_invoice_count += 1 + end + end + + puts "Invoices processed: #{processed_invoice_count}" + end +end \ No newline at end of file diff --git a/test/fixtures/invoices.yml b/test/fixtures/invoices.yml index 9957f787ae..45e2494b71 100644 --- a/test/fixtures/invoices.yml +++ b/test/fixtures/invoices.yml @@ -4,8 +4,10 @@ one: currency: EUR seller_name: John Doe seller_iban: 1234 - buyer: bestnames + seller_address: Main Street 1, 1234, NY, NY State, United States + registrar: bestnames buyer_name: Jane Doe + buyer_address: Main Street 2, 1234, NY, NY State, United States vat_rate: 0.1 total: 16.50 reference_no: 13 @@ -18,8 +20,10 @@ for_payments_test: currency: EUR seller_name: John Doe seller_iban: 1234 - buyer: bestnames + seller_address: Main Street 1, 1234, NY, NY State, United States + registrar: bestnames buyer_name: Jane Doe + buyer_address: Main Street 2, 1234, NY, NY State, United States vat_rate: 0.1 reference_no: 13 total: 12.00 \ No newline at end of file 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 56d5334588..0e60fb098e 100644 --- a/test/models/invoice_test.rb +++ b/test/models/invoice_test.rb @@ -65,7 +65,7 @@ def test_vat_rate_defaults_to_effective_vat_rate_of_a_registrar registrar = registrars(:bestnames) invoice = @invoice.dup invoice.vat_rate = nil - invoice.buyer = registrar + invoice.registrar = registrar invoice.items = @invoice.items registrar.stub(:effective_vat_rate, BigDecimal(55)) do @@ -127,7 +127,7 @@ def test_buyer_vat_no_is_taken_from_registrar_by_default registrar.vat_no = 'US1234' invoice = @invoice.dup invoice.buyer_vat_no = nil - invoice.buyer = registrar + invoice.registrar = registrar invoice.items = @invoice.items invoice.save! assert_equal 'US1234', invoice.buyer_vat_no @@ -150,9 +150,48 @@ def test_iterates_over_invoice_items assert_equal 1, iteration_count end - def test_returns_combined_seller_address - invoice = Invoice.new(seller_street: 'street', seller_city: 'city', seller_state: 'state', - seller_zip: nil) - assert_equal 'street, city, state', invoice.seller_address + 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 end \ No newline at end of file diff --git a/test/models/registrar_test.rb b/test/models/registrar_test.rb index 312822a8f3..03a6c703ec 100644 --- a/test/models/registrar_test.rb +++ b/test/models/registrar_test.rb @@ -96,4 +96,26 @@ def test_issues_new_invoice Setting.days_to_keep_invoices_active = @original_days_to_keep_invoices_active_setting end + + 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 end diff --git a/test/models/registry_test.rb b/test/models/registry_test.rb index 80c88c8bf8..13986958e3 100644 --- a/test/models/registry_test.rb +++ b/test/models/registry_test.rb @@ -17,4 +17,18 @@ def test_vat_rate Setting.registry_vat_prc = original_vat_prc end -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' + + 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 diff --git a/test/tasks/data_migrations/populate_invoice_parties_addresses_test.rb b/test/tasks/data_migrations/populate_invoice_parties_addresses_test.rb new file mode 100644 index 0000000000..808bc98bbc --- /dev/null +++ b/test/tasks/data_migrations/populate_invoice_parties_addresses_test.rb @@ -0,0 +1,59 @@ +require 'test_helper' + +class PopulateInvoicePartiesAddressesTaskTest < ActiveSupport::TestCase + setup do + @invoice = invoices(:one) + end + + def test_populates_seller_address + @invoice.update!(seller_address: '', + seller_street: 'Main Street', + seller_zip: '1234', + seller_city: 'NY', + seller_state: 'NY State', + seller_country_code: 'DE') + + capture_io do + run_task + end + @invoice.reload + + assert_not_empty @invoice.seller_address + end + + def test_populates_buyer_address + @invoice.update!(buyer_address: '', + buyer_street: 'Main Street', + buyer_zip: '1234', + buyer_city: 'NY', + buyer_state: 'NY State', + buyer_country_code: 'DE') + + capture_io do + run_task + end + @invoice.reload + + assert_not_empty @invoice.buyer_address + end + + def test_output + eliminate_effect_of_all_invoices_except(@invoice) + + assert_output "Invoices processed: 1\n" do + run_task + end + end + + private + + def eliminate_effect_of_all_invoices_except(invoice) + Invoice.connection.disable_referential_integrity do + Invoice.delete_all("id != #{invoice.id}") + end + end + + def run_task + Rake::Task['data_migrations:populate_invoice_parties_addresses'].execute + end +end \ No newline at end of file