Merge branch 'Qloapps:develop' into gli-2934
This commit is contained in:
@@ -220,6 +220,40 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{if $hotels.unselected|@count + $hotels.selected|@count > 1}
|
||||
<p class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" id="hotel_restriction" name="hotel_restriction" value="1" {if $hotels.unselected|@count}checked="checked"{/if} />
|
||||
{l s='Hotel selection'}
|
||||
</label>
|
||||
</p>
|
||||
<div id="hotel_restriction_div">
|
||||
<br />
|
||||
<table class="table">
|
||||
<tr>
|
||||
<td>
|
||||
<p>{l s='Unselected hotels'}</p>
|
||||
<select id="hotel_select_1" class="input-large" multiple>
|
||||
{foreach from=$hotels.unselected item='hotel'}
|
||||
<option value="{$hotel.id_hotel|intval}"> {$hotel.hotel_name|escape}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
<a id="hotel_select_add" class="btn btn-default btn-block clearfix" >{l s='Add'} <i class="icon-arrow-right"></i></a>
|
||||
</td>
|
||||
<td>
|
||||
<p>{l s='Selected hotels'}</p>
|
||||
<select name="hotel_select[]" class="input-large" id="hotel_select_2" multiple>
|
||||
{foreach from=$hotels.selected item='hotel'}
|
||||
<option value="{$hotel.id_hotel|intval}"> {$hotel.hotel_name|escape}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
<a id="hotel_select_remove" class="btn btn-default btn-block clearfix" ><i class="icon-arrow-left"></i> {l s='Remove'}</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{if $cart_rules.unselected|@count + $cart_rules.selected|@count > 0}
|
||||
<p class="checkbox">
|
||||
<label>
|
||||
|
||||
@@ -147,7 +147,7 @@ function updateProductRuleShortDescription(item)
|
||||
$('#' + id2 + '_match').val(length);
|
||||
}
|
||||
|
||||
var restrictions = new Array('country', 'carrier', 'group', 'cart_rule', 'shop');
|
||||
var restrictions = new Array('country', 'carrier', 'group', 'hotel', 'cart_rule', 'shop');
|
||||
for (i in restrictions)
|
||||
{
|
||||
toggleCartRuleFilter($('#' + restrictions[i] + '_restriction'));
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
{**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License version 3.0
|
||||
* that is bundled with this package in the file LICENSE.md
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/license/osl-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 support@qloapps.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this module to a newer
|
||||
* versions in the future. If you wish to customize this module for your needs
|
||||
* please refer to https://store.webkul.com/customisation-guidelines for more information.
|
||||
*
|
||||
* @author Webkul IN
|
||||
* @copyright Since 2010 Webkul
|
||||
* @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0
|
||||
*}
|
||||
|
||||
{if $hotel_names_first}
|
||||
<span>{$hotel_names_first|escape:'html':'UTF-8'}</span>
|
||||
{if $hotel_names_remaining}
|
||||
{capture name='hotel_names_tooltip'}
|
||||
<div class="tooltip_cont">
|
||||
<div class="tip_header"><div class="tip_date">{l s='Selected Hotels'}</div></div>
|
||||
<ul>
|
||||
{foreach from=$selected_hotels item='hotel'}
|
||||
<li class="tip_element_value">{$hotel|escape:'html':'UTF-8'}</li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
</div>
|
||||
{/capture}
|
||||
{capture name='hotel_names_tooltip_title'}<span class="badge tooltip-trigger">+{$hotel_names_remaining|@count}</span>{/capture}
|
||||
{include file='helpers/tooltip.tpl' tooltip_content=$smarty.capture.hotel_names_tooltip tooltip_title=$smarty.capture.hotel_names_tooltip_title}
|
||||
{/if}
|
||||
{else}
|
||||
--
|
||||
{/if}
|
||||
@@ -0,0 +1,24 @@
|
||||
{**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License version 3.0
|
||||
* that is bundled with this package in the file LICENSE.md
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/license/osl-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 support@qloapps.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this module to a newer
|
||||
* versions in the future. If you wish to customize this module for your needs
|
||||
* please refer to https://store.webkul.com/customisation-guidelines for more information.
|
||||
*
|
||||
* @author Webkul IN
|
||||
* @copyright Since 2010 Webkul
|
||||
* @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0
|
||||
*}
|
||||
|
||||
{l s='Total credit slip amount for this order:'} <strong><span id="booking-total-slip-amount">-</span></strong><br>
|
||||
<span id="booking-slip-ids-wrapper" style="display:none;">{l s='Credit slip generated for this order: '} <strong><span id="booking-slip-ids"></span></strong></span>
|
||||
@@ -0,0 +1,25 @@
|
||||
{**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License version 3.0
|
||||
* that is bundled with this package in the file LICENSE.md
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/license/osl-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 support@qloapps.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this module to a newer
|
||||
* versions in the future. If you wish to customize this module for your needs
|
||||
* please refer to https://store.webkul.com/customisation-guidelines for more information.
|
||||
*
|
||||
* @author Webkul IN
|
||||
* @copyright Since 2010 Webkul
|
||||
* @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0
|
||||
*}
|
||||
|
||||
{l s='Total room price:'} <strong><span id="booking-room-amount">-</span></strong><br>
|
||||
{l s='Total service price:'} <strong><span id="booking-service-amount">-</span></strong><br>
|
||||
{l s='Total room booking price:'} <strong><span id="booking-amount">-</span></strong><br>
|
||||
@@ -0,0 +1,27 @@
|
||||
{**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License version 3.0
|
||||
* that is bundled with this package in the file LICENSE.md
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/license/osl-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 support@qloapps.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this module to a newer
|
||||
* versions in the future. If you wish to customize this module for your needs
|
||||
* please refer to https://store.webkul.com/customisation-guidelines for more information.
|
||||
*
|
||||
* @author Webkul IN
|
||||
* @copyright Since 2010 Webkul
|
||||
* @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0
|
||||
*}
|
||||
|
||||
{if $id_order}
|
||||
<a class="btn btn-link" href="{$link->getAdminLink('AdminOrders')|escape:'html':'UTF-8'}&id_order={$id_order}&vieworder" target="_blank">
|
||||
#{$id_order}
|
||||
</a>
|
||||
{/if}
|
||||
@@ -24,6 +24,8 @@
|
||||
<a class="btn btn-link" href="{$link->getAdminLink('AdminCartRules')|escape:'html':'UTF-8'}&updatecart_rule&id_cart_rule={$id_cart_rule}" target="_blank">
|
||||
#{$id_cart_rule}
|
||||
</a>
|
||||
{elseif $row['redeem_status'] == OrderSlip::REDEEM_STATUS_REDEEMED}
|
||||
--
|
||||
{else}
|
||||
<a href="{$link->getAdminLink('AdminSlip')|escape:'html':'UTF-8'}&generateVoucher=1&id_order_slip={$row['id_order_slip']}" class="btn btn-default" title="{l s='Generate voucher for credit slip'}">
|
||||
<i class="icon-refresh"></i> {l s='Generate Voucher'}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
{**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License version 3.0
|
||||
* that is bundled with this package in the file LICENSE.md
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/license/osl-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 support@qloapps.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this module to a newer
|
||||
* versions in the future. If you wish to customize this module for your needs
|
||||
* please refer to https://store.webkul.com/customisation-guidelines for more information.
|
||||
*
|
||||
* @author Webkul IN
|
||||
* @copyright Since 2010 Webkul
|
||||
* @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0
|
||||
*}
|
||||
|
||||
<span id="order-info" style="display:none; margin-right:15px;"></span>
|
||||
<a id="order-view-link" href="#" target="_blank" style="display:none;">
|
||||
{l s='View Order'} <i class="icon-external-link"></i>
|
||||
</a>
|
||||
<span id="order-total-amount-wrapper" style="display:none;"><br>{l s='Total order amount:'} <strong><span id="order-total-amount">-</span></strong></span>
|
||||
<span id="order-total-paid-wrapper" style="display:none;"><br>{l s='Total paid amount:'} <strong><span id="order-total-paid">-</span></strong></span>
|
||||
<span id="order-total-return-wrapper" style="display:none;"><br>{l s='Total return amount (Refund + Credit Slip):'} <strong><span id="order-total-return">-</span></strong></span>
|
||||
@@ -22,7 +22,11 @@
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"><i class="icon-remove-sign"></i></button>
|
||||
<h4 class="modal-title"><i class="icon icon-exclamation-triangle"></i> {l s='Confirm Update'}</h4>
|
||||
<p>{l s='This action is irreversable, Are you sure you want to change the status?'}</p>
|
||||
<p>
|
||||
{l s='This action is irreversible. Once the status is changed, you will not be able to create a voucher.'}
|
||||
<br>
|
||||
{l s='Are you sure you want to change the status?'}
|
||||
</p>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="row">
|
||||
|
||||
@@ -59,6 +59,7 @@ class CartRuleCore extends ObjectModel
|
||||
public $cart_rule_restriction;
|
||||
public $product_restriction;
|
||||
public $shop_restriction;
|
||||
public $hotel_restriction;
|
||||
public $free_shipping;
|
||||
public $reduction_percent;
|
||||
public $reduction_amount;
|
||||
@@ -102,6 +103,7 @@ class CartRuleCore extends ObjectModel
|
||||
'cart_rule_restriction' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'product_restriction' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'shop_restriction' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'hotel_restriction' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'free_shipping' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'reduction_percent' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPercentage'),
|
||||
'reduction_amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
|
||||
@@ -163,6 +165,7 @@ class CartRuleCore extends ObjectModel
|
||||
$r &= Db::getInstance()->delete('cart_rule_carrier', '`id_cart_rule` = '.(int)$this->id);
|
||||
$r &= Db::getInstance()->delete('cart_rule_shop', '`id_cart_rule` = '.(int)$this->id);
|
||||
$r &= Db::getInstance()->delete('cart_rule_group', '`id_cart_rule` = '.(int)$this->id);
|
||||
$r &= Db::getInstance()->delete('cart_rule_hotel', '`id_cart_rule` = '.(int)$this->id);
|
||||
$r &= Db::getInstance()->delete('cart_rule_country', '`id_cart_rule` = '.(int)$this->id);
|
||||
$r &= Db::getInstance()->delete('cart_rule_combination', '`id_cart_rule_1` = '.(int)$this->id.' OR `id_cart_rule_2` = '.(int)$this->id);
|
||||
$r &= Db::getInstance()->delete('cart_rule_product_rule_group', '`id_cart_rule` = '.(int)$this->id);
|
||||
@@ -355,6 +358,28 @@ class CartRuleCore extends ObjectModel
|
||||
unset($result[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove cart rule if the cart contains a product from a hotel not covered by its hotel restriction
|
||||
foreach ($result as $key => $cart_rule) {
|
||||
if ($cart_rule['hotel_restriction']) {
|
||||
$total_cart_products = (int)Db::getInstance()->getValue('
|
||||
SELECT COUNT(cp.id_product)
|
||||
FROM '._DB_PREFIX_.'cart_product cp
|
||||
WHERE cp.id_cart = '.(int)$cart->id
|
||||
);
|
||||
$allowed_cart_products = (int)Db::getInstance()->getValue('
|
||||
SELECT COUNT(cp.id_product)
|
||||
FROM '._DB_PREFIX_.'cart_product cp
|
||||
INNER JOIN '._DB_PREFIX_.'htl_room_type hrt ON hrt.id_product = cp.id_product
|
||||
INNER JOIN '._DB_PREFIX_.'cart_rule_hotel crh ON crh.id_hotel = hrt.id_hotel
|
||||
WHERE crh.id_cart_rule = '.(int)$cart_rule['id_cart_rule'].'
|
||||
AND cp.id_cart = '.(int)$cart->id
|
||||
);
|
||||
if (!$total_cart_products || $total_cart_products != $allowed_cart_products) {
|
||||
unset($result[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result_bak = $result;
|
||||
@@ -637,6 +662,26 @@ class CartRuleCore extends ObjectModel
|
||||
}
|
||||
}
|
||||
|
||||
// Check if all the products in the cart belong to the restricted hotel(s)
|
||||
if ($this->hotel_restriction) {
|
||||
$total_cart_products = (int)Db::getInstance()->getValue('
|
||||
SELECT COUNT(cp.id_product)
|
||||
FROM '._DB_PREFIX_.'cart_product cp
|
||||
WHERE cp.id_cart = '.(int)$context->cart->id
|
||||
);
|
||||
$allowed_cart_products = (int)Db::getInstance()->getValue('
|
||||
SELECT COUNT(cp.id_product)
|
||||
FROM '._DB_PREFIX_.'cart_product cp
|
||||
INNER JOIN '._DB_PREFIX_.'htl_room_type hrt ON hrt.id_product = cp.id_product
|
||||
INNER JOIN '._DB_PREFIX_.'cart_rule_hotel crh ON crh.id_hotel = hrt.id_hotel
|
||||
WHERE crh.id_cart_rule = '.(int)$this->id.'
|
||||
AND cp.id_cart = '.(int)$context->cart->id
|
||||
);
|
||||
if (!$total_cart_products || $total_cart_products != $allowed_cart_products) {
|
||||
return (!$display_error) ? false : Tools::displayError('You cannot use this voucher with the selected hotels');
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the products chosen by the customer are usable with the cart rule
|
||||
if ($this->product_restriction) {
|
||||
$r = $this->checkProductRestrictions($context, false, $display_error, $alreadyInCart);
|
||||
@@ -1370,6 +1415,49 @@ class CartRuleCore extends ObjectModel
|
||||
return $array;
|
||||
}
|
||||
|
||||
public function getHotelRestrictions($id_profile = null)
|
||||
{
|
||||
$array = array('selected' => array(), 'unselected' => array());
|
||||
$id_lang = (int)Context::getContext()->language->id;
|
||||
|
||||
$hotel_access_condition = '';
|
||||
if ($id_profile) {
|
||||
$accessible_hotels = HotelBranchInformation::getProfileAccessedHotels($id_profile, 1, 1);
|
||||
if (!empty($accessible_hotels)) {
|
||||
$hotel_access_condition = ' AND hbi.`id` IN ('.implode(',', array_map('intval', $accessible_hotels)).')';
|
||||
}
|
||||
}
|
||||
|
||||
if (!Validate::isLoadedObject($this) || $this->hotel_restriction == 0) {
|
||||
$array['selected'] = Db::getInstance()->executeS('
|
||||
SELECT hbi.`id` AS id_hotel, hbl.`hotel_name`, 1 AS selected
|
||||
FROM `'._DB_PREFIX_.'htl_branch_info` hbi
|
||||
LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbl
|
||||
ON (hbl.`id` = hbi.`id` AND hbl.`id_lang` = '.$id_lang.')
|
||||
WHERE hbi.`active` = 1'.$hotel_access_condition.'
|
||||
ORDER BY hbl.`hotel_name` ASC
|
||||
');
|
||||
} else {
|
||||
$resource = Db::getInstance()->query('
|
||||
SELECT hbi.`id` AS id_hotel, hbl.`hotel_name`,
|
||||
IF(crh.id_hotel IS NULL, 0, 1) AS selected
|
||||
FROM `'._DB_PREFIX_.'htl_branch_info` hbi
|
||||
LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbl
|
||||
ON (hbl.`id` = hbi.`id` AND hbl.`id_lang` = '.$id_lang.')
|
||||
LEFT JOIN (
|
||||
SELECT id_hotel FROM `'._DB_PREFIX_.'cart_rule_hotel`
|
||||
WHERE id_cart_rule = '.(int)$this->id.'
|
||||
) crh ON hbi.`id` = crh.id_hotel
|
||||
WHERE hbi.`active` = 1'.$hotel_access_condition.'
|
||||
ORDER BY hbl.`hotel_name` ASC
|
||||
');
|
||||
while ($row = Db::getInstance()->nextRow($resource)) {
|
||||
$array[$row['selected'] ? 'selected' : 'unselected'][] = $row;
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
public static function autoRemoveFromCart($context = null)
|
||||
{
|
||||
if (!$context) {
|
||||
|
||||
@@ -1038,12 +1038,21 @@ class OrderCore extends ObjectModel
|
||||
return $orders;
|
||||
}
|
||||
|
||||
public static function getOrdersWithInformations($limit = null, ?Context $context = null)
|
||||
public static function getOrdersWithInformations($limit = null, ?Context $context = null, $applyHotelRestriction = false)
|
||||
{
|
||||
if (!$context) {
|
||||
$context = Context::getContext();
|
||||
}
|
||||
|
||||
$hotelJoin = '';
|
||||
$hotelRestriction = '';
|
||||
$groupBy = '';
|
||||
if ($applyHotelRestriction) {
|
||||
$hotelJoin = ' INNER JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (hbd.`id_order` = o.`id_order`)';
|
||||
$hotelRestriction = HotelBranchInformation::addHotelRestriction(false, 'hbd');
|
||||
$groupBy = ' GROUP BY o.`id_order`';
|
||||
}
|
||||
|
||||
$sql = 'SELECT *, (
|
||||
SELECT osl.`name`
|
||||
FROM `'._DB_PREFIX_.'order_state_lang` osl
|
||||
@@ -1053,8 +1062,11 @@ class OrderCore extends ObjectModel
|
||||
) AS `state_name`, o.`date_add` AS `date_add`, o.`date_upd` AS `date_upd`
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = o.`id_customer`)
|
||||
'.$hotelJoin.'
|
||||
WHERE 1
|
||||
'.Shop::addSqlRestriction(false, 'o').'
|
||||
'.$hotelRestriction.'
|
||||
'.$groupBy.'
|
||||
ORDER BY o.`date_add` DESC
|
||||
'.((int)$limit ? 'LIMIT 0, '.(int)$limit : '');
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
|
||||
@@ -77,8 +77,12 @@ class OrderSlipCore extends ObjectModel
|
||||
/** @var int */
|
||||
public $order_slip_type = 0;
|
||||
|
||||
public $remark;
|
||||
|
||||
const REDEEM_STATUS_ACTIVE = 1;
|
||||
const REDEEM_STATUS_REDEEMED = 2;
|
||||
const ORDER_SLIP_TYPE_REFUND = 1;
|
||||
const ORDER_SLIP_TYPE_MANUAL = 2;
|
||||
|
||||
/**
|
||||
* @see ObjectModel::$definition
|
||||
@@ -101,9 +105,10 @@ class OrderSlipCore extends ObjectModel
|
||||
'partial' => array('type' => self::TYPE_INT),
|
||||
'redeem_status' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'id_cart_rule' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'order_slip_type' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
||||
'remark' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'order_slip_type' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -155,6 +160,25 @@ class OrderSlipCore extends ObjectModel
|
||||
ORDER BY `date_add` DESC');
|
||||
}
|
||||
|
||||
public static function getTotalOrderSlipAmountByOrder($id_order = false)
|
||||
{
|
||||
$sql = 'SELECT SUM(`amount`) FROM `'._DB_PREFIX_.'order_slip`';
|
||||
if ($id_order) {
|
||||
$sql .= ' WHERE `id_order` = '.(int)$id_order;
|
||||
}
|
||||
return (float) Db::getInstance()->getValue($sql);
|
||||
}
|
||||
|
||||
public static function getSlipIdsByOrder($id_order = false)
|
||||
{
|
||||
$sql = 'SELECT * FROM `'._DB_PREFIX_.'order_slip`';
|
||||
if ($id_order) {
|
||||
$sql .= ' WHERE `id_order` = '.(int)$id_order;
|
||||
}
|
||||
$sql .= ' ORDER BY `id_order_slip` ASC';
|
||||
return Db::getInstance()->executeS($sql);
|
||||
}
|
||||
|
||||
public static function getOrdersSlipDetail($id_order_slip = false, $id_order_detail = false)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
|
||||
@@ -276,6 +300,7 @@ class OrderSlipCore extends ObjectModel
|
||||
SELECT `id_order_slip`
|
||||
FROM `'._DB_PREFIX_.'order_slip` os
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = os.`id_order`)
|
||||
INNER JOIN `'._DB_PREFIX_.'htl_booking_detail` hbd ON (o.id_order = hbd.id_order)
|
||||
WHERE os.`date_add` BETWEEN \''.pSQL($dateFrom).' 00:00:00\' AND \''.pSQL($dateTo).' 23:59:59\'
|
||||
'.Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o'). ' ' .HotelBranchInformation::addHotelRestriction(false).'
|
||||
ORDER BY os.`date_add` ASC');
|
||||
@@ -310,7 +335,7 @@ class OrderSlipCore extends ObjectModel
|
||||
return OrderSlip::create($order, $product_list, $shipping);
|
||||
}
|
||||
|
||||
public static function create(Order $order, $product_list, $shipping_cost = false, $amount = 0, $amount_choosen = false, $add_tax = true)
|
||||
public static function create(Order $order, $product_list, $shipping_cost = false, $amount = 0, $amount_choosen = false, $add_tax = true , $orderSlipType = false, $remark = '')
|
||||
{
|
||||
$currency = new Currency((int)$order->id_currency);
|
||||
$order_slip = new OrderSlip();
|
||||
@@ -365,17 +390,6 @@ class OrderSlipCore extends ObjectModel
|
||||
}
|
||||
$price = (float)$product_row['unit_price'];
|
||||
|
||||
|
||||
$order_slip_resume = OrderSlip::getProductSlipResume((int)$order_detail->id);
|
||||
|
||||
if ($quantity + $order_slip_resume['product_quantity'] > $order_detail->product_quantity) {
|
||||
$quantity = $order_detail->product_quantity - $order_slip_resume['product_quantity'];
|
||||
}
|
||||
|
||||
if ($quantity == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!Tools::isSubmit('cancelProduct') && $order->hasBeenPaid()) {
|
||||
$order_detail->product_quantity_refunded += $quantity;
|
||||
}
|
||||
@@ -442,11 +456,11 @@ class OrderSlipCore extends ObjectModel
|
||||
$order_slip->{'total_products_tax_'.$inc_or_ex_2} -= (float)$amount && !$amount_choosen ? (float)$amount : 0;
|
||||
$order_slip->amount = $amount_choosen ? (float)$amount : $order_slip->{'total_products_tax_'.$inc_or_ex_1};
|
||||
|
||||
if ((float)$amount && !$amount_choosen) {
|
||||
$order_slip->order_slip_type = 1;
|
||||
if (isset($orderSlipType) && $orderSlipType) {
|
||||
$order_slip->order_slip_type = $orderSlipType;
|
||||
}
|
||||
if (((float)$amount && $amount_choosen)) {
|
||||
$order_slip->order_slip_type = 2;
|
||||
if (isset($remark) && $remark) {
|
||||
$order_slip->remark = $remark;
|
||||
}
|
||||
|
||||
if (!$order_slip->add()) {
|
||||
|
||||
@@ -47,6 +47,7 @@ class AdminCartRulesControllerCore extends AdminController
|
||||
$this->fields_list = array(
|
||||
'id_cart_rule' => array('title' => $this->l('ID'), 'align' => 'center', 'class' => 'fixed-width-xs'),
|
||||
'name' => array('title' => $this->l('Name')),
|
||||
'hotel_names' => array('title' => $this->l('Hotels'), 'orderby' => false, 'havingFilter' => true, 'filter_key' => 'hotel_names', 'callback' => 'formatHotelNames'),
|
||||
'priority' => array('title' => $this->l('Priority'), 'align' => 'center', 'class' => 'fixed-width-xs'),
|
||||
'code' => array('title' => $this->l('Code'), 'class' => 'fixed-width-sm'),
|
||||
'quantity' => array('title' => $this->l('Quantity'), 'align' => 'center', 'class' => 'fixed-width-xs'),
|
||||
@@ -54,6 +55,15 @@ class AdminCartRulesControllerCore extends AdminController
|
||||
'active' => array('title' => $this->l('Status'), 'active' => 'status', 'type' => 'bool', 'align' => 'center', 'class' => 'fixed-width-xs', 'orderby' => false),
|
||||
);
|
||||
|
||||
$this->_select = 'GROUP_CONCAT(DISTINCT hbl.`hotel_name` ORDER BY hbl.`hotel_name` ASC SEPARATOR "|||") AS hotel_names';
|
||||
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'cart_rule_hotel` crh ON (crh.`id_cart_rule` = a.`id_cart_rule`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'htl_branch_info` hbi ON (
|
||||
(a.`hotel_restriction` = 1 AND hbi.`id` = crh.`id_hotel`)
|
||||
OR (a.`hotel_restriction` = 0 AND hbi.`active` = 1)
|
||||
)
|
||||
LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hbl ON (hbl.`id` = hbi.`id` AND hbl.`id_lang` = '.(int)Context::getContext()->language->id.')';
|
||||
$this->_group = 'GROUP BY a.`id_cart_rule`';
|
||||
|
||||
// START send access query information to the admin controller
|
||||
$this->access_select = ' SELECT a.`id_cart_rule` FROM '._DB_PREFIX_.'cart_rule a';
|
||||
if ($acsHtls = HotelBranchInformation::getProfileAccessedHotels($this->context->employee->id_profile, 1, 1)) {
|
||||
@@ -76,6 +86,20 @@ class AdminCartRulesControllerCore extends AdminController
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function formatHotelNames($hotelNames, $row)
|
||||
{
|
||||
$hotels = !empty($hotelNames) ? explode('|||', $hotelNames) : array();
|
||||
$this->context->smarty->assign(array(
|
||||
'hotel_names_first' => !empty($hotels) ? $hotels[0] : null,
|
||||
'hotel_names_remaining' => count($hotels) > 1 ? array_slice($hotels, 1) : array(),
|
||||
'selected_hotels' => $hotels,
|
||||
));
|
||||
|
||||
return $this->context->smarty->fetch(
|
||||
'controllers/cart_rules/helpers/list/_hotel_names_tooltip.tpl'
|
||||
);
|
||||
}
|
||||
|
||||
public function ajaxProcessLoadCartRules()
|
||||
{
|
||||
$type = $token = $search = '';
|
||||
@@ -254,6 +278,7 @@ class AdminCartRulesControllerCore extends AdminController
|
||||
'room_rmv_txt' => $this->l('Unselect below room types'),
|
||||
)
|
||||
);
|
||||
$this->addJqueryUI('ui.tooltip', 'base', true);
|
||||
$this->addJS(_PS_JS_DIR_.'admin/cart-rules.js');
|
||||
$this->addJqueryPlugin(array('typewatch', 'fancybox', 'autocomplete'));
|
||||
}
|
||||
@@ -324,7 +349,7 @@ class AdminCartRulesControllerCore extends AdminController
|
||||
}
|
||||
|
||||
// These are checkboxes (which aren't sent through POST when they are not check), so they are forced to 0
|
||||
foreach (array('country', 'carrier', 'group', 'cart_rule', 'product', 'shop') as $type) {
|
||||
foreach (array('country', 'carrier', 'group', 'cart_rule', 'product', 'shop', 'hotel') as $type) {
|
||||
if (!Tools::getValue($type.'_restriction')) {
|
||||
$_POST[$type.'_restriction'] = 0;
|
||||
}
|
||||
@@ -380,7 +405,7 @@ class AdminCartRulesControllerCore extends AdminController
|
||||
{
|
||||
// All the associations are deleted for an update, then recreated when we call the "afterAdd" method
|
||||
$id_cart_rule = Tools::getValue('id_cart_rule');
|
||||
foreach (array('country', 'carrier', 'group', 'product_rule_group', 'shop') as $type) {
|
||||
foreach (array('country', 'carrier', 'group', 'hotel', 'product_rule_group', 'shop') as $type) {
|
||||
Db::getInstance()->delete('cart_rule_'.$type, '`id_cart_rule` = '.(int)$id_cart_rule);
|
||||
}
|
||||
Db::getInstance()->delete('cart_rule_product_rule', 'NOT EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'cart_rule_product_rule_group`
|
||||
@@ -414,7 +439,7 @@ class AdminCartRulesControllerCore extends AdminController
|
||||
*/
|
||||
protected function afterAdd($currentObject)
|
||||
{
|
||||
// Add restrictions for generic entities like country, carrier and group
|
||||
// Add restrictions for generic entities like country, carrier, group, hotel and shop
|
||||
foreach (array('country', 'carrier', 'group', 'shop') as $type) {
|
||||
if (Tools::getValue($type.'_restriction') && is_array($array = Tools::getValue($type.'_select')) && count($array)) {
|
||||
$values = array();
|
||||
@@ -424,6 +449,14 @@ class AdminCartRulesControllerCore extends AdminController
|
||||
Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'cart_rule_'.$type.'` (`id_cart_rule`, `id_'.$type.'`) VALUES '.implode(',', $values));
|
||||
}
|
||||
}
|
||||
// Add hotel restrictions
|
||||
if (Tools::getValue('hotel_restriction') && is_array($array = Tools::getValue('hotel_select')) && count($array)) {
|
||||
$values = array();
|
||||
foreach ($array as $id) {
|
||||
$values[] = '('.(int)$currentObject->id.','.(int)$id.')';
|
||||
}
|
||||
Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'cart_rule_hotel` (`id_cart_rule`, `id_hotel`) VALUES '.implode(',', $values));
|
||||
}
|
||||
// Add cart rule restrictions
|
||||
if (Tools::getValue('cart_rule_restriction') && is_array($array = Tools::getValue('cart_rule_select')) && count($array)) {
|
||||
$values = array();
|
||||
@@ -803,6 +836,7 @@ class AdminCartRulesControllerCore extends AdminController
|
||||
$languages = Language::getLanguages();
|
||||
$countries = $current_object->getAssociatedRestrictions('country', true, true);
|
||||
$groups = $current_object->getAssociatedRestrictions('group', false, true);
|
||||
$hotels = $current_object->getHotelRestrictions($this->context->employee->id_profile);
|
||||
$shops = $current_object->getAssociatedRestrictions('shop', false, false);
|
||||
$cart_rules = $current_object->getAssociatedRestrictions('cart_rule', false, true, 0, $limit);
|
||||
$carriers = $current_object->getAssociatedRestrictions('carrier', true, false);
|
||||
@@ -862,6 +896,7 @@ class AdminCartRulesControllerCore extends AdminController
|
||||
'countries' => $countries,
|
||||
'carriers' => $carriers,
|
||||
'groups' => $groups,
|
||||
'hotels' => $hotels,
|
||||
'shops' => $shops,
|
||||
'cart_rules' => $cart_rules,
|
||||
'product_rule_groups' => $product_rule_groups,
|
||||
|
||||
@@ -52,20 +52,23 @@ class AdminSlipControllerCore extends AdminController
|
||||
),
|
||||
'id_order' => array(
|
||||
'title' => $this->l('Order ID'),
|
||||
'align' => 'left',
|
||||
'align' => 'center',
|
||||
'class' => 'fixed-width-md',
|
||||
'havingFilter' => true
|
||||
'havingFilter' => true,
|
||||
'callback' => 'displayOrderLink',
|
||||
),
|
||||
'date_add' => array(
|
||||
'title' => $this->l('Date issued'),
|
||||
'type' => 'date',
|
||||
'align' => 'right',
|
||||
'class' => 'fixed-width-md',
|
||||
'align' => 'center',
|
||||
'filter_key' => 'a!date_add'
|
||||
),
|
||||
'id_pdf' => array(
|
||||
'title' => $this->l('PDF'),
|
||||
'align' => 'center',
|
||||
'callback' => 'printPDFIcons',
|
||||
'class' => 'fixed-width-xxl',
|
||||
'orderby' => false,
|
||||
'search' => false,
|
||||
'remove_onclick' => true
|
||||
@@ -80,13 +83,20 @@ class AdminSlipControllerCore extends AdminController
|
||||
'align' => 'center',
|
||||
'filter_key' => 'a!redeem_status',
|
||||
'callback' => 'displayRedeemStatus',
|
||||
'class' => 'fixed-width-md',
|
||||
'class' => 'fixed-width-xxl',
|
||||
),
|
||||
'id_cart_rule' => array(
|
||||
'title' => $this->l('Voucher'),
|
||||
'align' => 'center',
|
||||
'callback' => 'displayVoucherLink',
|
||||
'class' => 'fixed-width-lg',
|
||||
'class' => 'fixed-width-xxl',
|
||||
),
|
||||
'remark' => array(
|
||||
'title' => $this->l('Remark'),
|
||||
'filter_key' => 'a!remark',
|
||||
'align' => 'center',
|
||||
'orderby' => false,
|
||||
'callback' => 'displayRemark',
|
||||
),
|
||||
);
|
||||
|
||||
@@ -113,35 +123,131 @@ class AdminSlipControllerCore extends AdminController
|
||||
$this->_conf['33'] = $this->l('Voucher generated successfully');
|
||||
}
|
||||
|
||||
public function initPageHeaderToolbar()
|
||||
public function initPageHeaderToolbar()
|
||||
{
|
||||
if (empty($this->display) || $this->display == 'list') {
|
||||
$this->page_header_toolbar_btn['new_credit_slip'] = array(
|
||||
'href' => self::$currentIndex . '&add' . $this->table . '&token=' . $this->token,
|
||||
'desc' => $this->l('Add Credit Slip', null, null, false),
|
||||
'icon' => 'process-icon-new'
|
||||
);
|
||||
}
|
||||
|
||||
parent::initPageHeaderToolbar();
|
||||
}
|
||||
|
||||
public function renderForm()
|
||||
public function renderForm()
|
||||
{
|
||||
$this->fields_form = array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Print a PDF'),
|
||||
'icon' => 'icon-print'
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'date',
|
||||
'label' => $this->l('From'),
|
||||
'name' => 'date_from',
|
||||
'maxlength' => 10,
|
||||
'required' => true,
|
||||
'hint' => $this->l('Format: 2011-12-31 (inclusive).')
|
||||
if ($this->display == 'add') {
|
||||
$orderList = Order::getOrdersWithInformations(null, null, true);
|
||||
foreach ($orderList as &$order) {
|
||||
$order['order_label'] = $order['reference'] . ' #' . (int) $order['id_order'];
|
||||
}
|
||||
unset($order);
|
||||
|
||||
$this->fields_form = array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Credit slip'),
|
||||
'icon' => 'icon-print'
|
||||
),
|
||||
array(
|
||||
'type' => 'date',
|
||||
'label' => $this->l('To'),
|
||||
'name' => 'date_to',
|
||||
'maxlength' => 10,
|
||||
'required' => true,
|
||||
'hint' => $this->l('Format: 2012-12-31 (inclusive).')
|
||||
'description' => '<strong>' . $this->l('Note: Before generating the credit slip, please review all details carefully. Once the credit slip is generated, it cannot be modified.') . '</strong>',
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Order id'),
|
||||
'name' => 'id_order',
|
||||
'required' => true,
|
||||
'hint' => $this->l('Select an Order ID to generate the credit slip'),
|
||||
'class' => 'chosen',
|
||||
'col' => 3,
|
||||
'desc' => $this->context->smarty->fetch(
|
||||
_PS_ADMIN_DIR_ . '/themes/default/template/controllers/slip/_order_info_desc.tpl'
|
||||
),
|
||||
'options' => array(
|
||||
'query' => $orderList,
|
||||
'id' => 'id_order',
|
||||
'name' => 'order_label'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Room Type'),
|
||||
'name' => 'id_room_type',
|
||||
'required' => true,
|
||||
'hint' => $this->l('Select a room type'),
|
||||
'col' => 3,
|
||||
'options' => array(
|
||||
'query' => array(),
|
||||
'id' => 'id',
|
||||
'name' => 'name'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Room'),
|
||||
'name' => 'id_booking_detail',
|
||||
'required' => true,
|
||||
'hint' => $this->l('Select a room to generate the credit slip for'),
|
||||
'col' => 3,
|
||||
'desc' => $this->context->smarty->fetch(
|
||||
_PS_ADMIN_DIR_ . '/themes/default/template/controllers/slip/_booking_room_service_total_desc.tpl'
|
||||
),
|
||||
'options' => array(
|
||||
'query' => array(),
|
||||
'id' => 'id',
|
||||
'name' => 'room_label'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Amount of credit slip'),
|
||||
'hint' => $this->l('Enter the amount of the credit slip for the customer'),
|
||||
'name' => 'credit_slip_amount',
|
||||
'required' => true,
|
||||
'col' => 3,
|
||||
'suffix' => $this->context->currency->sign,
|
||||
'desc' => $this->context->smarty->fetch(
|
||||
_PS_ADMIN_DIR_ . '/themes/default/template/controllers/slip/_booking_amount_desc.tpl'
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'textarea',
|
||||
'label' => $this->l('Remark'),
|
||||
'hint' => $this->l('Enter any remark for this credit slip'),
|
||||
'name' => 'remark',
|
||||
'required' => true,
|
||||
'col' => 9,
|
||||
'rows' => 3,
|
||||
),
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Generate'),
|
||||
'name' => 'submitCreditSlip',
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->fields_form = array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Print a PDF'),
|
||||
'icon' => 'icon-print'
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'date',
|
||||
'label' => $this->l('From'),
|
||||
'name' => 'date_from',
|
||||
'maxlength' => 10,
|
||||
'required' => true,
|
||||
'hint' => $this->l('Format: 2011-12-31 (inclusive).')
|
||||
),
|
||||
array(
|
||||
'type' => 'date',
|
||||
'label' => $this->l('To'),
|
||||
'name' => 'date_to',
|
||||
'maxlength' => 10,
|
||||
'required' => true,
|
||||
'hint' => $this->l('Format: 2012-12-31 (inclusive).')
|
||||
)
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Generate PDF file'),
|
||||
@@ -149,6 +255,7 @@ class AdminSlipControllerCore extends AdminController
|
||||
'icon' => 'process-icon-download-alt'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->fields_value = array(
|
||||
'date_from' => date('Y-m-d'),
|
||||
@@ -159,9 +266,83 @@ class AdminSlipControllerCore extends AdminController
|
||||
return parent::renderForm();
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
public function postProcess()
|
||||
{
|
||||
if (Tools::getValue('submitAddorder_slip')) {
|
||||
if (Tools::getValue('submitCreditSlip')) {
|
||||
$creditSlipAmount = trim(Tools::getValue('credit_slip_amount'));
|
||||
if (empty($creditSlipAmount)) {
|
||||
$this->errors[] = $this->l('Credit slip amount is required.');
|
||||
} elseif (!is_numeric($creditSlipAmount)) {
|
||||
$this->errors[] = $this->l('Credit slip amount is not valid');
|
||||
} elseif ((float) $creditSlipAmount <= 0) {
|
||||
$this->errors[] = $this->l('Credit slip amount must be greater than 0');
|
||||
}
|
||||
|
||||
$remark = trim(Tools::getValue('remark'));
|
||||
if (empty($remark)) {
|
||||
$this->errors[] = $this->l('Remark is required.');
|
||||
} elseif (!Validate::isString($remark) || !Validate::isMessage($remark) || !Validate::isCleanHtml($remark)) {
|
||||
$this->errors[] = $this->l('Remark must be a valid text.');
|
||||
}
|
||||
|
||||
if (!count($this->errors)) {
|
||||
$objOrder = new Order(Tools::getValue('id_order'));
|
||||
$creditAmount = $creditSlipAmount;
|
||||
$idBookingDetail = Tools::getValue('id_booking_detail');
|
||||
$customer = new Customer($objOrder->id_customer);
|
||||
$bookingList = array();
|
||||
$objHotelBookingDetail = new HotelBookingDetail($idBookingDetail);
|
||||
|
||||
if ($idHtlBooking = $objHotelBookingDetail->id) {
|
||||
$numDays = HotelHelper::getNumberOfDays(
|
||||
$objHotelBookingDetail->date_from,
|
||||
$objHotelBookingDetail->date_to
|
||||
);
|
||||
|
||||
$idOrderDetail = $objHotelBookingDetail->id_order_detail;
|
||||
|
||||
$bookingList = array(
|
||||
array(
|
||||
'id_htl_booking' => $idHtlBooking,
|
||||
'id_order_detail' => $idOrderDetail,
|
||||
'quantity' => $numDays,
|
||||
'num_days' => $numDays,
|
||||
'unit_price' => (float) $creditAmount / $numDays,
|
||||
'amount' => (float) $creditAmount,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (!$idCreditSlip = OrderSlip::create($objOrder, $bookingList, 0, $creditAmount, $creditAmount, 0 , OrderSlip::ORDER_SLIP_TYPE_MANUAL, $remark)) {
|
||||
$this->errors[] = $this->l('A credit slip cannot be generated. ');
|
||||
} else {
|
||||
|
||||
Hook::exec('actionOrderSlipAdd', array('order' => $objOrder, 'bookingList' => $bookingList));
|
||||
|
||||
$params['{credit_slip_url}'] = $this->context->link->getPageLink('order-slip', true);
|
||||
|
||||
@Mail::Send(
|
||||
(int)$objOrder->id_lang,
|
||||
'credit_slip',
|
||||
Mail::l('New credit slip generated for you', (int)$objOrder->id_lang),
|
||||
$params,
|
||||
$customer->email,
|
||||
$customer->firstname.' '.$customer->lastname,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
_PS_MAIL_DIR_,
|
||||
true,
|
||||
(int)$objOrder->id_shop
|
||||
);
|
||||
}
|
||||
Tools::redirectAdmin(self::$currentIndex . '&token=' . $this->token . '&conf=3');
|
||||
} else {
|
||||
$this->display = 'add';
|
||||
return;
|
||||
}
|
||||
} else if (Tools::getValue('submitAddorder_slip')) {
|
||||
if (!Validate::isDate(Tools::getValue('date_from'))) {
|
||||
$this->errors[] = $this->l('Invalid "From" date');
|
||||
}
|
||||
@@ -236,9 +417,13 @@ class AdminSlipControllerCore extends AdminController
|
||||
$this->initTabModuleList();
|
||||
$this->initToolbar();
|
||||
$this->initPageHeaderToolbar();
|
||||
$this->content .= $this->renderList();
|
||||
if ($this->display != "add") {
|
||||
$this->content .= $this->renderList();
|
||||
}
|
||||
$this->content .= $this->renderForm();
|
||||
$this->content .= $this->renderOptions();
|
||||
if ($this->display != "add") {
|
||||
$this->content .= $this->renderOptions();
|
||||
}
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'content' => $this->content,
|
||||
@@ -288,6 +473,31 @@ class AdminSlipControllerCore extends AdminController
|
||||
return $this->createTemplate('_display_voucher_link.tpl')->fetch();
|
||||
}
|
||||
|
||||
public function displayOrderLink($idOrder, $row)
|
||||
{
|
||||
$this->context->smarty->assign(array(
|
||||
'id_order' => (int) $idOrder,
|
||||
));
|
||||
|
||||
return $this->createTemplate('_display_order_link.tpl')->fetch();
|
||||
}
|
||||
|
||||
public function displayRemark($remark, $row)
|
||||
{
|
||||
if (empty($remark)) {
|
||||
return '--';
|
||||
}
|
||||
|
||||
$maxLength = 100;
|
||||
if (Tools::strlen($remark) > $maxLength) {
|
||||
return '<span title="' . htmlspecialchars($remark, ENT_QUOTES, 'UTF-8') . '">'
|
||||
. htmlspecialchars(Tools::substr($remark, 0, $maxLength), ENT_QUOTES, 'UTF-8')
|
||||
. '<strong style="cursor:pointer;">...</strong></span>';
|
||||
}
|
||||
|
||||
return htmlspecialchars($remark, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
public function displayStatusChangeLink($token, $id)
|
||||
{
|
||||
$objOrderSlip = new OrderSlip($id);
|
||||
@@ -342,12 +552,73 @@ class AdminSlipControllerCore extends AdminController
|
||||
$this->ajaxDie(json_encode($response));
|
||||
}
|
||||
|
||||
public function ajaxProcessGetBookingDetails()
|
||||
{
|
||||
$idOrder = (int) Tools::getValue('id_order');
|
||||
$objOrder = new Order($idOrder);
|
||||
$currency = Currency::getCurrency((int)$objOrder->id_currency);
|
||||
$objHotelBookingDetail = new HotelBookingDetail();
|
||||
$bookingDetails = $objHotelBookingDetail->getBookingDataByOrderId($idOrder);
|
||||
|
||||
$objBookingDemands = new HotelBookingDemands();
|
||||
$objServiceProductOrderDetail = new ServiceProductOrderDetail();
|
||||
|
||||
foreach ($bookingDetails as &$booking) {
|
||||
$booking['extra_service_total_price_tax_incl'] = 0;
|
||||
|
||||
$extraDemands = $objBookingDemands->getRoomTypeBookingExtraDemands(
|
||||
$idOrder,
|
||||
$booking['id_product'],
|
||||
$booking['id_room'],
|
||||
$booking['date_from'],
|
||||
$booking['date_to'],
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
$booking['id']
|
||||
);
|
||||
if ($extraDemands) {
|
||||
foreach ($extraDemands as $demand) {
|
||||
$booking['extra_service_total_price_tax_incl'] += (float) $demand['total_price_tax_incl'];
|
||||
}
|
||||
}
|
||||
|
||||
$roomServices = $objServiceProductOrderDetail->getRoomTypeServiceProducts(
|
||||
0, 0, 0, 0, 0, 0, 0, 0, null, null, null, 0, $booking['id']
|
||||
);
|
||||
if ($roomServices && isset($roomServices[$booking['id']]['additional_services'])) {
|
||||
foreach ($roomServices[$booking['id']]['additional_services'] as $service) {
|
||||
$booking['extra_service_total_price_tax_incl'] += (float) $service['total_price_tax_incl'];
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($booking);
|
||||
|
||||
$totalSlipAmount = OrderSlip::getTotalOrderSlipAmountByOrder($idOrder);
|
||||
$slipIds = array_column(OrderSlip::getSlipIdsByOrder($idOrder), 'id_order_slip');
|
||||
$objOrderReturn = new OrderReturn();
|
||||
$refundedAmount = $objOrderReturn->getRefundedAmount($idOrder);
|
||||
|
||||
die(Tools::jsonEncode(array(
|
||||
'bookings' => $bookingDetails,
|
||||
'currency' => $currency,
|
||||
'total_slip_amount' => $totalSlipAmount,
|
||||
'slip_ids' => $slipIds,
|
||||
'order_total_amount' => (float) $objOrder->total_paid,
|
||||
'order_total_paid' => (float) $objOrder->total_paid_real,
|
||||
'order_refunded_amount' => (float) $refundedAmount
|
||||
)));
|
||||
}
|
||||
|
||||
public function setMedia()
|
||||
{
|
||||
parent::setMedia();
|
||||
Media::addJsDef(
|
||||
array(
|
||||
'admin_order_slip_tab_link' => $this->context->link->getAdminLink('AdminSlip'),
|
||||
'admin_order_view_link' => $this->context->link->getAdminLink('AdminOrders'),
|
||||
'restoreRoomTypeId' => (int) Tools::getValue('id_room_type'),
|
||||
'restoreBookingDetailId' => (int) Tools::getValue('id_booking_detail'),
|
||||
)
|
||||
);
|
||||
$this->addJS(_PS_JS_DIR_.'admin/slips.js');
|
||||
|
||||
@@ -226,6 +226,7 @@ CREATE TABLE `PREFIX_cart_rule` (
|
||||
`cart_rule_restriction` tinyint(1) unsigned NOT NULL DEFAULT '0',
|
||||
`product_restriction` tinyint(1) unsigned NOT NULL DEFAULT '0',
|
||||
`shop_restriction` tinyint(1) unsigned NOT NULL DEFAULT '0',
|
||||
`hotel_restriction` tinyint(1) unsigned NOT NULL DEFAULT '0',
|
||||
`free_shipping` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`reduction_percent` decimal(5,2) NOT NULL DEFAULT '0',
|
||||
`reduction_amount` decimal(17,2) NOT NULL DEFAULT '0',
|
||||
@@ -264,6 +265,12 @@ CREATE TABLE `PREFIX_cart_rule_group` (
|
||||
PRIMARY KEY (`id_cart_rule`, `id_group`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 COLLATION;
|
||||
|
||||
CREATE TABLE `PREFIX_cart_rule_hotel` (
|
||||
`id_cart_rule` int(10) unsigned NOT NULL,
|
||||
`id_hotel` int(10) unsigned NOT NULL,
|
||||
PRIMARY KEY (`id_cart_rule`, `id_hotel`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 COLLATION;
|
||||
|
||||
CREATE TABLE `PREFIX_cart_rule_carrier` (
|
||||
`id_cart_rule` int(10) unsigned NOT NULL,
|
||||
`id_carrier` int(10) unsigned NOT NULL,
|
||||
@@ -1409,6 +1416,7 @@ CREATE TABLE `PREFIX_order_slip` (
|
||||
`redeem_status` TINYINT(1) NOT NULL DEFAULT '0',
|
||||
`id_cart_rule` int(10) unsigned NOT NULL DEFAULT '0',
|
||||
`order_slip_type` TINYINT(1) unsigned NOT NULL DEFAULT '0',
|
||||
`remark` text,
|
||||
`date_add` datetime NOT NULL,
|
||||
`date_upd` datetime NOT NULL,
|
||||
PRIMARY KEY (`id_order_slip`),
|
||||
|
||||
@@ -103,4 +103,179 @@ $(document).ready(function() {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var allBookings = [];
|
||||
var currencySign = '';
|
||||
|
||||
if (typeof $.fn.chosen !== 'undefined') {
|
||||
$('select[name="id_order"]').chosen('destroy').chosen({
|
||||
width: '100%',
|
||||
search_contains: true
|
||||
});
|
||||
$('select[name="id_room_type"]').chosen({
|
||||
width: '100%',
|
||||
search_contains: true
|
||||
});
|
||||
$('select[name="id_booking_detail"]').chosen({
|
||||
width: '100%',
|
||||
search_contains: true
|
||||
});
|
||||
}
|
||||
|
||||
$('select[name="id_order"]').on('change', function () {
|
||||
var idOrder = $(this).val();
|
||||
var $roomTypeSelect = $('select[name="id_room_type"]');
|
||||
var $bookingSelect = $('select[name="id_booking_detail"]');
|
||||
|
||||
allBookings = [];
|
||||
$roomTypeSelect.empty().trigger('chosen:updated');
|
||||
$bookingSelect.empty().trigger('chosen:updated');
|
||||
|
||||
if (!idOrder) {
|
||||
$('#order-info').hide();
|
||||
$('#order-view-link').hide();
|
||||
$('#booking-total-slip-amount').text('-');
|
||||
$('#booking-slip-ids').html('');
|
||||
$('#booking-slip-ids-wrapper').hide();
|
||||
$('#order-total-amount').text('-');
|
||||
$('#order-total-amount-wrapper').hide();
|
||||
$('#order-total-paid').text('-');
|
||||
$('#order-total-paid-wrapper').hide();
|
||||
$('#order-total-return').text('-');
|
||||
$('#order-total-return-wrapper').hide();
|
||||
return;
|
||||
}
|
||||
|
||||
var selectedLabel = $('select[name="id_order"] option:selected').text();
|
||||
$('#order-info').text(selectedLabel).show();
|
||||
|
||||
$('#order-view-link')
|
||||
.attr('href', admin_order_view_link + '&id_order=' + idOrder + '&vieworder')
|
||||
.show();
|
||||
|
||||
$.ajax({
|
||||
url: admin_order_slip_tab_link,
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
ajax: 1,
|
||||
action: 'GetBookingDetails',
|
||||
id_order: idOrder
|
||||
},
|
||||
success: function (response) {
|
||||
allBookings = response.bookings || [];
|
||||
|
||||
currencySign = response.currency.sign;
|
||||
var totalSlipAmount = parseFloat(response.total_slip_amount || 0);
|
||||
$('#booking-total-slip-amount').text(currencySign + ' ' + totalSlipAmount.toFixed(2));
|
||||
|
||||
var orderTotalAmount = parseFloat(response.order_total_amount || 0);
|
||||
$('#order-total-amount').text(currencySign + ' ' + orderTotalAmount.toFixed(2));
|
||||
$('#order-total-amount-wrapper').show();
|
||||
|
||||
var orderTotalPaid = parseFloat(response.order_total_paid || 0);
|
||||
$('#order-total-paid').text(currencySign + ' ' + orderTotalPaid.toFixed(2));
|
||||
$('#order-total-paid-wrapper').show();
|
||||
|
||||
var orderRefundedAmount = parseFloat(response.order_refunded_amount || 0);
|
||||
$('#order-total-return').text(currencySign + ' ' + orderRefundedAmount.toFixed(2));
|
||||
$('#order-total-return-wrapper').show();
|
||||
var slipIds = response.slip_ids || [];
|
||||
if (slipIds.length) {
|
||||
var links = slipIds.map(function (id) {
|
||||
var href = admin_order_slip_tab_link
|
||||
+ '&order_slipFilter_id_order_slip=' + id
|
||||
+ '&submitFilterorder_slip=1';
|
||||
return '<a href="' + href + '">#' + id + '</a>';
|
||||
});
|
||||
$('#booking-slip-ids').html(links.join(', '));
|
||||
$('#booking-slip-ids-wrapper').show();
|
||||
} else {
|
||||
$('#booking-slip-ids').html('');
|
||||
$('#booking-slip-ids-wrapper').hide();
|
||||
}
|
||||
$('#credit_slip_amount')
|
||||
.closest('.input-group')
|
||||
.find('.input-group-addon, .input-group-text')
|
||||
.text(currencySign);
|
||||
|
||||
var addedRoomTypes = {};
|
||||
$.each(allBookings, function (_, booking) {
|
||||
if (!addedRoomTypes[booking.id_product]) {
|
||||
addedRoomTypes[booking.id_product] = true;
|
||||
$roomTypeSelect.append($('<option>', {
|
||||
value: booking.id_product,
|
||||
text: booking.room_type_name
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
$roomTypeSelect.trigger('chosen:updated');
|
||||
|
||||
if (restoreRoomTypeId > 0) {
|
||||
$roomTypeSelect.val(restoreRoomTypeId).trigger('chosen:updated');
|
||||
restoreRoomTypeId = 0;
|
||||
}
|
||||
$roomTypeSelect.trigger('change');
|
||||
},
|
||||
error: function (_, status, error) {
|
||||
console.error('[CreditSlip] AJAX error:', status, error);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('select[name="id_room_type"]').on('change', function () {
|
||||
var idProduct = $(this).val();
|
||||
var $bookingSelect = $('select[name="id_booking_detail"]');
|
||||
|
||||
$bookingSelect.empty();
|
||||
|
||||
if (!idProduct) {
|
||||
$bookingSelect.trigger('chosen:updated');
|
||||
return;
|
||||
}
|
||||
|
||||
var filtered = $.grep(allBookings, function (booking) {
|
||||
return String(booking.id_product) === String(idProduct);
|
||||
});
|
||||
|
||||
$.each(filtered, function (_, booking) {
|
||||
$bookingSelect.append($('<option>', {
|
||||
value: booking.id,
|
||||
text: booking.room_num + ' | ' + booking.date_from.substring(0, 10) + ' - ' + booking.date_to.substring(0, 10)
|
||||
}));
|
||||
});
|
||||
|
||||
$bookingSelect.trigger('chosen:updated');
|
||||
|
||||
if (restoreBookingDetailId > 0) {
|
||||
$bookingSelect.val(restoreBookingDetailId).trigger('chosen:updated');
|
||||
restoreBookingDetailId = 0;
|
||||
}
|
||||
$bookingSelect.trigger('change');
|
||||
});
|
||||
|
||||
$('select[name="id_booking_detail"]').on('change', function () {
|
||||
var idBooking = $(this).val();
|
||||
var booking = $.grep(allBookings, function (b) {
|
||||
return String(b.id) === String(idBooking);
|
||||
})[0];
|
||||
|
||||
if (booking) {
|
||||
var roomCost = parseFloat(booking.total_price_tax_incl);
|
||||
var serviceCost = parseFloat(booking.extra_service_total_price_tax_incl || 0);
|
||||
var total = roomCost + serviceCost;
|
||||
$('#booking-room-amount').text(currencySign + ' ' + roomCost.toFixed(2));
|
||||
$('#booking-service-amount').text(currencySign + ' ' + serviceCost.toFixed(2));
|
||||
$('#booking-amount').text(currencySign + ' ' + total.toFixed(2));
|
||||
} else {
|
||||
$('#booking-room-amount').text('-');
|
||||
$('#booking-service-amount').text('-');
|
||||
$('#booking-amount').text('-');
|
||||
}
|
||||
});
|
||||
|
||||
if ($('select[name="id_order"]').val()) {
|
||||
$('select[name="id_order"]').trigger('change');
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user