Class: Cetustek::CancelInvoice

Inherits:
Object
  • Object
show all
Includes:
Soap
Defined in:
lib/cetustek/cancel_invoice.rb

Overview

2.2 CancelInvoice 作廢發票確認. Returns "C0" on success, raises ResultError otherwise. Uploading is not the end of it — the cancellation still has to be confirmed manually on the 鯨躍 platform before the invoice counts as void.

Constant Summary collapse

SUCCESS_CODE =
'C0'
MAX_REMARK_LENGTH =
20
RESULT_MESSAGES =

Spec AVM-26-03 Table 10.

ResultCode::COMMON.merge(
  'C1' => '資料庫發生錯誤',
  'C2' => '資料有誤',
  'C3' => '該發票已過申報期間,需填入核准作廢文號 (return_tax_document_number)',
  'C4' => '無此發票號碼可以作廢',
  'C5' => '該發票已經作廢過',
  'C6' => '作廢資訊已經傳送過'
).freeze

Instance Method Summary collapse

Methods included from Soap

#rentid, #soap_call, #soap_client, #soap_return, #source

Constructor Details

#initialize(invoice_number, invoice_year, remark:, return_tax_document_number: nil) ⇒ CancelInvoice

remark 是 Table 9 的必填作廢原因,沒有預設值可用:理由是業務決定的。

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
# File 'lib/cetustek/cancel_invoice.rb', line 24

def initialize(invoice_number, invoice_year, remark:, return_tax_document_number: nil)
  raise ArgumentError, 'remark (作廢原因) is required' if remark.to_s.strip.empty?
  raise ArgumentError, "remark must not exceed #{MAX_REMARK_LENGTH} characters" if remark.length > MAX_REMARK_LENGTH

  @invoice_number = invoice_number
  @invoice_year = invoice_year
  @remark = remark
  @return_tax_document_number = return_tax_document_number
end

Instance Method Details

#executeObject



34
35
36
37
# File 'lib/cetustek/cancel_invoice.rb', line 34

def execute
  response = soap_call(:cancel_invoice, invoicexml: generate_xml)
  ResultCode.check!(soap_return(response, :cancel_invoice), RESULT_MESSAGES, success: SUCCESS_CODE)
end