Fixed: KPI access is now under employee permission in back-office

Co-authored-by: Name <sumit201@webkul.in>
This commit is contained in:
shazar rahman
2026-06-12 17:50:59 +05:30
parent a27e55c049
commit 653fdf3f7f
203 changed files with 9719 additions and 1593 deletions

View File

@@ -2024,6 +2024,16 @@ class AdminProductsControllerCore extends AdminController
$this->errors[] = $error;
}
if (!count($this->errors)) {
$objHotelRoomType = new HotelRoomType();
if ($roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($this->object->id)) {
$objHotelBranchInformation = new HotelBranchInformation((int)$roomTypeInfo['id_hotel']);
if (!$objHotelBranchInformation->active && !$this->object->active) {
$this->errors[] = $this->l('Room type can not be active as long as hotel is disabled.');
}
}
}
if (count($this->errors)) {
return false;
}
@@ -2041,6 +2051,61 @@ class AdminProductsControllerCore extends AdminController
return $res;
}
public function processBulkStatusSelection($status)
{
if (!is_array($this->boxes) || empty($this->boxes)) {
return parent::processBulkStatusSelection($status);
}
$disabledHotelRoomTypes = array();
$objHotelRoomType = new HotelRoomType();
$result = true;
$hasSuccessfulUpdate = false;
foreach ($this->boxes as $id) {
$id = (int) $id;
$object = new $this->className($id);
if (!Validate::isLoadedObject($object)) {
$this->errors[] = sprintf($this->l('Invalid room type ID %d.'), $id);
$result = false;
continue;
}
if ($status && ($roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($id))) {
$objHotelBranchInformation = new HotelBranchInformation((int) $roomTypeInfo['id_hotel']);
if (!$objHotelBranchInformation->active) {
$disabledHotelRoomTypes[] = Product::getProductName($id, null, (int)$this->context->language->id);
continue;
}
}
$object->setFieldsToUpdate(array('active' => true));
$object->active = (int) $status;
$isUpdated = (bool) $object->update();
$result = $result && $isUpdated;
$hasSuccessfulUpdate = $hasSuccessfulUpdate || $isUpdated;
if (!$isUpdated) {
$this->errors[] = sprintf($this->l('Can\'t update #%d status.'), $id);
}
}
if ($disabledHotelRoomTypes) {
$this->errors[] =
$this->l('Room types linked to inactive hotels cannot be enabled.');
}
if ($result && $hasSuccessfulUpdate && !$disabledHotelRoomTypes) {
$this->redirect_after = self::$currentIndex.'&conf=5&token='.$this->token;
} elseif ($result && $hasSuccessfulUpdate) {
$this->confirmations[] = $this->l('The status has been updated for the room types linked to active hotels.');
} elseif (!$result) {
$this->errors[] = $this->l('An error occurred while updating the status.');
}
return $result;
}
public function processToggleShowAtFront()
{
if (!$this->loadObject()) {
@@ -2366,6 +2431,10 @@ class AdminProductsControllerCore extends AdminController
} else if (!Validate::isLoadedObject($objHotel = new HotelBranchInformation($id_hotel))) {
$this->errors[] = Tools::displayError('Selected Hotel not found');
} else {
// Prevent enabling a room type when its hotel is disabled
if ((int)Tools::getValue('active') === 1 && isset($objHotel) && !$objHotel->active) {
$this->errors[] = Tools::displayError('Room type can not be active as long as hotel is disabled.');
}
$hotelIdCategory = $objHotel->id_category;
if (Validate::isLoadedObject($objCategory = new Category($hotelIdCategory))) {
foreach($objCategory->getParentsCategories() as $category) {
@@ -3407,10 +3476,6 @@ class AdminProductsControllerCore extends AdminController
}
if ($baseChildren == '' || !Validate::isUnsignedInt($baseChildren)) {
$this->errors[] = Tools::displayError('Invalid base children');
} else if (Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM')) {
if ($baseChildren > Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM')) {
$this->errors[] = sprintf(Tools::displayError('Base children cannot be greater than max childern allowed in the room of this room type (Max: %s)'), Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM'));
}
}
if (!$maxAdults || !Validate::isUnsignedInt($maxAdults)) {
$this->errors[] = Tools::displayError('Invalid maximum number of adults');
@@ -3425,10 +3490,6 @@ class AdminProductsControllerCore extends AdminController
$this->errors[] = Tools::displayError('Maximum number of children cannot be less than base children');
} elseif ($maxChildren >= $maxGuests) {
$this->errors[] = Tools::displayError('Maximum number of children cannot be more or equal than maximum number of guests.(1 adult is mandatory in a room)');
} else if (Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM')) {
if ($maxChildren > Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM')) {
$this->errors[] = sprintf(Tools::displayError('Maximum number of children cannot be greater than max childern allowed in the room of this room type (Max: %s)'), Configuration::get('WK_GLOBAL_MAX_CHILD_IN_ROOM'));
}
}
if (!$maxGuests || !Validate::isUnsignedInt($maxGuests)) {
$this->errors[] = Tools::displayError('Invalid maximum number of guests');