mirror of
https://github.com/internetee/registry.git
synced 2025-08-02 16:02:03 +02:00
Story#105852786 - Directo invoices are calculated based on invoices
This commit is contained in:
parent
bc640c63fe
commit
72bd54dc7c
6 changed files with 22 additions and 19 deletions
|
@ -32,7 +32,7 @@ class BankLink
|
|||
hash["VK_AMOUNT"] = number_with_precision(invoice.sum_cache, :precision => 2, :separator => ".")
|
||||
hash["VK_CURR"] = invoice.currency
|
||||
hash["VK_REF"] = ""
|
||||
hash["VK_MSG"] = "Order nr. #{invoice.number}"
|
||||
hash["VK_MSG"] = invoice.description
|
||||
hash["VK_RETURN"] = controller.registrar_return_payment_with_url(type)
|
||||
hash["VK_CANCEL"] = controller.registrar_return_payment_with_url(type)
|
||||
hash["VK_DATETIME"] = Time.now.strftime("%Y-%m-%dT%H:%M:%S%z")
|
||||
|
@ -101,6 +101,7 @@ class BankLink
|
|||
transaction.buyer_iban = params["VK_SND_ACC"]
|
||||
transaction.buyer_name = params["VK_SND_NAME"]
|
||||
transaction.paid_at = Time.parse(params["VK_T_DATETIME"])
|
||||
transaction.save!
|
||||
|
||||
transaction.autobind_invoice
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ class BankTransaction < ActiveRecord::Base
|
|||
include Versions
|
||||
belongs_to :bank_statement
|
||||
has_one :account_activity
|
||||
has_many :directo_records, as: :item, class_name: 'Directo'
|
||||
has_many :directo_records, as: :item, class_name: 'Directo'# Deprecated
|
||||
|
||||
scope :unbinded, lambda {
|
||||
where('id NOT IN (SELECT bank_transaction_id FROM account_activities where bank_transaction_id IS NOT NULL)')
|
||||
|
|
|
@ -2,30 +2,27 @@ class Directo < ActiveRecord::Base
|
|||
belongs_to :item, polymorphic: true
|
||||
|
||||
def self.send_receipts
|
||||
new_trans = BankTransaction.where(in_directo: false)
|
||||
new_trans = Invoice.where(invoice_type: "DEB", in_directo: false)
|
||||
new_trans.find_in_batches(batch_size: 10).each do |group|
|
||||
mappers = {} # need them as no direct connection between transaction and invoice
|
||||
mappers = {} # need them as no direct connection between invoice
|
||||
builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
|
||||
xml.invoices {
|
||||
group.each do |transaction|
|
||||
invoice = transaction.invoice
|
||||
next unless invoice
|
||||
num = transaction.invoice_num
|
||||
mappers[num] = transaction
|
||||
|
||||
group.each do |invoice|
|
||||
num = invoice.number
|
||||
mappers[num] = invoice
|
||||
xml.invoice(
|
||||
"SalesAgent" => Setting.directo_sales_agent,
|
||||
"Number" => num,
|
||||
"InvoiceDate" => (transaction.paid_at||transaction.created_at).strftime("%Y-%m-%dT%H:%M:%S"),
|
||||
"InvoiceDate" => (invoice.account_activity.try(:bank_transaction).try(:paid_at) || invoice.updated_at).strftime("%Y-%m-%dT%H:%M:%S"),
|
||||
"PaymentTerm" => Setting.directo_receipt_payment_term,
|
||||
"Currency" => transaction.currency,
|
||||
"Currency" => invoice.currency,
|
||||
"CustomerCode"=> invoice.buyer.try(:directo_handle)
|
||||
){
|
||||
xml.line(
|
||||
"ProductID"=> Setting.directo_receipt_product_name,
|
||||
"Quantity" => 1,
|
||||
"UnitPriceWoVAT" =>ActionController::Base.helpers.number_with_precision(invoice.sum_cache/(1+invoice.vat_prc), precision: 2, separator: "."),
|
||||
"ProductName" => transaction.description
|
||||
"ProductName" => invoice.description
|
||||
)
|
||||
}
|
||||
end
|
||||
|
|
|
@ -2,8 +2,9 @@ class Invoice < ActiveRecord::Base
|
|||
include Versions
|
||||
belongs_to :seller, class_name: 'Registrar'
|
||||
belongs_to :buyer, class_name: 'Registrar'
|
||||
has_one :account_activity
|
||||
has_many :invoice_items
|
||||
has_one :account_activity
|
||||
has_many :directo_records, as: :item, class_name: 'Directo'
|
||||
|
||||
accepts_nested_attributes_for :invoice_items
|
||||
|
||||
|
@ -99,6 +100,10 @@ class Invoice < ActiveRecord::Base
|
|||
kit.to_pdf
|
||||
end
|
||||
|
||||
def description
|
||||
"Order nr. #{number}"
|
||||
end
|
||||
|
||||
def pdf_name
|
||||
"invoice-#{number}.pdf"
|
||||
end
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
class AddInDirectoToBankTransaction < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :bank_transactions, :in_directo, :boolean, default: false
|
||||
end
|
||||
end
|
5
db/migrate/20160118092454_add_in_directo_to_invoice.rb
Normal file
5
db/migrate/20160118092454_add_in_directo_to_invoice.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class AddInDirectoToInvoice < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :invoices, :in_directo, :boolean, default: false
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue