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
|
289 |
|
public function getTax($price, $product = null, $productClass = null, $pref = null, $country = null) |
53
|
|
|
{ |
54
|
|
|
/* @var $TaxRule \Eccube\Entity\TaxRule */ |
55
|
289 |
|
$TaxRule = $this->taxRuleRepository->getByRule($product, $productClass, $pref, $country); |
56
|
|
|
|
57
|
289 |
|
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
|
288 |
|
public function getPriceIncTax($price, $product = null, $productClass = null, $pref = null, $country = null) |
71
|
|
|
{ |
72
|
288 |
|
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
|
291 |
|
public function calcTax($price, $taxRate, $RoundingType, $taxAdjust = 0) |
85
|
|
|
{ |
86
|
291 |
|
$tax = $price * $taxRate / 100; |
87
|
291 |
|
$roundTax = $this->roundByRoundingType($tax, $RoundingType); |
88
|
|
|
|
89
|
291 |
|
return $roundTax + $taxAdjust; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
|
|
|
|
93
|
|
|
* 課税規則に応じて端数処理を行う |
94
|
|
|
* |
95
|
|
|
* @param float|integer $value 端数処理を行う数値 |
96
|
|
|
* @param integer $calcRule 課税規則 |
|
|
|
|
97
|
|
|
* @return double 端数処理後の数値 |
98
|
|
|
*/ |
99
|
295 |
|
public function roundByRoundingType($value, $RoundingType) |
100
|
|
|
{ |
101
|
|
|
switch ($RoundingType) { |
102
|
|
|
// 四捨五入 |
103
|
295 |
|
case \Eccube\Entity\Master\RoundingType::ROUND: |
104
|
292 |
|
$ret = round($value); |
105
|
292 |
|
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
|
295 |
|
return $ret; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|