diff --git a/admin-dev/themes/template/orders/_print_pdf_icon.tpl b/admin-dev/themes/template/orders/_print_pdf_icon.tpl index 0c8c8741a..6fd634008 100644 --- a/admin-dev/themes/template/orders/_print_pdf_icon.tpl +++ b/admin-dev/themes/template/orders/_print_pdf_icon.tpl @@ -19,7 +19,7 @@ * * @author PrestaShop SA * @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 10336 $ +* @version Release: $Revision: 9589 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} diff --git a/classes/Tools.php b/classes/Tools.php index 026cdf0e0..e5f21fae5 100644 --- a/classes/Tools.php +++ b/classes/Tools.php @@ -463,7 +463,44 @@ class ToolsCore return $price; } + /** + * + * Convert amount from a currency to an other currency automatically + * @param float $amount + * @param Currency $currency_from if null we used the default currency + * @param Currency $currency_to if null we used the default currency + */ + public static function convertPriceFull($amount, Currency $currency_from = null, Currency $currency_to = null) + { + if ($currency_from == $currency_to) + return $amount; + if ($currency_from === null) + { + $currency_from = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); + $default_currency = $currency_from; + } + + if ($currency_to === null) + { + $currency_to = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); + $default_currency = $currency_to; + } + + if ($currency_from->id == Configuration::get('PS_CURRENCY_DEFAULT')) + $amount *= $currency_to->conversion_rate; + else + { + if (!isset($default_currency)) + $default_currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); + + // Convert amount to default currency + $amount = Tools::ps_round($amount / $default_currency->conversion_rate, 2); + // Convert to new currency + $amount *= $currency_to->conversion_rate; + } + return Tools::ps_round($amount, 2); + } /** * Display date regarding to language preferences diff --git a/classes/order/OrderInvoice.php b/classes/order/OrderInvoice.php index 6c44b0985..cf260b03d 100644 --- a/classes/order/OrderInvoice.php +++ b/classes/order/OrderInvoice.php @@ -20,7 +20,7 @@ * * @author PrestaShop SA * @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 10418 $ +* @version Release: $Revision: 6844 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ @@ -384,4 +384,4 @@ class OrderInvoiceCore extends ObjectModel AND `id_order_invoice` = '.(int)$this->id ); } -} +} \ No newline at end of file diff --git a/classes/order/OrderPayment.php b/classes/order/OrderPayment.php index fe3711867..5a887feb5 100644 --- a/classes/order/OrderPayment.php +++ b/classes/order/OrderPayment.php @@ -20,7 +20,7 @@ * * @author PrestaShop SA * @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 10336 $ +* @version Release: $Revision: 6844 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index abc788917..8bde730ff 100755 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -435,7 +435,7 @@ class AdminOrdersControllerCore extends AdminController { $reinjectableQuantity = (int)($orderDetail->product_quantity) - (int)($orderDetail->product_quantity_reinjected); $quantityToReinject = $qtyCancelProduct > $reinjectableQuantity ? $reinjectableQuantity : $qtyCancelProduct; - // TODO (Denis) : fix reinject quantities + // TODO (Denis) : fix reinject quantities // if (!Product::reinjectQuantities($orderDetail, $quantityToReinject)) // $this->_errors[] = Tools::displayError('Cannot re-stock product').' '.$orderDetail->product_name.''; // else @@ -598,13 +598,91 @@ class AdminOrdersControllerCore extends AdminController else $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } + elseif (Tools::isSubmit('submitChangeCurrency')) + { + if ($this->tabAccess['edit'] === '1') + { + $order = new Order(Tools::getValue('id_order')); + if (!Validate::isLoadedObject($order)) + throw new PrestashopException('Con\'t load Order object'); + + if (Tools::getValue('new_currency') != $order->id_currency && !$order->valid) + { + $old_currency = new Currency($order->id_currency); + $currency = new Currency(Tools::getValue('new_currency')); + if (!Validate::isLoadedObject($currency)) + throw new PrestashopException('Can\'t load Currency object'); + + // Update order detail amount + foreach($order->getOrderDetailList() as $row) + { + $order_detail = new OrderDetail($row['id_order_detail']); + $order_detail->product_price = Tools::convertPriceFull($order_detail->product_price, $old_currency, $currency); + $order_detail->reduction_amount = Tools::convertPriceFull($order_detail->reduction_amount, $old_currency, $currency); + $order_detail->unit_price_tax_incl = Tools::convertPriceFull($order_detail->unit_price_tax_incl, $old_currency, $currency); + $order_detail->unit_price_tax_excl = Tools::convertPriceFull($order_detail->unit_price_tax_excl, $old_currency, $currency); + $order_detail->total_price_tax_incl = Tools::convertPriceFull($order_detail->product_price, $old_currency, $currency); + $order_detail->total_price_tax_excl = Tools::convertPriceFull($order_detail->product_price, $old_currency, $currency); + $order_detail->group_reduction = Tools::convertPriceFull($order_detail->product_price, $old_currency, $currency); + $order_detail->product_quantity_discount = Tools::convertPriceFull($order_detail->product_price, $old_currency, $currency); + + $order_detail->update(); + } + + // Update order payment amount + foreach($order->getOrderPaymentCollection() as $payment) + { + $payment->id_currency = (int)$currency->id; + $payment->amount = Tools::convertPriceFull((float)$payment->amount, $old_currency, $currency); + $payment->update(); + } + + $order_carrier = Db::getInstance()->executeS(' + SELECT * + FROM `'._DB_PREFIX_.'order_carrier` + WHERE `id_order` = '.(int)$order->id); + // Update order carrier amount + Db::getInstance()->execute(' + UPDATE `'._DB_PREFIX_.'order_carrier` + SET `shipping_cost_tax_excl` = '.(float)Tools::convertPriceFull($order_carrier['shipping_cost_tax_excl'], $old_currency, $currency).', + `shipping_cost_tax_incl` = '.(float)Tools::convertPriceFull($order_carrier['shipping_cost_tax_incl'], $old_currency, $currency).' + WHERE `id_order` = '.(int)$order->id); + + // Update order amount + $order->total_discounts = Tools::convertPriceFull($order->total_discounts, $old_currency, $currency); + $order->total_discounts_tax_incl = Tools::convertPriceFull($order->total_discounts_tax_incl, $old_currency, $currency); + $order->total_discounts_tax_excl = Tools::convertPriceFull($order->total_discounts_tax_excl, $old_currency, $currency); + $order->total_paid = Tools::convertPriceFull($order->total_paid, $old_currency, $currency); + $order->total_paid_tax_incl = Tools::convertPriceFull($order->total_paid_tax_incl, $old_currency, $currency); + $order->total_paid_tax_excl = Tools::convertPriceFull($order->total_discounts_tax_excl, $old_currency, $currency); + $order->total_paid_real = Tools::convertPriceFull($order->total_paid_real, $old_currency, $currency); + $order->total_products = Tools::convertPriceFull($order->total_products, $old_currency, $currency); + $order->total_products_wt = Tools::convertPriceFull($order->total_products_wt, $old_currency, $currency); + $order->total_shipping = Tools::convertPriceFull($order->total_shipping, $old_currency, $currency); + $order->total_shipping_tax_incl = Tools::convertPriceFull($order->total_shipping_tax_incl, $old_currency, $currency); + $order->total_shipping_tax_excl = Tools::convertPriceFull($order->total_shipping_tax_excl, $old_currency, $currency); + $order->total_wrapping = Tools::convertPriceFull($order->total_wrapping, $old_currency, $currency); + $order->total_wrapping_tax_incl = Tools::convertPriceFull($order->total_wrapping_tax_incl, $old_currency, $currency); + $order->total_wrapping_tax_excl = Tools::convertPriceFull($order->total_wrapping_tax_excl, $old_currency, $currency); + + // Update currency in order + $order->id_currency = $currency->id; + + $order->update(); + } + else + $this->_errors[] = Tools::displayError('You can\'t change the currency'); + } + else + $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); + } parent::postProcess(); } public function initView() { - $order = $this->loadObject(); + $order = new Order(Tools::getValue('id_order')); if (!Validate::isLoadedObject($order)) throw new PrestashopException('object can\'t be loaded'); @@ -847,7 +925,7 @@ class AdminOrdersControllerCore extends AdminController $cart_rule->add(); $cart->addCartRule($cart_rule->id); - //$order->addCartRule($cart_rule->id, $cart_rule->name, $cart_rule->getContextualValue(true)); + $order->addCartRule($cart_rule->id, $cart_rule->name, $cart_rule->getContextualValue(true)); } // If order is valid, we can create a new invoice or edit an existing invoice diff --git a/js/admin_order.js b/js/admin_order.js index a379d3cde..757ade261 100644 --- a/js/admin_order.js +++ b/js/admin_order.js @@ -19,7 +19,7 @@ * * @author PrestaShop SA * @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 10575 $ +* @version Release: $Revision: 7310 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ @@ -216,22 +216,22 @@ $(document).ready(function() { return false; }); - $('.edit_shipping_number_link').click(function() { - $(this).parent().find('.shipping_number_show').hide(); - $(this).parent().find('.shipping_number_edit').show(); + $('#edit_shipping_number_link').click(function() { + $('#shipping_number_show').hide(); + $('#shipping_number_edit').show(); - $(this).parent().find('.edit_shipping_number_link').hide(); - $(this).parent().find('.cancel_shipping_number_link').show(); + $('#edit_shipping_number_link').hide(); + $('#cancel_shipping_number_link').show(); return false; }); - $('.cancel_shipping_number_link').click(function() { - $(this).parent().find('.shipping_number_show').show(); - $(this).parent().find('.shipping_number_edit').hide(); + $('#cancel_shipping_number_link').click(function() { + $('#shipping_number_show').show(); + $('#shipping_number_edit').hide(); - $(this).parent().find('.edit_shipping_number_link').show(); - $(this).parent().find('.cancel_shipping_number_link').hide(); + $('#edit_shipping_number_link').show(); + $('#cancel_shipping_number_link').hide(); return false; }); @@ -574,61 +574,4 @@ function closeAddProduct() $('#add_product_product_attribute_area').hide(); $('#add_product_product_stock').html('0'); current_product = null; -} - - - - - - - -/* Refund system script */ -var flagRefund = ''; - -$(document).ready(function() { - $('.standard_refund').click(function() { - - $.scrollTo('#refundForm', 1200, {offset: -100}); - - if (flagRefund == 'standard') - { - flagRefund = ''; - $('.partial_refund_fields').hide(); - $('.standard_refund_fields').hide(); - } - else - { - flagRefund = 'standard'; - $('.partial_refund_fields').hide(); - $('.standard_refund_fields').fadeIn(); - } - - return false; - }); - - $('.partial_refund').click(function() { - - $.scrollTo('#refundForm', 1200, {offset: -100}); - - if (flagRefund == 'partial') - { - flagRefund = ''; - $('.partial_refund_fields').hide(); - $('.standard_refund_fields').hide(); - } - else - { - flagRefund = 'partial'; - $('.standard_refund_fields').hide(); - $('.partial_refund_fields').fadeIn(); - } - - return false; - }); -}); - - - - - - +} \ No newline at end of file