ruckus/quickbooks-ruby — pull request #112 by markrickert (2014-05-14 18:46:29+00:00)
Title: JournalEntry implemented

No specs yet. Help? The documentation and examples for JournalEntry is not very good on their dev site. :/

So far, here's what I have to create a journal entry (with the new `Entity`) model:

```ruby
@service = QB.new_service('JournalEntry')
journal_entry = Quickbooks::Model::JournalEntry.new
journal_entry.doc_number = '1234'
journal_entry.txn_date = Time.now.to_date
journal_entry.line_items = []

line_items.each do |key, journal_line|
l = Quickbooks::Model::Line.new

l.line_num = journal_line['Sequence Number']
l.detail_type = 'JournalEntryLineDetail'
l.description = journal_line['Memo']
l.amount = (journal_line['AmountDebit'].nil?) ? journal_line['AmountCredit'] : journal_line['AmountDebit']

jeld = Quickbooks::Model::JournalEntryLineDetail.new
jeld.posting_type = (journal_line['AmountDebit'].nil?) ? 'Credit' : 'Debit'
jeld.account_id = 2
jeld.class_id = 3
jeld.department_id = 5

# Accounts Receivable
if # you're trying to link to an accounts receivable account
entity = Quickbooks::Model::Entity.new
entity.type = 'Customer'
entity.entity_id = customer_id
jeld.entity = entity
end

# Accounts Payable
if # you're trying to link to an accounts payable account
entity = Quickbooks::Model::Entity.new
entity.type = 'Vendor'
entity.entity_id = vendor_id
jeld.entity = entity
end

l.journal_entry_line_detail = jeld
journal_entry.line_items << l
end

@service.create(journal_entry)
```

or something like that :)

One thing to be aware of... getting a journal entry from the server, changing the line items, and then pushing it back up to the server will ADD the line items, even if you deleted them from the `line_items` array. grrrr. You probably have to remove all line items, update it, and then add your line items and update it again.