From 9180ded3e1785771708949a723c2454ea0cc7d6e Mon Sep 17 00:00:00 2001 From: Marion Muszynski Date: Fri, 12 May 2017 11:12:07 +0200 Subject: [PATCH] continuing refunding part --- .../AdminAntReturnprocess.php | 120 ++++++++++++++++-- 1 file changed, 108 insertions(+), 12 deletions(-) diff --git a/modules/ant_returnprocess/AdminAntReturnprocess.php b/modules/ant_returnprocess/AdminAntReturnprocess.php index 3d2201d2..b578633c 100644 --- a/modules/ant_returnprocess/AdminAntReturnprocess.php +++ b/modules/ant_returnprocess/AdminAntReturnprocess.php @@ -52,7 +52,7 @@ class AdminAntReturnprocess extends AdminTab Mail::Send((int)$order->id_lang, 'order_return_state', Mail::l('Your order return state has changed', (int)$order->id_lang), $vars, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, NULL, NULL, _PS_MAIL_DIR_, true); - Tools::redirectAdmin($currentIndex.'&id_order_return='.(int)$id_order_return.'&updateorder_return&conf=4&token='.$this->token); + Tools::redirectAdmin($currentIndex.'&id_order_return='.(int)$id_order_return.'&updateorder_return&ok=2&token='.$this->token); } } else { HelperFormBootstrap::displayErrors(Tools::displayError('No order return ID.')); @@ -104,7 +104,7 @@ class AdminAntReturnprocess extends AdminTab $ct->update(); $cm->update(); } - Tools::redirectAdmin($currentIndex.'&id_order_return='.(int)$id_order_return.'&updateorder_return&conf=4&token='.$this->token); + Tools::redirectAdmin($currentIndex.'&id_order_return='.(int)$id_order_return.'&updateorder_return&ok=3&token='.$this->token); } else { HelperFormBootstrap::displayErrors(Tools::displayError('An error occurred, your message was not sent. Please contact your system administrator.')); } @@ -154,10 +154,48 @@ class AdminAntReturnprocess extends AdminTab $customer->email, $customer->firstname.' '.$customer->lastname ); - Tools::redirectAdmin($currentIndex.'&id_order_return='.(int)$id_order_return.'&updateorder_return&conf=4&token='.$this->token); + Tools::redirectAdmin($currentIndex.'&id_order_return='.(int)$id_order_return.'&updateorder_return&ok=4&token='.$this->token); } else { HelperFormBootstrap::displayErrors(Tools::displayError('Order ID missing.')); } + } elseif (Tools::isSubmit('submitOrderState') && Tools::getValue('id_order_return') && ($id_order = (int)(Tools::getValue('id_order'))) AND Validate::isLoadedObject($order = new Order($id_order))) { + + $id_order_return = (int) Tools::getValue('id_order_return'); + if (!$newOrderStatusId = (int)(Tools::getValue('id_order_state'))) { + HelperFormBootstrap::displayErrors(Tools::displayError('Invalid new order status')); + } else { + $history = new OrderHistory(); + $history->id_order = (int)$id_order; + $history->id_employee = (int)($cookie->id_employee); + $history->changeIdOrderState((int)($newOrderStatusId), (int)($id_order)); + $order = new Order((int)$order->id); + $carrier = new Carrier((int)($order->id_carrier), (int)($order->id_lang)); + + $templateVars = array(); + if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') AND $order->shipping_number) { + $templateVars = array('{followup}' => str_replace('@', $order->shipping_number, $carrier->url)); + } elseif ($history->id_order_state == Configuration::get('PS_OS_CHEQUE')) { + $templateVars = array( + '{cheque_name}' => (Configuration::get('CHEQUE_NAME') ? Configuration::get('CHEQUE_NAME') : ''), + '{cheque_address_html}' => (Configuration::get('CHEQUE_ADDRESS') ? nl2br(Configuration::get('CHEQUE_ADDRESS')) : '')); + } elseif ($history->id_order_state == Configuration::get('PS_OS_BANKWIRE')) { + $templateVars = array( + '{bankwire_owner}' => (Configuration::get('BANK_WIRE_OWNER') ? Configuration::get('BANK_WIRE_OWNER') : ''), + '{bankwire_details}' => (Configuration::get('BANK_WIRE_DETAILS') ? nl2br(Configuration::get('BANK_WIRE_DETAILS')) : ''), + '{bankwire_address}' => (Configuration::get('BANK_WIRE_ADDRESS') ? nl2br(Configuration::get('BANK_WIRE_ADDRESS')) : '')); + } + + if (Tools::getValue('noSendMail')) { + if ($history->add()) { + Tools::redirectAdmin($currentIndex.'&id_order_return='.(int)$id_order_return.'&updateorder_return&ok=5&token='.$this->token); + } + } else { + if ($history->addWithemail(true, $templateVars)) { + Tools::redirectAdmin($currentIndex.'&id_order_return='.(int)$id_order_return.'&updateorder_return&ok=5&token='.$this->token); + } + } + HelperFormBootstrap::displayErrors(Tools::displayError('An error occurred while changing the status or was unable to send e-mail to the customer.')); + } } } @@ -189,14 +227,31 @@ class AdminAntReturnprocess extends AdminTab } } - if (isset($_GET['updateorder_return'])) - { + if (isset($_GET['updateorder_return'])) { + if(isset($_GET['ok'])){ + switch ($_GET['ok']) { + case '2': + $success_mess = 'Mise à jour enregistrée'; + break; + case '3': + $success_mess = 'Votre message a bien été envoyé'; + break; + case '4': + $success_mess = 'Les instructions on été renvoyées'; + break; + case '5': + $success_mess = 'Le nouveau statut de le commande a bien été enregistré'; + break; + default: + $success_mess = 'Mise à jour enregistrée'; + break; + } + HelperFormBootstrap::displaySuccess($success_mess); + } $this->displayForm(); echo '

'.$this->l('Back to list').'
'; - } - else - { + } else { $this->displaylist(); } } @@ -216,7 +271,7 @@ class AdminAntReturnprocess extends AdminTab $customer = new Customer((int)$order->id_customer); $data = $this->getOrderDetail($cart,(int)$cart->id_lang,$order); $currency = new Currency((int)(Configuration::get('PS_CURRENCY_DEFAULT'))); - $currentState = OrderHistory::getLastOrderState((int)$orderReturn->id_order); + $orderStates = OrderState::getOrderStates((int)($cookie->id_lang)); $shipping_numbers = Db::getInstance()->ExecuteS(' SELECT DISTINCT lpws.`shipping_number`, lpws.`date_add` FROM `'._DB_PREFIX_.'lapostews` lpws @@ -472,9 +527,9 @@ class AdminAntReturnprocess extends AdminTab '.$this->l('Prix U').' '.$this->l('Qté').' '.($order->hasBeenPaid() ?''.$this->l('Remb').'':'').' - '.($order->hasBeenDelivered() ?''.$this->l('Retour').'':'').' '.$this->l('Stock').' '.$this->l('Total').' + '.($order->module ? ($order->module=="paybox"?' ':' ') : '').' '; @@ -500,7 +555,7 @@ class AdminAntReturnprocess extends AdminTab - '.$product['product_name'].'
+ '.$product['product_name'].'
'.($product['product_reference'] ? ''.$this->l('Ref:').' '.$product['product_reference'].'
' : '') .($product['product_supplier_reference'] ? ''.$this->l('Ref Supplier:').' '.$product['product_supplier_reference'].'' : '') .'
@@ -508,9 +563,10 @@ class AdminAntReturnprocess extends AdminTab '.Tools::displayPrice($product_price,$currency).' '.$quantity.' '.($order->hasBeenPaid() ? ''.(int)($product['product_quantity_refunded']).'' : '').' - '.($order->hasBeenDelivered() ? ''.(int)($product['product_quantity_return']).'' : '').' '.(int)$stock['quantity'].' '.Tools::displayPrice(Tools::ps_round($product_price, 2) * ((int)($product['product_quantity']) - $product['customizationQuantityTotal']), $currency, false).' + + '; } } @@ -518,6 +574,46 @@ class AdminAntReturnprocess extends AdminTab +
+
+
+
+
'.$this->l('Changer le statut de la commande').'
+
+
+ +
+
+ +
+ + + +
+
+ +