Merge pull request #531 from abhishek-webkul/check-in-document

Allow admin to upload check-in documents
This commit is contained in:
Rohit Jain
2023-02-15 19:29:43 +05:30
committed by GitHub
18 changed files with 947 additions and 69 deletions

View File

@@ -7,4 +7,12 @@
.booking_occupancy
.booking_occupancy_wrapper
max-height: 250px
overflow-x: auto
overflow-x: auto
#booking-documents-modal
.documents-list
table
tbody
img
max-height: 55px
max-width: 55px

View File

@@ -0,0 +1,87 @@
{*
* 2007-2017 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2017 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
{if isset($conf)}
<div class="bootstrap">
<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">&times;</button>
{$conf}
</div>
</div>
{/if}
{if isset($errors) && count($errors) && current($errors) != '' && (!isset($disableDefaultErrorOutPut) || $disableDefaultErrorOutPut == false)}
<div class="bootstrap">
<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert">&times;</button>
{if count($errors) == 1}
{reset($errors)}
{else }
{l s='%d errors' sprintf=$errors|count}
<br/>
<ol>
{foreach $errors as $error}
<li>{$error}</li>
{/foreach}
</ol>
{/if}
</div>
</div>
{/if}
{if isset($informations) && count($informations) && $informations}
<div class="bootstrap">
<div class="alert alert-info">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<ul id="infos_block" class="list-unstyled">
{foreach $informations as $info}
<li>{$info}</li>
{/foreach}
</ul>
</div>
</div>
{/if}
{if isset($confirmations) && count($confirmations) && $confirmations}
<div class="bootstrap">
<div class="alert alert-success" style="display:block;">
{foreach $confirmations as $conf}
{$conf}
{/foreach}
</div>
</div>
{/if}
{if isset($warnings) && count($warnings)}
<div class="bootstrap">
<div class="alert alert-warning">
<button type="button" class="close" data-dismiss="alert">&times;</button>
{if count($warnings) > 1}
<h4>{l s='There are %d warnings:' sprintf=count($warnings)}</h4>
{/if}
<ul class="list-unstyled">
{foreach $warnings as $warning}
<li>{$warning}</li>
{/foreach}
</ul>
</div>
</div>
{/if}

View File

@@ -0,0 +1,53 @@
{**
* 2010-2023 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through LICENSE.txt file inside our module
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to CustomizationPolicy.txt file inside our module for more information.
*
* @author Webkul IN
* @copyright 2010-2023 Webkul IN
* @license LICENSE.txt
*}
{if is_array($booking_documents) && count($booking_documents)}
{foreach from=$booking_documents item=booking_document}
<tr>
<td class="text-center">
<a href="{$link->getAdminLink('AdminBookingDocument')}&action=getDocument&id_document={$booking_document.id_htl_booking_document}&is_preview=1" target="_blank">
{if $booking_document.file_type == HotelBookingDocument::FILE_TYPE_IMAGE}
<img class="img img-responsive img-thumbnail" src="{$link->getAdminLink('AdminBookingDocument')}&action=getDocument&id_document={$booking_document.id_htl_booking_document}&is_preview=1">
{elseif $booking_document.file_type == HotelBookingDocument::FILE_TYPE_PDF}
<img class="img img-responsive img-thumbnail" src="{$pdf_icon_link}">
{/if}
</a>
</td>
<td class="text-left">{$booking_document.title}</td>
<td class="text-center">{dateFormat date=$booking_document.date_add full=1}</td>
<td class="text-center">
<a class="btn btn-info" href="{$link->getAdminLink('AdminBookingDocument')}&action=getDocument&id_document={$booking_document.id_htl_booking_document}">
<i class="icon icon-cloud-download"></i>
</a>
<a class="btn btn-danger btn-delete-document" data-id-htl-booking-document="{$booking_document.id_htl_booking_document}">
<i class="icon icon-trash"></i>
</a>
</td>
</tr>
{/foreach}
{else}
<tr>
<td class="list-empty" colspan="4">
<div class="list-empty-msg">
<i class="icon-warning-sign list-empty-icon"></i>
{l s='No documents uploaded yet.'}
</div>
</td>
</tr>
{/if}

View File

@@ -0,0 +1,101 @@
{**
* 2010-2023 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through LICENSE.txt file inside our module
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to CustomizationPolicy.txt file inside our module for more information.
*
* @author Webkul IN
* @copyright 2010-2023 Webkul IN
* @license LICENSE.txt
*}
<div class="modal-body text-center">
<div class="row">
<div class="col-lg-12">
<div class="text-left errors-wrap"></div>
<div class="documents-list">
<table class="table table-bordered">
<thead>
<tr>
<th class="text-center">{l s='Preview'}</th>
<th class="text-left">{l s='Title'}</th>
<th class="text-center">{l s='Upload Date'}</th>
<th class="text-center">{l s='Actions'}</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<div class="add-new-document-form" style="margin-top: 10px;">
<div class="text-left add-new-wrap">
<a class="btn btn-primary btn-add-new-document">
{l s='Upload new document'}
</a>
<span></span>
</div>
<form id="form-add-new-document" class="well" method="post" action="#" style="display: none; margin-top: 5px;">
<input type="hidden" name="id_htl_booking" value="0">
<div class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-2">
<span class="label-tooltip" data-toggle="tooltip" title="" data-original-title="{l s='Write the title for the document. Invalid characters <>;=#{}'}">
{l s='Title'}
</span>
</label>
<div class="col-sm-10">
<div class="input-group fixed-width-xxl">
<input type="text" name="title" value="" placeholder="{l s='Eg. Passport, Driving license'}" />
</div>
</div>
</div>
<div class="form-group">
<label class="control-label required col-sm-2">
<span class="label-tooltip" data-toggle="tooltip" title="" data-original-title="{l s='Choose the document file to be uploaded.'}">
{l s='File'}
</span>
</label>
<div class="col-sm-10">
<div class="input-file-wrap"></div>
<div class="input-group fixed-width-xxl">
<span class="input-group-addon"><i class="icon-file"></i></span>
<input type="text" class="file-name" readonly="">
<span class="input-group-btn">
<button type="button" class="btn btn-default btn-add-file">
<i class="icon-folder-open"></i>
{l s='Add file'}
</button>
</span>
</div>
<p class="text-left" style="margin-top: 4px; font-style: italic;">
{l s='Upload a PDF or an image file. Allowed image formats: .gif, .jpg, .jpeg and .png'}
</p>
</div>
</div>
<div class="clearfix btn-group-add-new">
<button class="btn btn-primary pull-right upload" type="submit" name="submitAddPayment">
{l s='Upload'}
</button>
<button class="btn btn-default pull-left cancel">
{l s='Cancel'}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
{addJsDefL name=txt_booking_document_upload_success}{l s='Document uploaded successfully.' js=1}{/addJsDefL}
{addJsDefL name=txt_booking_document_delete_confirm}{l s='Are you sure?' js=1}{/addJsDefL}
{addJsDefL name=txt_booking_document_delete_success}{l s='Document deleted successfully.' js=1}{/addJsDefL}

View File

@@ -275,8 +275,8 @@
<tr>
<th>{l s='Room No.'}</th>
<th>{l s='Hotel Name'}</th>
<th>{l s='Date From'}</th>
<th>{l s='Date To'}</th>
<th>{l s='Duration'}</th>
<th>{l s='Documents'}</th>
<th>{l s='Order Status'}</th>
</tr>
{if isset($htl_booking_order_data) && $htl_booking_order_data}
@@ -291,10 +291,13 @@
</a>
</td>
<td>
{dateFormat date=$data['date_from']}
{dateFormat date=$data['date_from']} - {dateFormat date=$data['date_to']}
</td>
<td>
{dateFormat date=$data['date_to']}
<a class="btn btn-default" onclick="BookingDocumentsModal.init({$data.id|intval}, this); return false;">
<i class="icon icon-file-text"></i>
{l s='Documents'} <span class="badge badge-info count-documents">{$data.num_checkin_documents}</span>
</a>
</td>
<td>
<form action="" method="post" class="form-horizontal row room_status_info_form">

View File

@@ -23,68 +23,6 @@
* International Registered Trademark & Property of PrestaShop SA
*}
{$header}
{if isset($conf)}
<div class="bootstrap">
<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">&times;</button>
{$conf}
</div>
</div>
{/if}
{if count($errors) && current($errors) != '' && (!isset($disableDefaultErrorOutPut) || $disableDefaultErrorOutPut == false)}
<div class="bootstrap">
<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert">&times;</button>
{if count($errors) == 1}
{reset($errors)}
{else }
{l s='%d errors' sprintf=$errors|count}
<br/>
<ol>
{foreach $errors as $error}
<li>{$error}</li>
{/foreach}
</ol>
{/if}
</div>
</div>
{/if}
{if isset($informations) && count($informations) && $informations}
<div class="bootstrap">
<div class="alert alert-info">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<ul id="infos_block" class="list-unstyled">
{foreach $informations as $info}
<li>{$info}</li>
{/foreach}
</ul>
</div>
</div>
{/if}
{if isset($confirmations) && count($confirmations) && $confirmations}
<div class="bootstrap">
<div class="alert alert-success" style="display:block;">
{foreach $confirmations as $conf}
{$conf}
{/foreach}
</div>
</div>
{/if}
{if count($warnings)}
<div class="bootstrap">
<div class="alert alert-warning">
<button type="button" class="close" data-dismiss="alert">&times;</button>
{if count($warnings) > 1}
<h4>{l s='There are %d warnings:' sprintf=count($warnings)}</h4>
{/if}
<ul class="list-unstyled">
{foreach $warnings as $warning}
<li>{$warning}</li>
{/foreach}
</ul>
</div>
</div>
{/if}
{include file='./alerts.tpl'}
{$page}
{$footer}

View File

@@ -282,7 +282,12 @@ class AdminOrdersControllerCore extends AdminController
Tools::redirectAdmin($this->context->link->getAdminLink('AdminOrders'));
}
$this->toolbar_title[] = sprintf($this->l('Order %1$s from %2$s %3$s'), $order->reference, $customer->firstname, $customer->lastname);
if ($idHotel = HotelBookingDetail::getIdHotelByIdOrder($order->id)) {
$objHotelBranchInformation = new HotelBranchInformation($idHotel, $this->context->language->id);
$this->toolbar_title[] = sprintf($this->l('Order %1$s - %2$s'), $order->reference, $objHotelBranchInformation->hotel_name);
} else {
$this->toolbar_title[] = sprintf($this->l('Order %1$s'), $order->reference);
}
$this->addMetaTitle($this->toolbar_title[count($this->toolbar_title) - 1]);
if ($order->hasBeenShipped()) {
@@ -327,6 +332,12 @@ class AdminOrdersControllerCore extends AdminController
return $res;
}
public function initModal()
{
parent::initModal();
$this->modals[] = $this->getBookingDocumentsModal();
}
public function setMedia()
{
parent::setMedia();
@@ -1540,6 +1551,9 @@ class AdminOrdersControllerCore extends AdminController
// get booking information by order
$bookingOrderInfo = $objBookingDetail->getBookingDataByOrderId($order->id);
foreach ($bookingOrderInfo as &$bookingOrderRoomInfo) {
$bookingOrderRoomInfo['num_checkin_documents'] = HotelBookingDocument::getCountByIdHtlBooking($bookingOrderRoomInfo['id']);
}
// hotel booking statuses
$htlOrderStatus = HotelBookingDetail::getAllHotelOrderStatus();
@@ -1637,6 +1651,115 @@ class AdminOrdersControllerCore extends AdminController
return parent::renderView();
}
public function getBookingDocumentsModal()
{
$modalContent = $this->context->smarty->fetch('controllers/orders/_booking_documents_modal.tpl');
// set modal details
$modal = array(
'modal_id' => 'booking-documents-modal',
'modal_class' => 'modal-md',
'modal_title' => $this->l('Documents'),
'modal_content' => $modalContent,
'modal_actions' => array(), // required to show Close button
);
return $modal;
}
public function ajaxProcessGetBookingDocuments()
{
$response = array('status' => false);
$idHtlBooking = (int) Tools::getValue('id_htl_booking');
$objHotelBookingDetail = new HotelBookingDetail($idHtlBooking);
if (Validate::isLoadedObject($objHotelBookingDetail)) {
$response['html'] = $this->getRenderedBookingDocuments($idHtlBooking);
$response['status'] = true;
}
$this->ajaxDie(json_encode($response));
}
public function ajaxProcessUploadBookingDocument()
{
$response = array('status' => false);
$idHtlBooking = (int) Tools::getValue('id_htl_booking');
$title = Tools::getValue('title');
// validations
$objHotelBookingDetail = new HotelBookingDetail($idHtlBooking);
if (!Validate::isLoadedObject($objHotelBookingDetail)) {
$this->errors[] = $this->l('Booking detail not found.');
}
if (!$title) {
$title = '--';
} else {
if (!Validate::isCatalogName($title)) {
$this->errors[] = $this->l('Please enter a valid Title.');
}
}
$objHotelBookingDocument = new HotelBookingDocument();
$objHotelBookingDocument->setFileInfoForUploadedDocument('booking_document');
if (!count($objHotelBookingDocument->fileInfo)) {
$this->errors[] = $this->l('Please select a file to upload.');
} elseif ($objHotelBookingDocument->fileInfo['size'] > Tools::getMaxUploadSize()) {
$this->errors[] = $this->l('Uploaded file size is too large.');
} elseif(!(ImageManager::isRealImage($objHotelBookingDocument->fileInfo['tmp_name'])
|| $objHotelBookingDocument->fileInfo['mime'] == 'application/pdf')
) {
$this->errors[] = $this->l('Please upload an image or a PDF file only. Allowed image formats: .gif, .jpg, .jpeg and .png');
}
if (!count($this->errors)) {
$objHotelBookingDocument = new HotelBookingDocument();
$objHotelBookingDocument->setFileInfoForUploadedDocument('booking_document');
$objHotelBookingDocument->id_htl_booking = $idHtlBooking;
$objHotelBookingDocument->title = $title;
$objHotelBookingDocument->setFileType();
if ($objHotelBookingDocument->save()) {
$objHotelBookingDocument->saveDocumentFile();
$response['html'] = $this->getRenderedBookingDocuments($idHtlBooking);
$response['num_checkin_documents'] = HotelBookingDocument::getCountByIdHtlBooking($idHtlBooking);
$response['status'] = true;
} else {
$this->errors[] = $this->l('Document upload failed.');
}
} else {
$this->context->smarty->assign(array(
'errors' => $this->errors,
));
$response['errors'] = $this->context->smarty->fetch('alerts.tpl');
$response['status'] = false;
}
$this->ajaxDie(json_encode($response));
}
public function ajaxProcessDeleteBookingDocument()
{
$response = array('status' => false);
$idHtlBookingDocument = (int) Tools::getValue('id_htl_booking_document');
$objHotelBookingDocument = new HotelBookingDocument($idHtlBookingDocument);
if (Validate::isLoadedObject($objHotelBookingDocument)) {
$idHtlBooking = $objHotelBookingDocument->id_htl_booking;
if ($objHotelBookingDocument->delete()) {
$response['html'] = $this->getRenderedBookingDocuments($idHtlBooking);
$response['num_checkin_documents'] = HotelBookingDocument::getCountByIdHtlBooking($idHtlBooking);
$response['status'] = true;
}
}
$this->ajaxDie(json_encode($response));
}
public function ajaxProcessUpdateGuestDetails()
{
$response = array(
@@ -1680,6 +1803,19 @@ class AdminOrdersControllerCore extends AdminController
$this->ajaxDie(json_encode($response));
}
private function getRenderedBookingDocuments($idHtlBooking)
{
$bookingDocuments = HotelBookingDocument::getDocumentsByIdHtlBooking($idHtlBooking);
$this->context->smarty->assign(array(
'link' => $this->context->link,
'booking_documents' => $bookingDocuments,
'pdf_icon_link' => $this->context->link->getBaseLink().'modules/hotelreservationsystem/views/img/pdf-icon.jpg',
));
return $this->context->smarty->fetch('controllers/orders/_booking_document_line.tpl');
}
public function ajaxProcessSearchProducts()
{
Context::getContext()->customer = new Customer((int)Tools::getValue('id_customer'));

View File

@@ -1308,3 +1308,197 @@ function checkTotalRefundProductQuantity(it)
if (order_discount_price)
actualizeTotalRefundVoucher();
}
$(document).on('click', '#booking-documents-modal .btn-add-new-document', function() {
BookingDocumentsModal.addNew();
BookingDocumentsForm.addNew();
});
$(document).on('click', '#booking-documents-modal [data-dismiss="alert"]', function() {
BookingDocumentsModal.hideErrors();
});
$(document).on('change', '.input-booking-document', function(e) {
e.preventDefault();
if (!this.files.length) {
$(this).remove();
return;
}
BookingDocumentsForm.updatePreview();
});
$(document).on('click', '#form-add-new-document .btn-add-file', function(e) {
e.preventDefault();
BookingDocumentsForm.openFileChooser();
});
$(document).on('click', '#form-add-new-document .btn-group-add-new .cancel', function(e) {
e.preventDefault();
BookingDocumentsForm.close();
BookingDocumentsModal.enableAddNewButton();
});
$(document).on('click', '#form-add-new-document .btn-group-add-new .upload', function(e) {
e.preventDefault();
BookingDocumentsModal.uploadDocument();
});
$(document).on('click', '#booking-documents-modal .documents-list .btn-delete-document', function(e) {
e.preventDefault();
if (confirm(txt_booking_document_delete_confirm)) {
BookingDocumentsModal.deleteDocument(this);
}
});
const BookingDocumentsModal = {
init: function(idHtlBooking, $this) {
BookingDocumentsModal.currentTr = $this;
$('#booking-documents-modal .documents-list').find('[name="id_hotel_booking"]').val(idHtlBooking);
BookingDocumentsForm.init();
BookingDocumentsModal.reset();
BookingDocumentsModal.show(idHtlBooking);
},
reset: function() {
$('#booking-documents-modal .documents-list table tbody').html('');
},
show: function(idHtlBooking) {
$('#booking-documents-modal').modal('show');
$('#form-add-new-document').find('[name="id_htl_booking"]').attr('value', idHtlBooking);
let data = {
ajax: true,
action: 'getBookingDocuments',
id_htl_booking: parseInt(idHtlBooking),
};
$.ajax({
url: admin_order_tab_link,
data: data,
type: 'POST',
dataType: 'JSON',
success: function(response) {
if (response.status) {
BookingDocumentsModal.setBodyHtml(response.html);
}
},
});
},
setBodyHtml: function(html) {
$('#booking-documents-modal .documents-list table tbody').html(html);
},
close: function() {
$('#booking-documents-modal').modal('hide');
},
addNew: function() {
BookingDocumentsModal.hideErrors();
BookingDocumentsModal.hideAddNewButton();
},
beforeSubmit: function(cb) {
BookingDocumentsModal.hideErrors(cb);
},
uploadDocument: function() {
BookingDocumentsModal.beforeSubmit(function() {
let formData = new FormData($('form#form-add-new-document').get(0));
formData.append('ajax', true);
formData.append('action', 'uploadBookingDocument');
$.ajax({
url: admin_order_tab_link,
data: formData,
processData: false,
contentType: false,
type: 'POST',
success: function(response) {
let jsonResponse = JSON.parse(response);
if (jsonResponse.status) {
showSuccessMessage(txt_booking_document_upload_success);
BookingDocumentsModal.reset();
BookingDocumentsForm.reset();
BookingDocumentsForm.resetPreview();
BookingDocumentsModal.setBodyHtml(jsonResponse.html);
BookingDocumentsModal.setDocumentsCount(jsonResponse.num_checkin_documents);
} else {
BookingDocumentsModal.showErrors(jsonResponse.errors);
}
},
});
});
},
deleteDocument: function($this) {
BookingDocumentsModal.hideErrors();
let idHtlBookingDocument = parseInt($($this).attr('data-id-htl-booking-document'));
let data = {
ajax: true,
action: 'deleteBookingDocument',
id_htl_booking_document: idHtlBookingDocument,
};
$.ajax({
url: admin_order_tab_link,
data: data,
type: 'POST',
dataType: 'JSON',
success: function(response) {
if (response.status) {
BookingDocumentsModal.setBodyHtml(response.html);
BookingDocumentsModal.setDocumentsCount(response.num_checkin_documents);
showSuccessMessage(txt_booking_document_delete_success);
}
},
});
},
showErrors: function(errors) {
$('#booking-documents-modal .errors-wrap').stop().html(errors);
$('#booking-documents-modal .errors-wrap').show(200);
},
hideErrors: function(cb) {
$('#booking-documents-modal .errors-wrap').hide(200, function() {
$('#booking-documents-modal .errors-wrap').html('');
if (typeof cb === 'function') {
cb();
}
});
},
enableAddNewButton: function() {
$('#booking-documents-modal .btn-add-new-document').show(200);
},
hideAddNewButton: function() {
$('#booking-documents-modal .btn-add-new-document').hide();
},
setDocumentsCount: function(count) {
$(BookingDocumentsModal.currentTr).find('.count-documents').html(count);
},
}
const BookingDocumentsForm = {
init: function() {
BookingDocumentsForm.inputHtml = '<input type="file" accept="image/*, .pdf" class="input-booking-document hidden" name="booking_document">';
},
reset: function() {
$('#form-add-new-document').get(0).reset();
},
resetPreview: function() {
$('#form-add-new-document .file-name').val('');
},
updatePreview: function() {
BookingDocumentsForm.resetPreview();
let input = $('#form-add-new-document').find('.input-file-wrap input');
let file = $(input).get(0).files[0];
$('#form-add-new-document .file-name').val(file.name);
},
addNew: function() {
$('#booking-documents-modal #form-add-new-document').show(200);
$('#form-add-new-document').find('.input-file-wrap').html(BookingDocumentsForm.inputHtml);
},
openFileChooser: function() {
$('#form-add-new-document').find('.input-file-wrap').html(BookingDocumentsForm.inputHtml);
$('#form-add-new-document').find('.input-file-wrap input').click();
},
close: function() {
$('#booking-documents-modal #form-add-new-document').hide(200);
},
}

View File

@@ -1400,6 +1400,13 @@ class HotelBookingDetail extends ObjectModel
);
}
public static function getIdHotelByIdOrder($idOrder)
{
return Db::getInstance()->getValue(
'SELECT `id_hotel` FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `id_order` = '.(int) $idOrder
);
}
/**
* [updateBookingOrderStatusBYOrderId :: To update the order status of a room in the booking].
* @param [int] $order_id [Id of the order]

View File

@@ -0,0 +1,218 @@
<?php
/**
* 2010-2023 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through LICENSE.txt file inside our module
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to CustomizationPolicy.txt file inside our module for more information.
*
* @author Webkul IN
* @copyright 2010-2023 Webkul IN
* @license LICENSE.txt
*/
class HotelBookingDocument extends ObjectModel
{
public $id_htl_booking_document;
public $id_htl_booking;
public $title;
public $file_type;
public $file_name;
public $date_add;
const FILE_TYPE_IMAGE = 1;
const FILE_TYPE_PDF = 2;
const DOWNLOAD_FILE_PREFIX = 'checkin_document_';
protected static $accessRights = 0775;
public static $definition = array(
'table' => 'htl_booking_document',
'primary' => 'id_htl_booking_document',
'fields' => array(
'id_htl_booking' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'title' => array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName'),
'file_type' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'file_name' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
),
);
public function __construct($id = null)
{
$this->file_name = '';
parent::__construct($id);
$this->documentsBaseDir = _PS_MODULE_DIR_.'hotelreservationsystem/documents/booking_guests/';
$this->sourceIndexFile = $this->documentsBaseDir.'index.php';
}
public function save($null_values = false, $auto_date = true)
{
parent::save($null_values, $auto_date);
if ($this->id) {
$this->setFileName();
return $this->update();
}
return false;
}
public static function getDocumentsByIdHtlBooking($idHtlBooking)
{
return Db::getInstance()->executeS(
'SELECT *
FROM `'._DB_PREFIX_.'htl_booking_document`
WHERE `id_htl_booking` = '.(int) $idHtlBooking
);
}
public static function getCountByIdHtlBooking($idHtlBooking)
{
return (int) Db::getInstance()->getValue(
'SELECT COUNT(*)
FROM `'._DB_PREFIX_.'htl_booking_document`
WHERE `id_htl_booking` = '.(int) $idHtlBooking
);
}
public function setFileInfoForUploadedDocument($fileName)
{
$this->fileInfo = Tools::fileAttachment($fileName, false);
}
public function saveDocumentFile()
{
if (!$this->id) {
return false;
}
$this->setDocumentFolder();
$this->createDocumentFolder();
@move_uploaded_file($this->fileInfo['tmp_name'], $this->getDestinationFilePath());
}
public function setDocumentFolder()
{
if (!isset($this->documentFolder)) {
$this->documentFolder = $this->documentsBaseDir.Image::getImgFolderStatic($this->id);
}
}
public function createDocumentFolder()
{
if (!file_exists($this->documentFolder)) {
// Trying both methods for setting access rights
$mkdir = @mkdir($this->documentFolder, self::$accessRights, true);
$chmod = @chmod($this->documentFolder, self::$accessRights);
// Copy index.php file in the new folder
if (($mkdir || $chmod)
&& !file_exists($this->documentFolder.'index.php')
&& file_exists($this->sourceIndexFile)
) {
return @copy($this->sourceIndexFile, $this->documentFolder.'index.php');
}
}
return true;
}
public function getDestinationFilePath()
{
$fileExtension = pathinfo($this->fileInfo['rename'], PATHINFO_EXTENSION);
return $this->documentFolder.$this->id.'.'.$fileExtension;
}
public function setFileType()
{
if (ImageManager::isRealImage($this->fileInfo['tmp_name'])) {
$this->file_type = self::FILE_TYPE_IMAGE;
} elseif ($this->fileInfo['mime'] == 'application/pdf') {
$this->file_type = self::FILE_TYPE_PDF;
} else {
$this->file_type = 0;
}
}
public function setFileName()
{
$fileExtension = pathinfo($this->fileInfo['rename'], PATHINFO_EXTENSION);
$this->file_name = $this->id.'.'.$fileExtension;
}
public function getContentType()
{
$file = $this->getPhysicalPath();
$contentType = 'application/octet-stream';
if (function_exists('finfo_open')) {
$fileInfo = @finfo_open(FILEINFO_MIME);
$contentType = @finfo_file($fileInfo, $file);
@finfo_close($fileInfo);
} elseif (function_exists('mime_content_type')) {
$contentType = @mime_content_type($file);
} elseif (function_exists('exec')) {
$contentType = trim(@exec('file -b --mime-type '.escapeshellarg($file)));
if (!$contentType) {
$contentType = trim(@exec('file --mime '.escapeshellarg($file)));
}
if (!$contentType) {
$contentType = trim(@exec('file -bi '.escapeshellarg($file)));
}
}
return $contentType;
}
public function getContentLength()
{
$file = $this->getPhysicalPath();
if (Tools::file_exists_cache($file)) {
return filesize($file);
}
return 0;
}
public function getPhysicalPath()
{
$this->setDocumentFolder();
return $this->documentFolder.$this->file_name;
}
public function getDownloadFileName()
{
$objHotelBookingDetail = new HotelBookingDetail($this->id_htl_booking);
$fileExtension = pathinfo($this->file_name, PATHINFO_EXTENSION);
return self::DOWNLOAD_FILE_PREFIX.$this->id_htl_booking_document.'_'.date('YmdHis').'.'.$fileExtension;
}
public function deleteDocumentFolder()
{
$this->setDocumentFolder();
return Tools::deleteDirectory($this->documentFolder);
}
public function delete()
{
$this->deleteDocumentFolder();
return parent::delete();
}
}

View File

@@ -180,6 +180,16 @@ class HotelReservationSystemDb
PRIMARY KEY (`id`)
) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;",
"CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_booking_document` (
`id_htl_booking_document` int(11) NOT NULL AUTO_INCREMENT,
`id_htl_booking` int(11) NOT NULL,
`title` varchar(32) NOT NULL DEFAULT '',
`file_type` tinyint(1) NOT NULL DEFAULT '0',
`file_name` varchar(8) NOT NULL DEFAULT '',
`date_add` datetime NOT NULL,
PRIMARY KEY (`id_htl_booking_document`)
) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;",
"CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_booking_demands` (
`id_booking_demand` int(11) NOT NULL AUTO_INCREMENT,
`id_htl_booking` int(11) NOT NULL,
@@ -471,6 +481,7 @@ class HotelReservationSystemDb
`'._DB_PREFIX_.'htl_features_lang`,
`'._DB_PREFIX_.'htl_cart_booking_data`,
`'._DB_PREFIX_.'htl_booking_detail`,
`'._DB_PREFIX_.'htl_booking_document`,
`'._DB_PREFIX_.'htl_booking_demands`,
`'._DB_PREFIX_.'htl_booking_demands_tax`,
`'._DB_PREFIX_.'htl_room_status`,

View File

@@ -0,0 +1,61 @@
<?php
/**
* 2010-2023 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through LICENSE.txt file inside our module
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to CustomizationPolicy.txt file inside our module for more information.
*
* @author Webkul IN
* @copyright 2010-2023 Webkul IN
* @license LICENSE.txt
*/
class AdminBookingDocumentController extends ModuleAdminController
{
public function processGetDocument()
{
$idHtlBookingDocument = (int) Tools::getValue('id_document');
$objHotelBookingDocument = new HotelBookingDocument($idHtlBookingDocument);
if (Validate::isLoadedObject($objHotelBookingDocument)) {
Hook::exec('actionDownloadBookingDocument', array('attachment' => &$objHotelBookingDocument));
$contentType = $objHotelBookingDocument->getContentType();
$contentLength = $objHotelBookingDocument->getContentLength();
$filePath = $objHotelBookingDocument->getPhysicalPath();
$downloadFileName = $objHotelBookingDocument->getDownloadFileName();
$contentDisposition = Tools::getValue('is_preview') ? 'inline' : 'attachment';
if (Tools::file_exists_cache($filePath)) {
if (ob_get_level() && ob_get_length() > 0) {
ob_end_clean();
}
header('Content-Transfer-Encoding: binary');
header('Content-Type: '.$contentType);
header('Content-Length: '.$contentLength);
header('Content-Disposition: '.$contentDisposition.'; filename="'.$downloadFileName.'"');
@set_time_limit(0);
readfile($filePath);
}
exit;
}
header('HTTP/1.1 404 Not Found');
header('Status: 404 Not Found');
}
public function postProcess()
{
parent::postProcess();
exit;
}
}

View File

@@ -47,6 +47,7 @@ require_once 'classes/HotelRoomDisableDates.php';
require_once 'classes/HotelBranchRefundRules.php';
require_once 'classes/HotelSettingsLink.php';
require_once 'classes/HotelBookingDocument.php';
// Web services classes
require_once 'classes/WebserviceSpecificManagementQlo.php';

View File

@@ -0,0 +1 @@
Deny from all

View File

@@ -0,0 +1,29 @@
<?php
/**
* 2010-2023 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through LICENSE.txt file inside our module
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to CustomizationPolicy.txt file inside our module for more information.
*
* @author Webkul IN
* @copyright 2010-2023 Webkul IN
* @license LICENSE.txt
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,29 @@
<?php
/**
* 2010-2023 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through LICENSE.txt file inside our module
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to CustomizationPolicy.txt file inside our module for more information.
*
* @author Webkul IN
* @copyright 2010-2023 Webkul IN
* @license LICENSE.txt
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -367,6 +367,7 @@ class HotelReservationSystem extends Module
$this->installTab('AdminHotelFeaturePricesSettings', 'Advanced Price Rules', false, false);
$this->installTab('AdminRoomTypeGlobalDemand', 'Additional Demand Configuration', false, false);
$this->installTab('AdminAssignHotelFeatures', 'Assign Hotel Features', false, false);
$this->installTab('AdminBookingDocument', 'Booking Documents', false, false);
return true;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB