quickbooks-ruby-oauth2 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/quickbooks/faraday/middleware/gzip.rb +72 -0
- data/lib/quickbooks/model/access_token_response.rb +29 -0
- data/lib/quickbooks/model/account.rb +78 -0
- data/lib/quickbooks/model/account_based_expense_line_detail.rb +15 -0
- data/lib/quickbooks/model/attachable.rb +33 -0
- data/lib/quickbooks/model/attachable_ref.rb +22 -0
- data/lib/quickbooks/model/base_model.rb +120 -0
- data/lib/quickbooks/model/base_model_json.rb +16 -0
- data/lib/quickbooks/model/base_reference.rb +23 -0
- data/lib/quickbooks/model/batch_request.rb +45 -0
- data/lib/quickbooks/model/batch_response.rb +33 -0
- data/lib/quickbooks/model/bill.rb +45 -0
- data/lib/quickbooks/model/bill_line_item.rb +42 -0
- data/lib/quickbooks/model/bill_payment.rb +40 -0
- data/lib/quickbooks/model/bill_payment_check.rb +12 -0
- data/lib/quickbooks/model/bill_payment_credit_card.rb +10 -0
- data/lib/quickbooks/model/bill_payment_line_item.rb +21 -0
- data/lib/quickbooks/model/budget.rb +27 -0
- data/lib/quickbooks/model/budget_line_item.rb +15 -0
- data/lib/quickbooks/model/change_data_capture.rb +42 -0
- data/lib/quickbooks/model/change_model.rb +10 -0
- data/lib/quickbooks/model/check_payment.rb +11 -0
- data/lib/quickbooks/model/class.rb +31 -0
- data/lib/quickbooks/model/company_info.rb +69 -0
- data/lib/quickbooks/model/credit_card_payment.rb +17 -0
- data/lib/quickbooks/model/credit_memo.rb +59 -0
- data/lib/quickbooks/model/credit_memo_change.rb +8 -0
- data/lib/quickbooks/model/custom_field.rb +13 -0
- data/lib/quickbooks/model/customer.rb +76 -0
- data/lib/quickbooks/model/customer_change.rb +8 -0
- data/lib/quickbooks/model/definition.rb +46 -0
- data/lib/quickbooks/model/delivery_info.rb +8 -0
- data/lib/quickbooks/model/department.rb +31 -0
- data/lib/quickbooks/model/deposit.rb +44 -0
- data/lib/quickbooks/model/deposit_line_detail.rb +17 -0
- data/lib/quickbooks/model/deposit_line_item.rb +35 -0
- data/lib/quickbooks/model/description_line_detail.rb +7 -0
- data/lib/quickbooks/model/discount_line_detail.rb +15 -0
- data/lib/quickbooks/model/discount_override.rb +13 -0
- data/lib/quickbooks/model/document_numbering.rb +18 -0
- data/lib/quickbooks/model/effective_tax_rate.rb +15 -0
- data/lib/quickbooks/model/email_address.rb +19 -0
- data/lib/quickbooks/model/employee.rb +47 -0
- data/lib/quickbooks/model/entity.rb +16 -0
- data/lib/quickbooks/model/entity_ref.rb +8 -0
- data/lib/quickbooks/model/estimate.rb +76 -0
- data/lib/quickbooks/model/exchange_rate.rb +23 -0
- data/lib/quickbooks/model/fault.rb +16 -0
- data/lib/quickbooks/model/global_tax_calculation.rb +13 -0
- data/lib/quickbooks/model/group_line_detail.rb +13 -0
- data/lib/quickbooks/model/has_line_items.rb +14 -0
- data/lib/quickbooks/model/invoice.rb +107 -0
- data/lib/quickbooks/model/invoice_change.rb +9 -0
- data/lib/quickbooks/model/invoice_group_line_detail.rb +14 -0
- data/lib/quickbooks/model/invoice_line_item.rb +88 -0
- data/lib/quickbooks/model/item.rb +87 -0
- data/lib/quickbooks/model/item_based_expense_line_detail.rb +20 -0
- data/lib/quickbooks/model/item_change.rb +8 -0
- data/lib/quickbooks/model/item_group_detail.rb +9 -0
- data/lib/quickbooks/model/item_group_line.rb +20 -0
- data/lib/quickbooks/model/journal_entry.rb +36 -0
- data/lib/quickbooks/model/journal_entry_line_detail.rb +27 -0
- data/lib/quickbooks/model/line.rb +95 -0
- data/lib/quickbooks/model/line_ex.rb +9 -0
- data/lib/quickbooks/model/linked_transaction.rb +9 -0
- data/lib/quickbooks/model/markup_info.rb +12 -0
- data/lib/quickbooks/model/meta_data.rb +24 -0
- data/lib/quickbooks/model/name_value.rb +8 -0
- data/lib/quickbooks/model/other_contact_info.rb +8 -0
- data/lib/quickbooks/model/payment.rb +43 -0
- data/lib/quickbooks/model/payment_change.rb +8 -0
- data/lib/quickbooks/model/payment_line_detail.rb +12 -0
- data/lib/quickbooks/model/payment_method.rb +25 -0
- data/lib/quickbooks/model/physical_address.rb +40 -0
- data/lib/quickbooks/model/preferences.rb +49 -0
- data/lib/quickbooks/model/purchase.rb +57 -0
- data/lib/quickbooks/model/purchase_line_item.rb +44 -0
- data/lib/quickbooks/model/purchase_order.rb +50 -0
- data/lib/quickbooks/model/purchase_tax_rate_list.rb +11 -0
- data/lib/quickbooks/model/refund_receipt.rb +62 -0
- data/lib/quickbooks/model/refund_receipt_change.rb +8 -0
- data/lib/quickbooks/model/report.rb +52 -0
- data/lib/quickbooks/model/sales_item_line_detail.rb +16 -0
- data/lib/quickbooks/model/sales_receipt.rb +65 -0
- data/lib/quickbooks/model/sales_tax_rate_list.rb +11 -0
- data/lib/quickbooks/model/sub_total_line_detail.rb +13 -0
- data/lib/quickbooks/model/tax_agency.rb +18 -0
- data/lib/quickbooks/model/tax_code.rb +21 -0
- data/lib/quickbooks/model/tax_line.rb +15 -0
- data/lib/quickbooks/model/tax_line_detail.rb +16 -0
- data/lib/quickbooks/model/tax_rate.rb +28 -0
- data/lib/quickbooks/model/tax_rate_detail.rb +15 -0
- data/lib/quickbooks/model/tax_rate_detail_line.rb +23 -0
- data/lib/quickbooks/model/tax_service.rb +52 -0
- data/lib/quickbooks/model/telephone_number.rb +13 -0
- data/lib/quickbooks/model/term.rb +28 -0
- data/lib/quickbooks/model/time_activity.rb +79 -0
- data/lib/quickbooks/model/transaction_tax_detail.rb +12 -0
- data/lib/quickbooks/model/transfer.rb +21 -0
- data/lib/quickbooks/model/upload.rb +35 -0
- data/lib/quickbooks/model/validator.rb +10 -0
- data/lib/quickbooks/model/vendor.rb +53 -0
- data/lib/quickbooks/model/vendor_change.rb +8 -0
- data/lib/quickbooks/model/vendor_credit.rb +40 -0
- data/lib/quickbooks/model/web_site_address.rb +16 -0
- data/lib/quickbooks/service/access_token.rb +38 -0
- data/lib/quickbooks/service/account.rb +17 -0
- data/lib/quickbooks/service/attachable.rb +12 -0
- data/lib/quickbooks/service/base_service.rb +445 -0
- data/lib/quickbooks/service/base_service_json.rb +39 -0
- data/lib/quickbooks/service/batch.rb +11 -0
- data/lib/quickbooks/service/bill.rb +16 -0
- data/lib/quickbooks/service/bill_payment.rb +16 -0
- data/lib/quickbooks/service/budget.rb +12 -0
- data/lib/quickbooks/service/change_data_capture.rb +24 -0
- data/lib/quickbooks/service/change_service.rb +28 -0
- data/lib/quickbooks/service/class.rb +23 -0
- data/lib/quickbooks/service/company_info.rb +12 -0
- data/lib/quickbooks/service/credit_memo.rb +16 -0
- data/lib/quickbooks/service/credit_memo_change.rb +16 -0
- data/lib/quickbooks/service/customer.rb +18 -0
- data/lib/quickbooks/service/customer_change.rb +16 -0
- data/lib/quickbooks/service/department.rb +23 -0
- data/lib/quickbooks/service/deposit.rb +16 -0
- data/lib/quickbooks/service/employee.rb +24 -0
- data/lib/quickbooks/service/estimate.rb +22 -0
- data/lib/quickbooks/service/exchange_rate.rb +25 -0
- data/lib/quickbooks/service/invoice.rb +45 -0
- data/lib/quickbooks/service/invoice_change.rb +16 -0
- data/lib/quickbooks/service/item.rb +32 -0
- data/lib/quickbooks/service/item_change.rb +16 -0
- data/lib/quickbooks/service/journal_entry.rb +16 -0
- data/lib/quickbooks/service/payment.rb +29 -0
- data/lib/quickbooks/service/payment_change.rb +16 -0
- data/lib/quickbooks/service/payment_method.rb +30 -0
- data/lib/quickbooks/service/preferences.rb +12 -0
- data/lib/quickbooks/service/purchase.rb +16 -0
- data/lib/quickbooks/service/purchase_order.rb +16 -0
- data/lib/quickbooks/service/refund_receipt.rb +16 -0
- data/lib/quickbooks/service/refund_receipt_change.rb +16 -0
- data/lib/quickbooks/service/reports.rb +33 -0
- data/lib/quickbooks/service/responses/methods.rb +17 -0
- data/lib/quickbooks/service/responses/oauth1_http_response.rb +42 -0
- data/lib/quickbooks/service/responses/oauth2_http_response.rb +43 -0
- data/lib/quickbooks/service/responses/oauth_http_response.rb +21 -0
- data/lib/quickbooks/service/sales_receipt.rb +46 -0
- data/lib/quickbooks/service/service_crud.rb +75 -0
- data/lib/quickbooks/service/service_crud_json.rb +31 -0
- data/lib/quickbooks/service/tax_agency.rb +12 -0
- data/lib/quickbooks/service/tax_code.rb +12 -0
- data/lib/quickbooks/service/tax_rate.rb +12 -0
- data/lib/quickbooks/service/tax_service.rb +11 -0
- data/lib/quickbooks/service/term.rb +17 -0
- data/lib/quickbooks/service/time_activity.rb +16 -0
- data/lib/quickbooks/service/transfer.rb +16 -0
- data/lib/quickbooks/service/upload.rb +39 -0
- data/lib/quickbooks/service/vendor.rb +24 -0
- data/lib/quickbooks/service/vendor_change.rb +16 -0
- data/lib/quickbooks/service/vendor_credit.rb +16 -0
- data/lib/quickbooks/util/collection.rb +18 -0
- data/lib/quickbooks/util/http_encoding_helper.rb +54 -0
- data/lib/quickbooks/util/logging.rb +19 -0
- data/lib/quickbooks/util/multipart.rb +85 -0
- data/lib/quickbooks/util/name_entity.rb +85 -0
- data/lib/quickbooks/util/query_builder.rb +35 -0
- data/lib/quickbooks/version.rb +5 -0
- data/lib/quickbooks-ruby.rb +255 -0
- metadata +378 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class JournalEntry < BaseModel
|
4
|
+
include HasLineItems
|
5
|
+
|
6
|
+
XML_COLLECTION_NODE = "JournalEntry"
|
7
|
+
XML_NODE = "JournalEntry"
|
8
|
+
REST_RESOURCE = 'journalentry'
|
9
|
+
|
10
|
+
xml_accessor :id, :from => 'Id'
|
11
|
+
xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
|
12
|
+
xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
|
13
|
+
xml_accessor :doc_number, :from => 'DocNumber'
|
14
|
+
xml_accessor :txn_date, :from => 'TxnDate', :as => Date
|
15
|
+
xml_accessor :exchange_rate, :from => 'ExchangeRate', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
16
|
+
xml_accessor :private_note, :from => 'PrivateNote'
|
17
|
+
xml_accessor :line_items, :from => 'Line', :as => [Line]
|
18
|
+
xml_accessor :txn_tax_detail, :from => 'TxnTaxDetail', :as => TransactionTaxDetail
|
19
|
+
|
20
|
+
# Readonly
|
21
|
+
xml_accessor :currency_ref, :from => 'CurrencyRef', :as => BaseReference
|
22
|
+
xml_accessor :total, :from => 'TotalAmt', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
23
|
+
xml_accessor :home_total, :from => 'HomeTotalAmt', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
24
|
+
|
25
|
+
#== This adds aliases for backwards compatability to old attributes names
|
26
|
+
alias_method :total_amount, :total
|
27
|
+
alias_method :total_amount=, :total=
|
28
|
+
|
29
|
+
xml_accessor :adjustment?, :from => 'Adjustment'
|
30
|
+
|
31
|
+
reference_setters :currency_ref
|
32
|
+
|
33
|
+
validates_length_of :private_note, :maximum => 4000
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class JournalEntryLineDetail < BaseModel
|
4
|
+
include NameEntity::Quality
|
5
|
+
|
6
|
+
xml_accessor :posting_type, :from => 'PostingType'
|
7
|
+
xml_accessor :entity, :from => 'Entity', :as => Entity
|
8
|
+
xml_accessor :account_ref, :from => 'AccountRef', :as => BaseReference
|
9
|
+
xml_accessor :class_ref, :from => 'ClassRef', :as => BaseReference
|
10
|
+
xml_accessor :department_ref, :from => 'DepartmentRef', :as => BaseReference
|
11
|
+
|
12
|
+
xml_accessor :tax_code_ref, :from => 'TaxCodeRef', :as => BaseReference
|
13
|
+
xml_accessor :tax_applicable_on, :from => 'TaxApplicableOn', :as => :text
|
14
|
+
xml_accessor :tax_amount, :from => 'TaxAmount', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
15
|
+
|
16
|
+
xml_accessor :billable_status, :from => 'BillableStatus'
|
17
|
+
|
18
|
+
reference_setters :account_ref, :class_ref, :department_ref, :tax_code_ref
|
19
|
+
|
20
|
+
validates_length_of :description, :maximum => 4000
|
21
|
+
validates_numericality_of :tax_amount, allow_nil: true, greater_than_or_equal_to:0.0, less_than_or_equal_to:999999999.0
|
22
|
+
validate :posting_type_is_valid
|
23
|
+
validate :billable_status_is_valid
|
24
|
+
validate :journal_line_entry_tax
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class Line < BaseModel
|
4
|
+
#== Constants
|
5
|
+
SALES_ITEM_LINE_DETAIL = 'SalesItemLineDetail'
|
6
|
+
SUB_TOTAL_LINE_DETAIL = 'SubTotalLineDetail'
|
7
|
+
PAYMENT_LINE_DETAIL = 'PaymentLineDetail'
|
8
|
+
DISCOUNT_LINE_DETAIL = 'DiscountLineDetail'
|
9
|
+
JOURNAL_ENTRY_LINE_DETAIL = 'JournalEntryLineDetail'
|
10
|
+
|
11
|
+
xml_accessor :id, :from => 'Id'
|
12
|
+
xml_accessor :line_num, :from => 'LineNum', :as => Integer
|
13
|
+
xml_accessor :description, :from => 'Description'
|
14
|
+
xml_accessor :amount, :from => 'Amount', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
15
|
+
xml_accessor :detail_type, :from => 'DetailType'
|
16
|
+
xml_accessor :linked_transactions, :from => 'LinkedTxn', :as => [LinkedTransaction]
|
17
|
+
xml_accessor :line_extras, :from => 'LineEx', :as => LineEx
|
18
|
+
|
19
|
+
#== Various detail types
|
20
|
+
xml_accessor :sales_item_line_detail, :from => 'SalesItemLineDetail', :as => SalesItemLineDetail
|
21
|
+
xml_accessor :sub_total_line_detail, :from => 'SubTotalLineDetail', :as => SubTotalLineDetail
|
22
|
+
xml_accessor :payment_line_detail, :from => 'PaymentLineDetail', :as => PaymentLineDetail
|
23
|
+
xml_accessor :discount_line_detail, :from => 'DiscountLineDetail', :as => DiscountOverride
|
24
|
+
xml_accessor :journal_entry_line_detail, :from => 'JournalEntryLineDetail', :as => JournalEntryLineDetail
|
25
|
+
|
26
|
+
def initialize(*args)
|
27
|
+
self.linked_transactions ||= []
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
31
|
+
def invoice_id=(id)
|
32
|
+
update_linked_transactions([id], 'Invoice')
|
33
|
+
end
|
34
|
+
alias_method :invoice_ids=, :invoice_id=
|
35
|
+
|
36
|
+
def credit_memo_id=(id)
|
37
|
+
update_linked_transactions([id], 'CreditMemo')
|
38
|
+
end
|
39
|
+
alias_method :credit_memo_ids=, :credit_memo_id=
|
40
|
+
|
41
|
+
def sales_item!
|
42
|
+
self.detail_type = SALES_ITEM_LINE_DETAIL
|
43
|
+
self.sales_item_line_detail = SalesItemLineDetail.new
|
44
|
+
|
45
|
+
yield self.sales_item_line_detail if block_given?
|
46
|
+
end
|
47
|
+
|
48
|
+
def sub_total!
|
49
|
+
self.detail_type = SUB_TOTAL_LINE_DETAIL
|
50
|
+
self.sub_total_line_detail = SubTotalLineDetail.new
|
51
|
+
|
52
|
+
yield self.sub_total_line_detail if block_given?
|
53
|
+
end
|
54
|
+
|
55
|
+
def payment!
|
56
|
+
self.detail_type = PAYMENT_LINE_DETAIL
|
57
|
+
self.payment_line_detail = PaymentLineDetail.new
|
58
|
+
|
59
|
+
yield self.payment_line_detail if block_given?
|
60
|
+
end
|
61
|
+
|
62
|
+
def discount!
|
63
|
+
self.detail_type = DISCOUNT_LINE_DETAIL
|
64
|
+
self.discount_line_detail = DiscountLineDetail.new
|
65
|
+
|
66
|
+
yield self.discount_line_detail if block_given?
|
67
|
+
end
|
68
|
+
|
69
|
+
def journal_entry!
|
70
|
+
self.detail_type = JOURNAL_ENTRY_LINE_DETAIL
|
71
|
+
self.journal_entry_line_detail = JournalEntryLineDetail.new
|
72
|
+
|
73
|
+
yield self.journal_entry_line_detail if block_given?
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def update_linked_transactions(txn_ids, txn_type)
|
79
|
+
remove_linked_transactions(txn_type)
|
80
|
+
txn_ids.flatten.compact.each do |id|
|
81
|
+
add_linked_transaction(id, txn_type)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def remove_linked_transactions(txn_type)
|
86
|
+
self.linked_transactions.delete_if { |lt| lt.txn_type == txn_type }
|
87
|
+
end
|
88
|
+
|
89
|
+
def add_linked_transaction(txn_id, txn_type)
|
90
|
+
self.linked_transactions << LinkedTransaction.new(txn_id: txn_id,
|
91
|
+
txn_type: txn_type)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class MarkupInfo < BaseModel
|
4
|
+
xml_accessor :percent_based, :from => 'PercentBased'
|
5
|
+
xml_accessor :value, :from => 'Value', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
6
|
+
xml_accessor :percent, :from => 'Percent', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
7
|
+
xml_accessor :price_level_ref, :from => 'PriceLevelRef', :as => BaseReference
|
8
|
+
|
9
|
+
reference_setters :price_level_ref
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module Quickbooks
|
4
|
+
module Model
|
5
|
+
class MetaData < BaseModel
|
6
|
+
xml_accessor :create_time, :from => 'CreateTime', :as => Time
|
7
|
+
xml_accessor :last_updated_time, :from => 'LastUpdatedTime', :as => Time
|
8
|
+
|
9
|
+
def to_xml(options = {})
|
10
|
+
xml = %Q{<MetaData>}
|
11
|
+
xml = "#{xml}<CreateTime>#{formatted_date(create_time)}</CreateTime>"
|
12
|
+
xml = "#{xml}<LastUpdatedTime>#{formatted_date(last_updated_time)}</LastUpdatedTime></MetaData>"
|
13
|
+
xml
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def formatted_date(datetime)
|
19
|
+
datetime.strftime('%Y-%m-%dT%H:%M:%S%z')
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class Payment < BaseModel
|
4
|
+
include HasLineItems
|
5
|
+
|
6
|
+
XML_COLLECTION_NODE = "Payment"
|
7
|
+
XML_NODE = "Payment"
|
8
|
+
REST_RESOURCE = 'payment'
|
9
|
+
|
10
|
+
xml_accessor :id, :from => 'Id'
|
11
|
+
xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
|
12
|
+
xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
|
13
|
+
xml_accessor :txn_date, :from => 'TxnDate', :as => Date
|
14
|
+
xml_accessor :private_note, :from => 'PrivateNote'
|
15
|
+
xml_accessor :txn_status, :from => 'TxnStatus'
|
16
|
+
xml_accessor :line_items, :from => 'Line', :as => [Line]
|
17
|
+
xml_accessor :customer_ref, :from => 'CustomerRef', :as => BaseReference
|
18
|
+
xml_accessor :ar_account_ref, :from => 'ARAccountRef', :as => BaseReference
|
19
|
+
xml_accessor :deposit_to_account_ref, :from => 'DepositToAccountRef', :as => BaseReference
|
20
|
+
xml_accessor :payment_method_ref, :from => 'PaymentMethodRef', :as => BaseReference
|
21
|
+
xml_accessor :payment_ref_number, :from => 'PaymentRefNum'
|
22
|
+
xml_accessor :credit_card_payment, :from => 'CreditCardPayment', :as => CreditCardPayment
|
23
|
+
xml_accessor :total, :from => 'TotalAmt', :as => BigDecimal, :to_xml => :to_f.to_proc
|
24
|
+
xml_accessor :unapplied_amount, :from => 'UnappliedAmt', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
25
|
+
xml_accessor :process_payment, :from => 'ProcessPayment'
|
26
|
+
xml_accessor :currency_ref, :from => 'CurrencyRef', :as => BaseReference
|
27
|
+
xml_accessor :exchange_rate, :from => 'ExchangeRate', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
28
|
+
|
29
|
+
reference_setters :customer_ref, :ar_account_ref
|
30
|
+
reference_setters :payment_method_ref, :deposit_to_account_ref, :currency_ref
|
31
|
+
|
32
|
+
validate :existence_of_customer_ref
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def existence_of_customer_ref
|
37
|
+
if customer_ref.nil? || (customer_ref && customer_ref.value == 0)
|
38
|
+
errors.add(:customer_ref, "CustomerRef is required and must be a non-zero value.")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class PaymentLineDetail < BaseModel
|
4
|
+
xml_accessor :item_ref, :from => 'ItemRef', :as => BaseReference
|
5
|
+
xml_accessor :class_ref, :from => 'ClassRef', :as => BaseReference
|
6
|
+
xml_accessor :balance, :from => 'Balance', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
7
|
+
xml_accessor :discount, :from => 'Discount', :as => DiscountOverride
|
8
|
+
|
9
|
+
reference_setters :item_ref, :class_ref
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class PaymentMethod < BaseModel
|
4
|
+
REST_RESOURCE = 'paymentmethod'
|
5
|
+
XML_COLLECTION_NODE = "PaymentMethod"
|
6
|
+
XML_NODE = "PaymentMethod"
|
7
|
+
include NameEntity::PermitAlterations
|
8
|
+
|
9
|
+
CREDIT_CARD = "CREDIT_CARD"
|
10
|
+
NON_CREDIT_CARD = "NON_CREDIT_CARD"
|
11
|
+
|
12
|
+
PAYMENT_METHOD_TYPES = [CREDIT_CARD, NON_CREDIT_CARD]
|
13
|
+
|
14
|
+
xml_accessor :id, :from => 'Id'
|
15
|
+
xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
|
16
|
+
xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
|
17
|
+
xml_accessor :name, :from => 'Name'
|
18
|
+
xml_accessor :type, :from => 'Type'
|
19
|
+
xml_accessor :active?, :from => 'Active'
|
20
|
+
xml_accessor :amount, :from => 'Amount', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
21
|
+
|
22
|
+
validates_inclusion_of :type, :in => PAYMENT_METHOD_TYPES, :allow_nil => true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class PhysicalAddress < BaseModel
|
4
|
+
xml_accessor :id, :from => 'Id'
|
5
|
+
xml_accessor :line1, :from => 'Line1'
|
6
|
+
xml_accessor :line2, :from => 'Line2'
|
7
|
+
xml_accessor :line3, :from => 'Line3'
|
8
|
+
xml_accessor :line4, :from => 'Line4'
|
9
|
+
xml_accessor :line5, :from => 'Line5'
|
10
|
+
xml_accessor :city, :from => 'City'
|
11
|
+
xml_accessor :country, :from => 'Country'
|
12
|
+
xml_accessor :country_sub_division_code, :from => 'CountrySubDivisionCode'
|
13
|
+
xml_accessor :postal_code, :from => 'PostalCode'
|
14
|
+
xml_accessor :note, :from => 'Note'
|
15
|
+
xml_accessor :lat, :from => 'Lat'
|
16
|
+
xml_accessor :lon, :from => 'Long'
|
17
|
+
|
18
|
+
def zip
|
19
|
+
postal_code
|
20
|
+
end
|
21
|
+
|
22
|
+
def lat_to_f
|
23
|
+
BigDecimal.new(lat)
|
24
|
+
end
|
25
|
+
|
26
|
+
def lon_to_f
|
27
|
+
BigDecimal.new(lon)
|
28
|
+
end
|
29
|
+
|
30
|
+
def have_lat?
|
31
|
+
lat.to_s != "INVALID"
|
32
|
+
end
|
33
|
+
|
34
|
+
def have_lon?
|
35
|
+
lon.to_s != "INVALID"
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class Preferences < BaseModel
|
4
|
+
XML_COLLECTION_NODE = "Preferences"
|
5
|
+
XML_NODE = "Preferences"
|
6
|
+
REST_RESOURCE = 'preferences'
|
7
|
+
|
8
|
+
xml_name XML_NODE
|
9
|
+
|
10
|
+
def self.create_preference_class(*attrs, &block)
|
11
|
+
::Class.new(BaseModel) do
|
12
|
+
attrs.each do |a|
|
13
|
+
xml_reader(a.underscore, :from => a.gsub("?", ""))
|
14
|
+
end
|
15
|
+
instance_eval(&block) if block_given?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
PREFERENCE_SECTIONS = {
|
20
|
+
:accounting_info => %w(TrackDepartments DepartmentTerminology ClassTrackingPerTxnLine? ClassTrackingPerTxn? CustomerTerminology),
|
21
|
+
:product_and_services => %w(ForSales? ForPurchase? QuantityWithPriceAndRate? QuantityOnHand?),
|
22
|
+
:sales_forms => %w(CustomTxnNumbers? AllowDeposit? AllowDiscount? DefaultDiscountAccount? AllowEstimates? EstimateMessage?
|
23
|
+
ETransactionEnabledStatus? ETransactionAttachPDF? ETransactionPaymentEnabled? IPNSupportEnabled?
|
24
|
+
AllowServiceDate? AllowShipping? DefaultShippingAccount? DefaultTerms DefaultCustomerMessage),
|
25
|
+
:vendor_and_purchase => %w(TrackingByCustomer? BillableExpenseTracking? DefaultTerms? DefaultMarkup? POCustomField),
|
26
|
+
:time_tracking => %w(UseServices? BillCustomers? ShowBillRateToAll WorkWeekStartDate MarkTimeEntiresBillable?),
|
27
|
+
:tax => %w(UsingSalesTax?),
|
28
|
+
:currency => %w(MultiCurrencyEnabled? HomeCurrency),
|
29
|
+
:report => %w(ReportBasis)
|
30
|
+
}
|
31
|
+
|
32
|
+
PREFERENCE_SECTIONS.each do |section_name, fields|
|
33
|
+
xml_reader section_name, :from => "#{section_name}_prefs".camelize, :as => create_preference_class(*fields)
|
34
|
+
end
|
35
|
+
|
36
|
+
EmailMessage = create_preference_class("Subject", "Message")
|
37
|
+
EmailMessageContainer = create_preference_class do
|
38
|
+
%w(InvoiceMessage EstimateMessage SalesReceiptMessage StatementMessage).each do |msg|
|
39
|
+
xml_reader msg.underscore, :from => msg, :as => EmailMessage
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
xml_reader :email_messages, :from => "EmailMessagesPrefs", as: EmailMessageContainer
|
44
|
+
|
45
|
+
xml_reader :other_prefs, :from => "OtherPrefs/NameValue", :as => { :key => "Name", :value => "Value" }
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# == General
|
2
|
+
# This entity represents expenses, such as a purchase made from a vendor.
|
3
|
+
# There are three types of Purchases: Cash, Check, and Credit Card.
|
4
|
+
# * Cash Purchase contains information regarding a payment made in cash.
|
5
|
+
# * Check Purchase contains information regarding a payment made by check.
|
6
|
+
# * Credit Card Purchase contains information regarding a payment made by credit card.
|
7
|
+
#
|
8
|
+
# == Business Rules
|
9
|
+
# * You must specify an AccountRef for all puchases.
|
10
|
+
# * TotalAmt attribute must add up to sum of Line.Amount attributes
|
11
|
+
|
12
|
+
module Quickbooks
|
13
|
+
module Model
|
14
|
+
class Purchase < BaseModel
|
15
|
+
include GlobalTaxCalculation
|
16
|
+
include HasLineItems
|
17
|
+
|
18
|
+
#== Constants
|
19
|
+
REST_RESOURCE = 'purchase'
|
20
|
+
XML_COLLECTION_NODE = "Purchase"
|
21
|
+
XML_NODE = "Purchase"
|
22
|
+
|
23
|
+
xml_accessor :id, :from => 'Id'
|
24
|
+
xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
|
25
|
+
xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
|
26
|
+
xml_accessor :doc_number, :from => 'DocNumber'
|
27
|
+
xml_accessor :txn_date, :from => 'TxnDate', :as => Date
|
28
|
+
xml_accessor :private_note, :from => 'PrivateNote'
|
29
|
+
|
30
|
+
xml_accessor :line_items, :from => 'Line', :as => [PurchaseLineItem]
|
31
|
+
xml_accessor :account_ref, :from => 'AccountRef', :as => BaseReference
|
32
|
+
xml_accessor :txn_tax_detail, :from => 'TxnTaxDetail', :as => TransactionTaxDetail
|
33
|
+
|
34
|
+
xml_accessor :payment_type, :from => 'PaymentType'
|
35
|
+
xml_accessor :entity_ref, :from => 'EntityRef', :as => BaseReference
|
36
|
+
xml_accessor :remit_to_address, :from => 'RemitToAddr', :as => PhysicalAddress
|
37
|
+
xml_accessor :total, :from => 'TotalAmt', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
38
|
+
xml_accessor :print_status, :from => 'PrintStatus'
|
39
|
+
xml_accessor :department_ref, :from => 'DepartmentRef', :as => BaseReference
|
40
|
+
|
41
|
+
xml_accessor :currency_ref, :from => 'CurrencyRef', :as => BaseReference
|
42
|
+
xml_accessor :exchange_rate, :from => 'ExchangeRate', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
43
|
+
xml_accessor :linked_transactions, :from => 'LinkedTxn', :as => [LinkedTransaction]
|
44
|
+
xml_accessor :credit?, :from => 'Credit'
|
45
|
+
|
46
|
+
reference_setters
|
47
|
+
|
48
|
+
#== Validations
|
49
|
+
validate :line_item_size
|
50
|
+
|
51
|
+
#== This adds aliases for backwards compatability to old attributes names
|
52
|
+
alias_method :total_amount, :total
|
53
|
+
alias_method :total_amount=, :total=
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class PurchaseLineItem < BaseModel
|
4
|
+
|
5
|
+
#== Constants
|
6
|
+
ITEM_BASED_EXPENSE_LINE_DETAIL = 'ItemBasedExpenseLineDetail'
|
7
|
+
ACCOUNT_BASED_EXPENSE_LINE_DETAIL = 'AccountBasedExpenseLineDetail'
|
8
|
+
GROUP_LINE_DETAIL = 'GroupLineDetail'
|
9
|
+
|
10
|
+
xml_accessor :id, :from => 'Id'
|
11
|
+
xml_accessor :line_num, :from => 'LineNum', :as => Integer
|
12
|
+
xml_accessor :description, :from => 'Description'
|
13
|
+
xml_accessor :amount, :from => 'Amount', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
|
14
|
+
xml_accessor :detail_type, :from => 'DetailType'
|
15
|
+
|
16
|
+
#== Various detail types
|
17
|
+
xml_accessor :account_based_expense_line_detail, :from => ACCOUNT_BASED_EXPENSE_LINE_DETAIL, :as => AccountBasedExpenseLineDetail
|
18
|
+
xml_accessor :item_based_expense_line_detail, :from => ITEM_BASED_EXPENSE_LINE_DETAIL, :as => ItemBasedExpenseLineDetail
|
19
|
+
xml_accessor :group_line_detail, :from => GROUP_LINE_DETAIL, :as => GroupLineDetail
|
20
|
+
|
21
|
+
def account_based?
|
22
|
+
detail_type.to_s == ACCOUNT_BASED_EXPENSE_LINE_DETAIL
|
23
|
+
end
|
24
|
+
|
25
|
+
def item_based?
|
26
|
+
detail_type.to_s == ITEM_BASED_EXPENSE_LINE_DETAIL
|
27
|
+
end
|
28
|
+
|
29
|
+
def account_based_expense!
|
30
|
+
self.detail_type = ACCOUNT_BASED_EXPENSE_LINE_DETAIL
|
31
|
+
self.account_based_expense_line_detail = AccountBasedExpenseLineDetail.new
|
32
|
+
|
33
|
+
yield self.account_based_expense_line_detail if block_given?
|
34
|
+
end
|
35
|
+
|
36
|
+
def item_based_expense!
|
37
|
+
self.detail_type = ITEM_BASED_EXPENSE_LINE_DETAIL
|
38
|
+
self.item_based_expense_line_detail = ItemBasedExpenseLineDetail.new
|
39
|
+
|
40
|
+
yield self.item_based_expense_line_detail if block_given?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class PurchaseOrder < BaseModel
|
4
|
+
include GlobalTaxCalculation
|
5
|
+
include HasLineItems
|
6
|
+
|
7
|
+
#== Constants
|
8
|
+
REST_RESOURCE = 'purchaseorder'
|
9
|
+
XML_COLLECTION_NODE = "PurchaseOrder"
|
10
|
+
XML_NODE = "PurchaseOrder"
|
11
|
+
|
12
|
+
xml_accessor :id, :from => 'Id'
|
13
|
+
xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
|
14
|
+
xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
|
15
|
+
xml_accessor :doc_number, :from => 'DocNumber'
|
16
|
+
xml_accessor :txn_date, :from => 'TxnDate', :as => Date
|
17
|
+
xml_accessor :custom_fields, :from => 'CustomField', :as => [CustomField]
|
18
|
+
xml_accessor :private_note, :from => 'PrivateNote'
|
19
|
+
xml_accessor :memo, :from => 'Memo'
|
20
|
+
|
21
|
+
xml_accessor :linked_transactions, :from => 'LinkedTxn', :as => [LinkedTransaction]
|
22
|
+
xml_accessor :line_items, :from => 'Line', :as => [PurchaseLineItem]
|
23
|
+
|
24
|
+
xml_accessor :attachable_ref, :from => 'AttachableRef', :as => BaseReference
|
25
|
+
xml_accessor :vendor_ref, :from => 'VendorRef', :as => BaseReference
|
26
|
+
xml_accessor :ap_account_ref, :from => 'APAccountRef', :as => BaseReference
|
27
|
+
xml_accessor :class_ref, :from => 'ClassRef', :as => BaseReference
|
28
|
+
xml_accessor :sales_term_ref, :from => 'SalesTermRef', :as => BaseReference
|
29
|
+
|
30
|
+
xml_accessor :total, :from => 'TotalAmt', :as => BigDecimal, :to_xml => Proc.new { |val| val.to_f }
|
31
|
+
xml_accessor :due_date, :from => 'DueDate', :as => Date
|
32
|
+
xml_accessor :vendor_address, :from => 'VendorAddr', :as => PhysicalAddress
|
33
|
+
xml_accessor :ship_address, :from => 'ShipAddr', :as => PhysicalAddress
|
34
|
+
xml_accessor :ship_method_ref, :from => 'ShipMethodRef', :as => BaseReference
|
35
|
+
xml_accessor :po_status, :from => 'POStatus'
|
36
|
+
xml_accessor :txn_tax_detail, :from => 'TxnTaxDetail', :as => TransactionTaxDetail
|
37
|
+
|
38
|
+
xml_accessor :currency_ref, :from => 'CurrencyRef', :as => BaseReference
|
39
|
+
xml_accessor :exchange_rate, :from => 'ExchangeRate', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
40
|
+
xml_accessor :tax_code_ref, :from => 'TaxCodeRef', :as => BaseReference
|
41
|
+
|
42
|
+
reference_setters
|
43
|
+
|
44
|
+
#== This adds aliases for backwards compatability to old attributes names
|
45
|
+
alias_method :total_amount, :total
|
46
|
+
alias_method :total_amount=, :total=
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class PurchaseTaxRateList < BaseModel
|
4
|
+
XML_COLLECTION_NODE = "PurchaseTaxRateList"
|
5
|
+
XML_NODE = "PurchaseTaxRateList"
|
6
|
+
REST_RESOURCE = "purchasetaxratelist"
|
7
|
+
|
8
|
+
xml_accessor :tax_rate_detail, :from => "TaxRateDetail", :as => [TaxRateDetail]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
module Model
|
3
|
+
class RefundReceipt < BaseModel
|
4
|
+
include GlobalTaxCalculation
|
5
|
+
include HasLineItems
|
6
|
+
|
7
|
+
XML_COLLECTION_NODE = "RefundReceipt"
|
8
|
+
XML_NODE = "RefundReceipt"
|
9
|
+
REST_RESOURCE = 'refundreceipt'
|
10
|
+
|
11
|
+
xml_accessor :id, :from => 'Id'
|
12
|
+
xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
|
13
|
+
xml_accessor :meta_data, :from => 'MetaData', :as => MetaData
|
14
|
+
xml_accessor :auto_doc_number, :from => 'AutoDocNumber' # See auto_doc_number! method below for usage
|
15
|
+
xml_accessor :doc_number, :from => 'DocNumber'
|
16
|
+
xml_accessor :line_items, :from => 'Line', :as => [Line]
|
17
|
+
xml_accessor :customer_ref, :from => 'CustomerRef', :as => BaseReference
|
18
|
+
xml_accessor :department_ref, :from => 'DepartmentRef', :as => BaseReference
|
19
|
+
xml_accessor :bill_email, :from => 'BillEmail', :as => EmailAddress
|
20
|
+
xml_accessor :bill_address, :from => 'BillAddr', :as => PhysicalAddress
|
21
|
+
xml_accessor :ship_address, :from => 'ShipAddr', :as => PhysicalAddress
|
22
|
+
xml_accessor :po_number, :from => 'PONumber'
|
23
|
+
xml_accessor :ship_method_ref, :from => 'ShipMethodRef'
|
24
|
+
xml_accessor :ship_date, :from => 'ShipDate', :as => Time
|
25
|
+
xml_accessor :tracking_num, :from => 'TrackingNum'
|
26
|
+
xml_accessor :payment_method_ref, :from => 'PaymentMethodRef', :as => BaseReference
|
27
|
+
xml_accessor :payment_ref_number, :from => 'PaymentRefNum'
|
28
|
+
xml_accessor :deposit_to_account_ref, :from => 'DepositToAccountRef', :as => BaseReference
|
29
|
+
xml_accessor :customer_memo, :from => 'CustomerMemo'
|
30
|
+
xml_accessor :private_note, :from => 'PrivateNote'
|
31
|
+
xml_accessor :txn_tax_detail, :from => 'TxnTaxDetail', :as => TransactionTaxDetail
|
32
|
+
xml_accessor :txn_date, :from => 'TxnDate', :as => Date
|
33
|
+
xml_accessor :custom_fields, :from => 'CustomField', :as => [CustomField]
|
34
|
+
xml_accessor :currency_ref, :from => 'CurrencyRef', :as => BaseReference
|
35
|
+
xml_accessor :class_ref, :from => 'ClassRef', :as => BaseReference
|
36
|
+
xml_accessor :apply_tax_after_discount?, :from => 'ApplyTaxAfterDiscount'
|
37
|
+
xml_accessor :print_status, :from => 'PrintStatus'
|
38
|
+
xml_accessor :balance, :from => 'Balance', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
39
|
+
|
40
|
+
xml_accessor :exchange_rate, :from => 'ExchangeRate', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
41
|
+
xml_accessor :linked_transactions, :from => 'LinkedTxn', :as => [LinkedTransaction]
|
42
|
+
|
43
|
+
# readonly
|
44
|
+
xml_accessor :total, :from => 'TotalAmt', :as => BigDecimal
|
45
|
+
xml_accessor :home_total, :from => 'HomeTotalAmt', :as => BigDecimal, :to_xml => to_xml_big_decimal
|
46
|
+
|
47
|
+
# backward-compatible alias
|
48
|
+
alias_attribute :placed_on, :txn_date
|
49
|
+
|
50
|
+
include DocumentNumbering
|
51
|
+
reference_setters
|
52
|
+
|
53
|
+
validate :line_item_size
|
54
|
+
validate :document_numbering
|
55
|
+
|
56
|
+
def email=(email)
|
57
|
+
self.bill_email = EmailAddress.new(email)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|