Views: 237
Open Peppol C4で受信したデジタルインボイスの検証 Part 2
Nobuyuki SAMBUICHI
ISO/TC295 Audit data services/SG1 Semantic model Convener
1. Open Peppol C4でのスキーマトロン検証
昨年の記事で紹介したようにJP PINTでは、Basicルールが廃止されただけでなく、金額計算の基礎となる明細行の金額や税率ごとの課税対象金額の検証ルールが廃止されています。
また、Syntax bindingのページには、隅まで開かないと見落としてしまいそうな記載が隠されています。
これらの注意すべき条件も踏まえた検証ルールが不可欠です。
こちらの記事もご確認ください。
『JP PINT解体新書4 C4自動処理と記載金額の検算』
公開サイトからダウンロードできるサンプルインボイスを対象にして、こうした条件に違反したものがないか検証してみました。
1.1. 金額計算が正しいか
税率毎に集計された課税対象金額が正しく計算されているかの検証ルールが提供されていません。
C4でのデジタルインボイスに記載された金額が妥当か検証するルールを追加しました。
検証対象のXML要素を指定する context では、
/ubl:Invoice/cac:TaxTotal[cbc:TaxAmount/@currencyID = normalizeーspace(/ubl:Invoice/cbc:DocumentCurrencyCode)]/cac:TaxSubtotal[cac:TaxCategory/normalize-space(cbc:ID) = ‘S’]
および
/ubl:Invoice/cac:TaxTotal[cbc:TaxAmount/@currencyID = normalizeーspace(/ubl:Invoice/cbc:DocumentCurrencyCode)]/cac:TaxSubtotal[cac:TaxCategory/normalize-space(cbc:ID) = ‘AA’]
を条件としました。
課税対象金額
<rule context="/ubl:Invoice/cac:TaxTotal[cbc:TaxAmount/@currencyID=normalize-space(/ubl:Invoice/cbc:DocumentCurrencyCode)]/cac:TaxSubtotal[cac:TaxCategory/normalize-space(cbc:ID)='S']">
<assert id="WuWei-S-01" flag="fatal" test="
(
exists(/ubl:Invoice/cac:InvoiceLine[cac:Item/cac:ClassifiedTaxCategory/normalize-space(cbc:ID)='S']) or
exists(/ubl:Invoice/cac:AllowanceCharge[cac:TaxCategory/normalize-space(cbc:ID)='S'])
) and
u:slack(
xs:decimal(cbc:TaxableAmount),
(
sum(/ubl:Invoice/cac:InvoiceLine[cac:Item/cac:ClassifiedTaxCategory/normalize-space(cbc:ID)='S']/xs:decimal(cbc:LineExtensionAmount)) +
sum(/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator=true()][cac:TaxCategory/normalize-space(cbc:ID)='S']/xs:decimal(cbc:Amount)) -
sum(/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator=false()][cac:TaxCategory/normalize-space(cbc:ID)='S']/xs:decimal(cbc:Amount))
),
1
)
">
[WuWei-S-01]In case of the VAT category code (BT-118) is "Standard rated", the VAT category taxable amount (BT-116) in a VAT breakdown (BG-23) shall equal the sum of Invoice line net amounts (BT-131) plus the sum of document level charge amounts (BT-99) minus the sum of document level allowance amounts (BT-92) where the VAT category code (BT-151, BT-102, BT-95) is "Standard rated" and the VAT rate (BT-152, BT-103, BT-96) equals the VAT category rate (BT-119).
標準税率(BT-118 VAT category code is "S: Standard rated")のとき、課税分類毎の集計 (BG-23 VAT breakdown)に記載された課税対象金額(BT-116 VAT category taxable amount )は、 明細行の正味金額(BT-131 Invoice line net amounts ) に同じ区分と同じ税率の文書レベルの追加請求金額 (BT-99 sum of document level charge amounts )を加えた金額から同じ区分と同じ税率の文書レベルの返金金額 (BT-92 sum of document level allowance amounts )を差し引いた金額でなければならない。ここで、 課税区分コード (BT-151, BT-102, BT-95) は、標準税率 "S: Standard rated" であり、税率 (BT-152, BT-103, BT-96) は、その税率(BT-119)と等しいものとする。
</assert>
</rule>
<rule context="/ubl:Invoice/cac:TaxTotal[cbc:TaxAmount/@currencyID=normalize-space(/ubl:Invoice/cbc:DocumentCurrencyCode)]/cac:TaxSubtotal[cac:TaxCategory/normalize-space(cbc:ID)='AA']">
<assert id="WuWei-AA-01" flag="fatal" test="
(
exists(/ubl:Invoice/cac:InvoiceLine[cac:Item/cac:ClassifiedTaxCategory/normalize-space(cbc:ID)='AA']) or
exists(/ubl:Invoice/cac:AllowanceCharge[cac:TaxCategory/normalize-space(cbc:ID)='AA'])
) and
u:slack(
xs:decimal(cbc:TaxableAmount),
(
sum(/ubl:Invoice/cac:InvoiceLine[cac:Item/cac:ClassifiedTaxCategory/normalize-space(cbc:ID)='AA']/xs:decimal(cbc:LineExtensionAmount)) +
sum(/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator=true()][cac:TaxCategory/normalize-space(cbc:ID)='AA']/xs:decimal(cbc:Amount)) -
sum(/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator=false()][cac:TaxCategory/normalize-space(cbc:ID)='AA']/xs:decimal(cbc:Amount))
),
1
)
">
[WuWei-AA-01] In case of the VAT category code (BT-118) is "Reduced rated", the VAT category taxable amount (BT-116) in a VAT breakdown (BG-23) shall equal the sum of Invoice line net amounts (BT-131) plus the sum of document level charge amounts (BT-99) minus the sum of document level allowance amounts (BT-92) where the VAT category code (BT-151, BT-102, BT-95) is "Reduced rated" and the VAT rate (BT-152, BT-103, BT-96) equals the VAT category rate (BT-119).
軽減税率(BT-118 VAT category code is "AA: Reduced rated")のとき、課税分類毎の集計 (BG-23 VAT breakdown)に記載された課税対象金額(BT-116 VAT category taxable amount )は、 明細行の正味金額(BT-131 Invoice line net amounts ) に同じ区分と同じ税率の文書レベルの追加請求金額 (BT-99 sum of document level charge amounts)を加えた金額から同じ区分と同じ税率の文書レベルの返金金額 (BT-92 sum of document level allowance amounts )を差し引いた金額でなければならない。ここで、 課税区分コード (BT-151, BT-102, BT-95) は、軽減税率 "AA: Reduced rated" であり、税率 (BT-152, BT-103, BT-96) は、その税率(BT-119)と等しいものとする。
</assert>
</rule>
ここで、チェックのために使用しているのが slack() 関数です。
<xsl:function xmlns:xsl="http://www.w3.org/1999/XSL/Transform" name="u:slack" as="xs:boolean">
<xsl:param name="exp" as="xs:decimal"/>
<xsl:param name="val" as="xs:decimal"/>
<xsl:param name="slack" as="xs:decimal"/>
<xsl:value-of select="xs:decimal($exp + $slack) >= $val and xs:decimal($exp - $slack) <= $val"/>
</xsl:function>
チェック対象金額と計算結果の金額が判定範囲内かチェックします。
チェック対象金額 + slack値 >= 計算結果 and チェック対象金額 – slack値 <= 計算結果
注: cac:TaxTotal[cbc:TaxAmount/@currencyID=normalizeーspace(/ubl:Invoice/cbc:DocumentCurrencyCode)]は、外貨建ての場合の日本円での税率別合計 cac:TaxTotal[cac:TaxAmount/@currencyID=normalizeーspace(/ubl:Invoice/cbc:TaxCurrencyCode)]と区別するために条件を付加しています。
外貨について検証しないのであれば、cac:TaxTotal[cbc:TaxAmount/@currencyID=’JPY’]でも良いかと思います。
なお、外貨のときには、先に紹介すした slack() 関数の基準値を BIS Billing 3.0とあわせて 0.02 とすべきでしょう。
JPYと外貨で異なるルールを適用するのであれば、context条件を分解して、
/ubl:Invoice[normalizeーspace(cbc:DocumentCurrencyCode) = ‘JPY’]/cac:TaxTotal[cbc:TaxAmount/@currencyID = normalizeーspace(/ubl:Invoice/cbc:DocumentCurrencyCode)]/cac:TaxSubtotal[cac:TaxCategory/normalizeーspace(cbc:ID) = ‘S’]
および
/ubl:Invoice[normalizeーspace(cbc:DocumentCurrencyCode) != ‘JPY’]/cac:TaxTotal[cbc:TaxAmount/@currencyID = normalizeーspace(/ubl:Invoice/cbc:DocumentCurrencyCode)]/cac:TaxSubtotal[cac:TaxCategory/normalizeーspace(cbc:ID) = ‘S’]
のように定義して、それぞれで slack値を 1 および 0.02 としたルール定義が必要です。
明細行の金額
<rule context="cac:InvoiceLine">
<let name="lineExtensionAmount" value="
if (cbc:LineExtensionAmount)
then xs:decimal(cbc:LineExtensionAmount)
else 0"/>
<let name="quantity" value="
if (cbc:InvoicedQuantity)
then xs:decimal(cbc:InvoicedQuantity)
else 1"/>
<let name="priceAmount" value="
if (cac:Price/cbc:PriceAmount)
then xs:decimal(cac:Price/cbc:PriceAmount)
else 0"/>
<let name="baseQuantity" value="
if (
cac:Price/cbc:BaseQuantity and
xs:decimal(cac:Price/cbc:BaseQuantity) != 0
)
then xs:decimal(cac:Price/cbc:BaseQuantity)
else 1"/>
<let name="allowancesTotal" value="
if (cac:AllowanceCharge[normalize-space(cbc:ChargeIndicator) = 'false'])
then round(sum(cac:AllowanceCharge[normalize-space(cbc:ChargeIndicator) = 'false']/cbc:Amount/xs:decimal(.)) * 10 * 10) div 100
else 0"/>
<let name="chargesTotal" value="
if (cac:AllowanceCharge[normalize-space(cbc:ChargeIndicator) = 'true'])
then round(sum(cac:AllowanceCharge[normalize-space(cbc:ChargeIndicator) = 'true']/cbc:Amount/xs:decimal(.)) * 10 * 10) div 100
else 0"/>
<assert id="WuWei-R-01" flag="fatal" test="
u:slack(
$lineExtensionAmount,
($quantity * ($priceAmount div $baseQuantity)) + $chargesTotal - $allowancesTotal,
0.02
)">
[WuWei-R-01] ibt-131 Invoice line net amount MUST equal (ibt-146 Item net price X (ibt-129Invoiced quantity ÷ ibt-149Item price base quantity ) + ibt-141 Invoice line charge amount – ibt-136Invoice line allowance amount.
明細行の正味金額(ibt-131) = 品目の標準価格(ibt-146) X 請求する数量(ibt-129) ÷ 品奥の基準数量(ibt-149) + (ibt-141 Invoice line charge amount) – (ibt-136Invoice line allowance amount).
</assert>
</rule>
不正データの検証
意図的に品目単価および課税対象金額を不正な金額としたJapan PINT Invoice UBL Example1_error-minimum.xmlファイルを上記のルールで検証しました。
$ ./jp-pint-update-xslt-and-validate.sh
++ export LC_ALL=C
++ LC_ALL=C
++ Tmp=/tmp/jp-pint-update-xslt-and-validate.sh.37767
++ exec
convert to XSLT - takes forever
[INFO] Scanning for projects...
[INFO]
[INFO] -----------< com.helger:jp-pint-V1.0extra-validation-rules >------------
[INFO] Building JP-PINT-V1.0extra-validation-rules 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- ph-buildinfo-maven-plugin:3.0.0:generate-buildinfo (default) @ jp-pint-V1.0extra-validation-rules ---
[INFO] Successfully created temp directory buildinfo-maven-plugin
[INFO]
[INFO] --- ph-schematron-maven-plugin:5.2.0:convert (ubl) @ jp-pint-V1.0extra-validation-rules ---
[INFO] Converting Schematron file '/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/schematron/wuwei-validation-rules.sch' to XSLT file '/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/xslt/wuwei-validation-rules.xslt'
[WARNING] /Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/schematron/wuwei-validation-rules.sch [0:0]: Transformation warning - A function that computes atomic values should use xsl:sequence rather than xsl:value-of
[INFO] Converting Schematron file '/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/schematron/PINT-jurisdiction-aligned-rules.sch' to XSLT file '/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/xslt/PINT-jurisdiction-aligned-rules.xslt'
[WARNING] /Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/schematron/PINT-jurisdiction-aligned-rules.sch [0:0]: Transformation warning - A function that computes atomic values should use xsl:sequence rather than xsl:value-of
[INFO] Converting Schematron file '/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/schematron/PINT-UBL-validation-preprocessed.sch' to XSLT file '/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/xslt/PINT-UBL-validation-preprocessed.xslt'
[WARNING] /Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/schematron/PINT-UBL-validation-preprocessed.sch [0:0]: Transformation warning - A function that computes atomic values should use xsl:sequence rather than xsl:value-of
[WARNING] /Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/schematron/PINT-UBL-validation-preprocessed.sch [0:0]: Transformation warning - A function that computes atomic values should use xsl:sequence rather than xsl:value-of
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ jp-pint-V1.0extra-validation-rules ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/src/main/resources
[INFO] Copying 1 resource to META-INF
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.624 s
[INFO] Finished at: 2023-03-25T19:21:21+09:00
[INFO] ------------------------------------------------------------------------
validate afterwards
[INFO] Scanning for projects...
[INFO]
[INFO] -----------< com.helger:jp-pint-v1.0extra-validation-rules >------------
[INFO] Building JP-PINT-V1.0extra-validation-rules 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- ph-schematron-maven-plugin:5.2.0:validate (shared) @ jp-pint-v1.0extra-validation-rules ---
[INFO] Compiling XSLT instance [file=/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/xslt/PINT-UBL-validation-preprocessed.xslt]
[WARNING] /Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/xslt/PINT-UBL-validation-preprocessed.xslt [0:0]: Transformation warning - A function that computes atomic values should use xsl:sequence rather than xsl:value-of
[WARNING] /Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/xslt/PINT-UBL-validation-preprocessed.xslt [0:0]: Transformation warning - A function that computes atomic values should use xsl:sequence rather than xsl:value-of
[INFO] Successfully parsed Schematron file '/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/xslt/PINT-UBL-validation-preprocessed.xslt'
[INFO] Validating XML file '/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/check/Japan PINT Invoice UBL Example1_error-minimum.xml' against Schematron rules from '/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/xslt/PINT-UBL-validation-preprocessed.xslt' expecting success
[INFO] Creating JAXB context for package org.oclc.purl.dsdl.svrl using ClassLoader ClassRealm[plugin>com.helger.maven:ph-schematron-maven-plugin:5.2.0, parent: jdk.internal.loader.ClassLoaders$AppClassLoader@42110406]
[INFO]
[INFO] --- ph-schematron-maven-plugin:5.2.0:validate (aligned) @ jp-pint-v1.0extra-validation-rules ---
[INFO] Compiling XSLT instance [file=/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/xslt/PINT-jurisdiction-aligned-rules.xslt]
[WARNING] /Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/xslt/PINT-jurisdiction-aligned-rules.xslt [0:0]: Transformation warning - A function that computes atomic values should use xsl:sequence rather than xsl:value-of
[INFO] Successfully parsed Schematron file '/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/xslt/PINT-jurisdiction-aligned-rules.xslt'
[INFO] Validating XML file '/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/check/Japan PINT Invoice UBL Example1_error-minimum.xml' against Schematron rules from '/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/xslt/PINT-jurisdiction-aligned-rules.xslt' expecting success
[INFO]
[INFO] --- ph-schematron-maven-plugin:5.2.0:validate (extra) @ jp-pint-v1.0extra-validation-rules ---
[INFO] Compiling XSLT instance [file=/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/xslt/wuwei-validation-rules.xslt]
[WARNING] /Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/xslt/wuwei-validation-rules.xslt [0:0]: Transformation warning - A function that computes atomic values should use xsl:sequence rather than xsl:value-of
[INFO] Successfully parsed Schematron file '/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/xslt/wuwei-validation-rules.xslt'
[INFO] Validating XML file '/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/check/Japan PINT Invoice UBL Example1_error-minimum.xml' against Schematron rules from '/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/ubl/xslt/wuwei-validation-rules.xslt' expecting success
[ERROR] 2 failed Schematron assertions for XML file '/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/check/Japan PINT Invoice UBL Example1_error-minimum.xml'
[ERROR] [fatal_error] in /*:Invoice[namespace-uri()='urn:oasis:names:specification:ubl:schema:xsd:Invoice-2'][1]/*:TaxTotal[namespace-uri()='urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2'][1]/*:TaxSubtotal[namespace-uri()='urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2'][1] @ /Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/check/Japan PINT Invoice UBL Example1_error-minimum.xml [WuWei-S-01]In case of the VAT category code (BT-118) is "Standard rated", the VAT category taxable amount (BT-116) in a VAT breakdown (BG-23) shall equal the sum of Invoice line net amounts (BT-131) plus the sum of document level charge amounts (BT-99) minus the sum of document level allowance amounts (BT-92) where the VAT category code (BT-151, BT-102, BT-95) is "Standard rated" and the VAT rate (BT-152, BT-103, BT-96) equals the VAT category rate (BT-119).
????(BT-118 VAT category code is "S: Standard rated")???????????? (BG-23 VAT breakdown)????????????(BT-116 VAT category taxable amount )?? ????????(BT-131 Invoice line net amounts ) ??????????????????????? (BT-99 sum of document level charge amounts )???????????????????????????? (BT-92?sum of document level allowance amounts )?????????????????????? ??????? (BT-151, BT-102, BT-95) ?????? "S: Standard rated" ?????? (BT-152, BT-103, BT-96) ??????(BT-119)?????????? Test=( exists(/ubl:Invoice/cac:InvoiceLine[cac:Item/cac:ClassifiedTaxCategory/normalize-space(cbc:ID)='S']) or exists(/ubl:Invoice/cac:AllowanceCharge[cac:TaxCategory/normalize-space(cbc:ID)='S']) ) and ( ( xs:decimal(cbc:TaxableAmount - 1) < ( sum(/ubl:Invoice/cac:InvoiceLine[cac:Item/cac:ClassifiedTaxCategory/normalize-space(cbc:ID)='S']/xs:decimal(cbc:LineExtensionAmount)) + sum(/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator=true()][cac:TaxCategory/normalize-space(cbc:ID)='S']/xs:decimal(cbc:Amount)) - sum(/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator=false()][cac:TaxCategory/normalize-space(cbc:ID)='S']/xs:decimal(cbc:Amount)) ) ) and ( xs:decimal(cbc:TaxableAmount + 1) > ( sum(/ubl:Invoice/cac:InvoiceLine[cac:Item/cac:ClassifiedTaxCategory/normalize-space(cbc:ID)='S']/xs:decimal(cbc:LineExtensionAmount)) + sum(/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator=true()][cac:TaxCategory/normalize-space(cbc:ID)='S']/xs:decimal(cbc:Amount)) - sum(/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator=false()][cac:TaxCategory/normalize-space(cbc:ID)='S']/xs:decimal(cbc:Amount)) ) ) )
[ERROR] [fatal_error] in /*:Invoice[namespace-uri()='urn:oasis:names:specification:ubl:schema:xsd:Invoice-2'][1]/*:InvoiceLine[namespace-uri()='urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2'][2] @ /Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/check/Japan PINT Invoice UBL Example1_error-minimum.xml [WuWei-R-01] ibt-131 Invoice line net amount MUST equal (ibt-146 Item net price X (ibt-129Invoiced quantity ? ibt-149Item price base quantity ) + ibt-141 Invoice line charge amount ? ibt-136Invoice line allowance amount.
????????(ibt-131) = ???????(ibt-146) X ??????(ibt-129) ? ???????(ibt-149) + (ibt-141 Invoice line charge amount) ? (ibt-136Invoice line allowance amount). Test=u:slack( $lineExtensionAmount, ($quantity * ($priceAmount div $baseQuantity)) + $chargesTotal - $allowancesTotal, 0.02 )
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.371 s
[INFO] Finished at: 2023-03-25T19:21:27+09:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.helger.maven:ph-schematron-maven-plugin:5.2.0:validate (extra) on project jp-pint-v1.0extra-validation-rules: 2 failed Schematron assertions for XML file '/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/check/Japan PINT Invoice UBL Example1_error-minimum.xml' -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
$
SharedルールおよびAlignedルールでは問題が報告されませんでしたが、Extraルールでエラーが2件報告されています。
[ERROR] 2 failed Schematron assertions for XML file '/Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/check/Japan PINT Invoice UBL Example1_error-minimum.xml'
[ERROR] [fatal_error] in /*:Invoice[namespace-uri()='urn:oasis:names:specification:ubl:schema:xsd:Invoice-2'][1]/*:TaxTotal[namespace-uri()='urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2'][1]/*:TaxSubtotal[namespace-uri()='urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2'][1] @ /Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/check/Japan PINT Invoice UBL Example1_error-minimum.xml [WuWei-S-01]In case of the VAT category code (BT-118) is "Standard rated", the VAT category taxable amount (BT-116) in a VAT breakdown (BG-23) shall equal the sum of Invoice line net amounts (BT-131) plus the sum of document level charge amounts (BT-99) minus the sum of document level allowance amounts (BT-92) where the VAT category code (BT-151, BT-102, BT-95) is "Standard rated" and the VAT rate (BT-152, BT-103, BT-96) equals the VAT category rate (BT-119).
????(BT-118 VAT category code is "S: Standard rated")???????????? (BG-23 VAT breakdown)????????????(BT-116 VAT category taxable amount )?? ????????(BT-131 Invoice line net amounts ) ??????????????????????? (BT-99 sum of document level charge amounts )???????????????????????????? (BT-92?sum of document level allowance amounts )?????????????????????? ??????? (BT-151, BT-102, BT-95) ?????? "S: Standard rated" ?????? (BT-152, BT-103, BT-96) ??????(BT-119)?????????? Test=( exists(/ubl:Invoice/cac:InvoiceLine[cac:Item/cac:ClassifiedTaxCategory/normalize-space(cbc:ID)='S']) or exists(/ubl:Invoice/cac:AllowanceCharge[cac:TaxCategory/normalize-space(cbc:ID)='S']) ) and ( ( xs:decimal(cbc:TaxableAmount - 1) < ( sum(/ubl:Invoice/cac:InvoiceLine[cac:Item/cac:ClassifiedTaxCategory/normalize-space(cbc:ID)='S']/xs:decimal(cbc:LineExtensionAmount)) + sum(/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator=true()][cac:TaxCategory/normalize-space(cbc:ID)='S']/xs:decimal(cbc:Amount)) - sum(/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator=false()][cac:TaxCategory/normalize-space(cbc:ID)='S']/xs:decimal(cbc:Amount)) ) ) and ( xs:decimal(cbc:TaxableAmount + 1) > ( sum(/ubl:Invoice/cac:InvoiceLine[cac:Item/cac:ClassifiedTaxCategory/normalize-space(cbc:ID)='S']/xs:decimal(cbc:LineExtensionAmount)) + sum(/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator=true()][cac:TaxCategory/normalize-space(cbc:ID)='S']/xs:decimal(cbc:Amount)) - sum(/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator=false()][cac:TaxCategory/normalize-space(cbc:ID)='S']/xs:decimal(cbc:Amount)) ) ) )
[ERROR] [fatal_error] in /*:Invoice[namespace-uri()='urn:oasis:names:specification:ubl:schema:xsd:Invoice-2'][1]/*:InvoiceLine[namespace-uri()='urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2'][2] @ /Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/check/Japan PINT Invoice UBL Example1_error-minimum.xml [WuWei-R-01] ibt-131 Invoice line net amount MUST equal (ibt-146 Item net price X (ibt-129Invoiced quantity ? ibt-149Item price base quantity ) + ibt-141 Invoice line charge amount ? ibt-136Invoice line allowance amount.
????????(ibt-131) = ???????(ibt-146) X ??????(ibt-129) ? ???????(ibt-149) + (ibt-141 Invoice line charge amount) ? (ibt-136Invoice line allowance amount). Test=u:slack( $lineExtensionAmount, ($quantity * ($priceAmount div $baseQuantity)) + $chargesTotal - $allowancesTotal, 0.02 )
最初のエラーは、次のXPathで指定された箇所、最初の<cac:TaxSubtotal>です。[WuWei-S-01]ルールでエラーです。
/:Invoice[namespace-uri()=’urn:oasis:names:specification:ubl:schema:xsd:Invoice-2′][1]/:TaxTotal[namespace-uri()=’urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2′][1]/*:TaxSubtotal[namespace-uri()=’urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2′][1]
最初の<cac:TaxSubtotal>の課税対象金額を訂正しました。
<cac:TaxTotal>
<cbc:TaxAmount currencyID="JPY">25250</cbc:TaxAmount> <!-- IBT-110 - Invoice total TAX amount -->
<cac:TaxSubtotal> <!-- IBG-23 - TAX BREAKDOWN -->
<cbc:TaxableAmount currencyID="JPY">252500</cbc:TaxableAmount> <!-- IBT-116 - TAX category taxable amount -->
<cbc:TaxAmount currencyID="JPY">25250</cbc:TaxAmount> <!-- IBT-117 - TAX category tax amount -->
<cac:TaxCategory>
<cbc:ID>S</cbc:ID> <!-- IBT-118 - TAX category code -->
<cbc:Percent>10</cbc:Percent> <!-- IBT-119 - TAX category rate -->
<cac:TaxScheme>
<cbc:ID>VAT</cbc:ID> <!-- IBT-118, qualifier -->
</cac:TaxScheme>
</cac:TaxCategory>
</cac:TaxSubtotal>
インボイスの合計請求金額も訂正しました。
<cac:LegalMonetaryTotal> <!-- IBG-22 - DOCUMENT TOTALS -->
<cbc:LineExtensionAmount currencyID="JPY">255990</cbc:LineExtensionAmount> <!-- IBT-106 - Sum of Invoice line net amount -->
<cbc:TaxExclusiveAmount currencyID="JPY">255990</cbc:TaxExclusiveAmount> <!-- IBT-109 - Invoice total amount without TAX -->
<cbc:TaxInclusiveAmount currencyID="JPY">281240</cbc:TaxInclusiveAmount> <!-- IBT-112 - Invoice total amount with TAX -->
<cbc:AllowanceTotalAmount currencyID="JPY">0</cbc:AllowanceTotalAmount> <!-- IBT-107 - Sum of allowances on document level -->
<cbc:ChargeTotalAmount currencyID="JPY">0</cbc:ChargeTotalAmount> <!-- IBT-108 - Sum of charges on document level -->
<cbc:PrepaidAmount currencyID="JPY">0</cbc:PrepaidAmount> <!-- IBT-113 - Paid amount -->
<cbc:PayableRoundingAmount currencyID="JPY">0</cbc:PayableRoundingAmount> <!-- IBT-114 - Rounding amount -->
<cbc:PayableAmount currencyID="JPY">281240</cbc:PayableAmount> <!-- IBT-115 - Amount due for payment -->
</cac:LegalMonetaryTotal>
次のエラーは、次のXPathで指定された箇所、2件目の<cac:InvoiceLine>です。[WuWei-R-01]ルールでエラーです。
/:Invoice[namespace-uri()=’urn:oasis:names:specification:ubl:schema:xsd:Invoice-2′][1]/:InvoiceLine[namespace-uri()=’urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2′][2]
品目単価を訂正しました。
<cac:InvoiceLine> <!-- IBG-25 - INVOICE LINE -->
<cbc:ID>2</cbc:ID> <!-- IBT-126 - Invoice line identifier -->
<cbc:InvoicedQuantity unitCode="H87">5</cbc:InvoicedQuantity> <!-- IBT-130 - Invoiced quantity unit of measure code, IBT-129 - Invoiced quantity -->
<cbc:LineExtensionAmount currencyID="JPY">2500</cbc:LineExtensionAmount> <!-- IBT-131 - Invoice line net amount -->
<cac:InvoicePeriod> <!-- IBG-26 - INVOICE LINE PERIOD -->
<cbc:StartDate>2023-10-18</cbc:StartDate> <!-- IBT-134 - Invoice line period start date -->
<cbc:EndDate>2023-10-18</cbc:EndDate> <!-- IBT-135 - Invoice line period end date -->
</cac:InvoicePeriod>
<cac:Item> <!-- IBG-31 - ITEM INFORMATION -->
<cbc:Name>コピー用紙(A4)</cbc:Name> <!-- IBT-153 - Item name -->
<cac:ClassifiedTaxCategory> <!-- IBG-30 - LINE TAX INFORMATION -->
<cbc:ID>S</cbc:ID> <!-- IBT-151 - Invoiced item TAX category code -->
<cbc:Percent>10</cbc:Percent> <!-- IBT-152 - Invoiced item TAX rate -->
<cac:TaxScheme>
<cbc:ID>VAT</cbc:ID> <!-- IBT-167 - Tax Scheme -->
</cac:TaxScheme>
</cac:ClassifiedTaxCategory> <!-- IBG-32 - ITEM ATTRIBUTES -->
</cac:Item>
<cac:Price> <!-- IBG-29 - PRICE DETAILS -->
<cbc:PriceAmount currencyID="JPY">500</cbc:PriceAmount> <!-- IBT-146 - Item net price -->
<cbc:BaseQuantity unitCode="H87">1</cbc:BaseQuantity> <!-- IBT-149 - Item price base quantity, IBT-150 - Item price base quantity unit of measure code -->
</cac:Price>
</cac:InvoiceLine>
1.2. UBL構文で必須とされている要素の規定値の設定
構文バインディング(Syntax binding)一覧表には表示されていませんが、次の要素はUBLの必須項目なので既定値 NA を指定しなければなりません。
[WuWei-D-06]
cac:DespatchLineReference

) or
not(
(//cbc:StartDate >= '2023-10-01') or
(//cbc:EndDate >= '2023-10-01')
)">
[WuWei-D-08] If a date of an invoice period (ibg-14) or an invoice line period (ibg-26) is on and after October 1st 2023, Buyer Tax Identifier shall be coded by using a Registration Number for Qualified Invoice purpose in Japan, which consists of 14 digits that start with T.</assert>
Japan PINT Invoice UBL Example.xmlの検証ログを次に示します。
[ERROR] [fatal_error] in /*:Invoice[namespace-uri()='urn:oasis:names:specification:ubl:schema:xsd:Invoice-2'][1]/*:InvoiceLine[namespace-uri()='urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2'][1]/*:DespatchLineReference[namespace-uri()='urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2'][1] @ /Users/pontsoleil/Documents/GitHub/JP-PINT-Customized/validation/check/Japan PINT Invoice UBL Example.xml [WuWei-D-06] An identifier for a referenced despatch advice shall be reported with syntax required line identification and its value shall be 'NA'.
???????????????????ID???????????????????????NA?????????? Test=normalize-space(cbc:LineID)='NA'
エラー箇所のXPathは、/:Invoice[namespace-uri()=’urn:oasis:names:specification:ubl:schema:xsd:Invoice-2′][1]/:InvoiceLine[namespace-uri()=’urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2′][1]/*:DespatchLineReference[namespace-uri()=’urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2′][1]なので、XML編集ソフトで確認すると<cbc:LineID>に NA でなく 010 が設定されていることが分かりました。

Japan PINT Invoice UBL Example5-AllowanceCharge.xmlにも同様のエラーがありました。
[WuWei-D-07]
cac:CardAccount

請求書期間(ibg-14)または請求書明細期間(ibg-26)の日付が2023年10月1日以降の場合、買い手の適格請求書発行事業者登録番号は、Tで始まる14桁で構成されなければならない。</assert>
</rule>
<rule context="/ubl:Invoice/cac:TaxRepresentativeParty/cac:Party/cac:PartyTaxScheme[cac:TaxScheme/normalize-space(upper-case(cbc:ID))='VAT']">
<assert id="WuWei-D-09" flag="fatal" test="
(
(
(//cbc:StartDate >= '2023-10-01') or
(//cbc:EndDate >= '2023-10-01')) and
matches(normalize-space(cbc:CompanyID),'^T[0-9]{13}$'
エラー箇所のXPathは、/:Invoice[namespace-uri()=’urn:oasis:names:specification:ubl:schema:xsd:Invoice-2′][1]/:PaymentMeans[namespace-uri()=’urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2′][1]/*:CardAccount[namespace-uri()=’urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2′][1]なので、XML編集ソフトで確認すると<cbc:NetworkID>に NA でなく VISA が設定されていることが分かりました。

1.3. Tax Scheme IDの設定
消費税のTax Scheme IDは、VATです。
売り手、買い手、および売手の税務代理人の適格請求書発行事業者のTax Scheme IDは VAT でなければなりませんし、その番号は、先頭が T でその後に13個の数字が続く14桁でなければなりません。
<rule context="/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme">
<assert id="WuWei-D-01" flag="fatal" test="normalize-space(cbc:ID)='VAT'">
[WuWei-D-01] Seller's tax schema ID shall be VAT.
売り手の税スキーマは、VATでなければならない。</assert>
</rule>
<rule context="/ubl:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme">
<assert id="WuWei-D-02" flag="fatal" test="normalize-space(cbc:ID)='VAT'">
[WuWei-D-02] Buyer's tax schema ID shall be VAT.
買い手の税スキーマは、VATでなければならない。</assert>
</rule>
<rule context="/ubl:Invoice/cac:TaxRepresentativeParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme">
<assert id="WuWei-D-03" flag="fatal" test="
exists(cbc:ID) and
normalize-space(cbc:ID)='VAT'
">
[WuWei-D-03] Tax representative party's tax schema ID shall be VAT.
売り手の税代理人の税スキーマは、VATでなければならない。</assert>
</rule>
明細行の品目のTax Category CodeはVATでなければなりません。
<rule context="/ubl:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme[cac:TaxScheme/normalize-space(upper-case(cbc:ID))='VAT']">
<assert id="WuWei-D-08" flag="fatal" test="
(
(
(//cbc:StartDate >= '2023-10-01') or
(//cbc:EndDate >= '2023-10-01')) and
matches(normalize-space(cbc:CompanyID),'^T[0-9]{13}$'
)
<rule context="cac:TaxCategory/cac:TaxScheme/cbc:ID | cac:ClassifiedTaxCategory/cac:TaxScheme/cbc:ID">
<assert id="aligned-ibr-jp-03" flag="fatal" test="matches(normalize-space(.),'VAT')">[aligned-ibr-jp-03]-Tax scheme shall use VAT from UNECE 5153 code list. VAT means Consumption Tax in Japan.</assert>
</rule>
aligned-ibr-jp-03は、インボイスで表記できる税を消費税のみに限定しています。
消費税のTax Scheme IDは VAT でなければなりませんが、対象範囲を税率別の税額合計金額や文書レベルの返金/追加請求と詳細に分けて定義しておいて方が良いように思えます。
<rule context="/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator=false()]/cac:TaxCategory/cac:TaxScheme">
<assert id="WuWei-D-04" flag="fatal" test="
exists(cbc:ID) and
normalize-space(cbc:ID)='VAT'
">
[WuWei-D-04] Tax schema ID of the document level allowance shall be VAT.
文書レベルの返金の税スキーマは、VATでなければならない。</assert>
</rule>
<rule context="/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator=true()]/cac:TaxCategory/cac:TaxScheme">
<assert id="WuWei-D-05" flag="fatal" test="
exists(cbc:ID) and
normalize-space(cbc:ID)='VAT'
">
[WuWei-D-05] Tax schema ID of the document level charge shall be VAT.
文書レベルの追加請求の税スキーマは、VATでなければならない。</assert>
</rule>
<rule context="/Invoice/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cac:TaxScheme">
<assert id="WuWei-D-06" flag="fatal" test="
exists(cbc:ID) and
normalize-space(cbc:ID)='VAT'
">
[WuWei-D-06] Tax schema ID of the tax subtotal shall be VAT.
課税分類別の税スキーマは、VATでなければならない。</assert>
</rule>
<rule context="/Invoice/cac:InvoiceLine/cac:Item/cac:ClassifiedTaxCategory/cac:TaxScheme">
<assert id="WuWei-D-07" flag="fatal" test="
exists(cbc:ID) and
normalize-space(cbc:ID)='VAT'
">
[WuWei-D-07] Tax schema ID of the invoice line invoiced item shall be VAT.
明細行の品目の税スキーマは、VATでなければならない。</assert>
</rule>
車両を購入した際の重量税など請求書には消費税以外の税も記載されることがありますので、消費税しか表現できないように制限しているとJP PINTの適用範囲が限られてしまうと思います。文書レベルの返金/追加請求の税については、消費税に限定しない法が望ましいと思います。
1.4 買い手の適格請求書発行事業者番号
売り手の適格請求書発行事業者番号については、aligned-ibr-jp-01にルールが定義されていますが、買い手の適格請求書発行事業者番号についてのルールがありません。
Japanese jurisdiction specific PINT rules定義では、売り手の適格請求書発行事業者番号についてのルールが定義されていますが、同様に買い手や売手の税務代理人の適格請求書発行事業者番号についてのルールも必要です。
公開サイトから提供されているサンプルのインボイスにも買い手の適格請求書発行事業者番号が不正な値であるものが多くみられます。
Japan PINT Invoice UBL Example.xml
Japan PINT Invoice UBL Example3-SumInv1.xml
Japan PINT Invoice UBL Example4-SumInv2.xml
Japan PINT Invoice UBL Example5-AllowanceCharge.xml
Japan PINT Invoice UBL Example6-CorrInv.xml
Japan PINT Invoice UBL Example7-Return.Quan.ItPr.xml
Japan PINT Invoice UBL Example9-SumInv1 and O.xml
これらのサンプルでは、買い手の適格請求書発行事業者番号が >T3210987654321 と記載されていますが、提供されているスキーマトロンでは、不正なインボイスであることが発見できません。
<rule context="/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme[cac:TaxScheme/normalize-space(upper-case(cbc:ID))='VAT']">
<assert id="aligned-ibr-jp-01" flag="fatal" test="
(
(
(//cbc:StartDate >= '2023-10-01') or
(//cbc:EndDate >= '2023-10-01')) and
matches(normalize-space(cbc:CompanyID),'^T[0-9]{13}$'
)
) or
not(
(//cbc:StartDate >= '2023-10-01') or
(//cbc:EndDate >= '2023-10-01')
)">
[aligned-ibr-jp-01]-If a date of an invoice period (ibg-14) or an invoice line period (ibg-26) is on and after October 1st 2023, Seller Tax Identifier shall be coded by using a Registration Number for Qualified Invoice purpose in Japan, which consists of 14 digits that start with T.</assert>
</rule>
2. テスト環境
次の記事をお読みください。
使用するスキーマファイルは、次の定義です。
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<xsl:function xmlns:xsl="http://www.w3.org/1999/XSL/Transform" name="u:slack" as="xs:boolean">
<xsl:param name="exp" as="xs:decimal"/>
<xsl:param name="val" as="xs:decimal"/>
<xsl:param name="slack" as="xs:decimal"/>
<xsl:value-of select="xs:decimal($exp + $slack) >= $val and xs:decimal($exp - $slack) <= $val"/>
</xsl:function>
<ns prefix="ext" uri="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"/>
<ns prefix="cbc" uri="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"/>
<ns prefix="cac" uri="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"/>
<ns prefix="qdt" uri="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDataTypes-2"/>
<ns prefix="udt" uri="urn:oasis:names:specification:ubl:schema:xsd:UnqualifiedDataTypes-2"/>
<ns prefix="cn" uri="urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2"/>
<ns prefix="ubl" uri="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"/>
<ns prefix="u" uri="utils"/>
<ns prefix="xs" uri="http://www.w3.org/2001/XMLSchema"/>
<phase id="PINT-model-wuwei_phase">
<active pattern="UBL-model-wuwei"/>
</phase>
<pattern id="UBL-model-wuwei">
<rule context="/ubl:Invoice/cac:TaxTotal[cbc:TaxAmount/@currencyID=normalize-space(/ubl:Invoice/cbc:DocumentCurrencyCode)]/cac:TaxSubtotal[cac:TaxCategory/normalize-space(cbc:ID)='S']">
<assert id="WuWei-S-01" flag="fatal" test="
(
exists(/ubl:Invoice/cac:InvoiceLine[cac:Item/cac:ClassifiedTaxCategory/normalize-space(cbc:ID)='S']) or
exists(/ubl:Invoice/cac:AllowanceCharge[cac:TaxCategory/normalize-space(cbc:ID)='S'])
) and
u:slack(
xs:decimal(cbc:TaxableAmount),
(
sum(/ubl:Invoice/cac:InvoiceLine[cac:Item/cac:ClassifiedTaxCategory/normalize-space(cbc:ID)='S']/xs:decimal(cbc:LineExtensionAmount)) +
sum(/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator=true()][cac:TaxCategory/normalize-space(cbc:ID)='S']/xs:decimal(cbc:Amount)) -
sum(/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator=false()][cac:TaxCategory/normalize-space(cbc:ID)='S']/xs:decimal(cbc:Amount))
),
1
)
">
[WuWei-S-01]In case of the VAT category code (BT-118) is "Standard rated", the VAT category taxable amount (BT-116) in a VAT breakdown (BG-23) shall equal the sum of Invoice line net amounts (BT-131) plus the sum of document level charge amounts (BT-99) minus the sum of document level allowance amounts (BT-92) where the VAT category code (BT-151, BT-102, BT-95) is "Standard rated" and the VAT rate (BT-152, BT-103, BT-96) equals the VAT category rate (BT-119).
標準税率(BT-118 VAT category code is "S: Standard rated")のとき、課税分類毎の集計 (BG-23 VAT breakdown)に記載された課税対象金額(BT-116 VAT category taxable amount )は、 明細行の正味金額(BT-131 Invoice line net amounts ) に同じ区分と同じ税率の文書レベルの追加請求金額 (BT-99 sum of document level charge amounts )を加えた金額から同じ区分と同じ税率の文書レベルの返金金額 (BT-92 sum of document level allowance amounts )を差し引いた金額でなければならない。ここで、 課税区分コード (BT-151, BT-102, BT-95) は、標準税率 "S: Standard rated" であり、税率 (BT-152, BT-103, BT-96) は、その税率(BT-119)と等しいものとする。
</assert>
</rule>
<rule context="/ubl:Invoice/cac:TaxTotal[cbc:TaxAmount/@currencyID=normalize-space(/ubl:Invoice/cbc:DocumentCurrencyCode)]/cac:TaxSubtotal[cac:TaxCategory/normalize-space(cbc:ID)='AA']">
<assert id="WuWei-AA-01" flag="fatal" test="
(
exists(/ubl:Invoice/cac:InvoiceLine[cac:Item/cac:ClassifiedTaxCategory/normalize-space(cbc:ID)='AA']) or
exists(/ubl:Invoice/cac:AllowanceCharge[cac:TaxCategory/normalize-space(cbc:ID)='AA'])
) and
u:slack(
xs:decimal(cbc:TaxableAmount),
(
sum(/ubl:Invoice/cac:InvoiceLine[cac:Item/cac:ClassifiedTaxCategory/normalize-space(cbc:ID)='AA']/xs:decimal(cbc:LineExtensionAmount)) +
sum(/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator=true()][cac:TaxCategory/normalize-space(cbc:ID)='AA']/xs:decimal(cbc:Amount)) -
sum(/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator=false()][cac:TaxCategory/normalize-space(cbc:ID)='AA']/xs:decimal(cbc:Amount))
),
1
)
">
[WuWei-AA-01] In case of the VAT category code (BT-118) is "Reduced rated", the VAT category taxable amount (BT-116) in a VAT breakdown (BG-23) shall equal the sum of Invoice line net amounts (BT-131) plus the sum of document level charge amounts (BT-99) minus the sum of document level allowance amounts (BT-92) where the VAT category code (BT-151, BT-102, BT-95) is "Reduced rated" and the VAT rate (BT-152, BT-103, BT-96) equals the VAT category rate (BT-119).
軽減税率(BT-118 VAT category code is "AA: Reduced rated")のとき、課税分類毎の集計 (BG-23 VAT breakdown)に記載された課税対象金額(BT-116 VAT category taxable amount )は、 明細行の正味金額(BT-131 Invoice line net amounts ) に同じ区分と同じ税率の文書レベルの追加請求金額 (BT-99 sum of document level charge amounts)を加えた金額から同じ区分と同じ税率の文書レベルの返金金額 (BT-92 sum of document level allowance amounts )を差し引いた金額でなければならない。ここで、 課税区分コード (BT-151, BT-102, BT-95) は、軽減税率 "AA: Reduced rated" であり、税率 (BT-152, BT-103, BT-96) は、その税率(BT-119)と等しいものとする。
</assert>
</rule>
<rule context="cac:InvoiceLine">
<let name="lineExtensionAmount" value="
if (cbc:LineExtensionAmount)
then xs:decimal(cbc:LineExtensionAmount)
else 0"/>
<let name="quantity" value="
if (cbc:InvoicedQuantity)
then xs:decimal(cbc:InvoicedQuantity)
else 1"/>
<let name="priceAmount" value="
if (cac:Price/cbc:PriceAmount)
then xs:decimal(cac:Price/cbc:PriceAmount)
else 0"/>
<let name="baseQuantity" value="
if (
cac:Price/cbc:BaseQuantity and
xs:decimal(cac:Price/cbc:BaseQuantity) != 0
)
then xs:decimal(cac:Price/cbc:BaseQuantity)
else 1"/>
<let name="allowancesTotal" value="
if (cac:AllowanceCharge[normalize-space(cbc:ChargeIndicator) = 'false'])
then round(sum(cac:AllowanceCharge[normalize-space(cbc:ChargeIndicator) = 'false']/cbc:Amount/xs:decimal(.)) * 10 * 10) div 100
else 0"/>
<let name="chargesTotal" value="
if (cac:AllowanceCharge[normalize-space(cbc:ChargeIndicator) = 'true'])
then round(sum(cac:AllowanceCharge[normalize-space(cbc:ChargeIndicator) = 'true']/cbc:Amount/xs:decimal(.)) * 10 * 10) div 100
else 0"/>
<assert id="WuWei-R-01" flag="fatal" test="
u:slack(
$lineExtensionAmount,
($quantity * ($priceAmount div $baseQuantity)) + $chargesTotal - $allowancesTotal,
0.02
)">
[WuWei-R-01] ibt-131 Invoice line net amount MUST equal (ibt-146 Item net price X (ibt-129Invoiced quantity ÷ ibt-149Item price base quantity ) + ibt-141 Invoice line charge amount – ibt-136Invoice line allowance amount.
明細行の正味金額(ibt-131) = 品目の標準価格(ibt-146) X 請求する数量(ibt-129) ÷ 品奥の基準数量(ibt-149) + (ibt-141 Invoice line charge amount) – (ibt-136Invoice line allowance amount).
</assert>
</rule>
<rule context="/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme">
<assert id="WuWei-D-01" flag="fatal" test="normalize-space(cbc:ID)='VAT'">
[WuWei-D-01] Seller's tax schema ID shall be VAT.
売り手の税スキーマは、VATでなければならない。</assert>
</rule>
<rule context="/ubl:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme">
<assert id="WuWei-D-02" flag="fatal" test="normalize-space(cbc:ID)='VAT'">
[WuWei-D-02] Buyer's tax schema ID shall be VAT.
買い手の税スキーマは、VATでなければならない。</assert>
</rule>
<rule context="/ubl:Invoice/cac:TaxRepresentativeParty/cac:Party/cac:PartyTaxScheme/cac:TaxScheme">
<assert id="WuWei-D-03" flag="fatal" test="
exists(cbc:ID) and
normalize-space(cbc:ID)='VAT'
">
[WuWei-D-03] Tax representative party's tax schema ID shall be VAT.
売り手の税代理人の税スキーマは、VATでなければならない。</assert>
</rule>
<rule context="/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator=false()]/cac:TaxCategory/cac:TaxScheme">
<assert id="WuWei-D-04" flag="fatal" test="
exists(cbc:ID) and
normalize-space(cbc:ID)='VAT'
">
[WuWei-D-04] Tax schema ID of the document level allowance shall be VAT.
文書レベルの返金の税スキーマは、VATでなければならない。</assert>
</rule>
<rule context="/ubl:Invoice/cac:AllowanceCharge[cbc:ChargeIndicator=true()]/cac:TaxCategory/cac:TaxScheme">
<assert id="WuWei-D-05" flag="fatal" test="
exists(cbc:ID) and
normalize-space(cbc:ID)='VAT'
">
[WuWei-D-05] Tax schema ID of the document level charge shall be VAT.
文書レベルの追加請求の税スキーマは、VATでなければならない。</assert>
</rule>
<rule context="/Invoice/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cac:TaxScheme">
<assert id="WuWei-D-06" flag="fatal" test="
exists(cbc:ID) and
normalize-space(cbc:ID)='VAT'
">
[WuWei-D-06] Tax schema ID of the tax subtotal shall be VAT.
課税分類別の税スキーマは、VATでなければならない。</assert>
</rule>
<rule context="/Invoice/cac:InvoiceLine/cac:Item/cac:ClassifiedTaxCategory/cac:TaxScheme">
<assert id="WuWei-D-07" flag="fatal" test="
exists(cbc:ID) and
normalize-space(cbc:ID)='VAT'
">
[WuWei-D-07] Tax schema ID of the invoice line invoiced item shall be VAT.
明細行の品目の税スキーマは、VATでなければならない。</assert>
</rule>
<rule context="/ubl:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme[cac:TaxScheme/normalize-space(upper-case(cbc:ID))='VAT']">
<assert id="WuWei-D-08" flag="fatal" test="
(
(
(//cbc:StartDate >= '2023-10-01') or
(//cbc:EndDate >= '2023-10-01')) and
matches(normalize-space(cbc:CompanyID),'^T[0-9]{13}$'
)
) or
not(
(//cbc:StartDate >= '2023-10-01') or
(//cbc:EndDate >= '2023-10-01')
)">
[WuWei-D-08] If a date of an invoice period (ibg-14) or an invoice line period (ibg-26) is on and after October 1st 2023, Buyer Tax Identifier shall be coded by using a Registration Number for Qualified Invoice purpose in Japan, which consists of 14 digits that start with T.</assert>
請求書期間(ibg-14)または請求書明細期間(ibg-26)の日付が2023年10月1日以降の場合、買い手の適格請求書発行事業者登録番号は、Tで始まる14桁で構成されなければならない。</assert>
</rule>
<rule context="/ubl:Invoice/cac:TaxRepresentativeParty/cac:Party/cac:PartyTaxScheme[cac:TaxScheme/normalize-space(upper-case(cbc:ID))='VAT']">
<assert id="WuWei-D-09" flag="fatal" test="
(
(
(//cbc:StartDate >= '2023-10-01') or
(//cbc:EndDate >= '2023-10-01')) and
matches(normalize-space(cbc:CompanyID),'^T[0-9]{13}$'
)
) or
not(
(//cbc:StartDate >= '2023-10-01') or
(//cbc:EndDate >= '2023-10-01')
)">
[WuWei-D-09] If a date of an invoice period (ibg-14) or an invoice line period (ibg-26) is on and after October 1st 2023, Buyer Tax Identifier shall be coded by using a Registration Number for Qualified Invoice purpose in Japan, which consists of 14 digits that start with T.</assert>
請求書期間(ibg-14)または請求書明細期間(ibg-26)の日付が2023年10月1日以降の場合、売り手の税務代理人の適格請求書発行事業者登録番号は、Tで始まる14桁で構成されなければならない。</assert>
</rule>
<rule context="/ubl:Invoice/cac:InvoiceLine/cac:DespatchLineReference">
<assert id="WuWei-D-10" flag="fatal" test="normalize-space(cbc:LineID)='NA'">
[WuWei-D-10] An identifier for a referenced despatch advice shall be reported with syntax required line identification and its value shall be 'NA'.
出荷案内書参照は、構文で必須とされる行IDと合わせて記載されていなければならず、その値はNAでなければならない。
</assert>
</rule>
<rule context="/ubl:Invoice/cac:PaymentMeans/cac:CardAccount">
<assert id="WuWei-D-10" flag="fatal" test="
exists(cbc:NetworkID) and
normalize-space(cbc:NetworkID)='NA'
">
[WuWei-D-12] Card information shall contain syntax required an identifier for the financial service network provider of the card and its value shall be 'NA'.
カード情報には、構文で必須とされる発行サービス事業者が記載されていなければならず、その値はNAでなければならない。
</assert>
</rule>
</pattern>
</schema>