Added: Confirmation modal when deleting cart rules and while changes credit slip status

This commit is contained in:
Shreesh Arora
2024-07-31 17:42:02 +05:30
parent 684d96804f
commit 1743ca82f5
10 changed files with 511 additions and 6 deletions

View File

@@ -0,0 +1,46 @@
{*
* Since 2010 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* 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 https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright Since 2010 Webkul IN
* @license https://store.webkul.com/license.html
*}
<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>&nbsp;{l s='Confirm Delete'}</h4>
<p>{l s='The following cart rules in your selection were created dynamically from refunds or credit slips. Please confirm if you also intend to delete these cart rules.'}</p>
</div>
<div class="modal-body">
<div class="table-responsive">
<table class="table">
{foreach $cartRules as $cartRule}
<tr>
<td>
<input type="checkbox" class="cart_rule_to_delete" value="{$cartRule['id_cart_rule']}" checked>
</td>
<td>
<a href="{$link->getAdminLink('AdminCartRules')}&updatecart_rule&id_cart_rule={$cartRule['id_cart_rule']}" target="_blank">#{$cartRule['id_cart_rule']}</a>
</td>
<td>
<b>{if $cartRule['generated_by'] == CartRule::GENERATED_BY_REFUND}
{l s='Generated against refund'}
{else if $cartRule['generated_by'] == CartRule::GENERATED_BY_ORDER_SLIP}
{l s='Generated against credit slip'}
{/if}</b>
</td>
</tr>
{/foreach}
</table>
</div>
</div>

View File

@@ -0,0 +1,59 @@
{*
* Since 2010 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* 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 https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright Since 2010 Webkul IN
* @license https://store.webkul.com/license.html
*}
<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 Delete'}</h4>
<p>{l s='Are you sure, you want to delete this cart rule?'}</p>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-4">
<label>{l s='Voucher'}</label>
<p class="control-value">
{$cartRule->code} (<a href="{$link->getAdminLink('AdminCartRules')}&updatecart_rule&id_cart_rule={$cartRule->id}" target="_blank">#{$cartRule->id}</a>)
</p>
</div>
<div class="col-sm-4">
<label>{l s='Reason'}</label>
<p class="control-value">
{if $generatedBy == CartRule::GENERATED_BY_REFUND}
{l s='Generated against refund'}
{else if $generatedBy == CartRule::GENERATED_BY_ORDER_SLIP}
{l s='Generated against credit slip'}
{/if}
</p>
</div>
<div class="col-sm-4">
<label>{l s='Amount'}</label>
<p class="control-value">{displayPrice price=$cartRule->reduction_amount currency=$cartRule->reduction_currency}</p>
</div>
<div class="col-sm-4">
<label>{l s='Customer'}</label>
<p class="control-value">
{$customer->firstname} {$customer->lastname} (<a href="{$link->getAdminLink('AdminCustomers')}&viewcustomer&id_customer={$customer->id}" target="_blank">#{$customer->id}</a>)
</p>
</div>
<div class="col-sm-4">
<label>{l s='Order'}</label>
<p class="control-value">
{$order->reference} (<a href="{$link->getAdminLink('AdminOrders')}&vieworder&id_order={$order->id}" target="_blank">#{$order->id}</a>)
</p>
</div>
</div>
</div>

View File

@@ -17,7 +17,7 @@
* @license LICENSE.txt
*}
<a href="{$status_change_link|escape:'html':'UTF-8'}" title="{l s='Change Status'}">
<a href="{$status_change_link|escape:'html':'UTF-8'}" title="{l s='Change Status'}" class="change_status">
<i class="icon-refresh"></i>
{l s='Change Status'}
</a>

View File

@@ -0,0 +1,49 @@
{*
* Since 2010 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* 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 https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright Since 2010 Webkul IN
* @license https://store.webkul.com/license.html
*}
<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>&nbsp;{l s='Confirm Update'}</h4>
<p>{l s='Are you sure you want to change the status?'}</p>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-6">
<label>{l s='Credit Slip'}</label>
<p class="control-value">
<a href="{$link->getAdminLink('AdminCartRules')}&updatecart_rule&id_cart_rule={$orderSlip->id}" target="_blank">#{$orderSlip->id}</a>
</p>
</div>
<div class="col-sm-6">
<label>{l s='Amount'}</label>
<p class="control-value">{displayPrice price=$orderSlip->amount currency=$order->id_currency}</p>
</div>
<div class="col-sm-6">
<label>{l s='Customer'}</label>
<p class="control-value">
{$customer->firstname} {$customer->lastname} (<a href="{$link->getAdminLink('AdminCustomers')}&viewcustomer&id_customer={$customer->id}" target="_blank">#{$customer->id}</a>)
</p>
</div>
<div class="col-sm-6">
<label>{l s='Order'}</label>
<p class="control-value">
{$order->reference} (<a href="{$link->getAdminLink('AdminOrders')}&vieworder&id_order={$order->id}" target="_blank">#{$order->id}</a>)
</p>
</div>
</div>
</div>

View File

@@ -26,10 +26,10 @@
<div class="modal-dialog {if isset($modal_class)}{$modal_class}{/if}">
<div class="modal-content">
{if isset($modal_title)}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><i class="icon-remove-sign"></i></button>
<h4 class="modal-title">{$modal_title}</h4>
</div>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><i class="icon-remove-sign"></i></button>
<h4 class="modal-title">{$modal_title}</h4>
</div>
{/if}
{$modal_content}

View File

@@ -72,6 +72,9 @@ class CartRuleCore extends ObjectModel
public $date_add;
public $date_upd;
const GENERATED_BY_REFUND = 1;
const GENERATED_BY_ORDER_SLIP = 2;
/**
* @see ObjectModel::$definition
*/
@@ -1498,4 +1501,25 @@ class CartRuleCore extends ObjectModel
return Db::getInstance()->executeS($sql_base.' AND code LIKE \'%'.pSQL($name).'%\'');
}
}
public static function getGeneratedBy($id)
{
if (!$id) {
return false;
}
$response = array();
$sql = 'SELECT `id_order_slip` FROM '._DB_PREFIX_.'order_slip os
WHERE os.`id_cart_rule` = '.(int)$id;
if ($result = Db::getInstance()->getValue($sql)) {
$response['generated_by'] = self::GENERATED_BY_ORDER_SLIP;
$response['id_generated_by'] = $result;
}
$sql = 'SELECT `id_order_return` FROM '._DB_PREFIX_.'order_return o
WHERE o.`return_type` = '.OrderReturn::RETURN_TYPE_CART_RULE.' AND o.`id_return_type` = '.(int)$id;
if ($result = Db::getInstance()->getValue($sql)) {
$response['generated_by'] = self::GENERATED_BY_REFUND;
$response['id_generated_by'] = $result;
}
return $response;
}
}

View File

@@ -41,7 +41,8 @@ class AdminCartRulesControllerCore extends AdminController
$this->context = Context::getContext();
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'),'icon' => 'icon-trash', 'confirm' => $this->l('Delete selected items?')));
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'),'icon' => 'icon-trash'));
$this->specificConfirmDelete = false;
$this->fields_list = array(
'id_cart_rule' => array('title' => $this->l('ID'), 'align' => 'center', 'class' => 'fixed-width-xs'),
@@ -143,15 +144,103 @@ class AdminCartRulesControllerCore extends AdminController
echo json_encode(array('html' => $html, 'next_link' => $next_link));
}
public function ajaxProcessInitRuleDeleteModal()
{
$response = array('success' => false);
if ($idCartRule = Tools::getValue('id_cart_rule')) {
if ($generatedByDetails = CartRule::getGeneratedBy($idCartRule)) {
if (Validate::isLoadedObject($objCartRule = new CartRule($idCartRule, $this->context->language->id))) {
if ($generatedByDetails['generated_by'] == CartRule::GENERATED_BY_REFUND) {
$obj = new OrderReturn($generatedByDetails['id_generated_by']);
} else if ($generatedByDetails['generated_by'] == CartRule::GENERATED_BY_ORDER_SLIP) {
$obj = new OrderSlip($generatedByDetails['id_generated_by']);
}
$objOrder = new Order($obj->id_order);
$objCustomer = new Customer($objOrder->id_customer);
$modalConfirmDelete = $this->createTemplate('modal_confirm_delete.tpl');
$modalConfirmDelete->assign(array(
'generatedBy' => $generatedByDetails['generated_by'],
'generatedById' => $generatedByDetails['id_generated_by'],
'Customer' => $objCustomer,
'Order' => $objOrder,
'CartRule' => $objCartRule,
'link' => $this->context->link
));
$tpl = $this->createTemplate('modal.tpl');
$tpl->assign(array(
'modal_id' => 'moduleConfirmDelete',
'modal_class' => 'modal-lg',
'modal_content' => $modalConfirmDelete->fetch(),
'modal_actions' => array(
array(
'type' => 'button',
'class' => 'process_delete btn-primary',
'label' => $this->l('Delete'),
),
),
));
$response['confirm_delete'] = true;
$response['modalHtml'] = $tpl->fetch();
}
}
}
$response['success'] = true;
die(Tools::jsonEncode($response));
}
public function ajaxProcessInitRuleBulkDeleteModal()
{
$response = array('success' => false);
if ($idCartRules = Tools::getValue('id_cart_rule')) {
$toConfirm = array();
foreach($idCartRules as $idCartRule) {
if ($generatedByDetails = CartRule::getGeneratedBy($idCartRule)) {
$toConfirm[] = array_merge(['id_cart_rule' => $idCartRule], $generatedByDetails);
}
}
if (count($toConfirm)) {
$modalConfirmDelete = $this->createTemplate('modal_confirm_bulk_delete.tpl');
$modalConfirmDelete->assign(array(
'cartRules' => $toConfirm,
'link' => $this->context->link
));
$tpl = $this->createTemplate('modal.tpl');
$tpl->assign(array(
'modal_id' => 'moduleConfirmDelete',
'modal_class' => 'modal-md',
'modal_content' => $modalConfirmDelete->fetch(),
'modal_actions' => array(
array(
'type' => 'button',
'class' => 'process_delete btn-primary',
'label' => $this->l('Delete'),
),
),
));
$response['confirm_delete'] = true;
$response['modalHtml'] = $tpl->fetch();
}
}
$response['success'] = true;
die(Tools::jsonEncode($response));
}
public function setMedia()
{
parent::setMedia();
Media::addJsDef(
array(
'admin_cart_rule_tab_link' => $this->context->link->getAdminLink('AdminCartRules'),
'room_access_err' => $this->l('You can only select room types which hotel(s) access is provided to this employee.'),
'room_rmv_txt' => $this->l('Unselect below room types'),
)
);
$this->addJS(_PS_JS_DIR_.'admin/cart-rules.js');
$this->addJqueryPlugin(array('typewatch', 'fancybox', 'autocomplete'));
}

View File

@@ -296,9 +296,51 @@ class AdminSlipControllerCore extends AdminController
return '--';
}
public function ajaxProcessInitSlipStatusModal()
{
$response = array('success' => false);
if ($idOrderSlip = Tools::getValue('id_order_slip')) {
if (Validate::isLoadedObject($objOrderSlip = new OrderSlip($idOrderSlip, $this->context->language->id))) {
$objOrder = new Order($objOrderSlip->id_order);
$objCustomer = new Customer($objOrder->id_customer);
$modalConfirmDelete = $this->createTemplate('modal_confirm_update.tpl');
$modalConfirmDelete->assign(array(
'customer' => $objCustomer,
'order' => $objOrder,
'orderSlip' => $objOrderSlip,
'link' => $this->context->link
));
$tpl = $this->createTemplate('modal.tpl');
$tpl->assign(array(
'modal_id' => 'moduleConfirmUpdate',
'modal_class' => 'modal-md',
'modal_content' => $modalConfirmDelete->fetch(),
'modal_actions' => array(
array(
'type' => 'button',
'class' => 'process_update btn-primary',
'label' => $this->l('Change status'),
),
),
));
$response['modalHtml'] = $tpl->fetch();
}
}
$response['success'] = true;
die(Tools::jsonEncode($response));
}
public function setMedia()
{
parent::setMedia();
Media::addJsDef(
array(
'admin_order_slip_tab_link' => $this->context->link->getAdminLink('AdminSlip'),
)
);
$this->addJS(_PS_JS_DIR_.'admin/slips.js');
}

144
js/admin/cart-rules.js Normal file
View File

@@ -0,0 +1,144 @@
/**
* Since 2010 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* 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 https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright Since 2010 Webkul IN
* @license https://store.webkul.com/license.html
*/
$(document).ready(function() {
$('.btn-group-action .delete').on('click', function (e) {
e.preventDefault();
var id_cart_rule = $.trim($(this).closest('tr').find('td[data-key="id_cart_rule"]').text());
processDelete(id_cart_rule, $(this).attr('href'))
return false;
});
function processDelete(id_cart_rule, link)
{
confirmDelete(id_cart_rule).then((toDelete) => {
if (toDelete) {
window.location = link;
}
});
}
function confirmDelete(id_cart_rule)
{
return new Promise((resolve) => {
$.ajax({
type: 'POST',
url: admin_cart_rule_tab_link,
dataType: 'JSON',
cache: false,
data: {
ajax: true,
action: 'InitRuleDeleteModal',
id_cart_rule: id_cart_rule
},
success: function(result) {
if (result.success && result.confirm_delete) {
$('#moduleConfirmDelete').remove();
$('#footer').next('.bootstrap').append(result.modalHtml);
$('#moduleConfirmDelete').modal('show');
$('#moduleConfirmDelete .process_delete').click(() => {
resolve(true);
});
$('#moduleConfirmDelete .btn-close').click(() => {
resolve(false);
});
} else {
resolve(true);
}
},
complete: function() {
$(".loading_overlay").hide();
}
});
});
}
});
function confirmDeleteBulk(form)
{
var id_cart_rules = [];
$(form).find('[name="cart_ruleBox[]"]:checked').each(function () {
id_cart_rules.push($(this).val());
});
return new Promise((resolve) => {
$.ajax({
type: 'POST',
url: admin_cart_rule_tab_link,
dataType: 'JSON',
cache: false,
data: {
ajax: true,
action: 'InitRuleBulkDeleteModal',
id_cart_rule: id_cart_rules
},
success: function(result) {
if (result.success && result.confirm_delete) {
$('#moduleConfirmDelete').remove();
$('#footer').next('.bootstrap').append(result.modalHtml);
$('#moduleConfirmDelete').modal('show');
$('#moduleConfirmDelete .process_delete').click(() => {
resolve(true);
});
$('#moduleConfirmDelete .btn-close').click(() => {
resolve(false);
});
} else {
resolve(true);
}
},
complete: function() {
$(".loading_overlay").hide();
}
});
});
}
function sendBulkAction(form, action)
{
confirmDeleteBulk(form).then((toDelete) => {
if (toDelete) {
String.prototype.splice = function(index, remove, string) {
return (this.slice(0, index) + string + this.slice(index + Math.abs(remove)));
};
var form_action = $(form).attr('action');
if (form_action.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,'').replace(/\s+/g,' ') == '')
return false;
if (form_action.indexOf('#') == -1)
$(form).attr('action', form_action + '&' + action);
else
$(form).attr('action', form_action.splice(form_action.lastIndexOf('&'), 0, '&' + action));
$(form).submit();
}
});
}
$(document).on('change', '.cart_rule_to_delete', function() {
if ($(this).prop('checked')) {
$('[name="cart_ruleBox[]"][value="'+$(this).val()+'"]').prop('checked', true);
} else {
$('[name="cart_ruleBox[]"][value="'+$(this).val()+'"]').prop('checked', false);
}
});

View File

@@ -48,4 +48,56 @@ $(document).ready(function() {
}
},
});
$('.change_status').on('click', function (e) {
e.preventDefault();
var id_order_slip = $.trim($(this).closest('tr').find('td[data-key="id_order_slip"]').text());
processupdate(id_order_slip, $(this).attr('href'))
return false;
});
function processupdate(id_order_slip, link)
{
confirmDelete(id_order_slip).then((toUpdate) => {
if (toUpdate) {
window.location = link;
}
});
}
function confirmDelete(id_order_slip)
{
return new Promise((resolve) => {
$.ajax({
type: 'POST',
url: admin_order_slip_tab_link,
dataType: 'JSON',
cache: false,
data: {
ajax: true,
action: 'initSlipStatusModal',
id_order_slip: id_order_slip
},
success: function(result) {
if (result.success && result.modalHtml) {
$('#moduleConfirmUpdate').remove();
$('#footer').next('.bootstrap').append(result.modalHtml);
$('#moduleConfirmUpdate').modal('show');
$('#moduleConfirmUpdate .process_update').click(() => {
resolve(true);
});
$('#moduleConfirmUpdate .btn-close').click(() => {
resolve(false);
});
} else {
resolve(true);
}
},
complete: function() {
$(".loading_overlay").hide();
}
});
});
}
});