PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.6
VikBooking Hotel Booking Engine & PMS v1.6.6
1.8.16 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 All 37 releases
vikbooking / admin / helpers / report / istat_liguria.php

istat_liguria.php in VikBooking Hotel Booking Engine & PMS 1.6.6, at admin/helpers/report/istat_liguria.php

1,416 lines 42.8 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 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(document).ready(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;";
790 $this->dbo->setQuery($q);
791 $this->dbo->execute();
792 if ($this->dbo->getNumRows() > 0) {
793 $records = $this->dbo->loadAssocList();
794 }
795 if (!count($records)) {
796 $this->setError(JText::translate('VBOREPORTSERRNORESERV'));
797 return false;
798 }
799
800
801
802 //nest records with multiple rooms booked inside sub-array
803 $bookings = array();
804
805 foreach ($records as $v) {
806 if (!isset($bookings[$v['id']])) {
807 $bookings[$v['id']] = array();
808 }
809 // for bc, if the country is defined at booking level, set it also for the customer
810 if (empty($v['customer_country']) && !empty($v['country'])) {
811 $v['customer_country'] = $v['country'];
812 }
813 //calculate the from_ts and to_ts values for later comparison
814 $in_info = getdate($v['checkin']);
815 $out_info = getdate($v['checkout']);
816 $v['from_ts'] = mktime(0, 0, 0, $in_info['mon'], $in_info['mday'], $in_info['year']);
817 $v['to_ts'] = mktime(23, 59, 59, $out_info['mon'], ($out_info['mday'] - 1), $out_info['year']);
818 //
819 array_push($bookings[$v['id']], $v);
820 }
821 $this->bookings = $bookings;
822
823 //define the columns of the report
824 $this->cols = array(
825 //IdSWH (identificativo posizione - we use the booking ID)
826 array(
827 'key' => 'idswh',
828
829 'sortable' => 1,
830 'label' => 'Codice IDSWH',
831 'tip' => 'Questo è il codice identificativo della trasmissione del dato verso l\'ISTAT, ed è uguale all\'ID della prenotazione nel sistema.',
832 'export_name' => 'IdSWH'
833 ),
834 //Codice Struttura
835 array(
836 'key' => 'codstru',
837 'label' => 'Codice Struttura',
838 'tip' => 'Il codice della tua struttura che l\'Amministrazione competente ti ha assegnato. Il dato verrà comunicato all\'ISTAT.',
839 'export_name' => 'Codice'
840 ),
841 //customer
842 array(
843 'key' => 'customer',
844 'sortable' => 1,
845 'label' => 'Cliente',
846 'tip' => 'I nominativi dei clienti non verranno comunicati all\'ISTAT in quanto non necessari.',
847 'ignore_export' => 1
848 ),
849 //checkin
850 array(
851 'key' => 'checkin',
852 'attr' => array(
853 'class="center"'
854 ),
855 'sortable' => 1,
856 'label' => 'Arrivo'
857 ),
858 //checkout
859 array(
860 'key' => 'checkout',
861 'attr' => array(
862 'class="center"'
863 ),
864 'sortable' => 1,
865 'label' => 'Partenza'
866 ),
867 //italia
868 array(
869 'key' => 'italia',
870 'attr' => array(
871 'class="center"'
872 ),
873 'sortable' => 1,
874 'label' => 'Italia',
875 'tip' => 'Cittadino Italiano o Estero. Assicurati di fare la giusta selezione in caso di dati mancanti nel sistema (?) per certe prenotazioni.',
876 ),
877 //tipo (provenienza)
878 array(
879 'key' => 'tipo',
880 'attr' => array(
881 'class="center"'
882 ),
883 'sortable' => 1,
884 'label' => 'Provenienza',
885 'tip' => 'Codice di Provenienza del cliente. Assicurati di fare la giusta selezione in caso di dati mancanti nel sistema (?) per certe prenotazioni.',
886 'export_name' => 'Tipo'
887 ),
888 //quantità (numero di ospiti)
889 array(
890 'key' => 'guestsnum',
891 'attr' => array(
892 'class="center"'
893 ),
894 'sortable' => 1,
895 'label' => 'Numero Ospiti',
896 'tip' => 'Il numero di ospiti totali (adulti + bambini) per ogni prenotazione è un dato che verrà comunicato all\'ISTAT.',
897 'export_name' => 'Quantita'
898 ),
899 //occupazione (numero di camere prenotate)
900 array(
901 'key' => 'roomsbooked',
902 'attr' => array(
903 'class="center"'
904 ),
905 'sortable' => 1,
906 'label' => 'Occupazione',
907 'tip' => 'Questo valore indica il numero di camere occupate da ogni prenotazione, ed è un dato che verrà comunicato all\'ISTAT.',
908 ),
909 //camere (numero di camere totali)
910 array(
911 'key' => 'totrooms',
912 'attr' => array(
913 'class="center"'
914 ),
915 'sortable' => 1,
916 'label' => 'Camere',
917 '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.',
918 )
919
920 );
921
922 // total rooms units ("camere")
923 $total_rooms_units = $this->countRooms();
924
925 //loop over the bookings to build the rows of the report
926 foreach ($bookings as $gbook) {
927 $guestsnum = 0;
928 foreach ($gbook as $book) {
929 $guestsnum += $book['adults'] + $book['children'];
930 }
931 $country = '';
932 if (!empty($gbook[0]['country'])) {
933 $country = $gbook[0]['country'];
934 } elseif (!empty($gbook[0]['customer_country'])) {
935 $country = $gbook[0]['customer_country'];
936 }
937 $history_last = $gbook[0]['history_last'];
938 $tipo_provenienza = $this->guessTipoProvenienza($gbook[0]);
939 //push fields in the rows array as a new row
940 array_push($this->rows, array(
941 array(
942 'key' => 'idswh',
943 'callback' => function ($val) use ($history_last) {
944 if (!empty($history_last)) {
945 $tip = VikBooking::getVboApplication()->createPopover(array('title' => 'Data ultimo invio', 'content' => $history_last.'. Puoi comunque ritrasmettere questa informazione, e se cambia verrà aggiornata.'));
946 return '<a href="index.php?option=com_vikbooking&task=editorder&cid[]='.$val.'" target="_blank">'.$tip.' '.$val.'</a>';
947 }
948 return '<a href="index.php?option=com_vikbooking&task=editorder&cid[]='.$val.'" target="_blank"><i class="fa fa-external-link"></i> '.$val.'</a>';
949 },
950 'callback_export' => function ($val) {
951 return $val;
952 },
953 'value' => $gbook[0]['id']
954 ),
955 array(
956 'key' => 'codstru',
957 'value' => $pcodstru
958 ),
959 array(
960 'key' => 'customer',
961 'callback' => function ($val) use ($country) {
962 if (file_exists(VBO_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'countries'.DIRECTORY_SEPARATOR.$country.'.png')) {
963 return $val.'<img src="'.VBO_ADMIN_URI.'resources/countries/'.$country.'.png" title="'.$country.'" class="vbo-country-flag vbo-country-flag-left" />';
964 }
965 return $val;
966 },
967 'value' => $gbook[0]['first_name'] . ' ' . $gbook[0]['last_name'],
968 'ignore_export' => 1
969 ),
970 array(
971 'key' => 'checkin',
972 'attr' => array(
973 'class="center"'
974 ),
975 'callback' => function ($val) use ($df, $datesep) {
976 return date(str_replace("/", $datesep, $df), $val);
977 },
978 'callback_export' => function ($val) use ($df, $datesep) {
979 return date('Ymd', $val);
980 },
981 'value' => $gbook[0]['checkin']
982 ),
983 array(
984 'key' => 'checkout',
985 'attr' => array(
986 'class="center"'
987 ),
988 'callback' => function ($val) use ($df, $datesep) {
989 return date(str_replace("/", $datesep, $df), $val);
990 },
991 'callback_export' => function ($val) use ($df, $datesep) {
992 return date('Ymd', $val);
993 },
994 'value' => $gbook[0]['checkout']
995 ),
996 array(
997 'key' => 'italia',
998 'attr' => array(
999 'class="center'.(empty($gbook[0]['customer_country']) ? ' vbo-report-load-nazione' : '').'"'
1000 ),
1001 'callback' => function ($val) {
1002 if ($val < 0) {
1003 // empty country
1004 return '?';
1005 }
1006 if ($val == 1) {
1007 // Italian customer
1008 return 'Cittadino Italiano';
1009 }
1010 // non Italian customer
1011 return 'Cittadino Estero';
1012 },
1013 'callback_export' => function ($val) {
1014 return $val;
1015 },
1016 'value' => (empty($gbook[0]['customer_country']) ? -1 : (substr(strtoupper($gbook[0]['customer_country']), 0, 3) == 'ITA' ? 1 : 0))
1017 ),
1018 array(
1019 'key' => 'tipo',
1020 'attr' => array(
1021 'class="center'.($tipo_provenienza == -1 ? ' vbo-report-load-cittadinanza' : '').'"'
1022 ),
1023 'callback' => function ($val) {
1024 if ($val < 0) {
1025 // empty value
1026 return '?';
1027 }
1028 return $val;
1029 },
1030 'callback_export' => function ($val) {
1031 return $val;
1032 },
1033 'value' => $tipo_provenienza
1034 ),
1035 array(
1036 'key' => 'guestsnum',
1037 'attr' => array(
1038 'class="center"'
1039 ),
1040 'value' => $guestsnum
1041 ),
1042 array(
1043 'key' => 'roomsbooked',
1044 'attr' => array(
1045 'class="center"'
1046 ),
1047 'value' => count($gbook)
1048 ),
1049 array(
1050 'key' => 'totrooms',
1051 'attr' => array(
1052 'class="center"'
1053 ),
1054 'value' => $total_rooms_units
1055 )
1056
1057 ));
1058 }
1059
1060 //sort rows
1061 $this->sortRows($pkrsort, $pkrorder);
1062
1063 //the footer row will just print the amount of records to export
1064 array_push($this->footerRow, array(
1065 array(
1066 'attr' => array(
1067 'class="vbo-report-total"'
1068 ),
1069 'value' => '<h3>'.JText::translate('VBOREPORTSTOTALROW').'</h3>'
1070 ),
1071 array(
1072 'attr' => array(
1073 'colspan="'.(count($this->cols) - 1).'"'
1074 ),
1075 'value' => count($this->rows)
1076 )
1077 ));
1078
1079 //Debug
1080 if ($this->debug) {
1081 $this->setWarning('path to report file = '.urlencode(dirname(__FILE__)).'<br/>');
1082 $this->setWarning('$total_rooms_units = '.$total_rooms_units.'<br/>');
1083 $this->setWarning('$bookings:<pre>'.print_r($bookings, true).'</pre><br/>');
1084 }
1085 //
1086
1087 return true;
1088 }
1089
1090 /**
1091 * Attempts to guess the column 'tipo' (provenienza)
1092 * depending on the country and city given. For Italians,
1093 * the name of the region is returned (if any, given the city).
1094 * For foreigners, the country type is returned.
1095 *
1096 * @param array the booking record
1097 *
1098 * @return mixed string to use for the column 'tipo', -1 if empty.
1099 */
1100 private function guessTipoProvenienza($booking)
1101 {
1102 if (empty($booking['customer_country'])) {
1103 // unable to proceed when the country is missing (-1).
1104 return -1;
1105 }
1106
1107 // uppercase 3-char code of the country only
1108 $country3 = substr(strtoupper($booking['customer_country']), 0, 3);
1109
1110 if ($country3 == 'ITA') {
1111 // Italian customer
1112 if (!empty($booking['city'])) {
1113 foreach ($this->map_regioni_prov as $tipo => $cities) {
1114 foreach ($cities as $city) {
1115 if (stripos($city, $booking['city']) !== false) {
1116 // region was found
1117 return $city;
1118 }
1119 }
1120 }
1121 }
1122 // empty city or no city found in the map
1123 return -1;
1124 }
1125
1126 // foreigner customer
1127 if (isset($this->map_country_codes[$country3])) {
1128 // country name found for 'tipo' column
1129 return $this->map_country_codes[$country3];
1130 }
1131 // check the 'country_name' in 'other countries'
1132 if (!empty($booking['country_name'])) {
1133 foreach ($this->map_country_others as $tipo => $countries) {
1134 if (stripos($countries, $booking['country_name']) !== false) {
1135 // the name of the country taken from the 3-char code matches with an 'other country'. Guessing makes sense.
1136 return $tipo;
1137 }
1138 }
1139 }
1140
1141 // nothing found
1142 return -1;
1143 }
1144
1145 public function formatXML(&$xml)
1146 {
1147 if (!class_exists('DOMDocument')) {
1148 // we cannot format the XML because DOMDocument is missing
1149 return $xml;
1150 }
1151
1152 $dom = new DOMDocument;
1153 $dom->preserveWhiteSpace = false;
1154 $dom->loadXML($xml);
1155 $dom->formatOutput = true;
1156 $xml = $dom->saveXML();
1157
1158 return $xml;
1159 }
1160
1161 /**
1162 * Generates the report columns and rows, then it outputs a CSV file
1163 * for download. In case of errors, the process is not terminated (exit)
1164 * to let the View display the error message.
1165 * We use customExport() rather than exportCSV() only because we need a
1166 * different download button rather than the classic "Export as CSV".
1167 *
1168 * @param int $export_type the view will pass this argument to the method to call different types of export.
1169 *
1170 * @return mixed void on success with script termination, false otherwise.
1171 */
1172 public function customExport($export_type = 0)
1173 {
1174 if (!$this->getReportData()) {
1175 return false;
1176 }
1177
1178 $pfromdate = VikRequest::getString('fromdate', '', 'request');
1179 $ptodate = VikRequest::getString('todate', '', 'request');
1180 $pcodstru = VikRequest::getString('codstru', '', 'request');
1181 // manual values in filler
1182 $pfiller = VikRequest::getString('filler', '', 'request', VIKREQUEST_ALLOWRAW);
1183 $pfiller = !empty($pfiller) ? json_decode($pfiller, true) : array();
1184 $pfiller = !is_array($pfiller) ? array() : $pfiller;
1185
1186 //Debug
1187 if ($this->debug) {
1188 $this->setError('<pre>'.print_r($pfiller, true).'</pre><br/>');
1189 return false;
1190 }
1191 //
1192 $q = "SELECT SUM(`units`) FROM `#__vikbooking_rooms` WHERE `avail`= '1';";
1193 $this->dbo->setQuery($q);
1194 $this->dbo->execute();
1195 $totalRooms= $this->dbo->loadResult();
1196 $records = array();
1197 $q = "SELECT SUM(`units`) AS `sommaunita`, SUM(`totpeople`) AS `numeropersone`, COUNT(*) AS `numerocamere` FROM `#__vikbooking_rooms` WHERE `avail`= '1';";
1198 $this->dbo->setQuery($q);
1199 $this->dbo->execute();
1200 if ($this->dbo->getNumRows() > 0) {
1201 $records = $this->dbo->loadAssocList();
1202 }
1203 $totalBeds =(int) ($records[0]['sommaunita'] * ($records[0]['numeropersone']/$records[0]['numerocamere']));
1204 $pletti = VikRequest::getString('numletti', $totalBeds, 'request');
1205
1206
1207
1208 // pool of booking IDs to update their history
1209 $booking_ids = array();
1210 // update the history for all bookings affected
1211 foreach ($booking_ids as $bid) {
1212 VikBooking::getBookingHistoryInstance()->setBid($bid)->store('RP', $this->reportName);
1213 }
1214 $xml= '<?xml version=\'1.0\' encoding=\'utf-8\'?>
1215 <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).'">
1216 <mensile softwaregestionale="VikBooking" numcameredisp="'.$totalRooms.'" numlettidisp="'.$pletti.'"/>'."\n";
1217 $numOccupiedrooms = 0;
1218
1219 $date = new DateTime();
1220 $ts = $date->getTimestamp();
1221
1222 $map_country_codes_transfer = array_merge(array_unique($this->map_country_codes_transfer));
1223 sort($map_country_codes_transfer);
1224
1225 $map_prov_codes = array_merge(array_unique($this->map_prov_codes));
1226 sort($map_prov_codes);
1227 $arr = array(
1228 'italia' => array(),
1229 'estero' => array(),
1230 'idres' => array()
1231
1232 );
1233 $arrivi = 0;
1234 $partenze = 0;
1235 $presenti = 0;
1236
1237 foreach ($this->rows as $ind => $row) {
1238
1239 $csvrow = array();
1240 $italia = 0;
1241 $arrivi = 0;
1242 $partenze = 0;
1243 $presenti = 0;
1244 $idswh = 0;
1245
1246 foreach ($row as $field) {
1247 $arrcode = 0;
1248
1249
1250 if (isset($field['ignore_export'])) {
1251 continue;
1252 }
1253 // check if a value for this field was filled in manually
1254 if (is_array($pfiller) && isset($pfiller[$ind]) && isset($pfiller[$ind][$field['key']])) {
1255 if (strlen($pfiller[$ind][$field['key']])) {
1256 $field['value'] = $pfiller[$ind][$field['key']];
1257 }
1258 }
1259
1260 // values set to -1 are usually empty and should have been filled in manually
1261 if ($field['value'] === -1) {
1262 // we raise an error in this case without stopping the process
1263 $field['value'] = 0;
1264 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.');
1265 }
1266 if($field['key'] == 'idswh'){
1267 $idswh = $field['value'];
1268 }
1269 if (isset($field['callback_export'])) {
1270 $field['callback'] = $field['callback_export'];
1271 }
1272 $export_value = isset($field['callback']) && is_callable($field['callback']) ? $field['callback']($field['value']) : $field['value'];
1273
1274
1275 if ($field['key'] == 'italia') {
1276 if ($export_value == "1") {
1277 $italia = 1;
1278 }
1279 }
1280
1281 if ($field['key'] == 'tipo') {
1282 $arrcode = 0;
1283
1284 if (isset($this->map_country_codes_transfer[$export_value])) {
1285 $arrcode = $this->map_country_codes_transfer[$export_value];
1286 } elseif (isset($this->map_prov_codes[$export_value])) {
1287 $arrcode = $this->map_prov_codes[$export_value];
1288 }
1289
1290 if ($italia == 1 && !isset($arr['italia'][$arrcode])) {
1291 $arr['italia'][$arrcode] = array(
1292 'partiti' => 0,
1293 'arrivi' => 0,
1294 'presenti' => 0,
1295 );
1296 } elseif(!isset($arr['estero'][$arrcode])) {
1297 $arr['estero'][$arrcode] = array(
1298 'partiti' => 0,
1299 'arrivi' => 0,
1300 'presenti' => 0,
1301 );
1302 }
1303 foreach ($this->bookings as $gbook) {
1304 $guestsnum = 0;
1305 foreach ($gbook as $book) {
1306 $guestsnum += $book['adults'] + $book['children'];
1307 }
1308
1309 if ($italia == 1) {
1310 if ($idswh == $gbook[0]['id'] && $arrcode == $this->map_prov_codes[$export_value] && !in_array($gbook[0]['id'], $arr['idres'])) {
1311 array_push($arr['idres'], $gbook[0]['id']);
1312 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)) {
1313 $arr['italia'][$arrcode]['arrivi'] += $guestsnum;
1314 $arr['italia'][$arrcode]['presenti'] += $guestsnum;
1315 $arrivi = $arrivi + $guestsnum;
1316 $presenti = $presenti + $guestsnum;
1317 } 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)) {
1318 $arr['italia'][$arrcode]['partiti'] += $guestsnum;
1319 $partenze = $partenze + $guestsnum;
1320 } else {
1321 $arr['italia'][$arrcode]['presenti'] += $guestsnum;
1322 $presenti = $presenti + $guestsnum;
1323 }
1324 }
1325 } else {
1326 if ($idswh == $gbook[0]['id'] && $arrcode == $this->map_country_codes_transfer[$export_value] && !in_array($gbook[0]['id'], $arr['idres'])) {
1327 array_push($arr['idres'], $gbook[0]['id']);
1328 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)) {
1329 $arr['estero'][$arrcode]['arrivi'] += $guestsnum;
1330 $arr['estero'][$arrcode]['presenti'] += $guestsnum;
1331 $arrivi = $arrivi + $guestsnum;
1332 $presenti = $presenti + $guestsnum;
1333 } 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)) {
1334 $arr['estero'][$arrcode]['partiti'] += $guestsnum;
1335 $partenze = $partenze + $guestsnum;
1336 } else {
1337 $arr['estero'][$arrcode]['presenti'] += $guestsnum;
1338 $presenti = $presenti + $guestsnum;
1339 }
1340 }
1341 }
1342 }
1343 }
1344 if ($field['key'] == 'roomsbooked') {
1345 if ($partenze == 0) {
1346 if ($presenti != 0 ||$arrivi != 0) {
1347 $numOccupiedrooms = $numOccupiedrooms + $export_value;
1348 }
1349 }
1350 }
1351 }
1352 }
1353
1354 $xml .= ' <giornaliero numcamereoccupate="'.$numOccupiedrooms.'">'."\n";
1355
1356 foreach ($arr['italia'] as $key => $value) {
1357 if ($arr['italia'][$key]['presenti'] < 0) {
1358 $arr['italia'][$key]['presenti'] = 0;
1359 }
1360 $xml .= ' <rigac59 nazione="i" residenza= "'.$key.'" partiti="'.$arr['italia'][$key]['partiti'].'" arrivati="'.$arr['italia'][$key]['arrivi'].'" presenti="'.$arr['italia'][$key]['presenti'].'"/> '."\n";
1361 }
1362
1363 foreach ($arr['estero'] as $key => $value) {
1364 if ($arr['estero'][$key]['presenti'] < 0) {
1365 $arr['estero'][$key]['presenti'] = 0;
1366 }
1367 if (!array_sum($arr['estero'][$key])) {
1368 // FIX: no values found so do not include the node
1369 continue;
1370 }
1371 $xml .= ' <rigac59 nazione="e" residenza= "'.$key.'" partiti="'.$arr['estero'][$key]['partiti'].'" arrivati="'.$arr['estero'][$key]['arrivi'].'" presenti="'.$arr['estero'][$key]['presenti'].'"/> '."\n";
1372 }
1373
1374 $xml .= '</giornaliero> '."\n";
1375 $xml .= '</rm:c59>';
1376
1377 // format XML document
1378 $this->formatXML($xml);
1379
1380 /**
1381 * Custom export method supports a custom export handler, if previously set.
1382 *
1383 * @since 1.16.1 (J) - 1.6.1 (WP)
1384 */
1385 if ($this->hasExportHandler()) {
1386 // write data onto the custom file handler
1387 $fp = $this->getExportCSVHandler();
1388 fwrite($fp, $xml);
1389 fclose($fp);
1390
1391 return true;
1392 }
1393
1394 header('Content-Disposition: attachment; filename=' . $this->getExportCSVFileName());
1395 header('Content-type: text/xml');
1396 echo $xml;
1397
1398 exit;
1399 }
1400
1401 /**
1402 * Registers the name to give to the file being exported.
1403 *
1404 * @return void
1405 *
1406 * @since 1.16.1 (J) - 1.6.1 (WP)
1407 */
1408 protected function registerExportFileName()
1409 {
1410 $pfromdate = VikRequest::getString('fromdate', '', 'request');
1411 $ptodate = VikRequest::getString('todate', '', 'request');
1412
1413 $this->setExportCSVFileName(str_replace(' ', '_', $this->reportName) . '-' . str_replace('/', '_', $pfromdate) . '-' . str_replace('/', '_', $ptodate) . '.xml');
1414 }
1415 }
1416