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,45 @@
|
|
1
|
+
module Invoicexpress
|
2
|
+
module Models
|
3
|
+
|
4
|
+
#TODO Improve this in the future, maybe inherit
|
5
|
+
class Quarter01 < BaseModel
|
6
|
+
include HappyMapper
|
7
|
+
tag 'quarter-01'
|
8
|
+
element :invoicing, Float
|
9
|
+
element :taxes, Float
|
10
|
+
element :ytd, Float
|
11
|
+
end
|
12
|
+
class Quarter02 < BaseModel
|
13
|
+
include HappyMapper
|
14
|
+
tag 'quarter-02'
|
15
|
+
element :invoicing, Float
|
16
|
+
element :taxes, Float
|
17
|
+
element :ytd, Float
|
18
|
+
end
|
19
|
+
class Quarter03 < BaseModel
|
20
|
+
include HappyMapper
|
21
|
+
tag 'quarter-03'
|
22
|
+
element :invoicing, Float
|
23
|
+
element :taxes, Float
|
24
|
+
element :ytd, Float
|
25
|
+
end
|
26
|
+
class Quarter04 < BaseModel
|
27
|
+
include HappyMapper
|
28
|
+
tag 'quarter-04'
|
29
|
+
element :invoicing, Float
|
30
|
+
element :taxes, Float
|
31
|
+
element :ytd, Float
|
32
|
+
end
|
33
|
+
|
34
|
+
class QuarterlyResult < BaseModel
|
35
|
+
include HappyMapper
|
36
|
+
tag 'quarterly-results'
|
37
|
+
element :year, Integer
|
38
|
+
element :currency, String
|
39
|
+
has_one :quarter01, Quarter01
|
40
|
+
has_one :quarter02, Quarter02
|
41
|
+
has_one :quarter03, Quarter03
|
42
|
+
has_one :quarter04, Quarter04
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'invoicexpress/models/client'
|
2
|
+
require 'invoicexpress/models/invoice'
|
3
|
+
|
4
|
+
module Invoicexpress
|
5
|
+
module Models
|
6
|
+
|
7
|
+
class InvoiceTemplate < BaseModel
|
8
|
+
include BaseInvoice
|
9
|
+
tag 'invoice_template'
|
10
|
+
element :due_days, Integer
|
11
|
+
end
|
12
|
+
|
13
|
+
class SentInvoices < BaseModel
|
14
|
+
include HappyMapper
|
15
|
+
tag 'sent_invoices'
|
16
|
+
has_many :invoices, Invoice
|
17
|
+
end
|
18
|
+
|
19
|
+
module BaseSchedule
|
20
|
+
def self.included(base)
|
21
|
+
base.class_eval do
|
22
|
+
include HappyMapper
|
23
|
+
tag 'schedule'
|
24
|
+
|
25
|
+
element :id, Integer
|
26
|
+
#these fields are only used on create and update...
|
27
|
+
element :start_date, Date, :on_save => DATE_FORMAT
|
28
|
+
element :end_date, Date, :on_save => DATE_FORMAT
|
29
|
+
element :create_back, String
|
30
|
+
element :schedule_type, String
|
31
|
+
element :interval, String
|
32
|
+
element :send_to_client, String
|
33
|
+
element :description, String
|
34
|
+
|
35
|
+
# has_many :sent_invoices, Invoice
|
36
|
+
has_one :invoice_template, InvoiceTemplate
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class CoreSchedule < BaseModel
|
43
|
+
include BaseSchedule
|
44
|
+
end
|
45
|
+
|
46
|
+
class Schedule < CoreSchedule
|
47
|
+
include BaseSchedule
|
48
|
+
|
49
|
+
element :reference, String
|
50
|
+
element :retention, Float
|
51
|
+
element :currency, String
|
52
|
+
#observation instead of description?
|
53
|
+
element :observations, String
|
54
|
+
#items and client instead of invoice template?
|
55
|
+
has_many :items, Item
|
56
|
+
has_one :client, Client
|
57
|
+
element :sum, Float
|
58
|
+
element :discount, Float
|
59
|
+
element :before_taxes, Float
|
60
|
+
element :taxes, Float
|
61
|
+
element :total, Float
|
62
|
+
has_one :sent_invoices, SentInvoices
|
63
|
+
|
64
|
+
#creates a object that can be used in create/update by the invoicexpress API
|
65
|
+
def to_core_schedule()
|
66
|
+
Invoicexpress::Models::CoreSchedule.new(
|
67
|
+
:id=>self.id,
|
68
|
+
:start_date=>self.start_date,
|
69
|
+
:end_date=>self.end_date,
|
70
|
+
:create_back=>self.create_back,
|
71
|
+
:schedule_type=>self.schedule_type,
|
72
|
+
:interval=>self.interval,
|
73
|
+
:send_to_client=>self.send_to_client,
|
74
|
+
:description=>self.description,
|
75
|
+
:invoice_template=>self.invoice_template
|
76
|
+
)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class Schedules < BaseModel
|
81
|
+
include HappyMapper
|
82
|
+
tag 'schedules'
|
83
|
+
has_many :schedules, Schedule
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Invoicexpress
|
2
|
+
module Models
|
3
|
+
|
4
|
+
class Sequence < BaseModel
|
5
|
+
include HappyMapper
|
6
|
+
|
7
|
+
tag 'sequence'
|
8
|
+
element :id, String
|
9
|
+
element :serie, String
|
10
|
+
element :current_invoice_number, Integer
|
11
|
+
element :current_credit_note_number, Integer
|
12
|
+
element :current_debit_note_number, Integer
|
13
|
+
element :default_sequence, Boolean
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Invoicexpress
|
2
|
+
module Models
|
3
|
+
|
4
|
+
class Supplier < BaseModel
|
5
|
+
include HappyMapper
|
6
|
+
tag 'supplier'
|
7
|
+
element :id, String
|
8
|
+
element :name, String
|
9
|
+
element :code, String
|
10
|
+
element :email, String
|
11
|
+
element :address, String
|
12
|
+
element :postal_code, String
|
13
|
+
element :fiscal_id, String
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Invoicexpress
|
2
|
+
module Models
|
3
|
+
|
4
|
+
class Credentials < BaseModel
|
5
|
+
include HappyMapper
|
6
|
+
|
7
|
+
tag 'credentials'
|
8
|
+
element :login, String
|
9
|
+
element :password, String
|
10
|
+
end
|
11
|
+
|
12
|
+
class Account < BaseModel
|
13
|
+
include HappyMapper
|
14
|
+
|
15
|
+
tag 'account'
|
16
|
+
element :id, String
|
17
|
+
element :name, String
|
18
|
+
element :url, String
|
19
|
+
element :api_key, String
|
20
|
+
element :state, String
|
21
|
+
end
|
22
|
+
|
23
|
+
class ChangeAccountTo < BaseModel
|
24
|
+
include HappyMapper
|
25
|
+
|
26
|
+
tag 'change_account_to'
|
27
|
+
element :id, String
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Invoicexpress
|
2
|
+
module Request
|
3
|
+
|
4
|
+
def delete(path, options={})
|
5
|
+
request(:delete, path, options).body
|
6
|
+
end
|
7
|
+
|
8
|
+
def get(path, options={})
|
9
|
+
repsonse = request(:get, path, options).body
|
10
|
+
end
|
11
|
+
|
12
|
+
def patch(path, options={})
|
13
|
+
request(:patch, path, options).body
|
14
|
+
end
|
15
|
+
|
16
|
+
def post(path, options={})
|
17
|
+
request(:post, path, options).body
|
18
|
+
end
|
19
|
+
|
20
|
+
def put(path, options={})
|
21
|
+
request(:put, path, options).body
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
# Executes the request, checking if ti was successful
|
27
|
+
#
|
28
|
+
# @return [Boolean] True on success, false otherwise
|
29
|
+
def boolean_from_response(method, path, options={})
|
30
|
+
request(method, path, options).status == 204
|
31
|
+
rescue Invoicexpress::NotFound
|
32
|
+
false
|
33
|
+
end
|
34
|
+
|
35
|
+
def request(method, path, options={})
|
36
|
+
token = options.delete(:api_key) || api_key
|
37
|
+
url = options.delete(:endpoint) || (api_endpoint % screen_name)
|
38
|
+
klass = options.delete(:klass) || raise(ArgumentError, "Need a HappyMapper class to parse")
|
39
|
+
|
40
|
+
conn_options = {
|
41
|
+
:url => url,
|
42
|
+
:klass => klass
|
43
|
+
}
|
44
|
+
|
45
|
+
response = connection(conn_options).send(method) do |request|
|
46
|
+
request.headers['Accept'] = options.delete(:accept) || 'application/xml'
|
47
|
+
|
48
|
+
case method
|
49
|
+
when :get, :delete, :head
|
50
|
+
request.url(path, options)
|
51
|
+
when :patch, :post, :put
|
52
|
+
request.headers['Content-Type'] = "application/xml; charset=utf-8"
|
53
|
+
|
54
|
+
request.path = path
|
55
|
+
request.body = options[:body].to_xml unless options.empty?
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
response
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?>
|
2
|
+
<chart>
|
3
|
+
<series>
|
4
|
+
<value xid="0">Sep</value>
|
5
|
+
<value xid="1">Oct</value>
|
6
|
+
<value xid="2">Nov</value>
|
7
|
+
<value xid="3">Dec</value>
|
8
|
+
<value xid="4">Jan</value>
|
9
|
+
<value xid="5">Feb</value>
|
10
|
+
</series>
|
11
|
+
<graphs>
|
12
|
+
<graph gid="invoicing">
|
13
|
+
<value xid="0">0</value>
|
14
|
+
<value xid="1">0</value>
|
15
|
+
<value xid="2">0</value>
|
16
|
+
<value xid="3">0</value>
|
17
|
+
<value xid="4">0</value>
|
18
|
+
<value xid="5">60</value>
|
19
|
+
</graph>
|
20
|
+
</graphs>
|
21
|
+
</chart>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<quarterly-results>
|
3
|
+
<year>2010</year>
|
4
|
+
<currency>€</currency>
|
5
|
+
<quarter-01>
|
6
|
+
<invoicing>60.0</invoicing>
|
7
|
+
<taxes>0.0</taxes>
|
8
|
+
<ytd></ytd>
|
9
|
+
</quarter-01>
|
10
|
+
<quarter-02>
|
11
|
+
<invoicing>0</invoicing>
|
12
|
+
<taxes>0</taxes>
|
13
|
+
<ytd></ytd>
|
14
|
+
</quarter-02>
|
15
|
+
<quarter-03>
|
16
|
+
<invoicing>0</invoicing>
|
17
|
+
<taxes>0</taxes>
|
18
|
+
<ytd></ytd>
|
19
|
+
</quarter-03>
|
20
|
+
<quarter-04>
|
21
|
+
<invoicing>0</invoicing>
|
22
|
+
<taxes>0</taxes>
|
23
|
+
<ytd></ytd>
|
24
|
+
</quarter-04>
|
25
|
+
</quarterly-results>
|
@@ -0,0 +1,49 @@
|
|
1
|
+
<chart>
|
2
|
+
<series>
|
3
|
+
<value xid="0">Jan</value>
|
4
|
+
<value xid="1">Fev</value>
|
5
|
+
<value xid="2">Mar</value>
|
6
|
+
<value xid="3">Abr</value>
|
7
|
+
<value xid="4">Mai</value>
|
8
|
+
<value xid="5">Jun</value>
|
9
|
+
<value xid="6">Jul</value>
|
10
|
+
</series>
|
11
|
+
<graphs>
|
12
|
+
<graph title="Recebido" gid="settled_values">
|
13
|
+
<value xid="0">0</value>
|
14
|
+
<value xid="1">0</value>
|
15
|
+
<value xid="2">0</value>
|
16
|
+
<value xid="3">0</value>
|
17
|
+
<value xid="4">0</value>
|
18
|
+
<value xid="5">0</value>
|
19
|
+
<value xid="6">0</value>
|
20
|
+
</graph>
|
21
|
+
<graph title="Dentro Prazo" gid="due_values">
|
22
|
+
<value xid="0">0</value>
|
23
|
+
<value xid="1">0</value>
|
24
|
+
<value xid="2">0</value>
|
25
|
+
<value xid="3">0</value>
|
26
|
+
<value xid="4">0</value>
|
27
|
+
<value xid="5">0</value>
|
28
|
+
<value xid="6">0</value>
|
29
|
+
</graph>
|
30
|
+
<graph title="Vencido" gid="overdue_values">
|
31
|
+
<value xid="0">0</value>
|
32
|
+
<value xid="1">60</value>
|
33
|
+
<value xid="2">0</value>
|
34
|
+
<value xid="3">0</value>
|
35
|
+
<value xid="4">0</value>
|
36
|
+
<value xid="5">0</value>
|
37
|
+
<value xid="6">0</value>
|
38
|
+
</graph>
|
39
|
+
<graph title="Previsão" gid="forecast_values">
|
40
|
+
<value xid="0">0</value>
|
41
|
+
<value xid="1">60</value>
|
42
|
+
<value xid="2">0</value>
|
43
|
+
<value xid="3">0</value>
|
44
|
+
<value xid="4">0</value>
|
45
|
+
<value xid="5">0</value>
|
46
|
+
<value xid="6">0</value>
|
47
|
+
</graph>
|
48
|
+
</graphs>
|
49
|
+
</chart>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<client>
|
3
|
+
<id>345</id>
|
4
|
+
<name>Bruce Norris</name>
|
5
|
+
<code>1337</code>
|
6
|
+
<email>foo@bar.com</email>
|
7
|
+
<address>Badgad</address>
|
8
|
+
<postal_code>123-456</postal_code>
|
9
|
+
<fiscal_id>1122331122</fiscal_id>
|
10
|
+
<website>www.brucenorris.com</website>
|
11
|
+
<phone>4433551242</phone>
|
12
|
+
<fax>4433551243</fax>
|
13
|
+
<preferred_contact>
|
14
|
+
<name>Rui Alves</name>
|
15
|
+
<email>xpto@xpto.pt</email>
|
16
|
+
<phone>4433551242</phone>
|
17
|
+
</preferred_contact>
|
18
|
+
<observations>Computer Processed</observations>
|
19
|
+
<send_options>1</send_options>
|
20
|
+
<!-- 1 - Original -->
|
21
|
+
</client>
|