[*] BO : Improvement invoices management

This commit is contained in:
jBreux
2011-12-16 09:14:11 +00:00
parent 3653774e17
commit a4f970280c
12 changed files with 189 additions and 46 deletions
+39
View File
@@ -69,6 +69,9 @@ class OrderInvoiceCore extends ObjectModel
/** @var intger */
public $date_add;
/** @var array Total paid cache */
protected static $_total_paid_cache = array();
/**
* @see ObjectModel::$definition
*/
@@ -449,4 +452,40 @@ class OrderInvoiceCore extends ObjectModel
throw new PrestashopException('Can\'t load Order Invoice object for id: '.$id);
return $order_invoice;
}
/**
* Amounts of payments
* @since 1.5.0.2
* @return float Total paid
*/
public function getTotalPaid()
{
if (!array_key_exists($this->id, self::$_total_paid_cache))
{
self::$_total_paid_cache[$this->id] = 0;
$payments = OrderPayment::getByInvoiceId($this->id);
foreach ($payments as $payment)
self::$_total_paid_cache[$this->id] += $payment->amount;
}
return self::$_total_paid_cache[$this->id];
}
/**
* Rest Paid
* @since 1.5.0.2
* @return float Rest Paid
*/
public function getRestPaid()
{
return $this->total_paid_tax_incl - $this->getTotalPaid();
}
/**
* @since 1.5.0.2
* @return bool Is paid ?
*/
public function isPaid()
{
return $this->getTotalPaid() == $this->total_paid_tax_incl;
}
}