[-] 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:
mDeflotte
2012-07-09 16:30:12 +00:00
parent 649cb9af43
commit e8b686d928
5 changed files with 94 additions and 25 deletions
@@ -82,12 +82,12 @@
-- --
{else} {else}
{displayPrice price=$document->total_paid_tax_incl currency=$currency->id}  {displayPrice price=$document->total_paid_tax_incl currency=$currency->id} 
{if $document->getGlobalRestPaid()} {if $document->getTotalPaid()}
<span style="color:red;font-weight:bold;"> <span style="color:red;font-weight:bold;">
{if $document->getGlobalRestPaid() >= 0} {if $document->getRestPaid() > 0}
({displayPrice price=$document->getGlobalRestPaid() currency=$currency->id} {l s='not paid'}) ({displayPrice price=$document->getRestPaid() currency=$currency->id} {l s='not paid'})
{else} {else if $document->getRestPaid() < 0}
({displayPrice price=-$document->getGlobalRestPaid() currency=$currency->id} {l s='overpaid'}) ({displayPrice price=-$document->getRestPaid() currency=$currency->id} {l s='overpaid'})
{/if} {/if}
</span> </span>
{/if} {/if}
+1 -1
View File
@@ -531,7 +531,7 @@ abstract class PaymentModuleCore extends Module
// So you migth have two order states // So you migth have two order states
$new_history = new OrderHistory(); $new_history = new OrderHistory();
$new_history->id_order = (int)$order->id; $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); $new_history->addWithemail(true, $extra_vars);
unset($order_detail); unset($order_detail);
+19 -16
View File
@@ -1070,8 +1070,8 @@ class OrderCore extends ObjectModel
return false; return false;
} }
public static function getLastInvoiceNumber() public static function getLastInvoiceNumber()
{ {
return Db::getInstance()->getValue(' return Db::getInstance()->getValue('
SELECT MAX(`number`) SELECT MAX(`number`)
FROM `'._DB_PREFIX_.'order_invoice` FROM `'._DB_PREFIX_.'order_invoice`
@@ -1081,7 +1081,7 @@ class OrderCore extends ObjectModel
/** /**
* This method allows to generate first invoice of the current order * This method allows to generate first invoice of the current order
*/ */
public function setInvoice() public function setInvoice($use_existing_payment = false)
{ {
if (!$this->hasInvoice()) if (!$this->hasInvoice())
{ {
@@ -1129,19 +1129,22 @@ class OrderCore extends ObjectModel
WHERE `id_order` = '.(int)$order_invoice->id_order); WHERE `id_order` = '.(int)$order_invoice->id_order);
// Update order payment // Update order payment
$id_order_payment = Db::getInstance()->getValue(' if ($use_existing_payment)
SELECT id_order_payment FROM `'._DB_PREFIX_.'order_payment` op {
INNER JOIN `'._DB_PREFIX_.'orders` o $id_order_payment = Db::getInstance()->getValue('
ON o.reference = op.order_reference SELECT MAX(id_order_payment) FROM `'._DB_PREFIX_.'order_payment` op
WHERE id_order = '.(int)$order_invoice->id_order); INNER JOIN `'._DB_PREFIX_.'orders` o
ON o.reference = op.order_reference
if ($id_order_payment) WHERE id_order = '.(int)$order_invoice->id_order);
Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'order_invoice_payment` if ($id_order_payment)
SET Db::getInstance()->execute('
`id_order_invoice` = '.(int)$order_invoice->id.', INSERT INTO `'._DB_PREFIX_.'order_invoice_payment`
`id_order_payment` = '.(int)$id_order_payment.', SET
`id_order` = '.(int)$order_invoice->id_order); `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 // Update order cart rule
Db::getInstance()->execute(' Db::getInstance()->execute('
+3 -2
View File
@@ -72,8 +72,9 @@ class OrderHistoryCore extends ObjectModel
* *
* @param int $new_order_state * @param int $new_order_state
* @param int $id_order * @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) if (!$new_order_state || !$id_order)
return; return;
@@ -216,7 +217,7 @@ class OrderHistoryCore extends ObjectModel
$order->update(); $order->update();
if ($new_os->invoice && !$order->invoice_number) if ($new_os->invoice && !$order->invoice_number)
$order->setInvoice(); $order->setInvoice($use_existing_payment);
// set orders as paid // set orders as paid
if ($new_os->paid == 1) if ($new_os->paid == 1)
+66 -1
View File
@@ -27,6 +27,10 @@
class OrderInvoiceCore extends ObjectModel class OrderInvoiceCore extends ObjectModel
{ {
const TAX_EXCL = 0;
const TAX_INCL = 1;
const DETAIL = 2;
/** @var integer */ /** @var integer */
public $id_order; public $id_order;
@@ -496,7 +500,68 @@ class OrderInvoiceCore extends ObjectModel
*/ */
public function getRestPaid() 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;
}
} }
/** /**