PluginProbe
VikBooking Hotel Booking Engine & PMS / trunk
VikBooking Hotel Booking Engine & PMS vtrunk
1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 All 36 releases
vikbooking / admin / helpers / einvoicing / drivers / MydataAade / constants.php

constants.php in VikBooking Hotel Booking Engine & PMS trunk, at admin/helpers/einvoicing/drivers/MydataAade/constants.php

250 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage com_vikbooking
5 * @author Alessio Gaggii - e4j - Extensionsforjoomla.com
6 * @copyright Copyright (C) 2018 e4j - Extensionsforjoomla.com. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 * @link https://vikwp.com
9 */
10
11 defined('ABSPATH') or die('No script kiddies please!');
12
13 /**
14 * Helper Class to define some constants for the XML generation
15 */
16 class VikBookingMydataAadeConstants
17 {
18 /**
19 * Namespace attributes of main node <InvoicesDoc>.
20 * Namespace attributes will affect the incomeClassification
21 * sub nodes. Options available are, for example, the followings:
22 *
23 * <icls:classificationType>
24 * or
25 * <N1:classificationType>
26 *
27 * Old/alternative namespaces were:
28 * xmlns="http://www.aade.gr/myDATA/invoice/v1.0"
29 * xmlns:icls="https://www.aade.gr/myDATA/incomeClassification/v1.0"
30 * xmlns:ecls="https://www.aade.gr/myDATA/expensesClassification/v1.0"
31 * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
32 * xsi:schemaLocation="http://www.aade.gr/myDATA/invoice/v1.0 schema.xsd"
33 *
34 * @see https://mydata-dev.portal.azure-api.net/issues/5f3c411ac75730207831ead4
35 *
36 * @see !!!!IMPORTANT!!!!
37 * https://www.aade.gr/sites/default/files/2020-04/invoicesDoc-v0.6.xsd
38 * There is probably a typo in the official schema importing the namespaces
39 * for income and expense classifications. The official nodes are actually
40 * spelling the schemas namespaces as "https://www.aade.gr/myDATA/incomeClassificaton/v1.0"
41 * and "https://www.aade.gr/myDATA/expensesClassificaton/v1.0". It says "incomeClassificaTON"
42 * instead of "incomeClassificaTION". One "i" is missing, not sure if this is a typo, but the
43 * attributes below must spell the namespace like the official schema, so "classificaTON".
44 */
45 const INVOICESDOC_NMSP_ATTR_N1 = '
46 xmlns="http://www.aade.gr/myDATA/invoice/v1.0"
47 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
48 xmlns:N1="https://www.aade.gr/myDATA/incomeClassificaton/v1.0"
49 xsi:schemaLocation="http://www.aade.gr/myDATA/invoice/v1.0 schema.xsd"';
50
51 /**
52 * Another possible list of namespace attributes for the incomeClassification
53 */
54 const INVOICESDOC_NMSP_ATTR_ICLS = '
55 xmlns="http://www.aade.gr/myDATA/invoice/v1.0"
56 xmlns:icls="https://www.aade.gr/myDATA/incomeClassificaton/v1.0"
57 xmlns:ecls="https://www.aade.gr/myDATA/expensesClassificaton/v1.0"
58 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
59 xsi:schemaLocation="http://www.aade.gr/myDATA/invoice/v1.0 schema.xsd"';
60
61 /**
62 * Node invoiceType
63 */
64 const DEFAULT_INVOICE_TYPE = '1.1';
65
66 /**
67 * Node measurementUnit (1 for "Pieces")
68 */
69 const DEFAULT_MEAS_UNIT = '1';
70
71 /**
72 * Package description
73 */
74 const DESCRPACKAGENIGHTS = 'Packagage for a stay of %d nights';
75
76 /**
77 * Room nights description
78 */
79 const DESCRSTAYROOMNIGHTS = '%d night-stay in room %s';
80
81 /**
82 * Room Option description
83 */
84 const DESCRROOMOPTION = 'Service %s';
85
86 /**
87 * Tourist tax description
88 */
89 const DESCRTOURISTTAX = 'Tourist tax';
90
91 /**
92 * Room Extra Cost description
93 */
94 const DESCRROOMEXTRACOST = 'Extra fee %s';
95
96 /**
97 * XSD schema file name
98 */
99 const EINVSCHEMAFNAME = 'invoicesDoc-v0.6.xsd';
100
101 /**
102 * Development endpoint for myDATA. That's all we know.
103 * The live-mode endpoint is a driver setting because it's
104 * not mentioned anywhere in the docs, hence we cannot know it.
105 * Before 2024 it used to be https://mydata-dev.azure-api.net/.
106 */
107 const MYDATA_DEV_ENDPOINT_BASE = 'https://mydataapidev.aade.gr/';
108
109 /**
110 * QR Code PNG default width (points indicating pixels per cell).
111 * 1 ~= 49px/69px.
112 *
113 * @since 1.16.7 (J) - 1.6.7 (WP)
114 */
115 const QRCODE_PNG_WIDTH = 4;
116
117 /**
118 * QR Code PNG default height (points indicating pixels per cell).
119 * 1 ~= 49px/69px.
120 *
121 * @since 1.16.7 (J) - 1.6.7 (WP)
122 */
123 const QRCODE_PNG_HEIGHT = 4;
124
125 /**
126 * QR Code PNG default color (RGB) (black)
127 *
128 * @since 1.16.7 (J) - 1.6.7 (WP)
129 */
130 const QRCODE_PNG_COLOR_RGB = '0, 0, 0';
131
132 /**
133 * Returns the path to the local XSD schema. Official URL is:
134 * https://www.aade.gr/sites/default/files/2020-04/invoicesDoc-v0.6.xsd.
135 *
136 * @return string the XML Schema path
137 */
138 public static function getSchemaPath()
139 {
140 $path_parts = [VBO_ADMIN_PATH, 'helpers', 'einvoicing', 'drivers', 'MydataAade', self::EINVSCHEMAFNAME];
141
142 return implode(DIRECTORY_SEPARATOR, $path_parts);
143 }
144
145 /**
146 * Returns either the base path or base URI for the QR Code PNG files.
147 *
148 * @param string $base either "path" or "uri".
149 * @param string $fname optional file name to get a full path or URI.
150 *
151 * @return string either the base path or base URI.
152 *
153 * @since 1.16.7 (J) - 1.6.7 (WP)
154 */
155 public static function getQRCodeBase($base = 'path', $fname = '')
156 {
157 if (!strcasecmp($base, 'path')) {
158 // base path
159 $path_parts = [VBO_MEDIA_PATH, 'AADE'];
160
161 if ($fname) {
162 $path_parts[] = $fname;
163 }
164
165 return implode(DIRECTORY_SEPARATOR, $path_parts);
166 }
167
168 // base URI
169 return VBO_MEDIA_URI . 'AADE/' . $fname;
170 }
171
172 /**
173 * Given a percentage aliquote, returns the corresponding category int.
174 *
175 * @param int $aliquote the tax rate to parse.
176 *
177 * @return int the corresponding Vat Category.
178 *
179 * @see page 42 of https://www.aade.gr/sites/default/files/2020-04/myDATA%20API%20Documentation%20v0%206b_eng.pdf
180 */
181 public static function getVatCategory($aliquote)
182 {
183 $aliquote = (int)$aliquote;
184
185 if ($aliquote === 0) {
186 // without VAT 0%
187 return 7;
188 } elseif ($aliquote == 4) {
189 // VAT rate 4%
190 return 6;
191 } elseif ($aliquote == 9) {
192 // VAT rate 9%
193 return 5;
194 } elseif ($aliquote == 17) {
195 // VAT rate 17%
196 return 4;
197 } elseif ($aliquote == 6) {
198 // VAT rate 6%
199 return 3;
200 } elseif ($aliquote == 13 || $aliquote == 10) {
201 // VAT rate 13% (or 10% for testing)
202 return 2;
203 } elseif ($aliquote == 24) {
204 // VAT rate 24%
205 return 1;
206 } else {
207 // Records without VAT (which is not 0%, hence should never occur)
208 return 8;
209 }
210 }
211
212 /**
213 * Returns the myDATA development endpoint URL.
214 *
215 * @return string the base endpoint URL to be used.
216 */
217 public static function getDevEndpointBaseUrl()
218 {
219 return self::MYDATA_DEV_ENDPOINT_BASE;
220 }
221
222 /**
223 * This method will decide the namespace attributes to use
224 * for the main node <InvoicesDoc>. Change this method as
225 * well as the method below to switch between N1/ICLS.
226 *
227 * @return string
228 *
229 * @see getInvoiceChildrenNamespace() for children namespace.
230 */
231 public static function getInvoiceNamespaceAttributes()
232 {
233 return self::INVOICESDOC_NMSP_ATTR_N1;
234 }
235
236 /**
237 * This method will decide the namespace attribute to use
238 * for the children nodes of <incomeClassification>. Change
239 * this method as well as the method above to switch between N1/ICLS.
240 *
241 * @return string if null or an empty string, no namespaces will be used.
242 *
243 * @see getInvoiceNamespaceAttributes() for XML namespaces.
244 */
245 public static function getInvoiceChildrenNamespace()
246 {
247 return 'N1';
248 }
249 }
250