| 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 |
class VikBookingReportIstatLiguria extends VikBookingReport |
| 14 |
{ |
| 15 |
private $from_ts; |
| 16 |
private $to_ts; |
| 17 |
public $bookings; |
| 18 |
|
| 19 |
/** |
| 20 |
* Property 'defaultKeySort' is used by the View that renders the report. |
| 21 |
*/ |
| 22 |
public $defaultKeySort = 'checkin'; |
| 23 |
|
| 24 |
/** |
| 25 |
* Property 'defaultKeyOrder' is used by the View that renders the report. |
| 26 |
*/ |
| 27 |
public $defaultKeyOrder = 'ASC'; |
| 28 |
|
| 29 |
/** |
| 30 |
* Property 'customExport' is used by the View to display custom export buttons. |
| 31 |
* We should not define the property $exportAllowed. |
| 32 |
*/ |
| 33 |
public $customExport = ''; |
| 34 |
|
| 35 |
/** |
| 36 |
* Debug mode is activated by passing the value 'e4j_debug' > 0 |
| 37 |
*/ |
| 38 |
private $debug; |
| 39 |
|
| 40 |
/** |
| 41 |
* An associative array of regions (keys) and provinces (sub-arrays) |
| 42 |
* |
| 43 |
* @var array |
| 44 |
*/ |
| 45 |
private $map_regioni_prov = array( |
| 46 |
'Abruzzo' => array( |
| 47 |
'Aquila', |
| 48 |
'Chieti', |
| 49 |
'Pescara', |
| 50 |
'Teramo', |
| 51 |
), |
| 52 |
'Basilicata' => array( |
| 53 |
'Potenza', |
| 54 |
'Matera', |
| 55 |
), |
| 56 |
'Calabria' => array( |
| 57 |
'Reggio Calabria', |
| 58 |
'Catanzaro', |
| 59 |
'Crotone', |
| 60 |
'Vibo Valentia Marina', |
| 61 |
'Cosenza', |
| 62 |
), |
| 63 |
'Campania' => array( |
| 64 |
'Napoli', |
| 65 |
'Avellino', |
| 66 |
'Caserta', |
| 67 |
'Benevento', |
| 68 |
'Salerno', |
| 69 |
), |
| 70 |
'EmiliaRomagna' => array( |
| 71 |
'Bologna', |
| 72 |
'Reggio Emilia', |
| 73 |
'Parma', |
| 74 |
'Modena', |
| 75 |
'Ferrara', |
| 76 |
'Forlì Cesena', |
| 77 |
'Piacenza', |
| 78 |
'Ravenna', |
| 79 |
'Rimini', |
| 80 |
), |
| 81 |
'FriuliVeneziaGiulia' => array( |
| 82 |
'Trieste', |
| 83 |
'Gorizia', |
| 84 |
'Pordenone', |
| 85 |
'Udine', |
| 86 |
), |
| 87 |
'Lazio' => array( |
| 88 |
'Roma', |
| 89 |
'Rome', |
| 90 |
'Latina', |
| 91 |
'Frosinone', |
| 92 |
'Viterbo', |
| 93 |
'Rieti', |
| 94 |
), |
| 95 |
'Liguria' => array( |
| 96 |
'Genova', |
| 97 |
'Imperia', |
| 98 |
'La Spezia', |
| 99 |
'Savona', |
| 100 |
), |
| 101 |
'Lombardia' => array( |
| 102 |
'Milano', |
| 103 |
'Bergamo', |
| 104 |
'Brescia', |
| 105 |
'Como', |
| 106 |
'Cremona', |
| 107 |
'Mantova', |
| 108 |
'Monza e Brianza', |
| 109 |
'Pavia', |
| 110 |
'Sondrio', |
| 111 |
'Lodi', |
| 112 |
'Lecco', |
| 113 |
'Varese', |
| 114 |
), |
| 115 |
'Marche' => array( |
| 116 |
'Ancona', |
| 117 |
'Ascoli Piceno', |
| 118 |
'Fermo', |
| 119 |
'Macerata', |
| 120 |
'Pesaro Urbino', |
| 121 |
), |
| 122 |
'Molise' => array( |
| 123 |
'Campobasso', |
| 124 |
'Isernia', |
| 125 |
), |
| 126 |
'Piemonte' => array( |
| 127 |
'Torino', |
| 128 |
'Asti', |
| 129 |
'Alessandria', |
| 130 |
'Cuneo', |
| 131 |
'Novara', |
| 132 |
'Vercelli', |
| 133 |
'Verbania', |
| 134 |
'Biella', |
| 135 |
), |
| 136 |
'ValledAosta' => array( |
| 137 |
'Aosta', |
| 138 |
), |
| 139 |
'Puglia' => array( |
| 140 |
'Bari', |
| 141 |
'Barletta-Andria-Trani', |
| 142 |
'Brindisi', |
| 143 |
'Foggia', |
| 144 |
'Lecce', |
| 145 |
'Taranto', |
| 146 |
), |
| 147 |
'Sardegna' => array( |
| 148 |
'Cagliari', |
| 149 |
'Sassari', |
| 150 |
'Nuoro', |
| 151 |
'Oristano', |
| 152 |
'Carbonia Iglesias', |
| 153 |
'Medio Campidano', |
| 154 |
'Olbia Tempio', |
| 155 |
'Ogliastra', |
| 156 |
), |
| 157 |
'Sicilia' => array( |
| 158 |
'Palermo', |
| 159 |
'Agrigento', |
| 160 |
'Caltanissetta', |
| 161 |
'Catania', |
| 162 |
'Enna', |
| 163 |
'Messina', |
| 164 |
'Ragusa', |
| 165 |
'Siracusa', |
| 166 |
'Trapani', |
| 167 |
), |
| 168 |
'Toscana' => array( |
| 169 |
'Arezzo', |
| 170 |
'Massa Carrara', |
| 171 |
'Firenze', |
| 172 |
'Florence', |
| 173 |
'Livorno', |
| 174 |
'Grosseto', |
| 175 |
'Lucca', |
| 176 |
'Pisa', |
| 177 |
'Pistoia', |
| 178 |
'Prato', |
| 179 |
'Siena', |
| 180 |
), |
| 181 |
'Trento' => array( |
| 182 |
'Trento', |
| 183 |
), |
| 184 |
'Bolzano' => array( |
| 185 |
'Bolzano', |
| 186 |
), |
| 187 |
'Umbria' => array( |
| 188 |
'Perugia', |
| 189 |
'Terni', |
| 190 |
), |
| 191 |
'Veneto' => array( |
| 192 |
'Venezia', |
| 193 |
'Venice', |
| 194 |
'Belluno', |
| 195 |
'Padova', |
| 196 |
'Rovigo', |
| 197 |
'Treviso', |
| 198 |
'Verona', |
| 199 |
'Vicenza', |
| 200 |
) |
| 201 |
); |
| 202 |
|
| 203 |
private $map_reg_codes = array( |
| 204 |
"Piemonte" => "01", |
| 205 |
"ValledAosta" => "02", |
| 206 |
"Lombardia" => "03", |
| 207 |
"Veneto" => "04", |
| 208 |
"Veneto" => "05", |
| 209 |
"FriuliVeneziaGiulia" => "06", |
| 210 |
"Liguria" => "07", |
| 211 |
"EmiliaRomagna" => "08", |
| 212 |
"Toscana" => "09", |
| 213 |
"Umbria" => "10", |
| 214 |
"Abruzzo" => "11", |
| 215 |
"Lazio" => "12", |
| 216 |
"Marche" => "13", |
| 217 |
"Molise" => "14", |
| 218 |
"Campania" => "15", |
| 219 |
"Puglia" => "16", |
| 220 |
"Basilicata" => "17", |
| 221 |
"Calabria" => "18", |
| 222 |
"Sicilia" => "19", |
| 223 |
"Sardegna" => "20", |
| 224 |
"Bolzano" => "21", |
| 225 |
"Trento" => "22" |
| 226 |
); |
| 227 |
|
| 228 |
private $map_prov_codes = array( |
| 229 |
"Torino" => "001", |
| 230 |
"Vercelli" => "002", |
| 231 |
"Novara" => "003", |
| 232 |
"Cuneo" => "004", |
| 233 |
"Asti" => "005", |
| 234 |
"Alessandria" => "006", |
| 235 |
"Aosta" => "007", |
| 236 |
"Imperia" => "008", |
| 237 |
"Savona" => "009", |
| 238 |
"Genova" => "010", |
| 239 |
"La Spezia" => "011", |
| 240 |
"Varese" => "012", |
| 241 |
"Como" => "013", |
| 242 |
"Sondrio" => "014", |
| 243 |
"Milano" => "015", |
| 244 |
"Bergamo" => "016", |
| 245 |
"Brescia" => "017", |
| 246 |
"Pavia" => "018", |
| 247 |
"Cremona" => "019", |
| 248 |
"Mantova" => "020", |
| 249 |
"Bolzano" => "021", |
| 250 |
"Trento" => "022", |
| 251 |
"Verona" => "023", |
| 252 |
"Vicenza" => "024", |
| 253 |
"Belluno" => "025", |
| 254 |
"Treviso" => "026", |
| 255 |
"Venezia" => "027", |
| 256 |
"Venice" => "027", |
| 257 |
"Padova" => "028", |
| 258 |
"Rovigo" => "029", |
| 259 |
"Udine" => "030", |
| 260 |
"Gorizia" => "031", |
| 261 |
"Trieste" => "032", |
| 262 |
"Piacenza" => "033", |
| 263 |
"Parma" => "034", |
| 264 |
"Reggio Emilia" => "035", |
| 265 |
"Modena" => "036", |
| 266 |
"Bologna" => "037", |
| 267 |
"Ferrara" => "038", |
| 268 |
"Ravenna" => "039", |
| 269 |
"Forlì Cesena" => "040", |
| 270 |
"Pesaro Urbino" => "041", |
| 271 |
"Ancona" => "042", |
| 272 |
"Macerata" => "043", |
| 273 |
"Ascoli Piceno" => "044", |
| 274 |
"Massa Carrara" => "045", |
| 275 |
"Lucca" => "046", |
| 276 |
"Pistoia" => "047", |
| 277 |
"Firenze" => "048", |
| 278 |
"Florence" => "048", |
| 279 |
"Livorno" => "049", |
| 280 |
"Pisa" => "050", |
| 281 |
"Arezzo" => "051", |
| 282 |
"Siena" => "052", |
| 283 |
"Grosseto" => "053", |
| 284 |
"Perugia" => "054", |
| 285 |
"Terni" => "055", |
| 286 |
"Viterbo" => "056", |
| 287 |
"Rieti" => "057", |
| 288 |
"Roma" => "058", |
| 289 |
"Rome" => "058", |
| 290 |
"Latina" => "059", |
| 291 |
"Frosinone" => "060", |
| 292 |
"Caserta" => "061", |
| 293 |
"Benevento" => "062", |
| 294 |
"Napoli" => "063", |
| 295 |
"Avellino" => "064", |
| 296 |
"Salerno" => "065", |
| 297 |
"Aquila" => "066", |
| 298 |
"Teramo" => "067", |
| 299 |
"Pescara" => "068", |
| 300 |
"Chieti" => "069", |
| 301 |
"Campobasso" => "070", |
| 302 |
"Foggia" => "071", |
| 303 |
"Bari" => "072", |
| 304 |
"Taranto" => "073", |
| 305 |
"Brindisi" => "074", |
| 306 |
"Lecce" => "075", |
| 307 |
"Potenza" => "076", |
| 308 |
"Matera" => "077", |
| 309 |
"Cosenza" => "078", |
| 310 |
"Catanzaro" => "079", |
| 311 |
"Reggio Calabria" => "080", |
| 312 |
"Trapani" => "081", |
| 313 |
"Palermo" => "082", |
| 314 |
"Messina" => "083", |
| 315 |
"Agrigento" => "084", |
| 316 |
"Caltanissetta" => "085", |
| 317 |
"Enna" => "086", |
| 318 |
"Catania" => "087", |
| 319 |
"Ragusa" => "088", |
| 320 |
"Siracusa" => "089", |
| 321 |
"Sassari" => "090", |
| 322 |
"Nuoro" => "091", |
| 323 |
"Cagliari" => "092", |
| 324 |
"Pordenone" => "093", |
| 325 |
"Isernia" => "094", |
| 326 |
"Oristano" => "095", |
| 327 |
"Biella" => "096", |
| 328 |
"Lecco" => "097", |
| 329 |
"Lodi" => "098", |
| 330 |
"Rimini" => "099", |
| 331 |
"Prato" => "100", |
| 332 |
"Crotone" => "101", |
| 333 |
"Vibo Valentia Marina" => "102", |
| 334 |
"Verbania" => "103", |
| 335 |
"Olbia Tempio" => "104", |
| 336 |
"Ogliastra" => "105", |
| 337 |
"Medio Campidano" => "106", |
| 338 |
"Carbonia Iglesias" => "107", |
| 339 |
"Monza e Brianza" => "108", |
| 340 |
"Fermo" => "109", |
| 341 |
"Barletta-Andria-Trani" => "110" |
| 342 |
); |
| 343 |
|
| 344 |
private $map_country_codes = array( |
| 345 |
'AUT' => 'Austria', |
| 346 |
'BEL' => 'Belgio', |
| 347 |
'HRV' => 'Croazia', |
| 348 |
'DNK' => 'Danimarca', |
| 349 |
'EGY' => 'Egitto', |
| 350 |
'FIN' => 'Finlandia', |
| 351 |
'FRA' => 'Francia', |
| 352 |
'DEU' => 'Germania', |
| 353 |
'GRC' => 'Grecia', |
| 354 |
'IRL' => 'Irlanda', |
| 355 |
'ISL' => 'Islanda', |
| 356 |
'LUX' => 'Lussemburgo', |
| 357 |
'NOR' => 'Norvegia', |
| 358 |
'NLD' => 'PaesiBassi', |
| 359 |
'POL' => 'Polonia', |
| 360 |
'PRT' => 'Portogallo', |
| 361 |
'GBR' => 'RegnoUnito', |
| 362 |
'CZE' => 'RepubblicaCeca', |
| 363 |
'RUS' => 'Russia', |
| 364 |
'SVK' => 'Slovacchia', |
| 365 |
'SVN' => 'Slovenia', |
| 366 |
'ESP' => 'Spagna', |
| 367 |
'SWE' => 'Svezia', |
| 368 |
'CHE' => 'Svizzera', |
| 369 |
'LIE' => 'Svizzera', |
| 370 |
// |
| 371 |
'TUR' => 'Turchia', |
| 372 |
'HUN' => 'Ungheria', |
| 373 |
'BGR' => 'Bulgaria', |
| 374 |
'ROM' => 'Romania', |
| 375 |
'EST' => 'Estonia', |
| 376 |
'CYP' => 'Cipro', |
| 377 |
'LTU' => 'Lituania', |
| 378 |
'LVA' => 'Lettonia', |
| 379 |
'MLT' => 'Malta', |
| 380 |
'UKR' => 'Ucraina', |
| 381 |
'CAN' => 'Canada', |
| 382 |
'USA' => 'StatiUniti', |
| 383 |
'MEX' => 'Messico', |
| 384 |
'VEN' => 'Venezuela', |
| 385 |
'BRA' => 'Brasile', |
| 386 |
'ARG' => 'Argentina', |
| 387 |
'CHN' => 'Cina', |
| 388 |
'JPN' => 'Giappone', |
| 389 |
'KOR' => 'CoreaSud', |
| 390 |
'IND' => 'India', |
| 391 |
'ISR' => 'Israele', |
| 392 |
'ZAF' => 'Sudafrica', |
| 393 |
'AUS' => 'Australia', |
| 394 |
'NZL' => 'NuovaZelanda', |
| 395 |
); |
| 396 |
|
| 397 |
/** |
| 398 |
* An associative array of country 3-char codes (keys) and ISTAT "tipo" codes (values). |
| 399 |
* Only for those who live outside Italy |
| 400 |
* |
| 401 |
* @var array |
| 402 |
*/ |
| 403 |
public $map_country_codes_transfer = array( |
| 404 |
'Austria' => '038', |
| 405 |
'Belgio' => '017', |
| 406 |
'Croazia' => '092', |
| 407 |
'Danimarca' => '008', |
| 408 |
'Egitto' => '220', |
| 409 |
'Finlandia' => '032', |
| 410 |
'Francia' => '001', |
| 411 |
'Germania' => '004', |
| 412 |
'Grecia' => '009', |
| 413 |
'Irlanda' => '007', |
| 414 |
'Islanda' => '024', |
| 415 |
'Lussemburgo' => '018', |
| 416 |
'Norvegia' => '028', |
| 417 |
'PaesiBassi' => '003', |
| 418 |
'Polonia' => '060', |
| 419 |
'Portogallo' => '010', |
| 420 |
'RegnoUnito' => '006', |
| 421 |
'RepubblicaCeca' => '061', |
| 422 |
'Russia' => '075', |
| 423 |
'Slovacchia' => '063', |
| 424 |
'Slovenia' => '091', |
| 425 |
'Spagna' => '011', |
| 426 |
'Svezia' => '030', |
| 427 |
'Svizzera' => '036', |
| 428 |
'Liechtenstein' => '036', |
| 429 |
// Liechtenstein = Svizzera. We keep it here for the 3-char country code |
| 430 |
// |
| 431 |
'Turchia' => '052', |
| 432 |
'Ungheria' => '064', |
| 433 |
'Bulgaria' => '068', |
| 434 |
'Romania' => '066', |
| 435 |
'Estonia' => '053', |
| 436 |
'Cipro' => '600', |
| 437 |
'Lituania' => '055', |
| 438 |
'Lettonia' => '054', |
| 439 |
'Malta' => '046', |
| 440 |
'Ucraina' => '072', |
| 441 |
'Canada' => '404', |
| 442 |
'StatiUniti' => '400', |
| 443 |
'Messico' => '412', |
| 444 |
'Venezuela' => '484', |
| 445 |
'Brasile' => '508', |
| 446 |
'Argentina' => '528', |
| 447 |
'Cina' => '720', |
| 448 |
'Giappone' => '732', |
| 449 |
'CoreaSud' => '728', |
| 450 |
'India' => '664', |
| 451 |
'Israele' => '624', |
| 452 |
'Sudafrica' => '388', |
| 453 |
'Australia' => '800', |
| 454 |
'NuovaZelanda' => '804', |
| 455 |
'AltriEuropa' => '100', |
| 456 |
'AltriNordAmerica' => '410', |
| 457 |
'AltriSudAmerica' => '530', |
| 458 |
'AltriAsiaOccid' => '750', |
| 459 |
'AltriAsia' => '760', |
| 460 |
'AltriAfricaMed' => '230', |
| 461 |
'AltriAfrica' => '300', |
| 462 |
'AltriOceania' => '810', |
| 463 |
'NonSpecificato' => '777' |
| 464 |
); |
| 465 |
|
| 466 |
/** |
| 467 |
* An associative array of valid country types (keys) |
| 468 |
* and readable country types (values). |
| 469 |
* |
| 470 |
* @var array |
| 471 |
*/ |
| 472 |
private $map_country_others = array( |
| 473 |
'AltriEuropa' => 'Albania, Andorra, Bielorussia, Bosnia-Erzegovina, Faeroe Islands (DK), Gibilterra (UK), Guernsey, Isle of Man, |
| 474 |
Jersey, Kosovo, Macedonia, Moldova, Monaco, Montenegro, San Marino, Serbia, Stato della città del Vaticano, Svalbard e Jan |
| 475 |
Mayen, Bonaire, Saint Eustatius and Saba (NL).', |
| 476 |
'AltriNordAmerica' => 'Bermuda, Greenland, Saint Pierre e Miquelon', |
| 477 |
'AltriSudAmerica' => 'Antigua e Barbuda, Bahamas, Barbados, Belize, Bolivia, Chile, Colombia, Costa Rica, Cuba, Domenica, Dominican Republic, Ecuador, El Salvador, Jamaica, Grenada, Guatemala, Guyana, Haiti, Honduras, Nicaragua, Panama, Paraguay, Peru, Saint Kitts e Nevis, Saint Lucia, Saint Vincent and Grenadine, Suriname, Trinidad and Tobago, Uruguay', |
| 478 |
'AltriAsiaOccid' => 'Saudi Arabia, Armenia, Azerbaigian, Bahrein, United Arab Emirates, Georgia, Jordan, Iran, Iraq, Kuwait, Lebanon, Oman, Qatar, Siria, Palestina, Yemen', |
| 479 |
'AltriAsia' => 'Altri Asia', |
| 480 |
'AltriAfricaMed' => 'Libia, Tunisia, Algeria, Morocco', |
| 481 |
'AltriAfrica' => 'Altri Africa', |
| 482 |
'AltriOceania' => 'Fiji, Kiribati, Isole Marshall, Micronesia, Nauru, Palau, Papua New Guinea, Solomon Islands, Samoa, Tonga, Tuvalu, Vanuatu', |
| 483 |
'NonSpecificato' => 'Sconosciuto', |
| 484 |
); |
| 485 |
|
| 486 |
/** |
| 487 |
* Class constructor should define the name of the report and |
| 488 |
* other vars. Call the parent constructor to define the DB object. |
| 489 |
*/ |
| 490 |
function __construct() |
| 491 |
{ |
| 492 |
$this->reportFile = basename(__FILE__, '.php'); |
| 493 |
$this->reportName = 'ISTAT Liguria'; |
| 494 |
$this->reportFilters = array(); |
| 495 |
|
| 496 |
$this->cols = array(); |
| 497 |
$this->rows = array(); |
| 498 |
$this->footerRow = array(); |
| 499 |
|
| 500 |
$this->debug = (VikRequest::getInt('e4j_debug', 0, 'request') > 0); |
| 501 |
|
| 502 |
$this->registerExportFileName(); |
| 503 |
|
| 504 |
parent::__construct(); |
| 505 |
} |
| 506 |
|
| 507 |
/** |
| 508 |
* Returns the name of this report. |
| 509 |
* |
| 510 |
* @return string |
| 511 |
*/ |
| 512 |
public function getName() |
| 513 |
{ |
| 514 |
return $this->reportName; |
| 515 |
} |
| 516 |
|
| 517 |
/** |
| 518 |
* Returns the name of this file without .php. |
| 519 |
* |
| 520 |
* @return string |
| 521 |
*/ |
| 522 |
public function getFileName() |
| 523 |
{ |
| 524 |
return $this->reportFile; |
| 525 |
} |
| 526 |
|
| 527 |
/** |
| 528 |
* Returns the filters of this report. |
| 529 |
* |
| 530 |
* @return array |
| 531 |
*/ |
| 532 |
public function getFilters() |
| 533 |
{ |
| 534 |
if (count($this->reportFilters)) { |
| 535 |
//do not run this method twice, as it could load JS and CSS files. |
| 536 |
return $this->reportFilters; |
| 537 |
} |
| 538 |
|
| 539 |
//load the jQuery UI Datepicker |
| 540 |
$this->loadDatePicker(); |
| 541 |
|
| 542 |
//custom export button |
| 543 |
$this->customExport = '<a href="JavaScript: void(0);" onclick="vboDownloadIstatDoc();" class="vbcsvexport"><i class="fa fa-download"></i> <span>Genera Documento Dati ISTAT</span></a>'; |
| 544 |
|
| 545 |
// helper filters |
| 546 |
$hidden_vals = '<div id="vbo-report-istat-hidden" style="display: none;">'; |
| 547 |
// Italian filter |
| 548 |
$hidden_vals .= ' <div id="vbo-report-istat-italia" class="vbo-report-istat-selcont" style="display: none;">'; |
| 549 |
$hidden_vals .= ' <select id="choose-italia" onchange="vboReportChosenItalia(this);"><option value=""></option>'; |
| 550 |
$italias = array( |
| 551 |
1 => 'Cittadino Italiano', |
| 552 |
0 => 'Cittadino Estero' |
| 553 |
); |
| 554 |
foreach ($italias as $code => $v) { |
| 555 |
$hidden_vals .= ' <option value="'.$code.'">'.$v.'</option>'."\n"; |
| 556 |
} |
| 557 |
$hidden_vals .= ' </select>'; |
| 558 |
$hidden_vals .= ' </div>'; |
| 559 |
// tipo (provenienza) filter |
| 560 |
$hidden_vals .= ' <div id="vbo-report-istat-tipo" class="vbo-report-istat-selcont" style="display: none;">'; |
| 561 |
$hidden_vals .= ' <select id="choose-tipo" onchange="vboReportChosenTipo(this);"><option value=""></option>'; |
| 562 |
foreach ($this->map_regioni_prov as $region => $cities) { |
| 563 |
$hidden_vals .= ' <optgroup label="Italia - '.$region.'">'; |
| 564 |
foreach ($cities as $city) { |
| 565 |
$hidden_vals .= ' <option value="'.$city.'">'.$city.'</option>'; |
| 566 |
} |
| 567 |
$hidden_vals .= ' </optgroup>'; |
| 568 |
} |
| 569 |
// sort all foreign countries in a clone to not lose keys. |
| 570 |
$map_country_codes = array_merge(array_unique($this->map_country_codes)); |
| 571 |
sort($map_country_codes); |
| 572 |
// |
| 573 |
$hidden_vals .= ' <optgroup label="Estero - Nazioni">'; |
| 574 |
foreach ($map_country_codes as $countrytipo) { |
| 575 |
$hidden_vals .= ' <option value="'.$countrytipo.'">'.$countrytipo.'</option>'; |
| 576 |
} |
| 577 |
$hidden_vals .= ' </optgroup>'; |
| 578 |
$hidden_vals .= ' <optgroup label="Estero - Altri">'; |
| 579 |
foreach ($this->map_country_others as $countrytipo => $countryother) { |
| 580 |
$hidden_vals .= ' <option value="'.$countrytipo.'">'.$countryother.'</option>'; |
| 581 |
} |
| 582 |
$hidden_vals .= ' </optgroup>'; |
| 583 |
$hidden_vals .= ' </select>'; |
| 584 |
$hidden_vals .= ' </div>'; |
| 585 |
// |
| 586 |
$hidden_vals .= '</div>'; |
| 587 |
|
| 588 |
//From Date Filter |
| 589 |
$filter_opt = array( |
| 590 |
'label' => '<label for="fromdate">'.JText::translate('VBOREPORTSDATEFROM').'</label>', |
| 591 |
'html' => '<input type="text" id="fromdate" name="fromdate" value="" class="vbo-report-datepicker vbo-report-datepicker-from" />'.$hidden_vals, |
| 592 |
'type' => 'calendar', |
| 593 |
'name' => 'fromdate' |
| 594 |
); |
| 595 |
array_push($this->reportFilters, $filter_opt); |
| 596 |
|
| 597 |
//To Date Filter |
| 598 |
$filter_opt = array( |
| 599 |
'label' => '<label for="todate">'.JText::translate('VBOREPORTSDATETO').'</label>', |
| 600 |
'html' => '<input type="text" id="todate" name="todate" value="" class="vbo-report-datepicker vbo-report-datepicker-to" />', |
| 601 |
'type' => 'calendar', |
| 602 |
'name' => 'todate' |
| 603 |
); |
| 604 |
array_push($this->reportFilters, $filter_opt); |
| 605 |
// Filtro Numero Letti |
| 606 |
$pletti = VikRequest::getInt('numletti', 0, 'request'); |
| 607 |
$filter_opt = array( |
| 608 |
'label' => '<label for="numletti">Numero Letti Disponibili</label>', |
| 609 |
'html' => '<input type="number" id="numletti" name="numletti" value="'.$pletti.'" size="10" />', |
| 610 |
'type' => 'text', |
| 611 |
'name' => 'numletti' |
| 612 |
); |
| 613 |
array_push($this->reportFilters, $filter_opt); |
| 614 |
|
| 615 |
// Filtro Codice Struttura |
| 616 |
$pcodstru = VikRequest::getString('codstru', '', 'request'); |
| 617 |
$filter_opt = array( |
| 618 |
'label' => '<label for="codstru">Codice Struttura</label>', |
| 619 |
'html' => '<input type="text" id="codstru" name="codstru" value="'.$pcodstru.'" size="10" />', |
| 620 |
'type' => 'text', |
| 621 |
'name' => 'codstru' |
| 622 |
); |
| 623 |
array_push($this->reportFilters, $filter_opt); |
| 624 |
|
| 625 |
//jQuery code for the datepicker calendars and select2 |
| 626 |
$pfromdate = VikRequest::getString('fromdate', '', 'request'); |
| 627 |
$ptodate = VikRequest::getString('todate', '', 'request'); |
| 628 |
$js = 'var reportActiveCell = null, reportObj = {}; |
| 629 |
jQuery(function() { |
| 630 |
jQuery(".vbo-report-datepicker:input").datepicker({ |
| 631 |
maxDate: 0, |
| 632 |
dateFormat: "'.$this->getDateFormat('jui').'", |
| 633 |
onSelect: vboReportCheckDates |
| 634 |
}); |
| 635 |
'.(!empty($pfromdate) ? 'jQuery(".vbo-report-datepicker-from").datepicker("setDate", "'.$pfromdate.'");' : '').' |
| 636 |
'.(!empty($ptodate) ? 'jQuery(".vbo-report-datepicker-to").datepicker("setDate", "'.$ptodate.'");' : '').' |
| 637 |
//prepare filler helpers |
| 638 |
jQuery("#vbo-report-istat-hidden").children().detach().appendTo(".vbo-info-overlay-report"); |
| 639 |
jQuery("#choose-italia").select2({placeholder: "- Seleziona Nazionalità -", width: "200px"}); |
| 640 |
jQuery("#choose-tipo").select2({placeholder: "- Seleziona Regione o Nazione -", width: "400px"}); |
| 641 |
//click events |
| 642 |
jQuery(".vbo-report-load-nazione").click(function() { |
| 643 |
reportActiveCell = this; |
| 644 |
jQuery(".vbo-report-istat-selcont").hide(); |
| 645 |
jQuery("#vbo-report-istat-italia").show(); |
| 646 |
vboShowOverlay(); |
| 647 |
}); |
| 648 |
jQuery(".vbo-report-load-cittadinanza").click(function() { |
| 649 |
reportActiveCell = this; |
| 650 |
jQuery(".vbo-report-istat-selcont").hide(); |
| 651 |
jQuery("#vbo-report-istat-tipo").show(); |
| 652 |
vboShowOverlay(); |
| 653 |
}); |
| 654 |
}); |
| 655 |
function vboReportCheckDates(selectedDate, inst) { |
| 656 |
if (selectedDate === null || inst === null) { |
| 657 |
return; |
| 658 |
} |
| 659 |
var cur_from_date = jQuery(this).val(); |
| 660 |
if (jQuery(this).hasClass("vbo-report-datepicker-from") && cur_from_date.length) { |
| 661 |
var nowstart = jQuery(this).datepicker("getDate"); |
| 662 |
var nowstartdate = new Date(nowstart.getTime()); |
| 663 |
jQuery(".vbo-report-datepicker-to").datepicker("option", {minDate: nowstartdate}); |
| 664 |
} |
| 665 |
} |
| 666 |
function vboReportChosenItalia(italia) { |
| 667 |
var c_code = italia.value; |
| 668 |
var c_val = italia.options[italia.selectedIndex].text; |
| 669 |
if (reportActiveCell !== null) { |
| 670 |
var nowindex = jQuery(".vbo-reports-output table tbody tr").index(jQuery(reportActiveCell).closest("tr")); |
| 671 |
if (isNaN(nowindex) || parseInt(nowindex) < 0) { |
| 672 |
alert("Error, cannot find element to update."); |
| 673 |
} else { |
| 674 |
jQuery(reportActiveCell).addClass("vbo-report-load-elem-filled").find("span").text(c_val); |
| 675 |
if (!reportObj.hasOwnProperty(nowindex)) { |
| 676 |
reportObj[nowindex] = {}; |
| 677 |
} |
| 678 |
reportObj[nowindex].italia = c_code; |
| 679 |
} |
| 680 |
} |
| 681 |
reportActiveCell = null; |
| 682 |
vboHideOverlay(); |
| 683 |
jQuery("#choose-italia").val("").select2("data", null, false); |
| 684 |
} |
| 685 |
function vboReportChosenTipo(tipo) { |
| 686 |
var c_code = tipo.value; |
| 687 |
var c_val = tipo.options[tipo.selectedIndex].text; |
| 688 |
if (reportActiveCell !== null) { |
| 689 |
var nowindex = jQuery(".vbo-reports-output table tbody tr").index(jQuery(reportActiveCell).closest("tr")); |
| 690 |
if (isNaN(nowindex) || parseInt(nowindex) < 0) { |
| 691 |
alert("Error, cannot find element to update."); |
| 692 |
} else { |
| 693 |
// we need to display the value of the tipo, not the option text |
| 694 |
jQuery(reportActiveCell).addClass("vbo-report-load-elem-filled").find("span").text(c_code); |
| 695 |
if (!reportObj.hasOwnProperty(nowindex)) { |
| 696 |
reportObj[nowindex] = {}; |
| 697 |
} |
| 698 |
reportObj[nowindex].tipo = c_code; |
| 699 |
} |
| 700 |
} |
| 701 |
reportActiveCell = null; |
| 702 |
vboHideOverlay(); |
| 703 |
jQuery("#choose-tipo").val("").select2("data", null, false); |
| 704 |
} |
| 705 |
//download function |
| 706 |
function vboDownloadIstatDoc() { |
| 707 |
// check if empty values have been filled in or ask for confirmation |
| 708 |
var missing_italia = jQuery(".vbo-report-load-nazione").not(".vbo-report-load-elem-filled").length; |
| 709 |
var missing_tipo = jQuery(".vbo-report-load-cittadinanza").not(".vbo-report-load-elem-filled").length; |
| 710 |
if ((missing_italia > 0 || missing_tipo > 0) && !confirm("Qualche dato mancante evidenziato in rosso non è stato compilato. Vuoi continuare?")) { |
| 711 |
return false; |
| 712 |
} else if (!confirm("Sei sicuro di aver compilato tutti i dati per il documento?")) { |
| 713 |
return false; |
| 714 |
} |
| 715 |
document.adminForm.target = "_blank"; |
| 716 |
document.adminForm.action += "&tmpl=component"; |
| 717 |
vboSetFilters({exportreport: "1", filler: JSON.stringify(reportObj)}, true); |
| 718 |
setTimeout(function() { |
| 719 |
document.adminForm.target = ""; |
| 720 |
document.adminForm.action = document.adminForm.action.replace("&tmpl=component", ""); |
| 721 |
vboSetFilters({exportreport: "0", filler: ""}, false); |
| 722 |
}, 1000); |
| 723 |
} |
| 724 |
'; |
| 725 |
$this->setScript($js); |
| 726 |
|
| 727 |
return $this->reportFilters; |
| 728 |
} |
| 729 |
|
| 730 |
/** |
| 731 |
* Loads the report data from the DB. |
| 732 |
* Returns true in case of success, false otherwise. |
| 733 |
* Sets the columns and rows for the report to be displayed. |
| 734 |
* |
| 735 |
* @return boolean |
| 736 |
*/ |
| 737 |
public function getReportData() |
| 738 |
{ |
| 739 |
if (strlen($this->getError())) { |
| 740 |
//Export functions may set errors rather than exiting the process, and the View may continue the execution to attempt to render the report. |
| 741 |
return false; |
| 742 |
} |
| 743 |
//Input fields and other vars |
| 744 |
$pfromdate = VikRequest::getString('fromdate', '', 'request'); |
| 745 |
$ptodate = VikRequest::getString('todate', '', 'request'); |
| 746 |
$pcodstru = VikRequest::getString('codstru', '', 'request'); |
| 747 |
$pkrsort = VikRequest::getString('krsort', $this->defaultKeySort, 'request'); |
| 748 |
$pkrsort = empty($pkrsort) ? $this->defaultKeySort : $pkrsort; |
| 749 |
$pkrorder = VikRequest::getString('krorder', $this->defaultKeyOrder, 'request'); |
| 750 |
$pkrorder = empty($pkrorder) ? $this->defaultKeyOrder : $pkrorder; |
| 751 |
$pkrorder = $pkrorder == 'DESC' ? 'DESC' : 'ASC'; |
| 752 |
$df = $this->getDateFormat(); |
| 753 |
$datesep = VikBooking::getDateSeparator(); |
| 754 |
$records = array(); |
| 755 |
$q = "SELECT SUM(`units`) AS `sommaunita`, SUM(`totpeople`) AS `numeropersone`, COUNT(*) AS `numerocamere` FROM `#__vikbooking_rooms` WHERE `avail`= '1';"; |
| 756 |
$this->dbo->setQuery($q); |
| 757 |
$this->dbo->execute(); |
| 758 |
if ($this->dbo->getNumRows() > 0) { |
| 759 |
$records = $this->dbo->loadAssocList(); |
| 760 |
} |
| 761 |
$totalBeds =(int) ($records[0]['sommaunita'] * ($records[0]['numeropersone']/$records[0]['numerocamere'])); |
| 762 |
$pletti = VikRequest::getString('numletti', $totalBeds, 'request'); |
| 763 |
if (empty($ptodate)) { |
| 764 |
$ptodate = $pfromdate; |
| 765 |
} |
| 766 |
//Get dates timestamps |
| 767 |
$from_ts = VikBooking::getDateTimestamp($pfromdate, 0, 0); |
| 768 |
$to_ts = VikBooking::getDateTimestamp($ptodate, 23, 59, 59); |
| 769 |
$this->from_ts = $from_ts; |
| 770 |
$this->to_ts = $to_ts; |
| 771 |
if (empty($pfromdate) || empty($from_ts) || empty($to_ts)) { |
| 772 |
$this->setError(JText::translate('VBOREPORTSERRNODATES')); |
| 773 |
return false; |
| 774 |
} |
| 775 |
if (empty($pcodstru)) { |
| 776 |
$this->setError('Inserisci il codice della tua Struttura.<br/>Si tratta di un codice univoco di identificazione che ti viene assegnato dall\'Amministrazione competente.'); |
| 777 |
return false; |
| 778 |
} |
| 779 |
|
| 780 |
//Query to obtain the records (all check-ins within the dates filter) |
| 781 |
$records = array(); |
| 782 |
$q = "SELECT `o`.`id`,`o`.`custdata`,`o`.`ts`,`o`.`days`,`o`.`checkin`,`o`.`checkout`,`o`.`totpaid`,`o`.`roomsnum`,`o`.`total`,`o`.`idorderota`,`o`.`channel`,`o`.`country`,". |
| 783 |
"`or`.`idorder`,`or`.`idroom`,`or`.`adults`,`or`.`children`,`or`.`t_first_name`,`or`.`t_last_name`,`or`.`cust_cost`,`or`.`cust_idiva`,`or`.`extracosts`,`or`.`room_cost`,". |
| 784 |
"`co`.`idcustomer`,`co`.`pax_data`,`c`.`first_name`,`c`.`last_name`,`c`.`country` AS `customer_country`,`c`.`city`,`c`.`doctype`,`c`.`docnum`,`c`.`gender`,`c`.`bdate`,`c`.`pbirth`,`cy`.`country_name`,". |
| 785 |
"(SELECT `h`.`dt` FROM `#__vikbooking_orderhistory` AS `h` WHERE `h`.`idorder`=`o`.`id` AND `h`.`type`='RP' AND `h`.`descr`=".$this->dbo->quote($this->reportName)." ORDER BY `h`.`dt` DESC LIMIT 1) AS `history_last` ". |
| 786 |
"FROM `#__vikbooking_orders` AS `o` LEFT JOIN `#__vikbooking_ordersrooms` AS `or` ON `or`.`idorder`=`o`.`id` ". |
| 787 |
"LEFT JOIN `#__vikbooking_customers_orders` AS `co` ON `co`.`idorder`=`o`.`id` LEFT JOIN `#__vikbooking_customers` AS `c` ON `c`.`id`=`co`.`idcustomer` LEFT JOIN `#__vikbooking_countries` AS `cy` ON `cy`.`country_3_code`=`c`.`country` ". |
| 788 |
"WHERE `o`.`status`='confirmed' AND `o`.`closure`=0 AND ((`o`.`checkin`>=".$from_ts." AND `o`.`checkin`<=".$to_ts.") OR (`o`.`checkout`>=".$from_ts." AND `o`.`checkout`<=".$to_ts.") OR (`o`.`checkin`<=".$from_ts." AND `o`.`checkout`>=".$to_ts.")) ". |
| 789 |
"ORDER BY `o`.`checkin` ASC, `o`.`id` ASC, `or`.`id` ASC;"; |
| 790 |
$this->dbo->setQuery($q); |
| 791 |
$records = $this->dbo->loadAssocList(); |
| 792 |
|
| 793 |
if (!$records) { |
| 794 |
$this->setError(JText::translate('VBOREPORTSERRNORESERV')); |
| 795 |
return false; |
| 796 |
} |
| 797 |
|
| 798 |
//nest records with multiple rooms booked inside sub-array |
| 799 |
$bookings = array(); |
| 800 |
|
| 801 |
foreach ($records as $v) { |
| 802 |
if (!isset($bookings[$v['id']])) { |
| 803 |
$bookings[$v['id']] = array(); |
| 804 |
} |
| 805 |
// for bc, if the country is defined at booking level, set it also for the customer |
| 806 |
if (empty($v['customer_country']) && !empty($v['country'])) { |
| 807 |
$v['customer_country'] = $v['country']; |
| 808 |
} |
| 809 |
//calculate the from_ts and to_ts values for later comparison |
| 810 |
$in_info = getdate($v['checkin']); |
| 811 |
$out_info = getdate($v['checkout']); |
| 812 |
$v['from_ts'] = mktime(0, 0, 0, $in_info['mon'], $in_info['mday'], $in_info['year']); |
| 813 |
$v['to_ts'] = mktime(23, 59, 59, $out_info['mon'], ($out_info['mday'] - 1), $out_info['year']); |
| 814 |
// |
| 815 |
array_push($bookings[$v['id']], $v); |
| 816 |
} |
| 817 |
$this->bookings = $bookings; |
| 818 |
|
| 819 |
//define the columns of the report |
| 820 |
$this->cols = array( |
| 821 |
//IdSWH (identificativo posizione - we use the booking ID) |
| 822 |
array( |
| 823 |
'key' => 'idswh', |
| 824 |
|
| 825 |
'sortable' => 1, |
| 826 |
'label' => 'Codice IDSWH', |
| 827 |
'tip' => 'Questo è il codice identificativo della trasmissione del dato verso l\'ISTAT, ed è uguale all\'ID della prenotazione nel sistema.', |
| 828 |
'export_name' => 'IdSWH' |
| 829 |
), |
| 830 |
//Codice Struttura |
| 831 |
array( |
| 832 |
'key' => 'codstru', |
| 833 |
'label' => 'Codice Struttura', |
| 834 |
'tip' => 'Il codice della tua struttura che l\'Amministrazione competente ti ha assegnato. Il dato verrà comunicato all\'ISTAT.', |
| 835 |
'export_name' => 'Codice' |
| 836 |
), |
| 837 |
//customer |
| 838 |
array( |
| 839 |
'key' => 'customer', |
| 840 |
'sortable' => 1, |
| 841 |
'label' => 'Cliente', |
| 842 |
'tip' => 'I nominativi dei clienti non verranno comunicati all\'ISTAT in quanto non necessari.', |
| 843 |
'ignore_export' => 1 |
| 844 |
), |
| 845 |
//checkin |
| 846 |
array( |
| 847 |
'key' => 'checkin', |
| 848 |
'attr' => array( |
| 849 |
'class="center"' |
| 850 |
), |
| 851 |
'sortable' => 1, |
| 852 |
'label' => 'Arrivo' |
| 853 |
), |
| 854 |
//checkout |
| 855 |
array( |
| 856 |
'key' => 'checkout', |
| 857 |
'attr' => array( |
| 858 |
'class="center"' |
| 859 |
), |
| 860 |
'sortable' => 1, |
| 861 |
'label' => 'Partenza' |
| 862 |
), |
| 863 |
//italia |
| 864 |
array( |
| 865 |
'key' => 'italia', |
| 866 |
'attr' => array( |
| 867 |
'class="center"' |
| 868 |
), |
| 869 |
'sortable' => 1, |
| 870 |
'label' => 'Italia', |
| 871 |
'tip' => 'Cittadino Italiano o Estero. Assicurati di fare la giusta selezione in caso di dati mancanti nel sistema (?) per certe prenotazioni.', |
| 872 |
), |
| 873 |
//tipo (provenienza) |
| 874 |
array( |
| 875 |
'key' => 'tipo', |
| 876 |
'attr' => array( |
| 877 |
'class="center"' |
| 878 |
), |
| 879 |
'sortable' => 1, |
| 880 |
'label' => 'Provenienza', |
| 881 |
'tip' => 'Codice di Provenienza del cliente. Assicurati di fare la giusta selezione in caso di dati mancanti nel sistema (?) per certe prenotazioni.', |
| 882 |
'export_name' => 'Tipo' |
| 883 |
), |
| 884 |
//quantità (numero di ospiti) |
| 885 |
array( |
| 886 |
'key' => 'guestsnum', |
| 887 |
'attr' => array( |
| 888 |
'class="center"' |
| 889 |
), |
| 890 |
'sortable' => 1, |
| 891 |
'label' => 'Numero Ospiti', |
| 892 |
'tip' => 'Il numero di ospiti totali (adulti + bambini) per ogni prenotazione è un dato che verrà comunicato all\'ISTAT.', |
| 893 |
'export_name' => 'Quantita' |
| 894 |
), |
| 895 |
//occupazione (numero di camere prenotate) |
| 896 |
array( |
| 897 |
'key' => 'roomsbooked', |
| 898 |
'attr' => array( |
| 899 |
'class="center"' |
| 900 |
), |
| 901 |
'sortable' => 1, |
| 902 |
'label' => 'Occupazione', |
| 903 |
'tip' => 'Questo valore indica il numero di camere occupate da ogni prenotazione, ed è un dato che verrà comunicato all\'ISTAT.', |
| 904 |
), |
| 905 |
//camere (numero di camere totali) |
| 906 |
array( |
| 907 |
'key' => 'totrooms', |
| 908 |
'attr' => array( |
| 909 |
'class="center"' |
| 910 |
), |
| 911 |
'sortable' => 1, |
| 912 |
'label' => 'Camere', |
| 913 |
'tip' => 'Questo valore indica il numero totale di camere nella tua struttura, ed è un dato che deve essere comunicato all\'ISTAT. Viene calcolato con una somma delle unità di tutte le camere attualmente Pubblicate nel sistema.', |
| 914 |
) |
| 915 |
|
| 916 |
); |
| 917 |
|
| 918 |
// total rooms units ("camere") |
| 919 |
$total_rooms_units = $this->countRooms() ?: 1; |
| 920 |
|
| 921 |
//loop over the bookings to build the rows of the report |
| 922 |
foreach ($bookings as $gbook) { |
| 923 |
$guestsnum = 0; |
| 924 |
foreach ($gbook as $book) { |
| 925 |
$guestsnum += $book['adults'] + $book['children']; |
| 926 |
} |
| 927 |
$country = ''; |
| 928 |
if (!empty($gbook[0]['country'])) { |
| 929 |
$country = $gbook[0]['country']; |
| 930 |
} elseif (!empty($gbook[0]['customer_country'])) { |
| 931 |
$country = $gbook[0]['customer_country']; |
| 932 |
} |
| 933 |
$history_last = $gbook[0]['history_last']; |
| 934 |
$tipo_provenienza = $this->guessTipoProvenienza($gbook[0]); |
| 935 |
//push fields in the rows array as a new row |
| 936 |
array_push($this->rows, array( |
| 937 |
array( |
| 938 |
'key' => 'idswh', |
| 939 |
'callback' => function ($val) use ($history_last) { |
| 940 |
if (!empty($history_last)) { |
| 941 |
$tip = VikBooking::getVboApplication()->createPopover(array('title' => 'Data ultimo invio', 'content' => $history_last.'. Puoi comunque ritrasmettere questa informazione, e se cambia verrà aggiornata.')); |
| 942 |
return '<a href="index.php?option=com_vikbooking&task=editorder&cid[]='.$val.'" target="_blank">'.$tip.' '.$val.'</a>'; |
| 943 |
} |
| 944 |
return '<a href="index.php?option=com_vikbooking&task=editorder&cid[]='.$val.'" target="_blank"><i class="fa fa-external-link"></i> '.$val.'</a>'; |
| 945 |
}, |
| 946 |
'callback_export' => function ($val) { |
| 947 |
return $val; |
| 948 |
}, |
| 949 |
'value' => $gbook[0]['id'] |
| 950 |
), |
| 951 |
array( |
| 952 |
'key' => 'codstru', |
| 953 |
'value' => $pcodstru |
| 954 |
), |
| 955 |
array( |
| 956 |
'key' => 'customer', |
| 957 |
'callback' => function ($val) use ($country) { |
| 958 |
if (file_exists(VBO_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'countries'.DIRECTORY_SEPARATOR.$country.'.png')) { |
| 959 |
return $val.'<img src="'.VBO_ADMIN_URI.'resources/countries/'.$country.'.png" title="'.$country.'" class="vbo-country-flag vbo-country-flag-left" />'; |
| 960 |
} |
| 961 |
return $val; |
| 962 |
}, |
| 963 |
'value' => $gbook[0]['first_name'] . ' ' . $gbook[0]['last_name'], |
| 964 |
'ignore_export' => 1 |
| 965 |
), |
| 966 |
array( |
| 967 |
'key' => 'checkin', |
| 968 |
'attr' => array( |
| 969 |
'class="center"' |
| 970 |
), |
| 971 |
'callback' => function ($val) use ($df, $datesep) { |
| 972 |
return date(str_replace("/", $datesep, $df), $val); |
| 973 |
}, |
| 974 |
'callback_export' => function ($val) use ($df, $datesep) { |
| 975 |
return date('Ymd', $val); |
| 976 |
}, |
| 977 |
'value' => $gbook[0]['checkin'] |
| 978 |
), |
| 979 |
array( |
| 980 |
'key' => 'checkout', |
| 981 |
'attr' => array( |
| 982 |
'class="center"' |
| 983 |
), |
| 984 |
'callback' => function ($val) use ($df, $datesep) { |
| 985 |
return date(str_replace("/", $datesep, $df), $val); |
| 986 |
}, |
| 987 |
'callback_export' => function ($val) use ($df, $datesep) { |
| 988 |
return date('Ymd', $val); |
| 989 |
}, |
| 990 |
'value' => $gbook[0]['checkout'] |
| 991 |
), |
| 992 |
array( |
| 993 |
'key' => 'italia', |
| 994 |
'attr' => array( |
| 995 |
'class="center'.(empty($gbook[0]['customer_country']) ? ' vbo-report-load-nazione' : '').'"' |
| 996 |
), |
| 997 |
'callback' => function ($val) { |
| 998 |
if ($val < 0) { |
| 999 |
// empty country |
| 1000 |
return '?'; |
| 1001 |
} |
| 1002 |
if ($val == 1) { |
| 1003 |
// Italian customer |
| 1004 |
return 'Cittadino Italiano'; |
| 1005 |
} |
| 1006 |
// non Italian customer |
| 1007 |
return 'Cittadino Estero'; |
| 1008 |
}, |
| 1009 |
'callback_export' => function ($val) { |
| 1010 |
return $val; |
| 1011 |
}, |
| 1012 |
'value' => (empty($gbook[0]['customer_country']) ? -1 : (substr(strtoupper($gbook[0]['customer_country']), 0, 3) == 'ITA' ? 1 : 0)) |
| 1013 |
), |
| 1014 |
array( |
| 1015 |
'key' => 'tipo', |
| 1016 |
'attr' => array( |
| 1017 |
'class="center'.($tipo_provenienza == -1 ? ' vbo-report-load-cittadinanza' : '').'"' |
| 1018 |
), |
| 1019 |
'callback' => function ($val) { |
| 1020 |
if ($val < 0) { |
| 1021 |
// empty value |
| 1022 |
return '?'; |
| 1023 |
} |
| 1024 |
return $val; |
| 1025 |
}, |
| 1026 |
'callback_export' => function ($val) { |
| 1027 |
return $val; |
| 1028 |
}, |
| 1029 |
'value' => $tipo_provenienza |
| 1030 |
), |
| 1031 |
array( |
| 1032 |
'key' => 'guestsnum', |
| 1033 |
'attr' => array( |
| 1034 |
'class="center"' |
| 1035 |
), |
| 1036 |
'value' => $guestsnum |
| 1037 |
), |
| 1038 |
array( |
| 1039 |
'key' => 'roomsbooked', |
| 1040 |
'attr' => array( |
| 1041 |
'class="center"' |
| 1042 |
), |
| 1043 |
'value' => count($gbook) |
| 1044 |
), |
| 1045 |
array( |
| 1046 |
'key' => 'totrooms', |
| 1047 |
'attr' => array( |
| 1048 |
'class="center"' |
| 1049 |
), |
| 1050 |
'value' => $total_rooms_units |
| 1051 |
) |
| 1052 |
|
| 1053 |
)); |
| 1054 |
} |
| 1055 |
|
| 1056 |
//sort rows |
| 1057 |
$this->sortRows($pkrsort, $pkrorder); |
| 1058 |
|
| 1059 |
//the footer row will just print the amount of records to export |
| 1060 |
array_push($this->footerRow, array( |
| 1061 |
array( |
| 1062 |
'attr' => array( |
| 1063 |
'class="vbo-report-total"' |
| 1064 |
), |
| 1065 |
'value' => '<h3>'.JText::translate('VBOREPORTSTOTALROW').'</h3>' |
| 1066 |
), |
| 1067 |
array( |
| 1068 |
'attr' => array( |
| 1069 |
'colspan="'.(count($this->cols) - 1).'"' |
| 1070 |
), |
| 1071 |
'value' => count($this->rows) |
| 1072 |
) |
| 1073 |
)); |
| 1074 |
|
| 1075 |
//Debug |
| 1076 |
if ($this->debug) { |
| 1077 |
$this->setWarning('path to report file = '.urlencode(dirname(__FILE__)).'<br/>'); |
| 1078 |
$this->setWarning('$total_rooms_units = '.$total_rooms_units.'<br/>'); |
| 1079 |
$this->setWarning('$bookings:<pre>'.print_r($bookings, true).'</pre><br/>'); |
| 1080 |
} |
| 1081 |
// |
| 1082 |
|
| 1083 |
return true; |
| 1084 |
} |
| 1085 |
|
| 1086 |
/** |
| 1087 |
* Attempts to guess the column 'tipo' (provenienza) |
| 1088 |
* depending on the country and city given. For Italians, |
| 1089 |
* the name of the region is returned (if any, given the city). |
| 1090 |
* For foreigners, the country type is returned. |
| 1091 |
* |
| 1092 |
* @param array the booking record |
| 1093 |
* |
| 1094 |
* @return mixed string to use for the column 'tipo', -1 if empty. |
| 1095 |
*/ |
| 1096 |
private function guessTipoProvenienza($booking) |
| 1097 |
{ |
| 1098 |
if (empty($booking['customer_country'])) { |
| 1099 |
// unable to proceed when the country is missing (-1). |
| 1100 |
return -1; |
| 1101 |
} |
| 1102 |
|
| 1103 |
// uppercase 3-char code of the country only |
| 1104 |
$country3 = substr(strtoupper($booking['customer_country']), 0, 3); |
| 1105 |
|
| 1106 |
if ($country3 == 'ITA') { |
| 1107 |
// Italian customer |
| 1108 |
if (!empty($booking['city'])) { |
| 1109 |
foreach ($this->map_regioni_prov as $tipo => $cities) { |
| 1110 |
foreach ($cities as $city) { |
| 1111 |
if (stripos($city, $booking['city']) !== false) { |
| 1112 |
// region was found |
| 1113 |
return $city; |
| 1114 |
} |
| 1115 |
} |
| 1116 |
} |
| 1117 |
} |
| 1118 |
// empty city or no city found in the map |
| 1119 |
return -1; |
| 1120 |
} |
| 1121 |
|
| 1122 |
// foreigner customer |
| 1123 |
if (isset($this->map_country_codes[$country3])) { |
| 1124 |
// country name found for 'tipo' column |
| 1125 |
return $this->map_country_codes[$country3]; |
| 1126 |
} |
| 1127 |
// check the 'country_name' in 'other countries' |
| 1128 |
if (!empty($booking['country_name'])) { |
| 1129 |
foreach ($this->map_country_others as $tipo => $countries) { |
| 1130 |
if (stripos($countries, $booking['country_name']) !== false) { |
| 1131 |
// the name of the country taken from the 3-char code matches with an 'other country'. Guessing makes sense. |
| 1132 |
return $tipo; |
| 1133 |
} |
| 1134 |
} |
| 1135 |
} |
| 1136 |
|
| 1137 |
// nothing found |
| 1138 |
return -1; |
| 1139 |
} |
| 1140 |
|
| 1141 |
public function formatXML(&$xml) |
| 1142 |
{ |
| 1143 |
if (!class_exists('DOMDocument')) { |
| 1144 |
// we cannot format the XML because DOMDocument is missing |
| 1145 |
return $xml; |
| 1146 |
} |
| 1147 |
|
| 1148 |
$dom = new DOMDocument; |
| 1149 |
$dom->preserveWhiteSpace = false; |
| 1150 |
$dom->loadXML($xml); |
| 1151 |
$dom->formatOutput = true; |
| 1152 |
$xml = $dom->saveXML(); |
| 1153 |
|
| 1154 |
return $xml; |
| 1155 |
} |
| 1156 |
|
| 1157 |
/** |
| 1158 |
* Generates the report columns and rows, then it outputs a CSV file |
| 1159 |
* for download. In case of errors, the process is not terminated (exit) |
| 1160 |
* to let the View display the error message. |
| 1161 |
* We use customExport() rather than exportCSV() only because we need a |
| 1162 |
* different download button rather than the classic "Export as CSV". |
| 1163 |
* |
| 1164 |
* @param string $export_type Differentiates the type of export requested. |
| 1165 |
* |
| 1166 |
* @return void|bool Void in case of script termination, boolean otherwise. |
| 1167 |
*/ |
| 1168 |
public function customExport($export_type = 0) |
| 1169 |
{ |
| 1170 |
if (!$this->getReportData()) { |
| 1171 |
return false; |
| 1172 |
} |
| 1173 |
|
| 1174 |
$pfromdate = VikRequest::getString('fromdate', '', 'request'); |
| 1175 |
$ptodate = VikRequest::getString('todate', '', 'request'); |
| 1176 |
$pcodstru = VikRequest::getString('codstru', '', 'request'); |
| 1177 |
// manual values in filler |
| 1178 |
$pfiller = VikRequest::getString('filler', '', 'request', VIKREQUEST_ALLOWRAW); |
| 1179 |
$pfiller = !empty($pfiller) ? json_decode($pfiller, true) : array(); |
| 1180 |
$pfiller = !is_array($pfiller) ? array() : $pfiller; |
| 1181 |
|
| 1182 |
//Debug |
| 1183 |
if ($this->debug) { |
| 1184 |
$this->setError('<pre>'.print_r($pfiller, true).'</pre><br/>'); |
| 1185 |
return false; |
| 1186 |
} |
| 1187 |
// |
| 1188 |
$q = "SELECT SUM(`units`) FROM `#__vikbooking_rooms` WHERE `avail`= '1';"; |
| 1189 |
$this->dbo->setQuery($q); |
| 1190 |
$this->dbo->execute(); |
| 1191 |
$totalRooms= $this->dbo->loadResult(); |
| 1192 |
$records = array(); |
| 1193 |
$q = "SELECT SUM(`units`) AS `sommaunita`, SUM(`totpeople`) AS `numeropersone`, COUNT(*) AS `numerocamere` FROM `#__vikbooking_rooms` WHERE `avail`= '1';"; |
| 1194 |
$this->dbo->setQuery($q); |
| 1195 |
$this->dbo->execute(); |
| 1196 |
if ($this->dbo->getNumRows() > 0) { |
| 1197 |
$records = $this->dbo->loadAssocList(); |
| 1198 |
} |
| 1199 |
$totalBeds =(int) ($records[0]['sommaunita'] * ($records[0]['numeropersone']/$records[0]['numerocamere'])); |
| 1200 |
$pletti = VikRequest::getString('numletti', $totalBeds, 'request'); |
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
// pool of booking IDs to update their history |
| 1205 |
$booking_ids = array(); |
| 1206 |
// update the history for all bookings affected |
| 1207 |
foreach ($booking_ids as $bid) { |
| 1208 |
VikBooking::getBookingHistoryInstance()->setBid($bid)->store('RP', $this->reportName); |
| 1209 |
} |
| 1210 |
$xml= '<?xml version=\'1.0\' encoding=\'utf-8\'?> |
| 1211 |
<rm:c59 xmlns:rm="http://www.regione.liguria.it/turismo/rimovcli" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" idstruttura="'.$pcodstru.'" data="'.substr($pfromdate,6,4).'-'.substr($pfromdate,3,2).'-'.substr($pfromdate,0,2).'"> |
| 1212 |
<mensile softwaregestionale="VikBooking" numcameredisp="'.$totalRooms.'" numlettidisp="'.$pletti.'"/>'."\n"; |
| 1213 |
$numOccupiedrooms = 0; |
| 1214 |
|
| 1215 |
$date = new DateTime(); |
| 1216 |
$ts = $date->getTimestamp(); |
| 1217 |
|
| 1218 |
$map_country_codes_transfer = array_merge(array_unique($this->map_country_codes_transfer)); |
| 1219 |
sort($map_country_codes_transfer); |
| 1220 |
|
| 1221 |
$map_prov_codes = array_merge(array_unique($this->map_prov_codes)); |
| 1222 |
sort($map_prov_codes); |
| 1223 |
$arr = array( |
| 1224 |
'italia' => array(), |
| 1225 |
'estero' => array(), |
| 1226 |
'idres' => array() |
| 1227 |
|
| 1228 |
); |
| 1229 |
$arrivi = 0; |
| 1230 |
$partenze = 0; |
| 1231 |
$presenti = 0; |
| 1232 |
|
| 1233 |
foreach ($this->rows as $ind => $row) { |
| 1234 |
|
| 1235 |
$csvrow = array(); |
| 1236 |
$italia = 0; |
| 1237 |
$arrivi = 0; |
| 1238 |
$partenze = 0; |
| 1239 |
$presenti = 0; |
| 1240 |
$idswh = 0; |
| 1241 |
|
| 1242 |
foreach ($row as $field) { |
| 1243 |
$arrcode = 0; |
| 1244 |
|
| 1245 |
|
| 1246 |
if (isset($field['ignore_export'])) { |
| 1247 |
continue; |
| 1248 |
} |
| 1249 |
// check if a value for this field was filled in manually |
| 1250 |
if (is_array($pfiller) && isset($pfiller[$ind]) && isset($pfiller[$ind][$field['key']])) { |
| 1251 |
if (strlen($pfiller[$ind][$field['key']])) { |
| 1252 |
$field['value'] = $pfiller[$ind][$field['key']]; |
| 1253 |
} |
| 1254 |
} |
| 1255 |
|
| 1256 |
// values set to -1 are usually empty and should have been filled in manually |
| 1257 |
if ($field['value'] === -1) { |
| 1258 |
// we raise an error in this case without stopping the process |
| 1259 |
$field['value'] = 0; |
| 1260 |
VikError::raiseWarning('', 'La riga #'.$ind.' ha un valore vuoto che doveva essere riempito manualmente cliccando sul blocco in rosso. Il file potrebbe contenere valori invalidi per questa riga.'); |
| 1261 |
} |
| 1262 |
if($field['key'] == 'idswh'){ |
| 1263 |
$idswh = $field['value']; |
| 1264 |
} |
| 1265 |
if (isset($field['callback_export'])) { |
| 1266 |
$field['callback'] = $field['callback_export']; |
| 1267 |
} |
| 1268 |
$export_value = isset($field['callback']) && is_callable($field['callback']) ? $field['callback']($field['value']) : $field['value']; |
| 1269 |
|
| 1270 |
|
| 1271 |
if ($field['key'] == 'italia') { |
| 1272 |
if ($export_value == "1") { |
| 1273 |
$italia = 1; |
| 1274 |
} |
| 1275 |
} |
| 1276 |
|
| 1277 |
if ($field['key'] == 'tipo') { |
| 1278 |
$arrcode = 0; |
| 1279 |
|
| 1280 |
if (isset($this->map_country_codes_transfer[$export_value])) { |
| 1281 |
$arrcode = $this->map_country_codes_transfer[$export_value]; |
| 1282 |
} elseif (isset($this->map_prov_codes[$export_value])) { |
| 1283 |
$arrcode = $this->map_prov_codes[$export_value]; |
| 1284 |
} |
| 1285 |
|
| 1286 |
if ($italia == 1 && !isset($arr['italia'][$arrcode])) { |
| 1287 |
$arr['italia'][$arrcode] = array( |
| 1288 |
'partiti' => 0, |
| 1289 |
'arrivi' => 0, |
| 1290 |
'presenti' => 0, |
| 1291 |
); |
| 1292 |
} elseif(!isset($arr['estero'][$arrcode])) { |
| 1293 |
$arr['estero'][$arrcode] = array( |
| 1294 |
'partiti' => 0, |
| 1295 |
'arrivi' => 0, |
| 1296 |
'presenti' => 0, |
| 1297 |
); |
| 1298 |
} |
| 1299 |
foreach ($this->bookings as $gbook) { |
| 1300 |
$guestsnum = 0; |
| 1301 |
foreach ($gbook as $book) { |
| 1302 |
$guestsnum += $book['adults'] + $book['children']; |
| 1303 |
} |
| 1304 |
|
| 1305 |
if ($italia == 1) { |
| 1306 |
if ($idswh == $gbook[0]['id'] && $arrcode == $this->map_prov_codes[$export_value] && !in_array($gbook[0]['id'], $arr['idres'])) { |
| 1307 |
array_push($arr['idres'], $gbook[0]['id']); |
| 1308 |
if (date('Y-m-d',$gbook[0]['checkin']) == date('Y-m-d',$this->from_ts) || date('Y-m-d',$gbook[0]['checkin']) == date('Y-m-d',$this->to_ts)) { |
| 1309 |
$arr['italia'][$arrcode]['arrivi'] += $guestsnum; |
| 1310 |
$arr['italia'][$arrcode]['presenti'] += $guestsnum; |
| 1311 |
$arrivi = $arrivi + $guestsnum; |
| 1312 |
$presenti = $presenti + $guestsnum; |
| 1313 |
} elseif (date('Y-m-d',$gbook[0]['checkout']) == date('Y-m-d',$this->from_ts)|| date('Y-m-d',$gbook[0]['checkout']) == date('Y-m-d',$this->to_ts)) { |
| 1314 |
$arr['italia'][$arrcode]['partiti'] += $guestsnum; |
| 1315 |
$partenze = $partenze + $guestsnum; |
| 1316 |
} else { |
| 1317 |
$arr['italia'][$arrcode]['presenti'] += $guestsnum; |
| 1318 |
$presenti = $presenti + $guestsnum; |
| 1319 |
} |
| 1320 |
} |
| 1321 |
} else { |
| 1322 |
if ($idswh == $gbook[0]['id'] && $arrcode == $this->map_country_codes_transfer[$export_value] && !in_array($gbook[0]['id'], $arr['idres'])) { |
| 1323 |
array_push($arr['idres'], $gbook[0]['id']); |
| 1324 |
if (date('Y-m-d',$gbook[0]['checkin']) == date('Y-m-d',$this->from_ts) || date('Y-m-d',$gbook[0]['checkin']) == date('Y-m-d',$this->to_ts)) { |
| 1325 |
$arr['estero'][$arrcode]['arrivi'] += $guestsnum; |
| 1326 |
$arr['estero'][$arrcode]['presenti'] += $guestsnum; |
| 1327 |
$arrivi = $arrivi + $guestsnum; |
| 1328 |
$presenti = $presenti + $guestsnum; |
| 1329 |
} elseif (date('Y-m-d',$gbook[0]['checkout']) == date('Y-m-d',$this->from_ts)|| date('Y-m-d',$gbook[0]['checkout']) == date('Y-m-d',$this->to_ts)) { |
| 1330 |
$arr['estero'][$arrcode]['partiti'] += $guestsnum; |
| 1331 |
$partenze = $partenze + $guestsnum; |
| 1332 |
} else { |
| 1333 |
$arr['estero'][$arrcode]['presenti'] += $guestsnum; |
| 1334 |
$presenti = $presenti + $guestsnum; |
| 1335 |
} |
| 1336 |
} |
| 1337 |
} |
| 1338 |
} |
| 1339 |
} |
| 1340 |
if ($field['key'] == 'roomsbooked') { |
| 1341 |
if ($partenze == 0) { |
| 1342 |
if ($presenti != 0 ||$arrivi != 0) { |
| 1343 |
$numOccupiedrooms = $numOccupiedrooms + $export_value; |
| 1344 |
} |
| 1345 |
} |
| 1346 |
} |
| 1347 |
} |
| 1348 |
} |
| 1349 |
|
| 1350 |
$xml .= ' <giornaliero numcamereoccupate="'.$numOccupiedrooms.'">'."\n"; |
| 1351 |
|
| 1352 |
foreach ($arr['italia'] as $key => $value) { |
| 1353 |
if ($arr['italia'][$key]['presenti'] < 0) { |
| 1354 |
$arr['italia'][$key]['presenti'] = 0; |
| 1355 |
} |
| 1356 |
$xml .= ' <rigac59 nazione="i" residenza= "'.$key.'" partiti="'.$arr['italia'][$key]['partiti'].'" arrivati="'.$arr['italia'][$key]['arrivi'].'" presenti="'.$arr['italia'][$key]['presenti'].'"/> '."\n"; |
| 1357 |
} |
| 1358 |
|
| 1359 |
foreach ($arr['estero'] as $key => $value) { |
| 1360 |
if ($arr['estero'][$key]['presenti'] < 0) { |
| 1361 |
$arr['estero'][$key]['presenti'] = 0; |
| 1362 |
} |
| 1363 |
if (!array_sum($arr['estero'][$key])) { |
| 1364 |
// FIX: no values found so do not include the node |
| 1365 |
continue; |
| 1366 |
} |
| 1367 |
$xml .= ' <rigac59 nazione="e" residenza= "'.$key.'" partiti="'.$arr['estero'][$key]['partiti'].'" arrivati="'.$arr['estero'][$key]['arrivi'].'" presenti="'.$arr['estero'][$key]['presenti'].'"/> '."\n"; |
| 1368 |
} |
| 1369 |
|
| 1370 |
$xml .= '</giornaliero> '."\n"; |
| 1371 |
$xml .= '</rm:c59>'; |
| 1372 |
|
| 1373 |
// format XML document |
| 1374 |
$this->formatXML($xml); |
| 1375 |
|
| 1376 |
/** |
| 1377 |
* Custom export method supports a custom export handler, if previously set. |
| 1378 |
* |
| 1379 |
* @since 1.16.1 (J) - 1.6.1 (WP) |
| 1380 |
*/ |
| 1381 |
if ($this->hasExportHandler()) { |
| 1382 |
// write data onto the custom file handler |
| 1383 |
$fp = $this->getExportCSVHandler(); |
| 1384 |
fwrite($fp, $xml); |
| 1385 |
fclose($fp); |
| 1386 |
|
| 1387 |
return true; |
| 1388 |
} |
| 1389 |
|
| 1390 |
header('Content-Disposition: attachment; filename=' . $this->getExportCSVFileName()); |
| 1391 |
header('Content-type: text/xml'); |
| 1392 |
echo $xml; |
| 1393 |
|
| 1394 |
exit; |
| 1395 |
} |
| 1396 |
|
| 1397 |
/** |
| 1398 |
* Registers the name to give to the file being exported. |
| 1399 |
* |
| 1400 |
* @return void |
| 1401 |
* |
| 1402 |
* @since 1.16.1 (J) - 1.6.1 (WP) |
| 1403 |
*/ |
| 1404 |
protected function registerExportFileName() |
| 1405 |
{ |
| 1406 |
$pfromdate = VikRequest::getString('fromdate', '', 'request'); |
| 1407 |
$ptodate = VikRequest::getString('todate', '', 'request'); |
| 1408 |
|
| 1409 |
$this->setExportCSVFileName(str_replace(' ', '_', $this->reportName) . '-' . str_replace('/', '_', $pfromdate) . '-' . str_replace('/', '_', $ptodate) . '.xml'); |
| 1410 |
} |
| 1411 |
} |
| 1412 |
|