Merge branch '14.0' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2021-09-09 02:29:10 +02:00
commit 4db234e036

View File

@ -4345,10 +4345,10 @@ class Societe extends CommonObject
} }
/** /**
* Return amount of order not paid and total * Return amount of proposal not yet paid and total an dlist of all proposals
* *
* @param string $mode 'customer' or 'supplier' * @param string $mode 'customer' or 'supplier'
* @return array array('opened'=>Amount, 'total'=>Total amount) * @return array array('opened'=>Amount including tax that remains to pay, 'total_ht'=>Total amount without tax of all objects paid or not, 'total_ttc'=>Total amunt including tax of all object paid or not)
*/ */
public function getOutstandingProposals($mode = 'customer') public function getOutstandingProposals($mode = 'customer')
{ {
@ -4389,10 +4389,10 @@ class Societe extends CommonObject
} }
/** /**
* Return amount of order not paid and total * Return amount of order not yet paid and total and list of all orders
* *
* @param string $mode 'customer' or 'supplier' * @param string $mode 'customer' or 'supplier'
* @return array array('opened'=>Amount, 'total'=>Total amount) * @return array array('opened'=>Amount including tax that remains to pay, 'total_ht'=>Total amount without tax of all objects paid or not, 'total_ttc'=>Total amunt including tax of all object paid or not)
*/ */
public function getOutstandingOrders($mode = 'customer') public function getOutstandingOrders($mode = 'customer')
{ {
@ -4432,11 +4432,11 @@ class Societe extends CommonObject
} }
/** /**
* Return amount of bill not paid and total * Return amount of bill not yet paid and total of all invoices
* *
* @param string $mode 'customer' or 'supplier' * @param string $mode 'customer' or 'supplier'
* @param int $late 0 => all invoice, 1=> only late * @param int $late 0 => all invoice, 1=> only late
* @return array array('opened'=>Amount, 'total'=>Total amount) * @return array array('opened'=>Amount including tax that remains to pay, 'total_ht'=>Total amount without tax of all objects paid or not, 'total_ttc'=>Total amunt including tax of all object paid or not)
*/ */
public function getOutstandingBills($mode = 'customer', $late = 0) public function getOutstandingBills($mode = 'customer', $late = 0)
{ {
@ -4470,6 +4470,7 @@ class Societe extends CommonObject
$outstandingTotal = 0; $outstandingTotal = 0;
$outstandingTotalIncTax = 0; $outstandingTotalIncTax = 0;
$arrayofref = array(); $arrayofref = array();
$arrayofrefopened = array();
if ($mode == 'supplier') { if ($mode == 'supplier') {
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
$tmpobject = new FactureFournisseur($this->db); $tmpobject = new FactureFournisseur($this->db);
@ -4487,6 +4488,9 @@ class Societe extends CommonObject
$outstandingTotal += $obj->total_ht; $outstandingTotal += $obj->total_ht;
$outstandingTotalIncTax += $obj->total_ttc; $outstandingTotalIncTax += $obj->total_ttc;
} }
$remaintopay = 0;
if ($obj->paye == 0 if ($obj->paye == 0
&& $obj->status != $tmpobject::STATUS_DRAFT // Not a draft && $obj->status != $tmpobject::STATUS_DRAFT // Not a draft
&& $obj->status != $tmpobject::STATUS_ABANDONED // Not abandonned && $obj->status != $tmpobject::STATUS_ABANDONED // Not abandonned
@ -4496,16 +4500,23 @@ class Societe extends CommonObject
$creditnotes = $tmpobject->getSumCreditNotesUsed(); $creditnotes = $tmpobject->getSumCreditNotesUsed();
$deposits = $tmpobject->getSumDepositsUsed(); $deposits = $tmpobject->getSumDepositsUsed();
$outstandingOpened += $obj->total_ttc - $paiement - $creditnotes - $deposits; $remaintopay = ($obj->total_ttc - $paiement - $creditnotes - $deposits);
$outstandingOpened += $remaintopay;
} }
//if credit note is converted but not used //if credit note is converted but not used
// TODO Do this also for customer ? // TODO Do this also for customer ?
if ($mode == 'supplier' && $obj->type == FactureFournisseur::TYPE_CREDIT_NOTE && $tmpobject->isCreditNoteUsed()) { if ($mode == 'supplier' && $obj->type == FactureFournisseur::TYPE_CREDIT_NOTE && $tmpobject->isCreditNoteUsed()) {
$outstandingOpened -= $tmpobject->getSumFromThisCreditNotesNotUsed(); $remainingcreditnote = $tmpobject->getSumFromThisCreditNotesNotUsed();
$remaintopay -= $remainingcreditnote;
$outstandingOpened -= $remainingcreditnote;
}
if ($remaintopay) {
$arrayofrefopened[$obj->rowid] = $obj->ref;
} }
} }
return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax, 'refs'=>$arrayofref); // 'opened' is 'incl taxes' return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax, 'refs'=>$arrayofref, 'refsopened'=>$arrayofrefopened); // 'opened' is 'incl taxes'
} else { } else {
dol_syslog("Sql error ".$this->db->lasterror, LOG_ERR); dol_syslog("Sql error ".$this->db->lasterror, LOG_ERR);
return array(); return array();