diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php
index b03f36dfbf0..804451777b8 100644
--- a/htdocs/compta/facture/card.php
+++ b/htdocs/compta/facture/card.php
@@ -4487,6 +4487,9 @@ if ($action == 'create') {
$morehtmlref .= '';
$object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
+ $object->totalcreditnotes = $totalcreditnotes;
+ $object->totaldeposits = $totaldeposits;
+ $object->remaintopay = price2num($object->total_ttc - $object->totalpaid - $object->totalcreditnotes - $object->totaldeposits, 'MT');
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '');
@@ -5039,7 +5042,9 @@ if ($action == 'create') {
$current_situation_counter = array();
foreach ($object->tab_previous_situation_invoice as $prev_invoice) {
- $tmptotalpaidforthisinvoice = $prev_invoice->getSommePaiement();
+ $tmptotalallpayments = $prev_invoice->getSommePaiement(0);
+ $tmptotalallpayments += $prev_invoice->getSumDepositsUsed(0);
+ $tmptotalallpayments += $prev_invoice->getSumCreditNotesUsed(0);
$total_prev_ht += $prev_invoice->total_ht;
$total_prev_ttc += $prev_invoice->total_ttc;
$current_situation_counter[] = (($prev_invoice->type == Facture::TYPE_CREDIT_NOTE) ?-1 : 1) * $prev_invoice->situation_counter;
@@ -5052,11 +5057,14 @@ if ($action == 'create') {
}
print '
'.price($prev_invoice->total_ht).' | ';
print ''.price($prev_invoice->total_ttc).' | ';
- print ''.$prev_invoice->getLibStatut(3, $tmptotalpaidforthisinvoice).' | ';
+ print ''.$prev_invoice->getLibStatut(3, $tmptotalallpayments).' | ';
print '';
}
}
+ $totalallpayments = $object->getSommePaiement(0);
+ $totalallpayments += $object->getSumCreditNotesUsed(0);
+ $totalallpayments += $object->getSumDepositsUsed(0);
$total_global_ht += $total_prev_ht;
$total_global_ttc += $total_prev_ttc;
@@ -5072,7 +5080,7 @@ if ($action == 'create') {
}
print ''.price($object->total_ht).' | ';
print ''.price($object->total_ttc).' | ';
- print ''.$object->getLibStatut(3, $object->getSommePaiement()).' | ';
+ print ''.$object->getLibStatut(3, $totalallpayments).' | ';
print '';
@@ -5114,7 +5122,9 @@ if ($action == 'create') {
$total_next_ht = $total_next_ttc = 0;
foreach ($object->tab_next_situation_invoice as $next_invoice) {
- $totalpaid = $next_invoice->getSommePaiement();
+ $totalpaid = $next_invoice->getSommePaiement(0);
+ $totalcreditnotes = $next_invoice->getSumCreditNotesUsed(0);
+ $totaldeposits = $next_invoice->getSumDepositsUsed(0);
$total_next_ht += $next_invoice->total_ht;
$total_next_ttc += $next_invoice->total_ttc;
@@ -5127,7 +5137,7 @@ if ($action == 'create') {
}
print ''.price($next_invoice->total_ht).' | ';
print ''.price($next_invoice->total_ttc).' | ';
- print ''.$next_invoice->getLibStatut(3, $totalpaid).' | ';
+ print ''.$next_invoice->getLibStatut(3, $totalpaid + $totalcreditnotes + $totaldeposits).' | ';
print '';
}
diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php
index a6fa25cfd13..d3469f3f74d 100644
--- a/htdocs/compta/facture/list.php
+++ b/htdocs/compta/facture/list.php
@@ -422,8 +422,8 @@ if ($action == 'makepayment_confirm' && $user->hasRight('facture', 'paiement'))
$paiementAmount = $facture->getSommePaiement();
$totalcreditnotes = $facture->getSumCreditNotesUsed();
$totaldeposits = $facture->getSumDepositsUsed();
- $totalpay = $paiementAmount + $totalcreditnotes + $totaldeposits;
- $remaintopay = price2num($facture->total_ttc - $totalpay);
+ $totalallpayments = $paiementAmount + $totalcreditnotes + $totaldeposits;
+ $remaintopay = price2num($facture->total_ttc - $totalallpayments);
if ($remaintopay != 0) {
$resultBank = $facture->setBankAccount($bankid);
if ($resultBank < 0) {
@@ -1821,7 +1821,7 @@ if ($resql) {
$totalarray['val']['f.total_tva'] = 0;
$totalarray['val']['f.total_ht'] = 0;
$totalarray['val']['f.total_ttc'] = 0;
- $totalarray['val']['totalam'] = 0;
+ $totalarray['val']['dynamount_payed'] = 0;
$totalarray['val']['rtp'] = 0;
@@ -1910,8 +1910,8 @@ if ($resql) {
$multicurrency_totalcreditnotes = $facturestatic->getSumCreditNotesUsed(1);
$multicurrency_totaldeposits = $facturestatic->getSumDepositsUsed(1);
- $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
- $remaintopay = price2num($facturestatic->total_ttc - $totalpay);
+ $totalallpayments = $paiement + $totalcreditnotes + $totaldeposits;
+ $remaintopay = $obj->total_ttc - $totalallpayments;
$multicurrency_totalpay = $multicurrency_paiement + $multicurrency_totalcreditnotes + $multicurrency_totaldeposits;
$multicurrency_remaintopay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_totalpay);
@@ -1923,13 +1923,16 @@ if ($resql) {
if ($facturestatic->type == Facture::TYPE_CREDIT_NOTE && $obj->paye == 1) { // If credit note closed, we take into account the amount not yet consumed
$remaincreditnote = $discount->getAvailableDiscounts($companystatic, '', 'rc.fk_facture_source='.$facturestatic->id);
$remaintopay = -$remaincreditnote;
- $totalpay = price2num($facturestatic->total_ttc - $remaintopay);
+ $totalallpayments = price2num($facturestatic->total_ttc - $remaintopay);
$multicurrency_remaincreditnote = $discount->getAvailableDiscounts($companystatic, '', 'rc.fk_facture_source='.$facturestatic->id, 0, 0, 1);
$multicurrency_remaintopay = -$multicurrency_remaincreditnote;
$multicurrency_totalpay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_remaintopay);
}
$facturestatic->alreadypaid = $paiement;
+ $facturestatic->totalpaid = $paiement;
+ $facturestatic->totalcreditnotes = $totalcreditnotes;
+ $facturestatic->totaldeposits = $totaldeposits;
$marginInfo = array();
if ($with_margin_info === true) {
@@ -2382,14 +2385,14 @@ if ($resql) {
}
if (!empty($arrayfields['dynamount_payed']['checked'])) {
- print ''.(!empty($totalpay) ? price($totalpay, 0, $langs) : ' ').' | '; // TODO Use a denormalized field
+ print ''.(!empty($totalallpayments) ? price($totalallpayments, 0, $langs) : ' ').' | '; // TODO Use a denormalized field
if (!$i) {
$totalarray['nbfield']++;
}
if (!$i) {
- $totalarray['pos'][$totalarray['nbfield']] = 'totalam';
+ $totalarray['pos'][$totalarray['nbfield']] = 'dynamount_payed';
}
- $totalarray['val']['totalam'] += $totalpay;
+ $totalarray['val']['dynamount_payed'] += $totalallpayments;
}
// Pending amount
@@ -2580,7 +2583,7 @@ if ($resql) {
// Status
if (!empty($arrayfields['f.fk_statut']['checked'])) {
print '';
- print $facturestatic->getLibStatut(5, $paiement);
+ print $facturestatic->getLibStatut(5, $totalallpayments);
print " | ";
if (!$i) {
$totalarray['nbfield']++;
diff --git a/htdocs/compta/facture/tpl/linkedobjectblock.tpl.php b/htdocs/compta/facture/tpl/linkedobjectblock.tpl.php
index 04d7f97baef..c002e5a7e5f 100644
--- a/htdocs/compta/facture/tpl/linkedobjectblock.tpl.php
+++ b/htdocs/compta/facture/tpl/linkedobjectblock.tpl.php
@@ -86,11 +86,24 @@ foreach ($linkedObjectBlock as $key => $objectlink) {
print '';
print '';
+ $totalallpayments = 0;
+ $totalcalculated = false;
if (method_exists($objectlink, 'getSommePaiement')) {
print $objectlink->getLibStatut(3, $objectlink->getSommePaiement());
+ $totalcalculated = true;
+ $totalallpayments += $objectlink->getSommePaiement();
} else {
print $objectlink->getLibStatut(3);
}
+ if (method_exists($objectlink, 'getSumDepositsUsed')) {
+ $totalcalculated = true;
+ $totalallpayments += $objectlink->getSumDepositsUsed();
+ }
+ if (method_exists($objectlink, 'getSumCreditNotesUsed')) {
+ $totalcalculated = true;
+ $totalallpayments += $objectlink->getSumCreditNotesUsed();
+ }
+ print $objectlink->getLibStatut(3, ($totalcalculated ? $totalallpayments : -1));
print ' | ';
print 'id.'&action=dellink&token='.newToken().'&dellinkid='.$key.'">'.img_picto($langs->transnoentitiesnoconv("RemoveLink"), 'unlink').' | ';
print "\n";
diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php
index a340d7ef7c3..e7df99729bb 100644
--- a/htdocs/compta/index.php
+++ b/htdocs/compta/index.php
@@ -215,6 +215,9 @@ if (isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
$thirdpartystatic->code_compta = $obj->code_compta;
//$thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
+ $totalallpayments = $tmpinvoice->getSommePaiement(0);
+ $totalallpayments += $tmpinvoice->getSumCreditNotesUsed(0);
+ $totalallpayments += $tmpinvoice->getSumDepositsUsed(0);
print '';
print '| ';
@@ -247,7 +250,7 @@ if (isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
print ' | jdate($obj->tms), 'dayhour', 'tzuserrel')).'">'.dol_print_date($db->jdate($obj->tms), 'day', 'tzuserrel').' | ';
- print ''.$tmpinvoice->getLibStatut(3, $obj->am).' | ';
+ print ''.$tmpinvoice->getLibStatut(3, $totalallpayments).' | ';
print '
';
@@ -377,6 +380,8 @@ if ((isModEnabled('fournisseur') && empty($conf->global->MAIN_USE_NEW_SUPPLIERMO
print ''.price($obj->total_ttc).' | ';
print 'jdate($obj->tms), 'dayhour', 'tzuserrel')).'">'.dol_print_date($db->jdate($obj->tms), 'day', 'tzuserrel').' | ';
$alreadypaid = $facstatic->getSommePaiement();
+ $alreadypaid += $facstatic->getSumCreditNotesUsed();
+ $alreadypaid += $facstatic->getSumDepositsUsed();
print ''.$facstatic->getLibStatut(3, $alreadypaid).' | ';
print '';
$total_ht += $obj->total_ht;
diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php
index 94e2d570fcf..307d5a41f27 100644
--- a/htdocs/compta/paiement/class/paiement.class.php
+++ b/htdocs/compta/paiement/class/paiement.class.php
@@ -1269,7 +1269,7 @@ class Paiement extends CommonObject
$facturestatic = new Facture($this->db);
foreach ($arraybill as $billid) {
$facturestatic->fetch($billid);
- $label .= '
'.$facturestatic->getNomUrl(1, '', 0, 0, '', 1).' '.$facturestatic->getLibStatut(2, 1);
+ $label .= '
'.$facturestatic->getNomUrl(1, '', 0, 0, '', 1).' '.$facturestatic->getLibStatut(2, -1);
}
}
}
diff --git a/htdocs/compta/prelevement/index.php b/htdocs/compta/prelevement/index.php
index 71677f0051c..dbe814569f0 100644
--- a/htdocs/compta/prelevement/index.php
+++ b/htdocs/compta/prelevement/index.php
@@ -101,7 +101,7 @@ print '
';
/*
* Invoices waiting for withdraw
*/
-$sql = "SELECT f.ref, f.rowid, f.total_ttc, f.fk_statut, f.paye, f.type,";
+$sql = "SELECT f.ref, f.rowid, f.total_ttc, f.fk_statut as status, f.paye, f.type,";
$sql .= " pfd.date_demande, pfd.amount,";
$sql .= " s.nom as name, s.email, s.rowid as socid, s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6";
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
@@ -141,10 +141,13 @@ if ($resql) {
$invoicestatic->id = $obj->rowid;
$invoicestatic->ref = $obj->ref;
- $invoicestatic->statut = $obj->fk_statut;
+ $invoicestatic->statut = $obj->status;
+ $invoicestatic->status = $obj->status;
$invoicestatic->paye = $obj->paye;
$invoicestatic->type = $obj->type;
- $alreadypayed = $invoicestatic->getSommePaiement();
+ $totalallpayments = $invoicestatic->getSommePaiement(0);
+ $totalallpayments += $invoicestatic->getSumCreditNotesUsed(0);
+ $totalallpayments += $invoicestatic->getSumDepositsUsed(0);
$thirdpartystatic->id = $obj->socid;
$thirdpartystatic->name = $obj->name;
@@ -177,7 +180,7 @@ if ($resql) {
print '';
print '';
- print $invoicestatic->getLibStatut(3, $alreadypayed);
+ print $invoicestatic->getLibStatut(3, $totalallpayments);
print ' | ';
print '';
$i++;
diff --git a/htdocs/compta/recap-compta.php b/htdocs/compta/recap-compta.php
index 0808e5a7aab..73ed2069438 100644
--- a/htdocs/compta/recap-compta.php
+++ b/htdocs/compta/recap-compta.php
@@ -159,7 +159,9 @@ if ($id > 0) {
print $fac->error."
";
continue;
}
- $totalpaid = $fac->getSommePaiement();
+ $alreadypaid = $fac->getSommePaiement();
+ $alreadypaid += $fac->getSumDepositsUsed();
+ $alreadypaid += $fac->getSumCreditNotesUsed();
$userstatic->id = $objf->userid;
$userstatic->login = $objf->login;
@@ -169,7 +171,7 @@ if ($id > 0) {
'date' => $fac->date,
'datefieldforsort' => $fac->date.'-'.$fac->ref,
'link' => $fac->getNomUrl(1),
- 'status' => $fac->getLibStatut(2, $totalpaid),
+ 'status' => $fac->getLibStatut(2, $alreadypaid),
'amount' => $fac->total_ttc,
'author' => $userstatic->getLoginUrl(1)
);
diff --git a/htdocs/compta/tva/list.php b/htdocs/compta/tva/list.php
index 9e5a28b6905..ec2ee333490 100644
--- a/htdocs/compta/tva/list.php
+++ b/htdocs/compta/tva/list.php
@@ -719,7 +719,8 @@ while ($i < $imaxinloop) {
}
if (!empty($arrayfields['t.status']['checked'])) {
- print '' . $tva_static->getLibStatut(5, $obj->alreadypayed) . ' | ';
+ $totalallpayments = $obj->alreadypayed;
+ print '' . $tva_static->getLibStatut(5, $totalallpayments) . ' | ';
if (!$i) {
$totalarray['nbfield']++;
}
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 0218301af75..d87132dc7a5 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -2451,7 +2451,16 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi
} else {
$morehtmlstatus .= ''.$object->getLibStatut(6, 1).'';
}
- } elseif (in_array($object->element, array('facture', 'invoice', 'invoice_supplier', 'chargesociales', 'loan', 'tva', 'salary'))) {
+ } elseif (in_array($object->element, array('facture', 'invoice', 'invoice_supplier'))) {
+ $totalallpayments = $object->getSommePaiement(0);
+ $totalallpayments += $object->getSumCreditNotesUsed(0);
+ $totalallpayments += $object->getSumDepositsUsed(0);
+ $tmptxt = $object->getLibStatut(6, $totalallpayments);
+ if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) {
+ $tmptxt = $object->getLibStatut(5, $totalallpayments);
+ }
+ $morehtmlstatus .= $tmptxt;
+ } elseif (in_array($object->element, array('chargesociales', 'loan', 'tva'))) {
$tmptxt = $object->getLibStatut(6, $object->totalpaid);
if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) {
$tmptxt = $object->getLibStatut(5, $object->totalpaid);