mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 23:24:48 +02:00
parent
6f9ea85a95
commit
c47ca77ca6
9 changed files with 105 additions and 1 deletions
|
@ -79,7 +79,8 @@ module Admin
|
|||
:code,
|
||||
:test_registrar,
|
||||
:accounting_customer_code,
|
||||
:language)
|
||||
:language,
|
||||
:vat_rate,)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,10 +17,22 @@ class Registrar < ActiveRecord::Base
|
|||
validates :name, :reg_no, :reference_no, :code, uniqueness: true
|
||||
validates :accounting_customer_code, presence: true
|
||||
validates :language, presence: true
|
||||
validates :vat_rate, :vat_no, absence: true, if: :local_vat_payer?
|
||||
validates :vat_rate, presence: true, if: 'foreign_vat_payer? && vat_no.blank?'
|
||||
validates :vat_rate, absence: true, if: 'foreign_vat_payer? && vat_no?'
|
||||
validates :vat_rate, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 99 }, allow_nil: true
|
||||
validate :forbidden_codes
|
||||
|
||||
after_initialize :set_defaults
|
||||
|
||||
before_save do
|
||||
self.vat_rate = vat_rate / 100.0 if vat_rate
|
||||
end
|
||||
|
||||
after_find do |registrar|
|
||||
registrar.vat_rate = registrar.vat_rate * 100 if registrar.vat_rate
|
||||
end
|
||||
|
||||
def forbidden_codes
|
||||
return true unless ['CID'].include? code
|
||||
errors.add(:code, I18n.t(:forbidden_code))
|
||||
|
@ -163,4 +175,12 @@ class Registrar < ActiveRecord::Base
|
|||
def set_defaults
|
||||
self.language = Setting.default_language unless language
|
||||
end
|
||||
|
||||
def local_vat_payer?
|
||||
country == Registry.instance.legal_address_country
|
||||
end
|
||||
|
||||
def foreign_vat_payer?
|
||||
!local_vat_payer?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
<dt><%= Registrar.human_attribute_name :vat_no %></dt>
|
||||
<dd><%= registrar.vat_no %></dd>
|
||||
|
||||
<dt><%= Registrar.human_attribute_name :vat_rate %></dt>
|
||||
<dd><%= number_to_percentage registrar.vat_rate, precision: 1 %></dd>
|
||||
|
||||
<dt><%= Registrar.human_attribute_name :accounting_customer_code %></dt>
|
||||
<dd><%= registrar.accounting_customer_code %></dd>
|
||||
|
||||
|
|
|
@ -17,6 +17,18 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-md-4 control-label">
|
||||
<%= f.label :vat_rate %>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="input-group">
|
||||
<%= f.number_field :vat_rate, class: 'form-control' %>
|
||||
<div class="input-group-addon">%</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-md-4 control-label">
|
||||
<%= f.label :accounting_customer_code %>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue