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 ].freeze
- SHIPMENT_ATTRIBUTES =
%i[ shipment emailaddresses copyaddresses ].freeze
- SHIPMENT_MODES =
{ paper: "PAPER", email: "EMAIL", paper_and_email: "PAPER_AND_EMAIL" }.freeze
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.
31 32 33 34 |
# File 'lib/sendregning/invoice.rb', line 31 def initialize(attributes = {}) 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) @shipment[method] else super end end |
Instance Attribute Details
#city ⇒ Object
Returns the value of attribute city.
27 28 29 |
# File 'lib/sendregning/invoice.rb', line 27 def city @city end |
#client ⇒ Object
Returns the value of attribute client.
26 27 28 |
# File 'lib/sendregning/invoice.rb', line 26 def client @client end |
#lines ⇒ Object
Returns the value of attribute lines.
29 30 31 |
# File 'lib/sendregning/invoice.rb', line 29 def lines @lines end |
#name ⇒ Object
Returns the value of attribute name.
27 28 29 |
# File 'lib/sendregning/invoice.rb', line 27 def name @name end |
#optional ⇒ Object
Returns the value of attribute optional.
28 29 30 |
# File 'lib/sendregning/invoice.rb', line 28 def optional @optional end |
#shipment ⇒ Object
Returns the value of attribute shipment.
28 29 30 |
# File 'lib/sendregning/invoice.rb', line 28 def shipment @shipment end |
#zip ⇒ Object
Returns the value of attribute zip.
27 28 29 |
# File 'lib/sendregning/invoice.rb', line 27 def zip @zip end |
Instance Method Details
#add_line(line) ⇒ Object
45 46 47 48 49 |
# File 'lib/sendregning/invoice.rb', line 45 def add_line(line) line = Sendregning::Line.new(line) unless line.is_a?(Sendregning::Line) @lines << line line end |
#paid? ⇒ Boolean
56 57 58 |
# File 'lib/sendregning/invoice.rb', line 56 def paid? state == "paid" end |
#send! ⇒ Object
Sends an invoice
52 53 54 |
# File 'lib/sendregning/invoice.rb', line 52 def send! client.send_invoice(self) end |
#shipment_mode ⇒ Object
60 61 62 63 64 65 |
# File 'lib/sendregning/invoice.rb', line 60 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
68 69 70 |
# File 'lib/sendregning/invoice.rb', line 68 def to_xml( = {}) InvoiceSerializer.build(self, ) end |
#update(attributes = {}) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/sendregning/invoice.rb', line 36 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 |