[+] BO : add new feature, Order edition
This commit is contained in:
+210
-29
@@ -91,13 +91,13 @@ class OrderCore extends ObjectModel
|
||||
/** @var float Total to pay tax excluded */
|
||||
public $total_paid_tax_excl;
|
||||
|
||||
/** @var float Total really paid */
|
||||
/** @var float Total really paid @deprecated 1.5.0.1 */
|
||||
public $total_paid_real;
|
||||
|
||||
/** @var float Products total */
|
||||
public $total_products;
|
||||
|
||||
/** @var float Products total tax excluded */
|
||||
/** @var float Products total tax included */
|
||||
public $total_products_wt;
|
||||
|
||||
/** @var float Shipping total */
|
||||
@@ -467,8 +467,14 @@ class OrderCore extends ObjectModel
|
||||
');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated 1.5.0.1
|
||||
* @see OrderInvoice::setProductPrices
|
||||
*/
|
||||
public function setProductPrices(&$row)
|
||||
{
|
||||
//Tools::displayAsDeprecated();
|
||||
$tax_calculator = OrderDetail::getTaxCalculatorStatic((int)$row['id_order_detail']);
|
||||
$row['tax_calculator'] = $tax_calculator;
|
||||
$row['tax_rate'] = $tax_calculator->getTotalRate();
|
||||
@@ -979,36 +985,50 @@ class OrderCore extends ObjectModel
|
||||
return ((int)(Configuration::get('PS_ORDER_RETURN')) == 1 AND (int)($this->getCurrentState()) == Configuration::get('PS_OS_DELIVERED') AND $this->getNumberOfDays());
|
||||
}
|
||||
|
||||
|
||||
public static function getLastInvoiceNumber()
|
||||
{
|
||||
return (int)Db::getInstance()->getValue('
|
||||
SELECT MAX(`invoice_number`) AS `invoice_number`
|
||||
FROM `'._DB_PREFIX_.'orders`');
|
||||
public static function getLastInvoiceNumber()
|
||||
{
|
||||
return Db::getInstance()->getValue('
|
||||
SELECT MAX(`number`)
|
||||
FROM `'._DB_PREFIX_.'order_invoice`
|
||||
');
|
||||
}
|
||||
|
||||
public function setInvoice()
|
||||
{
|
||||
$number = (int)Configuration::get('PS_INVOICE_START_NUMBER');
|
||||
if ($number)
|
||||
$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
|
||||
$number = '(SELECT `invoice_number`
|
||||
FROM (
|
||||
SELECT MAX(`invoice_number`) + 1 AS `invoice_number`
|
||||
FROM `'._DB_PREFIX_.'orders`)
|
||||
tmp )';
|
||||
// a way to avoid duplicate invoice number
|
||||
$order_invoice->number = self::getLastInvoiceNumber() + 1;
|
||||
|
||||
$order_invoice->total_discount_tax_excl = $this->total_discount_tax_excl;
|
||||
$order_invoice->total_discount_tax_incl = $this->total_discount_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->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();
|
||||
|
||||
// Update order_carrier
|
||||
Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'orders`
|
||||
SET `invoice_number` = '.$number.', `invoice_date` = \''.date('Y-m-d H:i:s').'\'
|
||||
WHERE `id_order` = '.(int)$this->id
|
||||
);
|
||||
$res = Db::getInstance()->getRow('
|
||||
SELECT `invoice_number`, `invoice_date`
|
||||
FROM `'._DB_PREFIX_.'orders`
|
||||
WHERE `id_order` = '.(int)$this->id
|
||||
);
|
||||
UPDATE `'._DB_PREFIX_.'order_carrier`
|
||||
SET `id_order_invoice` = '.(int)$order_invoice->id.'
|
||||
WHERE `id_order` = '.(int)$order_invoice->id_order);
|
||||
|
||||
// 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);
|
||||
|
||||
$this->invoice_date = $res['invoice_date'];
|
||||
$this->invoice_number = $res['invoice_number'];
|
||||
@@ -1070,8 +1090,14 @@ class OrderCore extends ObjectModel
|
||||
return (float)($result['weight']);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $id_invoice
|
||||
* @deprecated 1.5.0.1
|
||||
*/
|
||||
public static function getInvoice($id_invoice)
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT `invoice_number`, `id_order`
|
||||
FROM `'._DB_PREFIX_.'orders`
|
||||
@@ -1128,9 +1154,9 @@ class OrderCore extends ObjectModel
|
||||
$history->id_employee = (int)$id_employee;
|
||||
$history->changeIdOrderState((int)$id_order_state, (int)$this->id);
|
||||
$res = Db::getInstance()->getRow('
|
||||
SELECT `invoice_number`, `invoice_date`, `delivery_number`, `delivery_date`
|
||||
FROM `'._DB_PREFIX_.'orders`
|
||||
WHERE `id_order` = '.(int)$this->id);
|
||||
SELECT `invoice_number`, `invoice_date`, `delivery_number`, `delivery_date`
|
||||
FROM `'._DB_PREFIX_.'orders`
|
||||
WHERE `id_order` = '.(int)$this->id);
|
||||
$this->invoice_date = $res['invoice_date'];
|
||||
$this->invoice_number = $res['invoice_number'];
|
||||
$this->delivery_date = $res['delivery_date'];
|
||||
@@ -1156,6 +1182,7 @@ class OrderCore extends ObjectModel
|
||||
|
||||
/**
|
||||
* This method return the ID of the previous order
|
||||
* @since 1.5.0.1
|
||||
* @return int
|
||||
*/
|
||||
public function getPreviousOrderId()
|
||||
@@ -1169,6 +1196,7 @@ class OrderCore extends ObjectModel
|
||||
|
||||
/**
|
||||
* This method return the ID of the next order
|
||||
* @since 1.5.0.1
|
||||
* @return int
|
||||
*/
|
||||
public function getNextOrderId()
|
||||
@@ -1243,9 +1271,162 @@ class OrderCore extends ObjectModel
|
||||
WHERE od.`id_order` = '.(int)$this->id.'
|
||||
AND od.`tax_computation_method` = '.(int)TaxCalculator::ONE_AFTER_ANOTHER_METHOD
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allows to get all Order Payment for the current order
|
||||
* @since 1.5.0.1
|
||||
* @return array Collection of Order Payment
|
||||
*/
|
||||
public function getOrderPaymentCollection()
|
||||
{
|
||||
$order_payment = Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'order_payment`
|
||||
WHERE `id_order` = '.(int)$this->id);
|
||||
return ObjectModel::hydrateCollection('OrderPayment', $order_payment);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* This method allows to add a payment to the current order
|
||||
* @since 1.5.0.1
|
||||
* @param float $amount_paid
|
||||
* @param string $payment_method
|
||||
* @param string $payment_transaction_id
|
||||
* @param Currency $currency
|
||||
* @param string $date
|
||||
* @return bool
|
||||
*/
|
||||
public function addOrderPayment($amount_paid, $payment_method = null, $payment_transaction_id = null, $currency = null, $date = null)
|
||||
{
|
||||
$order_payment = new OrderPayment();
|
||||
$order_payment->id_order = $this->id;
|
||||
$order_payment->id_currency = ($currency ? $currency->id : $this->id_currency);
|
||||
// we kept the currency rate for historization reasons
|
||||
$order_payment->conversion_rate = ($currency ? $currency->conversion_rate : 1);
|
||||
// if payment_method is define, we used this
|
||||
$order_payment->payment_method = ($payment_method ? $payment_method : $this->payment);
|
||||
$order_payment->transacation_id = $payment_transaction_id;
|
||||
$order_payment->amount = $amount_paid;
|
||||
$order_payment->date_add = ($date ? $date : null);
|
||||
|
||||
// Update total_paid_real value for backward compatibility reasons
|
||||
if ($order_payment->id_currency == $this->id_currency)
|
||||
$this->total_paid_real += $order_payment->amount;
|
||||
else
|
||||
$this->total_paid_real += Tools::ps_round(Tools::convertPrice($order_payment->amount, $order_payment->id_currency, false), 2);
|
||||
|
||||
return $order_payment->add() && $this->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the correct product taxes breakdown.
|
||||
*
|
||||
* Get all documents linked to the current order
|
||||
*
|
||||
* @since 1.5.0.1
|
||||
* @return array
|
||||
*/
|
||||
public function getDocuments()
|
||||
{
|
||||
// TODO
|
||||
$invoices = $this->getInvoicesCollection();
|
||||
|
||||
return $invoices;
|
||||
}
|
||||
|
||||
public function getReturn()
|
||||
{
|
||||
return OrderReturn::getOrdersReturn($this->id_customer, $this->id);
|
||||
}
|
||||
|
||||
public function getShipping()
|
||||
{
|
||||
$shipping = Db::getInstance()->ExecuteS('
|
||||
SELECT DISTINCT oc.`id_order_invoice`, oc.`weight`, oc.`shipping_cost_tax_excl`, oc.`shipping_cost_tax_incl`, c.`url`, oc.`id_carrier`, c.`name` as `state_name`, oc.`date_add`, "Delivery" as `type`, "true" as `can_edit`, oc.`tracking_number`
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_history` oh
|
||||
ON (o.`id_order` = oh.`id_order`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_carrier` oc
|
||||
ON (o.`id_order` = oc.`id_order`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'carrier` c
|
||||
ON (oc.`id_carrier` = c.`id_carrier`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl
|
||||
ON (oh.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)Context::getContext()->language->id.')
|
||||
WHERE o.`id_order` = '.(int)$this->id);
|
||||
return $shipping;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get all invoices for the current order
|
||||
* @since 1.5.0.1
|
||||
* @return array Collection of Order invoice
|
||||
*/
|
||||
public function getInvoicesCollection()
|
||||
{
|
||||
$invoices = Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'order_invoice`
|
||||
WHERE `id_order` = '.(int)$this->id);
|
||||
return ObjectModel::hydrateCollection('OrderInvoice', $invoices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total paid
|
||||
*
|
||||
* @since 1.5.0.1
|
||||
* @param Currency $currency currency used for the total paid of the current order
|
||||
* @return float amount in the $currency
|
||||
*/
|
||||
public function getTotalPaid($currency = null)
|
||||
{
|
||||
if (!$currency)
|
||||
$currency = new Currency($this->id_currency);
|
||||
|
||||
$total = 0;
|
||||
// Retrieve all payments
|
||||
$payments = $this->getOrderPaymentCollection();
|
||||
foreach($payments as $payment)
|
||||
{
|
||||
if ($payment->id_currency == $currency->id)
|
||||
$total += $payment->amount;
|
||||
else
|
||||
{
|
||||
$amount = Tools::convertPrice($payment->amount, $payment->id_currency, false);
|
||||
if ($currency->id == Configuration::get('PS_DEFAULT_CURRENCY'))
|
||||
$total += $amount;
|
||||
else
|
||||
$total += Tool::convertPrice($amount, $currency->id, true);
|
||||
}
|
||||
}
|
||||
|
||||
return Tools::ps_round($total, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* This method allows to change the shipping cost of the current order
|
||||
* @since 1.5.0.1
|
||||
* @param float $amount
|
||||
* @return bool
|
||||
*/
|
||||
public function updateShippingCost($amount)
|
||||
{
|
||||
$difference = $amount - $this->total_shipping;
|
||||
// if the current amount is same as the new, we return true
|
||||
if ($difference == 0)
|
||||
return true;
|
||||
|
||||
// update the total_shipping value
|
||||
$this->total_shipping = $amount;
|
||||
// update the total of this order
|
||||
$this->total_paid += $difference;
|
||||
|
||||
// update database
|
||||
return $this->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the correct product taxes breakdown.
|
||||
|
||||
@@ -33,6 +33,9 @@ class OrderDetailCore extends ObjectModel
|
||||
/** @var integer */
|
||||
public $id_order;
|
||||
|
||||
/** @var integer */
|
||||
public $id_order_invoice;
|
||||
|
||||
/** @var integer */
|
||||
public $product_id;
|
||||
|
||||
@@ -133,6 +136,7 @@ class OrderDetailCore extends ObjectModel
|
||||
|
||||
protected $fieldsValidate = array(
|
||||
'id_order' => 'isUnsignedId',
|
||||
'id_order_invoice' => 'isUnsignedId',
|
||||
'product_id' => 'isUnsignedId',
|
||||
'product_attribute_id' => 'isUnsignedId',
|
||||
'product_name' => 'isGenericName',
|
||||
@@ -213,6 +217,7 @@ class OrderDetailCore extends ObjectModel
|
||||
$this->validateFields();
|
||||
|
||||
$fields['id_order'] = (int)$this->id_order;
|
||||
$fields['id_order_invoice'] = (int)$this->id_order_invoice;
|
||||
$fields['product_id'] = (int)$this->product_id;
|
||||
$fields['product_attribute_id'] = (int)$this->product_attribute_id;
|
||||
$fields['product_name'] = pSQL($this->product_name);
|
||||
@@ -229,7 +234,7 @@ class OrderDetailCore extends ObjectModel
|
||||
$fields['product_ean13'] = pSQL($this->product_ean13);
|
||||
$fields['product_upc'] = pSQL($this->product_upc);
|
||||
$fields['product_reference'] = pSQL($this->product_reference);
|
||||
$fields['product_supplier_reference'] = pSQL($this->product_reference);
|
||||
$fields['product_supplier_reference'] = pSQL($this->product_supplier_reference);
|
||||
$fields['product_weight'] = (float)$this->product_weight;
|
||||
$fields['tax_name'] = pSQL($this->tax_name);
|
||||
$fields['tax_rate'] = (float)$this->tax_rate;
|
||||
@@ -405,11 +410,11 @@ class OrderDetailCore extends ObjectModel
|
||||
$this->tax_calculator = $tax_manager->getTaxCalculator();
|
||||
}
|
||||
|
||||
$this->ecotax_tax_rate = 0;
|
||||
if (!empty($product['ecotax']))
|
||||
$this->ecotax_tax_rate = Tax::getProductEcotaxRate($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
|
||||
$this->ecotax_tax_rate = 0;
|
||||
if (!empty($product['ecotax']))
|
||||
$this->ecotax_tax_rate = Tax::getProductEcotaxRate($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
|
||||
|
||||
$this->tax_computation_method = (int)$this->tax_calculator->computation_method;
|
||||
$this->tax_computation_method = (int)$this->tax_calculator->computation_method;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -445,12 +450,14 @@ class OrderDetailCore extends ObjectModel
|
||||
$customer = new Customer((int)$order->id_customer);
|
||||
$customer_address = new Address((int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
|
||||
|
||||
$this->specificPrice = SpecificPrice::getSpecificPrice((int)$product['id_product'],
|
||||
(int)$order->id_shop,
|
||||
(int)$order->id_currency,
|
||||
(int)$customer_address->id_country,
|
||||
(int)$customer->id_default_group,
|
||||
(int)$product['cart_quantity']);
|
||||
$this->specificPrice = SpecificPrice::getSpecificPrice(
|
||||
(int)$product['id_product'],
|
||||
(int)$order->id_shop,
|
||||
(int)$order->id_currency,
|
||||
(int)$customer_address->id_country,
|
||||
(int)$customer->id_default_group,
|
||||
(int)$product['cart_quantity']
|
||||
);
|
||||
|
||||
$this->product_price = (float)$product['price'];
|
||||
$this->unit_price_tax_incl = (float)$product['price_wt'];
|
||||
@@ -462,7 +469,12 @@ class OrderDetailCore extends ObjectModel
|
||||
|
||||
$this->group_reduction = (float)(Group::getReduction((int)($order->id_customer)));
|
||||
|
||||
$quantityDiscount = SpecificPrice::getQuantityDiscount((int)$product['id_product'], $this->context->shop->getID(),
|
||||
if (isset($this->context->shop))
|
||||
$shop_id = $this->context->shop->getID();
|
||||
else
|
||||
$shop_id = $cart->id_shop;
|
||||
|
||||
$quantityDiscount = SpecificPrice::getQuantityDiscount((int)$product['id_product'], $shop_id,
|
||||
(int)$cart->id_currency, (int)$this->vat_address->id_country,
|
||||
(int)$this->customer->id_default_group, (int)$product['cart_quantity']);
|
||||
|
||||
@@ -484,10 +496,13 @@ class OrderDetailCore extends ObjectModel
|
||||
* @param object $cart
|
||||
* @param array $product
|
||||
* @param int $id_order_status
|
||||
* @param int $id_order_invoice
|
||||
* @param bool $use_taxes set to false if you don't want to use taxes
|
||||
*/
|
||||
protected function create(Order $order, Cart $cart, $product, $id_order_state)
|
||||
protected function create(Order $order, Cart $cart, $product, $id_order_state, $id_order_invoice, $use_taxes = true)
|
||||
{
|
||||
$this->tax_calculator = new TaxCalculator();
|
||||
if ($use_taxes)
|
||||
$this->tax_calculator = new TaxCalculator();
|
||||
|
||||
$this->id = null;
|
||||
|
||||
@@ -510,13 +525,19 @@ class OrderDetailCore extends ObjectModel
|
||||
|
||||
$this->setVirtualProductInformation($product);
|
||||
$this->checkProductStock($product, $id_order_state);
|
||||
$this->setProductTax($order, $product);
|
||||
|
||||
if ($use_taxes)
|
||||
$this->setProductTax($order, $product);
|
||||
$this->setDetailProductPrice($order, $cart, $product);
|
||||
|
||||
// Set order invoice id
|
||||
$this->id_order_invoice = (int)$id_order_invoice;
|
||||
|
||||
// Add new entry to the table
|
||||
$this->save();
|
||||
|
||||
$this->saveTaxCalculator();
|
||||
if ($use_taxes)
|
||||
$this->saveTaxCalculator();
|
||||
unset($this->tax_calculator);
|
||||
}
|
||||
|
||||
@@ -525,18 +546,19 @@ class OrderDetailCore extends ObjectModel
|
||||
* @param object $order
|
||||
* @param object $cart
|
||||
* @param int $id_order_status
|
||||
* @param int $id_order_invoice
|
||||
* @param bool $use_taxes set to false if you don't want to use taxes
|
||||
*/
|
||||
public function createList(Order $order, Cart $cart, $id_order_state, $product_list)
|
||||
public function createList(Order $order, Cart $cart, $id_order_state, $product_list, $id_order_invoice, $use_taxes = true)
|
||||
{
|
||||
$this->vat_address = new Address((int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
|
||||
$this->customer = new Customer((int)($order->id_customer));
|
||||
|
||||
$this->id_order = $order->id;
|
||||
$products = $product_list;
|
||||
$this->outOfStock = false;
|
||||
|
||||
foreach ($products as $product)
|
||||
$this->create($order, $cart, $product, $id_order_state);
|
||||
foreach ($product_list as $product)
|
||||
$this->create($order, $cart, $product, $id_order_state, $id_order_invoice, $use_taxes);
|
||||
|
||||
unset($this->vat_address);
|
||||
unset($products);
|
||||
|
||||
@@ -0,0 +1,387 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 10418 $
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class OrderInvoiceCore extends ObjectModel
|
||||
{
|
||||
/** @var integer */
|
||||
public $id_order;
|
||||
|
||||
/** @var integer */
|
||||
public $number;
|
||||
|
||||
/** @var float */
|
||||
public $total_discount_tax_excl;
|
||||
|
||||
/** @var float */
|
||||
public $total_discount_tax_incl;
|
||||
|
||||
/** @var float */
|
||||
public $total_paid_tax_excl;
|
||||
|
||||
/** @var float */
|
||||
public $total_paid_tax_incl;
|
||||
|
||||
/** @var float */
|
||||
public $total_products;
|
||||
|
||||
/** @var float */
|
||||
public $total_products_wt;
|
||||
|
||||
/** @var float */
|
||||
public $total_shipping_tax_excl;
|
||||
|
||||
/** @var float */
|
||||
public $total_shipping_tax_incl;
|
||||
|
||||
/** @var float */
|
||||
public $total_wrapping_tax_excl;
|
||||
|
||||
/** @var float */
|
||||
public $total_wrapping_tax_incl;
|
||||
|
||||
/** @var intger */
|
||||
public $date_add;
|
||||
|
||||
protected $fieldsRequired = array('id_order', 'number');
|
||||
protected $fieldsValidate = array('id_order' => 'isUnsignedId', 'number' => 'isUnsignedId');
|
||||
|
||||
protected $table = 'order_invoice';
|
||||
protected $identifier = 'id_order_invoice';
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
$this->validateFields();
|
||||
|
||||
$fields['id_order'] = (int)$this->id_order;
|
||||
$fields['number'] = (int)$this->number;
|
||||
$fields['total_discount_tax_excl'] = (float)$this->total_discount_tax_excl;
|
||||
$fields['total_discount_tax_incl'] = (float)$this->total_discount_tax_incl;
|
||||
$fields['total_paid_tax_excl'] = (float)$this->total_paid_tax_excl;
|
||||
$fields['total_paid_tax_incl'] = (float)$this->total_paid_tax_incl;
|
||||
$fields['total_products'] = (float)$this->total_products;
|
||||
$fields['total_products_wt'] = (float)$this->total_products_wt;
|
||||
$fields['total_shipping_tax_excl'] = (float)$this->total_shipping_tax_excl;
|
||||
$fields['total_shipping_tax_incl'] = (float)$this->total_shipping_tax_incl;
|
||||
$fields['total_wrapping_tax_excl'] = (float)$this->total_wrapping_tax_excl;
|
||||
$fields['total_wrapping_tax_incl'] = (float)$this->total_wrapping_tax_incl;
|
||||
$fields['date_add'] = pSQL($this->date_add);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function getProductsDetail()
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'order_detail` od
|
||||
WHERE od.`id_order` = '.(int)$this->id_order.'
|
||||
AND od.`id_order_invoice` = '.(int)$this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get order products
|
||||
*
|
||||
* @return array Products with price, quantity (with taxe and without)
|
||||
*/
|
||||
public function getProducts($products = false, $selectedProducts = false, $selectedQty = false)
|
||||
{
|
||||
if (!$products)
|
||||
$products = $this->getProductsDetail();
|
||||
|
||||
$order = new Order($this->id_order);
|
||||
$customized_datas = Product::getAllCustomizedDatas($order->id_cart);
|
||||
|
||||
$resultArray = array();
|
||||
foreach ($products AS $row)
|
||||
{
|
||||
// Change qty if selected
|
||||
if ($selectedQty)
|
||||
{
|
||||
$row['product_quantity'] = 0;
|
||||
foreach ($selectedProducts AS $key => $id_product)
|
||||
if ($row['id_order_detail'] == $id_product)
|
||||
$row['product_quantity'] = (int)($selectedQty[$key]);
|
||||
if (!$row['product_quantity'])
|
||||
continue ;
|
||||
}
|
||||
|
||||
$this->setProductImageInformations($row);
|
||||
$this->setProductCurrentStock($row);
|
||||
$this->setProductPrices($row, $order);
|
||||
$this->setProductCustomizedDatas($row, $customized_datas);
|
||||
|
||||
// Add information for virtual product
|
||||
if ($row['download_hash'] && !empty($row['download_hash']))
|
||||
{
|
||||
if ($row['product_attribute_id'] && !empty($row['product_attribute_id']))
|
||||
$row['filename'] = ProductDownload::getFilenameFromIdAttribute((int)$row['product_id'], (int)$row['product_attribute_id']);
|
||||
else
|
||||
$row['filename'] = ProductDownload::getFilenameFromIdProduct((int)$row['product_id']);
|
||||
// Get the display filename
|
||||
$row['display_filename'] = ProductDownload::getFilenameFromFilename($row['filename']);
|
||||
}
|
||||
/* Stock product */
|
||||
$resultArray[(int)$row['id_order_detail']] = $row;
|
||||
}
|
||||
|
||||
if ($customized_datas)
|
||||
Product::addCustomizationPrice($resultArray, $customized_datas);
|
||||
|
||||
return $resultArray;
|
||||
}
|
||||
|
||||
protected function setProductCustomizedDatas(&$product, $customized_datas)
|
||||
{
|
||||
$product['customizedDatas'] = null;
|
||||
if (isset($customized_datas[$product['product_id']][$product['product_attribute_id']]))
|
||||
$product['customizedDatas'] = $customized_datas[$product['product_id']][$product['product_attribute_id']];
|
||||
else
|
||||
$product['customizationQuantityTotal'] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* This method allow to add stock information on a product detail
|
||||
* @param array &$product
|
||||
*/
|
||||
protected function setProductCurrentStock(&$product)
|
||||
{
|
||||
$product['current_stock'] = StockManagerFactory::getManager()->getProductPhysicalQuantities($product['product_id'], $product['product_attribute_id'], null, true);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* This method allow to add image information on a product detail
|
||||
* @param array &$product
|
||||
*/
|
||||
protected function setProductImageInformations(&$product)
|
||||
{
|
||||
if (isset($product['product_attribute_id']) && $product['product_attribute_id'])
|
||||
$id_image = Db::getInstance()->getValue('
|
||||
SELECT id_image
|
||||
FROM '._DB_PREFIX_.'product_attribute_image
|
||||
WHERE id_product_attribute = '.(int)$product['product_attribute_id']);
|
||||
|
||||
if (!isset($image['id_image']) || !$image['id_image'])
|
||||
$id_image = Db::getInstance()->getValue('
|
||||
SELECT id_image
|
||||
FROM '._DB_PREFIX_.'image
|
||||
WHERE id_product = '.(int)($product['product_id']).' AND cover = 1
|
||||
');
|
||||
|
||||
$product['image'] = null;
|
||||
$product['image_size'] = null;
|
||||
|
||||
if ($id_image)
|
||||
$product['image'] = new Image($id_image);
|
||||
}
|
||||
|
||||
public function setProductPrices(&$row, $order)
|
||||
{
|
||||
$tax_calculator = OrderDetail::getTaxCalculatorStatic((int)$row['id_order_detail']);
|
||||
$row['tax_calculator'] = $tax_calculator;
|
||||
$row['tax_rate'] = $tax_calculator->getTotalRate();
|
||||
|
||||
if ($order->getTaxCalculationMethod() == PS_TAX_EXC)
|
||||
$row['product_price'] = Tools::ps_round($row['product_price'], 2);
|
||||
else
|
||||
$row['product_price_wt'] = Tools::ps_round($tax_calculator->addTaxes($row['product_price']), 2);
|
||||
|
||||
$group_reduction = 1;
|
||||
if ($row['group_reduction'] > 0)
|
||||
$group_reduction = 1 - $row['group_reduction'] / 100;
|
||||
|
||||
if ($row['reduction_percent'] != 0)
|
||||
{
|
||||
if ($order->getTaxCalculationMethod() == PS_TAX_EXC)
|
||||
$row['product_price'] = ($row['product_price'] - $row['product_price'] * ($row['reduction_percent'] * 0.01));
|
||||
else
|
||||
$row['product_price_wt'] = Tools::ps_round(($row['product_price_wt'] - $row['product_price_wt'] * ($row['reduction_percent'] * 0.01)), 2);
|
||||
}
|
||||
|
||||
if ($row['reduction_amount'] != 0)
|
||||
{
|
||||
if ($this->_taxCalculationMethod == PS_TAX_EXC)
|
||||
$row['product_price'] = ($row['product_price'] - ($tax_calculator->removeTaxes($row['reduction_amount'])));
|
||||
else
|
||||
$row['product_price_wt'] = Tools::ps_round(($row['product_price_wt'] - $row['reduction_amount']), 2);
|
||||
}
|
||||
|
||||
if ($row['group_reduction'] > 0)
|
||||
{
|
||||
if ($this->_taxCalculationMethod == PS_TAX_EXC)
|
||||
$row['product_price'] = $row['product_price'] * $group_reduction;
|
||||
else
|
||||
$row['product_price_wt'] = Tools::ps_round($row['product_price_wt'] * $group_reduction , 2);
|
||||
}
|
||||
|
||||
if (($row['reduction_percent'] OR $row['reduction_amount'] OR $row['group_reduction']) AND $order->getTaxCalculationMethod() == PS_TAX_EXC)
|
||||
$row['product_price'] = Tools::ps_round($row['product_price'], 2);
|
||||
|
||||
if ($order->getTaxCalculationMethod() == PS_TAX_EXC)
|
||||
$row['product_price_wt'] = Tools::ps_round($tax_calculator->addTaxes($row['product_price']), 2) + Tools::ps_round($row['ecotax'] * (1 + $row['ecotax_tax_rate'] / 100), 2);
|
||||
else
|
||||
{
|
||||
$row['product_price_wt_but_ecotax'] = $row['product_price_wt'];
|
||||
$row['product_price_wt'] = Tools::ps_round($row['product_price_wt'] + $row['ecotax'] * (1 + $row['ecotax_tax_rate'] / 100), 2);
|
||||
}
|
||||
|
||||
$row['total_wt'] = $row['product_quantity'] * $row['product_price_wt'];
|
||||
$row['total_price'] = $row['product_quantity'] * $row['product_price'];
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns true if at least one order details uses the
|
||||
* One After Another tax computation method.
|
||||
*
|
||||
* @since 1.5.0.1
|
||||
* @return boolean
|
||||
*/
|
||||
public function useOneAfterAnotherTaxComputationMethod()
|
||||
{
|
||||
// if one of the order details use the tax computation method the display will be different
|
||||
return Db::getInstance()->getValue('
|
||||
SELECT od.`tax_computation_method`
|
||||
FROM `'._DB_PREFIX_.'order_detail_tax` odt
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
|
||||
WHERE od.`id_order` = '.(int)$this->id_order.'
|
||||
AND od.`id_order_invoice` = '.(int)$this->id.'
|
||||
AND od.`tax_computation_method` = '.(int)TaxCalculator::ONE_AFTER_ANOTHER_METHOD
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the correct product taxes breakdown.
|
||||
*
|
||||
* @since 1.5.0.1
|
||||
* @return array
|
||||
*/
|
||||
public function getProductTaxesBreakdown()
|
||||
{
|
||||
$tmp_tax_infos = array();
|
||||
if ($this->useOneAfterAnotherTaxComputationMethod())
|
||||
{
|
||||
// sum by taxes
|
||||
$taxes_by_tax = Db::getInstance()->executeS('
|
||||
SELECT odt.`id_order_detail`, t.`name`, t.`rate`, SUM(`total_amount`) AS `total_amount`
|
||||
FROM `'._DB_PREFIX_.'order_detail_tax` odt
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = odt.`id_tax`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
|
||||
WHERE od.`id_order` = '.(int)$this->id_order.'
|
||||
AND od.`id_order_invoice` = '.(int)$this->id.'
|
||||
GROUP BY odt.`id_tax`
|
||||
');
|
||||
|
||||
// format response
|
||||
$tmp_tax_infos = array();
|
||||
foreach ($taxes_infos as $tax_infos)
|
||||
{
|
||||
$tmp_tax_infos[$tax_infos['rate']]['total_amount'] = $tax_infos['tax_amount'];
|
||||
$tmp_tax_infos[$tax_infos['rate']]['name'] = $tax_infos['name'];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// sum by order details in order to retrieve real taxes rate
|
||||
$taxes_infos = Db::getInstance()->executeS('
|
||||
SELECT odt.`id_order_detail`, t.`rate` AS `name`, SUM(od.`total_price_tax_excl`) AS total_price_tax_excl, SUM(t.`rate`) AS rate, SUM(`total_amount`) AS `total_amount`
|
||||
FROM `'._DB_PREFIX_.'order_detail_tax` odt
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = odt.`id_tax`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
|
||||
WHERE od.`id_order` = '.(int)$this->id_order.'
|
||||
AND od.`id_order_invoice` = '.(int)$this->id.'
|
||||
GROUP BY odt.`id_order_detail`
|
||||
');
|
||||
|
||||
// sum by taxes
|
||||
$tmp_tax_infos = array();
|
||||
foreach ($taxes_infos as $tax_infos)
|
||||
{
|
||||
if (!isset($tmp_tax_infos[$tax_infos['rate']]))
|
||||
$tmp_tax_infos[$tax_infos['rate']] = array('total_amount' => 0,
|
||||
'name' => 0,
|
||||
'total_price_tax_excl' => 0);
|
||||
|
||||
$tmp_tax_infos[$tax_infos['rate']]['total_amount'] += $tax_infos['total_amount'];
|
||||
$tmp_tax_infos[$tax_infos['rate']]['name'] = $tax_infos['name'];
|
||||
$tmp_tax_infos[$tax_infos['rate']]['total_price_tax_excl'] += $tax_infos['total_price_tax_excl'];
|
||||
}
|
||||
}
|
||||
|
||||
return $tmp_tax_infos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shipping taxes breakdown
|
||||
*
|
||||
* @since 1.5.0.1
|
||||
* @return array
|
||||
*/
|
||||
public function getShippingTaxesBreakdown($order)
|
||||
{
|
||||
$taxes_breakdown = array();
|
||||
|
||||
$shipping_tax_amount = $this->total_shipping_tax_incl - $this->total_shipping_tax_excl;
|
||||
|
||||
if ($shipping_tax_amount > 0)
|
||||
$taxes_breakdown[] = array(
|
||||
'rate' => $order->carrier_tax_rate,
|
||||
'total_amount' => $shipping_tax_amount
|
||||
);
|
||||
|
||||
return $taxes_breakdown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the wrapping taxes breakdown
|
||||
* @todo
|
||||
|
||||
* @since 1.5.0.1
|
||||
* @return array
|
||||
*/
|
||||
public function getWrappingTaxesBreakdown()
|
||||
{
|
||||
$taxes_breakdown = array();
|
||||
return $taxes_breakdown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ecotax taxes breakdown
|
||||
*
|
||||
* @since 1.5.0.1
|
||||
* @return array
|
||||
*/
|
||||
public function getEcoTaxTaxesBreakdown()
|
||||
{
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT `ecotax_tax_rate`, SUM(`ecotax`) as `ecotax_tax_excl`, SUM(`ecotax`) as `ecotax_tax_incl`
|
||||
FROM `'._DB_PREFIX_.'order_detail`
|
||||
WHERE `id_order` = '.(int)$this->id_order.'
|
||||
AND `id_order_invoice` = '.(int)$this->id
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 10336 $
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class OrderPaymentCore extends ObjectModel
|
||||
{
|
||||
public $id_order;
|
||||
public $id_currency;
|
||||
public $amount;
|
||||
public $payment_method;
|
||||
public $conversion_rate;
|
||||
public $transaction_id;
|
||||
public $card_number;
|
||||
public $card_brand;
|
||||
public $card_expiration;
|
||||
public $card_holder;
|
||||
public $date_add;
|
||||
|
||||
protected $fieldsRequired = array('id_order', 'id_currency', 'amount');
|
||||
protected $fieldsSize = array('transaction_id' => 254, 'card_number' => 254, 'card_brand' => 254, 'card_expiration' => 254, 'card_holder' => 254);
|
||||
protected $fieldsValidate = array(
|
||||
'id_order' => 'isUnsignedId',
|
||||
'id_currency' => 'isUnsignedId',
|
||||
'amount' => 'isPrice',
|
||||
'payment_method' => 'isName',
|
||||
'conversion_rate' => 'isFloat',
|
||||
'transaction_id' => 'isAnything',
|
||||
'card_number' => 'isAnything',
|
||||
'card_brand' => 'isAnything',
|
||||
'card_expiration' => 'isAnything',
|
||||
'card_holder' => 'isAnything'
|
||||
);
|
||||
|
||||
protected $table = 'order_payment';
|
||||
protected $identifier = 'id_order_payment';
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
$this->validateFields();
|
||||
$fields['id_order'] = (int)($this->id_order);
|
||||
$fields['id_currency'] = (int)($this->id_currency);
|
||||
$fields['amount'] = (float)($this->amount);
|
||||
$fields['payment_method'] = pSQL($this->payment_method);
|
||||
$fields['transaction_id'] = pSQL($this->transaction_id);
|
||||
$fields['card_number'] = pSQL($this->card_number);
|
||||
$fields['card_brand'] = pSQL($this->card_brand);
|
||||
$fields['card_expiration'] = pSQL($this->card_expiration);
|
||||
$fields['card_holder'] = pSQL($this->card_holder);
|
||||
$fields['date_add'] = pSQL($this->date_add);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function add($autodate = true, $nullValues = false)
|
||||
{
|
||||
if (parent::add($autodate, $nullValues))
|
||||
{
|
||||
Hook::exec('paymentCCAdded', array('paymentCC' => $this));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the detailed payment of an order
|
||||
* @param int $id_order
|
||||
* @return array
|
||||
*/
|
||||
public static function getByOrderId($id_order)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'payment_order`
|
||||
WHERE `id_order` = '.(int)$id_order);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,10 +143,13 @@ class OrderReturnCore extends ObjectModel
|
||||
($order_id ? ' AND `id_order` = '.(int)($order_id) : '').
|
||||
($no_denied ? ' AND `state` != 4' : '').'
|
||||
ORDER BY `date_add` DESC');
|
||||
foreach ($data AS $k => $or)
|
||||
foreach ($data as $k => $or)
|
||||
{
|
||||
$state = new OrderReturnState($or['state']);
|
||||
$data[$k]['state_name'] = $state->name[$context->language->id];
|
||||
$data[$k]['type'] = 'Return';
|
||||
$data[$k]['tracking_number'] = $or['id_order_return'];
|
||||
$data[$k]['can_edit'] = false;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ class OrderSlipCore extends ObjectModel
|
||||
.($id_order_detail ? ' WHERE `id_order_detail` = '.(int)($id_order_detail) : ''));
|
||||
}
|
||||
|
||||
// TODO clean getProducts($resTab) => now getProducts method don't use his parameters
|
||||
public static function getOrdersSlipProducts($orderSlipId, $order)
|
||||
{
|
||||
$cart_rules = $order->getCartRules(true);
|
||||
|
||||
Reference in New Issue
Block a user