Ref: https://www.einvoice.nat.gov.tw/home/DownLoad?fileName=1510206773173_0.pdf
卡別 卡別說明 3J0002 手機條碼 1K0001 悠遊卡 1H0001 一卡通 CQ0001 自然人憑證條碼
CARD_TYPE= | |
CARD_NO= | |
APPID= | |
CARD_ENCRYPT= |
.env | |
*.json | |
invoice.list |
Ref: https://www.einvoice.nat.gov.tw/home/DownLoad?fileName=1510206773173_0.pdf
卡別 卡別說明 3J0002 手機條碼 1K0001 悠遊卡 1H0001 一卡通 CQ0001 自然人憑證條碼
#! /bin/bash | |
set pipefail | |
# Get CARD_TYPE, CARD_NO, APPID and CARD_ENCRYPT(password) | |
source .env | |
# Decide start date and end date | |
# | |
# If 'MONTH' is not specified, then we just query yesterday | |
# If 'MONTH' is specified, then we query the whole month | |
# 'YEAR' is optional. If not specify, use this year | |
YEAR=${YEAR:-$(date +%Y)} | |
if [[ -n $MONTH ]]; then | |
START_OF_MONTH=${YEAR}-${MONTH}-01 | |
STARTDATE=$(date --date "$START_OF_MONTH" +%Y/%m/%d) | |
ENDDATE=$(date --date "$START_OF_MONTH +1month -1day" +%Y/%m/%d ) | |
else | |
YESTERDAY=`date --date -1day +%Y/%m/%d` | |
STARTDATE=$YESTERDAY | |
ENDDATE=$YESTERDAY | |
fi | |
echo Time Period: $STARTDATE $ENDDATE >/dev/tty | |
curl -s https://api.einvoice.nat.gov.tw/PB2CAPIVAN/invServ/InvServ \ | |
-H 'accept: application/json' \ | |
-d version=0.5 \ | |
-d cardType=$CARD_TYPE \ | |
-d cardNo=$CARD_NO \ | |
-d expTimeStamp=`date -d +1minutes +%s` \ | |
-d action=carrierInvChk \ | |
-d timeStamp=`date -d +20seconds +%s` \ | |
-d startDate=$STARTDATE \ | |
-d endDate=$ENDDATE \ | |
-d onlyWinningInv=N \ | |
-d uuid=$(date +%s) \ | |
-d appID=$APPID \ | |
-d cardEncrypt=$CARD_ENCRYPT | \ | |
jq -r '.details[]|"\(.invDate.month)/\(.invDate.date) \(.invNum)"' | \ | |
while read date_not_paded INVNUM; do | |
echo $YEAR/$(date --date $date_not_paded +%m/%d) $INVNUM | |
done | sort | |
exit ${PIPESTATUS[0]} |
.ONESHELL: | |
SHELL := bash | |
invoice.list: | |
./get_invoices.sh >$@ | |
details: invoice.list | |
cat $< | while read date invoice; do | |
./query_details.sh $$invoice $$date | |
done |
source .env | |
curl -s https://api.einvoice.nat.gov.tw/PB2CAPIVAN/invServ/InvServ \ | |
-H 'accept: application/json' \ | |
-d version=0.5 \ | |
-d cardType=$CARD_TYPE \ | |
-d cardNo=$CARD_NO \ | |
-d expTimeStamp=`date -d +5minutes +%s` \ | |
-d action=carrierInvDetail \ | |
-d timeStamp=`date -d +20seconds +%s` \ | |
-d invNum=$1 \ | |
-d invDate=$2 \ | |
-d uuid=$(date +%s%3N) \ | |
-d appID=$APPID \ | |
-d cardEncrypt=$CARD_ENCRYPT | \ | |
jq . | \ | |
jq -r '"Expenses:Invoice \(.amount)\t\t\tTWD\n no: \"\(.invNum)\"\n desc: \"\(.details[0].description)\"\n time: \"\(.invoiceTime)\""' | |
exit ${PIPESTATUS[0]} |