mirror of
https://github.com/internetee/registry.git
synced 2025-07-23 11:16:00 +02:00
parent
3d107bd198
commit
b68fe6e312
16 changed files with 110 additions and 92 deletions
|
@ -29,7 +29,7 @@ class BankLink
|
|||
hash["VK_VERSION"] = "008"
|
||||
hash["VK_SND_ID"] = ENV["payments_#{type}_seller_account"]
|
||||
hash["VK_STAMP"] = invoice.number
|
||||
hash["VK_AMOUNT"] = number_with_precision(invoice.sum_cache, :precision => 2, :separator => ".")
|
||||
hash["VK_AMOUNT"] = number_with_precision(invoice.total, :precision => 2, :separator => ".")
|
||||
hash["VK_CURR"] = invoice.currency
|
||||
hash["VK_REF"] = ""
|
||||
hash["VK_MSG"] = invoice.order
|
||||
|
@ -140,7 +140,7 @@ class BankLink
|
|||
|
||||
def validate_amount
|
||||
source = number_with_precision(BigDecimal.new(params["VK_AMOUNT"].to_s), precision: 2, separator: ".")
|
||||
target = number_with_precision(invoice.sum_cache, precision: 2, separator: ".")
|
||||
target = number_with_precision(invoice.total, precision: 2, separator: ".")
|
||||
|
||||
source == target
|
||||
end
|
||||
|
|
|
@ -47,7 +47,7 @@ class BankTransaction < ActiveRecord::Base
|
|||
return if invoice.binded?
|
||||
return if invoice.cancelled?
|
||||
|
||||
return if invoice.sum != sum
|
||||
return if invoice.total != sum
|
||||
create_activity(registrar, invoice)
|
||||
end
|
||||
# rubocop: enable Metrics/PerceivedComplexity
|
||||
|
@ -76,7 +76,7 @@ class BankTransaction < ActiveRecord::Base
|
|||
return
|
||||
end
|
||||
|
||||
if invoice.sum != sum
|
||||
if invoice.total != sum
|
||||
errors.add(:base, I18n.t('invoice_and_transaction_sums_do_not_match'))
|
||||
return
|
||||
end
|
||||
|
@ -88,7 +88,7 @@ class BankTransaction < ActiveRecord::Base
|
|||
create_account_activity(
|
||||
account: registrar.cash_account,
|
||||
invoice: invoice,
|
||||
sum: invoice.sum_without_vat,
|
||||
sum: invoice.subtotal,
|
||||
currency: currency,
|
||||
description: description,
|
||||
activity_type: AccountActivity::ADD_CREDIT
|
||||
|
|
|
@ -15,7 +15,7 @@ class Directo < ActiveRecord::Base
|
|||
group.each do |invoice|
|
||||
|
||||
if invoice.account_activity.nil? || invoice.account_activity.bank_transaction.nil? ||
|
||||
invoice.account_activity.bank_transaction.sum.nil? || invoice.account_activity.bank_transaction.sum != invoice.sum_cache
|
||||
invoice.account_activity.bank_transaction.sum.nil? || invoice.account_activity.bank_transaction.sum != invoice.total
|
||||
Rails.logger.info("[DIRECTO] Invoice #{invoice.number} has been skipped")
|
||||
next
|
||||
end
|
||||
|
@ -34,7 +34,7 @@ class Directo < ActiveRecord::Base
|
|||
xml.line(
|
||||
"ProductID" => Setting.directo_receipt_product_name,
|
||||
"Quantity" => 1,
|
||||
"UnitPriceWoVAT" => ActionController::Base.helpers.number_with_precision(invoice.sum_cache/(1+invoice.vat_rate), precision: 2, separator: "."),
|
||||
"UnitPriceWoVAT" => ActionController::Base.helpers.number_with_precision(invoice.total/(1+invoice.vat_rate), precision: 2, separator: "."),
|
||||
"ProductName" => invoice.order
|
||||
)
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ class Invoice < ActiveRecord::Base
|
|||
|
||||
before_create :set_invoice_number
|
||||
before_create :apply_default_vat_rate, unless: :vat_rate?
|
||||
before_create :save_total
|
||||
|
||||
attribute :vat_rate, ::Type::VATRate.new
|
||||
attr_readonly :vat_rate
|
||||
|
@ -54,8 +55,6 @@ class Invoice < ActiveRecord::Base
|
|||
false
|
||||
end
|
||||
|
||||
before_save -> { self.sum_cache = sum }
|
||||
|
||||
class << self
|
||||
def cancel_overdue_invoices
|
||||
STDOUT << "#{Time.zone.now.utc} - Cancelling overdue invoices\n" unless Rails.env.test?
|
||||
|
@ -150,17 +149,13 @@ class Invoice < ActiveRecord::Base
|
|||
invoice_items
|
||||
end
|
||||
|
||||
def sum_without_vat
|
||||
def subtotal
|
||||
(items.map(&:item_sum_without_vat).sum).round(2)
|
||||
end
|
||||
|
||||
def vat
|
||||
return 0 unless vat_rate
|
||||
sum_without_vat * vat_rate / 100
|
||||
end
|
||||
|
||||
def sum
|
||||
(sum_without_vat + vat).round(2)
|
||||
subtotal * vat_rate / 100
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -168,4 +163,8 @@ class Invoice < ActiveRecord::Base
|
|||
def apply_default_vat_rate
|
||||
self.vat_rate = buyer.effective_vat_rate
|
||||
end
|
||||
|
||||
def calculate_total
|
||||
# (sum_without_vat + vat).round(2)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue