invoicexpress 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +0 -0
- data/README.md +322 -0
- data/Rakefile +19 -0
- data/invoicexpress.gemspec +26 -0
- data/lib/faraday/response/parse_xml.rb +23 -0
- data/lib/faraday/response/raise_invoicexpress_errors.rb +20 -0
- data/lib/invoicexpress.rb +26 -0
- data/lib/invoicexpress/authentication.rb +15 -0
- data/lib/invoicexpress/client.rb +56 -0
- data/lib/invoicexpress/client/cash_invoices.rb +110 -0
- data/lib/invoicexpress/client/charts.rb +57 -0
- data/lib/invoicexpress/client/clients.rb +215 -0
- data/lib/invoicexpress/client/credit_notes.rb +128 -0
- data/lib/invoicexpress/client/debit_notes.rb +129 -0
- data/lib/invoicexpress/client/invoices.rb +107 -0
- data/lib/invoicexpress/client/items.rb +82 -0
- data/lib/invoicexpress/client/purchase_orders.rb +126 -0
- data/lib/invoicexpress/client/schedules.rb +110 -0
- data/lib/invoicexpress/client/sequences.rb +71 -0
- data/lib/invoicexpress/client/simplified_invoices.rb +130 -0
- data/lib/invoicexpress/client/taxes.rb +82 -0
- data/lib/invoicexpress/client/users.rb +48 -0
- data/lib/invoicexpress/configuration.rb +51 -0
- data/lib/invoicexpress/connection.rb +40 -0
- data/lib/invoicexpress/error.rb +68 -0
- data/lib/invoicexpress/models.rb +29 -0
- data/lib/invoicexpress/models/chart.rb +41 -0
- data/lib/invoicexpress/models/client.rb +24 -0
- data/lib/invoicexpress/models/filter.rb +60 -0
- data/lib/invoicexpress/models/invoice.rb +235 -0
- data/lib/invoicexpress/models/purchase_order.rb +72 -0
- data/lib/invoicexpress/models/quarterly_result.rb +45 -0
- data/lib/invoicexpress/models/schedule.rb +87 -0
- data/lib/invoicexpress/models/sequence.rb +17 -0
- data/lib/invoicexpress/models/supplier.rb +17 -0
- data/lib/invoicexpress/models/top_client.rb +15 -0
- data/lib/invoicexpress/models/top_debtor.rb +14 -0
- data/lib/invoicexpress/models/user.rb +31 -0
- data/lib/invoicexpress/request.rb +63 -0
- data/lib/invoicexpress/version.rb +3 -0
- data/spec/fixtures/charts.invoicing.xml +21 -0
- data/spec/fixtures/charts.quarterly-results.xml +25 -0
- data/spec/fixtures/charts.top-clients.xml +10 -0
- data/spec/fixtures/charts.top-debtors.xml +10 -0
- data/spec/fixtures/charts.treasury.xml +49 -0
- data/spec/fixtures/clients.create.xml +6 -0
- data/spec/fixtures/clients.get.xml +21 -0
- data/spec/fixtures/clients.invoices.xml +11 -0
- data/spec/fixtures/clients.list.xml +18 -0
- data/spec/fixtures/clients.update.xml +1 -0
- data/spec/fixtures/credit_notes.create.xml +53 -0
- data/spec/fixtures/credit_notes.email_document.xml +9 -0
- data/spec/fixtures/credit_notes.list.xml +114 -0
- data/spec/fixtures/credit_notes.update_state.xml +7 -0
- data/spec/fixtures/invoices.create.xml +37 -0
- data/spec/fixtures/invoices.get.xml +50 -0
- data/spec/fixtures/invoices.list.xml +537 -0
- data/spec/fixtures/invoices.update_state.xml +7 -0
- data/spec/fixtures/ok.xml +0 -0
- data/spec/fixtures/po.create.xml +42 -0
- data/spec/fixtures/po.email_document.xml +0 -0
- data/spec/fixtures/po.get.xml +42 -0
- data/spec/fixtures/po.list.xml +44 -0
- data/spec/fixtures/po.update_state.xml +7 -0
- data/spec/fixtures/schedules.create.xml +48 -0
- data/spec/fixtures/schedules.get.xml +57 -0
- data/spec/fixtures/schedules.list.xml +40 -0
- data/spec/fixtures/sequences.create.xml +9 -0
- data/spec/fixtures/sequences.get.xml +10 -0
- data/spec/fixtures/sequences.list.xml +12 -0
- data/spec/fixtures/sequences.update.xml +10 -0
- data/spec/fixtures/simplified_invoices.create.xml +53 -0
- data/spec/fixtures/simplified_invoices.email_document.xml +9 -0
- data/spec/fixtures/simplified_invoices.get.xml +74 -0
- data/spec/fixtures/simplified_invoices.list.xml +114 -0
- data/spec/fixtures/simplified_invoices.update.xml +0 -0
- data/spec/fixtures/simplified_invoices.update_state.xml +7 -0
- data/spec/fixtures/taxes.create.xml +7 -0
- data/spec/fixtures/taxes.list.xml +18 -0
- data/spec/fixtures/taxes.update.xml +7 -0
- data/spec/fixtures/users.accounts.xml +12 -0
- data/spec/fixtures/users.change-account.xml +0 -0
- data/spec/fixtures/users.login.xml +11 -0
- data/spec/helper.rb +62 -0
- data/spec/invoicexpress/client/charts_spec.rb +69 -0
- data/spec/invoicexpress/client/clients_spec.rb +108 -0
- data/spec/invoicexpress/client/credit_notes_spec.rb +104 -0
- data/spec/invoicexpress/client/invoices_spec.rb +110 -0
- data/spec/invoicexpress/client/purchase_orders_spec.rb +116 -0
- data/spec/invoicexpress/client/schedules_spec.rb +111 -0
- data/spec/invoicexpress/client/sequences_spec.rb +68 -0
- data/spec/invoicexpress/client/simplified_invoices_spec.rb +116 -0
- data/spec/invoicexpress/client/taxes_spec.rb +70 -0
- data/spec/invoicexpress/client/users_spec.rb +40 -0
- data/spec/invoicexpress/client_spec.rb +24 -0
- data/spec/invoicexpress_spec.rb +19 -0
- metadata +279 -0
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'invoicexpress/models'
|
2
|
+
|
3
|
+
module Invoicexpress
|
4
|
+
class Client
|
5
|
+
module DebitNotes
|
6
|
+
|
7
|
+
# Returns all your debit notes
|
8
|
+
#
|
9
|
+
# @option options [Integer] page (1) You can ask a specific page of debit notes
|
10
|
+
#
|
11
|
+
# @return [Invoicexpress::Models::DebitNotes] A struct with results (pagination) and all the debit notes
|
12
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
13
|
+
def debit_notes(options={})
|
14
|
+
params = { :page => 1, :klass => Invoicexpress::Models::DebitNote }
|
15
|
+
|
16
|
+
get("debit_notes.xml", params.merge(options))
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns all the information about a debit note:
|
20
|
+
# - Basic information (date, status, sequence number)
|
21
|
+
# - Client
|
22
|
+
# - Document items
|
23
|
+
# - Document timeline
|
24
|
+
# Document timeline is composed by:
|
25
|
+
# - Date, time and the user who created it
|
26
|
+
# - Type of the event
|
27
|
+
# The complete list of timeline events is:
|
28
|
+
# - create
|
29
|
+
# - edited
|
30
|
+
# - send_email
|
31
|
+
# - canceled
|
32
|
+
# - deleted
|
33
|
+
# - settled
|
34
|
+
# - second_copy
|
35
|
+
# - archived
|
36
|
+
# - unarchived
|
37
|
+
# - comment
|
38
|
+
#
|
39
|
+
# @param debit_note_id [String] Requested debit note id
|
40
|
+
# @return [Invoicexpress::Models::DebitNote] The requested debit note
|
41
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
42
|
+
# @raise Invoicexpress::NotFound When the debit_note doesn't exist
|
43
|
+
def debit_note(debit_note_id, options={})
|
44
|
+
params = { :klass => Invoicexpress::Models::DebitNote }
|
45
|
+
|
46
|
+
get("debit_notes/#{debit_note_id}.xml", params.merge(options))
|
47
|
+
end
|
48
|
+
|
49
|
+
# Creates a new debit note. Also allows to create a new client and/or new items in the same request.
|
50
|
+
# If the client name does not exist a new one is created.
|
51
|
+
# If items do not exist with the given names, new ones will be created.
|
52
|
+
# If item name already exists, the item is updated with the new values.
|
53
|
+
# Regarding item taxes, if the tax name is not found, no tax is applyed to that item.
|
54
|
+
# Portuguese accounts should also send the IVA exemption reason if the invoice contains exempt items(IVA 0%)
|
55
|
+
#
|
56
|
+
# @param debit_note [Invoicexpress::Models::DebitNote] The debit note to create
|
57
|
+
# @return [Invoicexpress::Models::DebitNote] The created debit note
|
58
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
59
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
60
|
+
def create_debit_note(debit_note, options={})
|
61
|
+
raise(ArgumentError, "debit note has the wrong type") unless debit_note.is_a?(Invoicexpress::Models::DebitNote)
|
62
|
+
|
63
|
+
params = { :klass => Invoicexpress::Models::DebitNote, :body => debit_note }
|
64
|
+
post("debit_notes.xml", params.merge(options))
|
65
|
+
end
|
66
|
+
|
67
|
+
# Updates a debit note
|
68
|
+
# It also allows you to create a new client and/or items in the same request.
|
69
|
+
# If the client name does not exist a new client is created.
|
70
|
+
# Regarding item taxes, if the tax name is not found, no tax will be applied to that item.
|
71
|
+
# If item does not exist with the given name, a new one will be created.
|
72
|
+
# If item exists it will be updated with the new values
|
73
|
+
# Be careful when updating the document items, any missing items from the original document will be deleted.
|
74
|
+
#
|
75
|
+
# @param debit_note [Invoicexpress::Models::DebitNote] The cash debit note to update
|
76
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
77
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
78
|
+
# @raise Invoicexpress::NotFound When the debit note doesn't exist
|
79
|
+
def update_debit_note(debit_note, options={})
|
80
|
+
raise(ArgumentError, "debit note has the wrong type") unless debit_note.is_a?(Invoicexpress::Models::DebitNote)
|
81
|
+
|
82
|
+
if !debit_note.id
|
83
|
+
raise ArgumentError, "DebitNote ID is required"
|
84
|
+
end
|
85
|
+
params = { :klass => Invoicexpress::Models::DebitNote, :body => debit_note.to_core }
|
86
|
+
put("debit_notes/#{debit_note.id}.xml", params.merge(options))
|
87
|
+
end
|
88
|
+
|
89
|
+
# Changes the state of a debit note.
|
90
|
+
# Possible state transitions:
|
91
|
+
# - draft to final – finalized
|
92
|
+
# - draft to deleted – deleted
|
93
|
+
# - settled to final – unsettled
|
94
|
+
# - final to second copy – second_copy
|
95
|
+
# - final or second copy to canceled – canceled
|
96
|
+
# - final or second copy to settled – settled
|
97
|
+
# Any other transitions will fail.
|
98
|
+
# When canceling a debit note you must specify a reason.
|
99
|
+
#
|
100
|
+
# @param debit_note_id [String] The debit note id to change
|
101
|
+
# @param debit_note_state [Invoicexpress::Models::InvoiceState] The new state
|
102
|
+
# @return [Invoicexpress::Models::DebitNote] The updated debit note
|
103
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
104
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
105
|
+
# @raise Invoicexpress::NotFound When the debit note doesn't exist
|
106
|
+
def update_debit_note_state(debit_note_id, debit_note_state, options={})
|
107
|
+
raise(ArgumentError, "debit note state has the wrong type") unless debit_note_state.is_a?(Invoicexpress::Models::InvoiceState)
|
108
|
+
|
109
|
+
params = { :klass => Invoicexpress::Models::DebitNote, :body => debit_note_state }
|
110
|
+
put("debit_notes/#{debit_note_id}/change-state.xml", params.merge(options))
|
111
|
+
end
|
112
|
+
|
113
|
+
# Sends the debit note through email
|
114
|
+
#
|
115
|
+
# @param debit_note_id [String] The debit note id to send
|
116
|
+
# @param message [Invoicexpress::Models::Message] The message to send
|
117
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
118
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
119
|
+
# @raise Invoicexpress::NotFound When the debit note doesn't exist
|
120
|
+
def debit_note_mail(debit_note_id, message, options={})
|
121
|
+
raise(ArgumentError, "message has the wrong type") unless message.is_a?(Invoicexpress::Models::Message)
|
122
|
+
|
123
|
+
params = { :body => message, :klass => Invoicexpress::Models::DebitNote }
|
124
|
+
put("debit_notes/#{debit_note_id}/email-document.xml", params.merge(options))
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'invoicexpress/models'
|
2
|
+
|
3
|
+
module Invoicexpress
|
4
|
+
class Client
|
5
|
+
module Invoices
|
6
|
+
|
7
|
+
# Returns all your invoices
|
8
|
+
#
|
9
|
+
# @option options [Integer] page (1) You can ask a specific page of invoices
|
10
|
+
#
|
11
|
+
# @return [Array<Invoicexpress::Models::Invoice>] An array with all your invoices
|
12
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
13
|
+
def invoices(options={})
|
14
|
+
params = { :page => 1, :klass => Invoicexpress::Models::Invoices }
|
15
|
+
|
16
|
+
get("invoices.xml", params.merge(options))
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns a specific invoice
|
20
|
+
#
|
21
|
+
# @param invoice_id [String] Requested invoice id
|
22
|
+
# @return [Invoicexpress::Models::Invoice] The requested invoice
|
23
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
24
|
+
# @raise Invoicexpress::NotFound When the invoice doesn't exist
|
25
|
+
def invoice(invoice_id, options={})
|
26
|
+
params = { :klass => Invoicexpress::Models::Invoice }
|
27
|
+
|
28
|
+
get("invoices/#{invoice_id}.xml", params.merge(options))
|
29
|
+
end
|
30
|
+
|
31
|
+
# Creates a new invoice. Also allows to create a new client and/or new items in the same request.
|
32
|
+
# If the client name does not exist a new one is created.
|
33
|
+
# If items do not exist with the given names, new ones will be created.
|
34
|
+
# If item name already exists, the item is updated with the new values.
|
35
|
+
# Regarding item taxes, if the tax name is not found, no tax is applyed to that item.
|
36
|
+
# Portuguese accounts should also send the IVA exemption reason if the invoice contains exempt items(IVA 0%)
|
37
|
+
#
|
38
|
+
# @param invoice [Invoicexpress::Models::Invoice] The invoice to create
|
39
|
+
# @return [Invoicexpress::Models::Invoice] The created invoice
|
40
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
41
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
42
|
+
def create_invoice(invoice, options={})
|
43
|
+
raise(ArgumentError, "invoice has the wrong type") unless invoice.is_a?(Invoicexpress::Models::Invoice)
|
44
|
+
|
45
|
+
params = { :klass => Invoicexpress::Models::Invoice, :body => invoice }
|
46
|
+
post("invoices.xml", params.merge(options))
|
47
|
+
end
|
48
|
+
|
49
|
+
# Updates an invoice
|
50
|
+
# It also allows you to create a new client and/or items in the same request.
|
51
|
+
# If the client name does not exist a new client is created.
|
52
|
+
# Regarding item taxes, if the tax name is not found, no tax will be applied to that item.
|
53
|
+
# If item does not exist with the given name, a new one will be created.
|
54
|
+
# If item exists it will be updated with the new values
|
55
|
+
# Be careful when updating the document items, any missing items from the original document will be deleted.
|
56
|
+
#
|
57
|
+
# @param invoice [Invoicexpress::Models::Invoice] The invoice to update
|
58
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
59
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
60
|
+
# @raise Invoicexpress::NotFound When the invoice doesn't exist
|
61
|
+
def update_invoice(invoice, options={})
|
62
|
+
raise(ArgumentError, "invoice has the wrong type") unless invoice.is_a?(Invoicexpress::Models::Invoice)
|
63
|
+
|
64
|
+
params = { :klass => Invoicexpress::Models::Invoice, :body => invoice.to_core }
|
65
|
+
put("invoices/#{invoice.id}.xml", params.merge(options))
|
66
|
+
end
|
67
|
+
|
68
|
+
# Changes the state of an invoice.
|
69
|
+
# Possible state transitions:
|
70
|
+
# - draft to final – finalized
|
71
|
+
# - final to second copy – second_copy
|
72
|
+
# - final or second copy to canceled – canceled
|
73
|
+
# - final or second copy to settled – settled
|
74
|
+
# - settled to final – unsettled
|
75
|
+
# Any other transitions will fail.
|
76
|
+
# When canceling an invoice you must specify a reason.
|
77
|
+
#
|
78
|
+
# @param invoice_id [String] The invoice id to change
|
79
|
+
# @param invoice_state [Invoicexpress::Models::InvoiceState] The new state
|
80
|
+
# @return [Invoicexpress::Models::Invoice] The updated invoice
|
81
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
82
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
83
|
+
# @raise Invoicexpress::NotFound When the invoice doesn't exist
|
84
|
+
def update_invoice_state(invoice_id, invoice_state, options={})
|
85
|
+
raise(ArgumentError, "invoice_state has the wrong type") unless invoice_state.is_a?(Invoicexpress::Models::InvoiceState)
|
86
|
+
|
87
|
+
params = { :klass => Invoicexpress::Models::Invoice, :body => invoice_state }
|
88
|
+
put("invoices/#{invoice_id}/change-state.xml", params.merge(options))
|
89
|
+
end
|
90
|
+
|
91
|
+
# Sends the invoice by email
|
92
|
+
#
|
93
|
+
# @param invoice_id [String] The invoice id to change
|
94
|
+
# @param message [Invoicexpress::Models::Message] The message to send
|
95
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
96
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
97
|
+
# @raise Invoicexpress::NotFound When the invoice doesn't exist
|
98
|
+
def invoice_mail(invoice_id, message, options={})
|
99
|
+
raise(ArgumentError, "message has the wrong type") unless message.is_a?(Invoicexpress::Models::Message)
|
100
|
+
|
101
|
+
params = { :body => message, :klass => Invoicexpress::Models::Invoice }
|
102
|
+
put("invoices/#{invoice_id}/email-invoice.xml", params.merge(options))
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'invoicexpress/models'
|
2
|
+
|
3
|
+
module Invoicexpress
|
4
|
+
class Client
|
5
|
+
module Items
|
6
|
+
|
7
|
+
# Returns a list of all your items.
|
8
|
+
#
|
9
|
+
# @return [Array<Invoicexpress::Models::Item>] An array with all your items
|
10
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
11
|
+
def items(options = {})
|
12
|
+
params = { :klass => Invoicexpress::Models::Item }
|
13
|
+
|
14
|
+
get("items.xml", params.merge(options))
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns a specific item.
|
18
|
+
#
|
19
|
+
# @param item [Invoicexpress::Models::Item, String] The item or item ID
|
20
|
+
# @return [Invoicexpress::Models::Item] The item
|
21
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
22
|
+
# @raise Invoicexpress::NotFound When the item doesn't exist
|
23
|
+
def item(item, options={})
|
24
|
+
params = { :klass => Invoicexpress::Models::Item }
|
25
|
+
|
26
|
+
get("items/#{id_from_item(item)}.xml", params.merge(options))
|
27
|
+
end
|
28
|
+
|
29
|
+
# Creates a new item.
|
30
|
+
# Regarding item taxes, if the tax name is not found, no tax is applied to that item.
|
31
|
+
#
|
32
|
+
# @param item [Invoicexpress::Models::Item] The item to create
|
33
|
+
# @return [Invoicexpress::Models::Item] The created item
|
34
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
35
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
36
|
+
def create_item(item, options={})
|
37
|
+
raise(ArgumentError, "item has the wrong type") unless item.is_a?(Invoicexpress::Models::Item)
|
38
|
+
|
39
|
+
params = { :klass => Invoicexpress::Models::Item, :body => item }
|
40
|
+
post("items.xml", params.merge(options))
|
41
|
+
end
|
42
|
+
|
43
|
+
# Updates an item.
|
44
|
+
#
|
45
|
+
# @param item [Invoicexpress::Models::Item] The item to update
|
46
|
+
# @return [Invoicexpress::Models::Item] The updated item
|
47
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
48
|
+
# @raise Invoicexpress::NotFound When the item doesn't exist
|
49
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
50
|
+
def update_item(item, options={})
|
51
|
+
raise(ArgumentError, "item has the wrong type") unless item.is_a?(Invoicexpress::Models::Item)
|
52
|
+
|
53
|
+
params = { :klass => Invoicexpress::Models::Item, :body => item }
|
54
|
+
put("items/#{item.id}.xml", params.merge(options))
|
55
|
+
end
|
56
|
+
|
57
|
+
# Deletes an item.
|
58
|
+
#
|
59
|
+
# @param item [Invoicexpress::Models::Item, String] The item or item id
|
60
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
61
|
+
# @raise Invoicexpress::NotFound When the item doesn't exist
|
62
|
+
def delete_item(item, options={})
|
63
|
+
params = { :klass => Invoicexpress::Models::Item }
|
64
|
+
delete("items/#{id_from_item(item)}.xml", params.merge(options))
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
def id_from_item(item)
|
69
|
+
if item.is_a?(Invoicexpress::Models::Item)
|
70
|
+
item.id
|
71
|
+
elsif item.is_a?(String)
|
72
|
+
item
|
73
|
+
elsif item.is_a?(Integer)
|
74
|
+
item.to_s
|
75
|
+
else
|
76
|
+
raise ArgumentError, "Cannot get item id from #{item}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'invoicexpress/models'
|
2
|
+
module Invoicexpress
|
3
|
+
class Client
|
4
|
+
module PurchaseOrders
|
5
|
+
|
6
|
+
# Returns all your purchase orders.
|
7
|
+
# @option options [Integer] page (1) You can ask a specific page of PurchaseOrders
|
8
|
+
#
|
9
|
+
# @return [Array<Invoicexpress::Models::PurchaseOrder>] An array with all the PurchaseOrders
|
10
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
11
|
+
def purchase_orders(options = {})
|
12
|
+
params = { :page => 1, :klass => Invoicexpress::Models::PurchaseOrder }
|
13
|
+
|
14
|
+
get("purchase_orders.xml", params.merge(options))
|
15
|
+
end
|
16
|
+
|
17
|
+
#Creates a new purchase order.
|
18
|
+
#Creates a new purchase order. Also allows to create a new supplier and/or new items in the same request.
|
19
|
+
#If the supplier name does not exist a new one is created.
|
20
|
+
#If items do not exist with the given names, new ones will be created.
|
21
|
+
#If item name already exists, the item is updated with the new values.
|
22
|
+
#Regarding item taxes, if the tax name is not found, no tax is applyed to that item.
|
23
|
+
#
|
24
|
+
# @param purchase_order [Invoicexpress::Models::PurchaseOrder] The PurchaseOrder to create
|
25
|
+
# @return Invoicexpress::Models::PurchaseOrder The PurchaseOrder
|
26
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
27
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
28
|
+
def create_purchase_order(purchase_order, options={})
|
29
|
+
raise(ArgumentError, "purchase order has the wrong type") unless purchase_order.is_a?(Invoicexpress::Models::PurchaseOrder)
|
30
|
+
|
31
|
+
params = { :klass => Invoicexpress::Models::PurchaseOrder, :body => purchase_order }
|
32
|
+
post("purchase_orders.xml", params.merge(options))
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns a specific purchase order.
|
36
|
+
#
|
37
|
+
# @param purchase_order [Invoicexpress::Models::PurchaseOrder, String] The purchase order or purchase orderID
|
38
|
+
# @return Invoicexpress::Models::PurchaseOrder The PurchaseOrder
|
39
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
40
|
+
# @raise Invoicexpress::NotFound When the purchase_order doesn't exist
|
41
|
+
def purchase_order(purchase_order, options={})
|
42
|
+
params = { :klass => Invoicexpress::Models::PurchaseOrder }
|
43
|
+
|
44
|
+
get("purchase_orders/#{id_from_purchase_order(purchase_order)}.xml", params.merge(options))
|
45
|
+
end
|
46
|
+
|
47
|
+
# Updates a purchase order
|
48
|
+
#Updates a purchase order. Also allows to create a new supplier and/or new items in the same request.
|
49
|
+
#If the supplier name does not exist a new one is created.
|
50
|
+
#If items do not exist with the given names, new ones will be created.
|
51
|
+
#If item name already exists, the item is updated with the new values.
|
52
|
+
#Regarding item taxes, if the tax name is not found, no tax is applyed to that item.
|
53
|
+
#Be careful when updating the invoice items, any missing items from the original invoice will be deleted.
|
54
|
+
#
|
55
|
+
# @param purchase_order [Invoicexpress::Models::PurchaseOrder] The Purchase Order to update
|
56
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
57
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
58
|
+
# @raise Invoicexpress::NotFound When the credit note doesn't exist
|
59
|
+
def update_purchase_order(purchase_order, options={})
|
60
|
+
raise(ArgumentError, "purchase order has the wrong type") unless purchase_order.is_a?(Invoicexpress::Models::PurchaseOrder)
|
61
|
+
|
62
|
+
if !purchase_order.id
|
63
|
+
raise ArgumentError, "Purchase Order ID is required"
|
64
|
+
end
|
65
|
+
params = { :klass => Invoicexpress::Models::PurchaseOrder, :body => purchase_order.to_core_purchase_order }
|
66
|
+
put("purchase_orders/#{purchase_order.id}.xml", params.merge(options))
|
67
|
+
end
|
68
|
+
|
69
|
+
# Changes the state of a purchase order.
|
70
|
+
#Possible state transitions:
|
71
|
+
#- draft to final – finalized
|
72
|
+
#- draft to deleted – deleted
|
73
|
+
#- final to second_copy – second_copy
|
74
|
+
#- final to accepted – accepted
|
75
|
+
#- final to refused – refused
|
76
|
+
#- final to canceled – canceled
|
77
|
+
#- second_copy to canceled – canceled
|
78
|
+
#- accepted to refused – refused
|
79
|
+
#- accepted to completed – completed
|
80
|
+
#- refused to canceled – canceled
|
81
|
+
#- refused to accepted – accepted
|
82
|
+
#Any other transitions will fail.
|
83
|
+
#When canceling an purchase order you must specify a reason.
|
84
|
+
#
|
85
|
+
# @param purchase_order_id [String] The purchase order id to change
|
86
|
+
# @param purchase_order_state [Invoicexpress::Models::InvoiceState] The new state
|
87
|
+
# @return [Invoicexpress::Models::PurchaseOrder] The updated Purchase Order
|
88
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
89
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
90
|
+
# @raise Invoicexpress::NotFound When the credit note doesn't exist
|
91
|
+
def update_purchase_order_state(purchase_order_id, purchase_order_state, options={})
|
92
|
+
raise(ArgumentError, "purchase_order_state has the wrong type") unless purchase_order_state.is_a?(Invoicexpress::Models::InvoiceState)
|
93
|
+
|
94
|
+
params = { :klass => Invoicexpress::Models::PurchaseOrder, :body => purchase_order_state }
|
95
|
+
put("purchase_orders/#{purchase_order_id}/change-state.xml", params.merge(options))
|
96
|
+
end
|
97
|
+
|
98
|
+
# Sends the purchase order by email
|
99
|
+
#
|
100
|
+
# @param purchase_order_id [String] The credit note id to send
|
101
|
+
# @param message [Invoicexpress::Models::Message] The message to send
|
102
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
103
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
104
|
+
# @raise Invoicexpress::NotFound When the credit note doesn't exist
|
105
|
+
def purchase_order_mail(purchase_order_id, message, options={})
|
106
|
+
raise(ArgumentError, "message has the wrong type") unless message.is_a?(Invoicexpress::Models::Message)
|
107
|
+
|
108
|
+
params = { :body => message, :klass => Invoicexpress::Models::PurchaseOrder }
|
109
|
+
put("purchase_orders/#{purchase_order_id}/email-document.xml", params.merge(options))
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
def id_from_purchase_order(item)
|
114
|
+
if item.is_a?(Invoicexpress::Models::PurchaseOrder)
|
115
|
+
item.id
|
116
|
+
elsif item.is_a?(String)
|
117
|
+
item
|
118
|
+
elsif item.is_a?(Integer)
|
119
|
+
item.to_s
|
120
|
+
else
|
121
|
+
raise ArgumentError, "Cannot get Purchase Order id from #{item}"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'invoicexpress/models'
|
2
|
+
module Invoicexpress
|
3
|
+
class Client
|
4
|
+
module Schedules
|
5
|
+
|
6
|
+
# Returns all your schedules.
|
7
|
+
#
|
8
|
+
# @return [Array<Invoicexpress::Models::Schedule>] An array with all the schedules
|
9
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
10
|
+
def schedules(options = {})
|
11
|
+
params = { :klass => Invoicexpress::Models::Schedule }
|
12
|
+
|
13
|
+
get("schedules.xml", params.merge(options))
|
14
|
+
end
|
15
|
+
|
16
|
+
# Creates a new schedule.
|
17
|
+
# It also allows you to create a new client and/or items in the same request.
|
18
|
+
# If the client name does not exist a new one is created.
|
19
|
+
# Regarding item taxes, if the tax name is not found, it is ignored and no tax is applied to that item.
|
20
|
+
# If no item exists with the given name a new one will be created.
|
21
|
+
# If the item exists it will be updated with the new values.
|
22
|
+
# Be careful when updating the schedule items, as any missing items from the original invoice are deleted.
|
23
|
+
#
|
24
|
+
# @param schedule [Invoicexpress::Models::Schedule] The schedule to create
|
25
|
+
# @return Invoicexpress::Models::Schedule The schedule
|
26
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
27
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
28
|
+
def create_schedule(schedule, options={})
|
29
|
+
raise(ArgumentError, "schedule has the wrong type") unless schedule.is_a?(Invoicexpress::Models::Schedule)
|
30
|
+
|
31
|
+
params = { :klass => Invoicexpress::Models::Schedule, :body => schedule }
|
32
|
+
post("schedules.xml", params.merge(options))
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns a specific schedule.
|
36
|
+
#
|
37
|
+
# @param schedule [Invoicexpress::Models::Schedule, String] The schedule or schedule ID
|
38
|
+
# @return Invoicexpress::Models::Schedule The schedule
|
39
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
40
|
+
# @raise Invoicexpress::NotFound When the schedule doesn't exist
|
41
|
+
def schedule(schedule, options={})
|
42
|
+
params = { :klass => Invoicexpress::Models::Schedule }
|
43
|
+
get("schedules/#{id_from_schedule(schedule)}.xml", params.merge(options))
|
44
|
+
end
|
45
|
+
|
46
|
+
# Updates a schedule.
|
47
|
+
# It also allows you to create a new client and/or items in the same request.
|
48
|
+
# If the client name does not exist a new one is created.
|
49
|
+
# Regarding item taxes, if the tax name is not found, it is ignored and no tax is applied to that item.
|
50
|
+
# If no item exists with the given name a new one will be created.
|
51
|
+
# If the item exists it will be updated with the new values.
|
52
|
+
# Be careful when updating the schedule items, as any missing items from the original invoice are deleted.
|
53
|
+
#
|
54
|
+
# @param schedule [Invoicexpress::Models::Schedule] The schedule to update
|
55
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
56
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
57
|
+
# @raise Invoicexpress::NotFound When the invoice doesn't exist
|
58
|
+
def update_schedule(schedule, options={})
|
59
|
+
raise(ArgumentError, "schedule has the wrong type") unless schedule.is_a?(Invoicexpress::Models::Schedule)
|
60
|
+
if !schedule.id
|
61
|
+
raise ArgumentError, "Schedule's ID is required"
|
62
|
+
end
|
63
|
+
params = { :klass => Invoicexpress::Models::Schedule, :body => schedule.to_core_schedule() }
|
64
|
+
put("schedules/#{schedule.id}.xml", params.merge(options))
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
# Activates a previously deactivated schedule
|
70
|
+
#
|
71
|
+
# @param schedule [Schedule] The schedule to change
|
72
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
73
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
74
|
+
# @raise Invoicexpress::NotFound When the invoice doesn't exist
|
75
|
+
def activate_schedule(schedule, options={})
|
76
|
+
raise(ArgumentError, "schedule has the wrong type") unless schedule.is_a?(Invoicexpress::Models::Schedule)
|
77
|
+
|
78
|
+
params = { :body => schedule, :klass => Invoicexpress::Models::Schedule }
|
79
|
+
put("schedules/#{id_from_schedule(schedule)}/activate", params.merge(options))
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
# Deactivates a schedule. No invoices are created while the schedule is deactivated
|
84
|
+
#
|
85
|
+
# @param schedule [Schedule] The schedule to change
|
86
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
87
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
88
|
+
# @raise Invoicexpress::NotFound When the invoice doesn't exist
|
89
|
+
def deactivate_schedule(schedule, options={})
|
90
|
+
raise(ArgumentError, "schedule has the wrong type") unless schedule.is_a?(Invoicexpress::Models::Schedule)
|
91
|
+
|
92
|
+
params = { :body => schedule, :klass => Invoicexpress::Models::Schedule }
|
93
|
+
put("schedules/#{id_from_schedule(schedule)}/deactivate", params.merge(options))
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
def id_from_schedule(item)
|
98
|
+
if item.is_a?(Invoicexpress::Models::Schedule)
|
99
|
+
item.id
|
100
|
+
elsif item.is_a?(String)
|
101
|
+
item
|
102
|
+
elsif item.is_a?(Integer)
|
103
|
+
item.to_s
|
104
|
+
else
|
105
|
+
raise ArgumentError, "Cannot get schedule id from #{item}"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|