Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

インボイス対応 #762

Merged
merged 25 commits into from
Feb 14, 2024
Merged

インボイス対応 #762

merged 25 commits into from
Feb 14, 2024

Conversation

nanasess
Copy link
Contributor

@nanasess nanasess commented Sep 1, 2023

必要最低限の対応として、納品書のみインボイスに対応。
細心の注意を払っておりますが、集計方法、互換性等に問題ありそうでしたらご指摘ください🙇‍♂️

税額の集計方法は以下4系の PR に準拠
refs EC-CUBE/ec-cube#5382

data/config/config.php に以下のように登録番号を設定することで、納品書に記載可能。

define('INVOICE_REGISTRATION_NUM', 'T1234567891011');

(2.17系でのDBのカラム追加は避けたいため、上記のような対応としました)

  • 納品書を4.2系と同様にインボイス準拠するよう対応
  • 端数処理を税率設定と連動
  • 受注完了メールの「うち消費税」の表記を変更
  • ユニットテスト作成

納品書のサンプル
doc-(1)

以下のPRを取り込むことでテストはすべて通ることを確認済
#767

- 納品書を4.2系と同様にインボイス準拠するよう対応
- 受注完了メールの「うち消費税」の表記を削除(暫定)
@codecov-commenter
Copy link

codecov-commenter commented Sep 3, 2023

Codecov Report

Attention: 28 lines in your changes are missing coverage. Please review.

Comparison is base (21c0025) 55.38% compared to head (f99e6c0) 55.38%.

Files Patch % Lines
data/class/SC_Fpdf.php 0.00% 25 Missing ⚠️
data/class/helper/SC_Helper_TaxRule.php 91.42% 3 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #762      +/-   ##
==========================================
- Coverage   55.38%   55.38%   -0.01%     
==========================================
  Files          75       75              
  Lines        8908     8967      +59     
==========================================
+ Hits         4934     4966      +32     
- Misses       3974     4001      +27     
Flag Coverage Δ
tests 55.38% <53.33%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nanasess nanasess force-pushed the improve/invoice branch 4 times, most recently from 3ec19cb to 0b2ed2b Compare September 11, 2023 01:01
@bbkids
Copy link
Contributor

bbkids commented Jan 18, 2024

「税額集計と内訳出力のメソッドを分割」の修正いれますと、

例えば、以下の場合ですが合計金額とインボイスの内訳の合計金額が1円ズレます。
■基本情報管理>税率設定>共通税率設定>課税規則 → 「切り捨て」 設定の場合
10%対象商品合計 税込1,595円
8%対象商品合計 税込7,398円
値引き 92円
合計金額 税込8,901円
の場合、内訳は
(8%対象: 7,322円 内消費税: 542円)
(10%対象: 1,578円 内消費税: 143円)
と表示されます。

実際の合計金額は「8,901円」、インボイスの内訳の商品合計は8,900円(7,322円+1,578円)となり1円ズレている事になります。

■基本情報管理>税率設定>共通税率設定>課税規則 → 「切り上げ」 設定の場合ですと
逆に内訳の方が1円高くなります。

課税規則の設定で、消費税が1円高くなったり、安くなったりは当然あり得ると思うのですが、内訳の合計金額が実際の合計金額と一致している必要があると思うのですが、どうなんでしょうか?

$result = [];
foreach ($arrTaxableTotal as $rate => $total) {
if ($taxable_total > 0) {
$reduced_total = $total - $discount_total * $total / $taxable_total;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$reduced_total = $total - $discount_total * $total / $taxable_total;
$reduced_total = $total - static::roundByCalcRule($discount_total * $total / $taxable_total, $arrDefaultTaxRule['calc_rule']);

@nanasess
Copy link
Contributor Author

@bbkids ご指摘ありがとうございます。
以下のような感じで、按分した値引き額を丸めてやれば、正しい集計ができそうですね
https://github.com/EC-CUBE/ec-cube2/pull/762/files#r1456948018

10%対象商品合計 税込1,595円
8%対象商品合計 税込7,398円
値引き 92円

10%対象値引額 16.31713555円→16円(四捨五入)
8%対象値引額 75.68286445→76円(四捨五入)

10%対象値引後合計 1,579円
8%対象値引後合計 7,322円
1579+7322 = 8,901

10%対象消費税(四捨五入) 144円
8%対象消費税(四捨五入) 542円

@bbkids
Copy link
Contributor

bbkids commented Jan 18, 2024

10%対象商品合計 税込1,595円
8%対象商品合計 税込7,398円
値引き 92円

10%対象値引額 16.31713555円→16円(四捨五入)
8%対象値引額 75.68286445→76円(四捨五入)

10%対象値引後合計 1,579円
8%対象値引後合計 7,322円
1579+7322 = 8,901

ここまで
按分した値引き額を四捨五入で丸めるいう考えは自分もOKかと思います。
その後の
10%対象消費税と、8%対象消費税は、四捨五入固定ではなく
基本情報管理>税率設定>共通税率設定>課税規則の設定に基づいて「四捨五入」、「切り捨て」、「切り上げ」いずれかである必要がある様な気もします。

@nanasess
Copy link
Contributor Author

@bbkids

10%対象消費税と、8%対象消費税は、四捨五入固定ではなく
基本情報管理>税率設定>共通税率設定>課税規則の設定に基づいて「四捨五入」、「切り捨て」、「切り上げ」いずれかである必要がある様な気もします。

おっしゃる通りだと思いますので、修正案では課税規則の設定に基づくよう static::roundByCalcRule() を使用しています
#762 (comment)

@bbkids
Copy link
Contributor

bbkids commented Jan 18, 2024

すみません、仰る通りですね。
10%対象消費税と、8%対象消費税は、修正案では課税規則の設定に基づくようなってますね。

ちょっと気になったのは、按分した値引き額を丸めるところなのですが、
ここのコードは以下の箇所と思われますが
$reduced_total = $total - static::roundByCalcRule($discount_total * $total / $taxable_total, $arrDefaultTaxRule['calc_rule']);

ここは逆に四捨五入固定でなければならないと思うのですが、どうでしょうか?
ちなみに、そのコードの箇所が課税規則の設定に基づくように丸められると

今試して見たのですが、課税規則の設定で切り捨てを設定の場合、
内訳は10%対象1,579円、8%対象7,323円となり今度は実際の合計より1円オーバーしてしまいます。

@nanasess
Copy link
Contributor Author

@bbkids なるほど、あとでテストを書こうと思って四捨五入以外まで計算できていませんでした🙇‍♂️
四捨五入固定で問題なければ、それでよさそうですね。

@seasoftjapan
Copy link
Contributor

私も先日ローカルに落としてデバッグしていて、若干気になっていました。
多分、誤差分をあとで足し引きする処理が必要なのかなと。

四捨五入にしても、16.5 + 75.5 →(端数処理)→ 17 + 76 = 93 とか、成り得ないですか?

@bbkids
Copy link
Contributor

bbkids commented Jan 18, 2024

私も十分検証できていないので、@seasoftjapan さんの仰る通りあり得るかもしれません。
そうなると、誤差分を足し引きする処理が必要になって来ますね。

@nanasess
Copy link
Contributor Author

@seasoftjapan @bbkids
ご指摘ありがとうございます。合計と差額が出たら、その分を標準税率(10%)の値引後合計に加算する感じですかね。

4系でも同様の修正を入れる必要がありそうですが、今回のご指摘の話は聞かないのでレアケースなのかもしれません

@seasoftjapan
Copy link
Contributor

ついでなので、先日もう一点若干気になった点です。

税率ごとの対象金額・税額ですが、表に収めたいという事案もあったので、そうできる余地があると良いと思いました。(デフォルトは表外で良いと思います。)

浅知恵ですが、SC_Helper_TaxRule::getTaxDetail() は配列等で返して、SC_Fpdf 側で文字列を組み上げれば良いのかなと思いました。

@nanasess
Copy link
Contributor Author

@bbkids suggestion ありがとうございます!あとで再現テストを追加しますね


foreach ($arrTaxableTotal as $rate => $total) {
if($rate == $defaultTaxRule){
$discount[$rate] = $divide[$GTaxRule]['discount'];
Copy link
Contributor

@bbkids bbkids Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$discount[$rate] = $divide[$GTaxRule]['discount'];
$discount[$rate] = $divide[$defaultTaxRule]['discount'];

Fix Undefined variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テストが落ちているので確認します

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Division by zero が出ていたのと、PHP5.4 で動作しないコードを修正しました

data/class/SC_Fpdf.php Outdated Show resolved Hide resolved
@ji-eunsoo ji-eunsoo merged commit 1ee6369 into EC-CUBE:master Feb 14, 2024
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants