invoice_printer 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3804819a2872ad56e4ec83888f44bcb2990a9bdf
4
- data.tar.gz: 0bfe521b32c6bc434856ee0429ebc87583ab925c
3
+ metadata.gz: 84c63166563f07600da5c24502fe65718efa116e
4
+ data.tar.gz: 42db457839724f952cbf2b236452bae952d17457
5
5
  SHA512:
6
- metadata.gz: 801fa6d6d828e9a8f413189b8b45e1a56a7819733c8f9135345430fc32d49c9997e00a54b90c2ec1988ffecd88c7baf3ece2d27fc66182fc035af345b007b33b
7
- data.tar.gz: 1bc178261625fcc5a87d9587ce4fee878d6ff79692f003081768c2af51653d9e3b97b690bfef95e38e3dba05039b819e1c264053cdf1de2febef221129389254
6
+ metadata.gz: f8062350622bb3d92c942faf0afa56668b3da088c2894c66e3138e9c88c990434898150517bfb3dc57997ee7ac090b288cc538293ed17e69053f0e2342925726
7
+ data.tar.gz: 3b9315eaf70122a9ad504bcae26f8520193ff4e5c467a49569123f7308b9f76321ca0c6f3a0d7b8858ee88574af213f6111ee105ba4042516b6c4ec5fea4f343
@@ -0,0 +1,500 @@
1
+ %PDF-1.3
2
+ %����
3
+ 1 0 obj
4
+ << /Creator <feff0050007200610077006e>
5
+ /Producer <feff0050007200610077006e>
6
+ >>
7
+ endobj
8
+ 2 0 obj
9
+ << /Type /Catalog
10
+ /Pages 3 0 R
11
+ >>
12
+ endobj
13
+ 3 0 obj
14
+ << /Type /Pages
15
+ /Count 1
16
+ /Kids [5 0 R]
17
+ >>
18
+ endobj
19
+ 4 0 obj
20
+ << /Length 5402
21
+ >>
22
+ stream
23
+ q
24
+ /DeviceRGB cs
25
+ 0.000 0.000 0.000 scn
26
+
27
+ BT
28
+ 36.0 741.64 Td
29
+ /F1.0 20 Tf
30
+ [<496e> 20 <76> 25 <6f696365>] TJ
31
+ ET
32
+
33
+
34
+ BT
35
+ 402.24 741.64 Td
36
+ /F1.0 20 Tf
37
+ [<4e4f> 40 <2e20313938393030303030303031>] TJ
38
+ ET
39
+
40
+
41
+ BT
42
+ 46.0 688.82 Td
43
+ /F1.0 10 Tf
44
+ [<50726f> 15 <7669646572>] TJ
45
+ ET
46
+
47
+
48
+ BT
49
+ 46.0 665.948 Td
50
+ /F1.0 14 Tf
51
+ [<4a6f686e205768697465>] TJ
52
+ ET
53
+
54
+
55
+ BT
56
+ 46.0 648.82 Td
57
+ /F1.0 10 Tf
58
+ [<3574682041> 40 <76> 25 <656e> 10 <75652020202031>] TJ
59
+ ET
60
+
61
+
62
+ BT
63
+ 46.0 633.82 Td
64
+ /F1.0 10 Tf
65
+ [<373437203035>] TJ
66
+ ET
67
+
68
+
69
+ BT
70
+ 96.0 633.82 Td
71
+ /F1.0 10 Tf
72
+ [<4e5943>] TJ
73
+ ET
74
+
75
+
76
+ BT
77
+ 326.0 688.82 Td
78
+ /F1.0 10 Tf
79
+ [<507572636861736572>] TJ
80
+ ET
81
+
82
+
83
+ BT
84
+ 326.0 665.948 Td
85
+ /F1.0 14 Tf
86
+ [<57696c6c20426c6163> 20 <6b>] TJ
87
+ ET
88
+
89
+
90
+ BT
91
+ 326.0 648.82 Td
92
+ /F1.0 10 Tf
93
+ [<3774682041> 40 <76> 25 <656e> 10 <75652020202031>] TJ
94
+ ET
95
+
96
+
97
+ BT
98
+ 326.0 633.82 Td
99
+ /F1.0 10 Tf
100
+ [<373437203730>] TJ
101
+ ET
102
+
103
+
104
+ BT
105
+ 376.0 633.82 Td
106
+ /F1.0 10 Tf
107
+ [<4e5943>] TJ
108
+ ET
109
+
110
+ 42.0 706.0 m
111
+ 300.0 706.0 l
112
+ 303.3137 706.0 306.0 703.3137 306.0 700.0 c
113
+ 306.0 562.0 l
114
+ 306.0 558.6863 303.3137 556.0 300.0 556.0 c
115
+ 42.0 556.0 l
116
+ 38.6863 556.0 36.0 558.6863 36.0 562.0 c
117
+ 36.0 700.0 l
118
+ 36.0 703.3137 38.6863 706.0 42.0 706.0 c
119
+ h
120
+ S
121
+ 322.0 706.0 m
122
+ 580.0 706.0 l
123
+ 583.3137 706.0 586.0 703.3137 586.0 700.0 c
124
+ 586.0 562.0 l
125
+ 586.0 558.6863 583.3137 556.0 580.0 556.0 c
126
+ 322.0 556.0 l
127
+ 318.6863 556.0 316.0 558.6863 316.0 562.0 c
128
+ 316.0 700.0 l
129
+ 316.0 703.3137 318.6863 706.0 322.0 706.0 c
130
+ h
131
+ S
132
+
133
+ BT
134
+ 46.0 518.82 Td
135
+ /F1.0 10 Tf
136
+ [<50> 40 <61> 30 <796d656e742062> 20 <792062616e6b207472> 10 <616e7366> 30 <6572206f6e20746865206163636f756e742062656c6f> 15 <773a>] TJ
137
+ ET
138
+
139
+
140
+ BT
141
+ 46.0 503.82 Td
142
+ /F1.0 10 Tf
143
+ [<4163636f756e74204e4f3a>] TJ
144
+ ET
145
+
146
+
147
+ BT
148
+ 111.0 503.82 Td
149
+ /F1.0 10 Tf
150
+ [<313536353436353436343635>] TJ
151
+ ET
152
+
153
+ 42.0 536.0 m
154
+ 300.0 536.0 l
155
+ 303.3137 536.0 306.0 533.3137 306.0 530.0 c
156
+ 306.0 497.0 l
157
+ 306.0 493.6863 303.3137 491.0 300.0 491.0 c
158
+ 42.0 491.0 l
159
+ 38.6863 491.0 36.0 493.6863 36.0 497.0 c
160
+ 36.0 530.0 l
161
+ 36.0 533.3137 38.6863 536.0 42.0 536.0 c
162
+ h
163
+ S
164
+
165
+ BT
166
+ 326.0 518.82 Td
167
+ /F1.0 10 Tf
168
+ [<497373756520646174653a>] TJ
169
+ ET
170
+
171
+
172
+ BT
173
+ 426.0 518.82 Td
174
+ /F1.0 10 Tf
175
+ [<30352f30332f32303136>] TJ
176
+ ET
177
+
178
+
179
+ BT
180
+ 326.0 503.82 Td
181
+ /F1.0 10 Tf
182
+ [<44756520646174653a>] TJ
183
+ ET
184
+
185
+
186
+ BT
187
+ 426.0 503.82 Td
188
+ /F1.0 10 Tf
189
+ [<31392f30332f32303136>] TJ
190
+ ET
191
+
192
+ 322.0 536.0 m
193
+ 580.0 536.0 l
194
+ 583.3137 536.0 586.0 533.3137 586.0 530.0 c
195
+ 586.0 497.0 l
196
+ 586.0 493.6863 583.3137 491.0 580.0 491.0 c
197
+ 322.0 491.0 l
198
+ 318.6863 491.0 316.0 493.6863 316.0 497.0 c
199
+ 316.0 530.0 l
200
+ 316.0 533.3137 318.6863 536.0 322.0 536.0 c
201
+ h
202
+ S
203
+ 0.961 0.961 0.961 scn
204
+ 36.0 395.008 148.6971 22.872 re
205
+ f
206
+ 0.000 0.000 0.000 scn
207
+ 1 w
208
+ 36.0 418.38 m
209
+ 36.0 393.508 l
210
+ S
211
+ 184.6971 418.38 m
212
+ 184.6971 393.508 l
213
+ S
214
+ 36.0 417.88 m
215
+ 184.6971 417.88 l
216
+ S
217
+ 36.0 394.008 m
218
+ 184.6971 394.008 l
219
+ S
220
+ /DeviceRGB CS
221
+ 0.000 0.000 0.000 SCN
222
+ 1 w
223
+
224
+ BT
225
+ 41.0 401.636 Td
226
+ /F1.0 12 Tf
227
+ [<4974656d>] TJ
228
+ ET
229
+
230
+ 0.000 0.000 0.000 scn
231
+ 0.961 0.961 0.961 scn
232
+ 184.6971 395.008 98.5342 22.872 re
233
+ f
234
+ 0.000 0.000 0.000 scn
235
+ 1 w
236
+ 184.6971 418.38 m
237
+ 184.6971 393.508 l
238
+ S
239
+ 283.2313 418.38 m
240
+ 283.2313 393.508 l
241
+ S
242
+ 184.6971 417.88 m
243
+ 283.2313 417.88 l
244
+ S
245
+ 184.6971 394.008 m
246
+ 283.2313 394.008 l
247
+ S
248
+ 0.000 0.000 0.000 SCN
249
+ 1 w
250
+
251
+ BT
252
+ 233.5433 401.636 Td
253
+ /F1.0 12 Tf
254
+ [<5175616e74697479>] TJ
255
+ ET
256
+
257
+ 0.000 0.000 0.000 scn
258
+ 0.961 0.961 0.961 scn
259
+ 283.2313 395.008 57.329 22.872 re
260
+ f
261
+ 0.000 0.000 0.000 scn
262
+ 1 w
263
+ 283.2313 418.38 m
264
+ 283.2313 393.508 l
265
+ S
266
+ 340.5603 418.38 m
267
+ 340.5603 393.508 l
268
+ S
269
+ 283.2313 417.88 m
270
+ 340.5603 417.88 l
271
+ S
272
+ 283.2313 394.008 m
273
+ 340.5603 394.008 l
274
+ S
275
+ 0.000 0.000 0.000 SCN
276
+ 1 w
277
+
278
+ BT
279
+ 314.2243 401.636 Td
280
+ /F1.0 12 Tf
281
+ [<556e6974>] TJ
282
+ ET
283
+
284
+ 0.000 0.000 0.000 scn
285
+ 0.961 0.961 0.961 scn
286
+ 340.5603 395.008 152.2801 22.872 re
287
+ f
288
+ 0.000 0.000 0.000 scn
289
+ 1 w
290
+ 340.5603 418.38 m
291
+ 340.5603 393.508 l
292
+ S
293
+ 492.8404 418.38 m
294
+ 492.8404 393.508 l
295
+ S
296
+ 340.5603 417.88 m
297
+ 492.8404 417.88 l
298
+ S
299
+ 340.5603 394.008 m
300
+ 492.8404 394.008 l
301
+ S
302
+ 0.000 0.000 0.000 SCN
303
+ 1 w
304
+
305
+ BT
306
+ 413.6444 401.636 Td
307
+ /F1.0 12 Tf
308
+ [<5072> -15 <69636520706572206974656d>] TJ
309
+ ET
310
+
311
+ 0.000 0.000 0.000 scn
312
+ 0.961 0.961 0.961 scn
313
+ 492.8404 395.008 93.1596 22.872 re
314
+ f
315
+ 0.000 0.000 0.000 scn
316
+ 1 w
317
+ 492.8404 418.38 m
318
+ 492.8404 393.508 l
319
+ S
320
+ 586.0 418.38 m
321
+ 586.0 393.508 l
322
+ S
323
+ 492.8404 417.88 m
324
+ 586.0 417.88 l
325
+ S
326
+ 492.8404 394.008 m
327
+ 586.0 394.008 l
328
+ S
329
+ 0.000 0.000 0.000 SCN
330
+ 1 w
331
+
332
+ BT
333
+ 539.648 401.636 Td
334
+ /F1.0 12 Tf
335
+ [<416d6f756e74>] TJ
336
+ ET
337
+
338
+ 0.000 0.000 0.000 scn
339
+ 1 w
340
+ 36.0 394.508 m
341
+ 36.0 369.636 l
342
+ S
343
+ 184.6971 394.508 m
344
+ 184.6971 369.636 l
345
+ S
346
+ 36.0 370.136 m
347
+ 184.6971 370.136 l
348
+ S
349
+ 0.000 0.000 0.000 SCN
350
+ 1 w
351
+
352
+ BT
353
+ 41.0 377.764 Td
354
+ /F1.0 12 Tf
355
+ [<50726f67> 10 <72> 10 <616d6d696e67>] TJ
356
+ ET
357
+
358
+ 0.000 0.000 0.000 scn
359
+ 1 w
360
+ 184.6971 394.508 m
361
+ 184.6971 369.636 l
362
+ S
363
+ 283.2313 394.508 m
364
+ 283.2313 369.636 l
365
+ S
366
+ 184.6971 370.136 m
367
+ 283.2313 370.136 l
368
+ S
369
+ 0.000 0.000 0.000 SCN
370
+ 1 w
371
+
372
+ BT
373
+ 264.8873 377.764 Td
374
+ /F1.0 12 Tf
375
+ [<3130>] TJ
376
+ ET
377
+
378
+ 0.000 0.000 0.000 scn
379
+ 1 w
380
+ 283.2313 394.508 m
381
+ 283.2313 369.636 l
382
+ S
383
+ 340.5603 394.508 m
384
+ 340.5603 369.636 l
385
+ S
386
+ 283.2313 370.136 m
387
+ 340.5603 370.136 l
388
+ S
389
+ 0.000 0.000 0.000 SCN
390
+ 1 w
391
+
392
+ BT
393
+ 324.8923 377.764 Td
394
+ /F1.0 12 Tf
395
+ [<6872>] TJ
396
+ ET
397
+
398
+ 0.000 0.000 0.000 scn
399
+ 1 w
400
+ 340.5603 394.508 m
401
+ 340.5603 369.636 l
402
+ S
403
+ 492.8404 394.508 m
404
+ 492.8404 369.636 l
405
+ S
406
+ 340.5603 370.136 m
407
+ 492.8404 370.136 l
408
+ S
409
+ 0.000 0.000 0.000 SCN
410
+ 1 w
411
+
412
+ BT
413
+ 464.4884 377.764 Td
414
+ /F1.0 12 Tf
415
+ [<24203930>] TJ
416
+ ET
417
+
418
+ 0.000 0.000 0.000 scn
419
+ 1 w
420
+ 492.8404 394.508 m
421
+ 492.8404 369.636 l
422
+ S
423
+ 586.0 394.508 m
424
+ 586.0 369.636 l
425
+ S
426
+ 492.8404 370.136 m
427
+ 586.0 370.136 l
428
+ S
429
+ 0.000 0.000 0.000 SCN
430
+ 1 w
431
+
432
+ BT
433
+ 550.976 377.764 Td
434
+ /F1.0 12 Tf
435
+ [<2420393030>] TJ
436
+ ET
437
+
438
+ 0.000 0.000 0.000 scn
439
+
440
+ BT
441
+ 480.352 318.648 Td
442
+ /F2.0 16 Tf
443
+ [<54> 80 <6f74616c3a2020202420393030>] TJ
444
+ ET
445
+
446
+
447
+ BT
448
+ 552.648 27.384 Td
449
+ /F1.0 12 Tf
450
+ [<31202f2031>] TJ
451
+ ET
452
+
453
+ Q
454
+
455
+ endstream
456
+ endobj
457
+ 5 0 obj
458
+ << /Type /Page
459
+ /Parent 3 0 R
460
+ /MediaBox [0 0 612.0 792.0]
461
+ /Contents 4 0 R
462
+ /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
463
+ /Font << /F1.0 6 0 R
464
+ /F2.0 7 0 R
465
+ >>
466
+ >>
467
+ >>
468
+ endobj
469
+ 6 0 obj
470
+ << /Type /Font
471
+ /Subtype /Type1
472
+ /BaseFont /Helvetica
473
+ /Encoding /WinAnsiEncoding
474
+ >>
475
+ endobj
476
+ 7 0 obj
477
+ << /Type /Font
478
+ /Subtype /Type1
479
+ /BaseFont /Helvetica-Bold
480
+ /Encoding /WinAnsiEncoding
481
+ >>
482
+ endobj
483
+ xref
484
+ 0 8
485
+ 0000000000 65535 f
486
+ 0000000015 00000 n
487
+ 0000000109 00000 n
488
+ 0000000158 00000 n
489
+ 0000000215 00000 n
490
+ 0000005669 00000 n
491
+ 0000005859 00000 n
492
+ 0000005956 00000 n
493
+ trailer
494
+ << /Size 8
495
+ /Root 2 0 R
496
+ /Info 1 0 R
497
+ >>
498
+ startxref
499
+ 6058
500
+ %%EOF
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ # This is an example of a very simple invoice.
3
+
4
+ lib = File.expand_path('../../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'invoice_printer'
7
+
8
+ item = InvoicePrinter::Document::Item.new(
9
+ name: 'Programming',
10
+ quantity: '10',
11
+ unit: 'hr',
12
+ price: '$ 90',
13
+ amount: '$ 900'
14
+ )
15
+
16
+ invoice = InvoicePrinter::Document.new(
17
+ number: 'NO. 198900000001',
18
+ provider_name: 'John White',
19
+ provider_street: '5th Avenue',
20
+ provider_street_number: '1',
21
+ provider_postcode: '747 05',
22
+ provider_city: 'NYC',
23
+ purchaser_name: 'Will Black',
24
+ purchaser_street: '7th Avenue',
25
+ purchaser_street_number: '1',
26
+ purchaser_postcode: '747 70',
27
+ purchaser_city: 'NYC',
28
+ issue_date: '05/03/2016',
29
+ due_date: '19/03/2016',
30
+ total: '$ 900',
31
+ bank_account_number: '156546546465',
32
+ items: [item]
33
+ )
34
+
35
+ InvoicePrinter.print(
36
+ document: invoice,
37
+ file_name: 'simple_invoice.pdf'
38
+ )
@@ -40,6 +40,8 @@ module InvoicePrinter
40
40
  # +amount should equal the sum of all item's +amount+,
41
41
  # but this is not enforced.
42
42
  class Document
43
+ class InvalidInput < StandardError; end
44
+
43
45
  attr_reader :number,
44
46
  # Provider fields
45
47
  :provider_name,
@@ -107,36 +109,39 @@ module InvoicePrinter
107
109
  account_iban: nil,
108
110
  account_swift: nil,
109
111
  items: nil)
110
- @number = number
111
- @provider_name = provider_name
112
- @provider_ic = provider_ic
113
- @provider_dic = provider_dic
114
- @provider_street = provider_street
115
- @provider_street_number = provider_street_number
116
- @provider_postcode = provider_postcode
117
- @provider_city = provider_city
118
- @provider_city_part = provider_city_part
119
- @provider_extra_address_line = provider_extra_address_line
120
- @purchaser_name = purchaser_name
121
- @purchaser_ic = purchaser_ic
122
- @purchaser_dic = purchaser_dic
123
- @purchaser_street = purchaser_street
124
- @purchaser_street_number = purchaser_street_number
125
- @purchaser_postcode = purchaser_postcode
126
- @purchaser_city = purchaser_city
127
- @purchaser_city_part = purchaser_city_part
128
- @purchaser_extra_address_line = purchaser_extra_address_line
129
- @issue_date = issue_date
130
- @due_date = due_date
131
- @subtotal = subtotal
132
- @tax = tax
133
- @tax2 = tax2
134
- @tax3 = tax3
135
- @total = total
136
- @bank_account_number = bank_account_number
137
- @account_iban = account_iban
138
- @account_swift = account_swift
112
+ @number = String(number)
113
+ @provider_name = String(provider_name)
114
+ @provider_ic = String(provider_ic)
115
+ @provider_dic = String(provider_dic)
116
+ @provider_street = String(provider_street)
117
+ @provider_street_number = String(provider_street_number)
118
+ @provider_postcode = String(provider_postcode)
119
+ @provider_city = String(provider_city)
120
+ @provider_city_part = String(provider_city_part)
121
+ @provider_extra_address_line = String(provider_extra_address_line)
122
+ @purchaser_name = String(purchaser_name)
123
+ @purchaser_ic = String(purchaser_ic)
124
+ @purchaser_dic = String(purchaser_dic)
125
+ @purchaser_street = String(purchaser_street)
126
+ @purchaser_street_number = String(purchaser_street_number)
127
+ @purchaser_postcode = String(purchaser_postcode)
128
+ @purchaser_city = String(purchaser_city)
129
+ @purchaser_city_part = String(purchaser_city_part)
130
+ @purchaser_extra_address_line = String(purchaser_extra_address_line)
131
+ @issue_date = String(issue_date)
132
+ @due_date = String(due_date)
133
+ @subtotal = String(subtotal)
134
+ @tax = String(tax)
135
+ @tax2 = String(tax2)
136
+ @tax3 = String(tax3)
137
+ @total = String(total)
138
+ @bank_account_number = String(bank_account_number)
139
+ @account_iban = String(account_iban)
140
+ @account_swift = String(account_swift)
139
141
  @items = items
142
+
143
+ raise InvalidInput, 'items are not only a type of InvoicePrinter::Document::Item' \
144
+ unless @items.select{ |i| !i.is_a?(InvoicePrinter::Document::Item) }.empty?
140
145
  end
141
146
  end
142
147
  end
@@ -35,14 +35,14 @@ module InvoicePrinter
35
35
  tax2: nil,
36
36
  tax3: nil,
37
37
  amount: nil)
38
- @name = name
39
- @quantity = quantity
40
- @unit = unit
41
- @price = price
42
- @tax = tax
43
- @tax2 = tax2
44
- @tax3 = tax3
45
- @amount = amount
38
+ @name = String(name)
39
+ @quantity = String(quantity)
40
+ @unit = String(unit)
41
+ @price = String(price)
42
+ @tax = String(tax)
43
+ @tax2 = String(tax2)
44
+ @tax3 = String(tax3)
45
+ @amount = String(amount)
46
46
  end
47
47
  end
48
48
  end
@@ -14,10 +14,11 @@ module InvoicePrinter
14
14
  # logo: 'example.jpg'
15
15
  # )
16
16
  class PDFDocument
17
- attr_reader :invoice, :labels, :file_name, :font, :logo
18
-
19
17
  class FontFileNotFound < StandardError; end
20
18
  class LogoFileNotFound < StandardError; end
19
+ class InvalidInput < StandardError; end
20
+
21
+ attr_reader :invoice, :labels, :file_name, :font, :logo
21
22
 
22
23
  DEFAULT_LABELS = {
23
24
  name: 'Invoice',
@@ -58,22 +59,28 @@ module InvoicePrinter
58
59
  @document = document
59
60
  @labels = PDFDocument.labels.merge(labels)
60
61
  @pdf = Prawn::Document.new
62
+ @font = font
63
+ @logo = logo
64
+
65
+ raise InvalidInput, 'document is not a type of InvoicePrinter::Document' \
66
+ unless @document.is_a?(InvoicePrinter::Document)
61
67
 
62
- if logo && !logo.empty?
63
- if File.exist?(logo)
68
+ if @logo && !@logo.empty?
69
+ if File.exist?(@logo)
64
70
  @logo = logo
65
71
  else
66
- fail LogoFileNotFound, "Logotype file not found at #{logo}"
72
+ raise LogoFileNotFound, "Logotype file not found at #{@logo}"
67
73
  end
68
74
  end
69
75
 
70
- if font && !font.empty?
71
- if File.exist?(font)
72
- set_fonts(font) if font
76
+ if @font && !@font.empty?
77
+ if File.exist?(@font)
78
+ set_fonts(@font) if @font
73
79
  else
74
- fail FontFileNotFound, "Font file not found at #{font}"
80
+ raise FontFileNotFound, "Font file not found at #{@font}"
75
81
  end
76
82
  end
83
+
77
84
  build_pdf
78
85
  end
79
86
 
@@ -98,7 +105,6 @@ module InvoicePrinter
98
105
  bold_italic: font
99
106
  })
100
107
  @pdf.font(font_name)
101
- @font = font_name
102
108
  end
103
109
 
104
110
  def build_pdf
@@ -158,7 +164,7 @@ module InvoicePrinter
158
164
  at: [60, 605],
159
165
  width: 240
160
166
  )
161
- if @document.provider_city_part && !@document.provider_city_part.empty?
167
+ unless @document.provider_city_part.empty?
162
168
  @pdf.text_box(
163
169
  @document.provider_city_part,
164
170
  size: 10,
@@ -166,7 +172,7 @@ module InvoicePrinter
166
172
  width: 240
167
173
  )
168
174
  end
169
- if @document.provider_extra_address_line && !@document.provider_extra_address_line.empty?
175
+ unless @document.provider_extra_address_line.empty?
170
176
  @pdf.text_box(
171
177
  @document.provider_extra_address_line,
172
178
  size: 10,
@@ -174,7 +180,7 @@ module InvoicePrinter
174
180
  width: 240
175
181
  )
176
182
  end
177
- if @document.provider_ic && !@document.provider_ic.empty?
183
+ unless @document.provider_ic.empty?
178
184
  @pdf.text_box(
179
185
  "#{@labels[:ic]}: #{@document.provider_ic}",
180
186
  size: 10,
@@ -182,7 +188,7 @@ module InvoicePrinter
182
188
  width: 240
183
189
  )
184
190
  end
185
- if @document.provider_dic && !@document.provider_dic.empty?
191
+ unless @document.provider_dic.empty?
186
192
  @pdf.text_box(
187
193
  "#{@labels[:dic]}: #{@document.provider_dic}",
188
194
  size: 10,
@@ -223,7 +229,7 @@ module InvoicePrinter
223
229
  at: [340, 605],
224
230
  width: 240
225
231
  )
226
- if @document.purchaser_city_part && !@document.purchaser_city_part.empty?
232
+ unless @document.purchaser_city_part.empty?
227
233
  @pdf.text_box(
228
234
  @document.purchaser_city_part,
229
235
  size: 10,
@@ -231,7 +237,7 @@ module InvoicePrinter
231
237
  width: 240
232
238
  )
233
239
  end
234
- if @document.purchaser_extra_address_line && !@document.purchaser_extra_address_line.empty?
240
+ unless @document.purchaser_extra_address_line.empty?
235
241
  @pdf.text_box(
236
242
  @document.purchaser_extra_address_line,
237
243
  size: 10,
@@ -241,7 +247,7 @@ module InvoicePrinter
241
247
  end
242
248
  @pdf.stroke_rounded_rectangle([0, 670], 270, 150, 6)
243
249
  @pdf.stroke_rounded_rectangle([280, 670], 270, 150, 6)
244
- if @document.purchaser_dic && !@document.purchaser_dic.empty?
250
+ unless @document.purchaser_dic.empty?
245
251
  @pdf.text_box(
246
252
  "#{@labels[:dic]}: #{@document.purchaser_dic}",
247
253
  size: 10,
@@ -249,7 +255,7 @@ module InvoicePrinter
249
255
  width: 240
250
256
  )
251
257
  end
252
- if @document.purchaser_ic && !@document.purchaser_ic.empty?
258
+ unless @document.purchaser_ic.empty?
253
259
  @pdf.text_box(
254
260
  "#{@labels[:ic]}: #{@document.purchaser_ic}",
255
261
  size: 10,
@@ -260,7 +266,7 @@ module InvoicePrinter
260
266
  end
261
267
 
262
268
  def build_payment_method_box
263
- if @document.bank_account_number.nil?
269
+ if @document.bank_account_number.empty?
264
270
  @pdf.stroke_rounded_rectangle([0, 540 - @push_down], 270, 45, 6)
265
271
  @pdf.text_box(
266
272
  @labels[:payment],
@@ -296,7 +302,7 @@ module InvoicePrinter
296
302
  at: [75, 515 - @push_down],
297
303
  width: 240
298
304
  )
299
- if @document.account_swift && !@document.account_swift.empty?
305
+ unless @document.account_swift.empty?
300
306
  @pdf.text_box(
301
307
  "#{@labels[:swift]}:",
302
308
  size: 10,
@@ -312,7 +318,7 @@ module InvoicePrinter
312
318
  box_height += 15
313
319
  push_iban = 15
314
320
  end
315
- if @document.account_iban && !@document.account_iban.empty?
321
+ unless @document.account_iban.empty?
316
322
  @pdf.text_box(
317
323
  "#{@labels[:iban]}:",
318
324
  size: 10,
@@ -331,8 +337,8 @@ module InvoicePrinter
331
337
  end
332
338
 
333
339
  def build_info_box
334
- issue_date_present = @document.issue_date && !@document.issue_date.empty?
335
- due_date_present = @document.due_date && !@document.due_date.empty?
340
+ issue_date_present = !@document.issue_date.empty?
341
+ due_date_present = !@document.due_date.empty?
336
342
  if issue_date_present
337
343
  @pdf.text_box(
338
344
  "#{@labels[:issue_date]}:",
@@ -401,7 +407,7 @@ module InvoicePrinter
401
407
  }
402
408
  }
403
409
 
404
- @pdf.table(items, styles)
410
+ @pdf.table(items, styles) unless items.empty?
405
411
  end
406
412
 
407
413
  # Determine sections of the items table to show based on provided data
@@ -409,14 +415,14 @@ module InvoicePrinter
409
415
  items_params = {}
410
416
 
411
417
  @document.items.each do |item|
412
- items_params[:names] = true if item.name
413
- items_params[:quantities] = true if item.quantity
414
- items_params[:units] = true if item.unit
415
- items_params[:prices] = true if item.price
416
- items_params[:taxes] = true if item.tax
417
- items_params[:taxes2] = true if item.tax2
418
- items_params[:taxes3] = true if item.tax3
419
- items_params[:amounts] = true if item.amount
418
+ items_params[:names] = true unless item.name.empty?
419
+ items_params[:quantities] = true unless item.quantity.empty?
420
+ items_params[:units] = true unless item.unit.empty?
421
+ items_params[:prices] = true unless item.price.empty?
422
+ items_params[:taxes] = true unless item.tax.empty?
423
+ items_params[:taxes2] = true unless item.tax2.empty?
424
+ items_params[:taxes3] = true unless item.tax3.empty?
425
+ items_params[:amounts] = true unless item.amount.empty?
420
426
  end
421
427
 
422
428
  items_params
@@ -466,10 +472,10 @@ module InvoicePrinter
466
472
  @pdf.move_down(25)
467
473
 
468
474
  items = []
469
- items << ["#{@labels[:subtotal]}:", @document.subtotal] if @document.subtotal
470
- items << ["#{@labels[:tax]}:", @document.tax] if @document.tax
471
- items << ["#{@labels[:tax2]}:", @document.tax2] if @document.tax2
472
- items << ["#{@labels[:tax3]}:", @document.tax3] if @document.tax3
475
+ items << ["#{@labels[:subtotal]}:", @document.subtotal] unless @document.subtotal.empty?
476
+ items << ["#{@labels[:tax]}:", @document.tax] unless @document.tax.empty?
477
+ items << ["#{@labels[:tax2]}:", @document.tax2] unless @document.tax2.empty?
478
+ items << ["#{@labels[:tax3]}:", @document.tax3] unless @document.tax3.empty?
473
479
 
474
480
  width = [
475
481
  "#{@labels[:subtotal]}#{@document.subtotal}".size,
@@ -487,7 +493,7 @@ module InvoicePrinter
487
493
  }
488
494
 
489
495
  @pdf.span(width, position: :right) do
490
- @pdf.table(items, styles)
496
+ @pdf.table(items, styles) unless items.empty?
491
497
  end
492
498
 
493
499
  @pdf.move_down(15)
@@ -1,3 +1,3 @@
1
1
  module InvoicePrinter
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -0,0 +1,50 @@
1
+ require 'test_helper'
2
+
3
+ class InputsTest < Minitest::Test
4
+ include InvoicePrinterHelpers
5
+
6
+ def test_refuse_documents_of_wrong_class
7
+ assert_raises(StandardError) do
8
+ InvoicePrinter::PDFDocument.new(document: String.new)
9
+ end
10
+
11
+ assert_raises(StandardError) do
12
+ InvoicePrinter.render(document: String.new)
13
+ end
14
+ end
15
+
16
+ def test_refuse_items_of_wrong_class
17
+ assert_raises(StandardError) do
18
+ InvoicePrinter::Document.new(items: String.new)
19
+ end
20
+ end
21
+
22
+ def test_non_string_inputs_are_converted_to_strings
23
+ params = default_document_params.merge(
24
+ provider_ic: 12345678910,
25
+ provider_dic: 12345678910,
26
+ purchaser_ic: 12345678910,
27
+ purchaser_dic: 12345678910
28
+ )
29
+
30
+ # No exceptions should be raised
31
+ invoice = InvoicePrinter::Document.new(params)
32
+ InvoicePrinter.render(document: invoice)
33
+ end
34
+
35
+ def test_missing_font_raises_an_exception
36
+ invoice = InvoicePrinter::Document.new(default_document_params)
37
+
38
+ assert_raises(InvoicePrinter::PDFDocument::FontFileNotFound) do
39
+ InvoicePrinter.render(document: invoice, font: 'missing.font')
40
+ end
41
+ end
42
+
43
+ def test_missing_logo_raises_an_exception
44
+ invoice = InvoicePrinter::Document.new(default_document_params)
45
+
46
+ assert_raises(InvoicePrinter::PDFDocument::LogoFileNotFound) do
47
+ InvoicePrinter.render(document: invoice, logo: 'missing.png')
48
+ end
49
+ end
50
+ end
data/test/test_ext.rb CHANGED
@@ -16,8 +16,8 @@ module InvoicePrinter
16
16
  strings << @document.provider_city_part
17
17
  strings << @document.provider_extra_address_line
18
18
 
19
- strings << "#{@labels[:ic]}: #{@document.provider_ic}" unless @document.provider_ic.nil?
20
- strings << "#{@labels[:dic]}: #{@document.provider_dic}" unless @document.provider_dic.nil?
19
+ strings << "#{@labels[:ic]}: #{@document.provider_ic}" unless @document.provider_ic.empty?
20
+ strings << "#{@labels[:dic]}: #{@document.provider_dic}" unless @document.provider_dic.empty?
21
21
 
22
22
  strings << @labels[:purchaser]
23
23
  strings << @document.purchaser_name
@@ -27,8 +27,8 @@ module InvoicePrinter
27
27
  strings << @document.purchaser_city_part
28
28
  strings << @document.purchaser_extra_address_line
29
29
 
30
- strings << "#{@labels[:ic]}: #{@document.purchaser_ic}" unless @document.purchaser_ic.nil?
31
- strings << "#{@labels[:dic]}: #{@document.purchaser_dic}" unless @document.purchaser_dic.nil?
30
+ strings << "#{@labels[:ic]}: #{@document.purchaser_ic}" unless @document.purchaser_ic.empty?
31
+ strings << "#{@labels[:dic]}: #{@document.purchaser_dic}" unless @document.purchaser_dic.empty?
32
32
 
33
33
  # Account
34
34
  if @document.bank_account_number.nil?
@@ -68,6 +68,7 @@ module InvoicePrinter
68
68
  strings << @document.tax2
69
69
  strings << "#{@labels[:tax3]}:"
70
70
  strings << @document.tax3
71
+
71
72
  strings << "#{@labels[:total]}: #{@document.total}"
72
73
 
73
74
  # TODO: dynamically test page numbers
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: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josef Strzibny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-10 00:00:00.000000000 Z
11
+ date: 2016-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -81,6 +81,8 @@ files:
81
81
  - examples/czech_invoice.pdf
82
82
  - examples/czech_invoice.rb
83
83
  - examples/example.jpg
84
+ - examples/simple_invoice.pdf
85
+ - examples/simple_invoice.rb
84
86
  - invoice_printer.gemspec
85
87
  - lib/invoice_printer.rb
86
88
  - lib/invoice_printer/document.rb
@@ -88,6 +90,7 @@ files:
88
90
  - lib/invoice_printer/pdf_document.rb
89
91
  - lib/invoice_printer/version.rb
90
92
  - test/dates_box_test.rb
93
+ - test/inputs_test.rb
91
94
  - test/invoice_printer_test.rb
92
95
  - test/items_table_test.rb
93
96
  - test/labels_test.rb
@@ -120,6 +123,7 @@ specification_version: 4
120
123
  summary: Super simple PDF invoicing in pure Ruby
121
124
  test_files:
122
125
  - test/dates_box_test.rb
126
+ - test/inputs_test.rb
123
127
  - test/invoice_printer_test.rb
124
128
  - test/items_table_test.rb
125
129
  - test/labels_test.rb