|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
*@author nicolaas [at] sunnysideup.co.nz |
|
5
|
|
|
* |
|
6
|
|
|
**/ |
|
7
|
|
|
|
|
8
|
|
|
class GSTTaxModifierOptions extends DataObject |
|
|
|
|
|
|
9
|
|
|
{ |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* standard SS variable |
|
13
|
|
|
* @var Array |
|
14
|
|
|
*/ |
|
15
|
|
|
private static $db = array( |
|
|
|
|
|
|
16
|
|
|
"CountryCode" => "Varchar(3)", |
|
17
|
|
|
"Code" => "Varchar(12)", |
|
18
|
|
|
"Name" => "Varchar(175)", |
|
19
|
|
|
"LegalNotice" => "Varchar(255)", |
|
20
|
|
|
"InclusiveOrExclusive" => "Enum('Inclusive,Exclusive', 'Inclusive')", |
|
21
|
|
|
"Rate" => "Double", |
|
22
|
|
|
"DoesNotApplyToAllProducts" => "Boolean", |
|
23
|
|
|
"AppliesToAllCountries" => "Boolean" |
|
24
|
|
|
); |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* standard SS variable |
|
28
|
|
|
* @var Array |
|
29
|
|
|
*/ |
|
30
|
|
|
private static $defaults = array( |
|
|
|
|
|
|
31
|
|
|
"InclusiveOrExclusive" => "Inclusive" |
|
32
|
|
|
); |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* standard SS variable |
|
36
|
|
|
* @var Array |
|
37
|
|
|
*/ |
|
38
|
|
|
private static $casting = array( |
|
|
|
|
|
|
39
|
|
|
"CountryName" => "Varchar", |
|
40
|
|
|
"PercentageNice" => "Varchar" |
|
41
|
|
|
); |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* standard SS variable |
|
45
|
|
|
* @var Array |
|
46
|
|
|
*/ |
|
47
|
|
|
private static $indexes = array( |
|
|
|
|
|
|
48
|
|
|
"Code" => true |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* standard SS variable |
|
53
|
|
|
* @var Array |
|
54
|
|
|
*/ |
|
55
|
|
|
private static $searchable_fields = array( |
|
|
|
|
|
|
56
|
|
|
"CountryCode" => "PartialMatchFilter", |
|
57
|
|
|
"Code" => "PartialMatchFilter", |
|
58
|
|
|
"Name" => "PartialMatchFilter" |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* standard SS variable |
|
63
|
|
|
* @var Array |
|
64
|
|
|
*/ |
|
65
|
|
|
private static $field_labels = array( |
|
|
|
|
|
|
66
|
|
|
"CountryName" => "Country Name", |
|
67
|
|
|
"CountryCode" => "Country Code", |
|
68
|
|
|
"Code" => "Code for tax", |
|
69
|
|
|
"Name" => "Name for tax", |
|
70
|
|
|
"InclusiveOrExclusive" => "Inclusive/Exclusive", |
|
71
|
|
|
"LegalNotice" => "Here you can put your GST number or VAT registration number", |
|
72
|
|
|
"Rate" => "Rate (e.g. 0.125 = 12.5%)", |
|
73
|
|
|
"PercentageNice" => "Percentage", |
|
74
|
|
|
"DoesNotApplyToAllProducts" => "Added to individual products only" |
|
75
|
|
|
); |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* standard SS variable |
|
80
|
|
|
* @var Array |
|
81
|
|
|
*/ |
|
82
|
|
|
private static $summary_fields = array( |
|
|
|
|
|
|
83
|
|
|
"CountryName" => 'Country', |
|
84
|
|
|
"Code" => 'Code', |
|
85
|
|
|
"Name" => 'Title', |
|
86
|
|
|
"InclusiveOrExclusive" => 'Type', |
|
87
|
|
|
"PercentageNice" => 'Percentage' |
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* standard SS variable |
|
92
|
|
|
* @var String |
|
93
|
|
|
*/ |
|
94
|
|
|
private static $singular_name = "Tax Option"; |
|
|
|
|
|
|
95
|
|
|
public function i18n_singular_name() |
|
96
|
|
|
{ |
|
97
|
|
|
return _t("GSTTaxModifierOptions.TAXOPTION", "Tax Option"); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* standard SS variable |
|
103
|
|
|
* @var String |
|
104
|
|
|
*/ |
|
105
|
|
|
private static $plural_name = "Tax Options"; |
|
|
|
|
|
|
106
|
|
|
public function i18n_plural_name() |
|
107
|
|
|
{ |
|
108
|
|
|
return _t("GSTTaxModifierOptions.TAXOPTIONS", "Tax Options"); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* standard SS method |
|
113
|
|
|
* @param Member | NULL |
|
114
|
|
|
* @return Boolean |
|
|
|
|
|
|
115
|
|
|
*/ |
|
116
|
|
View Code Duplication |
public function canCreate($member = null) |
|
|
|
|
|
|
117
|
|
|
{ |
|
118
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member); |
|
119
|
|
|
if ($extended !== null) { |
|
120
|
|
|
return $extended; |
|
121
|
|
|
} |
|
122
|
|
|
if (Permission::checkMember($member, Config::inst()->get("EcommerceRole", "admin_permission_code"))) { |
|
123
|
|
|
return true; |
|
124
|
|
|
} |
|
125
|
|
|
return parent::canCreate($member); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* standard SS method |
|
130
|
|
|
* @param Member | NULL |
|
131
|
|
|
* @return Boolean |
|
|
|
|
|
|
132
|
|
|
*/ |
|
133
|
|
View Code Duplication |
public function canView($member = null) |
|
|
|
|
|
|
134
|
|
|
{ |
|
135
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member); |
|
136
|
|
|
if ($extended !== null) { |
|
137
|
|
|
return $extended; |
|
138
|
|
|
} |
|
139
|
|
|
if (Permission::checkMember($member, Config::inst()->get("EcommerceRole", "admin_permission_code"))) { |
|
140
|
|
|
return true; |
|
141
|
|
|
} |
|
142
|
|
|
return parent::canCreate($member); |
|
|
|
|
|
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* standard SS method |
|
147
|
|
|
* @param Member | NULL |
|
148
|
|
|
* @return Boolean |
|
|
|
|
|
|
149
|
|
|
*/ |
|
150
|
|
View Code Duplication |
public function canEdit($member = null) |
|
|
|
|
|
|
151
|
|
|
{ |
|
152
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member); |
|
153
|
|
|
if ($extended !== null) { |
|
154
|
|
|
return $extended; |
|
155
|
|
|
} |
|
156
|
|
|
if (Permission::checkMember($member, Config::inst()->get("EcommerceRole", "admin_permission_code"))) { |
|
157
|
|
|
return true; |
|
158
|
|
|
} |
|
159
|
|
|
return parent::canEdit($member); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* standard SS method |
|
164
|
|
|
* @param Member | NULL |
|
165
|
|
|
* @return Boolean |
|
|
|
|
|
|
166
|
|
|
*/ |
|
167
|
|
View Code Duplication |
public function canDelete($member = null) |
|
|
|
|
|
|
168
|
|
|
{ |
|
169
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member); |
|
170
|
|
|
if ($extended !== null) { |
|
171
|
|
|
return $extended; |
|
172
|
|
|
} |
|
173
|
|
|
if (Permission::checkMember($member, Config::inst()->get("EcommerceRole", "admin_permission_code"))) { |
|
174
|
|
|
return true; |
|
175
|
|
|
} |
|
176
|
|
|
return parent::canDelete($member); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* standard SS method |
|
181
|
|
|
* @return FieldList |
|
182
|
|
|
*/ |
|
183
|
|
|
public function getCMSFields() |
|
184
|
|
|
{ |
|
185
|
|
|
$fields = parent::getCMSFields(); |
|
186
|
|
|
$fieldLabels = $this->Config()->get("field_labels"); |
|
187
|
|
|
$fields->replaceField("CountryCode", new DropDownField("CountryCode", $fieldLabels["CountryCode"], EcommerceCountry::get_country_dropdown())); |
|
188
|
|
|
$InclusiveOrExclusive = "Inclusive"; |
|
|
|
|
|
|
189
|
|
|
if ($this->EcomConfig()->ShopPricesAreTaxExclusive) { |
|
190
|
|
|
$InclusiveOrExclusive = "Exclusive"; |
|
|
|
|
|
|
191
|
|
|
} |
|
192
|
|
|
$fields->replaceField("InclusiveOrExclusive", new ReadonlyField("InclusiveOrExclusive", "This tax is: ..., you can change this setting in the e-commerce configuration.")); |
|
193
|
|
|
return $fields; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
public function Title() |
|
197
|
|
|
{ |
|
198
|
|
|
return $this->getTitle(); |
|
199
|
|
|
} |
|
200
|
|
|
public function getTitle() |
|
201
|
|
|
{ |
|
202
|
|
|
if ($this->AppliesToAllCountries) { |
|
|
|
|
|
|
203
|
|
|
$country = _t("GSTTExModifierOption.WORLDWIDE", "world-wide"); |
|
204
|
|
|
} else { |
|
205
|
|
|
$country = $this->CountryCode; |
|
|
|
|
|
|
206
|
|
|
} |
|
207
|
|
|
return $this->Name." ($country, ".number_format($this->Rate * 100, 2) . '%)'; |
|
|
|
|
|
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* standard SS method |
|
212
|
|
|
*/ |
|
213
|
|
|
public function populateDefaults() |
|
214
|
|
|
{ |
|
215
|
|
|
parent::populateDefaults(); |
|
216
|
|
|
//can only run after first dev/build |
|
217
|
|
|
if (Security::database_is_ready()) { |
|
218
|
|
|
$controller = Controller::curr(); |
|
219
|
|
|
if ($controller instanceof DatabaseAdmin) { |
|
|
|
|
|
|
220
|
|
|
//cant do this now. |
|
221
|
|
|
} else { |
|
222
|
|
|
if ($this->EcomConfig()->ShopPricesAreTaxExclusive) { |
|
223
|
|
|
$this->InclusiveOrExclusive = "Exclusive"; |
|
|
|
|
|
|
224
|
|
|
} else { |
|
225
|
|
|
$this->InclusiveOrExclusive = "Inclusive"; |
|
|
|
|
|
|
226
|
|
|
} |
|
227
|
|
|
} |
|
228
|
|
|
} |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* standard SS method |
|
233
|
|
|
*/ |
|
234
|
|
|
public function onBeforeWrite() |
|
235
|
|
|
{ |
|
236
|
|
|
parent::onBeforeWrite(); |
|
237
|
|
|
if ($this->EcomConfig()->ShopPricesAreTaxExclusive) { |
|
238
|
|
|
$this->InclusiveOrExclusive = "Exclusive"; |
|
|
|
|
|
|
239
|
|
|
} else { |
|
240
|
|
|
$this->InclusiveOrExclusive = "Inclusive"; |
|
|
|
|
|
|
241
|
|
|
} |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
// /** |
|
245
|
|
|
// * standard SS method |
|
246
|
|
|
// */ |
|
247
|
|
|
// public function requireDefaultRecords() |
|
|
|
|
|
|
248
|
|
|
// { |
|
249
|
|
|
// parent::requireDefaultRecords(); |
|
|
|
|
|
|
250
|
|
|
// DB::query(" |
|
251
|
|
|
// UPDATE \"GSTTaxModifierOptions\" |
|
252
|
|
|
// SET \"InclusiveOrExclusive\" = 'Inclusive' |
|
253
|
|
|
// WHERE \"InclusiveOrExclusive\" <> 'Exclusive'" |
|
254
|
|
|
// ); |
|
255
|
|
|
// } |
|
256
|
|
|
|
|
257
|
|
|
/** |
|
258
|
|
|
* returns the instance of EcommerceDBConfig |
|
259
|
|
|
* |
|
260
|
|
|
* @return EcommerceDBConfig |
|
261
|
|
|
**/ |
|
262
|
|
|
public function EcomConfig() |
|
263
|
|
|
{ |
|
264
|
|
|
return EcommerceDBConfig::current_ecommerce_db_config(); |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
public function CountryName() |
|
268
|
|
|
{ |
|
269
|
|
|
return $this->getCountryName(); |
|
270
|
|
|
} |
|
271
|
|
|
public function getCountryName() |
|
272
|
|
|
{ |
|
273
|
|
|
return EcommerceCountry::find_title($this->CountryCode); |
|
|
|
|
|
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
public function PercentageNice() |
|
277
|
|
|
{ |
|
278
|
|
|
return $this->getPercentageNice(); |
|
279
|
|
|
} |
|
280
|
|
|
public function getPercentageNice() |
|
281
|
|
|
{ |
|
282
|
|
|
return DBField::create_field("Text", ($this->Rate * 100)."%"); |
|
|
|
|
|
|
283
|
|
|
} |
|
284
|
|
|
} |
|
285
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.