Class: Sendregning::Invoice
- Inherits:
-
Object
- Object
- Sendregning::Invoice
- Defined in:
- lib/sendregning/invoice.rb
Constant Summary collapse
- OPTIONAL_ATTRIBUTES =
[ # Request :invoiceType, :creditedId, :orderNo, :invoiceDate, :orderNo, :invoiceDate, :dueDate, :orderDate, :recipientNo, :address1, :address2, :country, :email, :ourRef, :yourRef, :comment, :invoiceText, :printDunningInfo, :itemTaxInclude, # Response :tax, :dueDate, :dunningFee, :invoiceNo, :total, :accountNo, :orgNrSuffix, :kid, :orgNo, :interestRate, :state ]
- SHIPMENT_ATTRIBUTES =
[ :shipment, :emailaddresses, :copyaddresses ]
- SHIPMENT_MODES =
{ :paper => 'PAPER', :email => 'EMAIL', :paper_and_email => 'PAPER_AND_EMAIL' }
Instance Attribute Summary collapse
-
#city ⇒ Object
Returns the value of attribute city.
-
#client ⇒ Object
Returns the value of attribute client.
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#name ⇒ Object
Returns the value of attribute name.
-
#optional ⇒ Object
readonly
Returns the value of attribute optional.
-
#shipment ⇒ Object
readonly
Returns the value of attribute shipment.
-
#zip ⇒ Object
Returns the value of attribute zip.
Instance Method Summary collapse
- #add_line(line) ⇒ Object
-
#initialize(attributes = {}) ⇒ Invoice
constructor
A new instance of Invoice.
- #paid? ⇒ Boolean
-
#send! ⇒ Object
Sends an invoice.
- #shipment_mode ⇒ Object
-
#to_xml(options = {}) ⇒ Object
Renders invoice to XML.
- #update(attributes = {}) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Invoice
Returns a new instance of Invoice.
30 31 32 33 |
# File 'lib/sendregning/invoice.rb', line 30 def initialize(attributes={}) self.update(attributes) @lines = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object (protected)
88 89 90 91 92 93 94 95 96 |
# File 'lib/sendregning/invoice.rb', line 88 def method_missing(method, *args) if OPTIONAL_ATTRIBUTES.include?(method) @optional[method] elsif SHIPMENT_ATTRIBUTES.include?(method) @shipping[method] else super end end |
Instance Attribute Details
#city ⇒ Object
Returns the value of attribute city.
26 27 28 |
# File 'lib/sendregning/invoice.rb', line 26 def city @city end |
#client ⇒ Object
Returns the value of attribute client.
25 26 27 |
# File 'lib/sendregning/invoice.rb', line 25 def client @client end |
#lines ⇒ Object
Returns the value of attribute lines.
28 29 30 |
# File 'lib/sendregning/invoice.rb', line 28 def lines @lines end |
#name ⇒ Object
Returns the value of attribute name.
26 27 28 |
# File 'lib/sendregning/invoice.rb', line 26 def name @name end |
#optional ⇒ Object
Returns the value of attribute optional.
27 28 29 |
# File 'lib/sendregning/invoice.rb', line 27 def optional @optional end |
#shipment ⇒ Object
Returns the value of attribute shipment.
27 28 29 |
# File 'lib/sendregning/invoice.rb', line 27 def shipment @shipment end |
#zip ⇒ Object
Returns the value of attribute zip.
26 27 28 |
# File 'lib/sendregning/invoice.rb', line 26 def zip @zip end |
Instance Method Details
#add_line(line) ⇒ Object
44 45 46 47 48 |
# File 'lib/sendregning/invoice.rb', line 44 def add_line(line) line = Sendregning::Line.new(line) unless line.kind_of?(Sendregning::Line) @lines << line line end |
#paid? ⇒ Boolean
55 56 57 |
# File 'lib/sendregning/invoice.rb', line 55 def paid? state == 'paid' end |
#send! ⇒ Object
Sends an invoice
51 52 53 |
# File 'lib/sendregning/invoice.rb', line 51 def send! self.client.send_invoice(self) end |
#shipment_mode ⇒ Object
59 60 61 62 63 |
# File 'lib/sendregning/invoice.rb', line 59 def shipment_mode mode = (@shipment[:shipment] || :paper).to_sym raise 'Invalid shipment mode!' unless SHIPMENT_MODES.keys.include?(mode) SHIPMENT_MODES[mode] end |
#to_xml(options = {}) ⇒ Object
Renders invoice to XML
66 67 68 |
# File 'lib/sendregning/invoice.rb', line 66 def to_xml(={}) InvoiceSerializer.build(self, ) end |
#update(attributes = {}) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/sendregning/invoice.rb', line 35 def update(attributes={}) @client = attributes[:client] if attributes[:client] @name = attributes[:name] if attributes[:name] @zip = attributes[:zip] if attributes[:zip] @city = attributes[:city] if attributes[:city] self.optional = attributes self.shipment = attributes end |