invoice_printer 1.2.0.alpha1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/docs/SERVER.md +7 -1
- data/examples/clients/node.js +125 -0
- data/lib/invoice_printer/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ddd0a166f35069b45db3f5c65500c8266944d76
|
4
|
+
data.tar.gz: a40efb4a2f1dabf24979ec48e55687ef372f8800
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c3f7dd04900eb6c8f9dc8d33af717a8478b67b8e0102e1ff16a884572ba72a9539b8da828cbd87a87bef8a684c051e865e5394fd549b3da461b8d77c353a78b
|
7
|
+
data.tar.gz: 941c1108dd6881bb4a6712070da699074dd34c430eb782409a01efb79d9453e884dc235eacf1a42a74a17ac67eb2005f0b8506855563eaa5d3fdcccef6ba32f1
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
- **Simple**, no styling required, no calculation, no money formatting (bring your own)
|
10
10
|
- **Pure Ruby**, no dependency on system libraries or browsers
|
11
|
-
- **Fast**, so you can render
|
11
|
+
- **Fast**, so you can render invoices on the fly during requests
|
12
12
|
|
13
13
|
## Examples
|
14
14
|
|
data/docs/SERVER.md
CHANGED
@@ -62,7 +62,9 @@ On error a `400` response is returned:
|
|
62
62
|
{ "result": "error", "error": "error description" }
|
63
63
|
```
|
64
64
|
|
65
|
-
####
|
65
|
+
#### Examples
|
66
|
+
|
67
|
+
##### curl
|
66
68
|
|
67
69
|
Example of calling the API to render a document using `curl`:
|
68
70
|
|
@@ -70,6 +72,10 @@ Example of calling the API to render a document using `curl`:
|
|
70
72
|
$ curl -X POST http://0.0.0.0:9393/render -H "Content-Type: application/json" --data '{"document":{"number":"c. 198900000001","provider_name":"Petr Novy","provider_tax_id":"56565656","provider_tax_id2":"","provider_street":"Rolnicka","provider_street_number":"1","provider_postcode":"747 05","provider_city":"Opava","provider_city_part":"Katerinky","provider_extra_address_line":"","purchaser_name":"Adam Cerny","purchaser_tax_id":"","purchaser_tax_id2":"","purchaser_street":"Ostravska","purchaser_street_number":"1","purchaser_postcode":"747 70","purchaser_city":"Opava","purchaser_city_part":"","purchaser_extra_address_line":"","issue_date":"05/03/2016","due_date":"19/03/2016","subtotal":"Kc 10.000","tax":"Kc 2.100","tax2":"","tax3":"","total":"Kc 12.100,-","bank_account_number":"156546546465","account_iban":"IBAN464545645","account_swift":"SWIFT5456","items":[{"name":"Konzultace","quantity":"2","unit":"hod","price":"Kc 500","tax":"","tax2":"","tax3":"","amount":"Kc 1.000"},{"name":"Programovani","quantity":"10","unit":"hod","price":"Kc 900","tax":"","tax2":"","tax3":"","amount":"Kc 9.000"}],"note":"Osoba je zapsána v zivnostenském rejstríku."}}'
|
71
73
|
```
|
72
74
|
|
75
|
+
##### Node.js
|
76
|
+
|
77
|
+
See [/examples/clients/node.js](/examples/clients/node.js).
|
78
|
+
|
73
79
|
### `POST /print`
|
74
80
|
|
75
81
|
Print resulting document to a file.
|
@@ -0,0 +1,125 @@
|
|
1
|
+
// Example: Create a PDF invoice and save it to a file called invoice_from_node.pdf
|
2
|
+
//
|
3
|
+
// This example requires InvoicePrinter Server to be running.
|
4
|
+
//
|
5
|
+
// You can run the server as:
|
6
|
+
// $ invoice_printer_server
|
7
|
+
//
|
8
|
+
// And run this example as:
|
9
|
+
// $ node node.js
|
10
|
+
|
11
|
+
const invoice = {
|
12
|
+
"number": "NO. 198900000001",
|
13
|
+
"provider_name": "John White",
|
14
|
+
"provider_tax_id": "",
|
15
|
+
"provider_tax_id2": "",
|
16
|
+
"provider_street": "5th Avenue",
|
17
|
+
"provider_street_number": "1",
|
18
|
+
"provider_postcode": "747 05",
|
19
|
+
"provider_city": "NYC",
|
20
|
+
"provider_city_part": "",
|
21
|
+
"provider_extra_address_line": "",
|
22
|
+
"purchaser_name": "Will Black",
|
23
|
+
"purchaser_tax_id": "",
|
24
|
+
"purchaser_tax_id2": "",
|
25
|
+
"purchaser_street": "7th Avenue",
|
26
|
+
"purchaser_street_number": "1",
|
27
|
+
"purchaser_postcode": "747 70",
|
28
|
+
"purchaser_city": "NYC",
|
29
|
+
"purchaser_city_part": "",
|
30
|
+
"purchaser_extra_address_line": "",
|
31
|
+
"issue_date": "05/03/2016",
|
32
|
+
"due_date": "19/03/2016",
|
33
|
+
"subtotal": "$ 1,000",
|
34
|
+
"tax": "$ 100",
|
35
|
+
"tax2": "",
|
36
|
+
"tax3": "",
|
37
|
+
"total": "$ 1,100",
|
38
|
+
"bank_account_number": "156546546465",
|
39
|
+
"account_iban": "",
|
40
|
+
"account_swift": "",
|
41
|
+
"items": [
|
42
|
+
{
|
43
|
+
"name": "Programming",
|
44
|
+
"quantity": "10",
|
45
|
+
"unit": "hr",
|
46
|
+
"price": "$ 60",
|
47
|
+
"tax": "$ 60",
|
48
|
+
"tax2": "",
|
49
|
+
"tax3": "",
|
50
|
+
"amount": "$ 600"
|
51
|
+
},
|
52
|
+
{
|
53
|
+
"name": "Consulting",
|
54
|
+
"quantity": "10",
|
55
|
+
"unit": "hr",
|
56
|
+
"price": "$ 30",
|
57
|
+
"tax": "$ 30",
|
58
|
+
"tax2": "",
|
59
|
+
"tax3": "",
|
60
|
+
"amount": "$ 300"
|
61
|
+
},
|
62
|
+
{
|
63
|
+
"name": "Support",
|
64
|
+
"quantity": "20",
|
65
|
+
"unit": "hr",
|
66
|
+
"price": "$ 15",
|
67
|
+
"tax": "$ 30",
|
68
|
+
"tax2": "",
|
69
|
+
"tax3": "",
|
70
|
+
"amount": "$ 330"
|
71
|
+
}
|
72
|
+
],
|
73
|
+
"note": "This is a note at the end."
|
74
|
+
}
|
75
|
+
|
76
|
+
const http = require('http');
|
77
|
+
const fs = require('fs');
|
78
|
+
|
79
|
+
// Prepare the JSON in the expected format
|
80
|
+
const postData = JSON.stringify({
|
81
|
+
"document" : invoice
|
82
|
+
});
|
83
|
+
|
84
|
+
// Prepare POST options such as correct headers
|
85
|
+
const postOptions = {
|
86
|
+
host: 'localhost',
|
87
|
+
port: '9393',
|
88
|
+
path: '/render',
|
89
|
+
method: 'POST',
|
90
|
+
headers: {
|
91
|
+
'Content-Type': 'application/json'
|
92
|
+
}
|
93
|
+
};
|
94
|
+
|
95
|
+
const postRequest = http.request(postOptions, (resp) => {
|
96
|
+
let data = '';
|
97
|
+
|
98
|
+
resp.on('data', (chunk) => {
|
99
|
+
data += chunk;
|
100
|
+
});
|
101
|
+
|
102
|
+
// Save the PDF if everything went okay
|
103
|
+
resp.on('end', () => {
|
104
|
+
response = JSON.parse(data);
|
105
|
+
|
106
|
+
if (response["data"]) {
|
107
|
+
const pdf = Buffer.from(response["data"], 'base64');
|
108
|
+
|
109
|
+
fs.writeFile("invoice_from_node.pdf", pdf, function(err) {
|
110
|
+
if(err) {
|
111
|
+
return console.log(err);
|
112
|
+
}
|
113
|
+
|
114
|
+
console.log("The file was saved!");
|
115
|
+
});
|
116
|
+
} else {
|
117
|
+
console.log("Error: " + response["error"])
|
118
|
+
}
|
119
|
+
});
|
120
|
+
}).on("error", (err) => {
|
121
|
+
console.log("Error: " + err.message);
|
122
|
+
});
|
123
|
+
|
124
|
+
postRequest.write(postData);
|
125
|
+
postRequest.end();
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: invoice_printer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josef Strzibny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- docs/LIBRARY.md
|
131
131
|
- docs/SERVER.md
|
132
132
|
- examples/background.png
|
133
|
+
- examples/clients/node.js
|
133
134
|
- examples/complex_invoice.rb
|
134
135
|
- examples/czech_invoice.rb
|
135
136
|
- examples/international_invoice.rb
|
@@ -176,12 +177,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
176
177
|
version: '0'
|
177
178
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
179
|
requirements:
|
179
|
-
- - "
|
180
|
+
- - ">="
|
180
181
|
- !ruby/object:Gem::Version
|
181
|
-
version:
|
182
|
+
version: '0'
|
182
183
|
requirements: []
|
183
184
|
rubyforge_project:
|
184
|
-
rubygems_version: 2.6.14
|
185
|
+
rubygems_version: 2.6.14.1
|
185
186
|
signing_key:
|
186
187
|
specification_version: 4
|
187
188
|
summary: Super simple PDF invoicing in pure Ruby
|