Resolve merge conflicts

This commit is contained in:
Abhishek Kumar
2022-11-30 19:39:37 +05:30
2885 changed files with 5490 additions and 106364 deletions

View File

@@ -112,6 +112,7 @@ class AdminProductsControllerCore extends AdminController
'Warehouses' => $this->l('Warehouses'),
'Configuration' => $this->l('Configuration'),
'Occupancy' => $this->l('Occupancy'),
'LengthOfStay' => $this->l('Length of Stay'),
'Booking' => $this->l('Booking Information'),
);
@@ -133,7 +134,8 @@ class AdminProductsControllerCore extends AdminController
//'Suppliers' => 13,
'Configuration' => 14,
'Occupancy' => 15,
'Booking' => 16,
'LengthOfStay' => 16,
'Booking' => 17,
));
}
@@ -1590,7 +1592,9 @@ class AdminProductsControllerCore extends AdminController
_PS_JS_DIR_.'admin/products.js',
));
if ($this->display == 'edit' || $this->display == 'add') {
if (in_array($this->display, array('add', 'edit'))
&& $this->tabAccess[$this->display] == '1'
) {
$this->addJqueryUI(array(
'ui.core',
'ui.widget'
@@ -2223,6 +2227,9 @@ class AdminProductsControllerCore extends AdminController
if ($this->isTabSubmitted('Occupancy')) {
$this->processOccupancy();
}
if ($this->isTabSubmitted('LengthOfStay')) {
$this->processLengthOfStay();
}
if ($this->isTabSubmitted('Configuration')) {
$this->processConfiguration();
}
@@ -2695,8 +2702,6 @@ class AdminProductsControllerCore extends AdminController
// used to build the new url when changing category
$this->tpl_list_vars['base_url'] = preg_replace('#&id_category=[0-9]*#', '', self::$currentIndex).'&token='.$this->token;
}
// @todo module free
$this->tpl_form_vars['vat_number'] = file_exists(_PS_MODULE_DIR_.'vatnumber/ajax.php');
parent::initContent();
}
@@ -2706,8 +2711,6 @@ class AdminProductsControllerCore extends AdminController
$time = time();
$kpis = array();
/* The data generation is located in AdminStatsControllerCore */
// if (Configuration::get('PS_STOCK_MANAGEMENT')) {
// $helper = new HelperKpi();
// $helper->id = 'box-products-stock';
@@ -2729,12 +2732,8 @@ class AdminProductsControllerCore extends AdminController
$helper->icon = 'icon-tags';
$helper->color = 'color2';
$helper->title = $this->l('Average Gross Margin %', null, null, false);
if (ConfigurationKPI::get('PRODUCT_AVG_GROSS_MARGIN') !== false) {
$helper->value = ConfigurationKPI::get('PRODUCT_AVG_GROSS_MARGIN');
}
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=product_avg_gross_margin';
$helper->tooltip = $this->l('Gross margin expressed in percentage assesses how cost-effectively you sell your room types. Out of $100, you will retain $X to cover profit and expenses.', null, null, false);
$helper->refresh = (bool)(ConfigurationKPI::get('PRODUCT_AVG_GROSS_MARGIN_EXPIRE') < $time);
$kpis[] = $helper->generate();
$helper = new HelperKpi();
@@ -2743,12 +2742,8 @@ class AdminProductsControllerCore extends AdminController
$helper->color = 'color3';
$helper->title = $this->l('Purchased References', null, null, false);
$helper->subtitle = $this->l('30 days', null, null, false);
if (ConfigurationKPI::get('8020_SALES_CATALOG') !== false) {
$helper->value = ConfigurationKPI::get('8020_SALES_CATALOG');
}
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=8020_sales_catalog';
$helper->tooltip = $this->l('X% of your references have been purchased for the past 30 days', null, null, false);
$helper->refresh = (bool)(ConfigurationKPI::get('8020_SALES_CATALOG_EXPIRE') < $time);
$helper->tooltip = $this->l('X% of your references have been purchased for the past 30 days.', null, null, false);
if (Module::isInstalled('statsbestproducts')) {
$helper->href = Context::getContext()->link->getAdminLink('AdminStats').'&module=statsbestproducts&datepickerFrom='.date('Y-m-d', strtotime('-30 days')).'&datepickerTo='.date('Y-m-d');
}
@@ -2760,12 +2755,8 @@ class AdminProductsControllerCore extends AdminController
$helper->color = 'color4';
$helper->href = $this->context->link->getAdminLink('AdminProducts');
$helper->title = $this->l('Disabled Room Types', null, null, false);
if (ConfigurationKPI::get('DISABLED_PRODUCTS') !== false) {
$helper->value = ConfigurationKPI::get('DISABLED_PRODUCTS');
}
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=disabled_products';
$helper->refresh = (bool)(ConfigurationKPI::get('DISABLED_PRODUCTS_EXPIRE') < $time);
$helper->tooltip = $this->l('X% of your room types are disabled and not visible to your customers', null, null, false);
$helper->tooltip = $this->l('X% of your room types are disabled and not visible to your customers.', null, null, false);
$helper->href = Context::getContext()->link->getAdminLink('AdminProducts').'&productFilter_active=0&submitFilterproduct=1';
$kpis[] = $helper->generate();
@@ -3487,6 +3478,141 @@ class AdminProductsControllerCore extends AdminController
}
}
// send information for the length of stay tab
public function initFormLengthOfStay($product)
{
$data = $this->createTemplate($this->tpl_form);
if ($product->id) {
if ($this->product_exists_in_shop) {
// Check if any hotel is created or not
$objRoomType = new HotelRoomType();
if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($product->id)) {
if ($roomTypeInfo['id_hotel']) {
// send length of stay date ranges for this room type
$objRoomTypeRestrictionDates = new HotelRoomTypeRestrictionDateRange();
$roomTypeInfo['restrictionDataRange'] = $objRoomTypeRestrictionDates->getRoomTypeLengthOfStayRestriction($product->id);
$smartyVars['roomTypeInfo'] = $roomTypeInfo;
} else {
$this->displayWarning($this->l('No hotel is attached to this room type.'));
}
} else {
$this->displayWarning($this->l('Room type information is missing.'));
}
} else {
$this->displayWarning($this->l('You must save room type before managing length of stay.'));
}
} else {
$this->displayWarning($this->l('You must save room type before managing length of stay.'));
}
$smartyVars['product'] = $product;
$data->assign($smartyVars);
$this->tpl_form_vars['custom_form'] = $data->fetch();
}
public function processLengthOfStay()
{
if ($this->tabAccess['edit'] == 1) {
$idProduct = Tools::getValue('id_product');
if (Validate::isLoadedObject($product = new Product((int)$idProduct))) {
$objRoomType = new HotelRoomType();
if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($idProduct)) {
$roomTypeMinLos = Tools::getValue('min_los');
$roomTypeMaxLos = Tools::getValue('max_los');
// validate length of stay global values for room type
if (!$roomTypeMinLos || $roomTypeMinLos == null) {
$this->errors[] = Tools::displayError('Global minimum length of stay is a required field.');
} elseif (!Validate::isUnsignedInt($roomTypeMinLos)) {
$this->errors[] = Tools::displayError('Global minimum length of stay value is invalid. Please enter integer value. Set 1 day incase of setting no limit on global minimum length of stay.');
}
if ($roomTypeMaxLos == null) {
$this->errors[] = Tools::displayError('Global maximum length of stay is a required field.');
} elseif (!Validate::isUnsignedInt($roomTypeMaxLos)) {
$this->errors[] = Tools::displayError('Invalid value entered for global maximum length of stay field. Please enter integer value. Set 0 day incase of setting no limit on maximum length of stay.');
} elseif ($roomTypeMinLos && $roomTypeMaxLos > 0 && ($roomTypeMinLos > $roomTypeMaxLos)) {
$this->errors[] = Tools::displayError('Value of global maximum length of stay must be greater than global minimum length of stay.');
}
if (Tools::getValue('active_restriction_dates')) {
if (Tools::getValue('restriction_date_from') && Tools::getValue('restriction_date_to')) {
$objRoomTypeRestrictDateRange = new HotelRoomTypeRestrictionDateRange();
$dateFromRestriction = Tools::getValue('restriction_date_from');
$dateToRestriction = Tools::getValue('restriction_date_to');
$minLosDays = Tools::getValue('restriction_min_los');
$maxLosDays = Tools::getValue('restriction_max_los');
$this->errors = array_merge($this->errors, $objRoomTypeRestrictDateRange->validateRoomTypeLengthOfStayRestriction($dateFromRestriction, $dateToRestriction, $minLosDays, $maxLosDays));
} else {
$this->errors[] = Tools::displayError('Please add at least one Minimum & maximum length of stay restriction for date range if \'Length of stay for date ranges\' option is enable.');
}
}
if (!$this->errors) {
$objRoomType = new HotelRoomType($roomTypeInfo['id']);
$objRoomType->min_los = $roomTypeMinLos;
$objRoomType->max_los = $roomTypeMaxLos;
if ($objRoomType->save()) {
if (Tools::getValue('active_restriction_dates') && Tools::getValue('restriction_date_from')) {
// @ToDo: we should validate this room type restriction ids belongs to this room type
$idRoomTypeRestriction = Tools::getValue('id_rt_restriction');
foreach ($dateFromRestriction as $restrictionKey => $dateFrom) {
// change into database compatible format
$dateFrom = date('Y-m-d', strtotime($dateFrom));
$dateTo = date('Y-m-d', strtotime($dateToRestriction[$restrictionKey]));
if ($idRoomTypeRestriction[$restrictionKey]) {
$objRoomTypeRestrictDateRange = new HotelRoomTypeRestrictionDateRange($idRoomTypeRestriction[$restrictionKey]);
} else {
$objRoomTypeRestrictDateRange = new HotelRoomTypeRestrictionDateRange();
}
$objRoomTypeRestrictDateRange->id_product = $idProduct;
$objRoomTypeRestrictDateRange->date_from = $dateFrom;
$objRoomTypeRestrictDateRange->date_to = $dateTo;
$objRoomTypeRestrictDateRange->min_los = $minLosDays[$restrictionKey];
$objRoomTypeRestrictDateRange->max_los = $maxLosDays[$restrictionKey];
$objRoomTypeRestrictDateRange->save();
}
} else {
// if disabled length of stay for date ranges then delete all previously saved
$objRoomTypeRestrictDateRange = new HotelRoomTypeRestrictionDateRange();
if ($losRestrictions = $objRoomTypeRestrictDateRange->getRoomTypeLengthOfStayRestriction($idProduct)) {
foreach ($losRestrictions as $losDate) {
$objRoomTypeRestrictDateRange = new HotelRoomTypeRestrictionDateRange($losDate['id_rt_restriction']);
$objRoomTypeRestrictDateRange->delete();
}
}
}
} else {
$this->errors[] = Tools::displayError('Something went wrong while saving global minimum & maximum length of stay values. Please try again !!');
}
}
}
}
} else {
$this->errors[] = Tools::displayError('You do not have the right permission.');
}
}
// delete the rows of length of stay on date range
public function ajaxProcessDeleteRoomTypeLengthOfStayRestriction()
{
if ($this->tabAccess['edit'] == 1) {
$objRoomTypeRestrictionDates = new HotelRoomTypeRestrictionDateRange(Tools::getValue('id_rt_restriction'));
if ($objRoomTypeRestrictionDates->delete()) {
die(json_encode(array('success' => $this->l('Successfully deleted'))));
} else {
die(json_encode(array('error' => $this->l('Something went wrong. Please reload the page and try again !!'))));
}
} else {
die(json_encode(array('error' => $this->l('You do not have the right permission'))));
}
}
public function validateDisableDateRanges($disableDates)
{
if (count($disableDates)) {
@@ -5497,7 +5623,6 @@ class AdminProductsControllerCore extends AdminController
public function getModalDuplicateOptions()
{
$tpl = $this->createTemplate('modal-duplicate-options.tpl');
$idsHotel = HotelBranchInformation::getProfileAccessedHotels($this->context->employee->id_profile, 1, 1);
$hotelsInfo = array();
foreach ($idsHotel as $idHotel) {
@@ -5513,13 +5638,15 @@ class AdminProductsControllerCore extends AdminController
$hotelsInfo[] = $hotelInfo;
}
}
$formAction = $this->context->link->getAdminLink('AdminProducts', true).'&duplicateproduct';
$tpl->assign(array(
$this->context->smarty->assign(array(
'action' => $formAction,
'hotels_info' => $hotelsInfo,
'duplicate_images' => 1,
));
$modalContent = $this->context->smarty->fetch('controllers/products/modal-duplicate-options.tpl');
$modalActions = array(
array(
'type' => 'button',
@@ -5534,9 +5661,10 @@ class AdminProductsControllerCore extends AdminController
'modal_id' => 'modal-duplicate-options',
'modal_class' => 'modal-md',
'modal_title' => $this->l('Duplication options'),
'modal_content' => $tpl->fetch(),
'modal_content' => $modalContent,
'modal_actions' => $modalActions,
);
return $modal;
}