Class: Cetustek::CancelInvoice

Inherits:
Object
  • Object
show all
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'
RESULT_MESSAGES =

Spec AVM-26-03 Table 10.

{
  'M:' => '欄位未填或格式錯誤',
  'M0' => 'XML 格式錯誤',
  'M1' => 'XML 格式錯誤',
  'C1' => '資料庫發生錯誤',
  'C2' => '資料有誤',
  'C3' => '該發票已過申報期間,需填入核准作廢文號 (return_tax_document_number)',
  'C4' => '無此發票號碼可以作廢',
  'C5' => '該發票已經作廢過',
  'C6' => '作廢資訊已經傳送過',
  'Invalid' => '無效 IP,請通知系統商'
}.freeze

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of CancelInvoice.

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
# File 'lib/cetustek/cancel_invoice.rb', line 27

def initialize(invoice_number, invoice_year, remark: '退貨', return_tax_document_number: nil)
  raise ArgumentError, 'remark (作廢原因) is required' if remark.to_s.strip.empty?

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

Instance Method Details

#executeObject



36
37
38
39
40
# File 'lib/cetustek/cancel_invoice.rb', line 36

def execute
  perform
  ResultCode.check!(@response.body[:cancel_invoice_response][:return],
                    RESULT_MESSAGES, success: SUCCESS_CODE)
end