|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of EC-CUBE |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
|
6
|
|
|
* |
|
7
|
|
|
* http://www.lockon.co.jp/ |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software; you can redistribute it and/or |
|
10
|
|
|
* modify it under the terms of the GNU General Public License |
|
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
|
12
|
|
|
* of the License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU General Public License |
|
20
|
|
|
* along with this program; if not, write to the Free Software |
|
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
namespace Eccube\Service; |
|
26
|
|
|
|
|
27
|
|
|
use Eccube\Annotation\Inject; |
|
28
|
|
|
use Eccube\Annotation\Service; |
|
29
|
|
|
use Eccube\Repository\TaxRuleRepository; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @Service |
|
33
|
|
|
*/ |
|
34
|
|
|
class TaxRuleService |
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* @Inject(TaxRuleRepository::class) |
|
38
|
|
|
* @var TaxRuleRepository |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $taxRuleRepository; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* 設定情報に基づいて税金の金額を返す |
|
44
|
|
|
* |
|
45
|
|
|
* @param int $price 計算対象の金額 |
|
46
|
|
|
* @param int|null|\Eccube\Entity\Product $product 商品 |
|
47
|
|
|
* @param int|null|\Eccube\Entity\ProductClass $productClass 商品規格 |
|
48
|
|
|
* @param int|null|\Eccube\Entity\Master\Pref $pref 都道府県 |
|
49
|
|
|
* @param int|null|\Eccube\Entity\Master\Country $country 国 |
|
50
|
|
|
* @return double 税金付与した金額 |
|
51
|
|
|
*/ |
|
52
|
275 |
|
public function getTax($price, $product = null, $productClass = null, $pref = null, $country = null) |
|
53
|
|
|
{ |
|
54
|
|
|
/* @var $TaxRule \Eccube\Entity\TaxRule */ |
|
55
|
275 |
|
$TaxRule = $this->taxRuleRepository->getByRule($product, $productClass, $pref, $country); |
|
56
|
|
|
|
|
57
|
275 |
|
return $this->calcTax($price, $TaxRule->getTaxRate(), $TaxRule->getRoundingType()->getId(), $TaxRule->getTaxAdjust()); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* calcIncTax |
|
62
|
|
|
* |
|
63
|
|
|
* @param int $price 計算対象の金額 |
|
64
|
|
|
* @param int|null|\Eccube\Entity\Product $product 商品 |
|
65
|
|
|
* @param int|null|\Eccube\Entity\ProductClass $productClass 商品規格 |
|
66
|
|
|
* @param int|null|\Eccube\Entity\Master\Pref $pref 都道府県 |
|
67
|
|
|
* @param int|null|\Eccube\Entity\Master\Country $country 国 |
|
68
|
|
|
* @return int |
|
69
|
|
|
*/ |
|
70
|
274 |
|
public function getPriceIncTax($price, $product = null, $productClass = null, $pref = null, $country = null) |
|
71
|
|
|
{ |
|
72
|
274 |
|
return $price + $this->getTax($price, $product, $productClass, $pref, $country); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* 税金額を計算する |
|
77
|
|
|
* |
|
78
|
|
|
* @param int $price 計算対象の金額 |
|
|
|
|
|
|
79
|
|
|
* @param int $taxRate 税率(%単位) |
|
|
|
|
|
|
80
|
|
|
* @param int $RoundingType 端数処理 |
|
|
|
|
|
|
81
|
|
|
* @param int $taxAdjust 調整額 |
|
|
|
|
|
|
82
|
|
|
* @return double 税金額 |
|
83
|
|
|
*/ |
|
84
|
277 |
|
public function calcTax($price, $taxRate, $RoundingType, $taxAdjust = 0) |
|
85
|
|
|
{ |
|
86
|
277 |
|
$tax = $price * $taxRate / 100; |
|
87
|
277 |
|
$roundTax = $this->roundByRoundingType($tax, $RoundingType); |
|
88
|
|
|
|
|
89
|
277 |
|
return $roundTax + $taxAdjust; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
|
|
|
|
|
93
|
|
|
* 課税規則に応じて端数処理を行う |
|
94
|
|
|
* |
|
95
|
|
|
* @param float|integer $value 端数処理を行う数値 |
|
96
|
|
|
* @param integer $calcRule 課税規則 |
|
|
|
|
|
|
97
|
|
|
* @return double 端数処理後の数値 |
|
98
|
|
|
*/ |
|
99
|
281 |
|
public function roundByRoundingType($value, $RoundingType) |
|
100
|
|
|
{ |
|
101
|
|
|
switch ($RoundingType) { |
|
102
|
|
|
// 四捨五入 |
|
103
|
281 |
|
case \Eccube\Entity\Master\RoundingType::ROUND: |
|
104
|
278 |
|
$ret = round($value); |
|
105
|
278 |
|
break; |
|
106
|
|
|
// 切り捨て |
|
107
|
3 |
|
case \Eccube\Entity\Master\RoundingType::FLOOR: |
|
108
|
1 |
|
$ret = floor($value); |
|
109
|
1 |
|
break; |
|
110
|
|
|
// 切り上げ |
|
111
|
2 |
|
case \Eccube\Entity\Master\RoundingType::CEIL: |
|
112
|
1 |
|
$ret = ceil($value); |
|
113
|
1 |
|
break; |
|
114
|
|
|
// デフォルト:切り上げ |
|
115
|
|
|
default: |
|
116
|
1 |
|
$ret = ceil($value); |
|
117
|
1 |
|
break; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
281 |
|
return $ret; |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|