[*] BO : Improvement invoices management
This commit is contained in:
@@ -1397,6 +1397,20 @@ class OrderCore extends ObjectModel
|
||||
return $order_invoices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all not paid invoices for the current order
|
||||
* @since 1.5.0.2
|
||||
* @return Collection of Order invoice not paid
|
||||
*/
|
||||
public function getNotPaidInvoicesCollection()
|
||||
{
|
||||
$invoices = $this->getInvoicesCollection();
|
||||
foreach ($invoices as $key => $invoice)
|
||||
if ($invoice->isPaid())
|
||||
unset($invoices[$key]);
|
||||
return $invoices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total paid
|
||||
*
|
||||
|
||||
@@ -143,6 +143,28 @@ class OrderHistoryCore extends ObjectModel
|
||||
}
|
||||
}
|
||||
|
||||
// Set order as paid
|
||||
if ($newOS->paid == 1)
|
||||
{
|
||||
$invoices = $order->getInvoicesCollection();
|
||||
$payment_method = Module::getInstanceByName($order->module);
|
||||
foreach ($invoices as $invoice)
|
||||
{
|
||||
$rest_paid = $invoice->getRestPaid();
|
||||
if ($rest_paid)
|
||||
{
|
||||
$payment = new OrderPayment();
|
||||
$payment->id_order = $order->id;
|
||||
$payment->id_order_invoice = $invoice->id;
|
||||
$payment->id_currency = $order->id_currency;
|
||||
$payment->amount = $rest_paid;
|
||||
$payment->payment_method = $payment_method->displayName;
|
||||
$payment->conversion_rate = 1;
|
||||
$payment->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->id_order_state = (int)($new_order_state);
|
||||
|
||||
/* Change invoice number of order ? */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -81,8 +81,21 @@ class OrderPaymentCore extends ObjectModel
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'payment_order`
|
||||
FROM `'._DB_PREFIX_.'order_payment`
|
||||
WHERE `id_order` = '.(int)$id_order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Order Payments By Invoice ID
|
||||
* @static
|
||||
* @param $id_invoice Invoice ID
|
||||
* @return Collection Collection
|
||||
*/
|
||||
public static function getByInvoiceId($id_invoice)
|
||||
{
|
||||
$payments = new Collection('OrderPayment');
|
||||
$payments->where('a.id_order_invoice = '.(int)$id_invoice);
|
||||
return $payments;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,9 @@ class OrderStateCore extends ObjectModel
|
||||
/** @var boolean Shipped */
|
||||
public $shipped;
|
||||
|
||||
/** @var boolean Paid */
|
||||
public $paid;
|
||||
|
||||
/**
|
||||
* @see ObjectModel::$definition
|
||||
*/
|
||||
@@ -72,6 +75,7 @@ class OrderStateCore extends ObjectModel
|
||||
'unremovable' =>array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'delivery' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'hidden' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'paid' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
|
||||
// Lang fields
|
||||
'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 64),
|
||||
|
||||
Reference in New Issue
Block a user