[+] BO : add new feature, Order edition

This commit is contained in:
dMetzger
2011-11-23 17:45:52 +00:00
parent f5de69ad84
commit d902a38ec8
31 changed files with 3349 additions and 846 deletions
+22 -4
View File
@@ -66,13 +66,31 @@ function generateSupplyOrderFormPDF()
function generateInvoicePDF() function generateInvoicePDF()
{ {
if (!isset($_GET['id_order'])) if (Tools::isSubmit('id_order'))
die (Tools::displayError('Missing order ID')); generateInvoicePDFByIdOrder(Tools::getValue('id_order'));
$order = new Order((int)($_GET['id_order'])); elseif (Tools::isSubmit('id_order_invoice'))
generateInvoicePDFByIdOrderInvoice(Tools::getValue('id_order_invoice'));
else
die (Tools::displayError('Missing order ID or invoice order ID'));
exit;
}
function generateInvoicePDFByIdOrder($id_order)
{
$order = new Order($id_order);
if (!Validate::isLoadedObject($order)) if (!Validate::isLoadedObject($order))
die(Tools::displayError('Cannot find order in database')); die(Tools::displayError('Cannot find order in database'));
generatePDF($order, PDF::TEMPLATE_INVOICE); generatePDF($order->getInvoicesCollection(), PDF::TEMPLATE_INVOICE);
}
function generateInvoicePDFByIdOrderInvoice($id_order_invoice)
{
$order_invoice = new OrderInvoice($id_order_invoice);
if (!Validate::isLoadedObject($order_invoice))
die(Tools::displayError('Cannot find order invoice in database'));
generatePDF($order_invoice, PDF::TEMPLATE_INVOICE);
} }
function generateOrderSlipPDF() function generateOrderSlipPDF()
@@ -47,6 +47,7 @@
{/if} {/if}
</td> </td>
<td align="center" class="cancelCheck">--</td> <td align="center" class="cancelCheck">--</td>
<td align="center" class="cancelQuantity">--</td>
</tr> </tr>
{foreach from=$product.customizedDatas key=customizationId item=customization} {foreach from=$product.customizedDatas key=customizationId item=customization}
<tr> <tr>
@@ -0,0 +1,49 @@
<tr id="new_product" height="52" style="display:none;background-color:#E8EDC2">
<td style="display:none;" colspan="2">
<input type="hidden" id="add_product_product_id" name="add_product[product_id]" value="0" />
{l s='Product:'} <input type="text" id="add_product_product_name" value="" size="42" />
<div id="add_product_product_attribute_area" style="margin-top: 5px;display: none;">
{l s='Combinations:'} <select name="add_product[product_attribute_id]" id="add_product_product_attribute_id"></select>
</div>
</td>
<td style="display:none;">
{if $currency->sign % 2}{$currency->sign}{/if}<input type="text" name="add_product[product_price_tax_excl]" id="add_product_product_price_tax_excl" value="" size="4" disabled="disabled" /> {if !($currency->sign % 2)}{$currency->sign}{/if} {l s='tax excl.'}<br />
{if $currency->sign % 2}{$currency->sign}{/if}<input type="text" name="add_product[product_price_tax_incl]" id="add_product_product_price_tax_incl" value="" size="4" disabled="disabled" /> {if !($currency->sign % 2)}{$currency->sign}{/if} {l s='tax incl.'}<br />
</td>
<td style="display:none;" align="center" class="productQuantity"><input type="text" name="add_product[product_quantity]" id="add_product_product_quantity" value="1" size="3" disabled="disabled" /></td>
{if ($order->hasBeenPaid())}<td style="display:none;" align="center" class="productQuantity">&nbsp;</td>{/if}
{if ($order->hasBeenDelivered())}<td style="display:none;" align="center" class="productQuantity">&nbsp;</td>{/if}
<td style="display:none;" align="center" class="productQuantity" id="add_product_product_stock">0</td>
<td style="display:none;" align="center" id="add_product_product_total">{displayPrice price=0 currency=$currency->id}</td>
<td style="display:none;" align="center" colspan="2">
{if $order->valid}
<select name="add_product[invoice]" id="add_product_product_invoice" disabled="disabled">
<optgroup label="{l s='Existing'}">
{foreach from=$invoices_collection item=invoice}
<option value="{$invoice->id}">#{Configuration::get('PS_INVOICE_PREFIX', $current_id_lang)}{'%06d'|sprintf:$invoice->number}</option>
{/foreach}
</optgroup>
<optgroup label="{l s='New'}">
<option value="0">{l s='Create a new invoice'}</option>
</optgroup>
</select>
{/if}
</td>
<td style="display:none;">
<input type="button" class="button" id="submitAddProduct" value="{l s='Add product'}" disabled="disabled" />
</td>
</tr>
<tr id="new_invoice" style="display:none;background-color:#E8EDC2">
<td colspan="10">
<h3>{l s='New invoice informations'}</h3>
<label>{l s='Carrier:'}</label>
<div class="margin-form">
{$carrier->name}
</div>
<div class="margin-form">
<input type="checkbox" name="add_invoice[free_shipping]" value="1" />
<label class="t">{l s='Free shipping'}</label>
<p>{l s='If you don\'t select the "Free shipping", the normal shipping cost will be applied'}</p>
</div>
</td>
</tr>
@@ -0,0 +1,43 @@
{*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
{* Generate HTML code for printing Invoice Icon with link *}
<span style="width:20px; margin-right:5px;">
{if (($order_state->invoice && $order->invoice_number) && $tr['product_number'])}
<a href="pdf.php?id_order={$order->id}&pdf"><img src="../img/admin/tab-invoice.gif" alt="invoice" /></a>
{else}
-
{/if}
</span>
{* Generate HTML code for printing Delivery Icon with link *}
<span style="width:20px;">
{if ($order_state->delivery && $order->delivery_number)}
<a href="pdf.php?id_delivery={$order->delivery_number}"><img src="../img/admin/delivery.gif" alt="delivery" /></a>
{else}
-
{/if}
</span>
@@ -26,9 +26,9 @@
{* Assign product price *} {* Assign product price *}
{if ($order->getTaxCalculationMethod() == $smarty.const.PS_TAX_EXC)} {if ($order->getTaxCalculationMethod() == $smarty.const.PS_TAX_EXC)}
{assign var=product_price value=($product['product_price'] + $product['ecotax'])} {assign var=product_price value=($product['unit_price_tax_excl'] + $product['ecotax'])}
{else} {else}
{assign var=product_price value=$product['product_price_wt']} {assign var=product_price value=$product['unit_price_tax_incl']}
{/if} {/if}
{if ($product['product_quantity'] > $product['customizationQuantityTotal'])} {if ($product['product_quantity'] > $product['customizationQuantityTotal'])}
@@ -39,13 +39,31 @@
{if $product.product_reference}{l s='Ref:'} {$product.product_reference}<br />{/if} {if $product.product_reference}{l s='Ref:'} {$product.product_reference}<br />{/if}
{if $product.product_supplier_reference}{l s='Ref Supplier:'} {$product.product_supplier_reference}{/if} {if $product.product_supplier_reference}{l s='Ref Supplier:'} {$product.product_supplier_reference}{/if}
</a></td> </a></td>
<td align="center">{displayPrice price=$product_price currency=$currency->id}</td> <td align="center">
<td align="center" class="productQuantity" {if ($product['product_quantity'] > 1)}style="font-weight:700;font-size:1.1em;color:red"{/if}>{$product['product_quantity']}</td> <span class="product_price_show">{displayPrice price=$product_price currency=$currency->id}</span>
{if $can_edit}
<span class="product_price_edit" style="display:none;">
<input type="hidden" name="product_id_order_detail" class="edit_product_id_order_detail" value="{$product['id_order_detail']}" />
{if $currency->sign % 2}{$currency->sign}{/if}<input type="text" name="product_price_tax_excl" class="edit_product_price_tax_excl edit_product_price" value="{Tools::ps_round($product['unit_price_tax_excl'], 2)}" size="5" /> {if !($currency->sign % 2)}{$currency->sign}{/if} {l s='tax excl.'}<br />
{if $currency->sign % 2}{$currency->sign}{/if}<input type="text" name="product_price_tax_incl" class="edit_product_price_tax_incl edit_product_price" value="{Tools::ps_round($product['unit_price_tax_incl'], 2)}" size="5" /> {if !($currency->sign % 2)}{$currency->sign}{/if} {l s='tax incl.'}
</span>
{/if}
</td>
<td align="center" class="productQuantity">
<span class="product_quantity_show">{$product['product_quantity']}</span>
{if $can_edit}
<span class="product_quantity_edit" style="display:none;">
<input type="text" name="product_quantity" class="edit_product_quantity" value="{$product['product_quantity']}" size="2" />
</span>
{/if}
</td>
{if ($order->hasBeenPaid())}<td align="center" class="productQuantity">{$product['product_quantity_refunded']}</td>{/if} {if ($order->hasBeenPaid())}<td align="center" class="productQuantity">{$product['product_quantity_refunded']}</td>{/if}
{if ($order->hasBeenDelivered())}<td align="center" class="productQuantity">{$product['product_quantity_return']}</td>{/if} {if ($order->hasBeenDelivered())}<td align="center" class="productQuantity">{$product['product_quantity_return']}</td>{/if}
<td align="center" class="productQuantity">{StockManagerFactory::getManager()->getProductRealQuantities($product['product_id'], $product['product_attribute_id'], null, true)}</td> <td align="center" class="productQuantity product_stock">{StockManagerFactory::getManager()->getProductRealQuantities($product['product_id'], $product['product_attribute_id'], null, true)}</td>
<td align="center">{displayPrice price=(Tools::ps_round($product_price, 2) * ($product['product_quantity'] - $product['customizationQuantityTotal'])) currency=$currency->id}</td> <td align="center" class="total_product">
<td align="center" class="cancelCheck"> {displayPrice price=(Tools::ps_round($product_price, 2) * ($product['product_quantity'] - $product['customizationQuantityTotal'])) currency=$currency->id}
</td>
<td align="center" class="cancelCheck standard_refund_fields" style="background-color:rgb(232, 237, 194);display:none">
<input type="hidden" name="totalQtyReturn" id="totalQtyReturn" value="{$product['product_quantity_return']}" /> <input type="hidden" name="totalQtyReturn" id="totalQtyReturn" value="{$product['product_quantity_return']}" />
<input type="hidden" name="totalQty" id="totalQty" value="{$product['product_quantity']}" /> <input type="hidden" name="totalQty" id="totalQty" value="{$product['product_quantity']}" />
<input type="hidden" name="productName" id="productName" value="{$product['product_name']}" /> <input type="hidden" name="productName" id="productName" value="{$product['product_name']}" />
@@ -55,7 +73,7 @@
-- --
{/if} {/if}
</td> </td>
<td class="cancelQuantity"> <td class="cancelQuantity standard_refund_fields" style="background-color:rgb(232, 237, 194);display:none">
{if ($product['product_quantity_return'] + $product['product_quantity_refunded'] >= $product['product_quantity'])} {if ($product['product_quantity_return'] + $product['product_quantity_refunded'] >= $product['product_quantity'])}
<input type="hidden" name="cancelQuantity[{$k}]" value="0" /> <input type="hidden" name="cancelQuantity[{$k}]" value="0" />
{elseif (!$order->hasBeenDelivered() OR Configuration::get('PS_ORDER_RETURN'))} {elseif (!$order->hasBeenDelivered() OR Configuration::get('PS_ORDER_RETURN'))}
@@ -76,5 +94,25 @@
0/{$productQuantity} 0/{$productQuantity}
{/if} {/if}
</td> </td>
<td class="partial_refund_fields" style="text-align:right;background-color:rgb(232, 237, 194);display:none"><input type="text" size="3" name="partialRefund[{$k}]" /> &euro;</td>
{if $can_edit}
<td class="product_invoice" colspan="2" style="display: none;text-align:center;">
{if $order->hasBeenPaid()}
<select name="product_invoice" class="edit_product_invoice">
{foreach from=$invoices_collection item=invoice}
<option value="{$invoice->id}" {if $invoice->id == $product['id_order_invoice']}selected="selected"{/if}>#{Configuration::get('PS_INVOICE_PREFIX', $current_id_lang)}{'%06d'|sprintf:$invoice->number}</option>
{/foreach}
</select>
{else}
&nbsp;
{/if}
</td>
<td class="product_action" style="text-align:right">
<a href="#" class="edit_product_change_link"><img src="../img/admin/edit.gif" alt="{l s='Edit'}" /></a>
<input type="submit" class="button" name="submitProductChange" value="{l s='Update'}" style="display: none;" />
<a href="#" class="cancel_product_change_link" style="display: none;"><img src="../img/admin/disabled.gif" alt="{l s='Cancel'}" /></a>
<a href="#" class="delete_product_line"><img src="../img/admin/delete.gif" alt="{l s='Delete'}" /></a>
</td>
{/if}
</tr> </tr>
{/if} {/if}
+3 -3
View File
@@ -467,10 +467,10 @@
products_found += '<label>{l s='Product:'}</label><select id="id_product" onclick="displayProductAttributes();">'; products_found += '<label>{l s='Product:'}</label><select id="id_product" onclick="displayProductAttributes();">';
attributes_html += '<label>{l s='Combination:'}</label>'; attributes_html += '<label>{l s='Combination:'}</label>';
$.each(res.products, function() { $.each(res.products, function() {
products_found += '<option '+(this.combinations.length > 0 ? 'rel="'+this.qty_in_stock+'"' : '')+' value="'+this.id_product+'">'+this.name+(this.combinations.length == 0 ? ' - '+this.price : '')+'</option>'; products_found += '<option '+(this.combinations.length > 0 ? 'rel="'+this.qty_in_stock+'"' : '')+' value="'+this.id_product+'">'+this.name+(this.combinations.length == 0 ? ' - '+this.formatted_price : '')+'</option>';
attributes_html += '<select class="id_product_attribute" id="ipa_'+this.id_product+'" style="display:none;">'; attributes_html += '<select class="id_product_attribute" id="ipa_'+this.id_product+'" style="display:none;">';
$.each(this.combinations, function() { $.each(this.combinations, function() {
attributes_html += '<option rel="'+this.qty_in_stock+'" '+(this.default_on == 1 ? 'selected="selected"' : '')+' value="'+this.id_product_attribute+'">'+this.attributes+' - '+this.price+'</option>'; attributes_html += '<option rel="'+this.qty_in_stock+'" '+(this.default_on == 1 ? 'selected="selected"' : '')+' value="'+this.id_product_attribute+'">'+this.attributes+' - '+this.formatted_price+'</option>';
}); });
attributes_html += '</select>'; attributes_html += '</select>';
}); });
@@ -508,7 +508,7 @@
var cart_content = ''; var cart_content = '';
$.each(products, function() { $.each(products, function() {
cart_quantity[this.id_product+'_'+this.id_product_attribute] = this.cart_quantity; cart_quantity[this.id_product+'_'+this.id_product_attribute] = this.cart_quantity;
cart_content += '<tr><td><img src="'+this.image_link+'" title="'+this.name+'" /></td><td>'+this.name+'<br />'+this.attributes_small+'</td><td>'+this.reference+'</td><td><input type="text" size="7" rel="'+this.id_product+'_'+this.id_product_attribute+'" class="product_unit_price" value="'+this.price+'" />&nbsp;<span class="currency_sign"></span></td><td>'; cart_content += '<tr><td><img src="'+this.image_link+'" title="'+this.name+'" /></td><td>'+this.name+'<br />'+this.attributes_small+'</td><td>'+this.reference+'</td><td><input type="text" size="7" rel="'+this.id_product+'_'+this.id_product_attribute+'" class="product_unit_price" value="'+this.formatted_price+'" />&nbsp;<span class="currency_sign"></span></td><td>';
cart_content += '<p><a href="#" class="delete_product" rel="delete_'+this.id_product+'_'+this.id_product_attribute+'" ><img src="../img/admin/delete.gif" /></a>'; cart_content += '<p><a href="#" class="delete_product" rel="delete_'+this.id_product+'_'+this.id_product_attribute+'" ><img src="../img/admin/delete.gif" /></a>';
cart_content += '<a href="#" class="increaseqty_product" rel="'+this.id_product+'_'+this.id_product_attribute+'" ><img src="../img/admin/up.gif" /></a><input type="text" rel="'+this.id_product+'_'+this.id_product_attribute+'" class="cart_quantity" size="2" value="'+this.cart_quantity+'" /></p>'; cart_content += '<a href="#" class="increaseqty_product" rel="'+this.id_product+'_'+this.id_product_attribute+'" ><img src="../img/admin/up.gif" /></a><input type="text" rel="'+this.id_product+'_'+this.id_product_attribute+'" class="cart_quantity" size="2" value="'+this.cart_quantity+'" /></p>';
cart_content += '<p style="float:right"><center><a href="#" class="decreaseqty_product" rel="'+this.id_product+'_'+this.id_product_attribute+'"><img src="../img/admin/down.gif" /></center></a>'; cart_content += '<p style="float:right"><center><a href="#" class="decreaseqty_product" rel="'+this.id_product+'_'+this.id_product_attribute+'"><img src="../img/admin/down.gif" /></center></a>';
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -918,6 +918,8 @@ class AdminControllerCore extends Controller
'desc' => $this->l('Save') 'desc' => $this->l('Save')
); );
break; break;
case 'view':
break;
default: // list default: // list
$this->toolbar_btn['new'] = array( $this->toolbar_btn['new'] = array(
'href' => self::$currentIndex.'&amp;add'.$this->table.'&amp;token='.$this->token, 'href' => self::$currentIndex.'&amp;add'.$this->table.'&amp;token='.$this->token,
@@ -1849,7 +1851,6 @@ class AdminControllerCore extends Controller
if (empty($order_by)) if (empty($order_by))
$order_by = $this->context->cookie->__get($this->table.'Orderby') ? $this->context->cookie->__get($this->table.'Orderby') : $this->_defaultOrderBy; $order_by = $this->context->cookie->__get($this->table.'Orderby') ? $this->context->cookie->__get($this->table.'Orderby') : $this->_defaultOrderBy;
if (empty($order_way)) if (empty($order_way))
$order_way = $this->context->cookie->__get($this->table.'Orderway') ? $this->context->cookie->__get($this->table.'Orderway') : 'ASC'; $order_way = $this->context->cookie->__get($this->table.'Orderway') ? $this->context->cookie->__get($this->table.'Orderway') : 'ASC';
+1
View File
@@ -257,6 +257,7 @@ class CartCore extends ObjectModel
/** /**
* @deprecated 1.5.0.1 * @deprecated 1.5.0.1
* @see Cart::getCartRules()
*/ */
public function getDiscounts($lite = false, $refresh = false) public function getDiscounts($lite = false, $refresh = false)
{ {
+2 -1
View File
@@ -426,7 +426,8 @@ class CartRuleCore extends ObjectModel
$minimum_amount = $this->minimum_amount; $minimum_amount = $this->minimum_amount;
if ($this->minimum_amount_currency != Configuration::get('PS_CURRENCY_DEFAULT')) if ($this->minimum_amount_currency != Configuration::get('PS_CURRENCY_DEFAULT'))
{ {
$minimumAmountCurrency = new Currency($this->minimum_amount); $minimumAmountCurrency = new Currency($this->minimum_amount_currency);
//p($this->minimum_amount_currency);
$minimum_amount = $this->minimum_amount / $minimumAmountCurrency->convertion_rate; $minimum_amount = $this->minimum_amount / $minimumAmountCurrency->convertion_rate;
} }
$cartTotal = $context->cart->getOrderTotal($this->minimum_amount_tax, Cart::ONLY_PRODUCTS); $cartTotal = $context->cart->getOrderTotal($this->minimum_amount_tax, Cart::ONLY_PRODUCTS);
+5 -5
View File
@@ -198,7 +198,7 @@ class CurrencyCore extends ObjectModel
* *
* @return array Currencies * @return array Currencies
*/ */
static public function getCurrencies($object = false, $active = 1, Shop $shop = null) public static function getCurrencies($object = false, $active = 1, Shop $shop = null)
{ {
if (!$shop) if (!$shop)
$shop = new Shop(Context::getContext()->shop->getID(true)); $shop = new Shop(Context::getContext()->shop->getID(true));
@@ -216,7 +216,7 @@ class CurrencyCore extends ObjectModel
return $tab; return $tab;
} }
static public function getPaymentCurrenciesSpecial($id_module, $id_shop = null) public static function getPaymentCurrenciesSpecial($id_module, $id_shop = null)
{ {
if (is_null($id_shop)) if (is_null($id_shop))
$id_shop = Context::getContext()->shop->getID(); $id_shop = Context::getContext()->shop->getID();
@@ -228,7 +228,7 @@ class CurrencyCore extends ObjectModel
return Db::getInstance()->getRow($sql); return Db::getInstance()->getRow($sql);
} }
static public function getPaymentCurrencies($id_module, $id_shop = null) public static function getPaymentCurrencies($id_module, $id_shop = null)
{ {
if (is_null($id_shop)) if (is_null($id_shop))
$id_shop = Context::getContext()->shop->getID(); $id_shop = Context::getContext()->shop->getID();
@@ -244,7 +244,7 @@ class CurrencyCore extends ObjectModel
return Db::getInstance()->executeS($sql); return Db::getInstance()->executeS($sql);
} }
static public function checkPaymentCurrencies($id_module, $id_shop = null) public static function checkPaymentCurrencies($id_module, $id_shop = null)
{ {
if (is_null($id_shop)) if (is_null($id_shop))
$id_shop = Context::getContext()->shop->getID(true); $id_shop = Context::getContext()->shop->getID(true);
@@ -275,7 +275,7 @@ class CurrencyCore extends ObjectModel
return $result['id_currency']; return $result['id_currency'];
} }
static public function getIdByIsoCodeNum($iso_code) public static function getIdByIsoCodeNum($iso_code)
{ {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT `id_currency` SELECT `id_currency`
+10 -6
View File
@@ -25,6 +25,12 @@
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*/ */
/**
*
* @deprecated 1.5.0.1
* @see OrderPaymentCore
*
*/
class PaymentCCCore extends ObjectModel class PaymentCCCore extends ObjectModel
{ {
public $id_order; public $id_order;
@@ -75,15 +81,13 @@ class PaymentCCCore extends ObjectModel
* Get the detailed payment of an order * Get the detailed payment of an order
* @param int $id_order * @param int $id_order
* @return array * @return array
* @deprecated 1.5.0.1
* @see OrderPaymentCore
*/ */
public static function getByOrderId($id_order) public static function getByOrderId($id_order)
{ {
$query = ' Tools::displayAsDeprecated();
SELECT * return null;
FROM `'._DB_PREFIX_.'payment_cc`
WHERE `id_order` = '.$id_order;
return Db::getInstance()->getRow($query);
} }
} }
+13 -34
View File
@@ -32,9 +32,6 @@ abstract class PaymentModuleCore extends Module
public $currencies = true; public $currencies = true;
public $currencies_mode = 'checkbox'; public $currencies_mode = 'checkbox';
/* @var object PaymentCC */
public $pcc = null;
public function install() public function install()
{ {
if (!parent::install()) if (!parent::install())
@@ -79,18 +76,6 @@ abstract class PaymentModuleCore extends Module
return parent::uninstall(); return parent::uninstall();
} }
public function __construct()
{
$this->pcc = new PaymentCC();
parent::__construct();
}
public function __destruct()
{
unset($this->pcc);
}
/** /**
* Validate an order in database * Validate an order in database
* Function called from a payment module * Function called from a payment module
@@ -162,7 +147,6 @@ abstract class PaymentModuleCore extends Module
$order->id_address_delivery = (int)$id_address; $order->id_address_delivery = (int)$id_address;
$order->id_currency = $id_currency; $order->id_currency = $id_currency;
$order->id_lang = (int)($cart->id_lang); $order->id_lang = (int)($cart->id_lang);
$order->id_warehouse = $package_list[$id_address][$id_package]['id_warehouse']; $order->id_warehouse = $package_list[$id_address][$id_package]['id_warehouse'];
$order->id_cart = (int)($cart->id); $order->id_cart = (int)($cart->id);
$order->reference = $reference; $order->reference = $reference;
@@ -221,8 +205,19 @@ abstract class PaymentModuleCore extends Module
$order_detail = new OrderDetail(null, null, $this->context); $order_detail = new OrderDetail(null, null, $this->context);
$order_detail->createList($order, $cart, $id_order_state, $product_list); $order_detail->createList($order, $cart, $id_order_state, $product_list);
$order_detail_list[] = $order_detail; $order_detail_list[] = $order_detail;
// Adding an entry in order_carrier table
Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'order_carrier` (`id_order`, `id_carrier`, `weight`, `shipping_cost_tax_excl`, `shipping_cost_tax_incl`, `date_add`) VALUES
('.(int)$order->id.', '.(int)$carrier->id.', '.(float)$order->getTotalWeight().', '.(float)$order->total_shipping_tax_excl.', '.(float)$order->total_shipping_tax_incl.', NOW())');
} }
$this->addPCC($reference, $id_currency, $amountPaid); // Register Payment
if (!$order->addOrderPayment($amountPaid))
{
$errorMessage = Tools::displayError('Can\'t save payment');
Logger::addLog($errorMessage, 4, '0000003', 'Order', intval($order->id));
die($errorMessage);
}
// Next ! // Next !
foreach ($order_detail_list as $key => $order_detail) foreach ($order_detail_list as $key => $order_detail)
@@ -373,7 +368,7 @@ abstract class PaymentModuleCore extends Module
$new_history->changeIdOrderState((int)$id_order_state, (int)$order->id); $new_history->changeIdOrderState((int)$id_order_state, (int)$order->id);
$new_history->addWithemail(true, $extraVars); $new_history->addWithemail(true, $extraVars);
unset($order_detail, $pcc); unset($order_detail);
// Order is reloaded because the status just changed // Order is reloaded because the status just changed
$order = new Order($order->id); $order = new Order($order->id);
@@ -471,22 +466,6 @@ abstract class PaymentModuleCore extends Module
} }
} }
/**
* Add new PaymentCC to the order
* @var int id_order
* @var int id_currency
* @var float amount
*/
private function addPCC($reference, $id_currency, $amount)
{
// Other information are set by the module
$this->pcc->order_reference = (int)$reference;
$this->pcc->id_currency = (int)$id_currency;
$this->pcc->amount = (float)$amount;
$this->pcc->add();
}
/** /**
* @param Object Address $the_address that needs to be txt formated * @param Object Address $the_address that needs to be txt formated
* @return String the txt formated address block * @return String the txt formated address block
+2 -1
View File
@@ -2715,7 +2715,8 @@ class ProductCore extends ObjectModel
$resultsArray = array(); $resultsArray = array();
foreach ($result as $row) foreach ($result as $row)
{ {
$row['price'] = Product::getPriceStatic($row['id_product'], true, null, 2); $row['price_tax_incl'] = Product::getPriceStatic($row['id_product'], true, null, 2);
$row['price_tax_excl'] = Product::getPriceStatic($row['id_product'], false, null, 2);
$resultsArray[] = $row; $resultsArray[] = $row;
} }
return $resultsArray; return $resultsArray;
+210 -29
View File
@@ -91,13 +91,13 @@ class OrderCore extends ObjectModel
/** @var float Total to pay tax excluded */ /** @var float Total to pay tax excluded */
public $total_paid_tax_excl; public $total_paid_tax_excl;
/** @var float Total really paid */ /** @var float Total really paid @deprecated 1.5.0.1 */
public $total_paid_real; public $total_paid_real;
/** @var float Products total */ /** @var float Products total */
public $total_products; public $total_products;
/** @var float Products total tax excluded */ /** @var float Products total tax included */
public $total_products_wt; public $total_products_wt;
/** @var float Shipping total */ /** @var float Shipping total */
@@ -467,8 +467,14 @@ class OrderCore extends ObjectModel
'); ');
} }
/**
*
* @deprecated 1.5.0.1
* @see OrderInvoice::setProductPrices
*/
public function setProductPrices(&$row) public function setProductPrices(&$row)
{ {
//Tools::displayAsDeprecated();
$tax_calculator = OrderDetail::getTaxCalculatorStatic((int)$row['id_order_detail']); $tax_calculator = OrderDetail::getTaxCalculatorStatic((int)$row['id_order_detail']);
$row['tax_calculator'] = $tax_calculator; $row['tax_calculator'] = $tax_calculator;
$row['tax_rate'] = $tax_calculator->getTotalRate(); $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()); return ((int)(Configuration::get('PS_ORDER_RETURN')) == 1 AND (int)($this->getCurrentState()) == Configuration::get('PS_OS_DELIVERED') AND $this->getNumberOfDays());
} }
public static function getLastInvoiceNumber()
public static function getLastInvoiceNumber() {
{ return Db::getInstance()->getValue('
return (int)Db::getInstance()->getValue(' SELECT MAX(`number`)
SELECT MAX(`invoice_number`) AS `invoice_number` FROM `'._DB_PREFIX_.'order_invoice`
FROM `'._DB_PREFIX_.'orders`'); ');
} }
public function setInvoice() public function setInvoice()
{ {
$number = (int)Configuration::get('PS_INVOICE_START_NUMBER'); $order_invoice = new OrderInvoice();
if ($number) $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); Configuration::updateValue('PS_INVOICE_START_NUMBER', false);
else else
$number = '(SELECT `invoice_number` $order_invoice->number = self::getLastInvoiceNumber() + 1;
FROM (
SELECT MAX(`invoice_number`) + 1 AS `invoice_number` $order_invoice->total_discount_tax_excl = $this->total_discount_tax_excl;
FROM `'._DB_PREFIX_.'orders`) $order_invoice->total_discount_tax_incl = $this->total_discount_tax_incl;
tmp )'; $order_invoice->total_paid_tax_excl = $this->total_paid_tax_excl;
// a way to avoid duplicate invoice number $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(' Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'orders` UPDATE `'._DB_PREFIX_.'order_carrier`
SET `invoice_number` = '.$number.', `invoice_date` = \''.date('Y-m-d H:i:s').'\' SET `id_order_invoice` = '.(int)$order_invoice->id.'
WHERE `id_order` = '.(int)$this->id WHERE `id_order` = '.(int)$order_invoice->id_order);
);
$res = Db::getInstance()->getRow(' // Update order detail
SELECT `invoice_number`, `invoice_date` Db::getInstance()->execute('
FROM `'._DB_PREFIX_.'orders` UPDATE `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int)$this->id SET `id_order_invoice` = '.(int)$order_invoice->id.'
); WHERE `id_order` = '.(int)$order_invoice->id_order);
$this->invoice_date = $res['invoice_date']; $this->invoice_date = $res['invoice_date'];
$this->invoice_number = $res['invoice_number']; $this->invoice_number = $res['invoice_number'];
@@ -1070,8 +1090,14 @@ class OrderCore extends ObjectModel
return (float)($result['weight']); return (float)($result['weight']);
} }
/**
*
* @param int $id_invoice
* @deprecated 1.5.0.1
*/
public static function getInvoice($id_invoice) public static function getInvoice($id_invoice)
{ {
Tools::displayAsDeprecated();
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT `invoice_number`, `id_order` SELECT `invoice_number`, `id_order`
FROM `'._DB_PREFIX_.'orders` FROM `'._DB_PREFIX_.'orders`
@@ -1128,9 +1154,9 @@ class OrderCore extends ObjectModel
$history->id_employee = (int)$id_employee; $history->id_employee = (int)$id_employee;
$history->changeIdOrderState((int)$id_order_state, (int)$this->id); $history->changeIdOrderState((int)$id_order_state, (int)$this->id);
$res = Db::getInstance()->getRow(' $res = Db::getInstance()->getRow('
SELECT `invoice_number`, `invoice_date`, `delivery_number`, `delivery_date` SELECT `invoice_number`, `invoice_date`, `delivery_number`, `delivery_date`
FROM `'._DB_PREFIX_.'orders` FROM `'._DB_PREFIX_.'orders`
WHERE `id_order` = '.(int)$this->id); WHERE `id_order` = '.(int)$this->id);
$this->invoice_date = $res['invoice_date']; $this->invoice_date = $res['invoice_date'];
$this->invoice_number = $res['invoice_number']; $this->invoice_number = $res['invoice_number'];
$this->delivery_date = $res['delivery_date']; $this->delivery_date = $res['delivery_date'];
@@ -1156,6 +1182,7 @@ class OrderCore extends ObjectModel
/** /**
* This method return the ID of the previous order * This method return the ID of the previous order
* @since 1.5.0.1
* @return int * @return int
*/ */
public function getPreviousOrderId() public function getPreviousOrderId()
@@ -1169,6 +1196,7 @@ class OrderCore extends ObjectModel
/** /**
* This method return the ID of the next order * This method return the ID of the next order
* @since 1.5.0.1
* @return int * @return int
*/ */
public function getNextOrderId() public function getNextOrderId()
@@ -1243,9 +1271,162 @@ class OrderCore extends ObjectModel
WHERE od.`id_order` = '.(int)$this->id.' WHERE od.`id_order` = '.(int)$this->id.'
AND od.`tax_computation_method` = '.(int)TaxCalculator::ONE_AFTER_ANOTHER_METHOD 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. * Returns the correct product taxes breakdown.
+42 -20
View File
@@ -33,6 +33,9 @@ class OrderDetailCore extends ObjectModel
/** @var integer */ /** @var integer */
public $id_order; public $id_order;
/** @var integer */
public $id_order_invoice;
/** @var integer */ /** @var integer */
public $product_id; public $product_id;
@@ -133,6 +136,7 @@ class OrderDetailCore extends ObjectModel
protected $fieldsValidate = array( protected $fieldsValidate = array(
'id_order' => 'isUnsignedId', 'id_order' => 'isUnsignedId',
'id_order_invoice' => 'isUnsignedId',
'product_id' => 'isUnsignedId', 'product_id' => 'isUnsignedId',
'product_attribute_id' => 'isUnsignedId', 'product_attribute_id' => 'isUnsignedId',
'product_name' => 'isGenericName', 'product_name' => 'isGenericName',
@@ -213,6 +217,7 @@ class OrderDetailCore extends ObjectModel
$this->validateFields(); $this->validateFields();
$fields['id_order'] = (int)$this->id_order; $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_id'] = (int)$this->product_id;
$fields['product_attribute_id'] = (int)$this->product_attribute_id; $fields['product_attribute_id'] = (int)$this->product_attribute_id;
$fields['product_name'] = pSQL($this->product_name); $fields['product_name'] = pSQL($this->product_name);
@@ -229,7 +234,7 @@ class OrderDetailCore extends ObjectModel
$fields['product_ean13'] = pSQL($this->product_ean13); $fields['product_ean13'] = pSQL($this->product_ean13);
$fields['product_upc'] = pSQL($this->product_upc); $fields['product_upc'] = pSQL($this->product_upc);
$fields['product_reference'] = pSQL($this->product_reference); $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['product_weight'] = (float)$this->product_weight;
$fields['tax_name'] = pSQL($this->tax_name); $fields['tax_name'] = pSQL($this->tax_name);
$fields['tax_rate'] = (float)$this->tax_rate; $fields['tax_rate'] = (float)$this->tax_rate;
@@ -405,11 +410,11 @@ class OrderDetailCore extends ObjectModel
$this->tax_calculator = $tax_manager->getTaxCalculator(); $this->tax_calculator = $tax_manager->getTaxCalculator();
} }
$this->ecotax_tax_rate = 0; $this->ecotax_tax_rate = 0;
if (!empty($product['ecotax'])) if (!empty($product['ecotax']))
$this->ecotax_tax_rate = Tax::getProductEcotaxRate($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $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 = new Customer((int)$order->id_customer);
$customer_address = new Address((int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $customer_address = new Address((int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$this->specificPrice = SpecificPrice::getSpecificPrice((int)$product['id_product'], $this->specificPrice = SpecificPrice::getSpecificPrice(
(int)$order->id_shop, (int)$product['id_product'],
(int)$order->id_currency, (int)$order->id_shop,
(int)$customer_address->id_country, (int)$order->id_currency,
(int)$customer->id_default_group, (int)$customer_address->id_country,
(int)$product['cart_quantity']); (int)$customer->id_default_group,
(int)$product['cart_quantity']
);
$this->product_price = (float)$product['price']; $this->product_price = (float)$product['price'];
$this->unit_price_tax_incl = (float)$product['price_wt']; $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))); $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)$cart->id_currency, (int)$this->vat_address->id_country,
(int)$this->customer->id_default_group, (int)$product['cart_quantity']); (int)$this->customer->id_default_group, (int)$product['cart_quantity']);
@@ -484,10 +496,13 @@ class OrderDetailCore extends ObjectModel
* @param object $cart * @param object $cart
* @param array $product * @param array $product
* @param int $id_order_status * @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; $this->id = null;
@@ -510,13 +525,19 @@ class OrderDetailCore extends ObjectModel
$this->setVirtualProductInformation($product); $this->setVirtualProductInformation($product);
$this->checkProductStock($product, $id_order_state); $this->checkProductStock($product, $id_order_state);
$this->setProductTax($order, $product);
if ($use_taxes)
$this->setProductTax($order, $product);
$this->setDetailProductPrice($order, $cart, $product); $this->setDetailProductPrice($order, $cart, $product);
// Set order invoice id
$this->id_order_invoice = (int)$id_order_invoice;
// Add new entry to the table // Add new entry to the table
$this->save(); $this->save();
$this->saveTaxCalculator(); if ($use_taxes)
$this->saveTaxCalculator();
unset($this->tax_calculator); unset($this->tax_calculator);
} }
@@ -525,18 +546,19 @@ class OrderDetailCore extends ObjectModel
* @param object $order * @param object $order
* @param object $cart * @param object $cart
* @param int $id_order_status * @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->vat_address = new Address((int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
$this->customer = new Customer((int)($order->id_customer)); $this->customer = new Customer((int)($order->id_customer));
$this->id_order = $order->id; $this->id_order = $order->id;
$products = $product_list;
$this->outOfStock = false; $this->outOfStock = false;
foreach ($products as $product) foreach ($product_list as $product)
$this->create($order, $cart, $product, $id_order_state); $this->create($order, $cart, $product, $id_order_state, $id_order_invoice, $use_taxes);
unset($this->vat_address); unset($this->vat_address);
unset($products); unset($products);
+387
View File
@@ -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
);
}
}
+99
View File
@@ -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);
}
}
+4 -1
View File
@@ -143,10 +143,13 @@ class OrderReturnCore extends ObjectModel
($order_id ? ' AND `id_order` = '.(int)($order_id) : ''). ($order_id ? ' AND `id_order` = '.(int)($order_id) : '').
($no_denied ? ' AND `state` != 4' : '').' ($no_denied ? ' AND `state` != 4' : '').'
ORDER BY `date_add` DESC'); ORDER BY `date_add` DESC');
foreach ($data AS $k => $or) foreach ($data as $k => $or)
{ {
$state = new OrderReturnState($or['state']); $state = new OrderReturnState($or['state']);
$data[$k]['state_name'] = $state->name[$context->language->id]; $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; return $data;
} }
+1
View File
@@ -97,6 +97,7 @@ class OrderSlipCore extends ObjectModel
.($id_order_detail ? ' WHERE `id_order_detail` = '.(int)($id_order_detail) : '')); .($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) public static function getOrdersSlipProducts($orderSlipId, $order)
{ {
$cart_rules = $order->getCartRules(true); $cart_rules = $order->getCartRules(true);
+14 -12
View File
@@ -34,17 +34,18 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
public $available_in_your_account = false; public $available_in_your_account = false;
public function __construct(Order $order, $smarty) public function __construct(OrderInvoice $order_invoice, $smarty)
{ {
$this->order = $order; $this->order_invoice = $order_invoice;
$this->smarty = $smarty; $this->order = new Order($this->order_invoice->id_order);
$this->smarty = $smarty;
// header informations // header informations
$this->date = Tools::displayDate($order->invoice_date, (int)$order->id_lang); $this->date = Tools::displayDate($order_invoice->date_add, (int)$this->order->id_lang);
$this->title = self::l('Invoice ').Configuration::get('PS_INVOICE_PREFIX').sprintf('%06d', $order->invoice_number); $this->title = self::l('Invoice ').Configuration::get('PS_INVOICE_PREFIX').sprintf('%06d', $order_invoice->number);
// footer informations // footer informations
$shop = new Shop((int)$order->id_shop); $shop = new Shop((int)$this->order->id_shop);
$this->address = $shop->getAddress(); $this->address = $shop->getAddress();
} }
@@ -69,7 +70,7 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
$this->smarty->assign(array( $this->smarty->assign(array(
'order' => $this->order, 'order' => $this->order,
'order_details' => $this->order->getProducts(), 'order_details' => $this->order_invoice->getProducts(),
'delivery_address' => $formatted_delivery_address, 'delivery_address' => $formatted_delivery_address,
'invoice_address' => $formatted_invoice_address, 'invoice_address' => $formatted_invoice_address,
'tax_excluded_display' => Group::getPriceDisplayMethod($customer->id_default_group), 'tax_excluded_display' => Group::getPriceDisplayMethod($customer->id_default_group),
@@ -91,11 +92,12 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
$this->smarty->assign(array( $this->smarty->assign(array(
'tax_exempt' => $tax_exempt, 'tax_exempt' => $tax_exempt,
'use_one_after_another_method' => $this->order->useOneAfterAnotherTaxComputationMethod(), 'use_one_after_another_method' => $this->order_invoice->useOneAfterAnotherTaxComputationMethod(),
'product_tax_breakdown' => $this->order->getProductTaxesBreakdown(), 'product_tax_breakdown' => $this->order_invoice->getProductTaxesBreakdown(),
'shipping_tax_breakdown' => $this->order->getShippingTaxesBreakdown(), 'shipping_tax_breakdown' => $this->order_invoice->getShippingTaxesBreakdown($this->order),
'ecotax_tax_breakdown' => $this->order->getEcoTaxTaxesBreakdown(), 'ecotax_tax_breakdown' => $this->order_invoice->getEcoTaxTaxesBreakdown(),
'order' => $this->order, 'order' => $this->order,
'order_invoice' => $this->order_invoice
)); ));
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/invoice.tax-tab.tpl'); return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/invoice.tax-tab.tpl');
@@ -131,7 +133,7 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
*/ */
public function getFilename() public function getFilename()
{ {
return Configuration::get('PS_INVOICE_PREFIX').sprintf('%06d', $this->order->invoice_number).'.pdf'; return Configuration::get('PS_INVOICE_PREFIX').sprintf('%06d', $this->order_invoice->number).'.pdf';
} }
} }
+665 -80
View File
@@ -27,6 +27,8 @@
class AdminOrdersControllerCore extends AdminController class AdminOrdersControllerCore extends AdminController
{ {
public $toolbar_title;
public function __construct() public function __construct()
{ {
$this->table = 'order'; $this->table = 'order';
@@ -52,7 +54,8 @@ class AdminOrdersControllerCore extends AdminController
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = oh.`id_order_state`) LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = oh.`id_order_state`)
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)$this->context->language->id.')'; LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)$this->context->language->id.')';
$this->_where = 'AND oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = a.`id_order` GROUP BY moh.`id_order`)'; $this->_where = 'AND oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = a.`id_order` GROUP BY moh.`id_order`)';
$this->_orderWay = 'DESC'; $this->_orderBy = '`id_order`';
$this->_orderWay = 'DESC'; // FIXME
$statesArray = array(); $statesArray = array();
$states = OrderState::getOrderStates((int)$this->context->language->id); $states = OrderState::getOrderStates((int)$this->context->language->id);
@@ -65,7 +68,7 @@ class AdminOrdersControllerCore extends AdminController
'reference' => array('title' => $this->l('Reference'), 'align' => 'center', 'width' => 65), 'reference' => array('title' => $this->l('Reference'), 'align' => 'center', 'width' => 65),
'new' => array('title' => $this->l('New'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'filter_key' => 'new', 'tmpTableFilter' => true, 'icon' => array(0 => 'blank.gif', 1 => 'news-new.gif'), 'orderby' => false), 'new' => array('title' => $this->l('New'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'filter_key' => 'new', 'tmpTableFilter' => true, 'icon' => array(0 => 'blank.gif', 1 => 'news-new.gif'), 'orderby' => false),
'customer' => array('title' => $this->l('Customer'), 'filter_key' => 'customer', 'tmpTableFilter' => true), 'customer' => array('title' => $this->l('Customer'), 'filter_key' => 'customer', 'tmpTableFilter' => true),
'total_paid' => array('title' => $this->l('Total'), 'width' => 70, 'align' => 'right', 'prefix' => '<b>', 'suffix' => '</b>', 'type' => 'price', 'currency' => true), 'total_paid_tax_incl' => array('title' => $this->l('Total'), 'width' => 70, 'align' => 'right', 'prefix' => '<b>', 'suffix' => '</b>', 'type' => 'price', 'currency' => true),
'payment' => array('title' => $this->l('Payment'), 'width' => 100), 'payment' => array('title' => $this->l('Payment'), 'width' => 100),
'osname' => array('title' => $this->l('Status'), 'width' => 230, 'type' => 'select', 'list' => $statesArray, 'filter_key' => 'os!id_order_state', 'filter_type' => 'int', 'width' => 200), 'osname' => array('title' => $this->l('Status'), 'width' => 230, 'type' => 'select', 'list' => $statesArray, 'filter_key' => 'os!id_order_state', 'filter_type' => 'int', 'width' => 200),
'date_add' => array('title' => $this->l('Date'), 'width' => 120, 'align' => 'right', 'type' => 'datetime', 'filter_key' => 'a!date_add'), 'date_add' => array('title' => $this->l('Date'), 'width' => 120, 'align' => 'right', 'type' => 'datetime', 'filter_key' => 'a!date_add'),
@@ -82,73 +85,118 @@ class AdminOrdersControllerCore extends AdminController
parent::initForm(); parent::initForm();
$this->addJqueryPlugin(array('autocomplete', 'fancybox', 'typewatch')); $this->addJqueryPlugin(array('autocomplete', 'fancybox', 'typewatch'));
$cart = new Cart((int)Tools::getValue('id_cart')); $cart = new Cart((int)Tools::getValue('id_cart'));
$this->context->smarty->assign(array('recyclable_pack' => (int)Configuration::get('PS_RECYCLABLE_PACK'), $this->context->smarty->assign(array(
'gift_wrapping' => (int)Configuration::get('PS_GIFT_WRAPPING'), 'recyclable_pack' => (int)Configuration::get('PS_RECYCLABLE_PACK'),
'cart' => $cart, 'gift_wrapping' => (int)Configuration::get('PS_GIFT_WRAPPING'),
'currencies' => Currency::getCurrencies(), 'cart' => $cart,
'langs' => Language::getLanguages(true, Context::getContext()->shop->id), 'currencies' => Currency::getCurrencies(),
'payment_modules' => PaymentModule::getInstalledPaymentModules(), 'langs' => Language::getLanguages(true, Context::getContext()->shop->id),
'order_states' => OrderState::getOrderStates((int)Context::getContext()->cookie->id_lang))); 'payment_modules' => PaymentModule::getInstalledPaymentModules(),
'order_states' => OrderState::getOrderStates((int)Context::getContext()->cookie->id_lang)));
$this->content .= $this->context->smarty->fetch('orders/form.tpl'); $this->content .= $this->context->smarty->fetch('orders/form.tpl');
} }
public function initToolbar()
{
if ($this->display == 'view')
{
$this->toolbar_btn['new'] = array(
'short' => 'Create',
'href' => '',
'desc' => $this->l('Add a product'),
'class' => 'add_product'
);
$this->toolbar_btn['standard_refund'] = array(
'short' => 'Create',
'href' => '',
'desc' => $this->l('Standard refund'),
'class' => 'process-icon-new standard_refund'
);
$this->toolbar_btn['partial_refund'] = array(
'short' => 'Create',
'href' => '',
'desc' => $this->l('Partial refund'),
'class' => 'process-icon-new partial_refund'
);
}
return parent::initToolbar();
}
public function setMedia()
{
parent::setMedia();
$this->addJqueryUI('ui.datepicker');
if ($this->tabAccess['edit'] == 1 && $this->display == 'view')
{
$this->addJS(_PS_JS_DIR_.'admin_order.js');
$this->addJS(_PS_JS_DIR_.'tools.js');
$this->addJqueryPlugin('autocomplete');
$this->addJqueryPlugin('scrollTo');
}
}
public function printPDFIcons($id_order, $tr) public function printPDFIcons($id_order, $tr)
{ {
$order = new Order($id_order); $order = new Order($id_order);
$orderState = OrderHistory::getLastOrderState($id_order); $order_state = OrderHistory::getLastOrderState($id_order);
if (!Validate::isLoadedObject($orderState) OR !Validate::isLoadedObject($order)) if (!Validate::isLoadedObject($order_state) OR !Validate::isLoadedObject($order))
die(Tools::displayError('Invalid objects')); die(Tools::displayError('Invalid objects'));
// Generate HTML code for printing Invoice Icon with link $this->context->smarty->assign(array(
$content = '<span style="width:20px; margin-right:5px;">'; 'order' => $order,
if (($orderState->invoice && $order->invoice_number) && (int)$tr['product_number']) 'order_state' => $order_state,
$content .= '<a href="pdf.php?id_order='.(int)$order->id.'&pdf"><img src="../img/admin/tab-invoice.gif" alt="invoice" /></a>'; 'tr' => $tr
else ));
$content .= '-';
$content .= '</span>';
// Generate HTML code for printing Delivery Icon with link return $this->context->smarty->fetch('orders/_print_pdf_icon.tpl');
$content .= '<span style="width:20px;">';
if ($orderState->delivery && $order->delivery_number)
$content .= '<a href="pdf.php?id_delivery='.(int)$order->delivery_number.'"><img src="../img/admin/delivery.gif" alt="delivery" /></a>';
else
$content .= '-';
$content .= '</span>';
return $content;
} }
public function postProcess() public function postProcess()
{ {
/* Update shipping number */ /* Update shipping number */
if (Tools::isSubmit('submitShippingNumber') AND ($id_order = (int)(Tools::getValue('id_order'))) AND Validate::isLoadedObject($order = new Order($id_order))) if (Tools::isSubmit('submitShippingNumber') AND ($id_order = (int)Tools::getValue('id_order')) AND Validate::isLoadedObject($order = new Order($id_order)))
{ {
if ($this->tabAccess['edit'] === '1') if ($this->tabAccess['edit'] === '1')
{ {
if (!$order->hasBeenShipped()) if (Validate::isUrl(Tools::getValue('tracking_number')))
throw new PrestashopException('The shipping number can only be set once the order has been shipped.');
$_GET['view'.$this->table] = true;
$shipping_number = pSQL(Tools::getValue('shipping_number'));
$order->shipping_number = $shipping_number;
$order->update();
if ($shipping_number)
{ {
global $_LANGMAIL; // update shipping number
$customer = new Customer((int)($order->id_customer)); $order->shipping_number = Tools::getValue('tracking_number');
$carrier = new Carrier((int)($order->id_carrier)); if ($order->update())
if (!Validate::isLoadedObject($customer) OR !Validate::isLoadedObject($carrier)) {
die(Tools::displayError()); // Update order_carrier
$templateVars = array( $id_order_invoice = Tools::getValue('id_order_invoice');
'{followup}' => str_replace('@', $order->shipping_number, $carrier->url), $id_carrier = Tools::getValue('id_carrier');
'{firstname}' => $customer->firstname, Db::getInstance()->execute('
'{lastname}' => $customer->lastname, UPDATE `'._DB_PREFIX_.'order_carrier`
'{id_order}' => (int)($order->id) SET `tracking_number` = '.pSQL(Tools::getValue('tracking_number')).'
); WHERE `id_order` = '.(int)$order->id.
@Mail::Send((int)($order->id_lang), 'in_transit', Mail::l('Package in transit'), $templateVars, ' AND `id_carrier` = '.(int)$id_carrier.
$customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, NULL, NULL, ($id_order_invoice ? ' AND `id_order_invoice` = '.(int)$id_order_invoice : ''));
_PS_MAIL_DIR_, true);
global $_LANGMAIL;
$customer = new Customer((int)$order->id_customer);
$carrier = new Carrier((int)$order->id_carrier);
if (!Validate::isLoadedObject($customer))
throw new PrestashopException('Can\'t load Customer object');
if (!Validate::isLoadedObject($carrier))
throw new PrestashopException('Can\'t load Carrier object');
$templateVars = array(
'{followup}' => str_replace('@', $order->shipping_number, $carrier->url),
'{firstname}' => $customer->firstname,
'{lastname}' => $customer->lastname,
'{id_order}' => (int)$order->id
);
@Mail::Send((int)$order->id_lang, 'in_transit', Mail::l('Package in transit'), $templateVars,
$customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, NULL, NULL,
_PS_MAIL_DIR_, true);
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token);
}
else
$this->_errors[] = Tools::displayError('An error occured on updating of order');
} }
else
$this->_errors[] = Tools::displayError('Shipping number is incorrect');
} }
else else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.'); $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
@@ -256,11 +304,11 @@ class AdminOrdersControllerCore extends AdminController
if (Validate::isLoadedObject($order)) if (Validate::isLoadedObject($order))
{ {
$varsTpl = array( $varsTpl = array(
'{lastname}' => $customer->lastname, '{lastname}' => $customer->lastname,
'{firstname}' => $customer->firstname, '{firstname}' => $customer->firstname,
'{id_order}' => $order->id, '{id_order}' => $order->id,
'{message}' => (Configuration::get('PS_MAIL_TYPE') == 2 ? $cm->message : Tools::nl2br($cm->message)) '{message}' => (Configuration::get('PS_MAIL_TYPE') == 2 ? $cm->message : Tools::nl2br($cm->message))
); );
if (@Mail::Send((int)($order->id_lang), 'order_merchant_comment', if (@Mail::Send((int)($order->id_lang), 'order_merchant_comment',
Mail::l('New message regarding your order'), $varsTpl, $customer->email, Mail::l('New message regarding your order'), $varsTpl, $customer->email,
$customer->firstname.' '.$customer->lastname, NULL, NULL, NULL, NULL, _PS_MAIL_DIR_, true)) $customer->firstname.' '.$customer->lastname, NULL, NULL, NULL, NULL, _PS_MAIL_DIR_, true))
@@ -349,10 +397,11 @@ class AdminOrdersControllerCore extends AdminController
{ {
$reinjectableQuantity = (int)($orderDetail->product_quantity) - (int)($orderDetail->product_quantity_reinjected); $reinjectableQuantity = (int)($orderDetail->product_quantity) - (int)($orderDetail->product_quantity_reinjected);
$quantityToReinject = $qtyCancelProduct > $reinjectableQuantity ? $reinjectableQuantity : $qtyCancelProduct; $quantityToReinject = $qtyCancelProduct > $reinjectableQuantity ? $reinjectableQuantity : $qtyCancelProduct;
if (!Product::reinjectQuantities($orderDetail, $quantityToReinject)) // TODO (Denis) : fix reinject quantities
$this->_errors[] = Tools::displayError('Cannot re-stock product').' <span class="bold">'.$orderDetail->product_name.'</span>'; // if (!Product::reinjectQuantities($orderDetail, $quantityToReinject))
else // $this->_errors[] = Tools::displayError('Cannot re-stock product').' <span class="bold">'.$orderDetail->product_name.'</span>';
{ // else
// {
$updProductAttributeID = !empty($orderDetail->product_attribute_id) ? (int)($orderDetail->product_attribute_id) : NULL; $updProductAttributeID = !empty($orderDetail->product_attribute_id) ? (int)($orderDetail->product_attribute_id) : NULL;
$newProductQty = Product::getQuantity($orderDetail->product_id, $updProductAttributeID); $newProductQty = Product::getQuantity($orderDetail->product_id, $updProductAttributeID);
$product = get_object_vars(new Product($orderDetail->product_id, false, $this->context->language->id, $order->id_shop)); $product = get_object_vars(new Product($orderDetail->product_id, false, $this->context->language->id, $order->id_shop));
@@ -367,7 +416,7 @@ class AdminOrdersControllerCore extends AdminController
$product['stock_quantity'] = $updProduct['stock_quantity']; $product['stock_quantity'] = $updProduct['stock_quantity'];
} }
Hook::exec('updateQuantity', array('product' => $product, 'order' => $order)); Hook::exec('updateQuantity', array('product' => $product, 'order' => $order));
} // }
} }
// Delete product // Delete product
@@ -436,6 +485,7 @@ class AdminOrdersControllerCore extends AdminController
{ {
Message::markAsReaded($_GET['messageReaded'], $this->context->employee->id); Message::markAsReaded($_GET['messageReaded'], $this->context->employee->id);
} }
// TODO clean PaymentCC
else if (Tools::isSubmit('setTransactionId') && ((int)Tools::getValue('id_order'))) else if (Tools::isSubmit('setTransactionId') && ((int)Tools::getValue('id_order')))
{ {
$order = new Order((int)(Tools::getValue('id_order'))); $order = new Order((int)(Tools::getValue('id_order')));
@@ -449,9 +499,34 @@ class AdminOrdersControllerCore extends AdminController
unset($order, $pcc); unset($order, $pcc);
} }
else if (Tools::isSubmit('submitAddPayment'))
{
if ($this->tabAccess['edit'] === '1')
{
$order = new Order(Tools::getValue('id_order'));
$amount = str_replace(',', '.', Tools::getValue('payment_amount'));
$currency = new Currency(Tools::getValue('payment_currency'));
if (!Validate::isLoadedObject($order))
$this->_errors[] = Tools::displayError('Order can\'t be found');
elseif (!Validate::isPrice($amount))
$this->_errors[] = Tools::displayError('Amount is invalid');
elseif (!Validate::isString(Tools::getValue('payment_method')))
$this->_errors[] = Tools::displayError('Payment method is invalid');
elseif (!Validate::isString(Tools::getValue('payment_transaction_id')))
$this->_errors[] = Tools::displayError('Transaction ID is invalid');
elseif (!Validate::isLoadedObject($currency))
$this->_errors[] = Tools::displayError('Currency is invalid');
elseif (!Validate::isDate(Tools::getValue('payment_date')))
$this->_errors[] = Tools::displayError('Date is invalid');
else
if (!$order->addOrderPayment($amount, Tools::getValue('payment_method'), Tools::getValue('payment_transaction_id'), $currency, Tools::getValue('payment_date')))
$this->_errors[] = Tools::displayError('An error occured on adding of order payment');
}
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
elseif (Tools::isSubmit('submitAddOrder') == 1 && ($id_cart = Tools::getValue('id_cart')) && ($module_name = pSQL(Tools::getValue('payment_module_name'))) && ($id_order_state = Tools::getValue('id_order_state'))) elseif (Tools::isSubmit('submitAddOrder') == 1 && ($id_cart = Tools::getValue('id_cart')) && ($module_name = pSQL(Tools::getValue('payment_module_name'))) && ($id_order_state = Tools::getValue('id_order_state')))
{ {
if ($this->tabAccess['edit'] === '1') if ($this->tabAccess['edit'] === '1')
{ {
$payment_module = Module::getInstanceByName($module_name); $payment_module = Module::getInstanceByName($module_name);
@@ -463,6 +538,29 @@ class AdminOrdersControllerCore extends AdminController
else else
$this->_errors[] = Tools::displayError('You do not have permission to add here.'); $this->_errors[] = Tools::displayError('You do not have permission to add here.');
} }
elseif (Tools::isSubmit('submitAddressShipping') || Tools::isSubmit('submitAddressInvoice'))
{
if ($this->tabAccess['edit'] === '1')
{
$address = new Address(Tools::getValue('id_address'));
if (Validate::isLoadedObject($address))
{
// Update the address on order
$order = new Order(Tools::getValue('id_order'));
if (Tools::isSubmit('submitAddressShipping'))
$order->id_address_delivery = $address->id;
elseif (Tools::isSubmit('submitAddressInvoice'))
$order->id_address_invoice = $address->id;
$order->update();
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token);
}
else
$this->_errors[] = Tools::displayErrror('This address can\'t be loaded');
}
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
parent::postProcess(); parent::postProcess();
} }
@@ -470,22 +568,11 @@ class AdminOrdersControllerCore extends AdminController
{ {
$order = $this->loadObject(); $order = $this->loadObject();
if (!Validate::isLoadedObject($order)) if (!Validate::isLoadedObject($order))
return; throw new PrestashopException('object can\'t be loaded');
$customer = new Customer($order->id_customer); $customer = new Customer($order->id_customer);
$carrier = new Carrier($order->id_carrier); $carrier = new Carrier($order->id_carrier);
$products = $order->getProducts(); $products = $this->getProducts($order);
foreach ($products as &$product)
{
if ($product['image'] != null)
{
$name = 'product_mini_'.(int)$product['product_id'].(isset($product['product_attribute_id']) ? '_'.(int)$product['product_attribute_id'] : '').'.jpg';
// generate image cache, only for back office
$product['image_tag'] = cacheImage(_PS_IMG_DIR_.'p/'.$product['image']->getExistingImgPath().'.jpg', $name, 45, 'jpg');
$product['image_size'] = getimagesize(_PS_TMP_IMG_DIR_.$name);
}
}
// Carrier module call // Carrier module call
$carrier_module_call = null; $carrier_module_call = null;
@@ -514,11 +601,14 @@ class AdminOrdersControllerCore extends AdminController
$deliveryState = new State((int)($addressDelivery->id_state)); $deliveryState = new State((int)($addressDelivery->id_state));
} }
$this->toolbar_title = $this->l('Order #').sprintf('%06d', $order->id).' - '.$customer->firstname.' '.$customer->lastname;
// Smarty assign // Smarty assign
$this->tpl_view_vars = array( $this->tpl_view_vars = array(
'order' => $order, 'order' => $order,
'cart' => new Cart($order->id), 'cart' => new Cart($order->id),
'customer' => $customer, 'customer' => $customer,
'customer_addresses' => $customer->getAddresses($this->context->language->id),
'addresses' => array( 'addresses' => array(
'delivery' => $addressDelivery, 'delivery' => $addressDelivery,
'deliveryState' => isset($deliveryState) ? $deliveryState : null, 'deliveryState' => isset($deliveryState) ? $deliveryState : null,
@@ -528,6 +618,7 @@ class AdminOrdersControllerCore extends AdminController
'customerStats' => $customer->getStats(), 'customerStats' => $customer->getStats(),
'products' => $products, 'products' => $products,
'discounts' => $order->getCartRules(), 'discounts' => $order->getCartRules(),
'total_paid' => $order->getTotalPaid(),
'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id), 'returns' => OrderReturn::getOrdersReturn($order->id_customer, $order->id),
'slips' => OrderSlip::getOrdersSlip($order->id_customer, $order->id), 'slips' => OrderSlip::getOrdersSlip($order->id_customer, $order->id),
'orderMessages' => OrderMessage::getOrderMessages($order->id_lang), 'orderMessages' => OrderMessage::getOrderMessages($order->id_lang),
@@ -539,20 +630,23 @@ class AdminOrdersControllerCore extends AdminController
'sources' => ConnectionsSource::getOrderSources($order->id), 'sources' => ConnectionsSource::getOrderSources($order->id),
'currentState' => OrderHistory::getLastOrderState($order->id), 'currentState' => OrderHistory::getLastOrderState($order->id),
'currency' => new Currency($order->id_currency), 'currency' => new Currency($order->id_currency),
'currencies' => Currency::getCurrencies(),
'previousOrder' => $order->getPreviousOrderId(), 'previousOrder' => $order->getPreviousOrderId(),
'nextOrder' => $order->getNextOrderId(), 'nextOrder' => $order->getNextOrderId(),
'currentIndex' => self::$currentIndex, 'currentIndex' => self::$currentIndex,
'carrierModuleCall' => $carrier_module_call, 'carrierModuleCall' => $carrier_module_call,
'iso_code_lang' => $this->context->language->iso_code, 'iso_code_lang' => $this->context->language->iso_code,
'id_lang' => $this->context->language->id, 'id_lang' => $this->context->language->id,
'paymentCCDetails' => PaymentCC::getByOrderId($order->id), 'can_edit' => ($this->tabAccess['edit'] == 1),
'current_id_lang' => $this->context->language->id,
'invoices_collection' => $order->getInvoicesCollection(),
'HOOK_INVOICE' => Hook::exec('invoice', array('id_order' => $order->id)), 'HOOK_INVOICE' => Hook::exec('invoice', array('id_order' => $order->id)),
'HOOK_ADMIN_ORDER' => Hook::exec('adminOrder', array('id_order' => $order->id)) 'HOOK_ADMIN_ORDER' => Hook::exec('adminOrder', array('id_order' => $order->id))
); );
return parent::initView(); return parent::initView();
} }
public function ajaxProcessSearchCustomers() public function ajaxProcessSearchCustomers()
{ {
if ($customers = Customer::searchByName(pSQL(Tools::getValue('customer_search')))) if ($customers = Customer::searchByName(pSQL(Tools::getValue('customer_search'))))
@@ -571,11 +665,18 @@ class AdminOrdersControllerCore extends AdminController
{ {
foreach ($products AS &$product) foreach ($products AS &$product)
{ {
$product['price'] = Tools::displayPrice(Tools::convertPrice($product['price'], $currency), $currency); // Formatted price
$product['formatted_price'] = Tools::displayPrice(Tools::convertPrice($product['price_tax_incl'], $currency), $currency);
// Concret price
$product['price_tax_incl'] = Tools::ps_round(Tools::convertPrice($product['price_tax_incl'], $currency), 2);
$product['price_tax_excl'] = Tools::ps_round(Tools::convertPrice($product['price_tax_excl'], $currency), 2);
$productObj = new Product((int)$product['id_product'], false, (int)$this->context->language->id); $productObj = new Product((int)$product['id_product'], false, (int)$this->context->language->id);
$combinations = array(); $combinations = array();
$attributes = $productObj->getAttributesGroups((int)$this->context->language->id); $attributes = $productObj->getAttributesGroups((int)$this->context->language->id);
$product['qty_in_stock'] = StockAvailable::getQuantityAvailableByProduct((int)$product['id_product'], 0, (int)$this->context->shop->getID()); $product['qty_in_stock'] = StockAvailable::getQuantityAvailableByProduct((int)$product['id_product'], 0, (int)$this->context->shop->getID());
// Tax rate for this customer
if (Tools::isSubmit('id_address'))
$product['tax_rate'] = $productObj->getTaxesRate(new Address(Tools::getValue('id_address')));
foreach($attributes AS $attribute) foreach($attributes AS $attribute)
{ {
if (!isset($combinations[$attribute['id_product_attribute']]['attributes'])) if (!isset($combinations[$attribute['id_product_attribute']]['attributes']))
@@ -584,7 +685,13 @@ class AdminOrdersControllerCore extends AdminController
$combinations[$attribute['id_product_attribute']]['id_product_attribute'] = $attribute['id_product_attribute']; $combinations[$attribute['id_product_attribute']]['id_product_attribute'] = $attribute['id_product_attribute'];
$combinations[$attribute['id_product_attribute']]['default_on'] = $attribute['default_on']; $combinations[$attribute['id_product_attribute']]['default_on'] = $attribute['default_on'];
if (!isset($combinations[$attribute['id_product_attribute']]['price'])) if (!isset($combinations[$attribute['id_product_attribute']]['price']))
$combinations[$attribute['id_product_attribute']]['price'] = Tools::displayPrice(Tools::convertPrice(Product::getPriceStatic((int)$product['id_product'], true, $attribute['id_product_attribute']), $currency), $currency); {
$price_tax_incl = Product::getPriceStatic((int)$product['id_product'], true, $attribute['id_product_attribute']);
$price_tax_excl = Product::getPriceStatic((int)$product['id_product'], false, $attribute['id_product_attribute']);
$combinations[$attribute['id_product_attribute']]['price_tax_incl'] = Tools::ps_round(Tools::convertPrice($price_tax_incl, $currency), 2);
$combinations[$attribute['id_product_attribute']]['price_tax_excl'] = Tools::ps_round(Tools::convertPrice($price_tax_excl, $currency), 2);
$combinations[$attribute['id_product_attribute']]['formatted_price'] = Tools::displayPrice(Tools::convertPrice($price_tax_incl, $currency), $currency);
}
if (!isset($combinations[$attribute['id_product_attribute']]['qty_in_stock'])) if (!isset($combinations[$attribute['id_product_attribute']]['qty_in_stock']))
$combinations[$attribute['id_product_attribute']]['qty_in_stock']= StockAvailable::getQuantityAvailableByProduct((int)$product['id_product'], $attribute['id_product_attribute'], (int)$this->context->shop->getID()); $combinations[$attribute['id_product_attribute']]['qty_in_stock']= StockAvailable::getQuantityAvailableByProduct((int)$product['id_product'], $attribute['id_product_attribute'], (int)$this->context->shop->getID());
} }
@@ -593,8 +700,10 @@ class AdminOrdersControllerCore extends AdminController
$combination['attributes'] = rtrim($combination['attributes'], ' - '); $combination['attributes'] = rtrim($combination['attributes'], ' - ');
$product['combinations'] = $combinations; $product['combinations'] = $combinations;
} }
$to_return = array('products' => $products, $to_return = array(
'found' => true); 'products' => $products,
'found' => true
);
} }
else else
$to_return = array('found' => false); $to_return = array('found' => false);
@@ -623,4 +732,480 @@ class AdminOrdersControllerCore extends AdminController
$this->content = Tools::jsonEncode(array('errors' => true, 'result' => $this->l('Error in sending the email to your customer.'))); $this->content = Tools::jsonEncode(array('errors' => true, 'result' => $this->l('Error in sending the email to your customer.')));
} }
} }
public function ajaxProcessAddProductOnOrder()
{
// Load object
$order = new Order(Tools::getValue('id_order'));
if (!Validate::isLoadedObject($order))
die(Tools::jsonEncode(array(
'result' => false,
'error' => Tools::displayError('Can\'t load Order object')
)));
$product_informations = $_POST['add_product'];
$product = new Product($product_informations['product_id'], false, $order->id_lang);
if (!Validate::isLoadedObject($product))
die(Tools::jsonEncode(array(
'result' => false,
'error' => Tools::displayError('Can\'t load Product object')
)));
if (isset($product_informations['product_attribute_id']) && $product_informations['product_attribute_id'])
{
$combination = new Combination($product_informations['product_attribute_id']);
if (!Validate::isLoadedObject($combination))
die(Tools::jsonEncode(array(
'result' => false,
'error' => Tools::displayError('Can\'t load Combination object')
)));
}
// Create new cart
$cart = new Cart();
$cart->id_group_shop = $order->id_group_shop;
$cart->id_shop = $order->id_shop;
$cart->id_customer = $order->id_customer;
$cart->id_carrier = $order->id_carrier;
$cart->id_address_delivery = $order->id_address_delivery;
$cart->id_address_invoice = $order->id_address_invoice;
$cart->id_currency = $order->id_currency;
$cart->id_customer = $order->id_customer;
$cart->id_lang = $order->id_lang;
$cart->id_carrier = $order->id_carrier;
$cart->secure_key = $order->secure_key;
// Save new cart
$cart->add();
// Save context (in order to apply cart rule)
$this->context->cart = $cart;
$this->context->customer = new Customer($order->id_customer);
// Add product to cart
$cart->updateQty($product_informations['product_quantity'], $product->id, isset($combination) ? $combination->id : null, false, 'up', new Shop($cart->id_shop));
$use_taxes = ($order->getTaxCalculationMethod() == PS_TAX_INC);
$initial_prodcut_price_tax_incl = Product::getPriceStatic($product->id, $use_taxes, isset($combination) ? $combination->id : null, 2, null, false, true, 1,
false, $order->id_customer, $cart->id, $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
if ($product_informations['product_price_tax_incl'] < $initial_prodcut_price_tax_incl)
{
$reduction_tax_incl = $initial_prodcut_price_tax_incl - $product_informations['product_price_tax_incl'];
// FIXME Cart Rule isn't applied but correctly save in database
$cart_rule = new CartRule();
$cart_rule->id_customer = $order->id_customer;
$cart_rule->date_from = date('Y-m-d H:i:s', time());
$cart_rule->date_to = date('Y-m-d H:i:s', time() + 24 * 3600);
$cart_rule->quantity = 1;
$cart_rule->quantity_per_user = 1;
$cart_rule->minimum_amount_currency = $order->id_currency;
$cart_rule->reduction_product = $product->id;
$cart_rule->reduction_amount = $reduction_tax_incl;
$cart_rule->reduction_currency = $order->id_currency;
$cart_rule->active = 1;
$cart_rule->add();
$cart->addCartRule($cart_rule->id);
//$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
if ($order->valid)
{
$order_invoice = new OrderInvoice($product_informations['invoice']);
// Create new invoice
if ($order_invoice->id == 0)
{
// Create Cart rule in order to make free shipping
if (isset($invoice_informations['free_shipping']) && $invoice_informations['free_shipping'])
{
// FIXME Cart Rule isn't applied but correctly save in database
$cart_rule = new CartRule();
$cart_rule->id_customer = $order->id_customer;
$cart_rule->date_from = date('Y-m-d H:i:s', time());
$cart_rule->date_to = date('Y-m-d H:i:s', time() + 24 * 3600);
$cart_rule->quantity = 1;
$cart_rule->quantity_per_user = 1;
$cart_rule->minimum_amount_currency = $order->id_currency;
$cart_rule->reduction_currency = $order->id_currency;
$cart_rule->free_shipping = true;
$cart_rule->active = 1;
$cart_rule->add();
$cart->addCartRule($cart_rule->id);
//$order->addCartRule($cart_rule->id, $cart_rule->name, $cart_rule->getContextualValue(true));
}
if (Tools::isSubmit('add_invoice'))
$invoice_informations = $_POST['add_invoice'];
$order_invoice->id_order = $order->id;
if ($order_invoice->number)
Configuration::updateValue('PS_INVOICE_START_NUMBER', false);
else
$order_invoice->number = Order::getLastInvoiceNumber() + 1;
$order_invoice->total_paid_tax_excl = Tools::ps_round((float)$cart->getOrderTotal(false, Cart::BOTH), 2);
$order_invoice->total_paid_tax_incl = Tools::ps_round((float)$cart->getOrderTotal($use_taxes, Cart::BOTH), 2);
$order_invoice->total_products = (float)$cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
$order_invoice->total_products_wt = (float)$cart->getOrderTotal($use_taxes, Cart::ONLY_PRODUCTS);
$order_invoice->total_shipping_tax_excl = (float)$cart->getOrderShippingCost(null, false);
$order_invoice->total_shipping_tax_incl = (float)$cart->getOrderShippingCost();
$order_invoice->total_wrapping_tax_excl = abs($cart->getOrderTotal(false, Cart::ONLY_WRAPPING));
$order_invoice->total_wrapping_tax_incl = abs($cart->getOrderTotal($use_taxes, Cart::ONLY_WRAPPING));
// Update current order field, only shipping because other field is updated later
$order->total_shipping += (float)$cart->getOrderShippingCost();
$order->total_shipping_tax_excl += (float)$cart->getOrderShippingCost(null, false);
$order->total_shipping_tax_incl += (float)$cart->getOrderShippingCost(null, $use_taxes);
$order->total_wrapping += abs($cart->getOrderTotal($use_taxes, Cart::ONLY_WRAPPING));
$order->total_wrapping_tax_excl += abs($cart->getOrderTotal(false, Cart::ONLY_WRAPPING));
$order->total_wrapping_tax_incl += abs($cart->getOrderTotal($use_taxes, Cart::ONLY_WRAPPING));
$order_invoice->add();
// Adding an entry in order_carrier table
Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'order_carrier` (`id_order`, `id_carrier`, `id_order_invoice`, `weight`, `shipping_cost_tax_excl`, `shipping_cost_tax_incl`, `date_add`) VALUES
('.(int)$order->id.', '.(int)$order->id_carrier.', '.(int)$order_invoice->id.', '.(float)$cart->getTotalWeight().', '.(float)$cart->getOrderShippingCost(null, false).', '.(float)$cart->getOrderShippingCost(null, $use_taxes).', NOW())');
}
// Update current invoice
else
{
$order_invoice->total_paid_tax_excl += Tools::ps_round((float)($cart->getOrderTotal(false, Cart::BOTH)), 2);
$order_invoice->total_paid_tax_incl += Tools::ps_round((float)($cart->getOrderTotal($use_taxes, Cart::BOTH)), 2);
$order_invoice->total_products += (float)$cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
$order_invoice->total_products_wt += (float)$cart->getOrderTotal($use_taxes, Cart::ONLY_PRODUCTS);
$order_invoice->total_shipping_tax_excl += (float)$cart->getOrderShippingCost(null, false);
$order_invoice->total_shipping_tax_incl += (float)$cart->getOrderShippingCost(null, $use_taxes);
$order_invoice->total_wrapping_tax_excl += abs($cart->getOrderTotal(false, Cart::ONLY_WRAPPING));
$order_invoice->total_wrapping_tax_incl += abs($cart->getOrderTotal($use_taxes, Cart::ONLY_WRAPPING));
$order_invoice->update();
}
}
// Create Order detail information
$order_detail = new OrderDetail();
$order_detail->createList($order, $cart, OrderHistory::getLastOrderState($order->id), $cart->getProducts(), (isset($order_invoice) ? $order_invoice->id : 0), $use_taxes);
// update totals amount of order
$order->total_products += (float)$cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
$order->total_products_wt += (float)$cart->getOrderTotal($use_taxes, Cart::ONLY_PRODUCTS);
$order->total_paid += Tools::ps_round((float)($cart->getOrderTotal(true, Cart::BOTH)), 2);
$order->total_paid_tax_excl += Tools::ps_round((float)($cart->getOrderTotal(false, Cart::BOTH)), 2);
$order->total_paid_tax_incl += Tools::ps_round((float)($cart->getOrderTotal($use_taxes, Cart::BOTH)), 2);
// Save changes of order
$order->update();
$products = $this->getProducts($order);
// Get the last product
$product = $products[max(array_keys($products))];
// 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' => $order->getInvoicesCollection()
));
die(Tools::jsonEncode(array(
'result' => true,
'view' => $this->context->smarty->fetch('orders/_product_line.tpl'),
'can_edit' => $this->tabAccess['add'],
'order' => $order
)));
}
public function ajaxProcessLoadProductInformation()
{
$order_detail = new OrderDetail(Tools::getValue('id_order_detail'));
if (!Validate::isLoadedObject($order_detail))
die(Tools::jsonEncode(array(
'result' => false,
'error' => Tools::displayError('Can\'t load OrderDetail object')
)));
$product = new Product($order_detail->product_id);
if (!Validate::isLoadedObject($product))
die(Tools::jsonEncode(array(
'result' => false,
'error' => Tools::displayError('Can\'t load Product object')
)));
$address = new Address(Tools::getValue('id_address'));
if (!Validate::isLoadedObject($address))
die(Tools::jsonEncode(array(
'result' => false,
'error' => Tools::displayError('Can\'t load Address object')
)));
die(Tools::jsonEncode(array(
'result' => true,
'product' => $product,
'tax_rate' => $product->getTaxesRate($address),
'price_tax_incl' => Product::getPriceStatic($product->id, true, $order_detail->product_attribute_id, 2),
'price_tax_excl' => Product::getPriceStatic($product->id, false, $order_detail->product_attribute_id, 2)
)));
}
public function ajaxProcessEditProductOnOrder()
{
// Return value
$res = true;
$order_detail = new OrderDetail(Tools::getValue('product_id_order_detail'));
if (Tools::isSubmit('product_invoice'))
$order_invoice = new OrderInvoice(Tools::getValue('product_invoice'));
$this->doEditProductValidation($order_detail, isset($order_invoice) ? $order_invoice : null);
$product_price_tax_incl = Tools::ps_round(Tools::getValue('product_price_tax_incl'), 2);
$product_price_tax_excl = Tools::ps_round(Tools::getValue('product_price_tax_excl'), 2);
$total_products_tax_incl = $product_price_tax_incl * Tools::getValue('product_quantity');
$total_products_tax_excl = $product_price_tax_excl * Tools::getValue('product_quantity');
// Calculate differences of price (Before / After)
$diff_price_tax_incl = $total_products_tax_incl - $order_detail->total_price_tax_incl;
$diff_price_tax_excl = $total_products_tax_excl - $order_detail->total_price_tax_excl;
// Apply change on OrderInvoice
if (isset($order_invoice))
// If OrderInvoice to use is different, we update the old invoice and new invoice
if ($order_detail->id_order_invoice != $order_invoice->id)
{
$old_order_invoice = new OrderInvoice($order_detail->id_order_invoice);
// We remove cost of products
$old_order_invoice->total_products -= $order_detail->total_price_tax_excl;
$old_order_invoice->total_products_wt -= $order_detail->total_price_tax_incl;
$old_order_invoice->total_paid_tax_excl -= $order_detail->total_price_tax_excl;
$old_order_invoice->total_paid_tax_incl -= $order_detail->total_price_tax_incl;
$res &= $old_order_invoice->update();
// TODO remove invoice if no item ?
$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();
}
$order_detail->product_quantity = Tools::getValue('product_quantity');
// Save order detail
$res &= $order_detail->update();
// Save order invoice
if (isset($order_invoice))
$res &= $order_invoice->update();
$products = $this->getProducts($order);
// Get the last product
$product = $products[$order_detail->id];
// 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']
));
if (!$res)
die(Tools::jsonEncode(array(
'result' => $res,
'error' => Tools::displayError('Error occured on edition of this product line')
)));
die(Tools::jsonEncode(array(
'result' => $res,
'view' => $this->context->smarty->fetch('orders/_product_line.tpl'),
'can_edit' => $this->tabAccess['add'],
'invoices_collection' => $order->getInvoicesCollection(),
'order' => $order
)));
}
public function ajaxProcessDeleteProductLine()
{
$res = true;
$order_detail = new OrderDetail(Tools::getValue('id_order_detail'));
$order = new Order(Tools::getValue('id_order'));
$this->doDeleteProductLinveValidation($order_detail, $order);
// Update OrderInvoice of this OrderDetail
if ($order_detail->id_order_invoice != 0)
{
$order_invoice = new OrderInvoice($order_detail->id_order_invoice);
/*
TODO refresh total_discount
$order_invoice->total_discount_tax_excl -= ;
$order_invoice->total_discount_tax_incl -= ;
$order_invoice->total_shipping_tax_excl -= ;
$order_invoice->total_shipping_tax_incl -= ;
$order_invoice->total_wrapping_tax_excl -= ;
$order_invoice->total_wrapping_tax_incl -= ;
*/
$order_invoice->total_paid_tax_excl -= $order_detail->total_price_tax_incl;
$order_invoice->total_paid_tax_incl -= $order_detail->total_price_tax_excl;
$order_invoice->total_products -= $order_detail->total_price_tax_incl;
$order_invoice->total_products_wt -= $order_detail->total_price_tax_excl;
$res &= $order_invoice->update();
}
// Update Order
/*
* TODO
$order->total_discounts -= ;
$order->total_discounts_tax_incl -= ;
$order->total_discounts_tax_excl -= ;
$order->total_discounts_tax_excl -= ;
$order->total_shipping -= ;
$order->total_shipping_tax_incl -= ;
$order->total_shipping_tax_excl -= ;
$order->total_wrapping -= ;
$order->total_wrapping_tax_incl -= ;
$order->total_wrapping_tax_excl -= ;
*/
$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_incl;
$order->total_products_wt -= $order_detail->total_price_tax_excl;
$res &= $order->update();
// Delete OrderDetail
$res &= $order_detail->delete();
if (!$res)
die(Tools::jsonEncode(array(
'result' => $res,
'error' => Tools::displayError('Error occured on deletion of this product line')
)));
die(Tools::jsonEncode(array(
'result' => $res,
'order' => $order
)));
}
protected function doEditProductValidation(OrderDetail $order_detail, OrderInvoice $order_invoice = null)
{
if (!Validate::isLoadedObject($order_detail))
die(Tools::jsonEncode(array(
'result' => false,
'error' => Tools::displayError('Can\'t load Order Detail object')
)));
if (!empty($order_invoice) && !Validate::isLoadedObject($order_invoice))
die(Tools::jsonEncode(array(
'result' => false,
'error' => Tools::displayError('Can\'t load Invoice object')
)));
if ($order_detail->id_order != Tools::getValue('id_order'))
die(Tools::jsonEncode(array(
'result' => false,
'error' => Tools::displayError('Can\'t edit this Order Detail for this order')
)));
if ($order_invoice->id_order != Tools::getValue('id_order'))
die(Tools::jsonEncode(array(
'result' => false,
'error' => Tools::displayError('Can\'t use this invoice for this order')
)));
// Clean price
$product_price_tax_incl = str_replace(',', '.', Tools::getValue('product_price_tax_incl'));
$product_price_tax_excl = str_replace(',', '.', Tools::getValue('product_price_tax_excl'));
if (!Validate::isPrice($product_price_tax_incl) || !Validate::isPrice($product_price_tax_excl))
die(Tools::jsonEncode(array(
'result' => false,
'error' => Tools::displayError('Invalid price')
)));
if (!Validate::isUnsignedInt(Tools::getValue('product_quantity')))
die(Tools::jsonEncode(array(
'result' => false,
'error' => Tools::displayError('Invalid quantity')
)));
}
protected function doDeleteProductLinveValidation(OrderDetail $order_detail, Order $order)
{
if (!Validate::isLoadedObject($order_detail))
die(Tools::jsonEncode(array(
'result' => false,
'error' => Tools::displayError('Can\'t load Order Detail object')
)));
if (!Validate::isLoadedObject($order))
die(Tools::jsonEncode(array(
'result' => false,
'error' => Tools::displayError('Can\'t load Order object')
)));
if ($order_detail->id_order != $order->id)
die(Tools::jsonEncode(array(
'result' => false,
'error' => Tools::displayError('Can\'t delete this Order Detail for this order')
)));
}
protected function getProducts($order)
{
$products = $order->getProducts();
foreach ($products as &$product)
{
if ($product['image'] != null)
{
$name = 'product_mini_'.(int)$product['product_id'].(isset($product['product_attribute_id']) ? '_'.(int)$product['product_attribute_id'] : '').'.jpg';
// generate image cache, only for back office
$product['image_tag'] = cacheImage(_PS_IMG_DIR_.'p/'.$product['image']->getExistingImgPath().'.jpg', $name, 45, 'jpg');
$product['image_size'] = getimagesize(_PS_TMP_IMG_DIR_.$name);
}
}
return $products;
}
} }
@@ -1912,8 +1912,7 @@ class AdminProductsControllerCore extends AdminController
public function getPreviewUrl(Product $product) public function getPreviewUrl(Product $product)
{ {
$shop_url = new ShopUrl($this->context->shop->id); if (!(bool)$this->context->shop->virtual_uri)
if (!$shop_url->id && !empty($this->context->cookie->shopContext))
return false; return false;
$preview_url = $this->context->link->getProductLink( $preview_url = $this->context->link->getProductLink(
+44 -4
View File
@@ -1047,16 +1047,36 @@ CREATE TABLE `PREFIX_orders` (
INDEX `date_add`(`date_add`) INDEX `date_add`(`date_add`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `PREFIX_order_detail_tax` ( CREATE TABLE `PREFIX_order_detail_tax` (
`id_order_detail` int(11) NOT NULL, `id_order_detail` int(11) NOT NULL,
`id_tax` int(11) NOT NULL, `id_tax` int(11) NOT NULL,
`unit_amount` DECIMAL( 10,6 ) NOT NULL default '0.00', `unit_amount` DECIMAL( 10,6 ) NOT NULL default '0.00',
`total_amount` DECIMAL( 10, 6 ) NOT NULL default '0.00' `total_amount` DECIMAL( 10, 6 ) NOT NULL default '0.00'
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE `PREFIX_order_invoice` (
`id_order_invoice` int(11) NOT NULL AUTO_INCREMENT,
`id_order` int(11) NOT NULL,
`number` int(11) NOT NULL,
`total_discount_tax_excl` decimal(17,2) NOT NULL DEFAULT '0.00',
`total_discount_tax_incl` decimal(17,2) NOT NULL DEFAULT '0.00',
`total_paid_tax_excl` decimal(17,2) NOT NULL DEFAULT '0.00',
`total_paid_tax_incl` decimal(17,2) NOT NULL DEFAULT '0.00',
`total_products` decimal(17,2) NOT NULL DEFAULT '0.00',
`total_products_wt` decimal(17,2) NOT NULL DEFAULT '0.00',
`total_shipping_tax_excl` decimal(17,2) NOT NULL DEFAULT '0.00',
`total_shipping_tax_incl` decimal(17,2) NOT NULL DEFAULT '0.00',
`total_wrapping_tax_excl` decimal(17,2) NOT NULL DEFAULT '0.00',
`total_wrapping_tax_incl` decimal(17,2) NOT NULL DEFAULT '0.00',
`date_add` datetime NOT NULL,
PRIMARY KEY (`id_order_invoice`),
KEY `id_order` (`id_order`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE `PREFIX_order_detail` ( CREATE TABLE `PREFIX_order_detail` (
`id_order_detail` int(10) unsigned NOT NULL auto_increment, `id_order_detail` int(10) unsigned NOT NULL auto_increment,
`id_order` int(10) unsigned NOT NULL, `id_order` int(10) unsigned NOT NULL,
`id_order_invoice` int(11) default NULL,
`product_id` int(10) unsigned NOT NULL, `product_id` int(10) unsigned NOT NULL,
`product_attribute_id` int(10) unsigned default NULL, `product_attribute_id` int(10) unsigned default NULL,
`product_name` varchar(255) NOT NULL, `product_name` varchar(255) NOT NULL,
@@ -1183,6 +1203,8 @@ CREATE TABLE `PREFIX_order_slip` (
`id_customer` int(10) unsigned NOT NULL, `id_customer` int(10) unsigned NOT NULL,
`id_order` int(10) unsigned NOT NULL, `id_order` int(10) unsigned NOT NULL,
`shipping_cost` tinyint(3) unsigned NOT NULL default '0', `shipping_cost` tinyint(3) unsigned NOT NULL default '0',
`amount` DECIMAL(10,2) NOT NULL,
`shipping_cost_amount` DECIMAL(10,2) NOT NULL,
`date_add` datetime NOT NULL, `date_add` datetime NOT NULL,
`date_upd` datetime NOT NULL, `date_upd` datetime NOT NULL,
PRIMARY KEY (`id_order_slip`), PRIMARY KEY (`id_order_slip`),
@@ -1194,6 +1216,7 @@ CREATE TABLE `PREFIX_order_slip_detail` (
`id_order_slip` int(10) unsigned NOT NULL, `id_order_slip` int(10) unsigned NOT NULL,
`id_order_detail` int(10) unsigned NOT NULL, `id_order_detail` int(10) unsigned NOT NULL,
`product_quantity` int(10) unsigned NOT NULL default '0', `product_quantity` int(10) unsigned NOT NULL default '0',
`amount` DECIMAL(10,2) NOT NULL,
PRIMARY KEY (`id_order_slip`,`id_order_detail`) PRIMARY KEY (`id_order_slip`,`id_order_detail`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
@@ -1250,18 +1273,21 @@ CREATE TABLE `PREFIX_page_viewed` (
PRIMARY KEY (`id_page`, `id_date_range`, `id_shop`) PRIMARY KEY (`id_page`, `id_date_range`, `id_shop`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE `PREFIX_payment_cc` ( CREATE TABLE `PREFIX_order_payment` (
`id_payment_cc` INT NOT NULL auto_increment, `id_order_payment` INT NOT NULL auto_increment,
`id_order_invoice` INT UNSIGNED NULL,
`id_order` INT UNSIGNED NULL, `id_order` INT UNSIGNED NULL,
`id_currency` INT UNSIGNED NOT NULL, `id_currency` INT UNSIGNED NOT NULL,
`amount` DECIMAL(10,2) NOT NULL, `amount` DECIMAL(10,2) NOT NULL,
`payment_method` varchar(255) NOT NULL,
`conversion_rate` decimal(13,6) NOT NULL DEFAULT 1,
`transaction_id` VARCHAR(254) NULL, `transaction_id` VARCHAR(254) NULL,
`card_number` VARCHAR(254) NULL, `card_number` VARCHAR(254) NULL,
`card_brand` VARCHAR(254) NULL, `card_brand` VARCHAR(254) NULL,
`card_expiration` CHAR(7) NULL, `card_expiration` CHAR(7) NULL,
`card_holder` VARCHAR(254) NULL, `card_holder` VARCHAR(254) NULL,
`date_add` DATETIME NOT NULL, `date_add` DATETIME NOT NULL,
PRIMARY KEY (`id_payment_cc`), PRIMARY KEY (`id_order_payment`),
KEY `id_order` (`id_order`) KEY `id_order` (`id_order`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
@@ -2245,3 +2271,17 @@ CREATE TABLE `PREFIX_accounting_product_zone_shop` (
PRIMARY KEY (`id_accounting_product_zone_shop`), PRIMARY KEY (`id_accounting_product_zone_shop`),
UNIQUE KEY `id_product` (`id_product`,`id_shop`,`id_zone`) UNIQUE KEY `id_product` (`id_product`,`id_shop`,`id_zone`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE `PREFIX_order_carrier` (
`id_order` int(11) unsigned NOT NULL,
`id_carrier` int(11) unsigned NOT NULL,
`id_order_invoice` int(11) unsigned DEFAULT NULL,
`weight` float DEFAULT NULL,
`shipping_cost_tax_excl` decimal(20,6) DEFAULT NULL,
`shipping_cost_tax_incl` decimal(20,6) DEFAULT NULL,
`tracking_number` int(11) unsigned DEFAULT NULL,
`date_add` datetime NOT NULL,
KEY `id_order` (`id_order`,`id_carrier`),
KEY `id_order_2` (`id_order`),
KEY `id_order_invoice` (`id_order_invoice`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
+6
View File
@@ -180,8 +180,11 @@ INSERT INTO `PREFIX_order_detail` (`id_order_detail`, `id_order`, `product_id`,
VALUES (1, 1, 7, 23, 'iPod touch - Capacité: 32Go', 1, 0, '392.140500', '0.000000', NULL, NULL, NULL, 0, '0.00', '', 0, '0000-00-00 00:00:00', ''); VALUES (1, 1, 7, 23, 'iPod touch - Capacité: 32Go', 1, 0, '392.140500', '0.000000', NULL, NULL, NULL, 0, '0.00', '', 0, '0000-00-00 00:00:00', '');
INSERT INTO `PREFIX_order_detail` (`id_order_detail`, `id_order`, `product_id`, `product_attribute_id`, `product_name`, `product_quantity`, `product_quantity_return`, `product_price`, `product_quantity_discount`, `product_ean13`, `product_reference`, `product_supplier_reference`, `product_weight`, `ecotax`, `download_hash`, `download_nb`, `download_deadline`, `tax_name`) INSERT INTO `PREFIX_order_detail` (`id_order_detail`, `id_order`, `product_id`, `product_attribute_id`, `product_name`, `product_quantity`, `product_quantity_return`, `product_price`, `product_quantity_discount`, `product_ean13`, `product_reference`, `product_supplier_reference`, `product_weight`, `ecotax`, `download_hash`, `download_nb`, `download_deadline`, `tax_name`)
VALUES (2, 1, 9, 0, 'Écouteurs à isolation sonore Shure SE210', 1, 0, '124.581900', '0.000000', NULL, NULL, NULL, 0, '0.00', '', 0, '0000-00-00 00:00:00', ''); VALUES (2, 1, 9, 0, 'Écouteurs à isolation sonore Shure SE210', 1, 0, '124.581900', '0.000000', NULL, NULL, NULL, 0, '0.00', '', 0, '0000-00-00 00:00:00', '');
INSERT INTO `PREFIX_order_history` (`id_order_history`, `id_employee`, `id_order`, `id_order_state`, `date_add`) VALUES (1, 0, 1, 1, NOW()); INSERT INTO `PREFIX_order_history` (`id_order_history`, `id_employee`, `id_order`, `id_order_state`, `date_add`) VALUES (1, 0, 1, 1, NOW());
INSERT INTO `PREFIX_order_payment` (`id_order`, `id_currency`, `amount`, `payment_method`, `date_add`) VALUES (1, 1, '625.98', 'Chèque', NOW());
INSERT INTO `PREFIX_manufacturer` (`id_manufacturer`, `name`, `date_add`, `date_upd`, `active`) VALUES (1, 'Apple Computer, Inc', NOW(), NOW(), 1); INSERT INTO `PREFIX_manufacturer` (`id_manufacturer`, `name`, `date_add`, `date_upd`, `active`) VALUES (1, 'Apple Computer, Inc', NOW(), NOW(), 1);
INSERT INTO `PREFIX_manufacturer` (`id_manufacturer`, `name`, `date_add`, `date_upd`, `active`) VALUES(2, 'Shure Incorporated', NOW(), NOW(), 1); INSERT INTO `PREFIX_manufacturer` (`id_manufacturer`, `name`, `date_add`, `date_upd`, `active`) VALUES(2, 'Shure Incorporated', NOW(), NOW(), 1);
@@ -1367,3 +1370,6 @@ INSERT INTO `PREFIX_stock_available` (`id_stock_available`, `id_product`, `id_pr
(28, 6, 0, 1, 4, 0, 2), (28, 6, 0, 1, 4, 0, 2),
(29, 8, 0, 1, 8, 0, 2), (29, 8, 0, 1, 8, 0, 2),
(30, 9, 0, 1, 15, 0, 2); (30, 9, 0, 1, 15, 0, 2);
INSERT INTO `PREFIX_order_carrier` (`id_order`, `id_carrier`, `date_add`) VALUES
(1, 2, NOW());
+45 -1
View File
@@ -239,6 +239,33 @@ ALTER TABLE `PREFIX_carrier` ADD `position` INT( 10 ) UNSIGNED NOT NULL DEFAULT
ALTER TABLE `PREFIX_order_state` ADD COLUMN `shipped` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0 AFTER `delivery`; ALTER TABLE `PREFIX_order_state` ADD COLUMN `shipped` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0 AFTER `delivery`;
UPDATE `PREFIX_order_state` SET `shipped` = 1 WHERE id_order_states IN (4, 5); UPDATE `PREFIX_order_state` SET `shipped` = 1 WHERE id_order_states IN (4, 5);
CREATE TABLE `PREFIX_order_invoice` (
`id_order_invoice` int(11) NOT NULL AUTO_INCREMENT,
`id_order` int(11) NOT NULL,
`number` int(11) NOT NULL,
`total_discount_tax_excl` decimal(17,2) NOT NULL DEFAULT '0.00',
`total_discount_tax_incl` decimal(17,2) NOT NULL DEFAULT '0.00',
`total_paid_tax_excl` decimal(17,2) NOT NULL DEFAULT '0.00',
`total_paid_tax_incl` decimal(17,2) NOT NULL DEFAULT '0.00',
`total_products` decimal(17,2) NOT NULL DEFAULT '0.00',
`total_products_wt` decimal(17,2) NOT NULL DEFAULT '0.00',
`total_shipping_tax_excl` decimal(17,2) NOT NULL DEFAULT '0.00',
`total_shipping_tax_incl` decimal(17,2) NOT NULL DEFAULT '0.00',
`total_wrapping_tax_excl` decimal(17,2) NOT NULL DEFAULT '0.00',
`total_wrapping_tax_incl` decimal(17,2) NOT NULL DEFAULT '0.00',
`date_add` datetime NOT NULL,
PRIMARY KEY (`id_order_invoice`),
KEY `id_order` (`id_order`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
ALTER TABLE `PREFIX_order_detail` ADD `id_order_invoice` int(11) NULL AFTER `id_order`;
ALTER TABLE `PREFIX_payment_cc` CHANGE `id_payment_cc` `id_order_payment` INT NOT NULL auto_increment;
ALTER TABLE `PREFIX_payment_cc` ADD `id_order_invoice` varchar(255) NOT NULL AFTER `id_order_payment`;
ALTER TABLE `PREFIX_payment_cc` ADD `payment_method` varchar(255) NOT NULL AFTER `amount`;
ALTER TABLE `PREFIX_payment_cc` ADD `conversion_rate` decimal(13,6) NOT NULL DEFAULT 1 AFTER `payment_method`;
RENAME TABLE `PREFIX_payment_cc` TO `PREFIX_order_payment`;
ALTER TABLE `PREFIX_carrier` ALTER TABLE `PREFIX_carrier`
ADD COLUMN `max_width` int(10) DEFAULT 0 AFTER `position`, ADD COLUMN `max_width` int(10) DEFAULT 0 AFTER `position`,
@@ -264,7 +291,6 @@ ALTER TABLE `PREFIX_customization` ADD COLUMN `id_address_delivery` int(10) UNSI
DROP PRIMARY KEY, DROP PRIMARY KEY,
ADD PRIMARY KEY USING BTREE(`id_customization`, `id_cart`, `id_product`, `id_address_delivery`); ADD PRIMARY KEY USING BTREE(`id_customization`, `id_cart`, `id_product`, `id_address_delivery`);
CREATE TABLE `PREFIX_cart_rule` ( CREATE TABLE `PREFIX_cart_rule` (
`id_cart_rule` int(10) unsigned NOT NULL auto_increment, `id_cart_rule` int(10) unsigned NOT NULL auto_increment,
`id_customer` int unsigned NOT NULL default 0, `id_customer` int unsigned NOT NULL default 0,
@@ -582,3 +608,21 @@ UPDATE `PREFIX_tab` SET `class_name` = 'AdminCmsContent' WHERE `class_name` = 'A
UPDATE `PREFIX_tab` SET `class_name` = 'AdminCms' WHERE `class_name` = 'AdminCMS'; UPDATE `PREFIX_tab` SET `class_name` = 'AdminCms' WHERE `class_name` = 'AdminCMS';
UPDATE `PREFIX_tab` SET `class_name` = 'AdminCmsCategories' WHERE `class_name` = 'AdminCMSCategories'; UPDATE `PREFIX_tab` SET `class_name` = 'AdminCmsCategories' WHERE `class_name` = 'AdminCMSCategories';
UPDATE `PREFIX_tab` SET `class_name` = 'AdminPdf' WHERE `class_name` = 'AdminPDF'; UPDATE `PREFIX_tab` SET `class_name` = 'AdminPdf' WHERE `class_name` = 'AdminPDF';
CREATE TABLE `PREFIX_order_carrier` (
`id_order` int(11) unsigned NOT NULL,
`id_carrier` int(11) unsigned NOT NULL,
`id_order_invoice` int(11) unsigned DEFAULT NULL,
`weight` float DEFAULT NULL,
`shipping_cost_tax_excl` decimal(20,6) DEFAULT NULL,
`shipping_cost_tax_incl` decimal(20,6) DEFAULT NULL,
`tracking_number` int(11) unsigned DEFAULT NULL,
`date_add` datetime NOT NULL,
KEY `id_order` (`id_order`,`id_carrier`),
KEY `id_order_2` (`id_order`),
KEY `id_order_invoice` (`id_order_invoice`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
ALTER TABLE `PREFIX_order_slip` ADD COLUMN `amount` DECIMAL(10,2) NOT NULL AFTER `shipping_cost`;
ALTER TABLE `PREFIX_order_slip` ADD COLUMN `shipping_cost_amount` DECIMAL(10,2) NOT NULL AFTER `amount`;
ALTER TABLE `PREFIX_order_slip_detail` ADD COLUMN `amount` DECIMAL(10,2) NOT NULL AFTER `product_quantity`;
+621
View File
@@ -0,0 +1,621 @@
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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: 10575 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
var current_product = null;
$(document).ready(function() {
$('.add_product').click(function() {
$('.cancel_product_change_link:visible').trigger('click');
$('tr#new_product').slideDown('fast', function () {
$('tr#new_product td').fadeIn('fast');
});
$.scrollTo('tr#new_product', 1200, {offset: -100});
return false;
});
$("#add_product_product_name").autocomplete(admin_order_tab_link,
{
minChars: 3,
max: 10,
width: 500,
selectFirst: false,
scroll: false,
dataType: "json",
highlightItem: true,
formatItem: function(data, i, max, value, term) {
return value;
},
parse: function(data) {
var products = new Array();
for (var i = 0; i < data.products.length; i++)
products[i] = { data: data.products[i], value: data.products[i].name };
return products;
},
extraParams: {
ajax: true,
token: token,
action: 'searchProducts',
id_lang: id_lang,
id_currency: id_currency,
id_address: id_address,
product_search: function() { return $('#add_product_product_name').val(); }
}
}
)
.result(function(event, data, formatted) {
if (!data)
{
$('tr#new_product input, tr#new_product select').each(function() {
if ($(this).attr('id') != 'add_product_product_name')
$('tr#new_product input, tr#new_product select').attr('disabled', 'disabled');
});
}
else
{
$('tr#new_product input, tr#new_product select').removeAttr('disabled');
// Keep product variable
current_product = data;
$('#add_product_product_id').val(data.id_product);
$('#add_product_product_name').val(data.name);
$('#add_product_product_price_tax_incl').val(data.price_tax_incl);
$('#add_product_product_price_tax_excl').val(data.price_tax_excl);
addProductRefreshTotal();
$('#add_product_product_stock').html(data.qty_in_stock);
if (current_product.combinations.length !== 0)
{
// Reset combinations list
$('select#add_product_product_attribute_id').html('');
$.each(current_product.combinations, function() {
$('select#add_product_product_attribute_id').append('<option value="'+this.id_product_attribute+'"'+(this.default_on == 1 ? ' selected="selected"' : '')+'>'+this.attributes+'</option>');
if (this.default_on == 1)
$('#add_product_product_stock').html(this.qty_in_stock);
});
// Show select list
$('#add_product_product_attribute_area').show();
}
else
{
// Reset combinations list
$('select#add_product_product_attribute_id').html('');
// Hide select list
$('#add_product_product_attribute_area').hide();
}
}
});
$('select#add_product_product_attribute_id').change(function() {
$('#add_product_product_price_tax_incl').val(current_product.combinations[$(this).val()].price_tax_incl);
$('#add_product_product_price_tax_excl').val(current_product.combinations[$(this).val()].price_tax_excl);
addProductRefreshTotal();
$('#add_product_product_stock').html(current_product.combinations[$(this).val()].qty_in_stock);
});
$('input#add_product_product_quantity').keyup(function() {
var quantity = parseInt($(this).val());
if (quantity < 1 || isNaN(quantity))
quantity = 1;
var stock_available = parseInt($('#add_product_product_stock').html());
// total update
addProductRefreshTotal();
// stock status update
if (quantity > stock_available)
$('#add_product_product_stock').css('font-weight', 'bold').css('color', 'red').css('font-size', '1.2em');
else
$('#add_product_product_stock').css('font-weight', 'normal').css('color', 'black').css('font-size', '1em');;
});
$('#submitAddProduct').click(function() {
var go = true;
if ($('input#add_product_product_id').val() == 0)
{
alert(txt_add_product_no_product);
go = false;
}
if ($('input#add_product_product_quantity').val() == 0)
{
alert(txt_add_product_no_product_quantity);
go = false;
}
if ($('input#add_product_product_price_excl').val() == 0)
{
alert(txt_add_product_no_product_price);
go = false;
}
if (go)
{
if (parseInt($('input#add_product_product_quantity').val()) > parseInt($('#add_product_product_stock').html()))
go = confirm(txt_add_product_stock_issue);
if (go && $('select#add_product_product_invoice').val() == 0)
go = confirm(txt_add_product_new_invoice);
if (go)
{
var query = 'ajax=1&token='+token+'&action=addProductOnOrder&id_order='+id_order+'&';
query += $('tr#new_product select, tr#new_product input').serialize();
if ($('select#add_product_product_invoice').val() == 0)
query += '&'+$('tr#new_invoice select, tr#new_invoice input').serialize();
$.ajax({
type: 'POST',
url: admin_order_tab_link,
cache: false,
dataType: 'json',
data : query,
success : function(data)
{
if (data.result)
{
addViewOrderDetailRow(data.view);
updateAmounts(data.order);
}
else
alert(data.error);
}
});
}
}
});
$('#edit_shipping_cost_link').click(function() {
$('#shipping_cost_show').hide();
$('#shipping_cost_edit').show();
$('#edit_shipping_cost_link').hide();
$('#cancel_shipping_cost_link').show();
return false;
});
$('#cancel_shipping_cost_link').click(function() {
$('#shipping_cost_show').show();
$('#shipping_cost_edit').hide();
$('#edit_shipping_cost_link').show();
$('#cancel_shipping_cost_link').hide();
return false;
});
$('.edit_shipping_number_link').click(function() {
$(this).parent().find('.shipping_number_show').hide();
$(this).parent().find('.shipping_number_edit').show();
$(this).parent().find('.edit_shipping_number_link').hide();
$(this).parent().find('.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();
$(this).parent().find('.edit_shipping_number_link').show();
$(this).parent().find('.cancel_shipping_number_link').hide();
return false;
});
$('#add_product_product_invoice').change(function() {
if ($(this).val() == '0')
$('#new_invoice').slideDown('slow');
else
$('#new_invoice').slideUp('slow');
});
$('#add_product_product_price_tax_excl').keyup(function() {
var price_tax_excl = parseFloat($(this).val());
if (price_tax_excl < 0 || isNaN(price_tax_excl))
price_tax_excl = 0;
var tax_rate = current_product.tax_rate / 100 + 1;
$('#add_product_product_price_tax_incl').val(ps_round(price_tax_excl * tax_rate, 2));
// Update total product
addProductRefreshTotal();
});
$('#add_product_product_price_tax_incl').keyup(function() {
var price_tax_incl = parseFloat($(this).val());
if (price_tax_incl < 0 || isNaN(price_tax_incl))
price_tax_incl = 0;
var tax_rate = current_product.tax_rate / 100 + 1;
$('#add_product_product_price_tax_excl').val(ps_round(price_tax_incl / tax_rate, 2));
// Update total product
addProductRefreshTotal();
});
$('.edit_product_change_link').click(function() {
$('.cancel_product_change_link:visible').trigger('click');
closeAddProduct();
query = 'ajax=1&token='+token+'&action=loadProductInformation&id_order_detail='+
$(this).parent().parent().find('input.edit_product_id_order_detail').val()+'&id_address='+id_address;
var element = $(this);
$.ajax({
type: 'POST',
url: admin_order_tab_link,
cache: false,
dataType: 'json',
data : query,
success : function(data)
{
if (data.result)
{
current_product = data;
element.parent().parent().css('background-color', '#E8EDC2');
element.parent().parent().find('td .product_price_show').hide();
element.parent().parent().find('td .product_quantity_show').hide();
element.parent().parent().find('td .product_price_edit').parent().attr('align', 'left');
element.parent().parent().find('td .product_price_edit').show();
element.parent().parent().find('td .product_quantity_edit').show();
element.parent().parent().find('td.cancelCheck').hide();
element.parent().parent().find('td.cancelQuantity').hide();
element.parent().parent().find('td.product_invoice').show();
element.parent().children('.delete_product_line').hide();
element.parent().children('.edit_product_change_link').hide();
element.parent().children('input[name=submitProductChange]').show();
element.parent().children('.cancel_product_change_link').show();
}
else
alert(data.error);
}
});
return false;
});
$('.cancel_product_change_link').click(function() {
current_product = null;
$(this).parent().parent().css('background-color', '#FFF');
$(this).parent().parent().find('td .product_price_show').show();
$(this).parent().parent().find('td .product_quantity_show').show();
$(this).parent().parent().find('td .product_price_edit').parent().attr('align', 'center');
$(this).parent().parent().find('td .product_price_edit').hide();
$(this).parent().parent().find('td .product_quantity_edit').hide();
$(this).parent().parent().find('td.product_invoice').hide();
$(this).parent().parent().find('td.cancelCheck').show();
$(this).parent().parent().find('td.cancelQuantity').show();
$(this).parent().children('.delete_product_line').show();
$(this).parent().children('.edit_product_change_link').show();
$(this).parent().children('input[name=submitProductChange]').hide();
$(this).parent().children('.cancel_product_change_link').hide();
return false;
});
$('input[name=submitProductChange]').click(function() {
if ($(this).parent().parent().find('td .edit_product_quantity').val() <= 0)
{
alert(txt_add_product_no_product_quantity);
return false;
}
if ($(this).parent().parent().find('td .edit_product_price').val() <= 0)
{
alert(txt_add_product_no_product_price);
return false;
}
if (confirm(txt_confirm))
{
var element = $(this);
query = 'ajax=1&token='+token+'&action=editProductOnOrder&id_order='+id_order+'&'+
element.parent().parent().find('input:visible, select:visible, input.edit_product_id_order_detail').serialize();
$.ajax({
type: 'POST',
url: admin_order_tab_link,
cache: false,
dataType: 'json',
data : query,
success : function(data)
{
if (data.result)
{
refreshProductLineView(element, data.view);
updateAmounts(data.order);
}
else
alert(data.error);
}
});
}
return false;
});
$('.edit_product_price_tax_excl').keyup(function() {
var price_tax_excl = parseFloat($(this).val());
if (price_tax_excl < 0 || isNaN(price_tax_excl))
price_tax_excl = 0;
var tax_rate = current_product.tax_rate / 100 + 1;
$('.edit_product_price_tax_incl:visible').val(ps_round(price_tax_excl * tax_rate, 2));
// Update total product
editProductRefreshTotal($(this));
});
$('.edit_product_price_tax_incl').keyup(function() {
var price_tax_incl = parseFloat($(this).val());
if (price_tax_incl < 0 || isNaN(price_tax_incl))
price_tax_incl = 0;
var tax_rate = current_product.tax_rate / 100 + 1;
$('.edit_product_price_tax_excl:visible').val(ps_round(price_tax_incl / tax_rate, 2));
// Update total product
editProductRefreshTotal($(this));
});
$('.edit_product_quantity').keyup(function() {
var quantity = parseInt($(this).val());
if (quantity < 1 || isNaN(quantity))
quantity = 1;
var stock_available = parseInt($(this).parent().parent().parent().find('td.product_stock').html());
// total update
editProductRefreshTotal($(this));
});
$('.delete_product_line').click(function() {
if (!confirm(txt_confirm))
return false;
var tr_product = $(this).parent().parent();
var id_order_detail = $(this).parent().parent().find('td .edit_product_id_order_detail').val();
var query = 'ajax=1&action=deleteProductLine&token='+token+'&id_order_detail='+id_order_detail+'&id_order='+id_order;
$.ajax({
type: 'POST',
url: admin_order_tab_link,
cache: false,
dataType: 'json',
data : query,
success : function(data)
{
if (data.result)
{
tr_product.fadeOut('slow', function() {
$(this).remove();
});
updateAmounts(data.order);
}
else
alert(data.error);
}
});
return false;
});
});
function addProductRefreshTotal()
{
var quantity = parseInt($('#add_product_product_quantity').val());
if (quantity < 1|| isNaN(quantity))
quantity = 1;
if (use_taxes)
var price = parseFloat($('#add_product_product_price_tax_incl').val());
else
var price = parseFloat($('#add_product_product_price_tax_excl').val());
if (price < 0 || isNaN(price))
price = 0;
var total = makeTotalProductCaculation(quantity, price);
$('#add_product_product_total').html(formatCurrency(total, currency_format, currency_sign, currency_blank));
}
function editProductRefreshTotal(element)
{
element = element.parent().parent().parent();
var quantity = parseInt(element.find('td .edit_product_quantity').val());
if (quantity < 1 || isNaN(quantity))
quantity = 1;
if (use_taxes)
var price = parseFloat(element.find('td .edit_product_price_tax_incl').val());
else
var price = parseFloat(element.find('td .edit_product_price_tax_excl').val())
if (price < 0 || isNaN(price))
price = 0;
var total = makeTotalProductCaculation(quantity, price);
element.find('td.total_product').html(formatCurrency(total, currency_format, currency_sign, currency_blank));
}
function makeTotalProductCaculation(quantity, price)
{
return Math.round(quantity * price * 100) / 100;
}
function addViewOrderDetailRow(view)
{
html = $(view);
html.find('td').hide();
$('tr#new_invoice').hide();
$('tr#new_product').hide();
// Initialize fields
closeAddProduct();
$('tr#new_product').before(html);
html.find('td').each(function() {
if (!$(this).is('.product_invoice'))
$(this).fadeIn('slow');
});
}
function refreshProductLineView(element, view)
{
var new_product_line = $(view);
new_product_line.find('td').hide();
var current_product_line = element.parent().parent();
current_product_line.before(new_product_line);
current_product_line.remove();
new_product_line.find('td').each(function() {
if (!$(this).is('.product_invoice'))
$(this).fadeIn('slow');
});
}
function updateAmounts(order)
{
$('#total_products td:last').fadeOut('slow', function() {
$(this).html(formatCurrency(parseFloat(order.total_products_wt), currency_format, currency_sign, currency_blank));
$(this).fadeIn('slow');
});
$('#total_discounts td:last').fadeOut('slow', function() {
$(this).html(formatCurrency(parseFloat(order.total_discounts_tax_incl), currency_format, currency_sign, currency_blank));
$(this).fadeIn('slow');
});
if (order.total_discounts_tax_incl > 0)
$('#total_discounts').slideDown('slow');
$('#total_wrapping td:last').fadeOut('slow', function() {
$(this).html(formatCurrency(parseFloat(order.total_wrapping_tax_incl), currency_format, currency_sign, currency_blank));
$(this).fadeIn('slow');
});
if (order.total_wrapping_tax_incl > 0)
$('#total_wrapping').slideDown('slow');
$('#total_shipping td:last').fadeOut('slow', function() {
$(this).html(formatCurrency(parseFloat(order.total_shipping_tax_incl), currency_format, currency_sign, currency_blank));
$(this).fadeIn('slow');
});
$('#total_order td:last').fadeOut('slow', function() {
$(this).html(formatCurrency(parseFloat(order.total_paid_tax_incl), currency_format, currency_sign, currency_blank));
$(this).fadeIn('slow');
});
$('.total_paid').fadeOut('slow', function() {
$(this).html(formatCurrency(parseFloat(order.total_paid_tax_incl), currency_format, currency_sign, currency_blank));
$(this).fadeIn('slow');
});
$('.alert').slideDown('slow');
$('#product_number').fadeOut('slow', function() {
var old_quantity = parseInt($(this).html());
$(this).html(old_quantity + 1);
$(this).fadeIn('slow');
});
}
function closeAddProduct()
{
$('tr#new_invoice').hide();
$('tr#new_product').hide();
// Initialize fields
$('tr#new_product select, tr#new_product input').each(function() {
if (!$(this).is('.button'))
$(this).val('')
});
$('tr#new_invoice select, tr#new_invoice input').val('');
$('#add_product_product_quantity').val('1');
$('#add_product_product_attribute_id option').remove();
$('#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;
});
});
+52
View File
@@ -24,6 +24,58 @@
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*/ */
function formatedNumberToFloat(price, currencyFormat, currencySign)
{
price = price.replace(currencySign, '');
if (currencyFormat == 1)
return parseFloat(price.replace(',', '').replace(' ', ''));
else if (currencyFormat == 2)
return parseFloat(price.replace(' ', '').replace(',', '.'));
else if (currencyFormat == 3)
return parseFloat(price.replace('.', '').replace(' ', '').replace(',', '.'));
else if (currencyFormat == 4)
return parseFloat(price.replace(',', '').replace(' ', ''));
return price;
}
//return a formatted number
function formatNumber(value, numberOfDecimal, thousenSeparator, virgule)
{
value = value.toFixed(numberOfDecimal);
var val_string = value+'';
var tmp = val_string.split('.');
var abs_val_string = (tmp.length == 2) ? tmp[0] : val_string;
var deci_string = ('0.' + (tmp.length == 2 ? tmp[1] : 0)).substr(2);
var nb = abs_val_string.length;
for (var i = 1 ; i < 4; i++)
if (value >= Math.pow(10, (3 * i)))
abs_val_string = abs_val_string.substring(0, nb - (3 * i)) + thousenSeparator + abs_val_string.substring(nb - (3 * i));
if (parseInt(numberOfDecimal) == 0)
return abs_val_string;
return abs_val_string + virgule + (deci_string > 0 ? deci_string : '00');
}
function formatCurrency(price, currencyFormat, currencySign, currencyBlank)
{
// if you modified this function, don't forget to modify the PHP function displayPrice (in the Tools.php class)
blank = '';
price = parseFloat(price.toFixed(6));
price = ps_round(price, priceDisplayPrecision);
if (currencyBlank > 0)
blank = ' ';
if (currencyFormat == 1)
return currencySign + blank + formatNumber(price, priceDisplayPrecision, ',', '.');
if (currencyFormat == 2)
return (formatNumber(price, priceDisplayPrecision, ' ', ',') + blank + currencySign);
if (currencyFormat == 3)
return (currencySign + blank + formatNumber(price, priceDisplayPrecision, '.', ','));
if (currencyFormat == 4)
return (formatNumber(price, priceDisplayPrecision, ',', '.') + blank + currencySign);
return price;
}
function ps_round(value, precision) function ps_round(value, precision)
{ {
if (typeof(roundMode) == 'undefined') if (typeof(roundMode) == 'undefined')
+28
View File
@@ -301,6 +301,34 @@
</tbody> </tbody>
</table> </table>
</div> </div>
<div class="table_block">
{if $order->getShipping()|count > 0}
<table class="std">
<thead>
<tr>
<th class="first_item">{l s='Date'}</th>
<th class="item">{l s='Carrier'}</th>
<th class="item">{l s='Weight'}</th>
<th class="item">{l s='Shipping cost'}</th>
<th class="last_item">{l s='Tracking number'}</th>
</tr>
</thead>
<tbody>
{foreach from=$order->getShipping() item=line}
<tr class="item">
<td>{$line.date_add}</td>
<td>{$line.state_name}</td>
<td>{$line.weight|string_format:"%.3f"} {Configuration::get('PS_WEIGHT_UNIT')}</td>
<td>{if $order->getTaxCalculationMethod() == $smarty.const.PS_TAX_INC}{displayPrice price=$line.shipping_cost_tax_incl currency=$currency->id}{else}{displayPrice price=$line.shipping_cost_tax_excl currency=$currency->id}{/if}</td>
<td>
<span id="shipping_number_show">{if $line.url && $line.tracking_number}<a href="{$line.url|replace:'@':$line.tracking_number}">{$line.tracking_number}</a>{else}{$line.tracking_number}{/if}</span>
</td>
</tr>
{/foreach}
</tbody>
</table>
{/if}
</div>
<br /> <br />
{if !$is_guest} {if !$is_guest}
{if $return_allowed} {if $return_allowed}
+1 -1
View File
@@ -33,7 +33,7 @@
<tr style="line-height:6px;background-color:{cycle values='#FFF,#DDD'};"> <tr style="line-height:6px;background-color:{cycle values='#FFF,#DDD'};">
<td style="width: 30%">{l s='Shipping' pdf='true'}</td> <td style="width: 30%">{l s='Shipping' pdf='true'}</td>
<td style="width: 20%">{$shipping_tax_infos.rate}</td> <td style="width: 20%">{$shipping_tax_infos.rate}</td>
<td style="width: 20%">{displayPrice currency=$order->id_currency price=$order->total_shipping_tax_excl}</td> <td style="width: 20%">{displayPrice currency=$order->id_currency price=$order_invoice->total_shipping_tax_excl}</td>
<td style="width: 20%; text-align: right;">{displayPrice currency=$order->id_currency price=$shipping_tax_infos.total_amount}</td> <td style="width: 20%; text-align: right;">{displayPrice currency=$order->id_currency price=$shipping_tax_infos.total_amount}</td>
</tr> </tr>
{/foreach} {/foreach}
+15 -15
View File
@@ -130,66 +130,66 @@
</table> </table>
<table style="width: 100%"> <table style="width: 100%">
{if (($order->total_paid_tax_incl - $order->total_paid_tax_excl) > 0)} {if (($order_invoice->total_paid_tax_incl - $order_invoice->total_paid_tax_excl) > 0)}
<tr style="line-height:5px;"> <tr style="line-height:5px;">
<td style="width: 85%; text-align: right; font-weight: bold">{l s='Product Total (Tax Excl.)' pdf='true'}</td> <td style="width: 85%; text-align: right; font-weight: bold">{l s='Product Total (Tax Excl.)' pdf='true'}</td>
<td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=$order->total_products}</td> <td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=$order_invoice->total_products}</td>
</tr> </tr>
<tr style="line-height:5px;"> <tr style="line-height:5px;">
<td style="width: 85%; text-align: right; font-weight: bold">{l s='Product Total (Tax Incl.)' pdf='true'}</td> <td style="width: 85%; text-align: right; font-weight: bold">{l s='Product Total (Tax Incl.)' pdf='true'}</td>
<td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=$order->total_products_wt}</td> <td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=$order_invoice->total_products_wt}</td>
</tr> </tr>
{else} {else}
<tr style="line-height:5px;"> <tr style="line-height:5px;">
<td style="width: 85%; text-align: right; font-weight: bold">{l s='Product Total' pdf='true'}</td> <td style="width: 85%; text-align: right; font-weight: bold">{l s='Product Total' pdf='true'}</td>
<td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=$order->total_products}</td> <td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=$order_invoice->total_products}</td>
</tr> </tr>
{/if} {/if}
{if $order->total_discounts_tax_incl > 0} {if $order_invoice->total_discount_tax_incl > 0}
<tr style="line-height:5px;"> <tr style="line-height:5px;">
<td style="text-align: right; font-weight: bold">{l s='Total Vouchers' pdf='true'}</td> <td style="text-align: right; font-weight: bold">{l s='Total Vouchers' pdf='true'}</td>
<td style="width: 15%; text-align: right;">-{displayPrice currency=$order->id_currency price=$order->total_discounts_tax_incl}</td> <td style="width: 15%; text-align: right;">-{displayPrice currency=$order->id_currency price=$order_invoice->total_discount_tax_incl}</td>
</tr> </tr>
{/if} {/if}
{if $order->total_wrapping_tax_incl > 0} {if $order_invoice->total_wrapping_tax_incl > 0}
<tr style="line-height:5px;"> <tr style="line-height:5px;">
<td style="text-align: right; font-weight: bold">{l s='Wrapping Cost' pdf='true'}</td> <td style="text-align: right; font-weight: bold">{l s='Wrapping Cost' pdf='true'}</td>
<td style="width: 15%; text-align: right;"> <td style="width: 15%; text-align: right;">
{if $tax_excluded_display} {if $tax_excluded_display}
{displayPrice currency=$order->id_currency price=$order->total_wrapping_tax_excl} {displayPrice currency=$order->id_currency price=$order_invoice->total_wrapping_tax_excl}
{else} {else}
{displayPrice currency=$order->id_currency price=$order->total_wrapping_tax_incl} {displayPrice currency=$order->id_currency price=$order_invoice->total_wrapping_tax_incl}
{/if} {/if}
</td> </td>
</tr> </tr>
{/if} {/if}
{if $order->total_shipping_tax_incl > 0} {if $order_invoice->total_shipping_tax_incl > 0}
<tr style="line-height:5px;"> <tr style="line-height:5px;">
<td style="text-align: right; font-weight: bold">{l s='Shipping Cost' pdf='true'}</td> <td style="text-align: right; font-weight: bold">{l s='Shipping Cost' pdf='true'}</td>
<td style="width: 15%; text-align: right;"> <td style="width: 15%; text-align: right;">
{if $tax_excluded_display} {if $tax_excluded_display}
{displayPrice currency=$order->id_currency price=$order->total_shipping_tax_excl} {displayPrice currency=$order->id_currency price=$order_invoice->total_shipping_tax_excl}
{else} {else}
{displayPrice currency=$order->id_currency price=$order->total_shipping_tax_incl} {displayPrice currency=$order->id_currency price=$order_invoice->total_shipping_tax_incl}
{/if} {/if}
</td> </td>
</tr> </tr>
{/if} {/if}
{if ($order->total_paid_tax_incl - $order->total_paid_tax_excl) > 0} {if ($order_invoice->total_paid_tax_incl - $order_invoice->total_paid_tax_excl) > 0}
<tr style="line-height:5px;"> <tr style="line-height:5px;">
<td style="text-align: right; font-weight: bold">{l s='Total Tax' pdf='true'}</td> <td style="text-align: right; font-weight: bold">{l s='Total Tax' pdf='true'}</td>
<td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=($order->total_paid_tax_incl - $order->total_paid_tax_excl)}</td> <td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=($order_invoice->total_paid_tax_incl - $order_invoice->total_paid_tax_excl)}</td>
</tr> </tr>
{/if} {/if}
<tr style="line-height:5px;"> <tr style="line-height:5px;">
<td style="text-align: right; font-weight: bold">{l s='Total' pdf='true'}</td> <td style="text-align: right; font-weight: bold">{l s='Total' pdf='true'}</td>
<td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=$order->total_paid_tax_incl}</td> <td style="width: 15%; text-align: right;">{displayPrice currency=$order->id_currency price=$order_invoice->total_paid_tax_incl}</td>
</tr> </tr>
</table> </table>