Class: Cetustek::QueryInvoice

Inherits:
Object
  • Object
show all
Extended by:
Soap
Defined in:
lib/cetustek/queries.rb

Overview

2.4 QueryInvoice 查詢發票資訊 (by invoice number + year)

Constant Summary collapse

FIELDS =

Spec AVM-26-03 Table 13.

%w[OrderID InvoiceNumber InvoiceDate InvoiceTime MainRemark CheckNumber
RandomNumber InvoiceStatus DonateMark SalesAmount FreeTaxSalesAmount
ZeroTaxSalesAmount TaxAmount TotalAmount CtkUrl].freeze
PARTY_FIELDS =
%w[Identifier Name Address PersonInCharge TelephoneNumber
FacsimileNumber EmailAddress].freeze
DETAIL_FIELDS =
%w[ProductCode Description Quantity Unit UnitPrice Amount SequenceNumber].freeze

Class Method Summary collapse

Methods included from Soap

rentid, soap_call, soap_client, soap_return, source

Class Method Details

.find(invoice_number, invoice_year) ⇒ Object

Same query, with the returned XML parsed into a Hash of snake_case keys plus :seller/:buyer sub-hashes and a :details array. nil when the platform answers with nothing at all, or the documented "nodata".



26
27
28
# File 'lib/cetustek/queries.rb', line 26

def self.find(invoice_number, invoice_year)
  parse(soap_return(query(invoice_number, invoice_year), :query_invoice))
end

.parse(xml) ⇒ Object

§2.5 QueryInvoicebyOrderid shares this exact XML shape (Table 13), so QueryInvoiceByOrderId#find reuses this instead of duplicating it.



32
33
34
35
36
37
38
39
40
41
# File 'lib/cetustek/queries.rb', line 32

def self.parse(xml)
  root = Xml.parse_response(xml, nil_values: %w[nodata])
  return nil unless root

  data = Xml.parse_fields(root, FIELDS)
  data[:seller] = parse_party(root, 'Seller')
  data[:buyer] = parse_party(root, 'Buyer')
  data[:details] = root.locate('Details/ProductItem').map { |item| Xml.parse_fields(item, DETAIL_FIELDS) }
  data
end

.query(invoice_number, invoice_year) ⇒ Object



19
20
21
# File 'lib/cetustek/queries.rb', line 19

def self.query(invoice_number, invoice_year)
  soap_call(:query_invoice, invoicenumber: invoice_number, invoiceyear: invoice_year)
end