class Quickbooks::Model::Line

def add_linked_transaction(txn_id, txn_type)

def add_linked_transaction(txn_id, txn_type)
  self.linked_transactions << LinkedTransaction.new(txn_id: txn_id,
                                                    txn_type: txn_type)
end

def credit_memo_id=(id)

def credit_memo_id=(id)
  update_linked_transactions([id], 'CreditMemo')
end

def discount!

def discount!
  self.detail_type = DISCOUNT_LINE_DETAIL
  self.discount_line_detail = DiscountLineDetail.new
  yield self.discount_line_detail if block_given?
end

def group_line!

def group_line!
  self.detail_type = GROUP_LINE_DETAIL
  self.group_line_detail = GroupLineDetail.new
  yield self.group_line_detail if block_given?
end

def initialize(*args)

def initialize(*args)
  self.linked_transactions ||= []
  super
end

def invoice_id=(id)

def invoice_id=(id)
  update_linked_transactions([id], 'Invoice')
end

def journal_entry!

def journal_entry!
  self.detail_type = JOURNAL_ENTRY_LINE_DETAIL
  self.journal_entry_line_detail = JournalEntryLineDetail.new
  yield self.journal_entry_line_detail if block_given?
end

def payment!

def payment!
  self.detail_type = PAYMENT_LINE_DETAIL
  self.payment_line_detail = PaymentLineDetail.new
  yield self.payment_line_detail if block_given?
end

def remove_linked_transactions(txn_type)

def remove_linked_transactions(txn_type)
  self.linked_transactions.delete_if { |lt| lt.txn_type == txn_type }
end

def sales_item!

def sales_item!
  self.detail_type = SALES_ITEM_LINE_DETAIL
  self.sales_item_line_detail = SalesItemLineDetail.new
  yield self.sales_item_line_detail if block_given?
end

def sub_total!

def sub_total!
  self.detail_type = SUB_TOTAL_LINE_DETAIL
  self.sub_total_line_detail = SubTotalLineDetail.new
  yield self.sub_total_line_detail if block_given?
end

def update_linked_transactions(txn_ids, txn_type)

def update_linked_transactions(txn_ids, txn_type)
  remove_linked_transactions(txn_type)
  txn_ids.flatten.compact.each do |id|
    add_linked_transaction(id, txn_type)
  end
end