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
|
|
|
class TaxRuleService |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var \Eccube\Repository\TaxRuleRepository |
31
|
|
|
*/ |
32
|
|
|
private $taxRuleRepository; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* __construct |
36
|
|
|
* |
37
|
|
|
* @param \Eccube\Repository\TaxRuleRepository $taxRuleRepository |
38
|
|
|
*/ |
39
|
1189 |
|
public function __construct(\Eccube\Repository\TaxRuleRepository $taxRuleRepository) |
40
|
|
|
{ |
41
|
1189 |
|
$this->taxRuleRepository = $taxRuleRepository; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* 設定情報に基づいて税金の金額を返す |
46
|
|
|
* |
47
|
|
|
* @param int $price 計算対象の金額 |
48
|
|
|
* @param int|null|\Eccube\Entity\Product $product 商品 |
49
|
|
|
* @param int|null|\Eccube\Entity\ProductClass $productClass 商品規格 |
50
|
|
|
* @param int|null|\Eccube\Entity\Master\Pref $pref 都道府県 |
51
|
|
|
* @param int|null|\Eccube\Entity\Master\Country $country 国 |
52
|
|
|
* @return double 税金付与した金額 |
53
|
|
|
*/ |
54
|
440 |
|
public function getTax($price, $product = null, $productClass = null, $pref = null, $country = null) |
55
|
|
|
{ |
56
|
|
|
/* @var $TaxRule \Eccube\Entity\TaxRule */ |
57
|
440 |
|
$TaxRule = $this->taxRuleRepository->getByRule($product, $productClass, $pref, $country); |
58
|
|
|
|
59
|
440 |
|
return $this->calcTax($price, $TaxRule->getTaxRate(), $TaxRule->getCalcRule()->getId(), $TaxRule->getTaxAdjust()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* calcIncTax |
64
|
|
|
* |
65
|
|
|
* @param int $price 計算対象の金額 |
66
|
|
|
* @param int|null|\Eccube\Entity\Product $product 商品 |
67
|
|
|
* @param int|null|\Eccube\Entity\ProductClass $productClass 商品規格 |
68
|
|
|
* @param int|null|\Eccube\Entity\Master\Pref $pref 都道府県 |
69
|
|
|
* @param int|null|\Eccube\Entity\Master\Country $country 国 |
70
|
|
|
* @return int |
71
|
|
|
*/ |
72
|
439 |
|
public function getPriceIncTax($price, $product = null, $productClass = null, $pref = null, $country = null) |
73
|
|
|
{ |
74
|
439 |
|
return $price + $this->getTax($price, $product, $productClass, $pref, $country); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* 税金額を計算する |
79
|
|
|
* |
80
|
|
|
* @param int $price 計算対象の金額 |
|
|
|
|
81
|
|
|
* @param int $taxRate 税率(%単位) |
|
|
|
|
82
|
|
|
* @param int $calcRule 端数処理 |
|
|
|
|
83
|
|
|
* @param int $taxAdjust 調整額 |
|
|
|
|
84
|
|
|
* @return double 税金額 |
85
|
|
|
*/ |
86
|
442 |
|
public function calcTax($price, $taxRate, $calcRule, $taxAdjust = 0) |
87
|
|
|
{ |
88
|
442 |
|
$tax = $price * $taxRate / 100; |
89
|
442 |
|
$roundTax = $this->roundByCalcRule($tax, $calcRule); |
90
|
|
|
|
91
|
442 |
|
return $roundTax + $taxAdjust; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* 課税規則に応じて端数処理を行う |
96
|
|
|
* |
97
|
|
|
* @param float|integer $value 端数処理を行う数値 |
98
|
|
|
* @param integer $calcRule 課税規則 |
99
|
|
|
* @return double 端数処理後の数値 |
100
|
|
|
*/ |
101
|
446 |
|
public function roundByCalcRule($value, $calcRule) |
102
|
|
|
{ |
103
|
|
|
switch ($calcRule) { |
104
|
|
|
// 四捨五入 |
105
|
446 |
|
case \Eccube\Entity\Master\Taxrule::ROUND: |
106
|
443 |
|
$ret = round($value); |
107
|
443 |
|
break; |
108
|
|
|
// 切り捨て |
109
|
3 |
|
case \Eccube\Entity\Master\Taxrule::FLOOR: |
110
|
1 |
|
$ret = floor($value); |
111
|
1 |
|
break; |
112
|
|
|
// 切り上げ |
113
|
2 |
|
case \Eccube\Entity\Master\Taxrule::CEIL: |
114
|
1 |
|
$ret = ceil($value); |
115
|
1 |
|
break; |
116
|
|
|
// デフォルト:切り上げ |
117
|
|
|
default: |
118
|
1 |
|
$ret = ceil($value); |
119
|
1 |
|
break; |
120
|
|
|
} |
121
|
|
|
|
122
|
446 |
|
return $ret; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|