Class: XeroKiwi::Accounting::Invoice
- Inherits:
-
Object
- Object
- XeroKiwi::Accounting::Invoice
- Defined in:
- lib/xero_kiwi/accounting/invoice.rb
Overview
Represents a Xero Invoice returned by the Accounting API.
See: developer.xero.com/documentation/api/accounting/invoices
Constant Summary collapse
- ATTRIBUTES =
{ invoice_id: "InvoiceID", invoice_number: "InvoiceNumber", type: "Type", contact: "Contact", date: "Date", due_date: "DueDate", status: "Status", line_amount_types: "LineAmountTypes", line_items: "LineItems", sub_total: "SubTotal", total_tax: "TotalTax", total: "Total", total_discount: "TotalDiscount", updated_date_utc: "UpdatedDateUTC", currency_code: "CurrencyCode", currency_rate: "CurrencyRate", reference: "Reference", branding_theme_id: "BrandingThemeID", url: "Url", sent_to_contact: "SentToContact", expected_payment_date: "ExpectedPaymentDate", planned_payment_date: "PlannedPaymentDate", has_attachments: "HasAttachments", repeating_invoice_id: "RepeatingInvoiceID", payments: "Payments", credit_notes: "CreditNotes", prepayments: "Prepayments", overpayments: "Overpayments", amount_due: "AmountDue", amount_paid: "AmountPaid", amount_credited: "AmountCredited", cis_deduction: "CISDeduction", fully_paid_on_date: "FullyPaidOnDate", sales_tax_calculation_type_code: "SalesTaxCalculationTypeCode", invoice_addresses: "InvoiceAddresses" }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #accounts_payable? ⇒ Boolean
- #accounts_receivable? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(attrs, reference: false) ⇒ Invoice
constructor
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity.
- #inspect ⇒ Object
- #reference? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(attrs, reference: false) ⇒ Invoice
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/xero_kiwi/accounting/invoice.rb', line 60 def initialize(attrs, reference: false) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity attrs = attrs.transform_keys(&:to_s) @is_reference = reference @invoice_id = attrs["InvoiceID"] @invoice_number = attrs["InvoiceNumber"] @type = attrs["Type"] @contact = attrs["Contact"] ? Contact.new(attrs["Contact"], reference: true) : nil @date = parse_time(attrs["Date"]) @due_date = parse_time(attrs["DueDate"]) @status = attrs["Status"] @line_amount_types = attrs["LineAmountTypes"] @line_items = (attrs["LineItems"] || []).map { |li| LineItem.new(li) } @sub_total = attrs["SubTotal"] @total_tax = attrs["TotalTax"] @total = attrs["Total"] @total_discount = attrs["TotalDiscount"] @updated_date_utc = parse_time(attrs["UpdatedDateUTC"]) @currency_code = attrs["CurrencyCode"] @currency_rate = attrs["CurrencyRate"] @reference = attrs["Reference"] @branding_theme_id = attrs["BrandingThemeID"] @url = attrs["Url"] @sent_to_contact = attrs["SentToContact"] @expected_payment_date = parse_time(attrs["ExpectedPaymentDate"]) @planned_payment_date = parse_time(attrs["PlannedPaymentDate"]) @has_attachments = attrs["HasAttachments"] @repeating_invoice_id = attrs["RepeatingInvoiceID"] @payments = (attrs["Payments"] || []).map { |p| Payment.new(p, reference: true) } @credit_notes = (attrs["CreditNotes"] || []).map { |cn| CreditNote.new(cn, reference: true) } @prepayments = (attrs["Prepayments"] || []).map { |p| Prepayment.new(p, reference: true) } @overpayments = (attrs["Overpayments"] || []).map { |o| Overpayment.new(o, reference: true) } @amount_due = attrs["AmountDue"] @amount_paid = attrs["AmountPaid"] @amount_credited = attrs["AmountCredited"] @cis_deduction = attrs["CISDeduction"] @fully_paid_on_date = parse_time(attrs["FullyPaidOnDate"]) @sales_tax_calculation_type_code = attrs["SalesTaxCalculationTypeCode"] @invoice_addresses = attrs["InvoiceAddresses"] || [] end |
Class Method Details
.from_response(payload) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/xero_kiwi/accounting/invoice.rb', line 51 def self.from_response(payload) return [] if payload.nil? items = payload["Invoices"] return [] if items.nil? items.map { |attrs| new(attrs) } end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
110 111 112 |
# File 'lib/xero_kiwi/accounting/invoice.rb', line 110 def ==(other) other.is_a?(Invoice) && other.invoice_id == invoice_id end |
#accounts_payable? ⇒ Boolean
104 |
# File 'lib/xero_kiwi/accounting/invoice.rb', line 104 def accounts_payable? = type == "ACCPAY" |
#accounts_receivable? ⇒ Boolean
102 |
# File 'lib/xero_kiwi/accounting/invoice.rb', line 102 def accounts_receivable? = type == "ACCREC" |
#hash ⇒ Object
115 |
# File 'lib/xero_kiwi/accounting/invoice.rb', line 115 def hash = [self.class, invoice_id].hash |
#inspect ⇒ Object
117 118 119 120 121 |
# File 'lib/xero_kiwi/accounting/invoice.rb', line 117 def inspect "#<#{self.class} invoice_id=#{invoice_id.inspect} " \ "invoice_number=#{invoice_number.inspect} type=#{type.inspect} " \ "status=#{status.inspect} total=#{total.inspect}>" end |
#reference? ⇒ Boolean
100 |
# File 'lib/xero_kiwi/accounting/invoice.rb', line 100 def reference? = @is_reference |
#to_h ⇒ Object
106 107 108 |
# File 'lib/xero_kiwi/accounting/invoice.rb', line 106 def to_h ATTRIBUTES.keys.to_h { |key| [key, public_send(key)] } end |