|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* oledrion |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright {@link http://xoops.org/ XOOPS Project} |
|
16
|
|
|
* @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
|
17
|
|
|
* @author Hervé Thouzard (http://www.herve-thouzard.com/) |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Gestion des TVA |
|
22
|
|
|
*/ |
|
23
|
|
|
require __DIR__ . '/classheader.php'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class Oledrion_vat |
|
27
|
|
|
*/ |
|
28
|
|
|
class Oledrion_vat extends Oledrion_Object |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* constructor |
|
32
|
|
|
* |
|
33
|
|
|
* normally, this is called from child classes only |
|
34
|
|
|
* |
|
35
|
|
|
* @access public |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->initVar('vat_id', XOBJ_DTYPE_INT, null, false); |
|
40
|
|
|
$this->initVar('vat_rate', XOBJ_DTYPE_TXTBOX, null, false); |
|
41
|
|
|
$this->initVar('vat_country', XOBJ_DTYPE_TXTBOX, null, false); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param string $format |
|
46
|
|
|
* @return array |
|
47
|
|
|
*/ |
|
48
|
|
View Code Duplication |
public function toArray($format = 's') |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
|
|
$ret = array(); |
|
|
|
|
|
|
51
|
|
|
$ret = parent::toArray($format); |
|
52
|
|
|
$oledrion_Currency = Oledrion_Currency::getInstance(); |
|
53
|
|
|
$ret['vat_rate_formated'] = $oledrion_Currency->amountInCurrency((float)$this->getVar('vat_rate', 'e')); |
|
54
|
|
|
|
|
55
|
|
|
return $ret; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Class OledrionOledrion_vatHandler |
|
61
|
|
|
*/ |
|
62
|
|
|
class OledrionOledrion_vatHandler extends Oledrion_XoopsPersistableObjectHandler |
|
|
|
|
|
|
63
|
|
|
{ |
|
64
|
|
|
/** |
|
65
|
|
|
* OledrionOledrion_vatHandler constructor. |
|
66
|
|
|
* @param XoopsDatabase|null $db |
|
67
|
|
|
*/ |
|
68
|
|
|
public function __construct(XoopsDatabase $db) |
|
69
|
|
|
{ // Table Classe Id |
|
70
|
|
|
parent::__construct($db, 'oledrion_vat', 'oledrion_vat', 'vat_id'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Renvoie la liste de toutes les TVA du module |
|
75
|
|
|
* |
|
76
|
|
|
* @param Oledrion_parameters $parameters |
|
77
|
|
|
* @return array tableau d'objets de type TVA |
|
78
|
|
|
* @internal param int $start Position de départ |
|
79
|
|
|
* @internal param int $limit Nombre total d'enregistrements à renvoyer |
|
80
|
|
|
* @internal param string $order Champ sur lequel faire le tri |
|
81
|
|
|
* @internal param string $order Ordre du tri |
|
82
|
|
|
* @internal param bool $idaskey Indique si le tableau renvoyé doit avoir pour clé l'identifiant unique de l'enregistrement |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getAllVats(Oledrion_parameters $parameters) |
|
85
|
|
|
{ |
|
86
|
|
|
$parameters = $parameters->extend(new Oledrion_parameters(array( |
|
|
|
|
|
|
87
|
|
|
'start' => 0, |
|
88
|
|
|
'limit' => 0, |
|
89
|
|
|
'sort' => 'vat_id', |
|
90
|
|
|
'order' => 'ASC', |
|
91
|
|
|
'idaskey' => true |
|
92
|
|
|
))); |
|
93
|
|
|
$critere = new Criteria('vat_id', 0, '<>'); |
|
94
|
|
|
$critere->setLimit($parameters['limit']); |
|
95
|
|
|
$critere->setStart($parameters['start']); |
|
96
|
|
|
$critere->setSort($parameters['sort']); |
|
97
|
|
|
$critere->setOrder($parameters['order']); |
|
98
|
|
|
$vats = array(); |
|
|
|
|
|
|
99
|
|
|
$vats = $this->getObjects($critere, $parameters['idaskey']); |
|
100
|
|
|
|
|
101
|
|
|
return $vats; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Renvoie la liste de toutes les TVA du module |
|
106
|
|
|
* |
|
107
|
|
|
* @param $country |
|
108
|
|
|
* @return array tableau d'objets de type TVA |
|
109
|
|
|
* @internal param int $start Position de départ |
|
110
|
|
|
* @internal param int $limit Nombre total d'enregistrements à renvoyer |
|
111
|
|
|
* @internal param string $order Champ sur lequel faire le tri |
|
112
|
|
|
* @internal param string $order Ordre du tri |
|
113
|
|
|
* @internal param bool $idaskey Indique si le tableau renvoyé doit avoir pour clé l'identifiant unique de l'enregistrement |
|
114
|
|
|
*/ |
|
115
|
|
|
public function getCountryVats($country) |
|
116
|
|
|
{ |
|
117
|
|
|
$parameters = new Oledrion_parameters(array( |
|
118
|
|
|
'start' => 0, |
|
119
|
|
|
'limit' => 0, |
|
120
|
|
|
'sort' => 'vat_id', |
|
121
|
|
|
'order' => 'ASC', |
|
122
|
|
|
'idaskey' => true |
|
123
|
|
|
)); |
|
124
|
|
|
$critere = new CriteriaCompo(); |
|
125
|
|
|
if (!empty($country)) { |
|
126
|
|
|
$critere->add(new Criteria('vat_country', $country, 'LIKE')); |
|
127
|
|
|
} |
|
128
|
|
|
$critere->setLimit($parameters['limit']); |
|
129
|
|
|
$critere->setStart($parameters['start']); |
|
130
|
|
|
$critere->setSort($parameters['sort']); |
|
131
|
|
|
$critere->setOrder($parameters['order']); |
|
132
|
|
|
$vats = array(); |
|
|
|
|
|
|
133
|
|
|
$vats = $this->getObjects($critere, $parameters['idaskey']); |
|
134
|
|
|
|
|
135
|
|
|
return $vats; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Suppression d'une TVA |
|
140
|
|
|
* |
|
141
|
|
|
* @param oledrion_vat $vat |
|
142
|
|
|
* @return boolean Le résultat de la suppressin |
|
143
|
|
|
*/ |
|
144
|
|
|
public function deleteVat(Oledrion_vat $vat) |
|
145
|
|
|
{ |
|
146
|
|
|
return $this->delete($vat, true); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Retourne le nombre de produits associés à une TVA |
|
151
|
|
|
* |
|
152
|
|
|
* @param integer $vat_id L'ID de la TVA |
|
153
|
|
|
* @return integer Le nombre de produits |
|
154
|
|
|
*/ |
|
155
|
|
|
public function getVatProductsCount($vat_id) |
|
156
|
|
|
{ |
|
157
|
|
|
global $h_oledrion_products; |
|
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
return $h_oledrion_products->getVatProductsCount($vat_id); |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.