Class: Cetustek::Models::InvoiceData

Inherits:
Object
  • Object
show all
Defined in:
lib/cetustek/models/invoice_data.rb

Overview

Request data for CreateInvoiceV3 (開立發票), spec AVM-26-03 Table 1/2. Rules the spec fixes in print are enforced here; anything needing an external lookup (捐贈碼、手機條碼是否存在) is left to the caller.

Constant Summary collapse

DEFAULT_TAX_RATE =
0.05
DEFAULT_INVOICE_TYPE =

一般稅額電子發票

'07'
SPECIAL_INVOICE_TYPE =

特種稅額電子發票

'08'
DEFAULT_RTN_MSG =

Json 回傳才拿得到平台配發的發票日期時間;Intertemporal 回開會讓本機日期失準。

'Json'
MAX_ITEMS =
9999
TAX_TYPES =
[TaxType::TAXABLE, TaxType::ZERO_RATE, TaxType::TAX_FREE,
TaxType::SPECIAL, TaxType::ZERO_RATE_CUSTOMS, TaxType::MIXED].freeze
[DonateMark::CARRIER, DonateMark::DONATE, DonateMark::PAPER].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ InvoiceData

Returns a new instance of InvoiceData.



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
99
100
101
102
103
# File 'lib/cetustek/models/invoice_data.rb', line 71

def initialize(attributes = {})
  @order_id = attributes[:order_id]
  @order_date = attributes[:order_date]
  @buyer_identifier = attributes[:buyer_identifier]
  @buyer_name = attributes[:buyer_name]
  @buyer_email = attributes[:buyer_email]
  @buyer_address = attributes[:buyer_address]
  @buyer_person_in_charge = attributes[:buyer_person_in_charge]
  @buyer_telephone = attributes[:buyer_telephone]
  @buyer_facsimile = attributes[:buyer_facsimile]
  @buyer_customer_number = attributes[:buyer_customer_number]
  @donate_mark = attributes[:donate_mark]
  @carrier_type = attributes[:carrier_type]
  @carrier_id1 = attributes[:carrier_id1] || attributes[:carrier_id]
  # 手機條碼與自然人憑證沒有顯碼隱碼之分,兩欄填相同值。
  @carrier_id2 = attributes[:carrier_id2] || @carrier_id1
  @npo_ban = attributes[:npo_ban]
  @items = attributes[:items] || []
  @payment_type = attributes[:payment_type]
  @tax_type = attributes[:tax_type] || TaxType::TAXABLE
  # 特種稅率是營業性質決定的,不能沿用 5% 預設值。
  @tax_rate = attributes.fetch(:tax_rate) { special_tax? ? nil : DEFAULT_TAX_RATE }
  @zero_reason = attributes[:zero_reason]
  @invoice_type = attributes[:invoice_type] || DEFAULT_INVOICE_TYPE
  # hastax: 0 = item prices are tax-exclusive, 1 = tax-inclusive.
  # Comes from the order (e.g. tax-free purchases), not a fixed value.
  @hastax = attributes.fetch(:hastax, 1)
  @remark = attributes[:remark]
  @round_num = attributes[:round_num]
  @mail_send = attributes[:mail_send]
  @rtn_msg = attributes.fetch(:rtn_msg, DEFAULT_RTN_MSG)
  validate!
end

Instance Attribute Details

#buyer_addressObject (readonly)

Returns the value of attribute buyer_address.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def buyer_address
  @buyer_address
end

#buyer_customer_numberObject (readonly)

Returns the value of attribute buyer_customer_number.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def buyer_customer_number
  @buyer_customer_number
end

#buyer_emailObject (readonly)

Returns the value of attribute buyer_email.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def buyer_email
  @buyer_email
end

#buyer_facsimileObject (readonly)

Returns the value of attribute buyer_facsimile.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def buyer_facsimile
  @buyer_facsimile
end

#buyer_identifierObject (readonly)

Returns the value of attribute buyer_identifier.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def buyer_identifier
  @buyer_identifier
end

#buyer_nameObject (readonly)

Returns the value of attribute buyer_name.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def buyer_name
  @buyer_name
end

#buyer_person_in_chargeObject (readonly)

Returns the value of attribute buyer_person_in_charge.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def buyer_person_in_charge
  @buyer_person_in_charge
end

#buyer_telephoneObject (readonly)

Returns the value of attribute buyer_telephone.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def buyer_telephone
  @buyer_telephone
end

#carrier_id1Object (readonly) Also known as: carrier_id

Returns the value of attribute carrier_id1.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def carrier_id1
  @carrier_id1
end

#carrier_id2Object (readonly)

Returns the value of attribute carrier_id2.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def carrier_id2
  @carrier_id2
end

#carrier_typeObject (readonly)

Returns the value of attribute carrier_type.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def carrier_type
  @carrier_type
end

Returns the value of attribute donate_mark.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def donate_mark
  @donate_mark
end

#hastaxObject (readonly)

Returns the value of attribute hastax.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def hastax
  @hastax
end

#invoice_typeObject (readonly)

Returns the value of attribute invoice_type.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def invoice_type
  @invoice_type
end

#itemsObject (readonly)

Returns the value of attribute items.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def items
  @items
end

#mail_sendObject (readonly)

Returns the value of attribute mail_send.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def mail_send
  @mail_send
end

#npo_banObject (readonly)

Returns the value of attribute npo_ban.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def npo_ban
  @npo_ban
end

#order_dateObject (readonly)

Returns the value of attribute order_date.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def order_date
  @order_date
end

#order_idObject (readonly)

Returns the value of attribute order_id.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def order_id
  @order_id
end

#payment_typeObject (readonly)

Returns the value of attribute payment_type.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def payment_type
  @payment_type
end

#remarkObject (readonly)

Returns the value of attribute remark.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def remark
  @remark
end

#round_numObject (readonly)

Returns the value of attribute round_num.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def round_num
  @round_num
end

#rtn_msgObject (readonly)

Returns the value of attribute rtn_msg.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def rtn_msg
  @rtn_msg
end

#tax_rateObject (readonly)

Returns the value of attribute tax_rate.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def tax_rate
  @tax_rate
end

#tax_typeObject (readonly)

Returns the value of attribute tax_type.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def tax_type
  @tax_type
end

#zero_reasonObject (readonly)

Returns the value of attribute zero_reason.



61
62
63
# File 'lib/cetustek/models/invoice_data.rb', line 61

def zero_reason
  @zero_reason
end

Instance Method Details

#mixed_tax?Boolean

混合稅率發票 (限收銀機):每筆明細需標註 DType。

Returns:

  • (Boolean)


106
107
108
# File 'lib/cetustek/models/invoice_data.rb', line 106

def mixed_tax?
  @tax_type.to_i == TaxType::MIXED
end

#special_tax?Boolean

特種稅額發票:TaxRate 必填,InvoiceType 必須為 08。

Returns:

  • (Boolean)


111
112
113
# File 'lib/cetustek/models/invoice_data.rb', line 111

def special_tax?
  @tax_type.to_i == TaxType::SPECIAL
end