Class: Cetustek::QueryAllowance
- Inherits:
-
Object
- Object
- Cetustek::QueryAllowance
- Extended by:
- Soap
- 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 Soap
rentid, soap_call, soap_client, soap_return, source
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 platform answers with nothing at all.
59 60 61 |
# File 'lib/cetustek/queries.rb', line 59 def self.find(allowance_number) parse(soap_return(query(allowance_number), :query_allowance)) end |
.parse(xml) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/cetustek/queries.rb', line 63 def self.parse(xml) body = xml.to_s.strip return nil if body.empty? # §2.11 只描述成功時的 XML;非 XML 的回覆是代碼字串,原樣拋給呼叫端。 ResultCode.raise!(body, ResultCode::COMMON) unless body.start_with?('<') 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
48 49 50 51 52 53 54 |
# File 'lib/cetustek/queries.rb', line 48 def self.query(allowance_number) soap_client.call(:query_allowance, message: { allowancenumber: allowance_number, source: source, rentid: rentid }) end |