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,56 @@
|
|
1
|
+
require 'invoicexpress/authentication'
|
2
|
+
require 'invoicexpress/connection'
|
3
|
+
require 'invoicexpress/request'
|
4
|
+
|
5
|
+
require 'invoicexpress/models'
|
6
|
+
|
7
|
+
require 'invoicexpress/client/clients'
|
8
|
+
require 'invoicexpress/client/invoices'
|
9
|
+
require 'invoicexpress/client/cash_invoices'
|
10
|
+
require 'invoicexpress/client/items'
|
11
|
+
require 'invoicexpress/client/sequences'
|
12
|
+
require 'invoicexpress/client/users'
|
13
|
+
require 'invoicexpress/client/charts'
|
14
|
+
require 'invoicexpress/client/taxes'
|
15
|
+
require 'invoicexpress/client/schedules'
|
16
|
+
require 'invoicexpress/client/purchase_orders'
|
17
|
+
require 'invoicexpress/client/debit_notes'
|
18
|
+
require 'invoicexpress/client/credit_notes'
|
19
|
+
require 'invoicexpress/client/simplified_invoices'
|
20
|
+
|
21
|
+
|
22
|
+
module Invoicexpress
|
23
|
+
# Please refer to each section inside the client for the respective documentation.
|
24
|
+
#
|
25
|
+
#
|
26
|
+
class Client
|
27
|
+
attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
|
28
|
+
|
29
|
+
def initialize(options={})
|
30
|
+
options = Invoicexpress.options.merge(options)
|
31
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
32
|
+
send("#{key}=", options[key])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
include Invoicexpress::Authentication
|
37
|
+
include Invoicexpress::Connection
|
38
|
+
include Invoicexpress::Request
|
39
|
+
|
40
|
+
include Invoicexpress::Client::Clients
|
41
|
+
include Invoicexpress::Client::Invoices
|
42
|
+
include Invoicexpress::Client::CashInvoices
|
43
|
+
include Invoicexpress::Client::Items
|
44
|
+
include Invoicexpress::Client::Sequences
|
45
|
+
include Invoicexpress::Client::Users
|
46
|
+
include Invoicexpress::Client::Charts
|
47
|
+
include Invoicexpress::Client::Taxes
|
48
|
+
include Invoicexpress::Client::Schedules
|
49
|
+
|
50
|
+
include Invoicexpress::Client::PurchaseOrders
|
51
|
+
include Invoicexpress::Client::DebitNotes
|
52
|
+
include Invoicexpress::Client::CreditNotes
|
53
|
+
include Invoicexpress::Client::SimplifiedInvoices
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'invoicexpress/models'
|
2
|
+
|
3
|
+
module Invoicexpress
|
4
|
+
class Client
|
5
|
+
module CashInvoices
|
6
|
+
|
7
|
+
# Returns all your cash invoices
|
8
|
+
#
|
9
|
+
# @option options [Integer] page (1) You can ask a specific page of invoices
|
10
|
+
# @return [Invoicexpress::Models::CashInvoices] A structure with results (pagination) and all the cash invoices
|
11
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
12
|
+
def cash_invoices(options={})
|
13
|
+
params = { :page => 1, :klass => Invoicexpress::Models::CashInvoices }
|
14
|
+
|
15
|
+
get("cash_invoices.xml", params.merge(options))
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns a specific cash invoice
|
19
|
+
#
|
20
|
+
# @param invoice_id [String] Requested invoice id
|
21
|
+
# @return [Invoicexpress::Models::CashInvoice] The requested cash invoice
|
22
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
23
|
+
# @raise Invoicexpress::NotFound When the invoice doesn't exist
|
24
|
+
def cash_invoice(invoice_id, options={})
|
25
|
+
params = { :klass => Invoicexpress::Models::CashInvoice }
|
26
|
+
|
27
|
+
get("cash_invoices/#{invoice_id}.xml", params.merge(options))
|
28
|
+
end
|
29
|
+
|
30
|
+
# Creates a new cash invoice. Also allows to create a new client and/or new items in the same request.
|
31
|
+
# If the client name does not exist a new one is created.
|
32
|
+
# If items do not exist with the given names, new ones will be created.
|
33
|
+
# If item name already exists, the item is updated with the new values.
|
34
|
+
# Regarding item taxes, if the tax name is not found, no tax is applyed to that item.
|
35
|
+
# Portuguese accounts should also send the IVA exemption reason if the invoice contains exempt items(IVA 0%)
|
36
|
+
#
|
37
|
+
# @param invoice [Invoicexpress::Models::CashInvoice] The cash invoice to create
|
38
|
+
# @return [Invoicexpress::Models::CashInvoice] The created cash invoice
|
39
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
40
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
41
|
+
def create_cash_invoice(invoice, options={})
|
42
|
+
raise(ArgumentError, "cash invoice has the wrong type") unless invoice.is_a?(Invoicexpress::Models::CashInvoice)
|
43
|
+
|
44
|
+
params = { :klass => Invoicexpress::Models::CashInvoice, :body => invoice }
|
45
|
+
post("cash_invoices.xml", params.merge(options))
|
46
|
+
end
|
47
|
+
|
48
|
+
# Updates a cash invoice
|
49
|
+
# It also allows you to create a new client and/or items in the same request.
|
50
|
+
# If the client name does not exist a new client is created.
|
51
|
+
# Regarding item taxes, if the tax name is not found, no tax will be applied to that item.
|
52
|
+
# If item does not exist with the given name, a new one will be created.
|
53
|
+
# If item exists it will be updated with the new values
|
54
|
+
# Be careful when updating the document items, any missing items from the original document will be deleted.
|
55
|
+
#
|
56
|
+
# @param invoice [Invoicexpress::Models::CashInvoice] The cash invoice to update
|
57
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
58
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
59
|
+
# @raise Invoicexpress::NotFound When the invoice doesn't exist
|
60
|
+
def update_cash_invoice(invoice, options={})
|
61
|
+
raise(ArgumentError, "cash invoice has the wrong type") unless invoice.is_a?(Invoicexpress::Models::CashInvoice)
|
62
|
+
|
63
|
+
if !invoice.id
|
64
|
+
raise ArgumentError, "Sequence ID is required"
|
65
|
+
end
|
66
|
+
params = { :klass => Invoicexpress::Models::CashInvoice, :body => invoice.to_core }
|
67
|
+
put("cash_invoices/#{invoice.id}.xml", params.merge(options))
|
68
|
+
end
|
69
|
+
|
70
|
+
# Changes the state of a cash invoice.
|
71
|
+
# Possible state transitions:
|
72
|
+
# - draft to settle – finalized
|
73
|
+
# - draft to deleted – deleted
|
74
|
+
# - settled to final – unsettled
|
75
|
+
# - final to second copy – second_copy
|
76
|
+
# - final or second copy to canceled – canceled
|
77
|
+
# - final or second copy to settled – settled
|
78
|
+
# Any other transitions will fail.
|
79
|
+
# When canceling a cash invoice you must specify a reason.
|
80
|
+
#
|
81
|
+
# @param invoice_id [String] The cash invoice id to change
|
82
|
+
# @param invoice_state [Invoicexpress::Models::InvoiceState] The new state
|
83
|
+
# @return [Invoicexpress::Models::CashInvoice] The updated cash invoice
|
84
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
85
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
86
|
+
# @raise Invoicexpress::NotFound When the invoice doesn't exist
|
87
|
+
def update_cash_invoice_state(invoice_id, invoice_state, options={})
|
88
|
+
raise(ArgumentError, "invoice_state has the wrong type") unless invoice_state.is_a?(Invoicexpress::Models::InvoiceState)
|
89
|
+
|
90
|
+
params = { :klass => Invoicexpress::Models::CashInvoice, :body => invoice_state }
|
91
|
+
put("cash_invoices/#{invoice_id}/change-state.xml", params.merge(options))
|
92
|
+
end
|
93
|
+
|
94
|
+
# Sends the invoice by email
|
95
|
+
#
|
96
|
+
# @param invoice_id [String] The cash invoice id to change
|
97
|
+
# @param message [Invoicexpress::Models::Message] The message to send
|
98
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
99
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
100
|
+
# @raise Invoicexpress::NotFound When the invoice doesn't exist
|
101
|
+
def invoice_email(invoice_id, message, options={})
|
102
|
+
raise(ArgumentError, "message has the wrong type") unless message.is_a?(Invoicexpress::Models::Message)
|
103
|
+
|
104
|
+
params = { :body => message, :klass => Invoicexpress::Models::CashInvoice }
|
105
|
+
put("cash_invoices/#{invoice_id}/email-document.xml", params.merge(options))
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Invoicexpress
|
2
|
+
class Client
|
3
|
+
module Charts
|
4
|
+
|
5
|
+
# Returns the invoicing chart data.
|
6
|
+
#
|
7
|
+
# @return [Array<Invoicexpress::Models::Chart>] An array with all the charting results
|
8
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
9
|
+
def invoicing_chart(options = {})
|
10
|
+
params = { :klass => Invoicexpress::Models::Chart }
|
11
|
+
get("api/charts/invoicing.xml", params.merge(options))
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns the treasury chart data.
|
15
|
+
#
|
16
|
+
# @return [Array<Invoicexpress::Models::Chart>] An array with all the charting results
|
17
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
18
|
+
def treasury_chart(options = {})
|
19
|
+
params = { :klass => Invoicexpress::Models::Chart }
|
20
|
+
get("api/charts/treasury.xml", params.merge(options))
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns your 5 top clients for which you have invoiced more.
|
24
|
+
#
|
25
|
+
# @return [Array<Invoicexpress::Models::TopClient>] An array with all the charting results
|
26
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
27
|
+
def top_clients(options = {})
|
28
|
+
params = { :klass => Invoicexpress::Models::TopClient }
|
29
|
+
get("api/charts/top-clients.xml", params.merge(options))
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns your 5 top debtors. Values are calculated based on the due amount.
|
33
|
+
#
|
34
|
+
# @return [Array<Invoicexpress::Models::TopClient>] An array with all the charting results
|
35
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
36
|
+
def top_debtors(options = {})
|
37
|
+
params = { :klass => Invoicexpress::Models::TopDebtor }
|
38
|
+
get("api/charts/top-debtors.xml", params.merge(options))
|
39
|
+
end
|
40
|
+
|
41
|
+
# This method allows you to obtain the quarterly results.
|
42
|
+
# Each quarter has:
|
43
|
+
# The amount invoiced before taxes
|
44
|
+
# Taxes amount
|
45
|
+
# Year to date (YTD) which consists on the difference between the invoiced on the current quarter less the invoiced on the same quarter one year ago
|
46
|
+
#
|
47
|
+
# @param year [Integer] By default year is the current year. It should obey the format YYYY (ex.: 2010)
|
48
|
+
# @return [Array<Invoicexpress::Models::TopClient>] An array with all the charting results
|
49
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
50
|
+
def quarterly_results(year=Date.today.year , options = {})
|
51
|
+
#params = { :klass => Invoicexpress::Models::QuaterlyResult }
|
52
|
+
params = { :klass => Invoicexpress::Models::QuarterlyResult, :year => year }
|
53
|
+
get("api/charts/quarterly-results.xml", params.merge(options))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
require 'invoicexpress/models'
|
2
|
+
|
3
|
+
module Invoicexpress
|
4
|
+
class Client
|
5
|
+
module Clients
|
6
|
+
|
7
|
+
# Returns all your clients
|
8
|
+
#
|
9
|
+
# @option options [Integer] per_page (30) You can specify how many results you want to fetch
|
10
|
+
# @option options [Integer] page (1) You can ask a specific page of clients
|
11
|
+
#
|
12
|
+
# @return [Array<Invoicexpress::Models::Client>] An array with all your clients
|
13
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
14
|
+
def clients(options={})
|
15
|
+
params = { :per_page => 30, :page => 1, :klass => Invoicexpress::Models::Client }
|
16
|
+
|
17
|
+
get("clients.xml", params.merge(options))
|
18
|
+
end
|
19
|
+
|
20
|
+
# Creates a new client.
|
21
|
+
#
|
22
|
+
# @param client [Invoicexpress::Models::Client] The client to create
|
23
|
+
# @return [Invoicexpress::Models::Client] The new client from the server
|
24
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
25
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
26
|
+
def create_client(client, options={})
|
27
|
+
if !client || !client.is_a?(Invoicexpress::Models::Client)
|
28
|
+
raise ArgumentError, "Need a Invoicexpress::Models::Client instance"
|
29
|
+
end
|
30
|
+
|
31
|
+
if !client.name
|
32
|
+
raise ArgumentError, "Client's name is required"
|
33
|
+
end
|
34
|
+
|
35
|
+
params = { :body => client, :klass => Invoicexpress::Models::Client }
|
36
|
+
post("clients.xml", params.merge(options))
|
37
|
+
end
|
38
|
+
|
39
|
+
# Updates a client.
|
40
|
+
#
|
41
|
+
# @param client [Invoicexpress::Models::Client] The client to update
|
42
|
+
# @return [Invoicexpress::Models::Client] The new client from the server
|
43
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
44
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
45
|
+
# @raise Invoicexpress::NotFound When the Client's ID is not found
|
46
|
+
def update_client(client, options={})
|
47
|
+
if !client || !client.is_a?(Invoicexpress::Models::Client)
|
48
|
+
raise ArgumentError, "Need a Invoicexpress::Models::Client instance"
|
49
|
+
end
|
50
|
+
|
51
|
+
if !client.id
|
52
|
+
raise ArgumentError, "Client's ID is required"
|
53
|
+
end
|
54
|
+
|
55
|
+
params = { :body => client, :klass => Invoicexpress::Models::Client }
|
56
|
+
put("clients/#{client.id.to_s}.xml", params.merge(options))
|
57
|
+
end
|
58
|
+
|
59
|
+
# Returns a specific client
|
60
|
+
#
|
61
|
+
# @param client_id [String] The client's ID
|
62
|
+
# @return [Invoicexpress::Models::Client] The remote client from the server
|
63
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
64
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
65
|
+
# @raise Invoicexpress::NotFound When the client ID is not found
|
66
|
+
def client(client_id, options={})
|
67
|
+
params = { :klass => Invoicexpress::Models::Client }
|
68
|
+
|
69
|
+
get("clients/#{client_id.to_s}.xml", params.merge(options))
|
70
|
+
end
|
71
|
+
|
72
|
+
# This method allows you to obtain the invoices for a specific client.
|
73
|
+
# Allowing filtering aswell.
|
74
|
+
#
|
75
|
+
# @param client_id [String] The client's ID
|
76
|
+
# @param filter [Invoicexpress::Models::Filter] An optional filter
|
77
|
+
# @option options [Integer] per_page (10) You can specify how many results you want to fetch
|
78
|
+
# @option options [Integer] page (1) You can ask a specific page of clients
|
79
|
+
# @return [Invoicexpress::Models::ClientInvoices] The invoices result
|
80
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
81
|
+
# @raise Invoicexpress::NotFound When the client ID is not found
|
82
|
+
def client_invoices(client_id, filter=Invoicexpress::Models::Filter.new, options={})
|
83
|
+
raise(ArgumentError, "filter has the wrong type") unless filter.is_a?(Invoicexpress::Models::Filter)
|
84
|
+
|
85
|
+
params = {
|
86
|
+
:klass => Invoicexpress::Models::ClientInvoices,
|
87
|
+
:per_page => 10,
|
88
|
+
:page => 1,
|
89
|
+
:body => filter
|
90
|
+
}
|
91
|
+
|
92
|
+
post("clients/#{client_id.to_s}/invoices.xml", params.merge(options))
|
93
|
+
end
|
94
|
+
|
95
|
+
# Use this method to obtain a client by name. Partial searches are not supported
|
96
|
+
#
|
97
|
+
# @param client_name [String] The client's name
|
98
|
+
# @return [Invoicexpress::Models::Client] The client
|
99
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
100
|
+
# @raise Invoicexpress::NotFound When there are no clients with that name
|
101
|
+
def client_by_name(client_name, options={})
|
102
|
+
params = {
|
103
|
+
:klass => Invoicexpress::Models::Client,
|
104
|
+
:client_name => client_name
|
105
|
+
}
|
106
|
+
|
107
|
+
get("clients/find-by-name.xml", params.merge(options))
|
108
|
+
end
|
109
|
+
|
110
|
+
# Use this method to obtain a client by your code. Partial searches are not supported
|
111
|
+
#
|
112
|
+
# @param client_code [String] The client's code (your code)
|
113
|
+
# @return [Invoicexpress::Models::Client] The client
|
114
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
115
|
+
# @raise Invoicexpress::NotFound When there are no clients with that name
|
116
|
+
def client_by_code(client_code, options={})
|
117
|
+
params = {
|
118
|
+
:klass => Invoicexpress::Models::Client,
|
119
|
+
:client_code => client_code
|
120
|
+
}
|
121
|
+
|
122
|
+
get("clients/find-by-code.xml", params.merge(options))
|
123
|
+
end
|
124
|
+
|
125
|
+
# This method allows you to create a new invoice for a specific client.
|
126
|
+
# When creating the invoice:
|
127
|
+
# - If items do not exist with the given names, new ones will be created.
|
128
|
+
# - If item name already exists, the item is updated with the new values.
|
129
|
+
# Regarding item taxes, if the tax name is not found, no tax is applied to that item.
|
130
|
+
#
|
131
|
+
# @param client_id [String] The ID of the client
|
132
|
+
# @return [Invoicexpress::Models::Invoice] The invoice
|
133
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
134
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
135
|
+
# @raise Invoicexpress::NotFound When there are no clients with that name
|
136
|
+
def client_create_invoice(client_id, invoice, options={})
|
137
|
+
raise(ArgumentError, "invoice has the wrong type") unless invoice.is_a?(Invoicexpress::Models::Invoice)
|
138
|
+
|
139
|
+
params = {
|
140
|
+
:klass => Invoicexpress::Models::Invoice,
|
141
|
+
:body => invoice
|
142
|
+
}
|
143
|
+
|
144
|
+
post("clients/#{client_id}/create/invoice.xml", params.merge(options))
|
145
|
+
end
|
146
|
+
|
147
|
+
# This method allows you to create a new cash invoice for a specific client.
|
148
|
+
# When creating the invoice:
|
149
|
+
# - If items do not exist with the given names, new ones will be created.
|
150
|
+
# - If item name already exists, the item is updated with the new values.
|
151
|
+
# Regarding item taxes, if the tax name is not found, no tax is applied to that item.
|
152
|
+
#
|
153
|
+
# @param client_id [String] The ID of the client
|
154
|
+
# @return [Invoicexpress::Models::CashInvoice] The invoice
|
155
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
156
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
157
|
+
# @raise Invoicexpress::NotFound When there are no clients with that name
|
158
|
+
def client_create_cash_invoice(client_id, invoice, options={})
|
159
|
+
raise(ArgumentError, "invoice has the wrong type") unless invoice.is_a?(Invoicexpress::Models::CashInvoice)
|
160
|
+
|
161
|
+
params = {
|
162
|
+
:klass => Invoicexpress::Models::CashInvoice,
|
163
|
+
:body => invoice
|
164
|
+
}
|
165
|
+
|
166
|
+
post("clients/#{client_id}/create/cash-invoice.xml", params.merge(options))
|
167
|
+
end
|
168
|
+
|
169
|
+
# This method allows you to create a new Credit Note for a specific client.
|
170
|
+
# When creating the invoice:
|
171
|
+
# - If items do not exist with the given names, new ones will be created.
|
172
|
+
# - If item name already exists, the item is updated with the new values.
|
173
|
+
# Regarding item taxes, if the tax name is not found, no tax is applied to that item.
|
174
|
+
#
|
175
|
+
# @param client_id [String] The ID of the client
|
176
|
+
# @return [Invoicexpress::Models::CreditNote] The credit note
|
177
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
178
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
179
|
+
# @raise Invoicexpress::NotFound When there are no clients with that name
|
180
|
+
def client_create_credit_note(client_id, invoice, options={})
|
181
|
+
raise(ArgumentError, "credit note has the wrong type") unless invoice.is_a?(Invoicexpress::Models::CreditNote)
|
182
|
+
|
183
|
+
params = {
|
184
|
+
:klass => Invoicexpress::Models::CreditNote,
|
185
|
+
:body => invoice
|
186
|
+
}
|
187
|
+
|
188
|
+
post("clients/#{client_id}/create/credit-note.xml", params.merge(options))
|
189
|
+
end
|
190
|
+
|
191
|
+
# This method allows you to create a new Debit Note for a specific client.
|
192
|
+
# When creating the invoice:
|
193
|
+
# - If items do not exist with the given names, new ones will be created.
|
194
|
+
# - If item name already exists, the item is updated with the new values.
|
195
|
+
# Regarding item taxes, if the tax name is not found, no tax is applied to that item.
|
196
|
+
#
|
197
|
+
# @param client_id [String] The ID of the client
|
198
|
+
# @return [Invoicexpress::Models::DebitNote] The debit note
|
199
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
200
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
201
|
+
# @raise Invoicexpress::NotFound When there are no clients with that name
|
202
|
+
def client_create_debit_note(client_id, invoice, options={})
|
203
|
+
raise(ArgumentError, "debit note has the wrong type") unless invoice.is_a?(Invoicexpress::Models::DebitNote)
|
204
|
+
|
205
|
+
params = {
|
206
|
+
:klass => Invoicexpress::Models::DebitNote,
|
207
|
+
:body => invoice
|
208
|
+
}
|
209
|
+
|
210
|
+
post("clients/#{client_id}/create/debit-note.xml", params.merge(options))
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'invoicexpress/models'
|
2
|
+
|
3
|
+
module Invoicexpress
|
4
|
+
class Client
|
5
|
+
module CreditNotes
|
6
|
+
|
7
|
+
# Returns all your credit notes
|
8
|
+
#
|
9
|
+
# @option options [Integer] page (1) You can ask a specific page of credit notes
|
10
|
+
#
|
11
|
+
# @return [Invoicexpress::Models::CreditNotes] A struct with results (pagination) and all the credit notes
|
12
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
13
|
+
def credit_notes(options={})
|
14
|
+
params = { :page => 1, :klass => Invoicexpress::Models::CreditNote }
|
15
|
+
|
16
|
+
get("credit_notes.xml", params.merge(options))
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns all the information about a credit 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 credit_note_id [String] Requested credit note id
|
40
|
+
# @return [Invoicexpress::Models::CreditNote] The requested credit note
|
41
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
42
|
+
# @raise Invoicexpress::NotFound When the credit_note doesn't exist
|
43
|
+
def credit_note(credit_note_id, options={})
|
44
|
+
params = { :klass => Invoicexpress::Models::CreditNote }
|
45
|
+
|
46
|
+
get("credit_notes/#{credit_note_id}.xml", params.merge(options))
|
47
|
+
end
|
48
|
+
|
49
|
+
# Creates a new credit 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 credit_note [Invoicexpress::Models::CreditNote] The credit note to create
|
57
|
+
# @return [Invoicexpress::Models::CreditNote] The created credit note
|
58
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
59
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
60
|
+
def create_credit_note(credit_note, options={})
|
61
|
+
raise(ArgumentError, "credit note has the wrong type") unless credit_note.is_a?(Invoicexpress::Models::CreditNote)
|
62
|
+
|
63
|
+
params = { :klass => Invoicexpress::Models::CreditNote, :body => credit_note }
|
64
|
+
post("credit_notes.xml", params.merge(options))
|
65
|
+
end
|
66
|
+
|
67
|
+
# Updates a credit 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 credit_note [Invoicexpress::Models::CreditNote] The credit 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 credit note doesn't exist
|
79
|
+
def update_credit_note(credit_note, options={})
|
80
|
+
raise(ArgumentError, "credit note has the wrong type") unless credit_note.is_a?(Invoicexpress::Models::CreditNote)
|
81
|
+
if !credit_note.id
|
82
|
+
raise ArgumentError, "CreditNote ID is required"
|
83
|
+
end
|
84
|
+
params = { :klass => Invoicexpress::Models::CreditNote, :body => credit_note.to_core }
|
85
|
+
put("credit_notes/#{credit_note.id}.xml", params.merge(options))
|
86
|
+
end
|
87
|
+
|
88
|
+
# Changes the state of a credit note.
|
89
|
+
# Possible state transitions:
|
90
|
+
# - draft to final – finalized
|
91
|
+
# - draft to deleted – deleted
|
92
|
+
# - settled to final – unsettled
|
93
|
+
# - final to second copy – second_copy
|
94
|
+
# - final or second copy to canceled – canceled
|
95
|
+
# - final or second copy to settled – settled
|
96
|
+
# Any other transitions will fail.
|
97
|
+
# When canceling a credit note you must specify a reason.
|
98
|
+
#
|
99
|
+
# @param credit_note_id [String] The credit note id to change
|
100
|
+
# @param credit_note_state [Invoicexpress::Models::InvoiceState] The new state
|
101
|
+
# @return [Invoicexpress::Models::CreditNote] The updated credit note
|
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 update_credit_note_state(credit_note_id, credit_note_state, options={})
|
106
|
+
raise(ArgumentError, "credit note state has the wrong type") unless credit_note_state.is_a?(Invoicexpress::Models::InvoiceState)
|
107
|
+
|
108
|
+
params = { :klass => Invoicexpress::Models::CreditNote, :body => credit_note_state }
|
109
|
+
put("credit_notes/#{credit_note_id}/change-state.xml", params.merge(options))
|
110
|
+
end
|
111
|
+
|
112
|
+
# Sends the credit note through email
|
113
|
+
#
|
114
|
+
# @param credit_note_id [String] The credit note id to send
|
115
|
+
# @param message [Invoicexpress::Models::Message] The message to send
|
116
|
+
# @raise Invoicexpress::Unauthorized When the client is unauthorized
|
117
|
+
# @raise Invoicexpress::UnprocessableEntity When there are errors on the submission
|
118
|
+
# @raise Invoicexpress::NotFound When the credit note doesn't exist
|
119
|
+
def credit_note_mail(credit_note_id, message, options={})
|
120
|
+
raise(ArgumentError, "message has the wrong type") unless message.is_a?(Invoicexpress::Models::Message)
|
121
|
+
|
122
|
+
params = { :body => message, :klass => Invoicexpress::Models::CreditNote }
|
123
|
+
put("credit_notes/#{credit_note_id}/email-document.xml", params.merge(options))
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|