Class: Clearbooks::Invoice

Inherits:
Base
  • Object
show all
Defined in:
lib/clearbooks/model/invoice.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

build, create

Constructor Details

#initialize(data) ⇒ Invoice

Returns a new instance of Invoice.

Parameters:



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/clearbooks/model/invoice.rb', line 111

def initialize data
  @invoice_id       = Integer data.savon(:invoice_id) rescue nil

  @date_created     = parse_date data.savon :date_created
  @date_due         = parse_date data.savon :date_due

  @credit_terms     = Integer data.savon(:credit_terms) rescue nil
  @description      = data.savon :description

  @entity_id        = Integer data.savon(:entity_id) rescue nil
  @reference        = data.savon :reference
  @project          = Integer data.savon(:project) rescue nil
  @status           = data.savon :status

  @invoice_prefix   = data.savon :invoice_prefix
  @invoice_number   = data.savon :invoice_number
  @external_id      = data.savon :external_id
  @statement_page   = CGI.unescapeHTML data.savon :statement_page rescue nil

  @date_modified    = parse_date data.savon :date_modified
  @date_accrual     = parse_date data.savon :date_accrual

  @type             = data.savon :type
  @bank_payment_id  = Integer data.savon(:bank_payment_id) rescue nil

  @gross            = BigDecimal data.savon(:gross) rescue nil
  @net              = BigDecimal data.savon(:net) rescue nil
  @vat              = BigDecimal data.savon(:vat) rescue nil
  @paid             = BigDecimal data.savon(:paid) rescue nil
  @balance          = BigDecimal data.savon(:balance) rescue nil
  @external_id      = data.savon(:external_id)

  @items = Item.build( data[:items].is_a?(Array) ? data[:items] : data[:items][:item] )
end

Instance Attribute Details

#balanceObject (readonly)

Returns the value of attribute balance.



14
15
16
# File 'lib/clearbooks/model/invoice.rb', line 14

def balance
  @balance
end

#bank_payment_idFixnum (readonly)

Optional. The bank account code.



72
73
74
# File 'lib/clearbooks/model/invoice.rb', line 72

def bank_payment_id
  @bank_payment_id
end

#credit_termsFixnum (readonly)

Required. The number of days after the tax point that the invoice is due.



41
42
43
# File 'lib/clearbooks/model/invoice.rb', line 41

def credit_terms
  @credit_terms
end

#date_accrualDateTime (readonly)

Optional. The invoice accrual date.



36
37
38
# File 'lib/clearbooks/model/invoice.rb', line 36

def date_accrual
  @date_accrual
end

#date_createdDateTime (readonly)

Required. The tax point of the invoice.



25
26
27
# File 'lib/clearbooks/model/invoice.rb', line 25

def date_created
  @date_created
end

#date_dueDateTime (readonly)

Required. The date the invoice is due. Use either this field or creditTerms.



30
31
32
# File 'lib/clearbooks/model/invoice.rb', line 30

def date_due
  @date_due
end

#date_modifiedDateTime (readonly)

Returns Date this invoice was last modified.

Returns:

  • (DateTime)

    Date this invoice was last modified.

See Also:



77
78
79
# File 'lib/clearbooks/model/invoice.rb', line 77

def date_modified
  @date_modified
end

#descriptionString (readonly)

Optional.



46
47
48
# File 'lib/clearbooks/model/invoice.rb', line 46

def description
  @description
end

#entity_idFixnum (readonly)

Required. The customer or supplier id.



51
52
53
# File 'lib/clearbooks/model/invoice.rb', line 51

def entity_id
  @entity_id
end

#external_idFixnum (readonly)

Returns Id used to link imported invoices.

Returns:

  • (Fixnum)

    Id used to link imported invoices.

See Also:



81
82
83
# File 'lib/clearbooks/model/invoice.rb', line 81

def external_id
  @external_id
end

#grossObject (readonly)

Returns the value of attribute gross.



14
15
16
# File 'lib/clearbooks/model/invoice.rb', line 14

def gross
  @gross
end

#invoice_idFixnum (readonly) Also known as: id

Returns Invoice Id.

Returns:

  • (Fixnum)

    Invoice Id.

See Also:



21
22
23
# File 'lib/clearbooks/model/invoice.rb', line 21

def invoice_id
  @invoice_id
end

#invoice_numberString (readonly)

Returns Invoice number.



85
86
87
# File 'lib/clearbooks/model/invoice.rb', line 85

def invoice_number
  @invoice_number
end

#invoice_prefixString (readonly)

Returns Invoice prefix.



102
103
104
# File 'lib/clearbooks/model/invoice.rb', line 102

def invoice_prefix
  @invoice_prefix
end

#itemsItem (readonly)

Required.

Returns:

  • (Item)

    A list of item elements identifying the line items.

See Also:



89
90
91
# File 'lib/clearbooks/model/invoice.rb', line 89

def items
  @items
end

#netObject (readonly)

Returns the value of attribute net.



14
15
16
# File 'lib/clearbooks/model/invoice.rb', line 14

def net
  @net
end

Returns the value of attribute paid.



14
15
16
# File 'lib/clearbooks/model/invoice.rb', line 14

def paid
  @paid
end

#projectFixnum (readonly)

Optional. The id of the project to assign the invoice to.



61
62
63
# File 'lib/clearbooks/model/invoice.rb', line 61

def project
  @project
end

#referenceString (readonly)

Optional. A reference string for the invoice.



56
57
58
# File 'lib/clearbooks/model/invoice.rb', line 56

def reference
  @reference
end

#statement_pageString (readonly)

Returns A link to a printable invoice page with a link to download as a PDF (top right corner).

Returns:

  • (String)

    A link to a printable invoice page with a link to download as a PDF (top right corner).

See Also:



94
95
96
# File 'lib/clearbooks/model/invoice.rb', line 94

def statement_page
  @statement_page
end

#statusString (readonly)

Returns Invoice status: paid, unpaid.

Returns:

  • (String)

    Invoice status: paid, unpaid.

See Also:



98
99
100
# File 'lib/clearbooks/model/invoice.rb', line 98

def status
  @status
end

#typeString (readonly)

Optional. A string identifying the type of the invoice. Value one of: purchases, sales, cn-sales, cn-purchases.



66
67
68
# File 'lib/clearbooks/model/invoice.rb', line 66

def type
  @type
end

#vatObject (readonly)

Returns the value of attribute vat.



14
15
16
# File 'lib/clearbooks/model/invoice.rb', line 14

def vat
  @vat
end

Instance Method Details

#to_savonHash

Returns self as Savon readable Hash

Returns:

  • (Hash)

    Returns self as Savon readable Hash



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/clearbooks/model/invoice.rb', line 150

def to_savon
  {
    invoice: {
      :@dateCreated => @date_created,
      :@entityId    => @entity_id,
      :@type        => @type,
      :@dateDue     => @date_due,
      :@dateAccural => @date_accural,
      :@creditTerms => @credit_terms,
      :@reference   => @reference,
      :@project     => @project,
      :@external_id => @external_id,

      description:  @description,
      items:        { item: items.map(&:to_savon) }
    }.compact
  }
end