PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.11
VikBooking Hotel Booking Engine & PMS v1.8.11
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.8.11, at admin/helpers/report/istat_veneto.php

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