Sha256: 0cdcefd1bf2b34fcd648466b82702bb034867346455977794ee60c9978396af2

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require_relative 'account'
require_relative 'currency'
require_relative 'customer'
require_relative 'department'
require_relative 'expense_line'
require_relative 'vendor'
require_relative 'bill_payment'

module LedgerSync
  module Ledgers
    module QuickBooksOnline
      class Expense < QuickBooksOnline::Resource
        PAYMENT_TYPES = BillPayment::PAYMENT_TYPES

        attribute :PrivateNote, type: Type::String
        attribute :PaymentType, type: Type::StringFromSet.new(values: PAYMENT_TYPES.keys)
        attribute :TxnDate, type: Type::Date
        attribute :ExchangeRate, type: Type::Float
        attribute :DocNumber, type: Type::String

        references_one :Entity, to: [Customer, Vendor]
        references_one :Account, to: Account
        references_one :Department, to: Department
        references_one :Currency, to: Currency

        references_many :Line, to: ExpenseLine

        def amount
          line_items.map(&:amount).sum
        end

        def name
          "Purchase: #{amount} #{self.Currency.try(:symbol)}"
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ledger_sync-1.6.0 lib/ledger_sync/ledgers/quickbooks_online/resources/expense.rb
ledger_sync-1.5.2 lib/ledger_sync/ledgers/quickbooks_online/resources/expense.rb
ledger_sync-1.5.1 lib/ledger_sync/ledgers/quickbooks_online/resources/expense.rb
ledger_sync-1.5.0 lib/ledger_sync/ledgers/quickbooks_online/resources/expense.rb