• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / lsp-data / a68ec7da-98f9-4517-b8c1-d6a203be55f1

11 Dec 2024 09:28PM UTC coverage: 99.785% (-0.2%) from 100.0%
a68ec7da-98f9-4517-b8c1-d6a203be55f1

Pull #24

circleci

mzelesky
initial work on invoice class
Pull Request #24: [WIP] Invoice class

57 of 58 new or added lines in 2 files covered. (98.28%)

464 of 465 relevant lines covered (99.78%)

6.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.25
/lib/lsp-data/api_invoice.rb
1
# frozen_string_literal: true
2

3
module LspData
1✔
4
  ### This class makes a model of an invoice object returned from Alma via API
5
  class ApiInvoice
1✔
6
    attr_reader :invoice_json
1✔
7

8
    def initialize(invoice_json:)
1✔
9
      @invoice_json = invoice_json
2✔
10
    end
11

12
    def invoice_number
1✔
13
      @invoice_number ||= invoice_json['number']
1✔
14
    end
15

16
    def invoice_date
1✔
17
      @invoice_date ||= begin
1✔
18
                          regex = /^([0-9]{4})\-([0-9]{2})\-([0-9]{2}).*$/
1✔
19
                          date = regex.match(invoice_json['invoice_date'])
1✔
20
                          if date
1✔
21
                            Time.new(date[1].to_i, date[2].to_i, date[3].to_i)
1✔
22
                          end
23
                        end
24
    end
25

26
    def invoice_total
1✔
27
      @invoice_total ||= BigDecimal(invoice_json['total_amount'].to_s)
1✔
28
    end
29

30
    def invoice_lines_total
1✔
31
      @invoice_lines_total ||= BigDecimal(invoice_json['total_invoice_lines_amount'].to_s)
1✔
32
    end
33

34
    # Unique Alma invoice identifier
35
    def pid
1✔
36
      @pid ||= invoice_json['id']
2✔
37
    end
38

39
    def reference_number
1✔
40
      @reference_number ||= begin
1✔
41
                              number = invoice_json['reference_number']
1✔
42
                              if number.size.positive?
1✔
NEW
43
                                number
×
44
                              else
45
                                nil
1✔
46
                              end
47
                            end
48
    end
49

50
    def creation_method
1✔
51
      @creation_method ||= invoice_json['creation_form']['desc']
1✔
52
    end
53

54
    def status
1✔
55
      @status ||= invoice_json['invoice_status']['desc']
1✔
56
    end
57

58
    def vendor
1✔
59
      @vendor ||= {
3✔
60
                    name: invoice_json['vendor']['desc'],
61
                    code: invoice_json['vendor']['value'],
62
                    account: invoice_json['vendor_account']
63
                  }
64
    end
65

66
    def currency
1✔
67
      @currency ||= {
2✔
68
                      name: invoice_json['currency']['desc'],
69
                      code: invoice_json['currency']['value'],
70
                    }
71
    end
72

73
    def owner
1✔
74
      @owner ||= invoice_json['owner']['value']
1✔
75
    end
76

77
    def payment
1✔
78
      @payment ||= {
4✔
79
                     prepaid: invoice_json['payment']['prepaid'],
80
                     internal_copy: invoice_json['payment']['prepaid'],
81
                     payment_status: invoice_json['payment']['payment_status']['desc'],
82
                     payment_method: invoice_json['payment_method']['desc']
83
                   }
84
    end
85
    def voucher_date
1✔
86
      @voucher_date ||= begin
1✔
87
                          regex = /^([0-9]{4})\-([0-9]{2})\-([0-9]{2}).*$/
1✔
88
                          date = regex.match(invoice_json['payment']['voucher_date'])
1✔
89
                          if date
1✔
90
                            Time.new(date[1].to_i, date[2].to_i, date[3].to_i)
1✔
91
                          end
92
                        end
93
    end
94

95
    def voucher_number
1✔
96
      @voucher_number ||= invoice_json['payment']['voucher_number']
1✔
97
    end
98

99
    def calculated_voucher_number
1✔
100
      @calculated_voucher_number ||= begin
1✔
101
                                       id_number_string = pid[2..-6]
1✔
102
                                       id = id_number_string.to_i
1✔
103
                                       "A#{id.to_s(36).rjust(7, '0')}"
1✔
104
                                     end
105
    end
106

107
    def voucher_amount
1✔
108
      @voucher_amount ||= begin
1✔
109
                            amount = invoice_json['payment']['voucher_amount']
1✔
110
                            if amount
1✔
111
                              BigDecimal(amount.to_s)
1✔
112
                            end
113
                          end
114
    end
115
    def voucher_currency
1✔
116
      @voucher_currency ||= {
2✔
117
                              name: invoice_json['payment']['voucher_currency']['desc'],
118
                              code: invoice_json['payment']['voucher_currency']['value']
119
                            }
120
    end
121
  end
122
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc