diff --git a/classes/order/OrderSlip.php b/classes/order/OrderSlip.php
index 758b6773a..62574b1c7 100644
--- a/classes/order/OrderSlip.php
+++ b/classes/order/OrderSlip.php
@@ -77,6 +77,8 @@ class OrderSlipCore extends ObjectModel
/** @var int */
public $order_slip_type = 0;
+ public $remark;
+
const REDEEM_STATUS_ACTIVE = 1;
const REDEEM_STATUS_REDEEMED = 2;
const REFUND_ORDER_SLIP_TYPE = 1;
@@ -103,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'),
),
);
@@ -157,6 +160,34 @@ class OrderSlipCore extends ObjectModel
ORDER BY `date_add` DESC');
}
+ public static function getTotalSlipAmountByOrder($id_order)
+ {
+ return (float) Db::getInstance()->getValue('
+ SELECT SUM(`amount`)
+ FROM `'._DB_PREFIX_.'order_slip`
+ WHERE `id_order` = '.(int)$id_order
+ );
+ }
+
+ public static function getSlipIdsByOrder($id_order)
+ {
+ $rows = Db::getInstance()->executeS('
+ SELECT `id_order_slip`
+ FROM `'._DB_PREFIX_.'order_slip`
+ WHERE `id_order` = '.(int)$id_order.'
+ ORDER BY `id_order_slip` ASC'
+ );
+
+ $slipIds = array();
+ if ($rows) {
+ foreach ($rows as $row) {
+ $slipIds[] = (int) $row['id_order_slip'];
+ }
+ }
+
+ return $slipIds;
+ }
+
public static function getOrdersSlipDetail($id_order_slip = false, $id_order_detail = false)
{
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
@@ -313,7 +344,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 , $orderSlipType = false)
+ 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();
@@ -437,6 +468,9 @@ class OrderSlipCore extends ObjectModel
if (isset($orderSlipType) && $orderSlipType) {
$order_slip->order_slip_type = $orderSlipType;
}
+ if (isset($remark) && $remark) {
+ $order_slip->remark = $remark;
+ }
if (!$order_slip->add()) {
return false;
diff --git a/config/defines.inc.php b/config/defines.inc.php
index f16e93903..d78f92763 100644
--- a/config/defines.inc.php
+++ b/config/defines.inc.php
@@ -26,7 +26,7 @@
/* Debug only */
if (!defined('_PS_MODE_DEV_')) {
- define('_PS_MODE_DEV_', false);
+ define('_PS_MODE_DEV_', true);
}
/* Compatibility warning */
define('_PS_DISPLAY_COMPATIBILITY_WARNING_', false);
diff --git a/controllers/admin/AdminSlipController.php b/controllers/admin/AdminSlipController.php
index c5048a4d8..3f253da30 100644
--- a/controllers/admin/AdminSlipController.php
+++ b/controllers/admin/AdminSlipController.php
@@ -52,20 +52,22 @@ class AdminSlipControllerCore extends AdminController
),
'id_order' => array(
'title' => $this->l('Order ID'),
- 'align' => 'left',
+ 'align' => 'center',
'class' => 'fixed-width-md',
'havingFilter' => true
),
'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 +82,21 @@ 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',
+ // 'class' => 'fixed-width-xxl',
+ 'orderby' => false,
+ 'callback' => 'displayRemark',
),
);
@@ -191,12 +201,21 @@ class AdminSlipControllerCore extends AdminController
'hint' => $this->l('Enter the amount of the credit slip for the customer'),
'name' => 'credit_slip_amount',
'required' => true,
- 'col' => 2,
+ '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'),
@@ -256,6 +275,13 @@ class AdminSlipControllerCore extends AdminController
$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)) {
+ $this->errors[] = $this->l('Remark must be a valid text.');
+ }
+
if (!count($this->errors)) {
$objOrder = new Order(Tools::getValue('id_order'));
$creditAmount = $creditSlipAmount;
@@ -284,7 +310,7 @@ class AdminSlipControllerCore extends AdminController
);
}
- if (!$idCreditSlip = OrderSlip::create($objOrder, $bookingList, 0, $creditAmount, $creditAmount, 0 , OrderSlip::MANUAL_CREDIT_SLIP_TYPE)) {
+ if (!$idCreditSlip = OrderSlip::create($objOrder, $bookingList, 0, $creditAmount, $creditAmount, 0 , OrderSlip::MANUAL_CREDIT_SLIP_TYPE, $remark)) {
$this->errors[] = $this->l('A credit slip cannot be generated. ');
} else {
@@ -444,6 +470,22 @@ class AdminSlipControllerCore extends AdminController
return $this->createTemplate('_display_voucher_link.tpl')->fetch();
}
+ public function displayRemark($remark, $row)
+ {
+ if (empty($remark)) {
+ return '--';
+ }
+
+ $maxLength = 100;
+ if (Tools::strlen($remark) > $maxLength) {
+ return '
'
+ . htmlspecialchars(Tools::substr($remark, 0, $maxLength), ENT_QUOTES, 'UTF-8')
+ . '...';
+ }
+
+ return htmlspecialchars($remark, ENT_QUOTES, 'UTF-8');
+ }
+
public function displayStatusChangeLink($token, $id)
{
$objOrderSlip = new OrderSlip($id);
@@ -540,9 +582,14 @@ class AdminSlipControllerCore extends AdminController
}
unset($booking);
+ $totalSlipAmount = OrderSlip::getTotalSlipAmountByOrder($idOrder);
+ $slipIds = OrderSlip::getSlipIdsByOrder($idOrder);
+
die(Tools::jsonEncode(array(
'bookings' => $bookingDetails,
- 'currency' => $currency
+ 'currency' => $currency,
+ 'total_slip_amount' => $totalSlipAmount,
+ 'slip_ids' => $slipIds
)));
}
diff --git a/install/data/db_structure.sql b/install/data/db_structure.sql
index 7550fbcad..66d4dce03 100644
--- a/install/data/db_structure.sql
+++ b/install/data/db_structure.sql
@@ -1408,6 +1408,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`),
diff --git a/js/admin/slips.js b/js/admin/slips.js
index adc5bf846..c1985e175 100644
--- a/js/admin/slips.js
+++ b/js/admin/slips.js
@@ -134,6 +134,9 @@ $(document).ready(function() {
if (!idOrder) {
$('#order-info').hide();
$('#order-view-link').hide();
+ $('#booking-total-slip-amount').text('-');
+ $('#booking-slip-ids').html('');
+ $('#booking-slip-ids-wrapper').hide();
return;
}
@@ -157,6 +160,22 @@ $(document).ready(function() {
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 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 '
#' + id + '';
+ });
+ $('#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')
@@ -228,8 +247,12 @@ $(document).ready(function() {
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('-');
}
});