PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.5
VikBooking Hotel Booking Engine & PMS v1.6.5
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_veneto.php

istat_veneto.php in VikBooking Hotel Booking Engine & PMS 1.6.5, at admin/helpers/report/istat_veneto.php

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