Class: Unleashed::InvoiceResource

Inherits:
BaseResource show all
Defined in:
lib/unleashed/resources/invoice_resource.rb

Overview

Resource for the Invoices API The Invoices resource allows sales invoices to be listed and viewed. An individual sales invoice details can be viewed by appending its identifier (a GUID formatted as XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX) to the URI.

Instance Method Summary collapse

Methods inherited from BaseResource

#initialize, #method_missing, #respond_to?

Constructor Details

This class inherits a constructor from Unleashed::BaseResource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Unleashed::BaseResource

Instance Method Details

#all(options = { Page: 1, PageSize: 200 }) ⇒ Array<Unleashed::Invoice>

List all invoices /Invoices - also returns the first 200 invoices because page number 1 is the default.

{ Pagination: { NumberOfItems: 2, PageSize: 200, PageNumber: 1, NumberOfPages: 1 }, Items: [ { InvoiceNumber: “SI-137”, OrderNumber: “SO-137”, QuoteNumber: nil,

InvoiceDate: "/Date(1565058456626)/", DueDate: "/Date(1568937600000)/",
InvoiceStatus: "Completed", Customer: { CustomerCode: "WADE",
  CustomerName: "Wade's Apparel & Accessories", CurrencyId: 110,
  Guid: "b9f21e05-07fe-4d9d-b460-a09db4c3caa9", LastModifiedOn: "/Date(1559778437146)/" },
  Comments: nil, PostalAddress: nil, DeliveryAddress: { AddressType: nil,
    AddressName: nil, StreetAddress: nil, StreetAddress2: nil, Suburb: nil, City: nil,
    Region: nil, Country: nil, PostalCode: nil, IsDefault: false },
    DeliveryInstruction: "Handle with care.", SubTotal: 25.0, TaxTotal: 5.0, Total: 30.0,
    BCSubTotal: 25.27, BCTaxTotal: 5.05, BCTotal: 30.32, CreatedBy: "[email protected]",
    PaymentTerm: "20th Month following", InvoiceLines: [ { LineNumber: 1, LineType: nil,
      Product: { Guid: "23280680-a2bd-4873-a390-501e0f3399d1", ProductCode: "NAIL-M",
        ProductDescription: "Medium Nails" }, OrderQuantity: 1.0, InvoiceQuantity: 1.0,
        UnitPrice: 25.0, DiscountRate: 0.0, LineTotal: 25.0, Comments: "", TaxRate: 0.2,
        LineTax: 5.0, BCUnitPrice: 25.2729, SerialNumbers: nil, BatchNumbers: nil,
        Guid: "866e295f-76fb-49e7-9407-b2ed4e0a5d0d", LastModifiedOn: "/Date(1565058457156)/" } ],
        Guid: "10a1571d-8c5a-4e5e-bbba-bc3215a27e17", LastModifiedOn: "/Date(1565058457161)/" },
        { InvoiceNumber: "SI-136", OrderNumber: "SO-136", QuoteNumber: nil,
          InvoiceDate: "/Date(1565058268231)/", DueDate: "/Date(1568937600000)/",
          InvoiceStatus: "Completed", Customer: { CustomerCode: "WADE",
            CustomerName: "Wade's Apparel & Accessories", CurrencyId: 110,
            Guid: "b9f21e05-07fe-4d9d-b460-a09db4c3caa9", LastModifiedOn: "/Date(1559778437146)/" },
            Comments: nil, PostalAddress: nil, DeliveryAddress: { AddressType: nil,
              AddressName: nil, StreetAddress: nil, StreetAddress2: nil, Suburb: nil, City: nil,
              Region: nil, Country: nil, PostalCode: nil, IsDefault: false },
              DeliveryInstruction: nil, SubTotal: 25.0, TaxTotal: 5.0, Total: 30.0,
              BCSubTotal: 25.27, BCTaxTotal: 5.05, BCTotal: 30.32, CreatedBy: "[email protected]",
              PaymentTerm: "20th Month following", InvoiceLines: [ { LineNumber: 1, LineType: nil,
                Product: { Guid: "23280680-a2bd-4873-a390-501e0f3399d1", ProductCode: "NAIL-M",
                  ProductDescription: "Medium Nails" }, OrderQuantity: 1.0, InvoiceQuantity: 1.0,
                  UnitPrice: 25.0, DiscountRate: 0.0, LineTotal: 25.0, Comments: "", TaxRate: 0.2,
                  LineTax: 5.0, BCUnitPrice: 25.2729, SerialNumbers: nil, BatchNumbers: nil,
                  Guid: "2b994962-e446-4b18-b8c7-5f445adde8cc", LastModifiedOn: "/Date(1565058268757)/" } ],
                  Guid: "5cc41e1e-468f-4c01-beb9-a077fc06df46", LastModifiedOn: "/Date(1565058268764)/" } ] }

Parameters:

  • options (Hash) (defaults to: { Page: 1, PageSize: 200 })

    Optional options.

  • Page: (Hash)

    a customizable set of options

  • PageSize: (Hash)

    a customizable set of options

  • CustomerCode: (Hash)

    a customizable set of options

  • StartDate: (Hash)

    a customizable set of options

  • EndDate: (Hash)

    a customizable set of options

  • ModifiedSince: (Hash)

    a customizable set of options

  • OrderNumber: (Hash)

    a customizable set of options

  • InvoiceNumber: (Hash)

    a customizable set of options

  • InvoiceStatus: (Hash)

    a customizable set of options

  • SerialBatch: (Hash)

    a customizable set of options

Returns:



64
65
66
67
68
69
70
71
72
73
# File 'lib/unleashed/resources/invoice_resource.rb', line 64

def all(options = { Page: 1, PageSize: 200 })
  endpoint = 'Invoices'
  params = options.dup

  # Handle Page option
  endpoint << "/#{params[:Page]}" if params[:Page].present?
  response = JSON.parse(@client.get(endpoint, params).body)
  invoices = response.key?('Items') ? response['Items'] : []
  invoices.map { |attributes| Unleashed::Invoice.new(@client, attributes) }
end

#find(id) ⇒ Unleashed::Invoice

Get a single invoice /Invoices/E6E8163F-6911-40e9-B740-90E5A0A3A996 - returns details of a particular invoice.

Parameters:

  • id (String)

    invoice ID.

Returns:



81
82
83
84
# File 'lib/unleashed/resources/invoice_resource.rb', line 81

def find(id)
  response = JSON.parse(@client.get("Invoices/#{id}").body)
  Unleashed::Invoice.new(@client, response)
end

#firstUnleashed::Invoice

Get a first invoice in all

Returns:



89
90
91
# File 'lib/unleashed/resources/invoice_resource.rb', line 89

def first
  all.first
end

#lastUnleashed::Invoice

Get a last invoice in all

Returns:



96
97
98
# File 'lib/unleashed/resources/invoice_resource.rb', line 96

def last
  all.last
end

#modelObject



9
10
11
# File 'lib/unleashed/resources/invoice_resource.rb', line 9

def model
  Unleashed::Invoice
end