コード例 #1
0
 /**
  * @param OrderInvoice $order_invoice
  * @param $smarty
  * @throws PrestaShopException
  */
 public function __construct(OrderInvoice $order_invoice, $smarty)
 {
     $this->order_invoice = $order_invoice;
     $this->order = new Order((int) $this->order_invoice->id_order);
     $this->smarty = $smarty;
     // header informations
     $this->date = Tools::displayDate($order_invoice->date_add);
     $id_lang = Context::getContext()->language->id;
     $this->title = $order_invoice->getInvoiceNumberFormatted($id_lang);
     $this->shop = new Shop((int) $this->order->id_shop);
 }
コード例 #2
0
 /**
  * @param OrderInvoice $order_invoice
  * @param $smarty
  * @throws PrestaShopException
  */
 public function __construct(OrderInvoice $order_invoice, $smarty, $bulk_mode = false)
 {
     $this->order_invoice = $order_invoice;
     $this->order = new Order((int) $this->order_invoice->id_order);
     $this->smarty = $smarty;
     // If shop_address is null, then update it with current one.
     // But no DB save required here to avoid massive updates for bulk PDF generation case.
     // (DB: bug fixed in 1.6.1.1 with upgrade SQL script to avoid null shop_address in old orderInvoices)
     if (!isset($this->order_invoice->shop_address) || !$this->order_invoice->shop_address) {
         $this->order_invoice->shop_address = OrderInvoice::getCurrentFormattedShopAddress((int) $this->order->id_shop);
         if (!$bulk_mode) {
             OrderInvoice::fixAllShopAddresses();
         }
     }
     // header informations
     $this->date = Tools::displayDate($order_invoice->date_add);
     $id_lang = Context::getContext()->language->id;
     $this->title = $order_invoice->getInvoiceNumberFormatted($id_lang);
     $this->shop = new Shop((int) $this->order->id_shop);
 }
コード例 #3
0
 public function postProcess()
 {
     if (Tools::isSubmit('submitAdddelivery')) {
         if (!Validate::isDate(Tools::getValue('date_from'))) {
             $this->errors[] = Tools::displayError('Invalid \'from\' date');
         }
         if (!Validate::isDate(Tools::getValue('date_to'))) {
             $this->errors[] = Tools::displayError('Invalid \'to\' date');
         }
         if (!count($this->errors)) {
             if (count(OrderInvoice::getByDeliveryDateInterval(Tools::getValue('date_from'), Tools::getValue('date_to')))) {
                 Tools::redirectAdmin($this->context->link->getAdminLink('AdminPdf') . '&submitAction=generateDeliverySlipsPDF&date_from=' . urlencode(Tools::getValue('date_from')) . '&date_to=' . urlencode(Tools::getValue('date_to')));
             } else {
                 $this->errors[] = Tools::displayError('No delivery slip was found for this period.');
             }
         }
     } else {
         parent::postProcess();
     }
 }
コード例 #4
0
 /**
  * @param OrderInvoice $order_invoice
  * @param $smarty
  * @throws PrestaShopException
  */
 public function __construct(OrderInvoice $order_invoice, $smarty, $bulk_mode = false)
 {
     $this->order_invoice = $order_invoice;
     $this->order = new Order($this->order_invoice->id_order);
     $this->smarty = $smarty;
     // If shop_address is null, then update it with current one.
     // But no DB save required here to avoid massive updates for bulk PDF generation case.
     // (DB: bug fixed in 1.6.1.1 with upgrade SQL script to avoid null shop_address in old orderInvoices)
     if (!isset($this->order_invoice->shop_address) || !$this->order_invoice->shop_address) {
         $this->order_invoice->shop_address = OrderInvoice::getCurrentFormattedShopAddress((int) $this->order->id_shop);
         if (!$bulk_mode) {
             OrderInvoice::fixAllShopAddresses();
         }
     }
     // header informations
     $this->date = Tools::displayDate($order_invoice->date_add);
     $prefix = Configuration::get('PS_DELIVERY_PREFIX', Context::getContext()->language->id);
     $this->title = sprintf(HTMLTemplateDeliverySlip::l('%1$s%2$06d'), $prefix, $this->order_invoice->delivery_number);
     // footer informations
     $this->shop = new Shop((int) $this->order->id_shop);
 }
コード例 #5
0
 /**
  * @param OrderInvoice $order_invoice
  * @param float $value_tax_incl
  * @param float $value_tax_excl
  */
 protected function applyDiscountOnInvoice($order_invoice, $value_tax_incl, $value_tax_excl)
 {
     // Update OrderInvoice
     $order_invoice->total_discount_tax_incl += $value_tax_incl;
     $order_invoice->total_discount_tax_excl += $value_tax_excl;
     $order_invoice->total_paid_tax_incl -= $value_tax_incl;
     $order_invoice->total_paid_tax_excl -= $value_tax_excl;
     $order_invoice->update();
 }
コード例 #6
0
ファイル: dateofdelivery.php プロジェクト: FAVHYAN/a3workout
 /**
  * Displays the delivery dates on the invoice
  *
  * @param $params contains an instance of OrderInvoice
  * @return string
  *
  */
 public function hookDisplayPDFInvoice($params)
 {
     $order_invoice = $params['object'];
     if (!$order_invoice instanceof OrderInvoice) {
         return;
     }
     $order = new Order((int) $order_invoice->id_order);
     $oos = false;
     // For out of stock management
     foreach ($order->getProducts() as $product) {
         if ($product['product_quantity_in_stock'] < 1) {
             $oos = true;
         }
     }
     $id_carrier = (int) OrderInvoice::getCarrierId($order_invoice->id);
     $return = '';
     if ($datesDelivery = $this->_getDatesOfDelivery($id_carrier, $oos, $order_invoice->date_add)) {
         $return = sprintf($this->l('Approximate date of delivery is between %1$s and %2$s'), $datesDelivery[0], $datesDelivery[1]);
     }
     return $return;
 }
コード例 #7
0
 public function postProcess()
 {
     if (Tools::getValue('submitAddinvoice_date')) {
         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)) {
             if (count(OrderInvoice::getByDateInterval(Tools::getValue('date_from'), Tools::getValue('date_to')))) {
                 Tools::redirectAdmin($this->context->link->getAdminLink('AdminPdf') . '&submitAction=generateInvoicesPDF&date_from=' . urlencode(Tools::getValue('date_from')) . '&date_to=' . urlencode(Tools::getValue('date_to')));
             }
             $this->errors[] = $this->l('No invoice has been found for this period.');
         }
     } else {
         if (Tools::isSubmit('submitAddinvoice_status')) {
             if (!is_array($status_array = Tools::getValue('id_order_state')) || !count($status_array)) {
                 $this->errors[] = $this->l('You must select at least one order status.');
             } else {
                 foreach ($status_array as $id_order_state) {
                     if (count(OrderInvoice::getByStatus((int) $id_order_state))) {
                         Tools::redirectAdmin($this->context->link->getAdminLink('AdminPdf') . '&submitAction=generateInvoicesPDF2&id_order_state=' . implode('-', $status_array));
                     }
                 }
                 $this->errors[] = $this->l('No invoice has been found for this status.');
             }
         } else {
             parent::postProcess();
         }
     }
 }
コード例 #8
0
ファイル: Order.php プロジェクト: dev-lav/htdocs
    /**
     * This method allows to generate first invoice of the current order
     */
    public function setInvoice($use_existing_payment = false)
    {
        if (!$this->hasInvoice()) {
            $order_invoice = new OrderInvoice();
            $order_invoice->id_order = $this->id;
            $order_invoice->number = 0;
            $address = new Address((int) $this->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
            $carrier = new Carrier((int) $this->id_carrier);
            $tax_calculator = $carrier->getTaxCalculator($address);
            $order_invoice->total_discount_tax_excl = $this->total_discounts_tax_excl;
            $order_invoice->total_discount_tax_incl = $this->total_discounts_tax_incl;
            $order_invoice->total_paid_tax_excl = $this->total_paid_tax_excl;
            $order_invoice->total_paid_tax_incl = $this->total_paid_tax_incl;
            $order_invoice->total_products = $this->total_products;
            $order_invoice->total_products_wt = $this->total_products_wt;
            $order_invoice->total_shipping_tax_excl = $this->total_shipping_tax_excl;
            $order_invoice->total_shipping_tax_incl = $this->total_shipping_tax_incl;
            $order_invoice->shipping_tax_computation_method = $tax_calculator->computation_method;
            $order_invoice->total_wrapping_tax_excl = $this->total_wrapping_tax_excl;
            $order_invoice->total_wrapping_tax_incl = $this->total_wrapping_tax_incl;
            // Save Order invoice
            $order_invoice->add();
            $this->setLastInvoiceNumber($order_invoice->id, $this->id_shop);
            $order_invoice->saveCarrierTaxCalculator($tax_calculator->getTaxesAmount($order_invoice->total_shipping_tax_excl));
            // Update order_carrier
            $id_order_carrier = Db::getInstance()->getValue('
				SELECT `id_order_carrier`
				FROM `' . _DB_PREFIX_ . 'order_carrier`
				WHERE `id_order` = ' . (int) $order_invoice->id_order . '
				AND (`id_order_invoice` IS NULL OR `id_order_invoice` = 0)');
            if ($id_order_carrier) {
                $order_carrier = new OrderCarrier($id_order_carrier);
                $order_carrier->id_order_invoice = (int) $order_invoice->id;
                $order_carrier->update();
            }
            // Update order detail
            Db::getInstance()->execute('
				UPDATE `' . _DB_PREFIX_ . 'order_detail`
				SET `id_order_invoice` = ' . (int) $order_invoice->id . '
				WHERE `id_order` = ' . (int) $order_invoice->id_order);
            // Update order payment
            if ($use_existing_payment) {
                $id_order_payments = Db::getInstance()->executeS('
					SELECT DISTINCT op.id_order_payment 
					FROM `' . _DB_PREFIX_ . 'order_payment` op
					INNER JOIN `' . _DB_PREFIX_ . 'orders` o ON (o.reference = op.order_reference)
					LEFT JOIN `' . _DB_PREFIX_ . 'order_invoice_payment` oip ON (oip.id_order_payment = op.id_order_payment)					
					WHERE (oip.id_order != ' . (int) $order_invoice->id_order . ' OR oip.id_order IS NULL) AND o.id_order = ' . (int) $order_invoice->id_order);
                if (count($id_order_payments)) {
                    foreach ($id_order_payments as $order_payment) {
                        Db::getInstance()->execute('
							INSERT INTO `' . _DB_PREFIX_ . 'order_invoice_payment`
							SET
								`id_order_invoice` = ' . (int) $order_invoice->id . ',
								`id_order_payment` = ' . (int) $order_payment['id_order_payment'] . ',
								`id_order` = ' . (int) $order_invoice->id_order);
                    }
                    // Clear cache
                    Cache::clean('order_invoice_paid_*');
                }
            }
            // Update order cart rule
            Db::getInstance()->execute('
				UPDATE `' . _DB_PREFIX_ . 'order_cart_rule`
				SET `id_order_invoice` = ' . (int) $order_invoice->id . '
				WHERE `id_order` = ' . (int) $order_invoice->id_order);
            // Keep it for backward compatibility, to remove on 1.6 version
            $this->invoice_date = $order_invoice->date_add;
            $this->invoice_number = $this->getInvoiceNumber($order_invoice->id);
            $this->update();
        }
    }
コード例 #9
0
 function getTag($tag)
 {
     $value = null;
     $value = parent::getTag($tag);
     return $value;
 }
コード例 #10
0
ファイル: OrderInvoice.php プロジェクト: jpodracky/dogs
 /**
  * @since 1.5
  * @param $id_order_invoice
  */
 public static function getCarrier($id_order_invoice)
 {
     $carrier = false;
     if ($id_carrier = OrderInvoice::getCarrierId($id_order_invoice)) {
         $carrier = new Carrier((int) $id_carrier);
     }
     return $carrier;
 }
コード例 #11
0
ファイル: OrderDetail.php プロジェクト: nmardones/PrestaShop
 /**
  * Set the additional shipping information
  *
  * @param Order $order
  * @param $product
  */
 public function setShippingCost(Order $order, $product)
 {
     $tax_rate = 0;
     $carrier = OrderInvoice::getCarrier((int) $this->id_order_invoice);
     if (isset($carrier) && Validate::isLoadedObject($carrier)) {
         $tax_rate = $carrier->getTaxesRate(new Address((int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
     }
     $this->total_shipping_price_tax_excl = (double) $product['additional_shipping_cost'];
     $this->total_shipping_price_tax_incl = (double) ($this->total_shipping_price_tax_excl * (1 + $tax_rate / 100));
     $this->total_shipping_price_tax_incl = Tools::ps_round($this->total_shipping_price_tax_incl, 2);
 }
コード例 #12
0
 public function processGenerateDeliverySlipsPDF()
 {
     $order_invoice_collection = OrderInvoice::getByDeliveryDateInterval(Tools::getValue('date_from'), Tools::getValue('date_to'));
     if (!count($order_invoice_collection)) {
         die($this->trans('No invoice was found.', array(), 'Admin.OrdersCustomers.Notification'));
     }
     $this->generatePDF($order_invoice_collection, PDF::TEMPLATE_DELIVERY_SLIP);
 }
コード例 #13
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
     $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) {
             // Update quantity of each customization
             Db::getInstance()->update('customization', array('quantity' => (int) $qty), 'id_customization = ' . (int) $id_customization);
             // Calculate the real quantity of the product
             $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);
     // 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;
     $ppropertiessmartprice_hook1 = null;
     // 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 = 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;
     }
     // 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 - PP::resolveQty($order_detail->product_quantity, $order_detail->product_quantity_fractional), $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_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'] = '--';
     }
     // 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')))));
 }
コード例 #14
0
ファイル: Order.php プロジェクト: rrameshsat/Prestashop
    /**
     * This method allows to generate first invoice of the current order
     */
    public function setInvoice($use_existing_payment = false)
    {
        if (!$this->hasInvoice()) {
            $order_invoice = new OrderInvoice();
            $order_invoice->id_order = $this->id;
            $order_invoice->number = Configuration::get('PS_INVOICE_START_NUMBER');
            // If invoice start number has been set, you clean the value of this configuration
            if ($order_invoice->number) {
                Configuration::updateValue('PS_INVOICE_START_NUMBER', false);
            } else {
                $order_invoice->number = Order::getLastInvoiceNumber() + 1;
            }
            $invoice_address = new Address((int) $this->id_address_invoice);
            $carrier = new Carrier((int) $this->id_carrier);
            $tax_calculator = $carrier->getTaxCalculator($invoice_address);
            $order_invoice->total_discount_tax_excl = $this->total_discounts_tax_excl;
            $order_invoice->total_discount_tax_incl = $this->total_discounts_tax_incl;
            $order_invoice->total_paid_tax_excl = $this->total_paid_tax_excl;
            $order_invoice->total_paid_tax_incl = $this->total_paid_tax_incl;
            $order_invoice->total_products = $this->total_products;
            $order_invoice->total_products_wt = $this->total_products_wt;
            $order_invoice->total_shipping_tax_excl = $this->total_shipping_tax_excl;
            $order_invoice->total_shipping_tax_incl = $this->total_shipping_tax_incl;
            $order_invoice->shipping_tax_computation_method = $tax_calculator->computation_method;
            $order_invoice->total_wrapping_tax_excl = $this->total_wrapping_tax_excl;
            $order_invoice->total_wrapping_tax_incl = $this->total_wrapping_tax_incl;
            // Save Order invoice
            $order_invoice->add();
            $order_invoice->saveCarrierTaxCalculator($tax_calculator->getTaxesAmount($order_invoice->total_shipping_tax_excl));
            // Update order_carrier
            $id_order_carrier = Db::getInstance()->getValue('
				SELECT `id_order_carrier`
				FROM `' . _DB_PREFIX_ . 'order_carrier`
				WHERE `id_order` = ' . (int) $order_invoice->id_order . '
				AND (`id_order_invoice` IS NULL OR `id_order_invoice` = 0)');
            if ($id_order_carrier) {
                $order_carrier = new OrderCarrier($id_order_carrier);
                $order_carrier->id_order_invoice = (int) $order_invoice->id;
                $order_carrier->update();
            }
            // Update order detail
            Db::getInstance()->execute('
				UPDATE `' . _DB_PREFIX_ . 'order_detail`
				SET `id_order_invoice` = ' . (int) $order_invoice->id . '
				WHERE `id_order` = ' . (int) $order_invoice->id_order);
            // Update order payment
            if ($use_existing_payment) {
                $id_order_payments = Db::getInstance()->executeS('
					SELECT op.id_order_payment 
					FROM `' . _DB_PREFIX_ . 'order_payment` op
					INNER JOIN `' . _DB_PREFIX_ . 'orders` o ON (o.reference = op.order_reference)
					LEFT JOIN `' . _DB_PREFIX_ . 'order_invoice_payment` oip ON (oip.id_order_payment = op.id_order_payment)					
					WHERE oip.id_order_payment IS NULL AND o.id_order = ' . (int) $order_invoice->id_order);
                if (count($id_order_payments)) {
                    foreach ($id_order_payments as $order_payment) {
                        Db::getInstance()->execute('
							INSERT INTO `' . _DB_PREFIX_ . 'order_invoice_payment`
							SET
								`id_order_invoice` = ' . (int) $order_invoice->id . ',
								`id_order_payment` = ' . (int) $order_payment['id_order_payment'] . ',
								`id_order` = ' . (int) $order_invoice->id_order);
                    }
                }
            }
            // Update order cart rule
            Db::getInstance()->execute('
				UPDATE `' . _DB_PREFIX_ . 'order_cart_rule`
				SET `id_order_invoice` = ' . (int) $order_invoice->id . '
				WHERE `id_order` = ' . (int) $order_invoice->id_order);
            // Keep it for backward compatibility, to remove on 1.6 version
            $this->invoice_date = $order_invoice->date_add;
            $this->invoice_number = $order_invoice->number;
            $this->update();
        }
    }
コード例 #15
0
 public function processChangeCarrier()
 {
     $id_order = (int) Tools::getValue('id_o');
     $id_new_carrier = (int) Tools::getValue('new_carrier');
     $price_incl = (double) Tools::getValue('pr_incl');
     $price_excl = (double) Tools::getValue('pr_excl');
     $order = new Order($id_order);
     $result = array();
     $result['error'] = '';
     if ($id_new_carrier == 0) {
         $result['error'] = $this->l('Error: cannot select carrier');
     } else {
         if ($order->id < 1) {
             $result['error'] = $this->l('Error: cannot find order');
         } else {
             $total_carrierwt = (double) $order->total_products_wt + (double) $price_incl;
             $total_carrier = (double) $order->total_products + (double) $price_excl;
             $order->total_paid = (double) $total_carrierwt;
             $order->total_paid_tax_incl = (double) $total_carrierwt;
             $order->total_paid_tax_excl = (double) $total_carrier;
             $order->total_paid_real = (double) $total_carrierwt;
             $order->total_shipping = (double) $price_incl;
             $order->total_shipping_tax_excl = (double) $price_excl;
             $order->total_shipping_tax_incl = (double) $price_incl;
             $order->carrier_tax_rate = (double) $order->carrier_tax_rate;
             $order->id_carrier = (int) $id_new_carrier;
             if (!$order->update()) {
                 $result['error'] = $this->l('Error: cannot update order');
                 $result['status'] = false;
             } else {
                 if ($order->invoice_number > 0) {
                     $order_invoice = new OrderInvoice($order->invoice_number);
                     $order_invoice->total_paid_tax_incl = (double) $total_carrierwt;
                     $order_invoice->total_paid_tax_excl = (double) $total_carrier;
                     $order_invoice->total_shipping_tax_excl = (double) $price_excl;
                     $order_invoice->total_shipping_tax_incl = (double) $price_incl;
                     if (!$order_invoice->update()) {
                         $result['error'] = $this->l('Error: cannot update order invoice');
                         $result['status'] = false;
                     }
                 }
                 $id_order_carrier = Db::getInstance()->getValue('
                         SELECT `id_order_carrier`
                         FROM `' . _DB_PREFIX_ . 'order_carrier`
                         WHERE `id_order` = ' . (int) $order->id);
                 if ($id_order_carrier) {
                     $order_carrier = new OrderCarrier($id_order_carrier);
                     $order_carrier->id_carrier = $order->id_carrier;
                     $order_carrier->shipping_cost_tax_excl = (double) $price_excl;
                     $order_carrier->shipping_cost_tax_incl = (double) $price_incl;
                     if (!$order_carrier->update()) {
                         $result['error'] = $this->l('Error: cannot update order carrier');
                         $result['status'] = false;
                     }
                 }
                 $result['status'] = true;
             }
         }
     }
     if ($result['status']) {
         $this->sendCarrierToYandex($order);
     }
     return $result;
 }
コード例 #16
0
 /**
  * This method allows to generate first delivery slip of the current order
  */
 public function setDeliverySlip()
 {
     if (!$this->hasInvoice()) {
         $order_invoice = new OrderInvoice();
         $order_invoice->id_order = $this->id;
         $order_invoice->number = 0;
         $order_invoice->add();
         $this->delivery_date = $order_invoice->date_add;
         $this->delivery_number = $this->getDeliveryNumber($order_invoice->id);
         $this->update();
     }
 }
コード例 #17
0
 public function ajaxProcessDeleteProductLine()
 {
     $res = true;
     $order_detail = new OrderDetail(Tools::getValue('id_order_detail'));
     $order = new Order(Tools::getValue('id_order'));
     $this->doDeleteProductLineValidation($order_detail, $order);
     // Update OrderInvoice of this OrderDetail
     if ($order_detail->id_order_invoice != 0) {
         $order_invoice = new OrderInvoice($order_detail->id_order_invoice);
         $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_invoice->total_products -= $order_detail->total_price_tax_excl;
         $order_invoice->total_products_wt -= $order_detail->total_price_tax_incl;
         $res &= $order_invoice->update();
     }
     // Update Order
     $order->total_paid -= $order_detail->total_price_tax_incl;
     $order->total_paid_tax_incl -= $order_detail->total_price_tax_incl;
     $order->total_paid_tax_excl -= $order_detail->total_price_tax_excl;
     $order->total_products -= $order_detail->total_price_tax_excl;
     $order->total_products_wt -= $order_detail->total_price_tax_incl;
     $res &= $order->update();
     // Delete OrderDetail
     $res &= $order_detail->delete();
     if (!$res) {
         die(Tools::jsonEncode(array('result' => $res, 'error' => Tools::displayError('Error occurred on deletion of this product line'))));
     }
     // Get invoices collection
     $invoice_collection = $order->getInvoicesCollection();
     $invoice_array = array();
     foreach ($invoice_collection as $invoice) {
         $invoice->name = $invoice->getInvoiceNumberFormatted(Context::getContext()->language->id);
         $invoice_array[] = $invoice;
     }
     // Assign to smarty informations in order to show the new product line
     $this->context->smarty->assign(array('order' => $order, 'currency' => new Currency($order->id_currency), 'invoices_collection' => $invoice_collection, 'current_id_lang' => Context::getContext()->language->id, 'link' => Context::getContext()->link, 'current_index' => self::$currentIndex));
     $this->sendChangedNotification($order);
     die(Tools::jsonEncode(array('result' => $res, 'order' => $order, 'invoices' => $invoice_array, 'documents_html' => $this->createTemplate('_documents.tpl')->fetch(), 'shipping_html' => $this->createTemplate('_shipping.tpl')->fetch())));
 }
コード例 #18
0
 public function ajaxProcessDeleteProductLine()
 {
     $res = true;
     $order_detail = new OrderDetail((int) Tools::getValue('id_order_detail'));
     $order = new Order((int) Tools::getValue('id_order'));
     $this->doDeleteProductLineValidation($order_detail, $order);
     // Update OrderInvoice of this OrderDetail
     if ($order_detail->id_order_invoice != 0) {
         $order_invoice = new OrderInvoice($order_detail->id_order_invoice);
         $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_invoice->total_products -= $order_detail->total_price_tax_excl;
         $order_invoice->total_products_wt -= $order_detail->total_price_tax_incl;
         $res &= $order_invoice->update();
     }
     // Update Order
     $order->total_paid -= $order_detail->total_price_tax_incl;
     $order->total_paid_tax_incl -= $order_detail->total_price_tax_incl;
     $order->total_paid_tax_excl -= $order_detail->total_price_tax_excl;
     $order->total_products -= $order_detail->total_price_tax_excl;
     $order->total_products_wt -= $order_detail->total_price_tax_incl;
     $res &= $order->update();
     // Reinject quantity in stock
     $this->reinjectQuantity($order_detail, $order_detail->product_quantity);
     // Delete OrderDetail
     $res &= $order_detail->delete();
     // 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);
         }
     }
     if (!$res) {
         die(Tools::jsonEncode(array('result' => $res, 'error' => Tools::displayError('An error occurred while attempting to delete the product line.'))));
     }
     // 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('order' => $order, 'currency' => new Currency($order->id_currency), 'invoices_collection' => $invoice_collection, 'current_id_lang' => Context::getContext()->language->id, 'link' => Context::getContext()->link, 'current_index' => self::$currentIndex));
     $this->sendChangedNotification($order);
     die(Tools::jsonEncode(array('result' => $res, 'order' => $order, 'invoices' => $invoice_array, 'documents_html' => $this->createTemplate('_documents.tpl')->fetch(), 'shipping_html' => $this->createTemplate('_shipping.tpl')->fetch())));
 }
コード例 #19
0
 public function processGenerateDeliverySlipsPDF()
 {
     $order_invoice_collection = OrderInvoice::getByDeliveryDateInterval(Tools::getValue('date_from'), Tools::getValue('date_to'));
     if (!count($order_invoice_collection)) {
         die(Tools::displayError('No invoice was found.'));
     }
     $this->generatePDF($order_invoice_collection, PDF::TEMPLATE_DELIVERY_SLIP);
 }
コード例 #20
0
 public function postProcess()
 {
     $this->context = Context::getContext();
     $this->query = trim(Tools::getValue('bo_query'));
     $searchType = (int) Tools::getValue('bo_search_type');
     /* Handle empty search field */
     if (!empty($this->query)) {
         if (!$searchType && strlen($this->query) > 1) {
             $this->searchFeatures();
         }
         /* Product research */
         if (!$searchType || $searchType == 1) {
             /* Handle product ID */
             if ($searchType == 1 && (int) $this->query && Validate::isUnsignedInt((int) $this->query)) {
                 if (($product = new Product($this->query)) && Validate::isLoadedObject($product)) {
                     Tools::redirectAdmin('index.php?tab=AdminProducts&id_product=' . (int) $product->id . '&addproduct' . '&token=' . Tools::getAdminTokenLite('AdminProducts'));
                 }
             }
             /* Normal catalog search */
             $this->searchCatalog();
         }
         /* Customer */
         if (!$searchType || $searchType == 2 || $searchType == 6) {
             if (!$searchType || $searchType == 2) {
                 /* Handle customer ID */
                 if ($searchType && (int) $this->query && Validate::isUnsignedInt((int) $this->query)) {
                     if (($customer = new Customer($this->query)) && Validate::isLoadedObject($customer)) {
                         Tools::redirectAdmin('index.php?tab=AdminCustomers&id_customer=' . (int) $customer->id . '&viewcustomer' . '&token=' . Tools::getAdminToken('AdminCustomers' . (int) Tab::getIdFromClassName('AdminCustomers') . (int) $this->context->employee->id));
                     }
                 }
                 /* Normal customer search */
                 $this->searchCustomer();
             }
             if ($searchType == 6) {
                 $this->searchIP();
             }
         }
         /* Order */
         if (!$searchType || $searchType == 3) {
             if (Validate::isUnsignedInt(trim($this->query)) && (int) $this->query && ($order = new Order((int) $this->query)) && Validate::isLoadedObject($order)) {
                 if ($searchType == 3) {
                     Tools::redirectAdmin('index.php?tab=AdminOrders&id_order=' . (int) $order->id . '&vieworder' . '&token=' . Tools::getAdminTokenLite('AdminOrders'));
                 } else {
                     $row = get_object_vars($order);
                     $row['id_order'] = $row['id'];
                     $customer = $order->getCustomer();
                     $row['customer'] = $customer->firstname . ' ' . $customer->lastname;
                     $order_state = $order->getCurrentOrderState();
                     $row['osname'] = $order_state->name[$this->context->language->id];
                     $this->_list['orders'] = array($row);
                 }
             } else {
                 $orders = Order::getByReference($this->query);
                 $nb_orders = count($orders);
                 if ($nb_orders == 1 && $searchType == 3) {
                     Tools::redirectAdmin('index.php?tab=AdminOrders&id_order=' . (int) $orders[0]->id . '&vieworder' . '&token=' . Tools::getAdminTokenLite('AdminOrders'));
                 } elseif ($nb_orders) {
                     $this->_list['orders'] = array();
                     foreach ($orders as $order) {
                         $row = get_object_vars($order);
                         $row['id_order'] = $row['id'];
                         $customer = $order->getCustomer();
                         $row['customer'] = $customer->firstname . ' ' . $customer->lastname;
                         $order_state = $order->getCurrentOrderState();
                         $row['osname'] = $order_state->name[$this->context->language->id];
                         $this->_list['orders'][] = $row;
                     }
                 } elseif ($searchType == 3) {
                     $this->errors[] = Tools::displayError('No order was found with this ID:') . ' ' . Tools::htmlentitiesUTF8($this->query);
                 }
             }
         }
         /* Invoices */
         if ($searchType == 4) {
             if (Validate::isOrderInvoiceNumber($this->query) && ($invoice = OrderInvoice::getInvoiceByNumber($this->query))) {
                 Tools::redirectAdmin($this->context->link->getAdminLink('AdminPdf') . '&submitAction=generateInvoicePDF&id_order=' . (int) $invoice->id_order);
             }
             $this->errors[] = Tools::displayError('No invoice was found with this ID:') . ' ' . Tools::htmlentitiesUTF8($this->query);
         }
         /* Cart */
         if ($searchType == 5) {
             if ((int) $this->query && Validate::isUnsignedInt((int) $this->query) && ($cart = new Cart($this->query)) && Validate::isLoadedObject($cart)) {
                 Tools::redirectAdmin('index.php?tab=AdminCarts&id_cart=' . (int) $cart->id . '&viewcart' . '&token=' . Tools::getAdminToken('AdminCarts' . (int) Tab::getIdFromClassName('AdminCarts') . (int) $this->context->employee->id));
             }
             $this->errors[] = Tools::displayError('No cart was found with this ID:') . ' ' . Tools::htmlentitiesUTF8($this->query);
         }
         /* IP */
         // 6 - but it is included in the customer block
         /* Module search */
         if (!$searchType || $searchType == 7) {
             /* Handle module name */
             if ($searchType == 7 && Validate::isModuleName($this->query) and ($module = Module::getInstanceByName($this->query)) && Validate::isLoadedObject($module)) {
                 Tools::redirectAdmin('index.php?tab=AdminModules&tab_module=' . $module->tab . '&module_name=' . $module->name . '&anchor=' . ucfirst($module->name) . '&token=' . Tools::getAdminTokenLite('AdminModules'));
             }
             /* Normal catalog search */
             $this->searchModule();
         }
     }
     $this->display = 'view';
 }
コード例 #21
0
ファイル: OrderInvoice.php プロジェクト: M03G/PrestaShop
 /**
  * This method is used to fix shop addresses that cannot be fixed during upgrade process
  * (because uses the whole environnement of PS classes that is not available during upgrade).
  * This method should execute once on an upgraded PrestaShop to fix all OrderInvoices in one shot.
  * This method is triggered once during a (non bulk) creation of a PDF from an OrderInvoice that is not fixed yet.
  *
  * @since 1.6.1.1
  */
 public static function fixAllShopAddresses()
 {
     $shop_ids = Shop::getShops(false, null, true);
     $db = Db::getInstance();
     foreach ($shop_ids as $id_shop) {
         $address = OrderInvoice::getCurrentFormattedShopAddress($id_shop);
         $escaped_address = $db->escape($address, true, true);
         $db->execute('UPDATE `' . _DB_PREFIX_ . 'order_invoice` INNER JOIN `' . _DB_PREFIX_ . 'orders` USING (`id_order`)
             SET `shop_address` = \'' . $escaped_address . '\' WHERE `shop_address` IS NULL AND `id_shop` = ' . $id_shop);
     }
 }