|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PriceModifier.php |
|
4
|
|
|
* |
|
5
|
|
|
* @author Bram de Leeuw |
|
6
|
|
|
* Date: 31/03/17 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Broarm\EventTickets; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class TaxModifier |
|
13
|
|
|
* |
|
14
|
|
|
* Adds a configurable tax rate on the receipt |
|
15
|
|
|
* |
|
16
|
|
|
* @package Broarm\EventTickets |
|
17
|
|
|
*/ |
|
18
|
|
|
class TaxModifier extends PriceModifier |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* Set the tax rate as a percentage |
|
22
|
|
|
* |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
private static $tax_rate = '21'; |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Set if the tax rate is inclusive or exclusive |
|
29
|
|
|
* |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
private static $inclusive = false; |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Set the default sort value to a large int so it always shows and calculates as last |
|
36
|
|
|
* |
|
37
|
|
|
* @var array |
|
38
|
|
|
*/ |
|
39
|
|
|
private static $defaults = array( |
|
|
|
|
|
|
40
|
|
|
'Title' => 'Tax modifier', |
|
41
|
|
|
'Sort' => 9999 |
|
42
|
|
|
); |
|
43
|
|
|
|
|
44
|
|
|
public function updateTotal(&$total) { |
|
45
|
|
|
$rate = (float)self::config()->get('tax_rate') / 100; |
|
46
|
|
|
$tax = $total * $rate; |
|
47
|
|
|
$this->setPriceModification($tax); |
|
48
|
|
|
if (!(bool)self::config()->get('inclusive')) { |
|
49
|
|
|
$total += $tax; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Show the used tax rate in the table title |
|
55
|
|
|
* |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getTableTitle() |
|
59
|
|
|
{ |
|
60
|
|
|
return _t( |
|
61
|
|
|
'TaxModifier.TABLE_TITLE', |
|
62
|
|
|
'{rate}% BTW', |
|
63
|
|
|
null, |
|
64
|
|
|
array( |
|
|
|
|
|
|
65
|
|
|
'rate' => (float)self::config()->get('tax_rate') |
|
66
|
|
|
) |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Show the calculated tax value as a positive value |
|
72
|
|
|
* |
|
73
|
|
|
* @return float |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getTableValue() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->PriceModification; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Create a tax modifier if it does not already exists |
|
82
|
|
|
* |
|
83
|
|
|
* @param Reservation $reservation |
|
84
|
|
|
* |
|
85
|
|
|
* @return TaxModifier|\DataObject|null|static |
|
86
|
|
|
*/ |
|
87
|
|
|
public static function findOrMake(Reservation $reservation) |
|
88
|
|
|
{ |
|
89
|
|
|
if (!$modifier = $reservation->PriceModifiers()->find('ClassName', self::class)) { |
|
|
|
|
|
|
90
|
|
|
$modifier = self::create(); |
|
91
|
|
|
$modifier->write(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return $modifier; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.