[-] BO : #PSCFV-3112 - Fix bug with payment by cheque and multishipping
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@16294 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -82,12 +82,12 @@
|
||||
--
|
||||
{else}
|
||||
{displayPrice price=$document->total_paid_tax_incl currency=$currency->id}
|
||||
{if $document->getGlobalRestPaid()}
|
||||
{if $document->getTotalPaid()}
|
||||
<span style="color:red;font-weight:bold;">
|
||||
{if $document->getGlobalRestPaid() >= 0}
|
||||
({displayPrice price=$document->getGlobalRestPaid() currency=$currency->id} {l s='not paid'})
|
||||
{else}
|
||||
({displayPrice price=-$document->getGlobalRestPaid() currency=$currency->id} {l s='overpaid'})
|
||||
{if $document->getRestPaid() > 0}
|
||||
({displayPrice price=$document->getRestPaid() currency=$currency->id} {l s='not paid'})
|
||||
{else if $document->getRestPaid() < 0}
|
||||
({displayPrice price=-$document->getRestPaid() currency=$currency->id} {l s='overpaid'})
|
||||
{/if}
|
||||
</span>
|
||||
{/if}
|
||||
|
||||
@@ -531,7 +531,7 @@ abstract class PaymentModuleCore extends Module
|
||||
// So you migth have two order states
|
||||
$new_history = new OrderHistory();
|
||||
$new_history->id_order = (int)$order->id;
|
||||
$new_history->changeIdOrderState((int)$id_order_state, (int)$order->id);
|
||||
$new_history->changeIdOrderState((int)$id_order_state, (int)$order->id, true);
|
||||
$new_history->addWithemail(true, $extra_vars);
|
||||
|
||||
unset($order_detail);
|
||||
|
||||
+19
-16
@@ -1070,8 +1070,8 @@ class OrderCore extends ObjectModel
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getLastInvoiceNumber()
|
||||
{
|
||||
public static function getLastInvoiceNumber()
|
||||
{
|
||||
return Db::getInstance()->getValue('
|
||||
SELECT MAX(`number`)
|
||||
FROM `'._DB_PREFIX_.'order_invoice`
|
||||
@@ -1081,7 +1081,7 @@ class OrderCore extends ObjectModel
|
||||
/**
|
||||
* This method allows to generate first invoice of the current order
|
||||
*/
|
||||
public function setInvoice()
|
||||
public function setInvoice($use_existing_payment = false)
|
||||
{
|
||||
if (!$this->hasInvoice())
|
||||
{
|
||||
@@ -1129,19 +1129,22 @@ class OrderCore extends ObjectModel
|
||||
WHERE `id_order` = '.(int)$order_invoice->id_order);
|
||||
|
||||
// Update order payment
|
||||
$id_order_payment = Db::getInstance()->getValue('
|
||||
SELECT id_order_payment FROM `'._DB_PREFIX_.'order_payment` op
|
||||
INNER JOIN `'._DB_PREFIX_.'orders` o
|
||||
ON o.reference = op.order_reference
|
||||
WHERE id_order = '.(int)$order_invoice->id_order);
|
||||
|
||||
if ($id_order_payment)
|
||||
Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'order_invoice_payment`
|
||||
SET
|
||||
`id_order_invoice` = '.(int)$order_invoice->id.',
|
||||
`id_order_payment` = '.(int)$id_order_payment.',
|
||||
`id_order` = '.(int)$order_invoice->id_order);
|
||||
if ($use_existing_payment)
|
||||
{
|
||||
$id_order_payment = Db::getInstance()->getValue('
|
||||
SELECT MAX(id_order_payment) FROM `'._DB_PREFIX_.'order_payment` op
|
||||
INNER JOIN `'._DB_PREFIX_.'orders` o
|
||||
ON o.reference = op.order_reference
|
||||
WHERE id_order = '.(int)$order_invoice->id_order);
|
||||
|
||||
if ($id_order_payment)
|
||||
Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'order_invoice_payment`
|
||||
SET
|
||||
`id_order_invoice` = '.(int)$order_invoice->id.',
|
||||
`id_order_payment` = '.(int)$id_order_payment.',
|
||||
`id_order` = '.(int)$order_invoice->id_order);
|
||||
}
|
||||
|
||||
// Update order cart rule
|
||||
Db::getInstance()->execute('
|
||||
|
||||
@@ -72,8 +72,9 @@ class OrderHistoryCore extends ObjectModel
|
||||
*
|
||||
* @param int $new_order_state
|
||||
* @param int $id_order
|
||||
* @param bool $use_existing_payment
|
||||
*/
|
||||
public function changeIdOrderState($new_order_state, $id_order)
|
||||
public function changeIdOrderState($new_order_state, $id_order, $use_existing_payment = false)
|
||||
{
|
||||
if (!$new_order_state || !$id_order)
|
||||
return;
|
||||
@@ -216,7 +217,7 @@ class OrderHistoryCore extends ObjectModel
|
||||
$order->update();
|
||||
|
||||
if ($new_os->invoice && !$order->invoice_number)
|
||||
$order->setInvoice();
|
||||
$order->setInvoice($use_existing_payment);
|
||||
|
||||
// set orders as paid
|
||||
if ($new_os->paid == 1)
|
||||
|
||||
@@ -27,6 +27,10 @@
|
||||
|
||||
class OrderInvoiceCore extends ObjectModel
|
||||
{
|
||||
const TAX_EXCL = 0;
|
||||
const TAX_INCL = 1;
|
||||
const DETAIL = 2;
|
||||
|
||||
/** @var integer */
|
||||
public $id_order;
|
||||
|
||||
@@ -496,7 +500,68 @@ class OrderInvoiceCore extends ObjectModel
|
||||
*/
|
||||
public function getRestPaid()
|
||||
{
|
||||
return round($this->total_paid_tax_incl - $this->getTotalPaid(), 2);
|
||||
return round($this->total_paid_tax_incl + $this->getSiblingTotal() - $this->getTotalPaid(), 2);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return collection of order invoice object linked to the payments of the current order invoice object
|
||||
*
|
||||
* @since 1.5.0.14
|
||||
*/
|
||||
public function getSibling()
|
||||
{
|
||||
$query = new DbQuery();
|
||||
$query->select('oip2.id_order_invoice');
|
||||
$query->from('order_invoice_payment', 'oip1');
|
||||
$query->innerJoin('order_invoice_payment', 'oip2',
|
||||
'oip2.id_order_payment = oip1.id_order_payment AND oip2.id_order_invoice <> oip1.id_order_invoice');
|
||||
$query->where('oip1.id_order_invoice = '.$this->id);
|
||||
|
||||
$invoices = Db::getInstance()->executeS($query);
|
||||
if (!$invoices)
|
||||
return array();
|
||||
|
||||
$invoice_list = array();
|
||||
foreach ($invoices as $invoice)
|
||||
$invoice_list[] = $invoice['id_order_invoice'];
|
||||
|
||||
$payments = new Collection('OrderInvoice');
|
||||
$payments->where('id_order_invoice', 'IN', $invoice_list);
|
||||
|
||||
return $payments;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return total to paid of sibling invoices
|
||||
*
|
||||
* @param int $mod TAX_EXCL, TAX_INCL, DETAIL
|
||||
*
|
||||
* @since 1.5.0.14
|
||||
*/
|
||||
public function getSiblingTotal($mod = OrderInvoice::TAX_INCL)
|
||||
{
|
||||
$query = new DbQuery();
|
||||
$query->select('SUM(oi.total_paid_tax_incl) as total_paid_tax_incl, SUM(oi.total_paid_tax_excl) as total_paid_tax_excl');
|
||||
$query->from('order_invoice_payment', 'oip1');
|
||||
$query->innerJoin('order_invoice_payment', 'oip2',
|
||||
'oip2.id_order_payment = oip1.id_order_payment AND oip2.id_order_invoice <> oip1.id_order_invoice');
|
||||
$query->leftJoin('order_invoice', 'oi',
|
||||
'oi.id_order_invoice = oip2.id_order_invoice');
|
||||
$query->where('oip1.id_order_invoice = '.$this->id);
|
||||
|
||||
$row = Db::getInstance()->getRow($query);
|
||||
|
||||
switch ($mod)
|
||||
{
|
||||
case OrderInvoice::TAX_EXCL:
|
||||
return $row['total_paid_tax_excl'];
|
||||
case OrderInvoice::TAX_INCL:
|
||||
return $row['total_paid_tax_incl'];
|
||||
default:
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user