123 lines
5.1 KiB
PHP
123 lines
5.1 KiB
PHP
<?php
|
|
if (!defined('_PS_VERSION_'))
|
|
exit;
|
|
|
|
class RefundReason extends Module {
|
|
public function __construct() {
|
|
$this->name = 'refundreason';
|
|
$this->tab = 'administration';
|
|
$this->author = 'Antadis';
|
|
$this->version = '1.0';
|
|
parent::__construct();
|
|
|
|
$this->displayName = $this->l('Reason for refund');
|
|
$this->description = $this->l('Allows to give a reason for refunds');
|
|
|
|
$this->reasons = array(
|
|
'---',
|
|
$this->l('Cancelled (before shipping)'),
|
|
$this->l('Cancelled (received, -7d)'),
|
|
$this->l('Return (received +7d)'),
|
|
$this->l('Product default'),
|
|
$this->l('Missing product (supplier)'),
|
|
$this->l('Logistics error'),
|
|
$this->l('Other'),
|
|
$this->l('ZZZZZ1'),
|
|
$this->l('ZZZZZ2'),
|
|
$this->l('ZZZZZ3'),
|
|
$this->l('ZZZZZ4'),
|
|
$this->l('ZZZZZ5'),
|
|
);
|
|
}
|
|
|
|
public function uninstall() {
|
|
Db::getInstance()->Execute('
|
|
DROP TABLE `'._DB_PREFIX_.'refundreason`
|
|
');
|
|
return parent::uninstall();
|
|
}
|
|
|
|
public function install() {
|
|
if(!(parent::install()
|
|
&& Db::getInstance()->Execute('
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'refundreason` (
|
|
`id_reason` INTEGER NOT NULL,
|
|
`id_order_slip` INTEGER NOT NULL,
|
|
`id_employee` INTEGER DEFAULT NULL,
|
|
PRIMARY KEY(`id_reason`, `id_order_slip`)
|
|
) ENGINE=MyIsam DEFAULT CHARSET=utf8
|
|
')
|
|
&& $this->registerHook('adminOrder')
|
|
&& $this->registerHook('orderSlip')
|
|
)) {
|
|
return FALSE;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
public function hookAdminOrder($params) {
|
|
global $cookie;
|
|
|
|
$output = '';
|
|
|
|
if($reasons = Db::getInstance()->ExecuteS('
|
|
SELECT *
|
|
FROM `'._DB_PREFIX_.'order_slip` s
|
|
LEFT JOIN `'._DB_PREFIX_.'refundreason` r
|
|
ON s.`id_order_slip` = r.`id_order_slip`
|
|
WHERE s.`id_order` = '.(int) $params['id_order'].'
|
|
')) {
|
|
$output .= '<br />
|
|
<fieldset style="width: 400px; font-size: 12px; line-height: 1.5em;">
|
|
<legend><img alt="'.$this->l('Refund reasons').'" src="../img/admin/return.gif">'.$this->l('Refund reasons').'</legend>
|
|
';
|
|
foreach($reasons as $reason) {
|
|
$output .= '<strong><a onclick="window.open(this.href); return false;" href="'.__PS_BASE_URI__.'adm/pdf.php?id_order_slip='.$reason['id_order_slip'].'">'.$this->l('#').$reason['id_order_slip'].'</a></strong>'.$this->l(':').' '.$this->reasons[$reason['id_reason']].'<br />';
|
|
}
|
|
$output .= '
|
|
</fieldset>';
|
|
}
|
|
|
|
$output .= '
|
|
<script type="text/javascript">
|
|
<!--
|
|
$(document).ready(function() {
|
|
$(\'<select id=\"typeReason\" name=\"typeReason\" style=\"display:none; margin-top: 5px; width: 167px;\"><option value=\"0\" style="color: #999999;">'.$this->l('Refund reason').'</option><option value=\"1\">'.$this->l('Cancelled (before shipping)').'</option><option value=\"2\">'.$this->l('Cancelled (received, -7d)').'</option><option value=\"11\">'.$this->l('ZZZZZ4').'</option><option value=\"4\">'.$this->l('Product default').'</option><option value=\"5\">'.$this->l('Missing product (supplier)').'</option><option value=\"3\">'.$this->l('Return (received +7d)').'</option><option value=\"6\">'.$this->l('Logistics error').'</option><option value=\"8\">'.$this->l('ZZZZZ1').'</option><option value=\"12\">'.$this->l('ZZZZZ5').'</option><option value=\"9\">'.$this->l('ZZZZZ2').'</option><option value=\"10\">'.$this->l('ZZZZZ3').'</option><option value=\"7\">'.$this->l('Other').'</option></select>\').insertAfter(\'#spanShippingBack\');
|
|
|
|
$(\'<p class="center"><select id=\"typeReasonTotal\" name=\"typeReason\"><option value=\"0\" style="color: #999999;">'.$this->l('Refund reason').'</option><option value=\"1\">'.$this->l('Cancelled (before shipping)').'</option><option value=\"2\">'.$this->l('Cancelled (received, -7d)').'</option><option value=\"11\">'.$this->l('ZZZZZ4').'</option><option value=\"4\">'.$this->l('Product default').'</option><option value=\"5\">'.$this->l('Missing product (supplier)').'</option><option value=\"3\">'.$this->l('Return (received +7d)').'</option><option value=\"6\">'.$this->l('Logistics error').'</option><option value=\"8\">'.$this->l('ZZZZZ1').'</option><option value=\"12\">'.$this->l('ZZZZZ5').'</option><option value=\"9\">'.$this->l('ZZZZZ2').'</option><option value=\"10\">'.$this->l('ZZZZZ3').'</option><option value=\"7\">'.$this->l('Other').'</option></select></p>\').insertBefore(\'form.refundform p\');
|
|
|
|
$("#generateCreditSlip, .cancelCheck input").click(function() {
|
|
if($("#generateCreditSlip:checked").length == 1) {
|
|
$("#typeReason").show();
|
|
} else {
|
|
$("#typeReason").hide();
|
|
}
|
|
});
|
|
});
|
|
-->
|
|
</script>
|
|
';
|
|
|
|
return $output;
|
|
}
|
|
|
|
public function hookOrderSlip($params) {
|
|
global $cookie;
|
|
|
|
$id_order = (int) $params['order']->id;
|
|
$id_reason = Tools::getValue('typeReason');
|
|
|
|
if($slip = Db::getInstance()->getRow('
|
|
SELECT `id_order_slip`
|
|
FROM `'._DB_PREFIX_.'order_slip`
|
|
WHERE `id_order` = '.$id_order.'
|
|
ORDER BY `date_add` DESC
|
|
')) {
|
|
Db::getInstance()->ExecuteS('
|
|
INSERT INTO `'._DB_PREFIX_.'refundreason`
|
|
VALUES ('.(int) $id_reason.', '.(int) $slip['id_order_slip'].', '.(int) $cookie->id_employee.')
|
|
');
|
|
}
|
|
}
|
|
}
|