diff --git a/modules/ant_returnprocess/AdminAntReturnprocess.php b/modules/ant_returnprocess/AdminAntReturnprocess.php new file mode 100644 index 00000000..faddff35 --- /dev/null +++ b/modules/ant_returnprocess/AdminAntReturnprocess.php @@ -0,0 +1,590 @@ +countProduct()) > 1) { + if (OrderReturn::deleteOrderReturnDetail($id_order_return, $id_order_detail, (int)(Tools::getValue('id_customization', 0)))){ + Tools::redirectAdmin($currentIndex.'&conf=4token='.$this->token); + } else { + HelperFormBootstrap::displayErrors(Tools::displayError('An error occurred while deleting an order return detail.')); + } + } else { + HelperFormBootstrap::displayErrors(Tools::displayError('You need at least one product.')); + } + } else { + HelperFormBootstrap::displayErrors(Tools::displayError('The order return is invalid.')); + } + } else { + HelperFormBootstrap::displayErrors(Tools::displayError('The order return detail is invalid.')); + } + } elseif (Tools::isSubmit('submitAddorder_return')) { + if (($id_order_return = (int)(Tools::getValue('id_order_return'))) AND Validate::isUnsignedId($id_order_return)) + { + $orderReturn = new OrderReturn($id_order_return); + $order = new Order($orderReturn->id_order); + $customer = new Customer($orderReturn->id_customer); + $orderReturn->state = (int)(Tools::getValue('state')); + if ($orderReturn->save()) + { + $orderReturnState = new OrderReturnState($orderReturn->state); + $vars = array( + '{lastname}' => $customer->lastname, + '{firstname}' => $customer->firstname, + '{id_order_return}' => $id_order_return, + '{state_order_return}' => (isset($orderReturnState->name[(int)$order->id_lang]) ? $orderReturnState->name[(int)$order->id_lang] : $orderReturnState->name[(int)Configuration::get('PS_LANG_DEFAULT')])); + 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); + } + } else { + HelperFormBootstrap::displayErrors(Tools::displayError('No order return ID.')); + } + } + } + + public function display() + { + global $cookie, $currentIndex; + + if($return_number = Tools::getValue('return_number')) { + if($return = Db::getInstance()->getRow(' + SELECT * + FROM `'._DB_PREFIX_.'order_return_link` + WHERE `return_number` = "'.pSQL($return_number).'" + ')) { + header('Location: /adm/index.php?tab=AdminAntReturnprocess&id_order_return='.(int) $return['id_order_return'].'&updateorder_return&token='.Tools::getValue('token')); + exit; + } + } + + if (isset($_GET['updateorder_return'])) + { + + $this->displayForm(); + echo '

'.$this->l('Back to list').'
'; + } + else + { + $this->displaylist(); + } + } + + public function displayForm() + { + global $cookie, $currentIndex; + + if (($id_order_return = (int)(Tools::getValue('id_order_return'))) AND Validate::isUnsignedId($id_order_return)) { + $orderReturn = new OrderReturn($id_order_return); + if (!Validate::isLoadedObject($orderReturn)) { + die(Tools::displayError()); + } + } + $order = new Order($orderReturn->id_order); + $cart = new Cart((int)$order->id_cart); + $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); + $shipping_numbers = Db::getInstance()->ExecuteS(' + SELECT DISTINCT lpws.`shipping_number`, lpws.`date_add` + FROM `'._DB_PREFIX_.'lapostews` lpws + LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = lpws.`id_order_detail`) + WHERE `id_order` ='. (int)$order->id + ); + $shipping_numbers2 = Db::getInstance()->ExecuteS(' + SELECT DISTINCT ppp.`shipping_number`, ppp.`date_add` + FROM `'._DB_PREFIX_.'philea_parcel` ppp + LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = ppp.`id_order_detail`) + WHERE od.`id_order` ='. (int)$order->id + ); + $query_thread = Db::getInstance()->getValue(' + SELECT `id_customer_thread` + FROM `'._DB_PREFIX_.'customer_thread` + WHERE id_customer ='.(int)$order->id_customer.' AND id_order = '.(int)$order->id.' + '); + if($query_thread) { + $thread = new CustomerThread((int)$query_thread); + } + + $returnProducts = OrderReturn::getOrdersReturnProducts($orderReturn->id, $order); + $orderReturnState = new OrderReturnState($orderReturn->state); + + $colorStates = array( + 1 => "anticon anticon-hour-glass text-orange", + 2 => "anticon anticon-hour-glass text-orange", + 3 => "anticon anticon-box-add text-orange", + 4 => "anticon anticon-cross text-rose", + 5 => "anticon anticon-checkmark text-green-light", + ); + + $helper = new HelperFormBootstrap(); + $helper->_select2 = true; + $helper->_inputMask = true; + $html = $helper->renderStyle(); + $html .= ' +
+
+
+
+

Retour #'.$id_order_return.'

+

'.$orderReturnState->name[(int)$cookie->id_lang].'

+
+
+
+
+
+ + + + + + + + + '; + $productReturned = array(); + foreach ($returnProducts AS $k => $product) { + $productReturned[] = $product['product_id']; + $img_path = ''; + $img = Db::getInstance()->getRow(' + SELECT id_image + FROM `'._DB_PREFIX_.'image` i + WHERE i.`id_product` = '.(int)$product['product_id'].' + AND i.`cover` = 1' + ); + if (isset($img['id_image']) && !empty($img['id_image'])) { + $image_obj = new Image((int)$img['id_image']); + $img_path = (isset($image_obj)?$image_obj->getExistingImgPath():''); + } + if (!isset($quantityDisplayed[(int)($product['id_order_detail'])]) OR (int)($product['product_quantity']) > (int)($quantityDisplayed[(int)($product['id_order_detail'])])) { + $html .=' + + + + + '; + } + } + $html .=' +
'.$this->l('Produit').''.$this->l('Qté').''.$this->l('Action').'
+ + '.mb_strimwidth($product['product_name'], 0, 55, "...").' +
+
+
'.$product['product_quantity'].'
+
+
+
+ '.($orderReturn->id ? '' : '').' + + + +
+ + +
+
+ +
+
+
+
+
+
+
+
'; + + $html .= ' +
+
+
+
+

Résumé Commande (#'.(int)$order->id.') - '.$customer->firstname.' '.$customer->lastname.' ('.$this->l('#').$customer->id.')

+
+
+
+
+
+
+
+
Détails paiement
+
'.Tools::substr($order->payment, 0, 32).' '.($order->module ? '('.$order->module.')' : '').'
+
+ + + '.($order->total_discounts > 0 ? '' : '').' + '.($order->total_wrapping > 0 ? '' : '').' + + +
'.$this->l('Products').''.Tools::displayPrice($order->getTotalProductsWithTaxes(), $currency, false).'
'.$this->l('Discounts').'-'.Tools::displayPrice($order->total_discounts, $currency, false).'
'.$this->l('Wrapping').''.Tools::displayPrice($order->total_wrapping, $currency, false).'
'.$this->l('Shipping').''.Tools::displayPrice($order->total_shipping, $currency, false).'
'.$this->l('Total').''.Tools::displayPrice($order->total_paid, $currency, false).($order->total_paid != $order->total_paid_real ? '
('.$this->l('Paid:').' '.Tools::displayPrice($order->total_paid_real, $currency, false, false).')' : '').'
+
+
+
+
Transporteur
+

'.$data['carrier_name'].'

+
    '; + if(count($shipping_numbers) > 0){ + foreach ($shipping_numbers as $key => $number) { + $date = new DateTime($number['date_add']); + $html .= '
  • '. $number['shipping_number'] .' ajouté le '. $date->format('d/m/Y') .'
  • '; + } + } + if(count($shipping_numbers2) > 0){ + foreach ($shipping_numbers2 as $key => $number) { + $date = new DateTime($number['date_add']); + $html .= '
  • '. $number['shipping_number'] .' ajouté le '. $date->format('d/m/Y') .'
  • '; + } + } + $html .= '
+
+
+
+
+
Adresse Facturation
+

'.$data['order_invoice_address'].'

+
+
+
Adresse Livraison
+

'.$data['order_address'].'

+
+
+
+
+
+
+ + + + + + + '.($order->hasBeenPaid() ?'':'').' + '.($order->hasBeenDelivered() ?'':'').' + + + + + '; + foreach ($order->getProducts() as $key => $product) { + if ($order->getTaxCalculationMethod() == PS_TAX_EXC) { + $product_price = $product['product_price'] + $product['ecotax']; + } else { + $product_price = $product['product_price_wt']; + } + + if ($product['product_quantity'] > $product['customizationQuantityTotal']) + { + $quantity = $product['product_quantity'] - $product['customizationQuantityTotal']; + + $html .=' + + + + + '.($order->hasBeenPaid() ? '' : '').' + '.($order->hasBeenDelivered() ? '' : '').' + + + '; + } + } + $html .= ' +
'.$this->l('Produit').''.$this->l('Prix U').''.$this->l('Qté').''.$this->l('Remb').''.$this->l('Retour').''.$this->l('Stock').''.$this->l('Total').'
+ + '.$product['product_name'].'
+ '.($product['product_reference'] ? ''.$this->l('Ref:').' '.$product['product_reference'].'
' : '') + .($product['product_supplier_reference'] ? ''.$this->l('Ref Supplier:').' '.$product['product_supplier_reference'].'' : '') + .'
+
'.Tools::displayPrice($product_price,$currency).''.$quantity.''.(int)($product['product_quantity_refunded']).''.(int)($product['product_quantity_return']).''.(int)$stock['quantity'].''.Tools::displayPrice(Tools::ps_round($product_price, 2) * ((int)($product['product_quantity']) - $product['customizationQuantityTotal']), $currency, false).'
+
+
+
+
+
+
+
+
+
+
+
+

SAV '.(isset($thread)?' Conversation #'.(int)($thread->id).'':'').'

+
+
+
+
+
'; + if(isset($thread)){ + $products = Db::getInstance()->ExecuteS(' + SELECT spc.*, pl.`name` + FROM `'._DB_PREFIX_.'support_product_customerthread` spc + LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = spc.`id_product`) + WHERE spc.`id_customer_thread` = '.(int)$thread->id.' + AND pl.`id_lang` = 2' + ); + if($products && !empty($products)) { + $html .='
Produit(s) Concerné(s) :
'; + foreach ($products as $product) { + $img_path = ''; + $img = Db::getInstance()->getRow(' + SELECT id_image + FROM `'._DB_PREFIX_.'image` i + WHERE i.`id_product` = '.(int)$product['id_product'].' + AND i.`cover` = 1' + ); + if (isset($img['id_image']) && !empty($img['id_image'])) { + $image_obj = new Image((int)$img['id_image']); + $img_path = (isset($image_obj)?$image_obj->getExistingImgPath():''); + } + $html .=' + + '.mb_strimwidth($product['name'], 0, 55, "...").' +
+
'; + } + } + $html .=''; + } else { + $html .='

Pas de conversation en rapport avec cette commande !

'; + } + $html .='
+
+
+
+ +
+
+
'; + $html .= $helper->renderScript(); + + echo $html; + + } + + public function displaylist() + { + global $cookie, $currentIndex; + + $order_returns = Db::getInstance()->ExecuteS(' + SELECT a.*, orsl.`name` + FROM '._DB_PREFIX_.'order_return a + LEFT JOIN '._DB_PREFIX_.'order_return_state_lang orsl ON (orsl.`id_order_return_state` = a.`state` AND orsl.`id_lang` = '.(int)($cookie->id_lang).')' + ); + + $colorStates = array( + 1 => "anticon anticon-hour-glass text-orange", + 2 => "anticon anticon-hour-glass text-orange", + 3 => "anticon anticon-box-add text-orange", + 4 => "anticon anticon-cross text-rose", + 5 => "anticon anticon-checkmark text-green-light", + ); + + $helper = new HelperFormBootstrap(); + $helper->_select2 = true; + $helper->_inputMask = true; + $html = $helper->renderStyle(); + $html .= ' +
+
+
+
+

Rechercher par code barre

+
+
+
+
+ + + + +
+
+
+
+
+
+
+

Rechercher par commande

+
+
+
+
+
+ + + + +
+
+
+
+
+
+
+
+
+
+

Liste des Retours

+
+
+
+
+ + + + + + + + + + + + '; + foreach ($order_returns as $key => $return) { + $html .= ' + + + + + + + + + '; + } + $html .= ' +
'.$this->l('#').''.$this->l('# Order').''.$this->l('# Customer').''.$this->l('Status').''.$this->l('Date').''.$this->l('Action').'
'.$return['id_order_return'].'n° '.$return['id_order'].''.$return['id_customer'].' '.$return['name'].''.date('d/m/Y H:i',strtotime($return['date_add'])).' +
+ + +
+
+
+
+
+
+
+
'; + + $helper->_js .= ' + '; + $html .= $helper->renderScript(); + + echo $html; + } + + public function getOrderDetail($cart, $id_lang, $order){ + if(Db::getInstance()->getValue(' + SELECT `id_carrier` + FROM `'._DB_PREFIX_.'carrier` + WHERE `id_carrier` = '.(int) $cart->id_carrier.' + AND `name` LIKE "%colissimo%" + ')) { + $socol = Db::getInstance()->getRow(' + SELECT * + FROM `'._DB_PREFIX_.'socolissimo_delivery_info` + WHERE `id_cart` = '.(int) $cart->id.' + AND `cecountry` IN ("FR","BE","ES") + AND (`pradress1`!= "" OR `pradress2`!= "" OR `pradress3`!= "" OR `pradress4`!= "") + '); + if((int) $cart->id_carrier == (int)Configuration::get('ANT_CARRIER_DOM')) { + $DOM_front = true; + } else { + $DOM_front = false; + } + if($socol && !$DOM_front) { + $order_address = nl2br(preg_replace("/(\r\n){2,}/", "\r\n", implode("\r\n", array( + $socol['cefirstname'].' '.$socol['cename'], + $socol['cecompanyname'], + $socol['prname'], + $socol['prcompladress'], + $socol['pradress1'], + $socol['pradress2'], + $socol['pradress3'], + $socol['pradress4'], + $socol['przipcode'].' '.$socol['prtown'], + $socol['cecountry'], + $socol['cephonenumber'], + !empty($socol['cedoorcode1'])? 'Code porte 1 : '.$socol['cedoorcode1']: '', + !empty($socol['cedoorcode2'])? 'Code porte 2 : '.$socol['cedoorcode2']: '', + $socol['cedeliveryinformation'], + )))); + } else { + $order_address = nl2br(AddressFormat::generateAddress(new Address((int) $order->id_address_delivery))); + } + } elseif(Db::getInstance()->getValue(' + SELECT COUNT(*) + FROM `'._DB_PREFIX_.'mr_method` + WHERE `id_carrier` = '.(int) $cart->id_carrier.' + ')) { + $mr = Db::getInstance()->getRow(' + SELECT mr_s.* + FROM `' . _DB_PREFIX_ . 'mr_selected` mr_s + WHERE `id_cart` = ' . (int) $cart->id . ' + '); + if($mr) { + $order_address = nl2br(preg_replace("/(\r\n){2,}/", "\r\n", implode("\r\n", array( + $mr['MR_Selected_LgAdr1'], + $mr['MR_Selected_LgAdr2'], + $mr['MR_Selected_LgAdr3'] . ' ' . $mr['MR_Selected_LgAdr4'], + $mr['MR_Selected_CP'] . ' ' . $mr['MR_Selected_Ville'], + 'FRANCE', + )))); + } else { + $order_address = nl2br(AddressFormat::generateAddress(new Address((int) $order->id_address_delivery))); + } + } else { + $order_address = nl2br(AddressFormat::generateAddress(new Address((int) $order->id_address_delivery))); + } + + $carrier_name = Db::getInstance()->getValue(' + SELECT `name` + FROM `'._DB_PREFIX_.'carrier` + WHERE `id_carrier` = '.(int) $cart->id_carrier.' + '); + + return array( + 'order_invoice_address' => nl2br(AddressFormat::generateAddress(new Address((int) $order->id_address_invoice))), + 'order_address' => $order_address, + 'carrier_name' => $carrier_name, + ); + } +} diff --git a/modules/ant_returnprocess/ant_returnprocess.php b/modules/ant_returnprocess/ant_returnprocess.php new file mode 100644 index 00000000..3e48f211 --- /dev/null +++ b/modules/ant_returnprocess/ant_returnprocess.php @@ -0,0 +1,40 @@ +name = 'ant_returnprocess'; + $this->tab = 'administration'; + $this->author = 'Antadis'; + $this->version = '1.0'; + $this->need_instance = 0; + + parent::__construct(); + + $this->displayName = $this->l('Administration de retours'); + $this->description = $this->l('Une administration des retours plus poussée'); + } + + public function install() + { + + if(!(parent::install())) { + return false; + } + return true; + } + + public function uninstall() { + + if(parent::uninstall() == false) { + return false; + } + + return true; + } + +}