Fully implemented prepayment Directo invoice forwarding, WIP on proformas

This commit is contained in:
Karl Erik Õunapuu 2020-02-12 17:14:18 +02:00
parent faeb50cad5
commit d5662f42b8
10 changed files with 249 additions and 337 deletions

View file

@ -102,6 +102,22 @@ class Invoice < ApplicationRecord
generator.generate
end
def as_directo_json
inv = ActiveSupport::JSON.decode(ActiveSupport::JSON.encode(self))
inv['customer_code'] = buyer.accounting_customer_code
inv['issue_date'] = issue_date.strftime('%Y-%m-%d')
inv['transaction_date'] = account_activity.bank_transaction&.paid_at&.strftime('%Y-%m-%d')
inv['language'] = buyer.language
inv['invoice_lines'] = [{
'product_id': Setting.directo_receipt_product_name,
'description': order,
'quantity': 1,
'price': ActionController::Base.helpers.number_with_precision(subtotal, precision: 2, separator: ".")
}].as_json
inv
end
private
def apply_default_buyer_vat_no
@ -111,4 +127,4 @@ class Invoice < ApplicationRecord
def calculate_total
self.total = subtotal + vat_amount
end
end
end