Save result of some methods into cached properties.
This commit is contained in:
parent
baa4608812
commit
0e36097eba
@ -93,6 +93,14 @@ abstract class CommonInvoice extends CommonObject
|
||||
const STATUS_ABANDONED = 3;
|
||||
|
||||
|
||||
public $sumpayed;
|
||||
public $sumpayed_multicurrency;
|
||||
public $sumdeposit;
|
||||
public $sumdeposit_multicurrency;
|
||||
public $sumcreditnote;
|
||||
public $sumcreditnote_multicurrency;
|
||||
|
||||
|
||||
/**
|
||||
* Return remain amount to pay. Property ->id and ->total_ttc must be set.
|
||||
* This does not include open direct debit requests.
|
||||
@ -118,8 +126,8 @@ abstract class CommonInvoice extends CommonObject
|
||||
* Return amount of payments already done. This must include ONLY the record into the payment table.
|
||||
* Payments dones using discounts, credit notes, etc are not included.
|
||||
*
|
||||
* @param int $multicurrency Return multicurrency_amount instead of amount
|
||||
* @return float Amount of payment already done, <0 if KO
|
||||
* @param int $multicurrency Return multicurrency_amount instead of amount
|
||||
* @return float Amount of payment already done, <0 and set ->error if KO
|
||||
*/
|
||||
public function getSommePaiement($multicurrency = 0)
|
||||
{
|
||||
@ -138,10 +146,13 @@ abstract class CommonInvoice extends CommonObject
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$this->db->free($resql);
|
||||
if ($multicurrency) {
|
||||
$this->sumpayed_multicurrency = $obj->multicurrency_amount;
|
||||
return $obj->multicurrency_amount;
|
||||
} else {
|
||||
$this->sumpayed = $obj->amount;
|
||||
return $obj->amount;
|
||||
}
|
||||
} else {
|
||||
@ -154,13 +165,13 @@ abstract class CommonInvoice extends CommonObject
|
||||
* Return amount (with tax) of all deposits invoices used by invoice.
|
||||
* Should always be empty, except if option FACTURE_DEPOSITS_ARE_JUST_PAYMENTS is on (not recommended).
|
||||
*
|
||||
* @param int $multicurrency Return multicurrency_amount instead of amount
|
||||
* @return float <0 if KO, Sum of deposits amount otherwise
|
||||
* @param int $multicurrency Return multicurrency_amount instead of amount
|
||||
* @return float <0 and set ->error if KO, Sum of deposits amount otherwise
|
||||
*/
|
||||
public function getSumDepositsUsed($multicurrency = 0)
|
||||
{
|
||||
if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') {
|
||||
// TODO
|
||||
// FACTURE_DEPOSITS_ARE_JUST_PAYMENTS was never supported for purchase invoice, so we can return 0 with no need of SQL for this case.
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@ -170,6 +181,12 @@ abstract class CommonInvoice extends CommonObject
|
||||
$result = $discountstatic->getSumDepositsUsed($this, $multicurrency);
|
||||
|
||||
if ($result >= 0) {
|
||||
if ($multicurrency) {
|
||||
$this->sumdeposit_multicurrency = $result;
|
||||
} else {
|
||||
$this->sumdeposit = $result;
|
||||
}
|
||||
|
||||
return $result;
|
||||
} else {
|
||||
$this->error = $discountstatic->error;
|
||||
@ -180,8 +197,8 @@ abstract class CommonInvoice extends CommonObject
|
||||
/**
|
||||
* Return amount (with tax) of all credit notes invoices + excess received used by invoice
|
||||
*
|
||||
* @param int $multicurrency Return multicurrency_amount instead of amount
|
||||
* @return float <0 if KO, Sum of credit notes and deposits amount otherwise
|
||||
* @param int $multicurrency Return multicurrency_amount instead of amount
|
||||
* @return float <0 and set ->error if KO, Sum of credit notes and deposits amount otherwise
|
||||
*/
|
||||
public function getSumCreditNotesUsed($multicurrency = 0)
|
||||
{
|
||||
@ -190,6 +207,12 @@ abstract class CommonInvoice extends CommonObject
|
||||
$discountstatic = new DiscountAbsolute($this->db);
|
||||
$result = $discountstatic->getSumCreditNotesUsed($this, $multicurrency);
|
||||
if ($result >= 0) {
|
||||
if ($multicurrency) {
|
||||
$this->sumcreditnote_multicurrency = $result;
|
||||
} else {
|
||||
$this->sumcreditnote = $result;
|
||||
}
|
||||
|
||||
return $result;
|
||||
} else {
|
||||
$this->error = $discountstatic->error;
|
||||
|
||||
@ -562,7 +562,7 @@ class DiscountAbsolute
|
||||
* Should always be empty, except if option FACTURE_DEPOSITS_ARE_JUST_PAYMENTS is on (not recommended).
|
||||
*
|
||||
* @param CommonInvoice $invoice Object invoice (customer of supplier)
|
||||
* @param int $multicurrency 1=Return multicurrency_amount instead of amount
|
||||
* @param int $multicurrency 1=Return multicurrency_amount instead of amount. TODO Add a mode multicurrency = -1 to return array with amount + multicurrency amount
|
||||
* @return int <0 if KO, Sum of credit notes and deposits amount otherwise
|
||||
*/
|
||||
public function getSumDepositsUsed($invoice, $multicurrency = 0)
|
||||
@ -603,7 +603,7 @@ class DiscountAbsolute
|
||||
* Return amount (with tax) of all credit notes invoices + excess received used by invoice as a payment
|
||||
*
|
||||
* @param CommonInvoice $invoice Object invoice
|
||||
* @param int $multicurrency 1=Return multicurrency_amount instead of amount
|
||||
* @param int $multicurrency 1=Return multicurrency_amount instead of amount. TODO Add a mode multicurrency = -1 to return array with amount + multicurrency amount
|
||||
* @return int <0 if KO, Sum of credit notes and excess received amount otherwise
|
||||
*/
|
||||
public function getSumCreditNotesUsed($invoice, $multicurrency = 0)
|
||||
@ -643,7 +643,7 @@ class DiscountAbsolute
|
||||
* Return amount (with tax) of all converted amount for this credit note
|
||||
*
|
||||
* @param CommonInvoice $invoice Object invoice
|
||||
* @param int $multicurrency Return multicurrency_amount instead of amount
|
||||
* @param int $multicurrency Return multicurrency_amount instead of amount. TODO Add a mode multicurrency = -1 to return array with amount + multicurrency amount
|
||||
* @return int <0 if KO, Sum of credit notes and deposits amount otherwise
|
||||
*/
|
||||
public function getSumFromThisCreditNotesNotUsed($invoice, $multicurrency = 0)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user