| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking |
| 4 |
* @subpackage com_vikbooking |
| 5 |
* @author E4J srl |
| 6 |
* @copyright Copyright (C) 2020 E4J srl. 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 VikBookingReportEsGuardiaCivil extends VikBookingReport |
| 14 |
{ |
| 15 |
/** |
| 16 |
* Property 'defaultKeySort' is used by the View that renders the report. |
| 17 |
*/ |
| 18 |
public $defaultKeySort = 'idbooking'; |
| 19 |
/** |
| 20 |
* Property 'defaultKeyOrder' is used by the View that renders the report. |
| 21 |
*/ |
| 22 |
public $defaultKeyOrder = 'ASC'; |
| 23 |
/** |
| 24 |
* Property 'customExport' is used by the View to display custom export buttons. |
| 25 |
*/ |
| 26 |
public $customExport = ''; |
| 27 |
/** |
| 28 |
* Debug mode is activated by passing the value 'e4j_debug' > 0 |
| 29 |
*/ |
| 30 |
private $debug; |
| 31 |
|
| 32 |
/** |
| 33 |
* Other private vars of this sub-class. |
| 34 |
*/ |
| 35 |
private $nazioni = []; |
| 36 |
private $documenti = []; |
| 37 |
|
| 38 |
/** |
| 39 |
* Class constructor should define the name of the report and |
| 40 |
* other vars. Call the parent constructor to define the DB object. |
| 41 |
*/ |
| 42 |
function __construct() |
| 43 |
{ |
| 44 |
$this->reportFile = basename(__FILE__, '.php'); |
| 45 |
$this->reportName = "Guardia Civil"; |
| 46 |
$this->reportFilters = []; |
| 47 |
|
| 48 |
$this->cols = []; |
| 49 |
$this->rows = []; |
| 50 |
$this->footerRow = []; |
| 51 |
|
| 52 |
$this->debug = (VikRequest::getInt('e4j_debug', 0, 'request') > 0); |
| 53 |
|
| 54 |
$this->registerExportFileName(); |
| 55 |
|
| 56 |
parent::__construct(); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Returns the name of this report. |
| 61 |
* |
| 62 |
* @return string |
| 63 |
*/ |
| 64 |
public function getName() |
| 65 |
{ |
| 66 |
return $this->reportName; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Returns the name of this file without .php. |
| 71 |
* |
| 72 |
* @return string |
| 73 |
*/ |
| 74 |
public function getFileName() |
| 75 |
{ |
| 76 |
return $this->reportFile; |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Returns the filters of this report. |
| 81 |
* |
| 82 |
* @return array |
| 83 |
*/ |
| 84 |
public function getFilters() |
| 85 |
{ |
| 86 |
if (count($this->reportFilters)) { |
| 87 |
//do not run this method twice, as it could load JS and CSS files. |
| 88 |
return $this->reportFilters; |
| 89 |
} |
| 90 |
|
| 91 |
//get VBO Application Object |
| 92 |
$vbo_app = VikBooking::getVboApplication(); |
| 93 |
|
| 94 |
//load the jQuery UI Datepicker |
| 95 |
$this->loadDatePicker(); |
| 96 |
|
| 97 |
//custom export button |
| 98 |
$this->customExport = '<a href="JavaScript: void(0);" onclick="vboDownloadSchedaGuardiaCivil();" class="vbcsvexport"><i class="'.VikBookingIcons::i('download').'"></i> <span>Download File</span></a>'; |
| 99 |
|
| 100 |
//build the hidden values for the selection of Comuni & Province. |
| 101 |
$this->nazioni = $this->loadNazioni(); |
| 102 |
$this->documenti = $this->loadDocumenti(); |
| 103 |
$hidden_vals = '<div id="vbo-report-guardiacivil-hidden" style="display: none;">'; |
| 104 |
|
| 105 |
//Nazioni |
| 106 |
$hidden_vals .= ' <div id="vbo-report-guardiacivil-nazione" class="vbo-report-guardiacivil-selcont" style="display: none;">'; |
| 107 |
$hidden_vals .= ' <select id="choose-nazione" onchange="vboReportChosenNazione(this);"><option value=""></option>'; |
| 108 |
if (count($this->nazioni)) { |
| 109 |
foreach ($this->nazioni as $code => $nazione) { |
| 110 |
$hidden_vals .= ' <option value="' . $nazione['name'] . '" data-threecode="' . $nazione['three_code'] . '">' . $nazione['name'] . '</option>'."\n"; |
| 111 |
} |
| 112 |
} |
| 113 |
$hidden_vals .= ' </select>'; |
| 114 |
$hidden_vals .= ' </div>'; |
| 115 |
|
| 116 |
//Documenti |
| 117 |
$hidden_vals .= ' <div id="vbo-report-guardiacivil-doctype" class="vbo-report-guardiacivil-selcont" style="display: none;">'; |
| 118 |
$hidden_vals .= ' <select id="choose-documento" onchange="vboReportChosenDocumento(this);"><option value=""></option>'; |
| 119 |
if (count($this->documenti)) { |
| 120 |
foreach ($this->documenti as $code => $documento) { |
| 121 |
$hidden_vals .= ' <option value="'.$code.'">'.$documento.'</option>'."\n"; |
| 122 |
} |
| 123 |
} |
| 124 |
$hidden_vals .= ' </select>'; |
| 125 |
$hidden_vals .= ' </div>'; |
| 126 |
|
| 127 |
//Sesso |
| 128 |
$hidden_vals .= ' <div id="vbo-report-guardiacivil-sesso" class="vbo-report-guardiacivil-selcont" style="display: none;">'; |
| 129 |
$hidden_vals .= ' <select id="choose-sesso" onchange="vboReportChosenSesso(this);"><option value=""></option>'; |
| 130 |
$sessos = array( |
| 131 |
1 => 'M', |
| 132 |
2 => 'F' |
| 133 |
); |
| 134 |
foreach ($sessos as $code => $ses) { |
| 135 |
$hidden_vals .= ' <option value="'.$code.'">'.$ses.'</option>'."\n"; |
| 136 |
} |
| 137 |
$hidden_vals .= ' </select>'; |
| 138 |
$hidden_vals .= ' </div>'; |
| 139 |
|
| 140 |
//Numero Documento |
| 141 |
$hidden_vals .= ' <div id="vbo-report-guardiacivil-docnum" class="vbo-report-guardiacivil-selcont" style="display: none;">'; |
| 142 |
$hidden_vals .= ' <input type="text" size="40" id="choose-docnum" placeholder="Número del Documento..." value="" /><br/>'; |
| 143 |
$hidden_vals .= ' <button type="button" class="btn" onclick="vboReportChosenDocnum(document.getElementById(\'choose-docnum\').value);">'.JText::translate('VBAPPLY').'</button>'; |
| 144 |
$hidden_vals .= ' </div>'; |
| 145 |
|
| 146 |
//Data di Nascita |
| 147 |
$hidden_vals .= ' <div id="vbo-report-guardiacivil-dbirth" class="vbo-report-guardiacivil-selcont" style="display: none;">'; |
| 148 |
$hidden_vals .= ' <input type="text" size="40" id="choose-dbirth" placeholder="'.JText::translate('VBCUSTOMERBDATE').'" value="" /><br/>'; |
| 149 |
$hidden_vals .= ' <button type="button" class="btn" onclick="vboReportChosenDbirth(document.getElementById(\'choose-dbirth\').value);">'.JText::translate('VBAPPLY').'</button>'; |
| 150 |
$hidden_vals .= ' </div>'; |
| 151 |
|
| 152 |
//Data di Emissione documento |
| 153 |
$hidden_vals .= ' <div id="vbo-report-guardiacivil-docissuedt" class="vbo-report-guardiacivil-selcont" style="display: none;">'; |
| 154 |
$hidden_vals .= ' <input type="text" size="40" id="choose-docissuedt" placeholder="Fecha de expedición del documento" value="" /><br/>'; |
| 155 |
$hidden_vals .= ' <button type="button" class="btn" onclick="vboReportChosenDocissuedt(document.getElementById(\'choose-docissuedt\').value);">'.JText::translate('VBAPPLY').'</button>'; |
| 156 |
$hidden_vals .= ' </div>'; |
| 157 |
|
| 158 |
$hidden_vals .= '</div>'; |
| 159 |
|
| 160 |
//From Date Filter (plus hidden values for the dropdown menus of custom values) |
| 161 |
$filter_opt = array( |
| 162 |
'label' => '<label for="fromdate">'.JText::translate('VBOREPORTSDATEFROM').'</label>', |
| 163 |
'html' => '<input type="text" id="fromdate" name="fromdate" value="" class="vbo-report-datepicker vbo-report-datepicker-from" />'.$hidden_vals, |
| 164 |
'type' => 'calendar', |
| 165 |
'name' => 'fromdate' |
| 166 |
); |
| 167 |
array_push($this->reportFilters, $filter_opt); |
| 168 |
|
| 169 |
//To Date Filter |
| 170 |
$filter_opt = array( |
| 171 |
'label' => '<label for="todate">'.JText::translate('VBOREPORTSDATETO').'</label>', |
| 172 |
'html' => '<input type="text" id="todate" name="todate" value="" class="vbo-report-datepicker vbo-report-datepicker-to" />', |
| 173 |
'type' => 'calendar', |
| 174 |
'name' => 'todate' |
| 175 |
); |
| 176 |
array_push($this->reportFilters, $filter_opt); |
| 177 |
|
| 178 |
// Filtro Nome Hotel |
| 179 |
$photelname = VikRequest::getString('hotelname', '', 'request'); |
| 180 |
$filter_opt = array( |
| 181 |
'label' => '<label for="hotelname">Nombre del hotel</label>', |
| 182 |
'html' => '<input type="text" id="hotelname" name="hotelname" value="'.$photelname.'" size="10" />', |
| 183 |
'type' => 'text', |
| 184 |
'name' => 'hotelname' |
| 185 |
); |
| 186 |
array_push($this->reportFilters, $filter_opt); |
| 187 |
|
| 188 |
// Filtro Codice Hotel |
| 189 |
$photelcode = VikRequest::getString('hotelcode', '', 'request'); |
| 190 |
$filter_opt = array( |
| 191 |
'label' => '<label for="hotelcode">Código del hotel</label>', |
| 192 |
'html' => '<input type="text" id="hotelcode" name="hotelcode" value="'.$photelcode.'" size="10" />', |
| 193 |
'type' => 'text', |
| 194 |
'name' => 'hotelcode' |
| 195 |
); |
| 196 |
array_push($this->reportFilters, $filter_opt); |
| 197 |
|
| 198 |
// append button to save the data when creating manual values |
| 199 |
$filter_opt = array( |
| 200 |
'label' => '<label class="vbo-report-guardiacivil-manualsave" style="display: none;">Data</label>', |
| 201 |
'html' => '<button type="button" class="btn vbo-config-btn vbo-report-guardiacivil-manualsave" style="display: none;" onclick="vboGuardiacivilSaveData();"><i class="' . VikBookingIcons::i('save') . '"></i> ' . JText::translate('VBSAVE') . '</button>', |
| 202 |
); |
| 203 |
array_push($this->reportFilters, $filter_opt); |
| 204 |
|
| 205 |
//jQuery code for the datepicker calendars, select2 and triggers for the dropdown menus |
| 206 |
$pfromdate = VikRequest::getString('fromdate', '', 'request'); |
| 207 |
$ptodate = VikRequest::getString('todate', '', 'request'); |
| 208 |
$js = 'var reportActiveCell = null, reportObj = {}; |
| 209 |
var vbo_guardiacivil_ajax_uri = "' . VikBooking::ajaxUrl('index.php?option=com_vikbooking&task=invoke_report&report=' . $this->reportFile) . '"; |
| 210 |
var vbo_guardiacivil_save_icn = "' . VikBookingIcons::i('save') . '"; |
| 211 |
var vbo_guardiacivil_saving_icn = "' . VikBookingIcons::i('circle-notch', 'fa-spin fa-fw') . '"; |
| 212 |
var vbo_guardiacivil_saved_icn = "' . VikBookingIcons::i('check-circle') . '"; |
| 213 |
jQuery(function() { |
| 214 |
//prepare main filters |
| 215 |
jQuery(".vbo-report-datepicker:input").datepicker({ |
| 216 |
maxDate: 0, |
| 217 |
dateFormat: "'.$this->getDateFormat('jui').'", |
| 218 |
onSelect: vboReportCheckDates |
| 219 |
}); |
| 220 |
'.(!empty($pfromdate) ? 'jQuery(".vbo-report-datepicker-from").datepicker("setDate", "'.$pfromdate.'");' : '').' |
| 221 |
'.(!empty($ptodate) ? 'jQuery(".vbo-report-datepicker-to").datepicker("setDate", "'.$ptodate.'");' : '').' |
| 222 |
//prepare filler helpers |
| 223 |
jQuery("#vbo-report-guardiacivil-hidden").children().detach().appendTo(".vbo-info-overlay-report"); |
| 224 |
jQuery("#choose-nazione").select2({placeholder: "- Selecciona una Nacion -", width: "200px"}); |
| 225 |
jQuery("#choose-documento").select2({placeholder: "- Selecciona un Documento -", width: "200px"}); |
| 226 |
jQuery("#choose-sesso").select2({placeholder: "- Selecciona Sexo -", width: "200px"}); |
| 227 |
jQuery("#choose-dbirth, #choose-docissuedt").datepicker({ |
| 228 |
maxDate: 0, |
| 229 |
dateFormat: "dd/mm/yy", |
| 230 |
changeMonth: true, |
| 231 |
changeYear: true, |
| 232 |
yearRange: "'.(date('Y') - 100).':'.date('Y').'" |
| 233 |
}); |
| 234 |
// click events |
| 235 |
jQuery(".vbo-report-load-nazione, .vbo-report-load-cittadinanza").click(function() { |
| 236 |
reportActiveCell = this; |
| 237 |
jQuery(".vbo-report-guardiacivil-selcont").hide(); |
| 238 |
jQuery("#vbo-report-guardiacivil-nazione").show(); |
| 239 |
vboShowOverlay(); |
| 240 |
}); |
| 241 |
jQuery(".vbo-report-load-doctype").click(function() { |
| 242 |
reportActiveCell = this; |
| 243 |
jQuery(".vbo-report-guardiacivil-selcont").hide(); |
| 244 |
jQuery("#vbo-report-guardiacivil-doctype").show(); |
| 245 |
vboShowOverlay(); |
| 246 |
}); |
| 247 |
jQuery(".vbo-report-load-docplace").click(function() { |
| 248 |
reportActiveCell = this; |
| 249 |
jQuery(".vbo-report-guardiacivil-selcont").hide(); |
| 250 |
jQuery("#vbo-report-guardiacivil-nazione").show(); |
| 251 |
vboShowOverlay(); |
| 252 |
}); |
| 253 |
jQuery(".vbo-report-load-sesso").click(function() { |
| 254 |
reportActiveCell = this; |
| 255 |
jQuery(".vbo-report-guardiacivil-selcont").hide(); |
| 256 |
jQuery("#vbo-report-guardiacivil-sesso").show(); |
| 257 |
vboShowOverlay(); |
| 258 |
}); |
| 259 |
jQuery(".vbo-report-load-docnum").click(function() { |
| 260 |
reportActiveCell = this; |
| 261 |
jQuery(".vbo-report-guardiacivil-selcont").hide(); |
| 262 |
jQuery("#vbo-report-guardiacivil-docnum").show(); |
| 263 |
vboShowOverlay(); |
| 264 |
setTimeout(function(){jQuery("#choose-docnum").focus();}, 500); |
| 265 |
}); |
| 266 |
jQuery(".vbo-report-load-dbirth").click(function() { |
| 267 |
reportActiveCell = this; |
| 268 |
jQuery(".vbo-report-guardiacivil-selcont").hide(); |
| 269 |
jQuery("#vbo-report-guardiacivil-dbirth").show(); |
| 270 |
vboShowOverlay(); |
| 271 |
}); |
| 272 |
jQuery(".vbo-report-load-docissuedt").click(function() { |
| 273 |
reportActiveCell = this; |
| 274 |
jQuery(".vbo-report-guardiacivil-selcont").hide(); |
| 275 |
jQuery("#vbo-report-guardiacivil-docissuedt").show(); |
| 276 |
vboShowOverlay(); |
| 277 |
}); |
| 278 |
}); |
| 279 |
function vboReportCheckDates(selectedDate, inst) { |
| 280 |
if (selectedDate === null || inst === null) { |
| 281 |
return; |
| 282 |
} |
| 283 |
var cur_from_date = jQuery(this).val(); |
| 284 |
if (jQuery(this).hasClass("vbo-report-datepicker-from") && cur_from_date.length) { |
| 285 |
var nowstart = jQuery(this).datepicker("getDate"); |
| 286 |
var nowstartdate = new Date(nowstart.getTime()); |
| 287 |
jQuery(".vbo-report-datepicker-to").datepicker("option", {minDate: nowstartdate}); |
| 288 |
} |
| 289 |
} |
| 290 |
function vboReportChosenNazione(naz) { |
| 291 |
var c_code = naz.value; |
| 292 |
var c_val = naz.options[naz.selectedIndex].text; |
| 293 |
var c_threecode = jQuery(naz).find("option:selected").attr("data-threecode"); |
| 294 |
if (reportActiveCell !== null) { |
| 295 |
var nowindex = jQuery(".vbo-reports-output table tbody tr").index(jQuery(reportActiveCell).closest("tr")); |
| 296 |
if (isNaN(nowindex) || parseInt(nowindex) < 0) { |
| 297 |
alert("Error, cannot find element to update."); |
| 298 |
} else { |
| 299 |
var rep_act_cell = jQuery(reportActiveCell); |
| 300 |
rep_act_cell.addClass("vbo-report-load-elem-filled").find("span").text(c_val); |
| 301 |
var rep_guest_bid = rep_act_cell.closest("tr").find("a[data-bid]").attr("data-bid"); |
| 302 |
if (!reportObj.hasOwnProperty(nowindex)) { |
| 303 |
reportObj[nowindex] = { |
| 304 |
bid: rep_guest_bid, |
| 305 |
bid_index: jQuery(".vbo-reports-output table tbody tr").index(jQuery("a[data-bid=\"" + rep_guest_bid + "\"]").first().closest("tr")) |
| 306 |
}; |
| 307 |
} |
| 308 |
if (jQuery(reportActiveCell).hasClass("vbo-report-load-nazione")) { |
| 309 |
reportObj[nowindex].stabirth = c_code; |
| 310 |
} else if (jQuery(reportActiveCell).hasClass("vbo-report-load-docplace")) { |
| 311 |
reportObj[nowindex].docplace = c_code; |
| 312 |
} else { |
| 313 |
reportObj[nowindex].country = c_code; |
| 314 |
reportObj[nowindex].country_code = c_threecode; |
| 315 |
} |
| 316 |
} |
| 317 |
} |
| 318 |
reportActiveCell = null; |
| 319 |
vboHideOverlay(); |
| 320 |
jQuery("#choose-nazione").val("").select2("data", null, false); |
| 321 |
jQuery(".vbo-report-guardiacivil-manualsave").show(); |
| 322 |
} |
| 323 |
function vboReportChosenDocumento(doctype) { |
| 324 |
var c_code = doctype.value; |
| 325 |
var c_val = doctype.options[doctype.selectedIndex].text; |
| 326 |
if (reportActiveCell !== null) { |
| 327 |
var nowindex = jQuery(".vbo-reports-output table tbody tr").index(jQuery(reportActiveCell).closest("tr")); |
| 328 |
if (isNaN(nowindex) || parseInt(nowindex) < 0) { |
| 329 |
alert("Error, cannot find element to update."); |
| 330 |
} else { |
| 331 |
var rep_act_cell = jQuery(reportActiveCell); |
| 332 |
rep_act_cell.addClass("vbo-report-load-elem-filled").find("span").text(c_val); |
| 333 |
var rep_guest_bid = rep_act_cell.closest("tr").find("a[data-bid]").attr("data-bid"); |
| 334 |
if (!reportObj.hasOwnProperty(nowindex)) { |
| 335 |
reportObj[nowindex] = { |
| 336 |
bid: rep_guest_bid, |
| 337 |
bid_index: jQuery(".vbo-reports-output table tbody tr").index(jQuery("a[data-bid=\"" + rep_guest_bid + "\"]").first().closest("tr")) |
| 338 |
}; |
| 339 |
} |
| 340 |
reportObj[nowindex].doctype = c_code; |
| 341 |
} |
| 342 |
} |
| 343 |
reportActiveCell = null; |
| 344 |
vboHideOverlay(); |
| 345 |
jQuery("#choose-documento").val("").select2("data", null, false); |
| 346 |
jQuery(".vbo-report-guardiacivil-manualsave").show(); |
| 347 |
} |
| 348 |
function vboReportChosenSesso(sesso) { |
| 349 |
var c_code = sesso.value; |
| 350 |
var c_val = sesso.options[sesso.selectedIndex].text; |
| 351 |
if (reportActiveCell !== null) { |
| 352 |
var nowindex = jQuery(".vbo-reports-output table tbody tr").index(jQuery(reportActiveCell).closest("tr")); |
| 353 |
if (isNaN(nowindex) || parseInt(nowindex) < 0) { |
| 354 |
alert("Error, cannot find element to update."); |
| 355 |
} else { |
| 356 |
var rep_act_cell = jQuery(reportActiveCell); |
| 357 |
rep_act_cell.addClass("vbo-report-load-elem-filled").find("span").text(c_val); |
| 358 |
var rep_guest_bid = rep_act_cell.closest("tr").find("a[data-bid]").attr("data-bid"); |
| 359 |
if (!reportObj.hasOwnProperty(nowindex)) { |
| 360 |
reportObj[nowindex] = { |
| 361 |
bid: rep_guest_bid, |
| 362 |
bid_index: jQuery(".vbo-reports-output table tbody tr").index(jQuery("a[data-bid=\"" + rep_guest_bid + "\"]").first().closest("tr")) |
| 363 |
}; |
| 364 |
} |
| 365 |
reportObj[nowindex].gender = c_code; |
| 366 |
} |
| 367 |
} |
| 368 |
reportActiveCell = null; |
| 369 |
vboHideOverlay(); |
| 370 |
jQuery("#choose-sesso").val("").select2("data", null, false); |
| 371 |
jQuery(".vbo-report-guardiacivil-manualsave").show(); |
| 372 |
} |
| 373 |
function vboReportChosenDocnum(val) { |
| 374 |
var c_code = val, c_val = val; |
| 375 |
if (reportActiveCell !== null) { |
| 376 |
var nowindex = jQuery(".vbo-reports-output table tbody tr").index(jQuery(reportActiveCell).closest("tr")); |
| 377 |
if (isNaN(nowindex) || parseInt(nowindex) < 0) { |
| 378 |
alert("Error, cannot find element to update."); |
| 379 |
} else { |
| 380 |
var rep_act_cell = jQuery(reportActiveCell); |
| 381 |
rep_act_cell.addClass("vbo-report-load-elem-filled").find("span").text(c_val); |
| 382 |
var rep_guest_bid = rep_act_cell.closest("tr").find("a[data-bid]").attr("data-bid"); |
| 383 |
if (!reportObj.hasOwnProperty(nowindex)) { |
| 384 |
reportObj[nowindex] = { |
| 385 |
bid: rep_guest_bid, |
| 386 |
bid_index: jQuery(".vbo-reports-output table tbody tr").index(jQuery("a[data-bid=\"" + rep_guest_bid + "\"]").first().closest("tr")) |
| 387 |
}; |
| 388 |
} |
| 389 |
reportObj[nowindex].docnum = c_code; |
| 390 |
} |
| 391 |
} |
| 392 |
reportActiveCell = null; |
| 393 |
vboHideOverlay(); |
| 394 |
jQuery("#choose-docnum").val(""); |
| 395 |
jQuery(".vbo-report-guardiacivil-manualsave").show(); |
| 396 |
} |
| 397 |
function vboReportChosenDbirth(val) { |
| 398 |
var c_code = val, c_val = val; |
| 399 |
if (reportActiveCell !== null) { |
| 400 |
var nowindex = jQuery(".vbo-reports-output table tbody tr").index(jQuery(reportActiveCell).closest("tr")); |
| 401 |
if (isNaN(nowindex) || parseInt(nowindex) < 0) { |
| 402 |
alert("Error, cannot find element to update."); |
| 403 |
} else { |
| 404 |
var rep_act_cell = jQuery(reportActiveCell); |
| 405 |
rep_act_cell.addClass("vbo-report-load-elem-filled").find("span").text(c_val); |
| 406 |
var rep_guest_bid = rep_act_cell.closest("tr").find("a[data-bid]").attr("data-bid"); |
| 407 |
if (!reportObj.hasOwnProperty(nowindex)) { |
| 408 |
reportObj[nowindex] = { |
| 409 |
bid: rep_guest_bid, |
| 410 |
bid_index: jQuery(".vbo-reports-output table tbody tr").index(jQuery("a[data-bid=\"" + rep_guest_bid + "\"]").first().closest("tr")) |
| 411 |
}; |
| 412 |
} |
| 413 |
reportObj[nowindex]["date_birth"] = c_code; |
| 414 |
} |
| 415 |
} |
| 416 |
reportActiveCell = null; |
| 417 |
vboHideOverlay(); |
| 418 |
jQuery("#choose-dbirth").val(""); |
| 419 |
jQuery(".vbo-report-guardiacivil-manualsave").show(); |
| 420 |
} |
| 421 |
function vboReportChosenDocissuedt(val) { |
| 422 |
var c_code = val, c_val = val; |
| 423 |
if (reportActiveCell !== null) { |
| 424 |
var nowindex = jQuery(".vbo-reports-output table tbody tr").index(jQuery(reportActiveCell).closest("tr")); |
| 425 |
if (isNaN(nowindex) || parseInt(nowindex) < 0) { |
| 426 |
alert("Error, cannot find element to update."); |
| 427 |
} else { |
| 428 |
var rep_act_cell = jQuery(reportActiveCell); |
| 429 |
rep_act_cell.addClass("vbo-report-load-elem-filled").find("span").text(c_val); |
| 430 |
var rep_guest_bid = rep_act_cell.closest("tr").find("a[data-bid]").attr("data-bid"); |
| 431 |
if (!reportObj.hasOwnProperty(nowindex)) { |
| 432 |
reportObj[nowindex] = { |
| 433 |
bid: rep_guest_bid, |
| 434 |
bid_index: jQuery(".vbo-reports-output table tbody tr").index(jQuery("a[data-bid=\"" + rep_guest_bid + "\"]").first().closest("tr")) |
| 435 |
}; |
| 436 |
} |
| 437 |
reportObj[nowindex].docissuedt = c_code; |
| 438 |
} |
| 439 |
} |
| 440 |
reportActiveCell = null; |
| 441 |
vboHideOverlay(); |
| 442 |
jQuery("#choose-docissuedt").val(""); |
| 443 |
jQuery(".vbo-report-guardiacivil-manualsave").show(); |
| 444 |
} |
| 445 |
//download function |
| 446 |
function vboDownloadSchedaGuardiaCivil() { |
| 447 |
if (!confirm("¿Está seguro de haber ingresado todos los datos requeridos por la Guardia Civil?")) { |
| 448 |
return false; |
| 449 |
} |
| 450 |
document.adminForm.target = "_blank"; |
| 451 |
document.adminForm.action += "&tmpl=component"; |
| 452 |
vboSetFilters({exportreport: "1", filler: JSON.stringify(reportObj)}, true); |
| 453 |
setTimeout(function() { |
| 454 |
document.adminForm.target = ""; |
| 455 |
document.adminForm.action = document.adminForm.action.replace("&tmpl=component", ""); |
| 456 |
vboSetFilters({exportreport: "0", filler: ""}, false); |
| 457 |
}, 1000); |
| 458 |
} |
| 459 |
// save data function |
| 460 |
function vboGuardiacivilSaveData() { |
| 461 |
jQuery("button.vbo-report-guardiacivil-manualsave").find("i").attr("class", vbo_guardiacivil_saving_icn); |
| 462 |
VBOCore.doAjax( |
| 463 |
vbo_guardiacivil_ajax_uri, |
| 464 |
{ |
| 465 |
call: "updatePaxData", |
| 466 |
params: reportObj, |
| 467 |
tmpl: "component" |
| 468 |
}, |
| 469 |
function(response) { |
| 470 |
if (!response || !response[0]) { |
| 471 |
alert("An error occurred."); |
| 472 |
return false; |
| 473 |
} |
| 474 |
jQuery("button.vbo-report-guardiacivil-manualsave").addClass("btn-success").find("i").attr("class", vbo_guardiacivil_saved_icn); |
| 475 |
}, |
| 476 |
function(error) { |
| 477 |
alert(error.responseText); |
| 478 |
jQuery("button.vbo-report-guardiacivil-manualsave").removeClass("btn-success").find("i").attr("class", vbo_guardiacivil_save_icn); |
| 479 |
} |
| 480 |
); |
| 481 |
} |
| 482 |
'; |
| 483 |
$this->setScript($js); |
| 484 |
|
| 485 |
return $this->reportFilters; |
| 486 |
} |
| 487 |
|
| 488 |
/** |
| 489 |
* Loads the report data from the DB. |
| 490 |
* Returns true in case of success, false otherwise. |
| 491 |
* Sets the columns and rows for the report to be displayed. |
| 492 |
* |
| 493 |
* @return boolean |
| 494 |
*/ |
| 495 |
public function getReportData() |
| 496 |
{ |
| 497 |
if (strlen($this->getError())) { |
| 498 |
//Export functions may set errors rather than exiting the process, and the View may continue the execution to attempt to render the report. |
| 499 |
return false; |
| 500 |
} |
| 501 |
$all_countries = VikBooking::getCountriesArray(); |
| 502 |
//Input fields and other vars |
| 503 |
$pfromdate = VikRequest::getString('fromdate', '', 'request'); |
| 504 |
$ptodate = VikRequest::getString('todate', '', 'request'); |
| 505 |
$photelname = VikRequest::getString('hotelname', '', 'request'); |
| 506 |
$photelcode = VikRequest::getString('hotelcode', '', 'request'); |
| 507 |
$pkrsort = VikRequest::getString('krsort', $this->defaultKeySort, 'request'); |
| 508 |
$pkrsort = empty($pkrsort) ? $this->defaultKeySort : $pkrsort; |
| 509 |
$pkrorder = VikRequest::getString('krorder', $this->defaultKeyOrder, 'request'); |
| 510 |
$pkrorder = empty($pkrorder) ? $this->defaultKeyOrder : $pkrorder; |
| 511 |
$pkrorder = $pkrorder == 'DESC' ? 'DESC' : 'ASC'; |
| 512 |
$currency_symb = VikBooking::getCurrencySymb(); |
| 513 |
$df = $this->getDateFormat(); |
| 514 |
$datesep = VikBooking::getDateSeparator(); |
| 515 |
if (empty($ptodate)) { |
| 516 |
$ptodate = $pfromdate; |
| 517 |
} |
| 518 |
|
| 519 |
if (empty($photelcode) || empty($photelname)) { |
| 520 |
$this->setError(JText::translate('VBOREPORTERRNODATA')); |
| 521 |
return false; |
| 522 |
} |
| 523 |
//Get dates timestamps |
| 524 |
$from_ts = VikBooking::getDateTimestamp($pfromdate, 0, 0); |
| 525 |
$to_ts = VikBooking::getDateTimestamp($ptodate, 23, 59, 59); |
| 526 |
if (empty($pfromdate) || empty($from_ts) || empty($to_ts)) { |
| 527 |
$this->setError(JText::translate('VBOREPORTSERRNODATES')); |
| 528 |
return false; |
| 529 |
} |
| 530 |
|
| 531 |
//Query to obtain the records (all check-ins within the dates filter) |
| 532 |
$records = array(); |
| 533 |
$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`,". |
| 534 |
"`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`,". |
| 535 |
"`co`.`idcustomer`,`co`.`pax_data`,`c`.`first_name`,`c`.`last_name`,`c`.`country` AS `customer_country`,`c`.`doctype`,`c`.`docnum`,`c`.`gender`,`c`.`bdate`,`c`.`pbirth` ". |
| 536 |
"FROM `#__vikbooking_orders` AS `o` LEFT JOIN `#__vikbooking_ordersrooms` AS `or` ON `or`.`idorder`=`o`.`id` ". |
| 537 |
"LEFT JOIN `#__vikbooking_customers_orders` AS `co` ON `co`.`idorder`=`o`.`id` LEFT JOIN `#__vikbooking_customers` AS `c` ON `c`.`id`=`co`.`idcustomer` ". |
| 538 |
"WHERE `o`.`status`='confirmed' AND `o`.`closure`=0 AND `o`.`checkin`>=".$from_ts." AND `o`.`checkin`<=".$to_ts." ". |
| 539 |
"ORDER BY `o`.`checkin` ASC, `o`.`id` ASC, `or`.`id` ASC;"; |
| 540 |
$this->dbo->setQuery($q); |
| 541 |
$records = $this->dbo->loadAssocList(); |
| 542 |
|
| 543 |
if (!$records) { |
| 544 |
$this->setError(JText::translate('VBOREPORTSERRNORESERV')); |
| 545 |
$this->setError('No llegan clientes en las fechas seleccionadas.'); |
| 546 |
return false; |
| 547 |
} |
| 548 |
|
| 549 |
//nest records with multiple rooms booked inside sub-array |
| 550 |
$bookings = array(); |
| 551 |
foreach ($records as $v) { |
| 552 |
if (!isset($bookings[$v['id']])) { |
| 553 |
$bookings[$v['id']] = array(); |
| 554 |
} |
| 555 |
array_push($bookings[$v['id']], $v); |
| 556 |
} |
| 557 |
|
| 558 |
//define the columns of the report |
| 559 |
$this->cols = array( |
| 560 |
//check-in |
| 561 |
array( |
| 562 |
'key' => 'checkin', |
| 563 |
'attr' => array( |
| 564 |
'class="center"' |
| 565 |
), |
| 566 |
'label' => JText::translate('VBPICKUPAT') |
| 567 |
), |
| 568 |
//cognome |
| 569 |
array( |
| 570 |
'key' => 'last_name', |
| 571 |
'label' => JText::translate('VBTRAVELERLNAME') |
| 572 |
), |
| 573 |
//nome |
| 574 |
array( |
| 575 |
'key' => 'first_name', |
| 576 |
'label' => JText::translate('VBTRAVELERNAME') |
| 577 |
), |
| 578 |
//sesso |
| 579 |
array( |
| 580 |
'key' => 'gender', |
| 581 |
'attr' => array( |
| 582 |
'class="center"' |
| 583 |
), |
| 584 |
'label' => JText::translate('VBCUSTOMERGENDER') |
| 585 |
), |
| 586 |
//data di nascita |
| 587 |
array( |
| 588 |
'key' => 'date_birth', |
| 589 |
'attr' => array( |
| 590 |
'class="center"' |
| 591 |
), |
| 592 |
'label' => JText::translate('VBCUSTOMERBDATE') |
| 593 |
), |
| 594 |
//cittadinanza |
| 595 |
array( |
| 596 |
'key' => 'country', |
| 597 |
'attr' => array( |
| 598 |
'class="center"' |
| 599 |
), |
| 600 |
'label' => JText::translate('VBCUSTOMERNATION') |
| 601 |
), |
| 602 |
//tipo documento |
| 603 |
array( |
| 604 |
'key' => 'doctype', |
| 605 |
'attr' => array( |
| 606 |
'class="center"' |
| 607 |
), |
| 608 |
'label' => JText::translate('VBCUSTOMERDOCTYPE') |
| 609 |
), |
| 610 |
//numero documento |
| 611 |
array( |
| 612 |
'key' => 'docnum', |
| 613 |
'attr' => array( |
| 614 |
'class="center"' |
| 615 |
), |
| 616 |
'label' => JText::translate('VBCUSTOMERDOCNUM') |
| 617 |
), |
| 618 |
//numero documento |
| 619 |
array( |
| 620 |
'key' => 'docissuedt', |
| 621 |
'attr' => array( |
| 622 |
'class="center"' |
| 623 |
), |
| 624 |
'label' => JText::translate('VBCUSTOMERDOCISSUE') |
| 625 |
), |
| 626 |
//id booking |
| 627 |
array( |
| 628 |
'key' => 'idbooking', |
| 629 |
'attr' => array( |
| 630 |
'class="center"' |
| 631 |
), |
| 632 |
'label' => 'ID' |
| 633 |
) |
| 634 |
); |
| 635 |
|
| 636 |
//loop over the bookings to build the rows of the report |
| 637 |
$from_info = getdate($from_ts); |
| 638 |
foreach ($bookings as $gbook) { |
| 639 |
$guests_rows = array($gbook[0]); |
| 640 |
$tot_guests_rows = 1; |
| 641 |
|
| 642 |
// count the total number of guests (only adults count) for all rooms of this booking |
| 643 |
$tot_booking_guests = 0; |
| 644 |
$room_guests = array(); |
| 645 |
foreach ($gbook as $rbook) { |
| 646 |
$tot_booking_guests += $rbook['adults']; |
| 647 |
$room_guests[] = $rbook['adults']; |
| 648 |
} |
| 649 |
|
| 650 |
if (!empty($gbook[0]['pax_data'])) { |
| 651 |
$pax_data = json_decode($gbook[0]['pax_data'], true); |
| 652 |
if (is_array($pax_data) && count($pax_data)) { |
| 653 |
$guests_rows[0]['pax_data'] = $pax_data; |
| 654 |
$tot_guests_rows = 0; |
| 655 |
foreach ($pax_data as $roomguests) { |
| 656 |
$tot_guests_rows += count($roomguests); |
| 657 |
} |
| 658 |
for ($i = 1; $i < $tot_guests_rows; $i++) { |
| 659 |
array_push($guests_rows, $guests_rows[0]); |
| 660 |
} |
| 661 |
} |
| 662 |
} |
| 663 |
|
| 664 |
//create one row for each guest |
| 665 |
$guest_ind = 1; |
| 666 |
foreach ($guests_rows as $ind => $guests) { |
| 667 |
$insert_row = array(); |
| 668 |
|
| 669 |
$use_pax_data = !empty($guests['pax_data']) && is_array($guests['pax_data']) ? $guests['pax_data'] : []; |
| 670 |
|
| 671 |
//Data Arrivo |
| 672 |
array_push($insert_row, array( |
| 673 |
'key' => 'checkin', |
| 674 |
'attr' => array( |
| 675 |
'class="center"' |
| 676 |
), |
| 677 |
'callback' => function ($val) { |
| 678 |
return $val; |
| 679 |
}, |
| 680 |
'callback_export' => function ($val) { |
| 681 |
return str_replace(['/', '-', '.'], '', $val); |
| 682 |
}, |
| 683 |
'value' => date('Y-m-d', $guests['checkin']) |
| 684 |
)); |
| 685 |
|
| 686 |
//Cognome |
| 687 |
$pax_cognome = $this->getGuestPaxDataValue($use_pax_data, $room_guests, $guest_ind, 'last_name'); |
| 688 |
$pax_cognome = empty($pax_cognome) && !empty($guests['t_last_name']) ? $guests['t_last_name'] : $pax_cognome; |
| 689 |
array_push($insert_row, array( |
| 690 |
'key' => 'last_name', |
| 691 |
'value' => $pax_cognome, |
| 692 |
)); |
| 693 |
|
| 694 |
//Nome |
| 695 |
$pax_nome = $this->getGuestPaxDataValue($use_pax_data, $room_guests, $guest_ind, 'first_name'); |
| 696 |
$pax_nome = empty($pax_nome) && !empty($guests['t_first_name']) ? $guests['t_first_name'] : $pax_nome; |
| 697 |
array_push($insert_row, array( |
| 698 |
'key' => 'first_name', |
| 699 |
'value' => $pax_nome, |
| 700 |
)); |
| 701 |
|
| 702 |
//Sesso |
| 703 |
$gender = !empty($guests['gender']) && $guest_ind < 2 ? strtoupper($guests['gender']) : ''; |
| 704 |
$pax_gender = $this->getGuestPaxDataValue($use_pax_data, $room_guests, $guest_ind, 'gender'); |
| 705 |
$gender = !empty($pax_gender) ? $pax_gender : $gender; |
| 706 |
if (!empty($gender) && $gender == '1') { |
| 707 |
$gender = 'M'; |
| 708 |
} elseif (!empty($gender) && $gender == '2') { |
| 709 |
$gender = 'F'; |
| 710 |
} |
| 711 |
array_push($insert_row, array( |
| 712 |
'key' => 'gender', |
| 713 |
'attr' => array( |
| 714 |
'class="center'.(empty($gender) ? ' vbo-report-load-sesso' : '').'"' |
| 715 |
), |
| 716 |
'callback' => function ($val) { |
| 717 |
return !empty($val) ? $val : '?'; |
| 718 |
}, |
| 719 |
'no_export_callback' => 1, |
| 720 |
'value' => $gender |
| 721 |
)); |
| 722 |
|
| 723 |
//Data di nascita |
| 724 |
$dbirth = !empty($guests['bdate']) && $guest_ind < 2 ? VikBooking::getDateTimestamp($guests['bdate'], 0, 0) : ''; |
| 725 |
$pax_dbirth = $this->getGuestPaxDataValue($use_pax_data, $room_guests, $guest_ind, 'date_birth'); |
| 726 |
$dbirth = !empty($pax_dbirth) ? $pax_dbirth : $dbirth; |
| 727 |
$dbirth = (strpos($dbirth, '/') === false && strpos($dbirth, VikBooking::getDateSeparator()) === false) ? $dbirth : VikBooking::getDateTimestamp($dbirth, 0, 0); |
| 728 |
array_push($insert_row, array( |
| 729 |
'key' => 'date_birth', |
| 730 |
'attr' => array( |
| 731 |
'class="center'.(empty($dbirth) ? ' vbo-report-load-dbirth' : '').'"' |
| 732 |
), |
| 733 |
'callback' => function ($val) { |
| 734 |
if (!empty($val) && strpos($val, '/') === false && strpos($val, VikBooking::getDateSeparator()) === false) { |
| 735 |
return date('d/m/Y', $val); |
| 736 |
} |
| 737 |
if (!empty($val) && strpos($val, '/') !== false) { |
| 738 |
return $val; |
| 739 |
} |
| 740 |
return '?'; |
| 741 |
}, |
| 742 |
'callback_export' => function ($val) { |
| 743 |
return (strpos($val, '/') === false && strpos($val, VikBooking::getDateSeparator()) === false) ? date('Ymd', $val) : date('Ymd', VikBooking::getDateTimestamp($val, 0, 0)); |
| 744 |
}, |
| 745 |
'value' => $dbirth |
| 746 |
)); |
| 747 |
|
| 748 |
//Cittadinanza |
| 749 |
$citizen = !empty($guests['country']) && $guest_ind < 2 ? $guests['country'] : ''; |
| 750 |
$citizenval = ''; |
| 751 |
if (!empty($citizen) && $guest_ind < 2) { |
| 752 |
$citizenval = $this->checkCountry($citizen); |
| 753 |
} |
| 754 |
if (!empty($citizenval) && isset($this->nazioni[$citizenval])) { |
| 755 |
$citizenval = $this->nazioni[$citizenval]['name']; |
| 756 |
} |
| 757 |
// give higher important to info collected through custom fields |
| 758 |
$pax_citizen = $this->getGuestPaxDataValue($use_pax_data, $room_guests, $guest_ind, 'country'); |
| 759 |
if (!empty($pax_citizen)) { |
| 760 |
$pax_citizen = strlen($pax_citizen) == 3 ? $this->checkCountry($pax_citizen) : $pax_citizen; |
| 761 |
$citizenval = isset($this->nazioni[$pax_citizen]) ? $this->nazioni[$pax_citizen]['name'] : $pax_citizen; |
| 762 |
} |
| 763 |
array_push($insert_row, array( |
| 764 |
'key' => 'country', |
| 765 |
'attr' => array( |
| 766 |
'class="center'.(empty($citizenval) ? ' vbo-report-load-cittadinanza' : '').'"' |
| 767 |
), |
| 768 |
'callback' => function ($val) { |
| 769 |
return !empty($val) ? strtoupper($val) : '?'; |
| 770 |
}, |
| 771 |
'no_export_callback' => 1, |
| 772 |
'value' => $citizenval |
| 773 |
)); |
| 774 |
|
| 775 |
//Tipo documento |
| 776 |
$pax_doctype = $this->getGuestPaxDataValue($use_pax_data, $room_guests, $guest_ind, 'doctype'); |
| 777 |
$all_doc_types = $this->loadDocumenti(); |
| 778 |
$doctype = $pax_doctype; |
| 779 |
array_push($insert_row, array( |
| 780 |
'key' => 'doctype', |
| 781 |
'attr' => array( |
| 782 |
'class="center'.(empty($doctype) ? ' vbo-report-load-doctype' : '').'"' |
| 783 |
), |
| 784 |
'callback' => function ($val) use ($all_doc_types) { |
| 785 |
return !empty($val) && isset($all_doc_types[$val]) ? $all_doc_types[$val] : '?'; |
| 786 |
}, |
| 787 |
'no_export_callback' => 1, |
| 788 |
'value' => $pax_doctype, |
| 789 |
)); |
| 790 |
|
| 791 |
//Numero documento |
| 792 |
$pax_docnum = $this->getGuestPaxDataValue($use_pax_data, $room_guests, $guest_ind, 'docnum'); |
| 793 |
$docnum = empty($pax_docnum) && !empty($guests['docnum']) && $guest_ind < 2 ? $guests['docnum'] : $pax_docnum; |
| 794 |
array_push($insert_row, array( |
| 795 |
'key' => 'docnum', |
| 796 |
'attr' => array( |
| 797 |
'class="center'.(empty($docnum) ? ' vbo-report-load-docnum' : '').'"' |
| 798 |
), |
| 799 |
'callback' => function ($val) { |
| 800 |
return empty($val) ? '?' : $val; |
| 801 |
}, |
| 802 |
'value' => $docnum, |
| 803 |
)); |
| 804 |
|
| 805 |
// Document issue date |
| 806 |
$pax_docissuedt = $this->getGuestPaxDataValue($use_pax_data, $room_guests, $guest_ind, 'docissuedt'); |
| 807 |
array_push($insert_row, array( |
| 808 |
'key' => 'docissuedt', |
| 809 |
'attr' => array( |
| 810 |
'class="center'.(empty($pax_docissuedt) ? ' vbo-report-load-docissue vbo-report-load-docissuedt' : '').'"' |
| 811 |
), |
| 812 |
'callback' => function ($val) { |
| 813 |
return !empty($val) ? $val : '?'; |
| 814 |
}, |
| 815 |
'callback_export' => function ($val) { |
| 816 |
return (strpos($val, '/') === false && strpos($val, VikBooking::getDateSeparator()) === false) ? date('Ymd', $val) : date('Ymd', VikBooking::getDateTimestamp($val, 0, 0)); |
| 817 |
}, |
| 818 |
'value' => $pax_docissuedt, |
| 819 |
)); |
| 820 |
|
| 821 |
//id booking |
| 822 |
array_push($insert_row, array( |
| 823 |
'key' => 'idbooking', |
| 824 |
'attr' => array( |
| 825 |
'class="center"' |
| 826 |
), |
| 827 |
'callback' => function ($val) { |
| 828 |
// make sure to keep the data-bid attribute as it's used by JS to identify the booking ID |
| 829 |
return '<a data-bid="' . $val . '" href="index.php?option=com_vikbooking&task=editorder&cid[]=' . $val . '" target="_blank"><i class="' . VikBookingIcons::i('external-link') . '"></i> ' . $val . '</a>'; |
| 830 |
}, |
| 831 |
'ignore_export' => 1, |
| 832 |
'value' => $guests['id'] |
| 833 |
)); |
| 834 |
|
| 835 |
//push fields in the rows array as a new row |
| 836 |
array_push($this->rows, $insert_row); |
| 837 |
|
| 838 |
//increment guest index |
| 839 |
$guest_ind++; |
| 840 |
} |
| 841 |
} |
| 842 |
|
| 843 |
// do not sort the rows for this report because the lines of the guests of the same booking must be consecutive |
| 844 |
|
| 845 |
//the footer row will just print the amount of records to export |
| 846 |
array_push($this->footerRow, array( |
| 847 |
array( |
| 848 |
'attr' => array( |
| 849 |
'class="vbo-report-total"' |
| 850 |
), |
| 851 |
'value' => '<h3>'.JText::translate('VBOREPORTSTOTALROW').'</h3>' |
| 852 |
), |
| 853 |
array( |
| 854 |
'attr' => array( |
| 855 |
'colspan="'.(count($this->cols) - 1).'"' |
| 856 |
), |
| 857 |
'value' => count($this->rows) |
| 858 |
) |
| 859 |
)); |
| 860 |
|
| 861 |
//Debug |
| 862 |
if ($this->debug) { |
| 863 |
$this->setWarning('path to report file = '.urlencode(dirname(__FILE__)).'<br/>'); |
| 864 |
$this->setWarning('$total_rooms_units = '.$total_rooms_units.'<br/>'); |
| 865 |
$this->setWarning('$bookings:<pre>'.print_r($bookings, true).'</pre><br/>'); |
| 866 |
} |
| 867 |
// |
| 868 |
|
| 869 |
return true; |
| 870 |
} |
| 871 |
|
| 872 |
/** |
| 873 |
* Generates the text file for the Italian Police, |
| 874 |
* then it sends it to output for download. |
| 875 |
* In case of errors, the process is not terminated (exit) |
| 876 |
* to let the View display the error message. |
| 877 |
* |
| 878 |
* @param string $export_type Differentiates the type of export requested. |
| 879 |
* |
| 880 |
* @return void|bool Void in case of script termination, boolean otherwise. |
| 881 |
*/ |
| 882 |
public function customExport($export_type = 0) |
| 883 |
{ |
| 884 |
if (!$this->getReportData()) { |
| 885 |
return false; |
| 886 |
} |
| 887 |
|
| 888 |
$photelname = VikRequest::getString('hotelname', '', 'request'); |
| 889 |
$photelcode = VikRequest::getString('hotelcode', '', 'request'); |
| 890 |
$pfiller = VikRequest::getString('filler', '', 'request', VIKREQUEST_ALLOWRAW); |
| 891 |
$pfiller = !empty($pfiller) ? json_decode($pfiller, true) : array(); |
| 892 |
$pfiller = !is_array($pfiller) ? array() : $pfiller; |
| 893 |
|
| 894 |
//pool of booking IDs to update their history |
| 895 |
$booking_ids = array(); |
| 896 |
|
| 897 |
//array of lines (one line for each guest) |
| 898 |
$lines = array(); |
| 899 |
$customers = array(); |
| 900 |
$customerCount = 0; |
| 901 |
$keyorder = array( |
| 902 |
"docnum", // Doc id for DNI |
| 903 |
"doctype", |
| 904 |
"docissuedt", |
| 905 |
"cognome1", |
| 906 |
"cognome2", |
| 907 |
"first_name", |
| 908 |
"gender", |
| 909 |
"date_birth", |
| 910 |
"country", |
| 911 |
"checkin" |
| 912 |
); |
| 913 |
|
| 914 |
//Push the lines of the Text file |
| 915 |
foreach ($this->rows as $ind => $row) { |
| 916 |
|
| 917 |
$line_cont = ''; |
| 918 |
foreach ($row as $field) { |
| 919 |
if ($field['key'] == 'idbooking' && !in_array($field['value'], $booking_ids)) { |
| 920 |
array_push($booking_ids, $field['value']); |
| 921 |
} |
| 922 |
if (isset($field['ignore_export'])) { |
| 923 |
continue; |
| 924 |
} |
| 925 |
//report value |
| 926 |
if (is_array($pfiller) && isset($pfiller[$ind]) && isset($pfiller[$ind][$field['key']])) { |
| 927 |
if (strlen($pfiller[$ind][$field['key']])) { |
| 928 |
$field['value'] = $pfiller[$ind][$field['key']]; |
| 929 |
} |
| 930 |
} |
| 931 |
|
| 932 |
// values set to -1 are usually empty and should have been filled in manually |
| 933 |
if ($field['value'] === -1) { |
| 934 |
// we raise an error in this case without stopping the process |
| 935 |
$field['value'] = 0; |
| 936 |
VikError::raiseWarning('', 'Line #' . $ind . ' has got an empty value that should have been manually filled by clicking the red box. File may be broken due to this line.'); |
| 937 |
} |
| 938 |
|
| 939 |
if (isset($field['callback_export'])) { |
| 940 |
$field['callback'] = $field['callback_export']; |
| 941 |
} |
| 942 |
$value = !isset($field['no_export_callback']) && isset($field['callback']) && is_callable($field['callback']) ? $field['callback']($field['value']) : $field['value']; |
| 943 |
//0 or '---' should be changed to an empty string (case of "-- Estero --" or field to be filled with Blank) |
| 944 |
$value = empty($value) || $value == '---' ? '' : $value; |
| 945 |
|
| 946 |
//this is necessary since the customer may have multiple last names. |
| 947 |
if ($field['key'] == 'last_name') { |
| 948 |
$cognomi = explode(" ", $value); |
| 949 |
$customers[$customerCount]['cognome1'] = $cognomi[0]; |
| 950 |
$customers[$customerCount]['cognome2'] = isset($cognomi[1]) ? $cognomi[1] : ""; |
| 951 |
continue; |
| 952 |
} |
| 953 |
//concatenate the field to the customer record |
| 954 |
$customers[$customerCount][$field['key']] = $this->valueFiller($value, ''); |
| 955 |
} |
| 956 |
$customerCount++; |
| 957 |
} |
| 958 |
|
| 959 |
$separator = '|'; |
| 960 |
$line_cont = implode($separator, [ |
| 961 |
'1', |
| 962 |
$photelcode, |
| 963 |
$photelname, |
| 964 |
date('Ymd'), |
| 965 |
date('Hi'), |
| 966 |
str_pad((string)count($customers), 5, '0', STR_PAD_LEFT), |
| 967 |
]); |
| 968 |
array_push($lines, $line_cont); |
| 969 |
foreach ($customers as $customer) { |
| 970 |
$line_cont = '2|'; |
| 971 |
foreach ($keyorder as $key) { |
| 972 |
if ($key == 'docnum') { |
| 973 |
$line_cont .= strtoupper($customer['doctype']) == 'D' ? (strtoupper($customer[$key]) . $separator . $separator) : ($separator . strtoupper($customer[$key]) . $separator); |
| 974 |
continue; |
| 975 |
} |
| 976 |
$line_cont .= strtoupper($customer[$key]) . $separator; |
| 977 |
} |
| 978 |
$line_cont = rtrim($line_cont, $separator); |
| 979 |
|
| 980 |
//push the line in the array of lines |
| 981 |
array_push($lines, $line_cont); |
| 982 |
} |
| 983 |
|
| 984 |
|
| 985 |
//update the history for all bookings affected |
| 986 |
foreach ($booking_ids as $bid) { |
| 987 |
VikBooking::getBookingHistoryInstance()->setBid($bid)->store('RP', $this->reportName); |
| 988 |
} |
| 989 |
|
| 990 |
/** |
| 991 |
* Custom export method supports a custom export handler, if previously set. |
| 992 |
* |
| 993 |
* @since 1.16.1 (J) - 1.6.1 (WP) |
| 994 |
*/ |
| 995 |
if ($this->hasExportHandler()) { |
| 996 |
// write data onto the custom file handler |
| 997 |
$fp = $this->getExportCSVHandler(); |
| 998 |
fwrite($fp, implode("\r\n", $lines)); |
| 999 |
fclose($fp); |
| 1000 |
|
| 1001 |
return true; |
| 1002 |
} |
| 1003 |
|
| 1004 |
// force text file download |
| 1005 |
header('Content-Type: text/plain; charset=utf-8'); |
| 1006 |
header('Cache-Control: no-store, no-cache'); |
| 1007 |
header('Content-Disposition: attachment; filename="' . $this->getExportCSVFileName() . '"'); |
| 1008 |
echo implode("\r\n", $lines); |
| 1009 |
exit; |
| 1010 |
} |
| 1011 |
|
| 1012 |
/** |
| 1013 |
* Helper method invoked via AJAX by the controller. |
| 1014 |
* Needed to save the manual entries for the pax data. |
| 1015 |
* |
| 1016 |
* @param array $manual_data the object representation of the manual entries. |
| 1017 |
* |
| 1018 |
* @return array one boolean value array with the operation result. |
| 1019 |
*/ |
| 1020 |
public function updatePaxData($manual_data = array()) |
| 1021 |
{ |
| 1022 |
if (!is_array($manual_data) || !$manual_data) { |
| 1023 |
VBOHttpDocument::getInstance()->close(400, 'Nothing to save!'); |
| 1024 |
} |
| 1025 |
|
| 1026 |
// re-build manual entries object representation |
| 1027 |
$bids_guests = array(); |
| 1028 |
foreach ($manual_data as $guest_ind => $guest_data) { |
| 1029 |
if (!is_numeric($guest_ind) || !is_array($guest_data) || empty($guest_data['bid']) || !isset($guest_data['bid_index']) || count($guest_data) < 2) { |
| 1030 |
// empty or invalid manual entries array |
| 1031 |
continue; |
| 1032 |
} |
| 1033 |
// the guest index in the reportObj starts from 0 |
| 1034 |
$use_guest_ind = ($guest_ind + 1 - (int)$guest_data['bid_index']); |
| 1035 |
if (!isset($bids_guests[$guest_data['bid']])) { |
| 1036 |
$bids_guests[$guest_data['bid']] = array(); |
| 1037 |
} |
| 1038 |
// set manual entries for this guest number |
| 1039 |
$bids_guests[$guest_data['bid']][$use_guest_ind] = $guest_data; |
| 1040 |
// remove the "bid" and "bid_index" keys |
| 1041 |
unset($bids_guests[$guest_data['bid']][$use_guest_ind]['bid'], $bids_guests[$guest_data['bid']][$use_guest_ind]['bid_index']); |
| 1042 |
} |
| 1043 |
|
| 1044 |
if (!count($bids_guests)) { |
| 1045 |
VBOHttpDocument::getInstance()->close(400, 'No manual entries to save found'); |
| 1046 |
} |
| 1047 |
|
| 1048 |
// loop through all bookings to update the data for the various rooms and guests |
| 1049 |
$bids_updated = 0; |
| 1050 |
foreach ($bids_guests as $bid => $entries) { |
| 1051 |
$b_rooms = VikBooking::loadOrdersRoomsData($bid); |
| 1052 |
if (empty($b_rooms)) { |
| 1053 |
continue; |
| 1054 |
} |
| 1055 |
// count adults per room |
| 1056 |
$room_guests = array(); |
| 1057 |
foreach ($b_rooms as $b_room) { |
| 1058 |
$room_guests[] = $b_room['adults']; |
| 1059 |
} |
| 1060 |
// get current booking pax data |
| 1061 |
$pax_data = VBOCheckinPax::getBookingPaxData($bid); |
| 1062 |
$pax_data = empty($pax_data) ? array() : $pax_data; |
| 1063 |
foreach ($entries as $guest_ind => $guest_data) { |
| 1064 |
if (!empty($guest_data['country']) && !empty($guest_data['country_code'])) { |
| 1065 |
// adjust manually entered country to store just the code for compliance with field of type "country" |
| 1066 |
$guest_data['country'] = $guest_data['country_code']; |
| 1067 |
unset($guest_data['country_code']); |
| 1068 |
} |
| 1069 |
// find room index for this guest |
| 1070 |
$room_num = 0; |
| 1071 |
$use_guest_ind = $guest_ind; |
| 1072 |
foreach ($room_guests as $room_index => $tot_guests) { |
| 1073 |
// find the proper guest index for the room to which this belongs |
| 1074 |
if ($use_guest_ind <= $tot_guests) { |
| 1075 |
// proper room index found for this guest |
| 1076 |
$room_num = $room_index; |
| 1077 |
break; |
| 1078 |
} else { |
| 1079 |
// it's probably in a next room |
| 1080 |
$use_guest_ind -= $tot_guests; |
| 1081 |
} |
| 1082 |
} |
| 1083 |
// push new pax data for this room and guest |
| 1084 |
if (!isset($pax_data[$room_num])) { |
| 1085 |
$pax_data[$room_num] = array(); |
| 1086 |
} |
| 1087 |
if (!isset($pax_data[$room_num][$use_guest_ind])) { |
| 1088 |
$pax_data[$room_num][$use_guest_ind] = $guest_data; |
| 1089 |
} else { |
| 1090 |
$pax_data[$room_num][$use_guest_ind] = array_merge($pax_data[$room_num][$use_guest_ind], $guest_data); |
| 1091 |
} |
| 1092 |
} |
| 1093 |
// update booking pax data |
| 1094 |
if (VBOCheckinPax::setBookingPaxData($bid, $pax_data)) { |
| 1095 |
$bids_updated++; |
| 1096 |
} |
| 1097 |
} |
| 1098 |
|
| 1099 |
return $bids_updated ? [true] : [false]; |
| 1100 |
} |
| 1101 |
|
| 1102 |
/** |
| 1103 |
* Parses the file Documenti.csv and returns an associative |
| 1104 |
* array with the code and name of the Documento. |
| 1105 |
* Every line of the CSV is composed of: Codice, Documento. |
| 1106 |
* |
| 1107 |
* @return array |
| 1108 |
*/ |
| 1109 |
public function loadDocumenti() |
| 1110 |
{ |
| 1111 |
return [ |
| 1112 |
"D" => "Documento Nacional de Identidad", |
| 1113 |
"P" => "Pasaporte", |
| 1114 |
"C" => "Permiso de Conducir", |
| 1115 |
"I" => "Carta o Documento de Identidad", |
| 1116 |
"N" => "Permiso de Residencia Español", |
| 1117 |
"X" => "Permiso de Residencia de otro Estado Miembro de la Unión Europea", |
| 1118 |
]; |
| 1119 |
} |
| 1120 |
|
| 1121 |
/** |
| 1122 |
* Registers the name to give to the file being exported. |
| 1123 |
* |
| 1124 |
* @return void |
| 1125 |
* |
| 1126 |
* @since 1.16.1 (J) - 1.6.1 (WP) |
| 1127 |
*/ |
| 1128 |
private function registerExportFileName() |
| 1129 |
{ |
| 1130 |
$pfromdate = VikRequest::getString('fromdate', '', 'request'); |
| 1131 |
$ptodate = VikRequest::getString('todate', '', 'request'); |
| 1132 |
|
| 1133 |
$this->setExportCSVFileName($this->reportName . '-' . str_replace('/', '_', $pfromdate) . '-' . str_replace('/', '_', $ptodate) . '.txt'); |
| 1134 |
} |
| 1135 |
|
| 1136 |
/** |
| 1137 |
* This method adds blank spaces to the string |
| 1138 |
* until the passed length of string is reached. |
| 1139 |
* |
| 1140 |
* @param string $val |
| 1141 |
* @param int $len |
| 1142 |
* |
| 1143 |
* @return string |
| 1144 |
*/ |
| 1145 |
private function valueFiller($val, $len) |
| 1146 |
{ |
| 1147 |
$len = empty($len) || (int)$len <= 0 ? strlen($val) : (int)$len; |
| 1148 |
|
| 1149 |
//clean up $val in case there is still a CR or LF |
| 1150 |
$val = str_replace(array("\r\n", "\r", "\n"), '', $val); |
| 1151 |
|
| 1152 |
if (strlen($val) < $len) { |
| 1153 |
while (strlen($val) < $len) { |
| 1154 |
$val .= ' '; |
| 1155 |
} |
| 1156 |
} elseif (strlen($val) > $len) { |
| 1157 |
$val = substr($val, 0, $len); |
| 1158 |
} |
| 1159 |
|
| 1160 |
return $val; |
| 1161 |
} |
| 1162 |
|
| 1163 |
/** |
| 1164 |
* Loads the country names from DB |
| 1165 |
* |
| 1166 |
* @return array |
| 1167 |
*/ |
| 1168 |
private function loadNazioni() |
| 1169 |
{ |
| 1170 |
$nazioni = []; |
| 1171 |
$records = []; |
| 1172 |
|
| 1173 |
$db = JFactory::getDbo(); |
| 1174 |
$q = "SELECT `country_3_code`, `country_name`,`country_2_code` FROM `#__vikbooking_countries`;"; |
| 1175 |
$db->setQuery($q); |
| 1176 |
$db->execute(); |
| 1177 |
if ($db->getNumRows()>0) { |
| 1178 |
$records = $db->loadAssocList(); |
| 1179 |
} |
| 1180 |
|
| 1181 |
foreach ($records as $key => $value) { |
| 1182 |
$nazioni[$value['country_2_code']]['name'] = $value['country_name']; |
| 1183 |
$nazioni[$value['country_2_code']]['three_code'] = $value['country_3_code']; |
| 1184 |
} |
| 1185 |
return $nazioni; |
| 1186 |
} |
| 1187 |
|
| 1188 |
/** |
| 1189 |
* |
| 1190 |
* Returns the key of the state selected by the user. |
| 1191 |
* |
| 1192 |
* @return string |
| 1193 |
* |
| 1194 |
*/ |
| 1195 |
private function checkCountry($country) { |
| 1196 |
$found = false; |
| 1197 |
$staval = ''; |
| 1198 |
if (!count($this->nazioni)) { |
| 1199 |
$this->nazioni = $this->loadNazioni(); |
| 1200 |
} |
| 1201 |
foreach ($this->nazioni as $key => $value) { |
| 1202 |
if (trim($value['three_code']) == trim($country)) { |
| 1203 |
$staval = $key; |
| 1204 |
$found = true; |
| 1205 |
break; |
| 1206 |
} |
| 1207 |
} |
| 1208 |
if ($found !== true) { |
| 1209 |
$staval = ''; |
| 1210 |
} |
| 1211 |
return $staval; |
| 1212 |
} |
| 1213 |
|
| 1214 |
/** |
| 1215 |
* Helper method to quickly get a pax_data property for the guest. |
| 1216 |
* |
| 1217 |
* @param array $pax_data the current pax_data stored. |
| 1218 |
* @param array $guests list of total guests per room. |
| 1219 |
* @param int $guest_ind the guest index. |
| 1220 |
* @param string $key the pax_data key to look for. |
| 1221 |
* |
| 1222 |
* @return mixed null on failure or value fetched. |
| 1223 |
* |
| 1224 |
* @since 1.15.2 (J) - 1.5.4 (WP) |
| 1225 |
*/ |
| 1226 |
private function getGuestPaxDataValue($pax_data, $guests, $guest_ind, $key) |
| 1227 |
{ |
| 1228 |
if (!is_array($pax_data) || !count($pax_data) || empty($key)) { |
| 1229 |
return null; |
| 1230 |
} |
| 1231 |
|
| 1232 |
// find room index for this guest number |
| 1233 |
$room_num = 0; |
| 1234 |
$use_guest_ind = $guest_ind; |
| 1235 |
foreach ($guests as $room_index => $room_tot_guests) { |
| 1236 |
// find the proper guest index for the room to which this belongs |
| 1237 |
if ($use_guest_ind <= $room_tot_guests) { |
| 1238 |
// proper room index found for this guest |
| 1239 |
$room_num = $room_index; |
| 1240 |
break; |
| 1241 |
} else { |
| 1242 |
// it's probably in a next room |
| 1243 |
$use_guest_ind -= $room_tot_guests; |
| 1244 |
} |
| 1245 |
} |
| 1246 |
|
| 1247 |
// check if a value exists for the requested key in the found room and guest indexes |
| 1248 |
if (isset($pax_data[$room_num]) && isset($pax_data[$room_num][$use_guest_ind])) { |
| 1249 |
if (isset($pax_data[$room_num][$use_guest_ind][$key])) { |
| 1250 |
// we've got a value previously stored |
| 1251 |
return $pax_data[$room_num][$use_guest_ind][$key]; |
| 1252 |
} |
| 1253 |
} |
| 1254 |
|
| 1255 |
// nothing was found |
| 1256 |
return null; |
| 1257 |
} |
| 1258 |
} |
| 1259 |
|