iReceipt
Generate Taiwan's electronic receipt including QR code, bar code, and XML for National Taxation Bureau. The spec. from National Taxation Bureau is trivial but very complicated and hard to read. iReceipt can save your life and time!!!
Installation
npm install ireceipt --save
Run in a Browser
Just leverage Webpack to bundle IReceipt
to let IReceipt
work in a browser.
Usage
; const info = 1234 id: '{{SELLER_ID}}' name: '{{SELLER_NAME}}' id: '{{BUYER_ID}}' name: '{{BUYER_NAME}}' false items = '{{ITEM_DESCRIPTION}}' 3000 1 receipt = info items AESKey = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; receipt ; // toXmLwindowconsole; // Taiwan Receipt Lottery// The format of the list of winners:// 53925591 10510LC60123189...// 53925591 10510LC60122037...const winnersList = IReceiptReceipt;windowconsole;
Receipt
The receipt JavaScript object. It owns a ReceiptInfo
, Item
s and creates a Amount
based on items.
constructor(info, items)
info
ReceiptInfo
items
array of Item
Member Methods
toXML()
Receipt object to xml string.
generateBarCodeString()
generate bar code string.
generateLeftQRCodeString()
generate left QR code string including the receipt's information.
generateRightQRCodeString()
generate right QR code string including information for all items.
renderRightQRCode()
generate right QR code svg string. return Promise
.
renderLeftQRCode(AESKey)
generate left QR code svg string. return Promise
.
AESKey
the type is array (see the usage section) and the AES key is applied from National Taxation Bureau. More details: 取得電子發票QRCODE中AES加密金鑰
renderBarCode()
generate bar code svg string. return Promise
.
render(AESKey)
render Taiwan's electronic receipt. return Promise
.
AESKey
refer to renderLeftQRCode(AESKey)
ReceiptInfo
Store the receipt information.
constructor(number, date, seller, buyer, type, carrier, donationID, orderno)
number
receipt number
date
receipt date
seller
seller information, including id and name. ({ id: '{{SELLER_ID}}', name: '{{SELLER_NAME}}' }
)
buyer
buyer information, including id and name. ({ id: '{{BUYER_ID}}', name: '{{BUYER_NAME}}' }
)
type
receipt type (default 07
)
carrier
receipt carrier information, including id and type. ({id: '{{CARRIER_ID}}', type:'CARRIER_TYPE'}
)
donationID
charity's love code (愛心碼)
orderno
order number
Item
The product item buyed by buyer.
constructor(description, unitPrice, sequenceNumber, quantity, taxType)
description
product item's description
unitPrice
unit price for a product item
sequenceNumber
sequence number
quantity
quantity of product items (default 1
)
taxType
tax type (default TaxType.TAX
)
Amount
Store the amount information.
constructor(taxItems, freeTaxItems, zeroTaxItems)
taxItems
tax items
freeTaxItems
free tax items
zeroTaxItems
zero tax items
TaxType
Tax type enum.
TAX: 1 ZERO_TAX: 2 FREE_TAX: 3 SPECIAL_TAX: 4 COMPOUND_TAX: 9
EncodeType
Encode type for QR code enum.
BIG5: 0 UTF8: 1 BASE64: 3
Reference
- E-invoice Platform (財政部電子發票整合服務平台)
- 電子發票證明聯一維及二維條碼規格說明(V1.6)
- 電子發票資料交換標準文件與範例(V3.1.2)
- 取得電子發票QRCODE中AES加密金鑰
Author
Zheng-Xiang Ke, kf99916@gmail.com
Contributors
Sin-Fong Lyu, kingispeak@gmail.com
License
iReceipt is available under the MIT license. See the LICENSE file for more info.