|
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\Common\EccubeConfig; |
|
17
|
|
|
use Eccube\Entity\Master\ProductStatus; |
|
18
|
|
|
use Eccube\Entity\Product; |
|
19
|
|
|
use Eccube\Entity\ProductClass; |
|
20
|
|
|
use Eccube\Entity\TaxRule; |
|
21
|
|
|
use Eccube\Repository\ProductRepository; |
|
22
|
|
|
use Eccube\Repository\TaxRuleRepository; |
|
23
|
|
|
use Eccube\Util\StringUtil; |
|
24
|
|
|
use Symfony\Component\Form\FormView; |
|
25
|
|
|
use Symfony\Component\Intl\Intl; |
|
26
|
|
|
use Twig\Extension\AbstractExtension; |
|
27
|
|
|
use Twig\TwigFilter; |
|
28
|
|
|
use Twig\TwigFunction; |
|
29
|
|
|
|
|
30
|
|
|
class TaxExtension extends AbstractExtension |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @var TaxRuleRepository |
|
34
|
|
|
*/ |
|
35
|
|
|
private $taxRuleRepository; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* TaxExtension constructor. |
|
39
|
|
|
* @param TaxRuleRepository $taxRuleRepository |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct(TaxRuleRepository $taxRuleRepository) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->taxRuleRepository = $taxRuleRepository; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Returns a list of functions to add to the existing list. |
|
48
|
|
|
* |
|
49
|
|
|
* @return TwigFunction[] An array of functions |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getFunctions() |
|
52
|
|
|
{ |
|
53
|
|
|
return [ |
|
54
|
|
|
new TwigFunction('is_reduced_tax_rate', [$this, 'isReducedTaxRate']), |
|
55
|
|
|
]; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* 明細が軽減税率対象かどうかを返す. |
|
60
|
|
|
* |
|
61
|
|
|
* 受注作成時点での標準税率と比較し, 異なれば軽減税率として判定する. |
|
62
|
|
|
* |
|
63
|
|
|
* @param null $OrderItem |
|
64
|
|
|
* @return bool |
|
65
|
|
|
*/ |
|
66
|
|
|
public function isReducedTaxRate($OrderItem = null) |
|
67
|
|
|
{ |
|
68
|
|
|
if (null === $OrderItem) { |
|
69
|
|
|
return false; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$Order = $OrderItem->getOrder(); |
|
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
$qb = $this->taxRuleRepository->createQueryBuilder('t'); |
|
75
|
|
|
try { |
|
76
|
|
|
$TaxRule = $qb |
|
77
|
|
|
->where('t.Product IS NULL AND t.ProductClass IS NULL AND t.apply_date < :apply_date') |
|
78
|
|
|
->orderBy('t.apply_date', 'DESC') |
|
79
|
|
|
->setParameter('apply_date', $Order->getCreateDate()) |
|
80
|
|
|
->setMaxResults(1) |
|
81
|
|
|
->getQuery() |
|
82
|
|
|
->getOneOrNullResult(); |
|
83
|
|
|
} catch (\Exception $e) { |
|
84
|
|
|
return false; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return $TaxRule && $TaxRule->getTaxRate() != $OrderItem->getTaxRate(); |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.