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\Doctrine\EventSubscriber; |
26
|
|
|
|
27
|
|
|
use Doctrine\Common\EventSubscriber; |
28
|
|
|
use Doctrine\Common\Persistence\Event\LifecycleEventArgs; |
29
|
|
|
use Doctrine\ORM\Events; |
30
|
|
|
use Eccube\Entity\OrderDetail; |
31
|
|
|
use Eccube\Entity\ProductClass; |
32
|
|
|
use Eccube\Entity\ShipmentItem; |
33
|
|
|
|
34
|
|
|
class TaxRuleEventSubscriber implements EventSubscriber |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* @var \Eccube\Service\TaxRuleService |
38
|
|
|
*/ |
39
|
|
|
private $taxRateService; |
40
|
|
|
|
41
|
721 |
|
public function __construct(\Eccube\Service\TaxRuleService $taxRateService) |
|
|
|
|
42
|
|
|
{ |
43
|
721 |
|
$this->taxRateService = $taxRateService; |
44
|
|
|
} |
45
|
|
|
|
46
|
721 |
|
public function getSubscribedEvents() |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
return array( |
49
|
721 |
|
Events::prePersist, |
50
|
721 |
|
Events::postLoad, |
51
|
721 |
|
Events::postPersist, |
52
|
721 |
|
Events::postUpdate, |
53
|
721 |
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
16 |
View Code Duplication |
public function prePersist(LifecycleEventArgs $args) |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
$entity = $args->getObject(); |
59
|
|
|
|
60
|
16 |
|
if ($entity instanceof ProductClass) { |
|
|
|
|
61
|
|
|
$entity->setPrice01IncTax($this->taxRateService->getPriceIncTax($entity->getPrice01(), $entity->getProduct(), $entity)); |
62
|
|
|
$entity->setPrice02IncTax($this->taxRateService->getPriceIncTax($entity->getPrice02(), $entity->getProduct(), $entity)); |
63
|
|
|
} |
64
|
16 |
|
if ($entity instanceof OrderDetail) { |
|
|
|
|
65
|
|
|
$entity->setPriceIncTax($entity->getPrice() + $this->taxRateService->calcTax($entity->getPrice(), $entity->getTaxRate(), $entity->getTaxRule())); |
66
|
|
|
} |
67
|
16 |
|
if ($entity instanceof ShipmentItem) { |
|
|
|
|
68
|
|
|
$entity->setPriceIncTax($this->taxRateService->getPriceIncTax($entity->getPrice(), $entity->getProduct(), $entity->getProductClass())); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
90 |
View Code Duplication |
public function postLoad(LifecycleEventArgs $args) |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
$entity = $args->getObject(); |
75
|
|
|
|
76
|
90 |
|
if ($entity instanceof ProductClass) { |
|
|
|
|
77
|
|
|
$entity->setPrice01IncTax($this->taxRateService->getPriceIncTax($entity->getPrice01(), $entity->getProduct(), $entity)); |
78
|
|
|
$entity->setPrice02IncTax($this->taxRateService->getPriceIncTax($entity->getPrice02(), $entity->getProduct(), $entity)); |
79
|
|
|
} |
80
|
90 |
|
if ($entity instanceof OrderDetail) { |
|
|
|
|
81
|
|
|
$entity->setPriceIncTax($entity->getPrice() + $this->taxRateService->calcTax($entity->getPrice(), $entity->getTaxRate(), $entity->getTaxRule())); |
82
|
|
|
} |
83
|
90 |
|
if ($entity instanceof ShipmentItem) { |
|
|
|
|
84
|
|
|
$entity->setPriceIncTax($this->taxRateService->getPriceIncTax($entity->getPrice(), $entity->getProduct(), $entity->getProductClass())); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
16 |
View Code Duplication |
public function postPersist(LifecycleEventArgs $args) |
|
|
|
|
89
|
|
|
{ |
90
|
|
|
$entity = $args->getObject(); |
91
|
|
|
|
92
|
16 |
|
if ($entity instanceof ProductClass) { |
|
|
|
|
93
|
|
|
$entity->setPrice01IncTax($this->taxRateService->getPriceIncTax($entity->getPrice01(), $entity->getProduct(), $entity)); |
94
|
|
|
$entity->setPrice02IncTax($this->taxRateService->getPriceIncTax($entity->getPrice02(), $entity->getProduct(), $entity)); |
95
|
|
|
} |
96
|
16 |
|
if ($entity instanceof OrderDetail) { |
|
|
|
|
97
|
|
|
$entity->setPriceIncTax($entity->getPrice() + $this->taxRateService->calcTax($entity->getPrice(), $entity->getTaxRate(), $entity->getTaxRule())); |
98
|
|
|
} |
99
|
16 |
|
if ($entity instanceof ShipmentItem) { |
|
|
|
|
100
|
|
|
$entity->setPriceIncTax($this->taxRateService->getPriceIncTax($entity->getPrice(), $entity->getProduct(), $entity->getProductClass())); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
78 |
View Code Duplication |
public function postUpdate(LifecycleEventArgs $args) |
|
|
|
|
105
|
|
|
{ |
106
|
|
|
$entity = $args->getObject(); |
107
|
|
|
|
108
|
78 |
|
if ($entity instanceof ProductClass) { |
|
|
|
|
109
|
|
|
$entity->setPrice01IncTax($this->taxRateService->getPriceIncTax($entity->getPrice01(), $entity->getProduct(), $entity)); |
110
|
|
|
$entity->setPrice02IncTax($this->taxRateService->getPriceIncTax($entity->getPrice02(), $entity->getProduct(), $entity)); |
111
|
|
|
} |
112
|
78 |
|
if ($entity instanceof OrderDetail) { |
|
|
|
|
113
|
|
|
$entity->setPriceIncTax($entity->getPrice() + $this->taxRateService->calcTax($entity->getPrice(), $entity->getTaxRate(), $entity->getTaxRule())); |
114
|
|
|
} |
115
|
78 |
|
if ($entity instanceof ShipmentItem) { |
|
|
|
|
116
|
|
|
$entity->setPriceIncTax($this->taxRateService->getPriceIncTax($entity->getPrice(), $entity->getProduct(), $entity->getProductClass())); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|