Пример #1
0
 public static function createOrderSlip($order, $productList, $qtyList, $shipping_cost = false)
 {
     // create orderSlip
     $orderSlip = new OrderSlip();
     $orderSlip->id_customer = intval($order->id_customer);
     $orderSlip->id_order = intval($order->id);
     $orderSlip->shipping_cost = intval($shipping_cost);
     if (!$orderSlip->add()) {
         return false;
     }
     // add details
     $orderSlip->addSlipDetail($productList, $qtyList);
     return true;
 }
Пример #2
0
 public function __construct(OrderSlip $order_slip, $smarty)
 {
     $this->order_slip = $order_slip;
     $this->order = new Order((int) $order_slip->id_order);
     $products = OrderSlip::getOrdersSlipProducts($this->order_slip->id, $this->order);
     $customized_datas = Product::getAllCustomizedDatas((int) $this->order->id_cart);
     Product::addCustomizationPrice($products, $customized_datas);
     $this->order->products = $products;
     $this->smarty = $smarty;
     // header informations
     $this->date = Tools::displayDate($this->order->invoice_date, (int) $this->order->id_lang);
     $this->title = HTMLTemplateOrderSlip::l('Slip #') . sprintf('%06d', (int) $this->order_slip->id);
     // footer informations
     $this->shop = new Shop((int) $this->order->id_shop);
 }
 public function __construct(OrderSlip $order_slip, $smarty)
 {
     $this->order_slip = $order_slip;
     $this->order = new Order((int) $order_slip->id_order);
     $products = OrderSlip::getOrdersSlipProducts($this->order_slip->id, $this->order);
     $customized_datas = Product::getAllCustomizedDatas((int) $this->order->id_cart);
     Product::addCustomizationPrice($products, $customized_datas);
     $this->order->products = $products;
     $this->smarty = $smarty;
     // header informations
     $this->date = Tools::displayDate($this->order_slip->date_add);
     $this->title = HTMLTemplateOrderSlip::l('Order slip #') . Configuration::get('PS_CREDIT_SLIP_PREFIX', Context::getContext()->language->id) . sprintf('%06d', (int) $this->order_slip->id);
     // footer informations
     $this->shop = new Shop((int) $this->order->id_shop);
 }
Пример #4
0
 public function getTemplateVarCreditSlips()
 {
     $credit_slips = [];
     $orders_slip = OrderSlip::getOrdersSlip((int) $this->context->cookie->id_customer);
     foreach ($orders_slip as $order_slip) {
         $order = new Order($order_slip['id_order']);
         $credit_slips[$order_slip['id_order_slip']] = $order_slip;
         $credit_slips[$order_slip['id_order_slip']]['credit_slip_number'] = sprintf($this->trans('#%06d', array(), 'Shop.Theme.CustomerAccount'), $order_slip['id_order_slip']);
         $credit_slips[$order_slip['id_order_slip']]['order_number'] = sprintf($this->trans('#%06d', array(), 'Shop.Theme.CustomerAccount'), $order_slip['id_order']);
         $credit_slips[$order_slip['id_order_slip']]['order_reference'] = $order->reference;
         $credit_slips[$order_slip['id_order_slip']]['credit_slip_date'] = Tools::displayDate($order_slip['date_add'], null, false);
         $credit_slips[$order_slip['id_order_slip']]['url'] = $this->context->link->getPageLink('pdf-order-slip', true, null, 'id_order_slip=' . (int) $order_slip['id_order_slip']);
         $credit_slips[$order_slip['id_order_slip']]['order_url_details'] = $this->context->link->getPageLink('order-detail', true, null, 'id_order=' . (int) $order_slip['id_order']);
     }
     return $credit_slips;
 }
Пример #5
0
 /**
  * @param OrderSlip $order_slip
  * @param $smarty
  * @throws PrestaShopException
  */
 public function __construct(OrderSlip $order_slip, $smarty)
 {
     $this->order_slip = $order_slip;
     $this->order = new Order((int) $order_slip->id_order);
     $this->id_cart = $this->order->id_cart;
     $products = OrderSlip::getOrdersSlipProducts($this->order_slip->id, $this->order);
     foreach ($products as $product) {
         $customized_datas = Product::getAllCustomizedDatas($this->id_cart, null, true, null, (int) $product['id_customization']);
         Product::addProductCustomizationPrice($product, $customized_datas);
     }
     $this->order->products = $products;
     $this->smarty = $smarty;
     // header informations
     $this->date = Tools::displayDate($this->order_slip->date_add);
     $prefix = Configuration::get('PS_CREDIT_SLIP_PREFIX', Context::getContext()->language->id);
     $this->title = sprintf(HTMLTemplateOrderSlip::l('%1$s%2$06d'), $prefix, (int) $this->order_slip->id);
     $this->shop = new Shop((int) $this->order->id_shop);
 }
Пример #6
0
 public function postProcess()
 {
     if (Tools::isSubmit('submitPrint')) {
         if (!Validate::isDate(Tools::getValue('date_from'))) {
             $this->_errors[] = $this->l('Invalid from date');
         }
         if (!Validate::isDate(Tools::getValue('date_to'))) {
             $this->_errors[] = $this->l('Invalid end date');
         }
         if (!sizeof($this->_errors)) {
             $orderSlips = OrderSlip::getSlipsIdByDate(Tools::getValue('date_from'), Tools::getValue('date_to'));
             if (count($orderSlips)) {
                 Tools::redirectAdmin('pdf.php?slips&date_from=' . urlencode(Tools::getValue('date_from')) . '&date_to=' . urlencode(Tools::getValue('date_to')) . '&token=' . $this->token);
             }
             $this->_errors[] = $this->l('No order slips found for this period');
         }
     }
     return parent::postProcess();
 }
Пример #7
0
 public function postProcess()
 {
     if (Tools::getValue('submitAddorder_slip')) {
         if (!Validate::isDate(Tools::getValue('date_from'))) {
             $this->errors[] = $this->l('Invalid "From" date');
         }
         if (!Validate::isDate(Tools::getValue('date_to'))) {
             $this->errors[] = $this->l('Invalid "To" date');
         }
         if (!count($this->errors)) {
             $order_slips = OrderSlip::getSlipsIdByDate(Tools::getValue('date_from'), Tools::getValue('date_to'));
             if (count($order_slips)) {
                 Tools::redirectAdmin($this->context->link->getAdminLink('AdminPdf') . '&submitAction=generateOrderSlipsPDF&date_from=' . urlencode(Tools::getValue('date_from')) . '&date_to=' . urlencode(Tools::getValue('date_to')));
             }
             $this->errors[] = $this->l('No order slips were found for this period.');
         }
     } else {
         return parent::postProcess();
     }
 }
Пример #8
0
    public function addPartialSlipDetail($order_detail_list)
    {
        foreach ($order_detail_list as $id_order_detail => $tab) {
            $order_detail = new OrderDetail($id_order_detail);
            $order_slip_resume = OrderSlip::getProductSlipResume($id_order_detail);
            if ($tab['amount'] + $order_slip_resume['amount_tax_incl'] > $order_detail->total_price_tax_incl) {
                $tab['amount'] = $order_detail->total_price_tax_incl - $order_slip_resume['amount_tax_incl'];
            }
            if ($tab['amount'] == 0) {
                continue;
            }
            if ($tab['quantity'] + $order_slip_resume['product_quantity'] > $order_detail->product_quantity) {
                $tab['quantity'] = $order_detail->product_quantity - $order_slip_resume['product_quantity'];
            }
            $tab['amount_tax_excl'] = $tab['amount_tax_incl'] = $tab['amount'];
            $id_tax = (int) Db::getInstance()->getValue('
				SELECT `id_tax`
				FROM `' . _DB_PREFIX_ . 'order_detail_tax`
				WHERE `id_order_detail` = ' . (int) $id_order_detail);
            if ($id_tax > 0) {
                $rate = (double) Db::getInstance()->getValue('
					SELECT `rate`
					FROM `' . _DB_PREFIX_ . 'tax`
					WHERE `id_tax` = ' . (int) $id_tax);
                if ($rate > 0) {
                    $rate = 1 + $rate / 100;
                    $tab['amount_tax_excl'] = $tab['amount_tax_excl'] / $rate;
                }
            }
            if ($tab['quantity'] > 0 && $tab['quantity'] > $order_detail->product_quantity_refunded) {
                $order_detail->product_quantity_refunded = $tab['quantity'];
                $order_detail->save();
            }
            $insert_order_slip = array('id_order_slip' => (int) $this->id, 'id_order_detail' => (int) $id_order_detail, 'product_quantity' => (int) $tab['quantity'], 'amount_tax_excl' => (double) $tab['amount_tax_excl'], 'amount_tax_incl' => (double) $tab['amount_tax_incl']);
            Db::getInstance()->insert('order_slip_detail', $insert_order_slip);
        }
    }
Пример #9
0
 public function processGenerateOrderSlipsPDF()
 {
     $id_order_slips_list = OrderSlip::getSlipsIdByDate(Tools::getValue('date_from'), Tools::getValue('date_to'));
     if (!count($id_order_slips_list)) {
         die(Tools::displayError('No order slips were found.'));
     }
     $order_slips = array();
     foreach ($id_order_slips_list as $id_order_slips) {
         $order_slips[] = new OrderSlip((int) $id_order_slips);
     }
     $this->generatePDF($order_slips, PDF::TEMPLATE_ORDER_SLIP);
 }
Пример #10
0
 public static function multipleOrderSlips($orderSlips)
 {
     $pdf = new PDF('P', 'mm', 'A4');
     foreach ($orderSlips as $id_order_slip) {
         $orderSlip = new OrderSlip((int) $id_order_slip);
         $order = new Order((int) $orderSlip->id_order);
         $order->products = OrderSlip::getOrdersSlipProducts($orderSlip->id, $order);
         if (Validate::isLoadedObject($orderSlip) and Validate::isLoadedObject($order)) {
             PDF::invoice($order, 'D', true, $pdf, $orderSlip);
         }
     }
     return $pdf->Output('order_slips.pdf', 'D');
 }
Пример #11
0
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     $this->context->smarty->assign('ordersSlip', OrderSlip::getOrdersSlip((int) $this->context->cookie->id_customer));
     $this->setTemplate(_PS_THEME_DIR_ . 'order-slip.tpl');
 }
Пример #12
0
 public function hookPayment($params)
 {
     if ($this->context->cart->getOrderTotal() < Configuration::get('PAYLATER_MIN_AMOUNT')) {
         return;
     }
     $currency_id = $params['cart']->id_currency;
     $currency = new Currency((int) $currency_id);
     if (in_array($currency->iso_code, $this->limited_currencies) == false) {
         return false;
     }
     $customer = new Customer((int) $params['cart']->id_customer);
     //prevent opening payment method if no credentials introduced
     if (Configuration::get('PAYLATER_ENVIRONMENT') == 0) {
         if (trim(Configuration::get('PAYLATER_ACCOUNT_ID_TEST')) == false || trim(Configuration::get('PAYLATER_ACCOUNT_KEY_TEST')) == false) {
             return false;
         }
     } else {
         if (trim(Configuration::get('PAYLATER_ACCOUNT_ID_LIVE')) == false || trim(Configuration::get('PAYLATER_ACCOUNT_KEY_LIVE')) == false) {
             return false;
         }
     }
     $cart_products = $this->context->cart->getProducts();
     $items = array();
     $desciption = array();
     $discount = Configuration::get('PAYLATER_DISCOUNT');
     $discount_boolean = $discount == 'true' ? 1 : 0;
     foreach ($cart_products as $p) {
         $items[] = array('description' => $p['name'] . " (" . $p['cart_quantity'] . ")", 'quantity' => $p['cart_quantity'], 'amount' => number_format($p['total_wt'], 2, '.', ''));
         $desciption[] = $p['name'] . " (" . $p['cart_quantity'] . ")";
     }
     //Shipping address
     $saddress = new Address($this->context->cart->id_address_delivery);
     $sstreet = $saddress->address1 . ' ' . $saddress->address2;
     $scity = $saddress->city;
     $suser_state = new State($saddress->id_state);
     $sprovince = $suser_state->name;
     $szipcode = $saddress->postcode;
     $sphone = $saddress->phone;
     $smobile_phone = $saddress->phone_mobile;
     //shippingAddress
     $address2 = new Address($this->context->cart->id_address_invoice);
     $street = $address2->address1 . ' ' . $address2->address2;
     $city = $address2->city;
     $user_state2 = new State($address2->id_state);
     $province = $user_state2->name;
     $zipcode = $address2->postcode;
     $phone = $address2->phone;
     $mobile_phone = $address2->phone_mobile;
     //dni
     if (property_exists($address2, 'dni') == false) {
         $dni = '';
     } else {
         $dni = $address2->dni;
     }
     //dynamic CallbackFilterIterator
     $callback_url = $this->getPagantisCallbackUrl('validation.php', array());
     if (version_compare(_PS_VERSION_, "1.5", "<")) {
         $shippingCost = $this->context->cart->getOrderShippingCost();
     } else {
         $shippingCost = $this->context->cart->getTotalShippingCost(null, true, null);
     }
     $url_OK = $this->getPagantisLink('confirmation.php', array('status' => 'ok', 'c' => $this->context->cart->id));
     $url_NOK = $this->getPagantisLink('confirmation.php', array('status' => 'ko'));
     if (version_compare(_PS_VERSION_, "1.5", "<")) {
         $cancelled_url = $url_NOK;
     } else {
         $cancelled_url = _PS_BASE_URL_ . '/' . __PS_BASE_URI__ . 'index.php?controller=order';
     }
     if ($shippingCost > 0) {
         $items[] = array('description' => $this->l('Shipping cost'), 'quantity' => 1, 'amount' => number_format($shippingCost, 2, '.', ''));
         $desciption[] = $this->l('Shipping cost');
     }
     if (Configuration::get('PAYLATER_ENVIRONMENT') == 1) {
         //mode live
         $account_id = Configuration::get('PAYLATER_ACCOUNT_ID_LIVE');
     } else {
         //mode test
         $account_id = Configuration::get('PAYLATER_ACCOUNT_ID_TEST');
     }
     //discount
     $discount = Configuration::get('PAYLATER_DISCOUNT');
     //1.4 fix
     if ($discount == '0') {
         $discount = 'false';
     }
     if ($discount == '1') {
         $discount = 'true';
     }
     $discount_boolean = $discount == 'true' ? 1 : 0;
     $iframe = Configuration::get('PAYLATER_IFRAME');
     if ($iframe == 1) {
         $iframe = 'true';
     }
     $endpoint = $this->url;
     $order_id = $this->context->cart->id;
     //description
     $description = implode(',', $desciption);
     $convert_price = Tools::convertPrice($this->context->cart->getOrderTotal(true, 3), $this->context->currency);
     $amount = number_format($convert_price, 2, '.', '');
     $amount = str_replace('.', '', $amount);
     if (Configuration::get('PAYLATER_ENVIRONMENT') == 1) {
         $key_to_use = Configuration::get('PAYLATER_ACCOUNT_KEY_LIVE');
     } else {
         $key_to_use = Configuration::get('PAYLATER_ACCOUNT_KEY_TEST');
     }
     $widget_type = Configuration::get('PAYLATER_TYPE') == 'false' ? '0' : '1';
     $total_paid = 0;
     $num_prev_orders = 0;
     $sign_up_date = '';
     $num_partial_refunds = 0;
     $amount_refunded = 0;
     $num_full_refunds = 0;
     $super_checkout_enabled = false;
     $onepagecheckoutps_enabled = false;
     $onepagecheckout_enabled = false;
     if (version_compare(_PS_VERSION_, "1.5", "<")) {
         if ($this->context->cookie->logged) {
             $orders = Order::getCustomerOrders($this->context->customer->id);
             foreach ($orders as $o) {
                 $total_paid += $o['total_paid'];
                 $num_prev_orders++;
             }
             $sign_up_date = Tools::substr($this->context->customer->date_add, 0, 10);
             $order_slips = OrderSlip::getOrdersSlip((int) $this->context->cookie->id_customer);
             foreach ($order_slips as $o) {
                 $num_full_refunds++;
                 $amount_refunded += $o['amount'];
             }
         }
     } else {
         //query for paid statuses
         $sql = new DbQuery();
         $sql->select('id_order_state');
         $sql->from('order_state', 'c');
         $sql->where('c.paid = 1');
         $db_paid_statuses = Db::getInstance()->executeS($sql);
         $paid_statuses = [];
         foreach ($db_paid_statuses as $p) {
             $paid_statuses[] = $p['id_order_state'];
         }
         if ($this->context->cookie->logged) {
             $orders = Order::getCustomerOrders($this->context->customer->id);
             foreach ($orders as $o) {
                 if (array_key_exists('id_order_state', $o) && in_array($o['id_order_state'], $paid_statuses)) {
                     $total_paid += $o['total_paid'];
                     $num_prev_orders++;
                 }
             }
             $sign_up_date = Tools::substr($this->context->customer->date_add, 0, 10);
             $order_slips = OrderSlip::getOrdersSlip((int) $this->context->cookie->id_customer);
             foreach ($order_slips as $o) {
                 $sql = new DbQuery();
                 $sql->select('total_paid');
                 $sql->from('orders', 'c');
                 $sql->where('c.id_order = ' . $o['id_order']);
                 $db_total_paid = Db::getInstance()->executeS($sql);
                 if ($db_total_paid[0]['total_paid'] <= $o['amount']) {
                     $num_full_refunds++;
                 } else {
                     $num_partial_refunds++;
                 }
                 $amount_refunded += $o['amount'];
             }
         }
         $super_checkout_enabled = Module::isEnabled('supercheckout');
         $onepagecheckoutps_enabled = Module::isEnabled('onepagecheckoutps');
         $onepagecheckout_enabled = Module::isEnabled('onepagecheckout');
     }
     //d($key_to_use.$account_id.$order_id.$amount.$this->context->currency->iso_code.$url_OK.$url_NOK);
     $text = $key_to_use . $account_id . $order_id . $amount . $this->context->currency->iso_code . $url_OK . $url_NOK . $callback_url . $discount . $cancelled_url;
     $signature = hash('sha512', $text);
     $this->smarty->assign(array('endpoint' => $endpoint, 'account_id' => $account_id, 'currency' => $this->context->currency->iso_code, 'ok_url' => $url_OK, 'nok_url' => $url_NOK, 'cancelled_url' => $cancelled_url, 'order_id' => $order_id, 'amount' => $amount, 'description' => $description, 'items' => $items, 'signature' => $signature, 'customer_name' => $this->context->cookie->logged ? $this->context->cookie->customer_firstname . ' ' . $this->context->cookie->customer_lastname : $customer->firstname . " " . $customer->lastname, 'customer_email' => $this->context->cookie->logged ? $this->context->cookie->email : $customer->email, 'locale' => $this->context->language->iso_code, 'cart_products' => $cart_products, 'street' => $street, 'city' => $city, 'province' => $province, 'zipcode' => $zipcode, 'sstreet' => $sstreet, 'scity' => $scity, 'sprovince' => $sprovince, 'szipcode' => $szipcode, 'phone' => $phone, 'mobile_phone' => $mobile_phone, 'dni' => $dni, 'callback_url' => $callback_url, 'discount' => $discount, 'discount_boolean' => $discount_boolean, 'dob' => $this->context->customer->birthday ? $this->context->customer->birthday : $customer->birthday, 'iframe' => $iframe, 'total_paid' => $total_paid, 'num_prev_orders' => $num_prev_orders, 'sign_up_date' => $sign_up_date, 'amount_refunded' => $amount_refunded, 'num_full_refunds' => $num_full_refunds, 'num_partial_refunds' => $num_partial_refunds, 'version4' => version_compare(_PS_VERSION_, "1.5", "<"), 'version3' => version_compare(_PS_VERSION_, "1.4", "<"), 'content' => "javascript:\$('#paylater_form').submit();"));
     if ($super_checkout_enabled) {
         return $this->display(__FILE__, 'views/templates/front/payment_supercheckout.tpl');
     } elseif ($onepagecheckoutps_enabled || $onepagecheckout_enabled) {
         return $this->display(__FILE__, 'views/templates/front/payment.tpl');
     } elseif ($widget_type) {
         return $this->display(__FILE__, 'views/templates/front/payment_widget.tpl');
     } else {
         return $this->display(__FILE__, 'views/templates/front/payment.tpl');
     }
 }
Пример #13
0
<?php

include dirname(__FILE__) . '/config/config.inc.php';
include dirname(__FILE__) . '/init.php';
$cookie = new Cookie('ps');
if (!$cookie->isLogged()) {
    Tools::redirect('authentication.php?back=order-follow.php');
}
if (isset($_GET['id_order_slip']) and Validate::isUnsignedId($_GET['id_order_slip'])) {
    $orderSlip = new OrderSlip(intval($_GET['id_order_slip']));
}
if (!isset($orderSlip) or !Validate::isLoadedObject($orderSlip)) {
    die(Tools::displayError('order return not found'));
} elseif ($orderSlip->id_customer != $cookie->id_customer) {
    die(Tools::displayError('order return not found'));
}
$order = new Order(intval($orderSlip->id_order));
if (!Validate::isLoadedObject($order)) {
    die(Tools::displayError('order not found'));
}
$order->products = OrderSlip::getOrdersSlipProducts(intval($orderSlip->id), $order);
$ref = NULL;
PDF::invoice($order, 'D', false, $ref, $orderSlip);
Пример #14
0
 public function processGenerateOrderSlipsPDF()
 {
     $id_order_slips_list = OrderSlip::getSlipsIdByDate(Tools::getValue('date_from'), Tools::getValue('date_to'));
     if (!count($id_order_slips_list)) {
         die($this->trans('No order slips were found.', array(), 'Admin.OrdersCustomers.Notification'));
     }
     $order_slips = array();
     foreach ($id_order_slips_list as $id_order_slips) {
         $order_slips[] = new OrderSlip((int) $id_order_slips);
     }
     $this->generatePDF($order_slips, PDF::TEMPLATE_ORDER_SLIP);
 }
Пример #15
0
 public function process()
 {
     parent::process();
     self::$smarty->assign('ordersSlip', OrderSlip::getOrdersSlip((int) self::$cookie->id_customer));
 }
Пример #16
0
    public function viewDetails()
    {
        global $currentIndex, $cookie, $link;
        $irow = 0;
        if (!($order = $this->loadObject())) {
            return;
        }
        $customer = new Customer($order->id_customer);
        $customerStats = $customer->getStats();
        $addressInvoice = new Address($order->id_address_invoice, (int) $cookie->id_lang);
        if (Validate::isLoadedObject($addressInvoice) and $addressInvoice->id_state) {
            $invoiceState = new State((int) $addressInvoice->id_state);
        }
        $addressDelivery = new Address($order->id_address_delivery, (int) $cookie->id_lang);
        if (Validate::isLoadedObject($addressDelivery) and $addressDelivery->id_state) {
            $deliveryState = new State((int) $addressDelivery->id_state);
        }
        $carrier = new Carrier($order->id_carrier);
        $history = $order->getHistory($cookie->id_lang);
        $products = $order->getProducts();
        $customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart);
        Product::addCustomizationPrice($products, $customizedDatas);
        $discounts = $order->getDiscounts();
        $messages = Message::getMessagesByOrderId($order->id, true);
        $states = OrderState::getOrderStates((int) $cookie->id_lang);
        $currency = new Currency($order->id_currency);
        $currentLanguage = new Language((int) $cookie->id_lang);
        $currentState = OrderHistory::getLastOrderState($order->id);
        $sources = ConnectionsSource::getOrderSources($order->id);
        $cart = Cart::getCartByOrderId($order->id);
        $row = array_shift($history);
        if ($prevOrder = Db::getInstance()->getValue('SELECT id_order FROM ' . _DB_PREFIX_ . 'orders WHERE id_order < ' . (int) $order->id . ' ORDER BY id_order DESC')) {
            $prevOrder = '<a href="' . $currentIndex . '&token=' . Tools::getValue('token') . '&vieworder&id_order=' . $prevOrder . '"><img style="width:24px;height:24px" src="../img/admin/arrow-left.png" /></a>';
        }
        if ($nextOrder = Db::getInstance()->getValue('SELECT id_order FROM ' . _DB_PREFIX_ . 'orders WHERE id_order > ' . (int) $order->id . ' ORDER BY id_order ASC')) {
            $nextOrder = '<a href="' . $currentIndex . '&token=' . Tools::getValue('token') . '&vieworder&id_order=' . $nextOrder . '"><img style="width:24px;height:24px" src="../img/admin/arrow-right.png" /></a>';
        }
        if ($order->total_paid != $order->total_paid_real) {
            echo '<center><span class="warning" style="font-size: 16px">' . $this->l('Warning:') . ' ' . Tools::displayPrice($order->total_paid_real, $currency, false) . ' ' . $this->l('paid instead of') . ' ' . Tools::displayPrice($order->total_paid, $currency, false) . ' !</span></center><div class="clear"><br /><br /></div>';
        }
        // display bar code if module enabled
        $hook = Module::hookExec('invoice', array('id_order' => $order->id));
        if ($hook !== false) {
            echo '<div style="float: right; margin: -40px 40px 10px 0;">';
            echo $hook;
            echo '</div><br class="clear" />';
        }
        // display order header
        echo '
		<div style="float:left" style="width:440px">';
        echo '<h2>
				' . $prevOrder . '
				' . (Validate::isLoadedObject($customer) ? $customer->firstname . ' ' . $customer->lastname . ' - ' : '') . $this->l('Order #') . sprintf('%06d', $order->id) . '
				' . $nextOrder . '
			</h2>
			<div style="width:429px">
				' . ((($currentState->invoice or $order->invoice_number) and count($products)) ? '<a href="pdf.php?id_order=' . $order->id . '&pdf"><img src="../img/admin/charged_ok.gif" alt="' . $this->l('View invoice') . '" /> ' . $this->l('View invoice') . '</a>' : '<img src="../img/admin/charged_ko.gif" alt="' . $this->l('No invoice') . '" /> ' . $this->l('No invoice')) . ' -
				' . (($currentState->delivery or $order->delivery_number) ? '<a href="pdf.php?id_delivery=' . $order->delivery_number . '"><img src="../img/admin/delivery.gif" alt="' . $this->l('View delivery slip') . '" /> ' . $this->l('View delivery slip') . '</a>' : '<img src="../img/admin/delivery_ko.gif" alt="' . $this->l('No delivery slip') . '" /> ' . $this->l('No delivery slip')) . ' -
				<a href="javascript:window.print()"><img src="../img/admin/printer.gif" alt="' . $this->l('Print order') . '" title="' . $this->l('Print order') . '" /> ' . $this->l('Print page') . '</a>
			</div>
			<div class="clear">&nbsp;</div>';
        /* Display current status */
        echo '
			<table cellspacing="0" cellpadding="0" class="table" style="width: 429px">
				<tr>
					<th>' . Tools::displayDate($row['date_add'], (int) $cookie->id_lang, true) . '</th>
					<th><img src="../img/os/' . $row['id_order_state'] . '.gif" /></th>
					<th>' . stripslashes($row['ostate_name']) . '</th>
					<th>' . (!empty($row['employee_lastname']) ? '(' . stripslashes(Tools::substr($row['employee_firstname'], 0, 1)) . '. ' . stripslashes($row['employee_lastname']) . ')' : '') . '</th>
				</tr>';
        /* Display previous status */
        foreach ($history as $row) {
            echo '
				<tr class="' . ($irow++ % 2 ? 'alt_row' : '') . '">
					<td>' . Tools::displayDate($row['date_add'], (int) $cookie->id_lang, true) . '</td>
					<td><img src="../img/os/' . $row['id_order_state'] . '.gif" /></td>
					<td>' . stripslashes($row['ostate_name']) . '</td>
					<td>' . (!empty($row['employee_lastname']) ? '(' . stripslashes(Tools::substr($row['employee_firstname'], 0, 1)) . '. ' . stripslashes($row['employee_lastname']) . ')' : '') . '</td>
				</tr>';
        }
        echo '
			</table>
			<br />';
        /* Display status form */
        echo '
			<form action="' . $currentIndex . '&view' . $this->table . '&token=' . $this->token . '" method="post" style="text-align:center;">
				<select name="id_order_state">';
        $currentStateTab = $order->getCurrentStateFull($cookie->id_lang);
        foreach ($states as $state) {
            echo '<option value="' . $state['id_order_state'] . '"' . ($state['id_order_state'] == $currentStateTab['id_order_state'] ? ' selected="selected"' : '') . '>' . stripslashes($state['name']) . '</option>';
        }
        echo '
				</select>
				<input type="hidden" name="id_order" value="' . $order->id . '" />
				<input type="submit" name="submitState" value="' . $this->l('Change') . '" class="button" />
			</form>';
        /* Display customer information */
        if (Validate::isLoadedObject($customer)) {
            echo '<br />
			<fieldset style="width: 400px">
				<legend><img src="../img/admin/tab-customers.gif" /> ' . $this->l('Customer information') . '</legend>
				<span style="font-weight: bold; font-size: 14px;"><a href="?tab=AdminCustomers&id_customer=' . $customer->id . '&viewcustomer&token=' . Tools::getAdminToken('AdminCustomers' . (int) Tab::getIdFromClassName('AdminCustomers') . (int) $cookie->id_employee) . '"> ' . $customer->firstname . ' ' . $customer->lastname . '</a></span> (' . $this->l('#') . $customer->id . ')<br />
				(<a href="mailto:' . $customer->email . '">' . $customer->email . '</a>)<br /><br />';
            if ($customer->isGuest()) {
                echo '
				' . $this->l('This order has been placed by a') . ' <b>' . $this->l('guest') . '</b>';
                if (!Customer::customerExists($customer->email)) {
                    echo '<form method="POST" action="index.php?tab=AdminCustomers&id_customer=' . (int) $customer->id . '&token=' . Tools::getAdminTokenLite('AdminCustomers') . '">
						<input type="hidden" name="id_lang" value="' . (int) $order->id_lang . '" />
						<p class="center"><input class="button" type="submit" name="submitGuestToCustomer" value="' . $this->l('Transform to customer') . '" /></p>
						' . $this->l('This feature will generate a random password and send an e-mail to the customer') . '
					</form>';
                } else {
                    echo '<div><b style="color:red;">' . $this->l('A registered customer account exists with the same email address') . '</b></div>';
                }
            } else {
                echo $this->l('Account registered:') . ' ' . Tools::displayDate($customer->date_add, (int) $cookie->id_lang, true) . '<br />
				' . $this->l('Valid orders placed:') . ' <b>' . $customerStats['nb_orders'] . '</b><br />
				' . $this->l('Total paid since registration:') . ' <b>' . Tools::displayPrice(Tools::ps_round(Tools::convertPrice($customerStats['total_orders'], $currency), 2), $currency, false) . '</b><br />';
            }
            echo '</fieldset>';
        }
        /* Display sources */
        if (sizeof($sources)) {
            echo '<br />
			<fieldset style="width: 400px;"><legend><img src="../img/admin/tab-stats.gif" /> ' . $this->l('Sources') . '</legend><ul ' . (sizeof($sources) > 3 ? 'style="height: 200px; overflow-y: scroll; width: 360px;"' : '') . '>';
            foreach ($sources as $source) {
                echo '<li>
						' . Tools::displayDate($source['date_add'], (int) $cookie->id_lang, true) . '<br />
						<b>' . $this->l('From:') . '</b> <a href="' . $source['http_referer'] . '">' . preg_replace('/^www./', '', parse_url($source['http_referer'], PHP_URL_HOST)) . '</a><br />
						<b>' . $this->l('To:') . '</b> ' . $source['request_uri'] . '<br />
						' . ($source['keywords'] ? '<b>' . $this->l('Keywords:') . '</b> ' . $source['keywords'] . '<br />' : '') . '<br />
					</li>';
            }
            echo '</ul></fieldset>';
        }
        // display hook specified to this page : AdminOrder
        if (($hook = Module::hookExec('adminOrder', array('id_order' => $order->id))) !== false) {
            echo $hook;
        }
        echo '
		</div>
		<div style="float: left; margin-left: 40px">';
        /* Display invoice information */
        echo '<fieldset style="width: 400px">';
        if (($currentState->invoice or $order->invoice_number) and count($products)) {
            echo '<legend><a href="pdf.php?id_order=' . $order->id . '&pdf"><img src="../img/admin/charged_ok.gif" /> ' . $this->l('Invoice') . '</a></legend>
				<a href="pdf.php?id_order=' . $order->id . '&pdf">' . $this->l('Invoice #') . '<b>' . Configuration::get('PS_INVOICE_PREFIX', (int) $cookie->id_lang) . sprintf('%06d', $order->invoice_number) . '</b></a>
				<br />' . $this->l('Created on:') . ' ' . Tools::displayDate($order->invoice_date, (int) $cookie->id_lang, true);
        } else {
            echo '<legend><img src="../img/admin/charged_ko.gif" />' . $this->l('Invoice') . '</legend>
				' . $this->l('No invoice yet.');
        }
        echo '</fieldset><br />';
        /* Display shipping infos */
        echo '
		<fieldset style="width:400px">
			<legend><img src="../img/admin/delivery.gif" /> ' . $this->l('Shipping information') . '</legend>
			' . $this->l('Total weight:') . ' <b>' . number_format($order->getTotalWeight(), 3) . ' ' . Configuration::get('PS_WEIGHT_UNIT') . '</b><br />
			' . $this->l('Carrier:') . ' <b>' . ($carrier->name == '0' ? Configuration::get('PS_SHOP_NAME') : $carrier->name) . '</b><br />
			' . (($currentState->delivery or $order->delivery_number) ? '<br /><a href="pdf.php?id_delivery=' . $order->delivery_number . '">' . $this->l('Delivery slip #') . '<b>' . Configuration::get('PS_DELIVERY_PREFIX', (int) $cookie->id_lang) . sprintf('%06d', $order->delivery_number) . '</b></a><br />' : '');
        if ($order->shipping_number) {
            echo $this->l('Tracking number:') . ' <b>' . $order->shipping_number . '</b> ' . (!empty($carrier->url) ? '(<a href="' . str_replace('@', $order->shipping_number, $carrier->url) . '" target="_blank">' . $this->l('Track the shipment') . '</a>)' : '');
        }
        /* Carrier module */
        if ($carrier->is_module == 1) {
            $module = Module::getInstanceByName($carrier->external_module_name);
            if (method_exists($module, 'displayInfoByCart')) {
                echo call_user_func(array($module, 'displayInfoByCart'), $order->id_cart);
            }
        }
        /* Display shipping number field */
        if ($carrier->url && $order->hasBeenShipped()) {
            echo '
				<form action="' . $currentIndex . '&view' . $this->table . '&token=' . $this->token . '" method="post" style="margin-top:10px;">
					<input type="text" name="shipping_number" value="' . $order->shipping_number . '" />
					<input type="hidden" name="id_order" value="' . $order->id . '" />
					<input type="submit" name="submitShippingNumber" value="' . $this->l('Set shipping number') . '" class="button" />
				</form>';
        }
        echo '
		</fieldset>';
        /* Display summary order */
        echo '
		<br />
		<fieldset style="width: 400px">
			<legend><img src="../img/admin/details.gif" /> ' . $this->l('Order details') . '</legend>
			<label>' . $this->l('Original cart:') . ' </label>
			<div style="margin: 2px 0 1em 190px;"><a href="?tab=AdminCarts&id_cart=' . $cart->id . '&viewcart&token=' . Tools::getAdminToken('AdminCarts' . (int) Tab::getIdFromClassName('AdminCarts') . (int) $cookie->id_employee) . '">' . $this->l('Cart #') . sprintf('%06d', $cart->id) . '</a></div>
			<label>' . $this->l('Payment mode:') . ' </label>
			<div style="margin: 2px 0 1em 190px;">' . Tools::substr($order->payment, 0, 32) . ' ' . ($order->module ? '(' . $order->module . ')' : '') . '</div>
			<div style="margin: 2px 0 1em 50px;">
				<table class="table" width="300px;" cellspacing="0" cellpadding="0">
					<tr><td width="150px;">' . $this->l('Products') . '</td><td align="right">' . Tools::displayPrice($order->getTotalProductsWithTaxes(), $currency, false) . '</td></tr>
					' . ($order->total_discounts > 0 ? '<tr><td>' . $this->l('Discounts') . '</td><td align="right">-' . Tools::displayPrice($order->total_discounts, $currency, false) . '</td></tr>' : '') . '
					' . ($order->total_wrapping > 0 ? '<tr><td>' . $this->l('Wrapping') . '</td><td align="right">' . Tools::displayPrice($order->total_wrapping, $currency, false) . '</td></tr>' : '') . '
					<tr><td>' . $this->l('Shipping') . '</td><td align="right">' . Tools::displayPrice($order->total_shipping, $currency, false) . '</td></tr>
					<tr style="font-size: 20px"><td>' . $this->l('Total') . '</td><td align="right">' . Tools::displayPrice($order->total_paid, $currency, false) . ($order->total_paid != $order->total_paid_real ? '<br /><font color="red">(' . $this->l('Paid:') . ' ' . Tools::displayPrice($order->total_paid_real, $currency, false, false) . ')</font>' : '') . '</td></tr>
				</table>
			</div>
			<div style="float: left; margin-right: 10px; margin-left: 42px;">
				<span class="bold">' . $this->l('Recycled package:') . '</span>
				' . ($order->recyclable ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />') . '
			</div>
			<div style="float: left; margin-right: 10px;">
				<span class="bold">' . $this->l('Gift wrapping:') . '</span>
				 ' . ($order->gift ? '<img src="../img/admin/enabled.gif" />
			</div>
			<div style="clear: left; margin: 0px 42px 0px 42px; padding-top: 2px;">
				' . (!empty($order->gift_message) ? '<div style="border: 1px dashed #999; padding: 5px; margin-top: 8px;"><b>' . $this->l('Message:') . '</b><br />' . nl2br2($order->gift_message) . '</div>' : '') : '<img src="../img/admin/disabled.gif" />') . '
			</div>
		</fieldset>';
        echo '</div>
		<div class="clear">&nbsp;</div>';
        /* Display adresses : delivery & invoice */
        echo '<div class="clear">&nbsp;</div>
		<div style="float: left">
			<fieldset style="width: 400px;">
				<legend><img src="../img/admin/delivery.gif" alt="' . $this->l('Shipping address') . '" />' . $this->l('Shipping address') . '</legend>
				<div style="float: right">
					<a href="?tab=AdminAddresses&id_address=' . $addressDelivery->id . '&addaddress&realedit=1&id_order=' . $order->id . ($addressDelivery->id == $addressInvoice->id ? '&address_type=1' : '') . '&token=' . Tools::getAdminToken('AdminAddresses' . (int) Tab::getIdFromClassName('AdminAddresses') . (int) $cookie->id_employee) . '&back=' . urlencode($_SERVER['REQUEST_URI']) . '"><img src="../img/admin/edit.gif" /></a>
					<a href="http://maps.google.com/maps?f=q&hl=' . $currentLanguage->iso_code . '&geocode=&q=' . $addressDelivery->address1 . ' ' . $addressDelivery->postcode . ' ' . $addressDelivery->city . ($addressDelivery->id_state ? ' ' . $deliveryState->name : '') . '" target="_blank"><img src="../img/admin/google.gif" alt="" class="middle" /></a>
				</div>
				' . $this->displayAddressDetail($addressDelivery) . (!empty($addressDelivery->other) ? '<hr />' . $addressDelivery->other . '<br />' : '') . '</fieldset>
		</div>
		<div style="float: left; margin-left: 40px">
			<fieldset style="width: 400px;">
				<legend><img src="../img/admin/invoice.gif" alt="' . $this->l('Invoice address') . '" />' . $this->l('Invoice address') . '</legend>
				<div style="float: right"><a href="?tab=AdminAddresses&id_address=' . $addressInvoice->id . '&addaddress&realedit=1&id_order=' . $order->id . ($addressDelivery->id == $addressInvoice->id ? '&address_type=2' : '') . '&back=' . urlencode($_SERVER['REQUEST_URI']) . '&token=' . Tools::getAdminToken('AdminAddresses' . (int) Tab::getIdFromClassName('AdminAddresses') . (int) $cookie->id_employee) . '"><img src="../img/admin/edit.gif" /></a></div>
				' . $this->displayAddressDetail($addressInvoice) . (!empty($addressInvoice->other) ? '<hr />' . $addressInvoice->other . '<br />' : '') . '</fieldset>
		</div>
		<div class="clear">&nbsp;</div>';
        // List of products
        echo '
		<a name="products"><br /></a>
		<form action="' . $currentIndex . '&submitCreditSlip&vieworder&token=' . $this->token . '" method="post" onsubmit="return orderDeleteProduct(\'' . $this->l('Cannot return this product') . '\', \'' . $this->l('Quantity to cancel is greater than quantity available') . '\');">
			<input type="hidden" name="id_order" value="' . $order->id . '" />
			<fieldset style="width: 868px; ">
				<legend><img src="../img/admin/cart.gif" alt="' . $this->l('Products') . '" />' . $this->l('Products') . '</legend>
				<div style="float:left;">
					<table style="width: 868px;" cellspacing="0" cellpadding="0" class="table" id="orderProducts">
						<tr>
							<th align="center" style="width: 60px">&nbsp;</th>
							<th>' . $this->l('Product') . '</th>
							<th style="width: 80px; text-align: center">' . $this->l('UP') . ' <sup>*</sup></th>
							<th style="width: 20px; text-align: center">' . $this->l('Qty') . '</th>
							' . ($order->hasBeenPaid() ? '<th style="width: 20px; text-align: center">' . $this->l('Refunded') . '</th>' : '') . '
							' . ($order->hasBeenDelivered() ? '<th style="width: 20px; text-align: center">' . $this->l('Returned') . '</th>' : '') . '
							<th style="width: 30px; text-align: center">' . $this->l('Stock') . '</th>
							<th style="width: 90px; text-align: center">' . $this->l('Total') . ' <sup>*</sup></th>
							<th colspan="2" style="width: 120px;"><img src="../img/admin/delete.gif" alt="' . $this->l('Products') . '" /> ' . ($order->hasBeenDelivered() ? $this->l('Return') : ($order->hasBeenPaid() ? $this->l('Refund') : $this->l('Cancel'))) . '</th>';
        echo '
						</tr>';
        $tokenCatalog = Tools::getAdminToken('AdminCatalog' . (int) Tab::getIdFromClassName('AdminCatalog') . (int) $cookie->id_employee);
        foreach ($products as $k => $product) {
            if ($order->getTaxCalculationMethod() == PS_TAX_EXC) {
                $product_price = $product['product_price'] + $product['ecotax'];
            } else {
                $product_price = $product['product_price_wt'];
            }
            $image = array();
            if (isset($product['product_attribute_id']) and (int) $product['product_attribute_id']) {
                $image = Db::getInstance()->getRow('
								SELECT id_image
								FROM ' . _DB_PREFIX_ . 'product_attribute_image
								WHERE id_product_attribute = ' . (int) $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 = ' . (int) $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 = ' . (int) $product['product_id'] . '
							' . ($product['product_attribute_id'] ? 'AND pa.id_product_attribute = ' . (int) $product['product_attribute_id'] : ''));
            if (isset($image['id_image'])) {
                $target = _PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $product['product_id'] . (isset($product['product_attribute_id']) ? '_' . (int) $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']) {
                $quantity = $product['product_quantity'] - $product['customizationQuantityTotal'];
                $imageObj = new Image($image['id_image']);
                echo '
								<tr' . ((isset($image['id_image']) and isset($products[$k]['image_size'])) ? ' height="' . ($products[$k]['image_size'][1] + 7) . '"' : '') . '>
									<td align="center">' . (isset($image['id_image']) ? cacheImage(_PS_IMG_DIR_ . 'p/' . $imageObj->getExistingImgPath() . '.jpg', 'product_mini_' . (int) $product['product_id'] . (isset($product['product_attribute_id']) ? '_' . (int) $product['product_attribute_id'] : '') . '.jpg', 45, 'jpg') : '--') . '</td>
									<td><a href="index.php?tab=AdminCatalog&id_product=' . $product['product_id'] . '&updateproduct&token=' . $tokenCatalog . '">
										<span class="productName">' . $product['product_name'] . '</span><br />
										' . ($product['product_reference'] ? $this->l('Ref:') . ' ' . $product['product_reference'] . '<br />' : '') . ($product['product_supplier_reference'] ? $this->l('Ref Supplier:') . ' ' . $product['product_supplier_reference'] : '') . '</a></td>
									<td align="center">' . Tools::displayPrice($product_price, $currency, false) . '</td>
									<td align="center" class="productQuantity" ' . ($quantity > 1 ? 'style="font-weight:700;font-size:1.1em;color:red"' : '') . '>' . (int) $quantity . '</td>
									' . ($order->hasBeenPaid() ? '<td align="center" class="productQuantity">' . (int) $product['product_quantity_refunded'] . '</td>' : '') . '
									' . ($order->hasBeenDelivered() ? '<td align="center" class="productQuantity">' . (int) $product['product_quantity_return'] . '</td>' : '') . '
									<td align="center" class="productQuantity">' . (int) $stock['quantity'] . '</td>
									<td align="center">' . Tools::displayPrice(Tools::ps_round($product_price, 2) * ((int) $product['product_quantity'] - $product['customizationQuantityTotal']), $currency, false) . '</td>
									<td align="center" class="cancelCheck">
										<input type="hidden" name="totalQtyReturn" id="totalQtyReturn" value="' . (int) $product['product_quantity_return'] . '" />
										<input type="hidden" name="totalQty" id="totalQty" value="' . (int) $product['product_quantity'] . '" />
										<input type="hidden" name="productName" id="productName" value="' . $product['product_name'] . '" />';
                if ((!$order->hasBeenDelivered() or Configuration::get('PS_ORDER_RETURN')) and (int) $product['product_quantity_return'] < (int) $product['product_quantity']) {
                    echo '
										<input type="checkbox" name="id_order_detail[' . $k . ']" id="id_order_detail[' . $k . ']" value="' . $product['id_order_detail'] . '" onchange="setCancelQuantity(this, ' . (int) $product['id_order_detail'] . ', ' . (int) ($product['product_quantity_in_stock'] - $product['customizationQuantityTotal'] - $product['product_quantity_reinjected']) . ')" ' . ((int) ($product['product_quantity_return'] + $product['product_quantity_refunded']) >= (int) $product['product_quantity'] ? 'disabled="disabled" ' : '') . '/>';
                } else {
                    echo '--';
                }
                echo '
									</td>
									<td class="cancelQuantity">';
                if ((int) ($product['product_quantity_return'] + $product['product_quantity_refunded']) >= (int) $product['product_quantity']) {
                    echo '<input type="hidden" name="cancelQuantity[' . $k . ']" value="0" />';
                } elseif (!$order->hasBeenDelivered() or Configuration::get('PS_ORDER_RETURN')) {
                    echo '
										<input type="text" id="cancelQuantity_' . (int) $product['id_order_detail'] . '" name="cancelQuantity[' . $k . ']" size="2" onclick="selectCheckbox(this);" value="" /> ';
                }
                echo $this->getCancelledProductNumber($order, $product) . '
									</td>
								</tr>';
            }
        }
        echo '
					</table>
					<div style="float:left; width:280px; margin-top:15px;"><sup>*</sup> ' . $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') ? '<br /><br />' . $this->l('Merchandise returns are disabled') : '') . '</div>';
        if (sizeof($discounts)) {
            echo '
					<div style="float:right; width:280px; margin-top:15px;">
					<table cellspacing="0" cellpadding="0" class="table" style="width:100%;">
						<tr>
							<th><img src="../img/admin/coupon.gif" alt="' . $this->l('Discounts') . '" />' . $this->l('Discount name') . '</th>
							<th align="center" style="width: 100px">' . $this->l('Value') . '</th>
						</tr>';
            foreach ($discounts as $discount) {
                echo '
						<tr>
							<td>' . $discount['name'] . '</td>
							<td align="center">' . ($discount['value'] != 0.0 ? '- ' : '') . Tools::displayPrice($discount['value'], $currency, false) . '</td>
						</tr>';
            }
            echo '
					</table></div>';
        }
        echo '
				</div>';
        // Cancel product
        echo '
				<div style="clear:both; height:15px;">&nbsp;</div>
				<div style="float: right; width: 160px;">';
        if ($order->hasBeenDelivered() and Configuration::get('PS_ORDER_RETURN')) {
            echo '
					<input type="checkbox" id="reinjectQuantities" name="reinjectQuantities" class="button" />&nbsp;<label for="reinjectQuantities" style="float:none; font-weight:normal;">' . $this->l('Re-stock products') . '</label><br />';
        }
        if (!$order->hasBeenDelivered() and $order->hasBeenPaid() or $order->hasBeenDelivered() and Configuration::get('PS_ORDER_RETURN')) {
            echo '
					<input type="checkbox" id="generateCreditSlip" name="generateCreditSlip" class="button" onclick="toogleShippingCost(this)" />&nbsp;<label for="generateCreditSlip" style="float:none; font-weight:normal;">' . $this->l('Generate a credit slip') . '</label><br />
					<input type="checkbox" id="generateDiscount" name="generateDiscount" class="button" onclick="toogleShippingCost(this)" />&nbsp;<label for="generateDiscount" style="float:none; font-weight:normal;">' . $this->l('Generate a voucher') . '</label><br />
					<span id="spanShippingBack" style="display:none;"><input type="checkbox" id="shippingBack" name="shippingBack" class="button" />&nbsp;<label for="shippingBack" style="float:none; font-weight:normal;">' . $this->l('Repay shipping costs') . '</label><br /></span>';
        }
        if (!$order->hasBeenDelivered() or $order->hasBeenDelivered() and Configuration::get('PS_ORDER_RETURN')) {
            echo '
					<div style="text-align:center; margin-top:5px;"><input type="submit" name="cancelProduct" value="' . ($order->hasBeenDelivered() ? $this->l('Return products') : ($order->hasBeenPaid() ? $this->l('Refund products') : $this->l('Cancel products'))) . '" class="button" style="margin-top:8px;" /></div>';
        }
        echo '
				</div>';
        echo '
			</fieldset>
		</form>
		<div class="clear" style="height:20px;">&nbsp;</div>';
        /* 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 '
		<div style="float: left">
			<form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '&token=' . $this->token . '" method="post" onsubmit="if (getE(\'visibility\').checked == true) return confirm(\'' . $this->l('Do you want to send this message to the customer?', __CLASS__, true, false) . '\');">
			<fieldset style="width: 400px;">
				<legend style="cursor: pointer;" onclick="$(\'#message\').slideToggle();$(\'#message_m\').slideToggle();return false"><img src="../img/admin/email_edit.gif" /> ' . $this->l('New message') . '</legend>
				<div id="message_m" style="display: ' . (Tools::getValue('message') ? 'none' : 'block') . '; overflow: auto; width: 400px;">
					<a href="#" onclick="$(\'#message\').slideToggle();$(\'#message_m\').slideToggle();return false"><b>' . $this->l('Click here') . '</b> ' . $this->l('to add a comment or send a message to the customer') . '</a>
				</div>
				<div id="message" style="display: ' . (Tools::getValue('message') ? 'block' : 'none') . '">
					<select 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>';
        $orderMessages = OrderMessage::getOrderMessages((int) $order->id_lang);
        foreach ($orderMessages as $orderMessage) {
            echo '		<option value="' . htmlentities($orderMessage['message'], ENT_COMPAT, 'UTF-8') . '">' . $orderMessage['name'] . '</option>';
        }
        echo '		</select><br /><br />
					<b>' . $this->l('Display to consumer?') . '</b>
					<input type="radio" name="visibility" id="visibility" value="0" /> ' . $this->l('Yes') . '
					<input type="radio" name="visibility" value="1" checked="checked" /> ' . $this->l('No') . '
					<p id="nbchars" style="display:inline;font-size:10px;color:#666;"></p><br /><br />
					<textarea id="txt_msg" name="message" cols="50" rows="8" onKeyUp="var length = document.getElementById(\'txt_msg\').value.length; if (length > 600) length = \'600+\'; document.getElementById(\'nbchars\').innerHTML = \'' . $this->l('600 chars max') . ' (\' + length + \')\';">' . htmlentities(Tools::getValue('message'), ENT_COMPAT, 'UTF-8') . '</textarea><br /><br />
					<input type="hidden" name="id_order" value="' . (int) $order->id . '" />
					<input type="hidden" name="id_customer" value="' . (int) $order->id_customer . '" />
					<input type="submit" class="button" name="submitMessage" value="' . $this->l('Send') . '" />
				</div>
			</fieldset>
			</form>';
        /* Display list of messages */
        if (sizeof($messages)) {
            echo '
			<br />
			<fieldset style="width: 400px;">
			<legend><img src="../img/admin/email.gif" /> ' . $this->l('Messages') . '</legend>';
            foreach ($messages as $message) {
                echo '<div style="overflow:auto; width:400px;" ' . ($message['is_new_for_me'] ? 'class="new_message"' : '') . '>';
                if ($message['is_new_for_me']) {
                    echo '<a class="new_message" title="' . $this->l('Mark this message as \'viewed\'') . '" href="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '&token=' . $this->token . '&messageReaded=' . (int) $message['id_message'] . '"><img src="../img/admin/enabled.gif" alt="" /></a>';
                }
                echo $this->l('At') . ' <i>' . Tools::displayDate($message['date_add'], (int) $cookie->id_lang, true);
                echo '</i> ' . $this->l('from') . ' <b>' . ($message['elastname'] ? $message['efirstname'] . ' ' . $message['elastname'] : $message['cfirstname'] . ' ' . $message['clastname']) . '</b>';
                echo (int) $message['private'] == 1 ? '<span style="color:red; font-weight:bold;">' . $this->l('Private:') . '</span>' : '';
                echo '<p>' . nl2br2($message['message']) . '</p>';
                echo '</div>';
                echo '<br />';
            }
            echo '<p class="info">' . $this->l('When you read a message, please click on the green check.') . '</p>';
            echo '</fieldset>';
        }
        echo '</div>';
        /* Display return product */
        echo '<div style="float: left; margin-left: 40px">
			<fieldset style="width: 400px;">
				<legend><img src="../img/admin/return.gif" alt="' . $this->l('Merchandise returns') . '" />' . $this->l('Merchandise returns') . '</legend>';
        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) . ') :
				<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> -
				' . $state->name[$cookie->id_lang] . '<br />';
            }
        }
        echo '</fieldset>';
        /* Display credit slip */
        echo '
				<br />
				<fieldset style="width: 400px;">
					<legend><img src="../img/admin/slip.gif" alt="' . $this->l('Credit slip') . '" />' . $this->l('Credit slip') . '</legend>';
        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) . ') : <b><a href="pdf.php?id_order_slip=' . $slip['id_order_slip'] . '">' . $this->l('#') . sprintf('%06d', $slip['id_order_slip']) . '</a></b><br />';
            }
        }
        echo '</fieldset>
		</div>';
        echo '<div class="clear">&nbsp;</div>';
        echo '<br /><br /><a href="' . $currentIndex . '&token=' . $this->token . '"><img src="../img/admin/arrow2.gif" /> ' . $this->l('Back to list') . '</a><br />';
    }
Пример #17
0
 public function ajaxProcessEditProductOnOrder()
 {
     $res = true;
     $order = new Order((int) Tools::getValue('id_order'));
     $order_detail = new OrderDetail((int) Tools::getValue('product_id_order_detail'));
     if (Tools::isSubmit('product_invoice')) {
         $order_invoice = new OrderInvoice((int) Tools::getValue('product_invoice'));
     }
     $this->doEditProductValidation($order_detail, $order, isset($order_invoice) ? $order_invoice : null);
     $qty_behavior = PP::qtyBehavior($order_detail, $order_detail->product_quantity) && !is_array(Tools::getValue('product_quantity'));
     $product_quantity = 0;
     if (is_array(Tools::getValue('product_quantity'))) {
         foreach (Tools::getValue('product_quantity') as $id_customization => $qty) {
             Db::getInstance()->update('customization', array('quantity' => (int) $qty), 'id_customization = ' . (int) $id_customization);
             $product_quantity += $qty;
         }
     } else {
         $product_quantity = str_replace(',', '.', Tools::getValue('product_quantity'));
     }
     $product_price_tax_incl = Tools::ps_round(Tools::getValue('product_price_tax_incl'), 2);
     $product_price_tax_excl = Tools::ps_round(Tools::getValue('product_price_tax_excl'), 2);
     $total_products_tax_incl = PP::calcPrice($product_price_tax_incl, $qty_behavior ? $order_detail->product_quantity : $product_quantity, $qty_behavior ? $product_quantity : $order_detail->product_quantity_fractional, $order_detail->product_id);
     $total_products_tax_excl = PP::calcPrice($product_price_tax_excl, $qty_behavior ? $order_detail->product_quantity : $product_quantity, $qty_behavior ? $product_quantity : $order_detail->product_quantity_fractional, $order_detail->product_id);
     $diff_price_tax_incl = $total_products_tax_incl - $order_detail->total_price_tax_incl;
     $diff_price_tax_excl = $total_products_tax_excl - $order_detail->total_price_tax_excl;
     $ppropertiessmartprice_hook1 = null;
     if (isset($order_invoice)) {
         if ($order_detail->id_order_invoice != $order_invoice->id) {
             $old_order_invoice = new OrderInvoice($order_detail->id_order_invoice);
             $old_order_invoice->total_products -= $order_detail->total_price_tax_excl;
             $old_order_invoice->total_products_wt -= $order_detail->total_price_tax_incl;
             $old_order_invoice->total_paid_tax_excl -= $order_detail->total_price_tax_excl;
             $old_order_invoice->total_paid_tax_incl -= $order_detail->total_price_tax_incl;
             $res &= $old_order_invoice->update();
             $order_invoice->total_products += $order_detail->total_price_tax_excl;
             $order_invoice->total_products_wt += $order_detail->total_price_tax_incl;
             $order_invoice->total_paid_tax_excl += $order_detail->total_price_tax_excl;
             $order_invoice->total_paid_tax_incl += $order_detail->total_price_tax_incl;
             $order_detail->id_order_invoice = $order_invoice->id;
         }
     }
     if ($diff_price_tax_incl != 0 && $diff_price_tax_excl != 0) {
         $order_detail->unit_price_tax_excl = $product_price_tax_excl;
         $order_detail->unit_price_tax_incl = $product_price_tax_incl;
         $order_detail->total_price_tax_incl += $diff_price_tax_incl;
         $order_detail->total_price_tax_excl += $diff_price_tax_excl;
         if (isset($order_invoice)) {
             $order_invoice->total_products += $diff_price_tax_excl;
             $order_invoice->total_products_wt += $diff_price_tax_incl;
             $order_invoice->total_paid_tax_excl += $diff_price_tax_excl;
             $order_invoice->total_paid_tax_incl += $diff_price_tax_incl;
         }
         $order = new Order($order_detail->id_order);
         $order->total_products += $diff_price_tax_excl;
         $order->total_products_wt += $diff_price_tax_incl;
         $order->total_paid += $diff_price_tax_incl;
         $order->total_paid_tax_excl += $diff_price_tax_excl;
         $order->total_paid_tax_incl += $diff_price_tax_incl;
         $res &= $order->update();
     }
     $old_quantity = PP::resolveQty($order_detail->product_quantity, $order_detail->product_quantity_fractional);
     if ($qty_behavior) {
         $order_detail->product_quantity_fractional = $product_quantity;
     } else {
         $order_detail->product_quantity = $product_quantity;
     }
     $res &= $order_detail->updateTaxAmount($order);
     $res &= $order_detail->update();
     $order_carrier = new OrderCarrier((int) $order->getIdOrderCarrier());
     if (Validate::isLoadedObject($order_carrier)) {
         $order_carrier->weight = (double) $order->getTotalWeight();
         $res &= $order_carrier->update();
         if ($res) {
             $order->weight = sprintf('%.3f ' . Configuration::get('PS_WEIGHT_UNIT'), $order_carrier->weight);
         }
     }
     if (isset($order_invoice)) {
         $res &= $order_invoice->update();
     }
     StockAvailable::updateQuantity($order_detail->product_id, $order_detail->product_attribute_id, $old_quantity - PP::resolveQty($order_detail->product_quantity, $order_detail->product_quantity_fractional), $order->id_shop);
     $products = $this->getProducts($order);
     $product = $products[$order_detail->id];
     $resume = OrderSlip::getProductSlipResume($order_detail->id);
     $product['quantity_refundable'] = $product['product_quantity'] - $resume['product_quantity'];
     $product['amount_refundable'] = $product['total_price_tax_excl'] - $resume['amount_tax_excl'];
     $product['amount_refund'] = Tools::displayPrice($resume['amount_tax_incl']);
     $product['refund_history'] = OrderSlip::getProductSlipDetail($order_detail->id);
     if ($product['id_warehouse'] != 0) {
         $warehouse = new Warehouse((int) $product['id_warehouse']);
         $product['warehouse_name'] = $warehouse->name;
     } else {
         $product['warehouse_name'] = '--';
     }
     $invoice_collection = $order->getInvoicesCollection();
     $invoice_array = array();
     foreach ($invoice_collection as $invoice) {
         $invoice->name = $invoice->getInvoiceNumberFormatted(Context::getContext()->language->id, (int) $order->id_shop);
         $invoice_array[] = $invoice;
     }
     $this->context->smarty->assign(array('product' => $product, 'order' => $order, 'currency' => new Currency($order->id_currency), 'can_edit' => $this->tabAccess['edit'], 'invoices_collection' => $invoice_collection, 'current_id_lang' => Context::getContext()->language->id, 'link' => Context::getContext()->link, 'current_index' => self::$currentIndex, 'display_warehouse' => (int) Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')));
     if (!$res) {
         die(Tools::jsonEncode(array('result' => $res, 'error' => Tools::displayError('An error occurred while editing the product line.'))));
     }
     if (is_array(Tools::getValue('product_quantity'))) {
         $view = $this->createTemplate('_customized_data.tpl')->fetch();
     } else {
         $view = $this->createTemplate('_product_line.tpl')->fetch();
     }
     $this->sendChangedNotification($order);
     die(Tools::jsonEncode(array('result' => $res, 'view' => $view, 'can_edit' => $this->tabAccess['add'], 'invoices_collection' => $invoice_collection, 'order' => $order, 'invoices' => $invoice_array, 'documents_html' => $this->createTemplate('_documents.tpl')->fetch(), 'shipping_html' => $this->createTemplate('_shipping.tpl')->fetch(), 'customized_product' => is_array(Tools::getValue('product_quantity')))));
 }
Пример #18
0
function generateOrderSlipsPDF()
{
    $orderSlips = OrderSlip::getSlipsIdByDate($_GET['date_from'], $_GET['date_to']);
    if (!count($orderSlips)) {
        die(Tools::displayError('No order slips found'));
    }
    PDF::multipleOrderSlips($orderSlips);
}
Пример #19
0
 public static function createOrderSlip($order, $productList, $qtyList, $shipping_cost = false)
 {
     $currency = new Currency($order->id_currency);
     $orderSlip = new OrderSlip();
     $orderSlip->id_customer = (int) $order->id_customer;
     $orderSlip->id_order = (int) $order->id;
     $orderSlip->shipping_cost = (int) $shipping_cost;
     $orderSlip->conversion_rate = $currency->conversion_rate;
     if (!$orderSlip->add()) {
         return false;
     }
     $orderSlip->addSlipDetail($productList, $qtyList);
     return true;
 }
Пример #20
0
if (isset($_GET['pdf'])) {
    if (!isset($_GET['id_order'])) {
        die(Tools::displayError('order ID is missing'));
    }
    $order = new Order(intval($_GET['id_order']));
    if (!Validate::isLoadedObject($order)) {
        die(Tools::displayError('cannot find order in database'));
    }
    PDF::invoice($order);
} elseif (isset($_GET['id_order_slip'])) {
    $orderSlip = new OrderSlip(intval($_GET['id_order_slip']));
    $order = new Order(intval($orderSlip->id_order));
    if (!Validate::isLoadedObject($order)) {
        die(Tools::displayError('cannot find order in database'));
    }
    $order->products = OrderSlip::getOrdersSlipProducts($orderSlip->id, $order);
    $tmp = NULL;
    PDF::invoice($order, 'D', false, $tmp, $orderSlip);
} elseif (isset($_GET['id_delivery'])) {
    $order = Order::getByDelivery(intval($_GET['id_delivery']));
    if (!Validate::isLoadedObject($order)) {
        die(Tools::displayError('cannot find order in database'));
    }
    $tmp = NULL;
    PDF::invoice($order, 'D', false, $tmp, false, $order->delivery_number);
} elseif (isset($_GET['invoices'])) {
    $invoices = Order::getOrdersIdInvoiceByDate($_GET['date_from'], $_GET['date_to'], NULL, 'invoice');
    if (is_array($invoices)) {
        PDF::multipleInvoices($invoices);
    }
} elseif (isset($_GET['deliveryslips'])) {
Пример #21
0
 public function ajaxProcessEditProductOnOrder()
 {
     // Return value
     $res = true;
     $order = new Order((int) Tools::getValue('id_order'));
     $order_detail = new OrderDetail((int) Tools::getValue('product_id_order_detail'));
     if (Tools::isSubmit('product_invoice')) {
         $order_invoice = new OrderInvoice((int) Tools::getValue('product_invoice'));
     }
     // Check fields validity
     $this->doEditProductValidation($order_detail, $order, isset($order_invoice) ? $order_invoice : null);
     // If multiple product_quantity, the order details concern a product customized
     $product_quantity = 0;
     if (is_array(Tools::getValue('product_quantity'))) {
         foreach (Tools::getValue('product_quantity') as $id_customization => $qty) {
             // Update quantity of each customization
             Db::getInstance()->update('customization', array('quantity' => $qty), 'id_customization = ' . (int) $id_customization);
             // Calculate the real quantity of the product
             $product_quantity += $qty;
         }
     } else {
         $product_quantity = Tools::getValue('product_quantity');
     }
     $product_price_tax_incl = Tools::ps_round(Tools::getValue('product_price_tax_incl'), 2);
     $product_price_tax_excl = Tools::ps_round(Tools::getValue('product_price_tax_excl'), 2);
     $total_products_tax_incl = $product_price_tax_incl * $product_quantity;
     $total_products_tax_excl = $product_price_tax_excl * $product_quantity;
     // Calculate differences of price (Before / After)
     $diff_price_tax_incl = $total_products_tax_incl - $order_detail->total_price_tax_incl;
     $diff_price_tax_excl = $total_products_tax_excl - $order_detail->total_price_tax_excl;
     // Apply change on OrderInvoice
     if (isset($order_invoice)) {
         // If OrderInvoice to use is different, we update the old invoice and new invoice
         if ($order_detail->id_order_invoice != $order_invoice->id) {
             $old_order_invoice = new OrderInvoice($order_detail->id_order_invoice);
             // We remove cost of products
             $old_order_invoice->total_products -= $order_detail->total_price_tax_excl;
             $old_order_invoice->total_products_wt -= $order_detail->total_price_tax_incl;
             $old_order_invoice->total_paid_tax_excl -= $order_detail->total_price_tax_excl;
             $old_order_invoice->total_paid_tax_incl -= $order_detail->total_price_tax_incl;
             $res &= $old_order_invoice->update();
             $order_invoice->total_products += $order_detail->total_price_tax_excl;
             $order_invoice->total_products_wt += $order_detail->total_price_tax_incl;
             $order_invoice->total_paid_tax_excl += $order_detail->total_price_tax_excl;
             $order_invoice->total_paid_tax_incl += $order_detail->total_price_tax_incl;
             $order_detail->id_order_invoice = $order_invoice->id;
         }
     }
     if ($diff_price_tax_incl != 0 && $diff_price_tax_excl != 0) {
         $order_detail->unit_price_tax_excl = $product_price_tax_excl;
         $order_detail->unit_price_tax_incl = $product_price_tax_incl;
         $order_detail->total_price_tax_incl += $diff_price_tax_incl;
         $order_detail->total_price_tax_excl += $diff_price_tax_excl;
         if (isset($order_invoice)) {
             // Apply changes on OrderInvoice
             $order_invoice->total_products += $diff_price_tax_excl;
             $order_invoice->total_products_wt += $diff_price_tax_incl;
             $order_invoice->total_paid_tax_excl += $diff_price_tax_excl;
             $order_invoice->total_paid_tax_incl += $diff_price_tax_incl;
         }
         // Apply changes on Order
         $order = new Order($order_detail->id_order);
         $order->total_products += $diff_price_tax_excl;
         $order->total_products_wt += $diff_price_tax_incl;
         $order->total_paid += $diff_price_tax_incl;
         $order->total_paid_tax_excl += $diff_price_tax_excl;
         $order->total_paid_tax_incl += $diff_price_tax_incl;
         $res &= $order->update();
     }
     $old_quantity = $order_detail->product_quantity;
     $order_detail->product_quantity = $product_quantity;
     // update taxes
     $res &= $order_detail->updateTaxAmount($order);
     // Save order detail
     $res &= $order_detail->update();
     // Update weight SUM
     $order_carrier = new OrderCarrier((int) $order->getIdOrderCarrier());
     if (Validate::isLoadedObject($order_carrier)) {
         $order_carrier->weight = (double) $order->getTotalWeight();
         $res &= $order_carrier->update();
         if ($res) {
             $order->weight = sprintf("%.3f " . Configuration::get('PS_WEIGHT_UNIT'), $order_carrier->weight);
         }
     }
     // Save order invoice
     if (isset($order_invoice)) {
         $res &= $order_invoice->update();
     }
     // Update product available quantity
     StockAvailable::updateQuantity($order_detail->product_id, $order_detail->product_attribute_id, $old_quantity - $order_detail->product_quantity, $order->id_shop);
     $products = $this->getProducts($order);
     // Get the last product
     $product = $products[$order_detail->id];
     $resume = OrderSlip::getProductSlipResume($order_detail->id);
     $product['quantity_refundable'] = $product['product_quantity'] - $resume['product_quantity'];
     $product['amount_refundable'] = $product['total_price_tax_incl'] - $resume['amount_tax_incl'];
     $product['amount_refund'] = Tools::displayPrice($resume['amount_tax_incl']);
     $product['refund_history'] = OrderSlip::getProductSlipDetail($order_detail->id);
     if ($product['id_warehouse'] != 0) {
         $warehouse = new Warehouse((int) $product['id_warehouse']);
         $product['warehouse_name'] = $warehouse->name;
     } else {
         $product['warehouse_name'] = '--';
     }
     // Get invoices collection
     $invoice_collection = $order->getInvoicesCollection();
     $invoice_array = array();
     foreach ($invoice_collection as $invoice) {
         $invoice->name = $invoice->getInvoiceNumberFormatted(Context::getContext()->language->id, (int) $order->id_shop);
         $invoice_array[] = $invoice;
     }
     // Assign to smarty informations in order to show the new product line
     $this->context->smarty->assign(array('product' => $product, 'order' => $order, 'currency' => new Currency($order->id_currency), 'can_edit' => $this->tabAccess['edit'], 'invoices_collection' => $invoice_collection, 'current_id_lang' => Context::getContext()->language->id, 'link' => Context::getContext()->link, 'current_index' => self::$currentIndex, 'display_warehouse' => (int) Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')));
     if (!$res) {
         die(Tools::jsonEncode(array('result' => $res, 'error' => Tools::displayError('An error occurred while editing the product line.'))));
     }
     if (is_array(Tools::getValue('product_quantity'))) {
         $view = $this->createTemplate('_customized_data.tpl')->fetch();
     } else {
         $view = $this->createTemplate('_product_line.tpl')->fetch();
     }
     $this->sendChangedNotification($order);
     die(Tools::jsonEncode(array('result' => $res, 'view' => $view, 'can_edit' => $this->tabAccess['add'], 'invoices_collection' => $invoice_collection, 'order' => $order, 'invoices' => $invoice_array, 'documents_html' => $this->createTemplate('_documents.tpl')->fetch(), 'shipping_html' => $this->createTemplate('_shipping.tpl')->fetch(), 'customized_product' => is_array(Tools::getValue('product_quantity')))));
 }
Пример #22
0
    public static function create(Order $order, $product_list, $shipping_cost = false, $amount = 0, $amount_choosen = false, $add_tax = true)
    {
        $currency = new Currency((int) $order->id_currency);
        $order_slip = new OrderSlip();
        $order_slip->id_customer = (int) $order->id_customer;
        $order_slip->id_order = (int) $order->id;
        $order_slip->conversion_rate = $currency->conversion_rate;
        if ($add_tax) {
            $add_or_remove = 'add';
            $inc_or_ex_1 = 'excl';
            $inc_or_ex_2 = 'incl';
        } else {
            $add_or_remove = 'remove';
            $inc_or_ex_1 = 'incl';
            $inc_or_ex_2 = 'excl';
        }
        $order_slip->{'total_shipping_tax_' . $inc_or_ex_1} = 0;
        $order_slip->{'total_shipping_tax_' . $inc_or_ex_2} = 0;
        $order_slip->partial = 0;
        if ($shipping_cost !== false) {
            $order_slip->shipping_cost = true;
            $carrier = new Carrier((int) $order->id_carrier);
            $address = Address::initialize($order->id_address_delivery, false);
            $tax_calculator = $carrier->getTaxCalculator($address);
            $order_slip->{'total_shipping_tax_' . $inc_or_ex_1} = $shipping_cost === null ? $order->{'total_shipping_tax_' . $inc_or_ex_1} : (double) $shipping_cost;
            if ($tax_calculator instanceof TaxCalculator) {
                $order_slip->{'total_shipping_tax_' . $inc_or_ex_2} = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($order_slip->{'total_shipping_tax_' . $inc_or_ex_1}), _PS_PRICE_COMPUTE_PRECISION_);
            } else {
                $order_slip->{'total_shipping_tax_' . $inc_or_ex_2} = $order_slip->{'total_shipping_tax_' . $inc_or_ex_1};
            }
        } else {
            $order_slip->shipping_cost = false;
        }
        $order_slip->amount = 0;
        $order_slip->{'total_products_tax_' . $inc_or_ex_1} = 0;
        $order_slip->{'total_products_tax_' . $inc_or_ex_2} = 0;
        foreach ($product_list as &$product) {
            $order_detail = new OrderDetail((int) $product['id_order_detail']);
            $price = (double) $product['unit_price'];
            $quantity = (int) $product['quantity'];
            $order_slip_resume = OrderSlip::getProductSlipResume((int) $order_detail->id);
            if ($quantity + $order_slip_resume['product_quantity'] > $order_detail->product_quantity) {
                $quantity = $order_detail->product_quantity - $order_slip_resume['product_quantity'];
            }
            if ($quantity == 0) {
                continue;
            }
            $order_detail->product_quantity_refunded += $quantity;
            $order_detail->save();
            $address = Address::initialize($order->id_address_invoice, false);
            $id_tax_rules_group = Product::getIdTaxRulesGroupByIdProduct((int) $order_detail->product_id);
            $tax_calculator = TaxManagerFactory::getManager($address, $id_tax_rules_group)->getTaxCalculator();
            $order_slip->{'total_products_tax_' . $inc_or_ex_1} += $price * $quantity;
            if (in_array(Configuration::get('PS_ROUND_TYPE'), array(Order::ROUND_ITEM, Order::ROUND_LINE))) {
                if (!isset($total_products[$id_tax_rules_group])) {
                    $total_products[$id_tax_rules_group] = 0;
                } else {
                    if (!isset($total_products[$id_tax_rules_group . '_' . $id_address])) {
                        $total_products[$id_tax_rules_group . '_' . $id_address] = 0;
                    }
                }
            }
            $product_tax_incl_line = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price) * $quantity, _PS_PRICE_COMPUTE_PRECISION_);
            switch (Configuration::get('PS_ROUND_TYPE')) {
                case Order::ROUND_ITEM:
                    $product_tax_incl = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price), _PS_PRICE_COMPUTE_PRECISION_) * $quantity;
                    $total_products[$id_tax_rules_group] += $product_tax_incl;
                    break;
                case Order::ROUND_LINE:
                    $product_tax_incl = $product_tax_incl_line;
                    $total_products[$id_tax_rules_group] += $product_tax_incl;
                    break;
                case Order::ROUND_TOTAL:
                    $product_tax_incl = $product_tax_incl_line;
                    $total_products[$id_tax_rules_group . '_' . $id_address] += $price * $quantity;
                    break;
            }
            $product['unit_price_tax_' . $inc_or_ex_1] = $price;
            $product['unit_price_tax_' . $inc_or_ex_2] = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price), _PS_PRICE_COMPUTE_PRECISION_);
            $product['total_price_tax_' . $inc_or_ex_1] = Tools::ps_round($price * $quantity, _PS_PRICE_COMPUTE_PRECISION_);
            $product['total_price_tax_' . $inc_or_ex_2] = Tools::ps_round($product_tax_incl, _PS_PRICE_COMPUTE_PRECISION_);
            $product['product_id'] = $order_detail->product_id;
        }
        unset($product);
        foreach ($total_products as $key => $price) {
            if (Configuration::get('PS_ROUND_TYPE') == Order::ROUND_TOTAL) {
                $tmp = explode('_', $key);
                $address = Address::initialize((int) $tmp[1], true);
                $tax_calculator = TaxManagerFactory::getManager($address, $tmp[0])->getTaxCalculator();
                $order_slip->{'total_products_tax_' . $inc_or_ex_2} += Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price), _PS_PRICE_COMPUTE_PRECISION_);
            } else {
                $order_slip->{'total_products_tax_' . $inc_or_ex_2} += $price;
            }
        }
        $order_slip->{'total_products_tax_' . $inc_or_ex_2} -= (double) $amount && !$amount_choosen ? (double) $amount : 0;
        $order_slip->amount = $amount_choosen ? (double) $amount : $order_slip->{'total_products_tax_' . $inc_or_ex_1};
        $order_slip->shipping_cost_amount = $order_slip->{'total_shipping_tax_' . $inc_or_ex_1};
        if ((double) $amount && !$amount_choosen) {
            $order_slip->order_slip_type = 1;
        }
        if ((double) $amount && $amount_choosen || $order_slip->shipping_cost_amount > 0) {
            $order_slip->order_slip_type = 2;
        }
        if (!$order_slip->add()) {
            return false;
        }
        $res = true;
        $param = array();
        $param['MerchantOrderID'] = $order->id;
        $prefix = _DB_PREFIX_;
        $i = 0;
        foreach ($product_list as $product) {
            $res &= $order_slip->addProductOrderSlip($product);
            $order_item_detail = new OrderDetail((int) $product['id_order_detail']);
            $sql = 'UPDATE `' . $prefix . 'stock_available` set
					`quantity` = `quantity` + ' . $product['quantity'] . '
					where `id_product` = ' . $product['product_id'] . ' and
					`id_product_attribute` = 0
					';
            //Db::getInstance()->Execute($sql);
            if ($order_item_detail->product_attribute_id > 0) {
                $sql = 'UPDATE `' . $prefix . 'stock_available` set
						`quantity` = `quantity` + ' . $product['quantity'] . '
						where `id_product` = ' . $product['product_id'] . ' and
						`id_product_attribute` = ' . $order_item_detail->product_attribute_id . '
						';
                //Db::getInstance()->Execute($sql);
            }
            $date = date('Y-m-d');
            $sql = 'UPDATE `' . $prefix . 'product_sale` set
					`quantity` = `quantity` - ' . $product['quantity'] . ',
					`sale_nbr` = `sale_nbr` - ' . $product['quantity'] . ',
					`date_upd` = ' . $date . '
					where `id_product` = ' . $product['product_id'] . '
					';
            //Db::getInstance()->Execute($sql);
            $param['items'][$i]['MerchantOrderItemID'] = $product['product_id'];
            $param['items'][$i]['Principal'] = $product['total_price_tax_incl'];
            $param['items'][$i]['Shipping'] = 0;
            $param['items'][$i]['Tax'] = 0;
            $param['items'][$i]['ShippingTax'] = 0;
            $param['items'][$i]['quantity'] = $product['quantity'];
            $i++;
        }
        $refund = new Pwapresta();
        $refund->pwa_refund_feed($param);
        return $res;
    }
Пример #23
0
 public static function createPartialOrderSlip($order, $amount, $shipping_cost_amount, $order_detail_list)
 {
     $currency = new Currency($order->id_currency);
     $orderSlip = new OrderSlip();
     $orderSlip->id_customer = (int) $order->id_customer;
     $orderSlip->id_order = (int) $order->id;
     $orderSlip->amount = (double) $amount;
     $orderSlip->shipping_cost = false;
     $orderSlip->shipping_cost_amount = (double) $shipping_cost_amount;
     $orderSlip->conversion_rate = $currency->conversion_rate;
     $orderSlip->partial = 1;
     if (!$orderSlip->add()) {
         return false;
     }
     $orderSlip->addPartialSlipDetail($order_detail_list);
     return true;
 }
Пример #24
0
<?php

/* SSL Management */
$useSSL = true;
include dirname(__FILE__) . '/config/config.inc.php';
include dirname(__FILE__) . '/init.php';
if (!$cookie->isLogged()) {
    Tools::redirect('authentication.php?back=history.php');
}
/* Js files call */
$js_files = array(__PS_BASE_URI__ . 'js/jquery/jquery.scrollto.js', _THEME_JS_DIR_ . 'history.js');
$smarty->assign('ordersSlip', OrderSlip::getOrdersSlip(intval($cookie->id_customer)));
include dirname(__FILE__) . '/header.php';
$smarty->display(_PS_THEME_DIR_ . 'order-slip.tpl');
include dirname(__FILE__) . '/footer.php';