diff --git a/admin-dev/themes/template/orders/_new_product.tpl b/admin-dev/themes/template/orders/_new_product.tpl index b8f62abba..7ddee6c8c 100644 --- a/admin-dev/themes/template/orders/_new_product.tpl +++ b/admin-dev/themes/template/orders/_new_product.tpl @@ -16,7 +16,7 @@ 0 {displayPrice price=0 currency=$currency->id} - {if $order->valid} + {if sizeof($invoices_collection)} € {if $can_edit} - {if $order->hasBeenPaid()} + {if sizeof($invoices_collection)} - {foreach from=$states item=state} - - {/foreach} - - - - - -
- - - - {foreach from=$history item=row key=key} - {if ($key == 0)} - - - - - - - {else} - - - - - - - {/if} - {/foreach} -
{dateFormat date=$row['date_add'] full=true}{$row['ostate_name']|stripslashes}{if $row['employee_lastname']}{$row['employee_firstname']|stripslashes} {$row['employee_lastname']|stripslashes}{/if}
{dateFormat date=$row['date_add'] full=true}{$row['ostate_name']|stripslashes}{if $row['employee_lastname']}{$row['employee_firstname']|stripslashes} {$row['employee_lastname']|stripslashes}{/if}
- - {if $customer->id} - -
-
- {l s='Customer information'} - {$customer->firstname} {$customer->lastname} ({l s='#'}{$customer->id})
- ({$customer->email})

- {if ($customer->isGuest())} - {l s='This order has been placed by a'} {l s='guest'} - {if (!Customer::customerExists($customer->email))} -
- -

- {l s='This feature will generate a random password and send an e-mail to the customer'} -
- {else} -
{l s='A registered customer account exists with the same email address'}
- {/if} - {else} - {l s='Account registered:'} {dateFormat date=$customer->date_add full=true}
- {l s='Valid orders placed:'} {$customerStats['nb_orders']}
- {l s='Total paid since registration:'} {displayPrice price=Tools::ps_round(Tools::convertPrice($customerStats['total_orders'], $currency), 2) currency=$currency->id}
-
- {/if} - {/if} - - - {if (sizeof($sources))} -
-
- {l s='Sources'} - -
- {/if} - - - {if $HOOK_ADMIN_ORDER} - {$HOOK_ADMIN_ORDER} - {/if} - - - - -
- -
- {l s='Documents'} - - - - - - - - - - - {foreach from=$order->getDocuments() item=document} - - - - - - {foreachelse} - - - - {/foreach} - -
DateDocumentNumber
{dateFormat date=$document->date_add}Invoice#{Configuration::get('PS_INVOICE_PREFIX', $current_id_lang)}{'%06d'|sprintf:$document->number}
{l s='No document is available'}
-
-
- - -
- {l s='Payment'} - - {if !$order->valid} -
-

{l s='Don\'t forget to update your conversion rate before make this change.'}

- - + {foreach from=$states item=state} + + {/foreach} - + + +
-
+
+ + + + {foreach from=$history item=row key=key} + {if ($key == 0)} + + + + + + + {else} + + + + + + + {/if} + {/foreach} +
{dateFormat date=$row['date_add'] full=true}{$row['ostate_name']|stripslashes}{if $row['employee_lastname']}{$row['employee_firstname']|stripslashes} {$row['employee_lastname']|stripslashes}{/if}
{dateFormat date=$row['date_add'] full=true}{$row['ostate_name']|stripslashes}{if $row['employee_lastname']}{$row['employee_firstname']|stripslashes} {$row['employee_lastname']|stripslashes}{/if}
+ + {if $customer->id} + +
+
+ {l s='Customer information'} + {$customer->firstname} {$customer->lastname} ({l s='#'}{$customer->id})
+ ({$customer->email})

+ {if ($customer->isGuest())} + {l s='This order has been placed by a'} {l s='guest'} + {if (!Customer::customerExists($customer->email))} +
+ +

+ {l s='This feature will generate a random password and send an e-mail to the customer'} +
+ {else} +
{l s='A registered customer account exists with the same email address'}
+ {/if} + {else} + {l s='Account registered:'} {dateFormat date=$customer->date_add full=true}
+ {l s='Valid orders placed:'} {$customerStats['nb_orders']}
+ {l s='Total paid since registration:'} {displayPrice price=Tools::ps_round(Tools::convertPrice($customerStats['total_orders'], $currency), 2) currency=$currency->id}
+
+ {/if} {/if} -

- {l s='Warning:'} {displayPrice price=$total_paid currency=$currency->id} - {l s='paid instead of'} {displayPrice price=$order->total_paid_tax_incl currency=$currency->id} -

+ + {if (sizeof($sources))} +
+
+ {l s='Sources'} + +
+ {/if} -
- + + {if $HOOK_ADMIN_ORDER} + {$HOOK_ADMIN_ORDER} + {/if} + + + + +
+ +
+ {l s='Documents'} + +
- - - - - + + + - {foreach from=$order->getOrderPaymentCollection() item=payment} + {foreach from=$order->getDocuments() item=document} - - - - - + + + + + {foreachelse} + + {/foreach} - - - - - - -
{l s='Date'}{l s='Payment method'}{l s='Transaction ID'}{l s='Amount'} DateDocumentNumber
{dateFormat date=$payment->date_add full=true}{$payment->payment_method}{$payment->transaction_id}{displayPrice price=$payment->amount currency=$payment->id_currency}{dateFormat date=$document->date_add}Invoice#{Configuration::get('PS_INVOICE_PREFIX', $current_id_lang)}{'%06d'|sprintf:$document->number}
+

{l s='No document is available'}

+

{l s='Generate invoice'}

+
- - - - - - -
-
-
-
+ +
- -
- {l s='Shipping'} + +
+ {l s='Payment'} -
- {l s='Recycled package:'} - {if $order->recyclable} - - {else} - + {if !$order->valid} +
+

{l s='Don\'t forget to update your conversion rate before make this change.'}

+ + + +
+
{/if} -
-
- {l s='Gift wrapping:'} - {if $order->gift} - -
-
- {if $order->gift_message} -
{l s='Message:'}
{$order->gift_message|nl2br}
+ +

+ {l s='Warning:'} {displayPrice price=$total_paid currency=$currency->id} + {l s='paid instead of'} {displayPrice price=$order->total_paid_tax_incl currency=$currency->id} +

+ +
+ + + + + + + + + + + + {foreach from=$order->getOrderPaymentCollection() item=payment} + + + + + + + + {/foreach} + + + + + + + + +
{l s='Date'}{l s='Payment method'}{l s='Transaction ID'}{l s='Amount'} 
{dateFormat date=$payment->date_add full=true}{$payment->payment_method}{$payment->transaction_id}{displayPrice price=$payment->amount currency=$payment->id_currency}
+ + + + + + +
+
+
+
+ + +
+ {l s='Shipping'} + +
+ {l s='Recycled package:'} + {if $order->recyclable} + + {else} + {/if} - {else} - +
+
+ {l s='Gift wrapping:'} + {if $order->gift} + +
+
+ {if $order->gift_message} +
{l s='Message:'}
{$order->gift_message|nl2br}
+ {/if} + {else} + + {/if} +
+
+ + + + + + + + + + + + + + {foreach from=$order->getShipping() item=line} + + + + + + + + + {/foreach} + +
{l s='Date:'}{l s='Type'}{l s='Carrier'}{l s='Weight'}{l s='Shipping cost'}{l s='Tracking number'}
{$line.date_add}{$line.type}{$line.state_name}{$line.weight|string_format:"%.3f"} {Configuration::get('PS_WEIGHT_UNIT')}{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} + {if $line.url && $line.tracking_number}{$line.tracking_number}{else}{$line.tracking_number}{/if} + {if $line.can_edit} +
+ + {l s='Edit'} + +
+ {/if} +
+ + {if $carrierModuleCall} + {$carrierModuleCall} {/if} -
-
+ +
- - - - - - - - - - - - - {foreach from=$order->getShipping() item=line} - - - - - - - - - {/foreach} - -
{l s='Date:'}{l s='Type'}{l s='Carrier'}{l s='Weight'}{l s='Shipping cost'}{l s='Tracking number'}
{$line.date_add}{$line.type}{$line.state_name}{$line.weight|string_format:"%.3f"} {Configuration::get('PS_WEIGHT_UNIT')}{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} - {if $line.url && $line.tracking_number}{$line.tracking_number}{else}{$line.tracking_number}{/if} - {if $line.can_edit} -
- - {l s='Edit'} - -
- {/if} -
+ +
+ {l s='Merchandise returns'} - {if $carrierModuleCall} - {$carrierModuleCall} - {/if} -
+ {if $order->getReturn()|count > 0} + + + + + + + + + + + {foreach from=$order->getReturn() item=line} + + + + + + + {/foreach} + +
DateTypeCarrierTracking number
{$line.date_add}{$line.type}{$line.state_name} + {if $line.url && $line.tracking_number}{$line.tracking_number}{else}{$line.tracking_number}{/if} + {if $line.can_edit} +
+ + {l s='Edit'} + +
+ {/if} +
+ {else} + {l s='No merchandise returns yet.'} + {/if} - -
- {l s='Merchandise returns'} - - {if $order->getReturn()|count > 0} - - - - - - - - - - - {foreach from=$order->getReturn() item=line} - - - - - - - {/foreach} - -
DateTypeCarrierTracking number
{$line.date_add}{$line.type}{$line.state_name} - {if $line.url && $line.tracking_number}{$line.tracking_number}{else}{$line.tracking_number}{/if} - {if $line.can_edit} -
- - {l s='Edit'} - -
- {/if} -
- {else} - {l s='No merchandise returns yet.'} - {/if} - - {if $carrierModuleCall} - {$carrierModuleCall} - {/if} -
+ {if $carrierModuleCall} + {$carrierModuleCall} + {/if} + + + +
- -
- -
- -
- {l s='Shipping address'}{l s='Shipping address'} +
+ +
+ +
+ {l s='Shipping address'}{l s='Shipping address'} - {if $can_edit} -
-
-

- - -

+ {if $can_edit} + +
+

+ + +

+
+ + {/if} + +
+ +
- - {/if} -
- - -
+ {displayAddressDetail address=$addresses.delivery newLine='
'} + {if $addresses.delivery->other}
{$addresses.delivery->other}
{/if} +
+
- {displayAddressDetail address=$addresses.delivery newLine='
'} - {if $addresses.delivery->other}
{$addresses.delivery->other}
{/if} -
-
+
+ +
+ {l s='Invoice address'}{l s='Invoice address'} -
- -
- {l s='Invoice address'}{l s='Invoice address'} + {if $can_edit} +
+
+

+ + +

+
+
+ {/if} - {if $can_edit} -
-
-

- - -

+
+
- - {/if} -
- -
- - {displayAddressDetail address=$addresses.invoice newLine='
'} - {if $addresses.invoice->other}
{$addresses.invoice->other}
{/if} -
+ {displayAddressDetail address=$addresses.invoice newLine='
'} + {if $addresses.invoice->other}
{$addresses.invoice->other}
{/if} +
+
+
-
-
+
{l s='Products'}{l s='Products'} @@ -551,28 +559,28 @@
- + total_discounts_tax_incl == 0}style="display: none;"{/if}> - + total_wrapping_tax_incl == 0}style="display: none;"{/if}> - + - + - - + diff --git a/classes/order/Order.php b/classes/order/Order.php index 639e0dfd1..86d667192 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -993,45 +993,51 @@ class OrderCore extends ObjectModel '); } + /** + * This method allows to generate first invoice of the current order + */ public function setInvoice() { - $order_invoice = new OrderInvoice(); - $order_invoice->id_order = $this->id; - $order_invoice->number = Configuration::get('PS_INVOICE_START_NUMBER'); - // If invoice start number has been set, you clean the value of this configuration - if ($order_invoice->number) - Configuration::updateValue('PS_INVOICE_START_NUMBER', false); - else - $order_invoice->number = self::getLastInvoiceNumber() + 1; + if (!$this->hasInvoice()) + { + $order_invoice = new OrderInvoice(); + $order_invoice->id_order = $this->id; + $order_invoice->number = Configuration::get('PS_INVOICE_START_NUMBER'); + // If invoice start number has been set, you clean the value of this configuration + if ($order_invoice->number) + Configuration::updateValue('PS_INVOICE_START_NUMBER', false); + else + $order_invoice->number = self::getLastInvoiceNumber() + 1; - $order_invoice->total_discount_tax_excl = $this->total_discount_tax_excl; - $order_invoice->total_discount_tax_incl = $this->total_discount_tax_incl; - $order_invoice->total_paid_tax_excl = $this->total_paid_tax_excl; - $order_invoice->total_paid_tax_incl = $this->total_paid_tax_incl; - $order_invoice->total_products = $this->total_products; - $order_invoice->total_products_wt = $this->total_products_wt; - $order_invoice->total_shipping_tax_excl = $this->total_shipping_tax_excl; - $order_invoice->total_shipping_tax_incl = $this->total_shipping_tax_incl; - $order_invoice->total_wrapping_tax_excl = $this->total_wrapping_tax_excl; - $order_invoice->total_wrapping_tax_incl = $this->total_wrapping_tax_incl; + $order_invoice->total_discount_tax_excl = $this->total_discount_tax_excl; + $order_invoice->total_discount_tax_incl = $this->total_discount_tax_incl; + $order_invoice->total_paid_tax_excl = $this->total_paid_tax_excl; + $order_invoice->total_paid_tax_incl = $this->total_paid_tax_incl; + $order_invoice->total_products = $this->total_products; + $order_invoice->total_products_wt = $this->total_products_wt; + $order_invoice->total_shipping_tax_excl = $this->total_shipping_tax_excl; + $order_invoice->total_shipping_tax_incl = $this->total_shipping_tax_incl; + $order_invoice->total_wrapping_tax_excl = $this->total_wrapping_tax_excl; + $order_invoice->total_wrapping_tax_incl = $this->total_wrapping_tax_incl; - // Save Order invoice - $order_invoice->add(); + // Save Order invoice + $order_invoice->add(); - // Update order_carrier - Db::getInstance()->execute(' - UPDATE `'._DB_PREFIX_.'order_carrier` - SET `id_order_invoice` = '.(int)$order_invoice->id.' - WHERE `id_order` = '.(int)$order_invoice->id_order); + // Update order_carrier + Db::getInstance()->execute(' + UPDATE `'._DB_PREFIX_.'order_carrier` + SET `id_order_invoice` = '.(int)$order_invoice->id.' + WHERE `id_order` = '.(int)$order_invoice->id_order); - // Update order detail - Db::getInstance()->execute(' - UPDATE `'._DB_PREFIX_.'order_detail` - SET `id_order_invoice` = '.(int)$order_invoice->id.' - WHERE `id_order` = '.(int)$order_invoice->id_order); + // Update order detail + Db::getInstance()->execute(' + UPDATE `'._DB_PREFIX_.'order_detail` + SET `id_order_invoice` = '.(int)$order_invoice->id.' + WHERE `id_order` = '.(int)$order_invoice->id_order); - $this->invoice_date = $res['invoice_date']; - $this->invoice_number = $res['invoice_number']; + $this->invoice_date = $res['invoice_date']; + $this->invoice_number = $res['invoice_number']; + } } public function setDelivery() @@ -1519,5 +1525,18 @@ class OrderCore extends ObjectModel WHERE `id_order` = '.(int)$this->id ); } + + /** + * + * Has invoice return true if this order has already an invoice + * @return bool + */ + public function hasInvoice() + { + return Db::getInstance()->getValue(' + SELECT COUNT(*) + FROM `'._DB_PREFIX_.'order_invoice` + WHERE `id_order` = '.(int)$this->id); + } } diff --git a/classes/order/OrderInvoice.php b/classes/order/OrderInvoice.php index cf260b03d..43aabf12c 100644 --- a/classes/order/OrderInvoice.php +++ b/classes/order/OrderInvoice.php @@ -225,7 +225,7 @@ class OrderInvoiceCore extends ObjectModel if ($row['reduction_amount'] != 0) { - if ($this->_taxCalculationMethod == PS_TAX_EXC) + if ($order->getTaxCalculationMethod() == 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); @@ -233,7 +233,7 @@ class OrderInvoiceCore extends ObjectModel if ($row['group_reduction'] > 0) { - if ($this->_taxCalculationMethod == PS_TAX_EXC) + if ($order->getTaxCalculationMethod() == 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); diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index ba0359ee6..5ac90d091 100755 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -634,13 +634,13 @@ class AdminOrdersControllerCore extends AdminController $payment->amount = Tools::convertPriceFull((float)$payment->amount, $old_currency, $currency); $payment->update(); } - + $order_carrier = Db::getInstance()->getRow(' SELECT * FROM `'._DB_PREFIX_.'order_carrier` WHERE `id_order` = '.(int)$order->id); - - // Update order carrier amount + + // Update order carrier amount Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'order_carrier` SET `shipping_cost_tax_excl` = '.(float)Tools::convertPriceFull($order_carrier['shipping_cost_tax_excl'], $old_currency, $currency).', @@ -675,6 +675,20 @@ class AdminOrdersControllerCore extends AdminController else $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } + elseif (Tools::isSubmit('submitGenerateInvoice')) + { + $order = new Order(Tools::getValue('id_order')); + if (!Validate::isLoadedObject($order)) + throw new PrestashopException('Order can\'t be loaded'); + + if ($order->hasInvoice()) + $this->_errors[] = Tools::displayError('This order has already invoice'); + else + { + $order->setInvoice(); + Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token); + } + } parent::postProcess(); }
{l s='Products'}{l s='Products'} {displayPrice price=$order->total_products_wt currency=$currency->id}
{l s='Discounts'}{l s='Discounts'} -{displayPrice price=$order->total_discounts_tax_incl currency=$currency->id}
{l s='Wrapping'}{l s='Wrapping'} {displayPrice price=$order->total_wrapping_tax_incl currency=$currency->id}
{l s='Shipping'}{l s='Shipping'} {displayPrice price=$order->total_shipping_tax_incl currency=$currency->id}
{l s='Total'} + {l s='Total'} {displayPrice price=$order->total_paid_tax_incl currency=$currency->id}