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
MAX_REMARK_LENGTH =
200
ROUND_NUMS =
(0..7).freeze
TAX_TYPES =
[TaxType::TAXABLE, TaxType::ZERO_RATE, TaxType::TAX_FREE,
TaxType::SPECIAL, TaxType::ZERO_RATE_CUSTOMS, TaxType::MIXED].freeze
ZERO_RATE_TAX_TYPES =
[TaxType::ZERO_RATE, TaxType::ZERO_RATE_CUSTOMS].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.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/cetustek/models/invoice_data.rb', line 86

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] || mirrored_carrier_id2
  @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.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def buyer_address
  @buyer_address
end

#buyer_customer_numberObject (readonly)

Returns the value of attribute buyer_customer_number.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def buyer_customer_number
  @buyer_customer_number
end

#buyer_emailObject (readonly)

Returns the value of attribute buyer_email.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def buyer_email
  @buyer_email
end

#buyer_facsimileObject (readonly)

Returns the value of attribute buyer_facsimile.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def buyer_facsimile
  @buyer_facsimile
end

#buyer_identifierObject (readonly)

Returns the value of attribute buyer_identifier.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def buyer_identifier
  @buyer_identifier
end

#buyer_nameObject (readonly)

Returns the value of attribute buyer_name.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def buyer_name
  @buyer_name
end

#buyer_person_in_chargeObject (readonly)

Returns the value of attribute buyer_person_in_charge.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def buyer_person_in_charge
  @buyer_person_in_charge
end

#buyer_telephoneObject (readonly)

Returns the value of attribute buyer_telephone.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def buyer_telephone
  @buyer_telephone
end

#carrier_id1Object (readonly) Also known as: carrier_id

Returns the value of attribute carrier_id1.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def carrier_id1
  @carrier_id1
end

#carrier_id2Object (readonly)

Returns the value of attribute carrier_id2.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def carrier_id2
  @carrier_id2
end

#carrier_typeObject (readonly)

Returns the value of attribute carrier_type.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def carrier_type
  @carrier_type
end

Returns the value of attribute donate_mark.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def donate_mark
  @donate_mark
end

#hastaxObject (readonly)

Returns the value of attribute hastax.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def hastax
  @hastax
end

#invoice_typeObject (readonly)

Returns the value of attribute invoice_type.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def invoice_type
  @invoice_type
end

#itemsObject (readonly)

Returns the value of attribute items.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def items
  @items
end

#mail_sendObject (readonly)

Returns the value of attribute mail_send.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def mail_send
  @mail_send
end

#npo_banObject (readonly)

Returns the value of attribute npo_ban.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def npo_ban
  @npo_ban
end

#order_dateObject (readonly)

Returns the value of attribute order_date.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def order_date
  @order_date
end

#order_idObject (readonly)

Returns the value of attribute order_id.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def order_id
  @order_id
end

#payment_typeObject (readonly)

Returns the value of attribute payment_type.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def payment_type
  @payment_type
end

#remarkObject (readonly)

Returns the value of attribute remark.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def remark
  @remark
end

#round_numObject (readonly)

Returns the value of attribute round_num.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def round_num
  @round_num
end

#rtn_msgObject (readonly)

Returns the value of attribute rtn_msg.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def rtn_msg
  @rtn_msg
end

#tax_rateObject (readonly)

Returns the value of attribute tax_rate.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def tax_rate
  @tax_rate
end

#tax_typeObject (readonly)

Returns the value of attribute tax_type.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def tax_type
  @tax_type
end

#zero_reasonObject (readonly)

Returns the value of attribute zero_reason.



76
77
78
# File 'lib/cetustek/models/invoice_data.rb', line 76

def zero_reason
  @zero_reason
end

Instance Method Details

#mixed_tax?Boolean

混合稅率發票:每筆明細需標註 DType。

Returns:

  • (Boolean)


120
121
122
# File 'lib/cetustek/models/invoice_data.rb', line 120

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

#special_tax?Boolean

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

Returns:

  • (Boolean)


125
126
127
# File 'lib/cetustek/models/invoice_data.rb', line 125

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