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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
28af248
インボイス対応
nanasess Sep 1, 2023
1077a19
Fix reduced total
nanasess Sep 3, 2023
9fde0f2
税額集計と内訳出力のメソッドを分割
nanasess Sep 8, 2023
70717b9
Add unit test
nanasess Sep 8, 2023
c654b70
debian-stretch が archive へ移動したため sources.list を修正
nanasess Sep 13, 2023
4a12b8b
Add PHP8.2
nanasess Sep 16, 2023
f2e7bb9
Merge pull request #127 from nanasess/add-php8.2-image
nanasess Sep 16, 2023
065f6f7
Merge pull request #128 from nanasess/use-debian-archive
nanasess Sep 16, 2023
b134893
build-args を修正
nanasess Sep 16, 2023
8f50a61
Merge pull request #129 from nanasess/use-debian-archive
nanasess Sep 16, 2023
9e56bdf
build-args を修正
nanasess Sep 16, 2023
e24f48d
Merge branch 'master' into use-debian-archive
nanasess Sep 16, 2023
5ef4289
Merge pull request #130 from nanasess/use-debian-archive
nanasess Sep 16, 2023
0945ae1
build-args を修正
nanasess Sep 16, 2023
14e026c
Merge branch 'master' into use-debian-archive
nanasess Sep 16, 2023
0b47729
Merge pull request #131 from nanasess/use-debian-archive
nanasess Sep 16, 2023
988f46c
Fix Division by zero on PHP8.0+
nanasess Sep 19, 2023
ca3834f
Merge remote-tracking branch 'origin/master' into improve/invoice
nanasess Oct 24, 2023
06c4356
Merge branch 'master' into improve/invoice
nanasess Oct 24, 2023
f9e1d19
Update data/class/helper/SC_Helper_TaxRule.php
nanasess Jan 23, 2024
29ed7c5
Update data/class/helper/SC_Helper_TaxRule.php
nanasess Jan 24, 2024
61c481c
Update data/class/SC_Fpdf.php
nanasess Jan 29, 2024
4899651
Merge remote-tracking branch 'upstream/master' into improve/invoice
nanasess Feb 4, 2024
ae08724
Fix divison by zero and format
nanasess Feb 4, 2024
f99e6c0
再現テスト追加
nanasess Feb 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

<!--{/section}-->
-------------------------------------------------
小 計 ¥<!--{$arrOrder.subtotal|n2s|default:0}--> <!--{if 0 < $arrOrder.tax}-->(うち消費税 ¥<!--{$arrOrder.tax|n2s|default:0}-->)<!--{/if}-->
小 計 ¥<!--{$arrOrder.subtotal|n2s|default:0}-->

<!--{if $arrOrder.use_point > 0}-->
値引き ¥<!--{$arrOrder.use_point*$smarty.const.POINT_VALUE+$arrOrder.discount|n2s|default:0}-->
Expand Down
2 changes: 1 addition & 1 deletion data/Smarty/templates/mobile/mail_templates/order_mail.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

<!--{/section}-->

小 計 ¥<!--{$arrOrder.subtotal|n2s|default:0}--> <!--{if 0 < $arrOrder.tax}-->(うち消費税 ¥<!--{$arrOrder.tax|n2s|default:0}-->)<!--{/if}-->
小 計 ¥<!--{$arrOrder.subtotal|n2s|default:0}-->

<!--{if $arrOrder.use_point > 0}-->
値引き ¥<!--{$arrOrder.use_point*$smarty.const.POINT_VALUE+$arrOrder.discount|n2s|default:0}-->
Expand Down
37 changes: 36 additions & 1 deletion data/class/SC_Fpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ private function setShopData()
//ロゴ画像
$logo_file = PDF_TEMPLATE_REALDIR . 'logo.png';
$this->Image($logo_file, 124, 46, 40);

if (defined('INVOICE_REGISTRATION_NUM')) {
$text = '登録番号: '.INVOICE_REGISTRATION_NUM;
$this->lfText(125, 87, $text, 8);
}
}

private function setMessageData()
Expand Down Expand Up @@ -228,6 +233,8 @@ private function setOrderData()
$monetary_unit = '円';
$point_unit = 'Pt';

$arrTaxableTotal = [];
$defaultTaxRule = SC_Helper_TaxRule_Ex::getTaxRule();
// 購入商品情報
for ($i = 0; $i < count($this->arrDisp['quantity']); $i++) {
// 購入数量
Expand All @@ -249,9 +256,18 @@ private function setOrderData()
$arrOrder[$i][0] .= ' * '.$this->arrDisp['classcategory_name2'][$i].' ]';
}
}

// 標準税率より低い税率は軽減税率として※を付与
if ($this->arrDisp['tax_rate'][$i] < $defaultTaxRule['tax_rate']) {
$arrOrder[$i][0] .= ' ※';
}
$arrOrder[$i][1] = number_format($data[0]);
$arrOrder[$i][2] = number_format($data[1]).$monetary_unit;
$arrOrder[$i][3] = number_format($data[2]).$monetary_unit;
if (array_key_exists($this->arrDisp['tax_rate'][$i], $arrTaxableTotal) === false) {
$arrTaxableTotal[$this->arrDisp['tax_rate'][$i]] = 0;
}
$arrTaxableTotal[$this->arrDisp['tax_rate'][$i]] += $data[2];
}

$arrOrder[$i][0] = '';
Expand All @@ -270,18 +286,21 @@ private function setOrderData()
$arrOrder[$i][1] = '';
$arrOrder[$i][2] = '送料';
$arrOrder[$i][3] = number_format($this->arrDisp['deliv_fee']).$monetary_unit;
$arrTaxableTotal[intval($defaultTaxRule['tax_rate'])] += $this->arrDisp['deliv_fee'];

$i++;
$arrOrder[$i][0] = '';
$arrOrder[$i][1] = '';
$arrOrder[$i][2] = '手数料';
$arrOrder[$i][3] = number_format($this->arrDisp['charge']).$monetary_unit;
$arrTaxableTotal[intval($defaultTaxRule['tax_rate'])] += $this->arrDisp['charge'];

$i++;
$arrOrder[$i][0] = '';
$arrOrder[$i][1] = '';
$arrOrder[$i][2] = '値引き';
$arrOrder[$i][3] = '- '.number_format(($this->arrDisp['use_point'] * POINT_VALUE) + $this->arrDisp['discount']).$monetary_unit;
$discount_total = ($this->arrDisp['use_point'] * POINT_VALUE) + $this->arrDisp['discount'];
$arrOrder[$i][3] = '- '.number_format($discount_total).$monetary_unit;

$i++;
$arrOrder[$i][0] = '';
Expand Down Expand Up @@ -311,6 +330,22 @@ private function setOrderData()
}

$this->FancyTable($this->label_cell, $arrOrder, $this->width_cell);

$this->SetLineWidth(.3);
$this->SetFont('SJIS', '', 6);

$this->Cell(0, 0, '', 0, 1, 'C', 0, '');
// 行頭近くの場合、表示崩れがあるためもう一個字下げする
if (270 <= $this->GetY()) {
$this->Cell(0, 0, '', 0, 1, 'C', 0, '');
}
$width = array_reduce($this->width_cell, function ($n, $w) {
return $n + $w;
});
$this->SetX(20);

$message = SC_Helper_TaxRule_Ex::getTaxDetail($arrTaxableTotal, $discount_total);
$this->MultiCell($width, 4, $message, 0, 'R', '');
}

/**
Expand Down
79 changes: 79 additions & 0 deletions data/class/helper/SC_Helper_TaxRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,85 @@ public static function sfTax($price, $product_id = 0, $product_class_id = 0, $pr
return SC_Helper_TaxRule_Ex::calcTax($price, $arrTaxRule['tax_rate'], $arrTaxRule['tax_rule'], $arrTaxRule['tax_adjust']);
}

/**
* 消費税の内訳を返す.
*
* 税率ごとに以下のような連想配列を返す.
* - discount: 税率毎の値引額
* - total: 値引後の税込み合計金額
* - tax: 値引後の税額
* 値引額合計は税率ごとに按分する.
* 課税規則は標準税率の設定を使用する.
*
* @param array{8?:int, 10?:int} $arrTaxableTotal 税率ごとのお支払い合計金額
* @param int $discount_total 値引額合計
* @return array{8?:array{discount;int,total:int,tax:int}, 10?:array{discount;int,total:int,tax:int}}
*/
public static function getTaxPerTaxRate($arrTaxableTotal, $discount_total = 0)
{
$arrDefaultTaxRule = static::getTaxRule();

ksort($arrTaxableTotal);
$cf_discount = 0;
$taxable_total = array_sum($arrTaxableTotal);
$divide = [];
$result = [];

// 按分後の値引額の合計(8%対象商品の按分後の値引額 + 10%対象商品の按分後の値引額)が実際の値引額より+-1円となる事への対処
// ①按分した値引き額を四捨五入で丸める
foreach ($arrTaxableTotal as $rate => $total) {
$discount[$rate] = $taxable_total !== 0 ? round(($discount_total * $total / $taxable_total), 0) : 0;
$divide[$rate] = [
'discount' => intval($discount[$rate]),
];
$cf_discount += $divide[$rate]['discount'];
}
// ②四捨五入したとしても、四捨五入前の値引額がそれぞれ 16.5 + 75.5 の場合 →(四捨五入端数処理)→ 17 + 76 両方繰り上がる。事への対処
$defaultTaxRule = $arrDefaultTaxRule['calc_rule'];
$diff = $discount_total - $cf_discount;
if ($diff > 0) {
$divide[$defaultTaxRule]['discount'] += $diff;
} elseif ($diff < 0) {
$divide[$defaultTaxRule]['discount'] -= $diff;
}

foreach ($arrTaxableTotal as $rate => $total) {
if ($rate == $defaultTaxRule) {
$discount[$rate] = $divide[$defaultTaxRule]['discount'];
} else {
$discount[$rate] = $taxable_total !== 0 ? round(($discount_total * $total / $taxable_total), 0) : 0;
}
$reduced_total = $total - $discount[$rate];
$tax = $reduced_total * ($rate / (100 + $rate));
$result[$rate] = [
'discount' => intval($discount[$rate]),
'total' => intval($reduced_total),
'tax' => intval(static::roundByCalcRule($tax, $defaultTaxRule)),
];
}
return $result;
}

/**
* 消費税の内訳の文字列を返す.
*
* 複数の税率がある場合は改行で区切る.
*
* @param array{8?:int, 10?:int} $arrTaxableTotal 税率ごとのお支払い合計金額
* @param int $discount_total 値引額合計
* @return string (<税率>%対象: <値引後税込合計>円 内消費税: <値引後税額>円)
*/
public static function getTaxDetail($arrTaxableTotal, $discount_total = 0)
{
$arrTaxPerTaxRate = static::getTaxPerTaxRate($arrTaxableTotal, $discount_total);
$result = '';
foreach ($arrTaxPerTaxRate as $rate => $item) {
$result .= '('.$rate .'%対象: '. number_format($item['total']).'円 内消費税: '.number_format($item['tax']).'円)'.PHP_EOL;
}

return $result;
}

/**
* 設定情報IDに基づいて税金付与した金額を返す
* (受注データのようにルールが決まっている場合用)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @author Nobuhiko Kimoto
* @version $Id$
*/
class SC_Helper_TaxRule_TestBase extends Common_TestCase
abstract class SC_Helper_TaxRule_TestBase extends Common_TestCase
{

/**
Expand Down
Loading
Loading