1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of EC-CUBE |
5
|
|
|
* |
6
|
|
|
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved. |
7
|
|
|
* |
8
|
|
|
* http://www.ec-cube.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\Twig\Extension; |
15
|
|
|
|
16
|
|
|
use Eccube\Entity\OrderItem; |
17
|
|
|
use Eccube\Repository\TaxRuleRepository; |
18
|
|
|
use Twig\Extension\AbstractExtension; |
19
|
|
|
use Twig\TwigFunction; |
20
|
|
|
|
21
|
|
|
class TaxExtension extends AbstractExtension |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var TaxRuleRepository |
25
|
|
|
*/ |
26
|
|
|
private $taxRuleRepository; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* TaxExtension constructor. |
30
|
|
|
* @param TaxRuleRepository $taxRuleRepository |
31
|
|
|
*/ |
32
|
|
|
public function __construct(TaxRuleRepository $taxRuleRepository) |
33
|
|
|
{ |
34
|
|
|
$this->taxRuleRepository = $taxRuleRepository; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Returns a list of functions to add to the existing list. |
39
|
|
|
* |
40
|
|
|
* @return TwigFunction[] An array of functions |
41
|
|
|
*/ |
42
|
|
|
public function getFunctions() |
43
|
|
|
{ |
44
|
|
|
return [ |
45
|
|
|
new TwigFunction('is_reduced_tax_rate', [$this, 'isReducedTaxRate']), |
46
|
|
|
]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* 明細が軽減税率対象かどうかを返す. |
51
|
|
|
* |
52
|
|
|
* 受注作成時点での標準税率と比較し, 異なれば軽減税率として判定する. |
53
|
|
|
* |
54
|
|
|
* @param OrderItem $OrderItem |
55
|
|
|
* @return bool |
56
|
|
|
*/ |
57
|
|
|
public function isReducedTaxRate(OrderItem $OrderItem) |
58
|
|
|
{ |
59
|
|
|
$Order = $OrderItem->getOrder(); |
60
|
|
|
|
61
|
|
|
$qb = $this->taxRuleRepository->createQueryBuilder('t'); |
62
|
|
|
try { |
63
|
|
|
$TaxRule = $qb |
64
|
|
|
->where('t.Product IS NULL AND t.ProductClass IS NULL AND t.apply_date < :apply_date') |
65
|
|
|
->orderBy('t.apply_date', 'DESC') |
66
|
|
|
->setParameter('apply_date', $Order->getCreateDate()) |
67
|
|
|
->setMaxResults(1) |
68
|
|
|
->getQuery() |
69
|
|
|
->getOneOrNullResult(); |
70
|
|
|
} catch (\Exception $e) { |
71
|
|
|
return false; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $TaxRule && $TaxRule->getTaxRate() != $OrderItem->getTaxRate(); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|