* @copyright PrestaShop * @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0 * @version 1.3 * */ include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php'); class AdminOrders extends AdminTab { public function __construct() { global $cookie, $currentIndex; $this->table = 'order'; $this->className = 'Order'; $this->view = true; $this->colorOnBackground = true; $this->_select = ' a.id_order AS id_pdf, CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`, osl.`name` AS `osname`, os.`color`, IF((SELECT COUNT(so.id_order) FROM `'._DB_PREFIX_.'orders` so WHERE so.id_customer = a.id_customer AND so.valid = 1) > 1, 0, 1) as new, (SELECT COUNT(od.`id_order`) FROM `'._DB_PREFIX_.'order_detail` od WHERE od.`id_order` = a.`id_order` GROUP BY `id_order`) AS product_number'; $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`) LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = a.`id_order`) LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = oh.`id_order_state`) LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.intval($cookie->id_lang).')'; $this->_where = 'AND oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = a.`id_order` GROUP BY moh.`id_order`)'; $statesArray = array(); $states = OrderState::getOrderStates(intval($cookie->id_lang)); foreach ($states AS $state) $statesArray[$state['id_order_state']] = $state['name']; $this->fieldsDisplay = array( 'id_order' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'new' => array('title' => $this->l('New'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'filter_key' => 'new', 'tmpTableFilter' => true, 'icon' => array(0 => 'blank.gif', 1 => 'news-new.gif'), 'orderby' => false), 'customer' => array('title' => $this->l('Customer'), 'widthColumn' => 160, 'width' => 140, 'filter_key' => 'customer', 'tmpTableFilter' => true), 'total_paid' => array('title' => $this->l('Total'), 'width' => 70, 'align' => 'right', 'prefix' => '', 'suffix' => '', 'price' => true, 'currency' => true), 'payment' => array('title' => $this->l('Payment'), 'width' => 100), 'osname' => array('title' => $this->l('Status'), 'widthColumn' => 250, 'type' => 'select', 'select' => $statesArray, 'filter_key' => 'os!id_order_state', 'filter_type' => 'int', 'width' => 200), 'date_add' => array('title' => $this->l('Date'), 'width' => 90, 'align' => 'right', 'type' => 'datetime', 'filter_key' => 'a!date_add'), 'id_pdf' => array('title' => $this->l('PDF'), 'callback' => 'printPDFIcons', 'orderby' => false, 'search' => false)); parent::__construct(); } /** * @global object $cookie Employee cookie necessary to keep trace of his/her actions */ public function postProcess() { global $currentIndex, $cookie; /* Update shipping number */ if (Tools::isSubmit('submitShippingNumber') AND ($id_order = intval(Tools::getValue('id_order'))) AND Validate::isLoadedObject($order = new Order($id_order))) { if ($this->tabAccess['edit'] === '1') { if (!$order->hasBeenShipped()) die(Tools::displayError('The shipping number can only be set once the order has been shipped!')); $_GET['view'.$this->table] = true; $shipping_number = pSQL(Tools::getValue('shipping_number')); $order->shipping_number = $shipping_number; $order->update(); if ($shipping_number) { global $_LANGMAIL; $customer = new Customer(intval($order->id_customer)); $carrier = new Carrier(intval($order->id_carrier)); if (!Validate::isLoadedObject($customer) OR !Validate::isLoadedObject($carrier)) die(Tools::displayError()); $templateVars = array( '{followup}' => str_replace('@', $order->shipping_number, $carrier->url), '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{id_order}' => intval($order->id) ); $subject = 'Package in transit'; Mail::Send(intval($order->id_lang), 'in_transit', ((is_array($_LANGMAIL) AND key_exists($subject, $_LANGMAIL)) ? $_LANGMAIL[$subject] : $subject), $templateVars, $customer->email, $customer->firstname.' '.$customer->lastname); } } else $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.'); } /* Change order state, add a new entry in order history and send an e-mail to the customer if needed */ elseif (Tools::isSubmit('submitState') AND ($id_order = intval(Tools::getValue('id_order'))) AND Validate::isLoadedObject($order = new Order($id_order))) { if ($this->tabAccess['edit'] === '1') { $_GET['view'.$this->table] = true; if (!$newOrderStatusId = intval(Tools::getValue('id_order_state'))) $this->_errors[] = Tools::displayError('Invalid new order status!'); else { $history = new OrderHistory(); $history->id_order = $id_order; $history->changeIdOrderState(intval($newOrderStatusId), intval($id_order)); $history->id_employee = intval($cookie->id_employee); $carrier = new Carrier(intval($order->id_carrier), intval($order->id_lang)); $templateVars = array('{followup}' => ($history->id_order_state == _PS_OS_SHIPPING_ AND $order->shipping_number) ? str_replace('@', $order->shipping_number, $carrier->url) : ''); if ($history->addWithemail(true, $templateVars)) Tools::redirectAdmin($currentIndex.'&id_order='.$id_order.'&vieworder'.'&token='.$this->token); $this->_errors[] = Tools::displayError('an error occurred while changing status or was unable to send e-mail to the customer'); } } else $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.'); } /* Add a new message for the current order and send an e-mail to the customer if needed */ elseif (isset($_POST['submitMessage'])) { $_GET['view'.$this->table] = true; if ($this->tabAccess['edit'] === '1') { if (!($id_order = intval(Tools::getValue('id_order'))) OR !($id_customer = intval(Tools::getValue('id_customer')))) $this->_errors[] = Tools::displayError('an error occurred before sending message'); elseif (!Tools::getValue('message')) $this->_errors[] = Tools::displayError('message cannot be blank'); 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') $this->_errors[] = Tools::displayError('field').' '.$field.' '.Tools::displayError('is required'); foreach ($rules['size'] AS $field => $maxLength) if (Tools::getValue($field) AND Tools::strlen(Tools::getValue($field)) > $maxLength) $this->_errors[] = Tools::displayError('field').' '.$field.' '.Tools::displayError('is too long').' ('.$maxLength.' '.Tools::displayError('chars max').')'; foreach ($rules['validate'] AS $field => $function) if (Tools::getValue($field)) if (!Validate::$function(htmlentities(Tools::getValue($field), ENT_COMPAT, 'UTF-8'))) $this->_errors[] = Tools::displayError('field').' '.$field.' '.Tools::displayError('is invalid'); if (!sizeof($this->_errors)) { $message = new Message(); $message->id_employee = intval($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()) $this->_errors[] = Tools::displayError('an error occurred while sending message'); elseif ($message->private) Tools::redirectAdmin($currentIndex.'&id_order='.$id_order.'&vieworder&conf=11'.'&token='.$this->token); elseif (Validate::isLoadedObject($customer = new Customer($id_customer))) { $order = new Order(intval($message->id_order)); if (Validate::isLoadedObject($order)) { $title = html_entity_decode($this->l('New message regarding your order').' '.$message->id_order, ENT_NOQUOTES, 'UTF-8'); $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(intval($order->id_lang), 'order_merchant_comment', $title, $varsTpl, $customer->email, $customer->firstname.' '.$customer->lastname)) Tools::redirectAdmin($currentIndex.'&id_order='.$id_order.'&vieworder&conf=11'.'&token='.$this->token); } } $this->_errors[] = Tools::displayError('an error occurred while sending e-mail to the customer'); } } } else $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } /* Cancel product from order */ elseif (Tools::isSubmit('cancelProduct') AND Validate::isLoadedObject($order = new Order(intval(Tools::getValue('id_order'))))) { if ($this->tabAccess['delete'] === '1') { $productList = Tools::getValue('id_order_detail'); $customizationList = Tools::getValue('id_customization'); $qtyList = Tools::getValue('cancelQuantity'); $customizationQtyList = Tools::getValue('cancelCustomizationQuantity'); if ($productList OR $customizationList) { if ($productList) foreach ($productList AS $key => $id_order_detail) { $qtyCancelProduct = abs($qtyList[$key]); if (!$qtyCancelProduct) $this->_errors[] = Tools::displayError('No quantity selected for product.'); } if ($customizationList) foreach ($customizationList AS $id_customization => $id_order_detail) { $qtyCancelProduct = abs($customizationQtyList[$id_customization]); if (!$qtyCancelProduct) $this->_errors[] = Tools::displayError('No quantity selected for product.'); } if (!sizeof($this->_errors) AND $productList) foreach ($productList AS $key => $id_order_detail) { $qtyCancelProduct = abs($qtyList[$key]); $orderDetail = new OrderDetail(intval($id_order_detail)); // Reinject product if (!$order->hasBeenDelivered() OR ($order->hasBeenDelivered() AND Tools::isSubmit('reinjectQuantities'))) { $reinjectableQuantity = intval($orderDetail->product_quantity_in_stock) - intval($orderDetail->product_quantity_reinjected); $quantityToReinject = $qtyCancelProduct > $reinjectableQuantity ? $reinjectableQuantity : $qtyCancelProduct; if (!Product::reinjectQuantities($orderDetail, $quantityToReinject)) $this->_errors[] = Tools::displayError('Cannot re-stock product').' '.$orderDetail->product_name.''; else { $updProductAttributeID = !empty($orderDetail->product_attribute_id) ? intval($orderDetail->product_attribute_id) : NULL; $newProductQty = Product::getQuantity(intval($orderDetail->product_id), $updProductAttributeID); if (!empty($orderDetail->product_attribute_id)) $updProduct['quantity_attribute'] = intval($newProductQty); else $updProduct['stock_quantity'] = intval($newProductQty); Hook::updateQuantity($updProduct, $order); } } // Delete product if (!$order->deleteProduct($order, $orderDetail, $qtyCancelProduct)) $this->_errors[] = Tools::displayError('an error occurred during deletion for the product').' '.$orderDetail->product_name.''; Module::hookExec('cancelProduct', array('order' => $order, 'id_order_detail' => $id_order_detail)); } if (!sizeof($this->_errors) AND $customizationList) foreach ($customizationList AS $id_customization => $id_order_detail) { $orderDetail = new OrderDetail(intval($id_order_detail)); $qtyCancelProduct = abs($customizationQtyList[$id_customization]); if (!$order->deleteCustomization($id_customization, $qtyCancelProduct, $orderDetail)) $this->_errors[] = Tools::displayError('an error occurred during deletion for the product customization').' '.$id_customization; } // E-mail params if ((isset($_POST['generateCreditSlip']) OR isset($_POST['generateDiscount'])) AND !sizeof($this->_errors)) { $customer = new Customer(intval($order->id_customer)); $params['{lastname}'] = $customer->lastname; $params['{firstname}'] = $customer->firstname; $params['{id_order}'] = $order->id; } // Generate credit slip if (isset($_POST['generateCreditSlip']) AND !sizeof($this->_errors)) { if (!OrderSlip::createOrderSlip($order, $productList, $qtyList, isset($_POST['shippingBack']))) $this->_errors[] = Tools::displayError('Cannot generate credit slip'); else { Module::hookExec('orderSlip', array('order' => $order, 'productList' => $productList, 'qtyList' => $qtyList)); @Mail::Send(intval($order->id_lang), 'credit_slip', html_entity_decode($this->l('New credit slip regarding your order #').$order->id, ENT_NOQUOTES, 'UTF-8'), $params, $customer->email, $customer->firstname.' '.$customer->lastname); } } // Generate voucher if (isset($_POST['generateDiscount']) AND !sizeof($this->_errors)) { if (!$voucher = Discount::createOrderDiscount($order, $productList, $qtyList, $this->l('Credit Slip concerning the order #'), isset($_POST['shippingBack']))) $this->_errors[] = Tools::displayError('Cannot generate voucher'); else { $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $params['{voucher_amount}'] = Tools::displayPrice($voucher->value, $currency, false, false); $params['{voucher_num}'] = $voucher->name; @Mail::Send(intval($order->id_lang), 'voucher', html_entity_decode($this->l('New voucher regarding your order #').$order->id, ENT_NOQUOTES, 'UTF-8'), $params, $customer->email, $customer->firstname.' '.$customer->lastname); } } } else $this->_errors[] = Tools::displayError('No product or quantity selected.'); // Redirect if no errors if (!sizeof($this->_errors)) Tools::redirectLink($currentIndex.'&id_order='.$order->id.'&vieworder&conf=1&token='.$this->token); } else $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } elseif (isset($_GET['messageReaded'])) { Message::markAsReaded(intval($_GET['messageReaded']), intval($cookie->id_employee)); } parent::postProcess(); } private function displayCustomizedDatas(&$customizedDatas, &$product, &$currency, &$image, $tokenCatalog, $id_order_detail) { $order = $this->loadObject(); if (is_array($customizedDatas) AND isset($customizedDatas[intval($product['product_id'])][intval($product['product_attribute_id'])])) { echo ' '.(isset($image['id_image']) ? cacheImage(_PS_IMG_DIR_.'p/'.intval($product['product_id']).'-'.intval($image['id_image']).'.jpg', 'product_mini_'.intval($product['product_id']).(isset($product['product_attribute_id']) ? '_'.intval($product['product_attribute_id']) : '').'.jpg', 45, 'jpg') : '--').' '.$product['product_name'].' - '.$this->l('customized').'
'.($product['product_reference'] ? $this->l('Ref:').' '.$product['product_reference'] : '') .(($product['product_reference'] AND $product['product_supplier_reference']) ? ' / '.$product['product_supplier_reference'] : '') .'
'.Tools::displayPrice($product['product_price_wt'], $currency, false, false).' '.$product['customizationQuantityTotal'].' '.($order->hasBeenPaid() ? ''.$product['customizationQuantityRefunded'].'' : '').' '.($order->hasBeenDelivered() ? ''.$product['customizationQuantityReturned'].'' : '').' - '.Tools::displayPrice($product['total_customization_wt'], $currency, false, false).' -- '; foreach ($customizedDatas[intval($product['product_id'])][intval($product['product_attribute_id'])] AS $customizationId => $customization) { echo ' '; foreach ($customization['datas'] AS $type => $datas) if ($type == _CUSTOMIZE_FILE_) { $i = 0; echo ''; } elseif ($type == _CUSTOMIZE_TEXTFIELD_) { $i = 0; echo ''; } echo ' - '.$customization['quantity'].' '.($order->hasBeenPaid() ? ''.$customization['quantity_refunded'].'' : '').' '.($order->hasBeenDelivered() ? ''.$customization['quantity_returned'].'' : '').' - '.Tools::displayPrice(Tools::ps_round($product['product_price'], 2) * (1 + ($product['tax_rate'] * 0.01)) * ($customization['quantity']), $currency, false, false).' '; if ((!$order->hasBeenDelivered() OR Configuration::get('PS_ORDER_RETURN')) AND intval(($customization['quantity_returned']) < intval($customization['quantity']))) echo ' = intval($customization['quantity'])) ? 'disabled="disabled" ' : '').'/>'; else echo '--'; echo ' '; if (intval($customization['quantity_returned'] + $customization['quantity_refunded']) >= intval($customization['quantity'])) echo ''; elseif (!$order->hasBeenDelivered() OR Configuration::get('PS_ORDER_RETURN')) echo ' '; echo ($order->hasBeenDelivered() ? intval($customization['quantity_returned']).'/'.(intval($customization['quantity']) - intval($customization['quantity_refunded'])) : ($order->hasBeenPaid() ? intval($customization['quantity_refunded']).'/'.intval($customization['quantity']) : '')).' '; echo ' '; } } } private function getCancelledProductNumber(&$order, &$product) { $productQuantity = array_key_exists('customizationQuantityTotal', $product) ? $product['product_quantity'] - $product['customizationQuantityTotal'] : $product['product_quantity']; $productRefunded = $product['product_quantity_refunded']; $productReturned = $product['product_quantity_return']; $content = '0/'.$productQuantity; if ($order->hasBeenDelivered()) $content = $productReturned.'/'.($productQuantity - $productRefunded); elseif ($order->hasBeenPaid()) $content = $productRefunded.'/'.$productQuantity; return $content; } public function viewDetails() { global $currentIndex, $cookie; $irow = 0; $order = $this->loadObject(); $customer = new Customer($order->id_customer); $customerStats = $customer->getStats(); $addressInvoice = new Address($order->id_address_invoice, intval($cookie->id_lang)); if (Validate::isLoadedObject($addressInvoice) AND $addressInvoice->id_state) $invoiceState = new State(intval($addressInvoice->id_state)); $addressDelivery = new Address($order->id_address_delivery, intval($cookie->id_lang)); if (Validate::isLoadedObject($addressDelivery) AND $addressDelivery->id_state) $deliveryState = new State(intval($addressDelivery->id_state)); $carrier = new Carrier($order->id_carrier); $history = $order->getHistory($cookie->id_lang); $products = $order->getProducts(); $customizedDatas = Product::getAllCustomizedDatas(intval($order->id_cart)); Product::addCustomizationPrice($products, $customizedDatas); $discounts = $order->getDiscounts(); $messages = Message::getMessagesByOrderId($order->id, true); $states = OrderState::getOrderStates(intval($cookie->id_lang)); $currency = new Currency($order->id_currency); $currentLanguage = new Language(intval($cookie->id_lang)); $currentState = OrderHistory::getLastOrderState($order->id); $sources = ConnectionsSource::getOrderSources($order->id); $cart = Cart::getCartByOrderId($order->id); $link = new Link(); $row = array_shift($history); if ($order->total_paid != $order->total_paid_real) echo '
'.$this->l('Warning:').' '.Tools::displayPrice($order->total_paid_real, $currency, false, false).' '.$this->l('paid instead of').' '.Tools::displayPrice($order->total_paid, $currency, false, false).' !


'; // display bar code if module enabled $hook = Module::hookExec('invoice', array('id_order' => $order->id)); if ($hook !== false) { echo '
'; echo $hook; echo '

'; } // display order header echo '
'; echo '

'.$customer->firstname.' '.$customer->lastname.' '.$this->l('#').sprintf('%06d', $order->id). ((($currentState->invoice OR $order->invoice_number) AND count($products)) ? ' - '.$this->l('View invoice').'' : ''). (($currentState->delivery OR $order->delivery_number) ? ' - '.$this->l('View delivery slip').'' : ''). ' - '.$this->l('Print order').''; echo '

'; /* Display current status */ echo ' '; /* Display previous status */ foreach ($history AS $row) { echo ' '; } echo '
'.Tools::displayDate($row['date_add'], intval($cookie->id_lang), true).' '.stripslashes($row['ostate_name']).' '.((!empty($row['employee_lastname'])) ? '('.stripslashes(Tools::substr($row['employee_firstname'], 0, 1)).'. '.stripslashes($row['employee_lastname']).')' : '').'
'.Tools::displayDate($row['date_add'], intval($cookie->id_lang), true).' '.stripslashes($row['ostate_name']).' '.((!empty($row['employee_lastname'])) ? '('.stripslashes(Tools::substr($row['employee_firstname'], 0, 1)).'. '.stripslashes($row['employee_lastname']).')' : '').'

'; /* Display status form */ if (sizeof($products)) { echo '
'; } /* Display customer information */ echo '
'.$this->l('Customer information').' '.$customer->firstname.' '.$customer->lastname.' ('.$this->l('#').$customer->id.')
('.$customer->email.')

'.$this->l('Account registered:').' '.Tools::displayDate($customer->date_add, intval($cookie->id_lang), true).'
'.$this->l('Valid orders placed:').' '.$customerStats['nb_orders'].'
'.$this->l('Total paid since registration:').' '.Tools::displayPrice(Tools::ps_round(Tools::convertPrice($customerStats['total_orders'], $currency), 2), $currency, false, false).'
'; /* Display sources */ if (sizeof($sources)) { echo '
'.$this->l('Sources').'
'; } // display hook specified to this page : AdminOrder if (($hook = Module::hookExec('adminOrder', array('id_order' => $order->id))) !== false) echo $hook; echo '
'; /* Display invoice information */ if (($currentState->invoice OR $order->invoice_number) AND count($products)) echo '
'.$this->l('Invoice').' '.$this->l('Invoice #').''.Configuration::get('PS_INVOICE_PREFIX', intval($cookie->id_lang)).sprintf('%06d', $order->invoice_number).'
'.$this->l('Created on:').' '.$order->invoice_date.'

'; /* Display shipping infos */ echo '
'.$this->l('Shipping information').' '.$this->l('Total weight:').' '.number_format($order->getTotalWeight(), 3).' '.Configuration::get('PS_WEIGHT_UNIT').'
'.$this->l('Carrier:').' '.($carrier->name == '0' ? Configuration::get('PS_SHOP_NAME') : $carrier->name).'
'.(($currentState->delivery OR $order->delivery_number) ? '
'.$this->l('Delivery slip #').''.Configuration::get('PS_DELIVERY_PREFIX', intval($cookie->id_lang)).sprintf('%06d', $order->delivery_number).'
' : ''); if ($order->shipping_number) echo $this->l('Tracking number:').' '.$order->shipping_number.' ('.$this->l('Track the shipment').')'; /* Carrier module */ if ($carrier->is_module == 1) { $module = Module::getInstanceByName($carrier->name); echo call_user_func(array($module, 'displayInfoByCart'), $order->id_cart); } /* Display shipping number field */ if ($carrier->url && $order->hasBeenShipped()) echo '
'; echo '
'; /* Display summary order */ echo '
'.$this->l('Order details').'
'.$this->l('Cart #').sprintf('%06d', $cart->id).'
'.$order->payment.' '.($order->module ? '('.$order->module.')' : '').'
'.($order->total_discounts > 0 ? '' : '').' '.($order->total_wrapping > 0 ? '' : '').'
'.$this->l('Products').''.Tools::displayPrice($order->getTotalProductsWithTaxes(), $currency, false, false).'
'.$this->l('Discounts').'-'.Tools::displayPrice($order->total_discounts, $currency, false, false).'
'.$this->l('Wrapping').''.Tools::displayPrice($order->total_wrapping, $currency, false, false).'
'.$this->l('Shipping').''.Tools::displayPrice($order->total_shipping, $currency, false, false).'
'.$this->l('Total').''.Tools::displayPrice($order->total_paid, $currency, false, false).($order->total_paid != $order->total_paid_real ? '
('.$this->l('Paid:').' '.Tools::displayPrice($order->total_paid_real, $currency, false, false).')' : '').'
'.$this->l('Recycled package:').' '.($order->recyclable ? '' : '').'
'.$this->l('Gift wrapping:').' '.($order->gift ? '
'.(!empty($order->gift_message) ? '
'.$this->l('Message:').'
'.nl2br2($order->gift_message).'
' : '') : '').'
'; echo '
'; echo '
 
'; /* Display adresses : delivery & invoice */ echo '
 
'.$this->l('Shipping address').''.$this->l('Shipping address').'
'. (!empty($addressDelivery->company) ? $addressDelivery->company.'
' : '') .$addressDelivery->firstname.' '.$addressDelivery->lastname.'
'.$addressDelivery->address1.'
'. (!empty($addressDelivery->address2) ? $addressDelivery->address2.'
' : '') .' '.$addressDelivery->postcode.' '.$addressDelivery->city.'
'.$addressDelivery->country.($addressDelivery->id_state ? ' - '.$deliveryState->name : '').'
'.(!empty($addressDelivery->phone) ? $addressDelivery->phone.'
' : '').' '.(!empty($addressDelivery->phone_mobile) ? $addressDelivery->phone_mobile.'
' : '').' '.(!empty($addressDelivery->other) ? '
'.$addressDelivery->other.'
' : '').'
'.$this->l('Invoice address').''.$this->l('Invoice address').'
'. (!empty($addressInvoice->company) ? $addressInvoice->company.'
' : '') .$addressInvoice->firstname.' '.$addressInvoice->lastname.'
'.$addressInvoice->address1.'
'. (!empty($addressInvoice->address2) ? $addressInvoice->address2.'
' : '') .' '.$addressInvoice->postcode.' '.$addressInvoice->city.'
'.$addressInvoice->country.($addressInvoice->id_state ? ' - '.$invoiceState->name : '').'
'.(!empty($addressInvoice->phone) ? $addressInvoice->phone.'
' : '').' '.(!empty($addressInvoice->phone_mobile) ? $addressInvoice->phone_mobile.'
' : '').' '.(!empty($addressInvoice->other) ? '
'.$addressInvoice->other.'
' : '').'
 
'; // List of products echo '
'.$this->l('Products').''.$this->l('Products').'
'.($order->hasBeenPaid() ? '' : '').' '.($order->hasBeenDelivered() ? '' : '').' '; echo ' '; $tokenCatalog = Tools::getAdminToken('AdminCatalog'.intval(Tab::getIdFromClassName('AdminCatalog')).intval($cookie->id_employee)); foreach ($products as $k => $product) { $image = array(); if (isset($product['product_attribute_id']) AND intval($product['product_attribute_id'])) $image = Db::getInstance()->getRow(' SELECT id_image FROM '._DB_PREFIX_.'product_attribute_image WHERE id_product_attribute = '.intval($product['product_attribute_id'])); if (!isset($image['id_image']) OR !$image['id_image']) $image = Db::getInstance()->getRow(' SELECT id_image FROM '._DB_PREFIX_.'image WHERE id_product = '.intval($product['product_id']).' AND cover = 1'); $stock = Db::getInstance()->getRow(' SELECT '.($product['product_attribute_id'] ? 'pa' : 'p').'.quantity FROM '._DB_PREFIX_.'product p '.($product['product_attribute_id'] ? 'LEFT JOIN '._DB_PREFIX_.'product_attribute pa ON p.id_product = pa.id_product' : '').' WHERE p.id_product = '.intval($product['product_id']).' '.($product['product_attribute_id'] ? 'AND pa.id_product_attribute = '.intval($product['product_attribute_id']) : '')); if (isset($image['id_image'])) { $target = '../img/tmp/product_mini_'.intval($product['product_id']).(isset($product['product_attribute_id']) ? '_'.intval($product['product_attribute_id']) : '').'.jpg'; if (file_exists($target)) $products[$k]['image_size'] = getimagesize($target); } // Customization display $this->displayCustomizedDatas($customizedDatas, $product, $currency, $image, $tokenCatalog, $k); // Normal display if ($product['product_quantity'] > $product['customizationQuantityTotal']) { echo ' '.($order->hasBeenPaid() ? '' : '').' '.($order->hasBeenDelivered() ? '' : '').' '; } } echo '
  '.$this->l('Product').' '.$this->l('UP').' * '.$this->l('Qty').''.$this->l('Refunded').''.$this->l('Returned').''.$this->l('Stock').' '.$this->l('Total').' * '.$this->l('Products').' '.($order->hasBeenDelivered() ? $this->l('Return') : ($order->hasBeenPaid() ? $this->l('Refund') : $this->l('Cancel'))).'
'.(isset($image['id_image']) ? cacheImage(_PS_IMG_DIR_.'p/'.intval($product['product_id']).'-'.intval($image['id_image']).'.jpg', 'product_mini_'.intval($product['product_id']).(isset($product['product_attribute_id']) ? '_'.intval($product['product_attribute_id']) : '').'.jpg', 45, 'jpg') : '--').' '.$product['product_name'].'
'.($product['product_reference'] ? $this->l('Ref:').' '.$product['product_reference'] : '') .(($product['product_reference'] AND $product['product_supplier_reference']) ? ' / '.$product['product_supplier_reference'] : '') .'
'.Tools::displayPrice($order->getTaxCalculationMethod() == PS_TAX_EXC ? $product['product_price'] : $product['product_price_wt'], $currency, false, false).' '.(intval($product['product_quantity']) - $product['customizationQuantityTotal']).''.intval($product['product_quantity_refunded']).''.intval($product['product_quantity_return']).''.intval($stock['quantity']).' '.Tools::displayPrice(($order->getTaxCalculationMethod() == PS_TAX_EXC ? $product['product_price'] : Tools::ps_round($product['product_price'] * (1 + ($product['tax_rate'] * 0.01)), 2)) * (intval($product['product_quantity']) - $product['customizationQuantityTotal']), $currency, false, false).' '; if ((!$order->hasBeenDelivered() OR Configuration::get('PS_ORDER_RETURN')) AND intval($product['product_quantity_return']) < intval($product['product_quantity'])) echo ' = intval($product['product_quantity'])) ? 'disabled="disabled" ' : '').'/>'; else echo '--'; echo ' '; if (intval($product['product_quantity_return'] + $product['product_quantity_refunded']) >= intval($product['product_quantity'])) echo ''; elseif (!$order->hasBeenDelivered() OR Configuration::get('PS_ORDER_RETURN')) echo ' '; echo $this->getCancelledProductNumber($order, $product).'
* '.$this->l('According to the group of this customer, prices are printed:').' '.($order->getTaxCalculationMethod() == PS_TAX_EXC ? $this->l('tax excluded.') : $this->l('tax included.')).(!Configuration::get('PS_ORDER_RETURN') ? '

'.$this->l('Merchandise returns are disabled') : '').'
'; if (sizeof($discounts)) { echo '
'; foreach ($discounts as $discount) echo ' '; echo '
'.$this->l('Discounts').''.$this->l('Discount name').' '.$this->l('Value').'
'.$discount['name'].' - '.Tools::displayPrice($discount['value'], $currency, false).'
'; } echo '
'; // Cancel product echo '
 
'; if ($order->hasBeenDelivered()) echo '  
'; if ((!$order->hasBeenDelivered() AND $order->hasBeenPaid()) OR ($order->hasBeenDelivered() AND Configuration::get('PS_ORDER_RETURN'))) echo '  
 
'; if (!$order->hasBeenDelivered() OR ($order->hasBeenDelivered() AND Configuration::get('PS_ORDER_RETURN'))) echo '
'; echo '
'; echo '
 
'; /* Display send a message to customer & returns/credit slip*/ $returns = OrderReturn::getOrdersReturn($order->id_customer, $order->id); $slips = OrderSlip::getOrdersSlip($order->id_customer, $order->id); echo '
'.$this->l('New message').'


'.$this->l('Display to consumer?').' '.$this->l('Yes').' '.$this->l('No').'





'; /* Display list of messages */ if (sizeof($messages)) { echo '
'.$this->l('Messages').''; foreach ($messages as $message) { echo '
'; if ($message['is_new_for_me']) echo ''; echo $this->l('At').' '.Tools::displayDate($message['date_add'], intval($cookie->id_lang), true); echo ' '.$this->l('from').' '.(($message['elastname']) ? ($message['efirstname'].' '.$message['elastname']) : ($message['cfirstname'].' '.$message['clastname'])).''; echo (intval($message['private']) == 1 ? ''.$this->l('Private:').'' : ''); echo '

'.nl2br2($message['message']).'

'; echo '
'; echo '
'; } echo '

'.$this->l('When you read a message, please click on the green check.').'

'; echo '
'; } echo '
'; /* Display return product */ echo '
'.$this->l('Merchandise returns').''.$this->l('Merchandise returns').''; if (!sizeof($returns)) echo $this->l('No merchandise return for this order.'); else foreach ($returns as $return) { $state = new OrderReturnState($return['state']); echo '('.Tools::displayDate($return['date_upd'], $cookie->id_lang).') : '.$this->l('#').sprintf('%06d', $return['id_order_return']).' - '.$state->name[$cookie->id_lang].'
'; } echo '
'; /* Display credit slip */ echo '
'.$this->l('Credit slip').''.$this->l('Credit slip').''; if (!sizeof($slips)) echo $this->l('No slip for this order.'); else foreach ($slips as $slip) echo '('.Tools::displayDate($slip['date_upd'], $cookie->id_lang).') : '.$this->l('#').sprintf('%06d', $slip['id_order_slip']).'
'; echo '
'; echo '
 
'; echo '

'.$this->l('Back to list').'
'; } public function display() { global $cookie; if (isset($_GET['view'.$this->table])) $this->viewDetails(); else { $this->getList(intval($cookie->id_lang), !Tools::getValue($this->table.'Orderby') ? 'date_add' : NULL, !Tools::getValue($this->table.'Orderway') ? 'DESC' : NULL); $currency = new Currency(intval(Configuration::get('PS_CURRENCY_DEFAULT'))); $this->displayList(); echo '

'.$this->l('Total:').' '.Tools::displayPrice($this->getTotal(), $currency).'

'; } } private function getTotal() { global $cookie; $total = 0; foreach($this->_list AS $item) if ($item['id_currency'] == Configuration::get('PS_CURRENCY_DEFAULT')) $total += floatval($item['total_paid']); else { $currency = new Currency(intval($item['id_currency'])); $total += Tools::ps_round(floatval($item['total_paid']) / floatval($currency->conversion_rate), 2); } return $total; } } ?>