Class: Cetustek::QueryAllowance
- Inherits:
-
Object
- Object
- Cetustek::QueryAllowance
- Extended by:
- Queries
- Defined in:
- lib/cetustek/queries.rb
Overview
2.11 QueryAllowance 查詢折讓資料
Constant Summary collapse
- FIELDS =
Spec AVM-26-03 Table 20. Note the query response uses ProductCode and InvoiceDate, unlike CreateAllowance's ProductionCode and InvoiceYear.
%w[AllowanceNumber AllowanceDate InvoiceNumber InvoiceDate BuyerIdentifier BuyerName BuyerAddress Reason AllowanceStatus BackStatus SaleAmount TaxAmount].freeze
- DETAIL_FIELDS =
%w[SequenceNumber ProductCode Description Quantity Unit UnitPrice Amount Tax TaxType].freeze
Class Method Summary collapse
-
.find(allowance_number) ⇒ Object
Same query, with the returned XML parsed into a Hash of snake_case keys plus a :details array.
- .parse(xml) ⇒ Object
- .query(allowance_number) ⇒ Object
Methods included from Queries
Class Method Details
.find(allowance_number) ⇒ Object
Same query, with the returned XML parsed into a Hash of snake_case keys plus a :details array. Values are the raw strings from the XML; returns nil when the allowance number is unknown.
72 73 74 |
# File 'lib/cetustek/queries.rb', line 72 def self.find(allowance_number) parse(query(allowance_number).body[:query_allowance_response][:return]) end |
.parse(xml) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/cetustek/queries.rb', line 76 def self.parse(xml) body = xml.to_s.strip return nil if body.empty? || body == 'nodata' root = Ox.parse(body) root = root.root if root.is_a?(Ox::Document) data = FIELDS.to_h { |field| [snake_case(field), text_of(root, field)] } data[:details] = root.locate('Details/ProductItem').map do |item| DETAIL_FIELDS.to_h { |field| [snake_case(field), text_of(item, field)] } end data end |
.query(allowance_number) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/cetustek/queries.rb', line 61 def self.query(allowance_number) soap_client.call(:query_allowance, message: { allowancenumber: allowance_number, source: source, rentid: rentid }) end |