PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.7.2
VikBooking Hotel Booking Engine & PMS v1.7.2
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_trentino.php

istat_trentino.php in VikBooking Hotel Booking Engine & PMS 1.7.2, at admin/helpers/report/istat_trentino.php

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