|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of EC-CUBE |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved. |
|
7
|
|
|
* |
|
8
|
|
|
* http://www.lockon.co.jp/ |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Eccube\Service; |
|
15
|
|
|
|
|
16
|
|
|
use Eccube\Repository\TaxRuleRepository; |
|
17
|
|
|
|
|
18
|
|
|
class TaxRuleService |
|
|
|
|
|
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var TaxRuleRepository |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $taxRuleRepository; |
|
24
|
|
|
|
|
25
|
469 |
|
public function __construct(TaxRuleRepository $taxRuleRepository) |
|
26
|
|
|
{ |
|
27
|
469 |
|
$this->taxRuleRepository = $taxRuleRepository; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* 設定情報に基づいて税金の金額を返す |
|
32
|
|
|
* |
|
33
|
|
|
* @param int $price 計算対象の金額 |
|
34
|
|
|
* @param int|null|\Eccube\Entity\Product $product 商品 |
|
35
|
|
|
* @param int|null|\Eccube\Entity\ProductClass $productClass 商品規格 |
|
36
|
|
|
* @param int|null|\Eccube\Entity\Master\Pref $pref 都道府県 |
|
37
|
|
|
* @param int|null|\Eccube\Entity\Master\Country $country 国 |
|
38
|
|
|
* |
|
39
|
|
|
* @return double 税金付与した金額 |
|
40
|
|
|
*/ |
|
41
|
463 |
|
public function getTax($price, $product = null, $productClass = null, $pref = null, $country = null) |
|
42
|
|
|
{ |
|
43
|
|
|
/* @var $TaxRule \Eccube\Entity\TaxRule */ |
|
44
|
463 |
|
$TaxRule = $this->taxRuleRepository->getByRule($product, $productClass, $pref, $country); |
|
45
|
|
|
|
|
46
|
463 |
|
return $this->calcTax($price, $TaxRule->getTaxRate(), $TaxRule->getRoundingType()->getId(), $TaxRule->getTaxAdjust()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* calcIncTax |
|
51
|
|
|
* |
|
52
|
|
|
* @param int $price 計算対象の金額 |
|
53
|
|
|
* @param int|null|\Eccube\Entity\Product $product 商品 |
|
54
|
|
|
* @param int|null|\Eccube\Entity\ProductClass $productClass 商品規格 |
|
55
|
|
|
* @param int|null|\Eccube\Entity\Master\Pref $pref 都道府県 |
|
56
|
|
|
* @param int|null|\Eccube\Entity\Master\Country $country 国 |
|
57
|
|
|
* |
|
58
|
|
|
* @return int |
|
59
|
|
|
*/ |
|
60
|
462 |
|
public function getPriceIncTax($price, $product = null, $productClass = null, $pref = null, $country = null) |
|
61
|
|
|
{ |
|
62
|
462 |
|
return $price + $this->getTax($price, $product, $productClass, $pref, $country); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* 税金額を計算する |
|
67
|
|
|
* |
|
68
|
|
|
* @param int $price 計算対象の金額 |
|
|
|
|
|
|
69
|
|
|
* @param int $taxRate 税率(%単位) |
|
|
|
|
|
|
70
|
|
|
* @param int $RoundingType 端数処理 |
|
|
|
|
|
|
71
|
|
|
* @param int $taxAdjust 調整額 |
|
|
|
|
|
|
72
|
|
|
* |
|
73
|
|
|
* @return double 税金額 |
|
74
|
|
|
*/ |
|
75
|
465 |
|
public function calcTax($price, $taxRate, $RoundingType, $taxAdjust = 0) |
|
76
|
|
|
{ |
|
77
|
465 |
|
$tax = $price * $taxRate / 100; |
|
78
|
465 |
|
$roundTax = $this->roundByRoundingType($tax, $RoundingType); |
|
79
|
|
|
|
|
80
|
465 |
|
return $roundTax + $taxAdjust; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* 税込金額から税金額を計算する |
|
85
|
|
|
* |
|
86
|
|
|
* @param int $price 計算対象の金額 |
|
|
|
|
|
|
87
|
|
|
* @param int $taxRate 税率(%単位) |
|
|
|
|
|
|
88
|
|
|
* @param int $RoundingType 端数処理 |
|
|
|
|
|
|
89
|
|
|
* @param int $taxAdjust 調整額 |
|
|
|
|
|
|
90
|
|
|
* |
|
91
|
|
|
* @return float 税金額 |
|
92
|
|
|
*/ |
|
93
|
203 |
|
public function calcTaxIncluded($price, $taxRate, $RoundingType, $taxAdjust = 0) |
|
94
|
|
|
{ |
|
95
|
203 |
|
$tax = ($price - $taxAdjust) * $taxRate / (100 + $taxRate); |
|
96
|
|
|
|
|
97
|
203 |
|
return $this->roundByRoundingType($tax, $RoundingType); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
|
|
|
|
|
101
|
|
|
* 課税規則に応じて端数処理を行う |
|
102
|
|
|
* |
|
103
|
|
|
* @param float|integer $value 端数処理を行う数値 |
|
104
|
|
|
* @param integer $calcRule 課税規則 |
|
|
|
|
|
|
105
|
|
|
* |
|
106
|
|
|
* @return double 端数処理後の数値 |
|
107
|
|
|
*/ |
|
108
|
469 |
|
public function roundByRoundingType($value, $RoundingType) |
|
109
|
|
|
{ |
|
110
|
|
|
switch ($RoundingType) { |
|
111
|
|
|
// 四捨五入 |
|
112
|
469 |
|
case \Eccube\Entity\Master\RoundingType::ROUND: |
|
113
|
466 |
|
$ret = round($value); |
|
114
|
466 |
|
break; |
|
115
|
|
|
// 切り捨て |
|
116
|
3 |
|
case \Eccube\Entity\Master\RoundingType::FLOOR: |
|
117
|
1 |
|
$ret = floor($value); |
|
118
|
1 |
|
break; |
|
119
|
|
|
// 切り上げ |
|
120
|
2 |
|
case \Eccube\Entity\Master\RoundingType::CEIL: |
|
121
|
1 |
|
$ret = ceil($value); |
|
122
|
1 |
|
break; |
|
123
|
|
|
// デフォルト:切り上げ |
|
124
|
|
|
default: |
|
125
|
1 |
|
$ret = ceil($value); |
|
126
|
1 |
|
break; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
469 |
|
return $ret; |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|