Merge branch 'ticket-13166-RetourProcess_3' into develop

This commit is contained in:
Marion Muszynski 2017-06-26 11:53:16 +02:00
commit 45fbaac030
3 changed files with 162 additions and 10 deletions

View File

@ -1574,7 +1574,7 @@ class AdminOrders extends AdminTab
}
echo '('.Tools::displayDate($return['date_upd'], $cookie->id_lang).') :
<b><a href="index.php?tab=AdminReturn&id_order_return='.$return['id_order_return'].'&updateorder_return&token='.Tools::getAdminToken('AdminReturn'.(int)(Tab::getIdFromClassName('AdminReturn')).(int)($cookie->id_employee)).'">'.$this->l('#').sprintf('%06d', $return['id_order_return']).'</a></b> -
<b><a href="index.php?tab=AdminAntReturnprocess&id_order_return='.$return['id_order_return'].'&updateorder_return&token='.Tools::getAdminToken('AdminAntReturnprocess'.(int)(Tab::getIdFromClassName('AdminAntReturnprocess')).(int)($cookie->id_employee)).'">'.$this->l('#').sprintf('%06d', $return['id_order_return']).'</a></b> -
'.$state->name[$cookie->id_lang].'<br />'.($return_link? ' ('.$this->l('return link:').' <a href="'.$return_link['link'].'" onclick="window.open(this.href); return false;">'.$return_link['return_number'].'</a> <a class="button" href="'.$currentIndex.'&send_return_instruction=1&id_order_return='.$return['id_order_return'].'&id_order='.(int)($order->id).'&vieworder&token='.$this->token.'">'.$this->l('Renvoyer les instructions retour').'</a>)': '');
}

View File

@ -250,6 +250,64 @@ class AdminAntReturnprocess extends AdminTab
} else {
HelperFormBootstrap::displayErrors(Tools::displayError('No order return ID.'));
}
} elseif(Tools::isSubmit('submitOrderMessage')){
if (!($id_order = (int)(Tools::getValue('id_order'))) OR !($id_customer = (int)(Tools::getValue('id_customer')))) {
HelperFormBootstrap::displayErrors(Tools::displayError('An error occurred before sending message'));
return;
} elseif (!Tools::getValue('message')) {
HelperFormBootstrap::displayErrors(Tools::displayError('Message cannot be blank'));
return;
} else {
/* Get message rules and and check fields validity */
$rules = call_user_func(array('Message', 'getValidationRules'), 'Message');
foreach ($rules['required'] AS $field) {
if (($value = Tools::getValue($field)) == false AND (string)$value != '0') {
if (!Tools::getValue('id_'.$this->table) OR $field != 'passwd') {
HelperFormBootstrap::displayErrors(Tools::displayError('field').' <b>'.$field.'</b> '.Tools::displayError('is required.'));
return;
}
}
}
foreach ($rules['size'] AS $field => $maxLength) {
if (Tools::getValue($field) AND Tools::strlen(Tools::getValue($field)) > $maxLength) {
HelperFormBootstrap::displayErrors(Tools::displayError('field').' <b>'.$field.'</b> '.Tools::displayError('is too long.').' ('.$maxLength.' '.Tools::displayError('chars max').')');
return;
}
}
foreach ($rules['validate'] AS $field => $function) {
if (Tools::getValue($field)) {
if (!Validate::$function(htmlentities(Tools::getValue($field), ENT_COMPAT, 'UTF-8'))) {
HelperFormBootstrap::displayErrors(Tools::displayError('field').' <b>'.$field.'</b> '.Tools::displayError('is invalid.'));
return;
}
}
}
$message = new Message();
$message->id_employee = (int)($cookie->id_employee);
$message->message = htmlentities(Tools::getValue('message'), ENT_COMPAT, 'UTF-8');
$message->id_order = $id_order;
$message->private = Tools::getValue('visibility');
if (!$message->add()) {
HelperFormBootstrap::displayErrors(Tools::displayError('An error occurred while sending message.'));
return;
} elseif ($message->private) {
HelperFormBootstrap::displaySuccess('Message bien envoyé');
return;
} elseif (Validate::isLoadedObject($customer = new Customer($id_customer))) {
$order = new Order((int)($message->id_order));
if (Validate::isLoadedObject($order))
{
$varsTpl = array('{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{id_order}' => $message->id_order, '{message}' => (Configuration::get('PS_MAIL_TYPE') == 2 ? $message->message : nl2br2($message->message)));
if (@Mail::Send((int)($order->id_lang), 'order_merchant_comment', Mail::l('New message regarding your order'), $varsTpl, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, NULL, NULL, _PS_MAIL_DIR_, true)){
HelperFormBootstrap::displaySuccess('Message bien envoyé');
return;
}
}
}
HelperFormBootstrap::displayErrors('Une erreur est survenue !');
return;
}
} elseif(Tools::getValue('send_return_instruction') && Tools::getValue('id_order_return')) {
$id_order = (int) Tools::getValue('id_order');
$id_order_return = (int) Tools::getValue('id_order_return');
@ -332,6 +390,12 @@ class AdminAntReturnprocess extends AdminTab
}
HelperFormBootstrap::displayErrors(Tools::displayError('An error occurred while changing the status or was unable to send e-mail to the customer.'));
}
} elseif(Tools::isSubmit('submitPayPalRefund') && Tools::getValue('id_order_return') && ($id_order = (int)(Tools::getValue('id_order'))) AND Validate::isLoadedObject($order = new Order($id_order))) {
$paypal = new Paypal();
if(!$paypal->generateTotalRefund($id_order)){
HelperFormBootstrap::displayErrors('Le remboursement n\'a pu avoir lieu');
return;
}
} elseif(Tools::isSubmit('submitCancelProduct') && Tools::getValue('id_order_return') && ($id_order = (int)(Tools::getValue('id_order'))) AND Validate::isLoadedObject($order = new Order($id_order))) {
$_POST['generateCreditSlip'] = 1;
$customer = new Customer($order->id_customer);
@ -903,6 +967,14 @@ class AdminAntReturnprocess extends AdminTab
);
}
$last_order_message = Db::getInstance()->getRow('
SELECT om.*, e.firstname, e.lastname
FROM `'._DB_PREFIX_.'message` om
LEFT JOIN `'._DB_PREFIX_.'employee` e ON (e.id_employee = om.id_employee)
WHERE om.id_order = '.(int)$order->id.' AND om.id_employee!=0 AND om.private=1
ORDER BY om.date_add DESC
');
$parcel_sent = Db::getInstance()->ExecuteS('
SELECT lpr.*, od.`product_name`
FROM '._DB_PREFIX_.'lapostews_return lpr
@ -964,6 +1036,7 @@ class AdminAntReturnprocess extends AdminTab
<input type="hidden" value="'.$id_order_return.'" id="id_order_return" name="id_order_return">
<input type="hidden" value="0" id="id_order_detail" name="id_order_detail">
<div class="form-group">
<label class="control-label">Raison</label>
<select class="form-control" id="reason" name="reason">
<option value="0">Changer les instructions</option>
<option value="2">CLIENT : Rétractation post-envoi</option>
@ -980,6 +1053,7 @@ class AdminAntReturnprocess extends AdminTab
</select>
</div>
<div class="form-group">
<label class="control-label">Instructions</label>
<select class="form-control" id="instruction" name="instruction">
<option value="0">Changer la Raison</option>
<option value="1">Remboursement + Mise en stock</option>
@ -1094,7 +1168,7 @@ class AdminAntReturnprocess extends AdminTab
'.$this->l('Commentaire').'
<a style="cursor:pointer;color:#fff;" class="pull-right" data-toggle="modal" data-target="#returnCommentModal"><i class="glyphicon glyphicon-edit"></i></a>
</h5>
<p class="" style="margin-bottom:20px; padding:0 10px;">'.(($return_link && !empty($return_link['return_comment']))?$return_link['return_comment']:'Sans commentaire').'<p>';
<p class="" style="margin-bottom:20px; padding:5px 20px;background:#efefef;">'.(($return_link && !empty($return_link['return_comment']))?$return_link['return_comment']:'Sans commentaire').'<p>';
if($return_history && !empty($return_history)) {
$html .= '
@ -1328,10 +1402,21 @@ class AdminAntReturnprocess extends AdminTab
</div>
<input type="hidden" name="id_order" value="'.$order->id.'" />
<input type="hidden" name="id_order_return" value="'.$orderReturn->id.'" />
<input class="btn btn-primary" type="submit" name="submitCancelProduct" value="Générer un remboursement"/>
<input class="btn btn-primary pull-right" type="submit" name="submitCancelProduct" value="Générer un Remboursement"/>
</div>
</div>
</form>
</form>';
if($order->module && $order->module=="paypal"){
$html.='
<form style="margin-top:10px;" action="'.$currentIndex.'&submitCancelProduct=1&updateorder_return&id_order_return='.(int)$orderReturn->id.'&token='.$this->token.'" method="post">
<div class="form-inline text-right">
<input type="hidden" name="id_order" value="'.$order->id.'" />
<input type="hidden" name="id_order_return" value="'.$orderReturn->id.'" />
<button type="submit" class="btn btn-primary" name="submitPayPalRefund">Remboursement Total Paypal <span class="anticon anticon-paypal"></span></button>
</div>
</form>';
}
$html.='
</div>
<div class="clearfix"></div>
<div class="ln_solid"></div>
@ -1579,6 +1664,7 @@ class AdminAntReturnprocess extends AdminTab
<div class="panel-content">
<div class="row">
<div class="col-md-12">';
$orderMessages = OrderMessage::getOrderMessages((int)($order->id_lang));
if(isset($thread)){
if($thread->id_order == $orderReturn->id_order) {
$products = Db::getInstance()->ExecuteS('
@ -1611,28 +1697,32 @@ class AdminAntReturnprocess extends AdminTab
}
}
if($last_message){
$html .='<h5 style="background:#504D8B;color:#fff;padding:5px; text-align:center;">Dernier Message '.($thread->id_order != $orderReturn->id_order?'<br/><i>(Ne concerne pas cette commande)</i>':'').'</h5>';
$html .='<h5 style="background:#504D8B;color:#fff;padding:5px; text-align:center;">
Dernier Message '.($thread->id_order != $orderReturn->id_order?'<br/><i>(Ne concerne pas cette commande)</i>':'').'
<a class="pull-right" style="color:#fff;" role="button" data-toggle="collapse" href="#last_message_box" aria-expanded="false" aria-controls="last_message_box">
<i class="anticon anticon-info"></i>
</a>
</h5>';
$last_message['message'] = preg_replace('/(https?:\/\/[a-z0-9#%&_=\(\)\.\? \+\-@\/]{6,1000})([\s\n<])/Uui', '<a href="\1">\1</a>\2', html_entity_decode($last_message['message'], ENT_NOQUOTES, 'UTF-8'));
if(!empty($last_message['employee_name'])) {
$html .='
<div>
<p class="text-center"><span class="anticon anticon-user-tie"></span> Bébé Boutik - ('.Tools::displayDate($last_message['date_add'], (int)($cookie->id_lang), true).')</p>
<p class="text-center"><span class="anticon anticon-user-tie"></span> Bébé Boutik - ('.Tools::displayDate($last_message['date_add'], (int)($cookie->id_lang), true).')</p>
<div id="last_message_box" class="collapse">
<p style="padding:5px 20px;background:#efefef;">
"'.$last_message['message'].'"
</p>
</div>';
} else {
$html .='
<div>
<p class="text-center"><span class="anticon anticon-user"></span> '.$customer->firstname.' '.$customer->lastname.' - ('.Tools::displayDate($last_message['date_add'], (int)($cookie->id_lang), true).')</p>
<p class="text-center"><span class="anticon anticon-user"></span> '.$customer->firstname.' '.$customer->lastname.' - ('.Tools::displayDate($last_message['date_add'], (int)($cookie->id_lang), true).')</p>
<div id="last_message_box" class="collapse">
<p style="padding:5px 20px;background:#efefef;">
"'.$last_message['message'].'"
</p>
</div>';
}
$orderMessages = OrderMessage::getOrderMessages((int)($last_message['id_lang']));
$html .='
<div>
<h5 style="background:#504D8B;color:#fff;padding:5px; text-align:center;">Envoyer un message</h5>
@ -1669,6 +1759,64 @@ class AdminAntReturnprocess extends AdminTab
</div>
</div>
<div class="panel">
<div class="panel-title">
<h2><span class="anticon anticon-bubbles4"></span> Message pour cette Commande</h2>
<div class="clearfix"></div>
</div>
<div class="panel-content">
<div class="row">
<div class="col-md-12">
<div><p class="text-center">Laissez un message à votre service client pour cette commande</p></div>';
if($last_order_message){
$html .='
<h5 style="background:#504D8B;color:#fff;padding:5px; text-align:center;">
Dernier un message
<a class="pull-right" style="color:#fff;" role="button" data-toggle="collapse" href="#last_order_message_box" aria-expanded="false" aria-controls="last_order_message_box">
<i class="anticon anticon-info"></i>
</a>
</h5>
<p class="text-center"><span class="anticon anticon-user-tie"></span> '.$last_order_message['firstname'].' '.$last_order_message['lastname'].' - ('.Tools::displayDate($last_order_message['date_add'], (int)($cookie->id_lang), true).')</p>
<div class="collapse" id="last_order_message_box">
<p style="padding:5px 20px;background:#efefef;">
"'.$last_order_message['message'].'"
</p>
</div>';
}
$html .='
<div>
<h5 style="background:#504D8B;color:#fff;padding:5px; text-align:center;">Laissez un message</h5>
<form action="'.Tools::htmlentitiesutf8($_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data">
<div class="form-group">
<select class="form-control" name="order_message" id="order_message" onchange="orderOverwriteMessage(this, \''.$this->l('Do you want to overwrite your existing message?').'\')">
<option value="0" selected="selected">-- '.$this->l('Choose a standard message').' --</option>';
foreach ($orderMessages AS $orderMessage) {
$html .= '<option value="'.htmlentities($orderMessage['message'], ENT_COMPAT, 'UTF-8').'">'.$orderMessage['name'].'</option>';
}
$html .= '
</select>
</div>
<div class="form-group">
<textarea rows="5" class="form-control" id="txt_msg" name="message">'.str_replace('\r\n', "\n", Configuration::get('PS_CUSTOMER_SERVICE_SIGNATURE', (int)$order->id_lang)).'</textarea>
</div>
<div class="checkbox text-center">
<label style="min-height:0px;">
<input type="checkbox" value="1" name="visibility" /> Ne pas montrer au client
</label>
</div>
<div style="text-align: right;">
<input type="hidden" name="id_order" value="'.$order->id.'" />
<input type="hidden" name="id_customer" value="'.$order->id_customer.'" />
<input type="hidden" name="id_order_return" value="'.$orderReturn->id.'" />
<input type="submit" class="btn btn-primary" name="submitOrderMessage" value="'.$this->l('Envoyer').'" style="margin-top:20px;" />
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>';

View File

@ -1126,6 +1126,10 @@ class PayPal extends PaymentModule
return $new_message->add();
}
public function generateTotalRefund($id_order){
$this->_doTotalRefund($id_order);
}
private function _doTotalRefund($id_order)
{
$paypal_order = PayPalOrder::getOrderById((int)$id_order);