mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-06 09:38:23 +01:00
Backport Fix wrong invoice status when invoice has discount (#31323)
Co-authored-by: Ulysse Valdenaire <uvaldenaire@easya.solutions>
This commit is contained in:
@@ -4487,6 +4487,9 @@ if ($action == 'create') {
|
||||
$morehtmlref .= '</div>';
|
||||
|
||||
$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 '<td class="right"><span class="amount">'.price($prev_invoice->total_ht).'</span></td>';
|
||||
print '<td class="right"><span class="amount">'.price($prev_invoice->total_ttc).'</span></td>';
|
||||
print '<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalpaidforthisinvoice).'</td>';
|
||||
print '<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalallpayments).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
}
|
||||
|
||||
$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 '<td class="right"><span class="amount">'.price($object->total_ht).'</span></td>';
|
||||
print '<td class="right"><span class="amount">'.price($object->total_ttc).'</span></td>';
|
||||
print '<td class="right">'.$object->getLibStatut(3, $object->getSommePaiement()).'</td>';
|
||||
print '<td class="right">'.$object->getLibStatut(3, $totalallpayments).'</td>';
|
||||
print '</tr>';
|
||||
|
||||
|
||||
@@ -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 '<td class="right"><span class="amount">'.price($next_invoice->total_ht).'</span></td>';
|
||||
print '<td class="right"><span class="amount">'.price($next_invoice->total_ttc).'</span></td>';
|
||||
print '<td class="right">'.$next_invoice->getLibStatut(3, $totalpaid).'</td>';
|
||||
print '<td class="right">'.$next_invoice->getLibStatut(3, $totalpaid + $totalcreditnotes + $totaldeposits).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
|
||||
@@ -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 '<td class="right nowraponall amount">'.(!empty($totalpay) ? price($totalpay, 0, $langs) : ' ').'</td>'; // TODO Use a denormalized field
|
||||
print '<td class="right nowraponall amount">'.(!empty($totalallpayments) ? price($totalallpayments, 0, $langs) : ' ').'</td>'; // 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 '<td class="nowrap right">';
|
||||
print $facturestatic->getLibStatut(5, $paiement);
|
||||
print $facturestatic->getLibStatut(5, $totalallpayments);
|
||||
print "</td>";
|
||||
if (!$i) {
|
||||
$totalarray['nbfield']++;
|
||||
|
||||
@@ -86,11 +86,24 @@ foreach ($linkedObjectBlock as $key => $objectlink) {
|
||||
|
||||
print '</td>';
|
||||
print '<td class="linkedcol-statut right">';
|
||||
$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 '</td>';
|
||||
print '<td class="linkedcol-action right"><a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=dellink&token='.newToken().'&dellinkid='.$key.'">'.img_picto($langs->transnoentitiesnoconv("RemoveLink"), 'unlink').'</a></td>';
|
||||
print "</tr>\n";
|
||||
|
||||
@@ -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 '<tr class="oddeven">';
|
||||
print '<td class="nowrap">';
|
||||
|
||||
@@ -247,7 +250,7 @@ if (isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
|
||||
|
||||
print '<td class="right" title="'.dol_escape_htmltag($langs->trans("DateModificationShort").' : '.dol_print_date($db->jdate($obj->tms), 'dayhour', 'tzuserrel')).'">'.dol_print_date($db->jdate($obj->tms), 'day', 'tzuserrel').'</td>';
|
||||
|
||||
print '<td>'.$tmpinvoice->getLibStatut(3, $obj->am).'</td>';
|
||||
print '<td>'.$tmpinvoice->getLibStatut(3, $totalallpayments).'</td>';
|
||||
|
||||
print '</tr>';
|
||||
|
||||
@@ -377,6 +380,8 @@ if ((isModEnabled('fournisseur') && empty($conf->global->MAIN_USE_NEW_SUPPLIERMO
|
||||
print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
|
||||
print '<td class="right" title="'.dol_escape_htmltag($langs->trans("DateModificationShort").' : '.dol_print_date($db->jdate($obj->tms), 'dayhour', 'tzuserrel')).'">'.dol_print_date($db->jdate($obj->tms), 'day', 'tzuserrel').'</td>';
|
||||
$alreadypaid = $facstatic->getSommePaiement();
|
||||
$alreadypaid += $facstatic->getSumCreditNotesUsed();
|
||||
$alreadypaid += $facstatic->getSumDepositsUsed();
|
||||
print '<td>'.$facstatic->getLibStatut(3, $alreadypaid).'</td>';
|
||||
print '</tr>';
|
||||
$total_ht += $obj->total_ht;
|
||||
|
||||
@@ -1269,7 +1269,7 @@ class Paiement extends CommonObject
|
||||
$facturestatic = new Facture($this->db);
|
||||
foreach ($arraybill as $billid) {
|
||||
$facturestatic->fetch($billid);
|
||||
$label .= '<br> '.$facturestatic->getNomUrl(1, '', 0, 0, '', 1).' '.$facturestatic->getLibStatut(2, 1);
|
||||
$label .= '<br> '.$facturestatic->getNomUrl(1, '', 0, 0, '', 1).' '.$facturestatic->getLibStatut(2, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ print '</span></td></tr></table></div><br>';
|
||||
/*
|
||||
* 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 '</td>';
|
||||
|
||||
print '<td class="right">';
|
||||
print $invoicestatic->getLibStatut(3, $alreadypayed);
|
||||
print $invoicestatic->getLibStatut(3, $totalallpayments);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
$i++;
|
||||
|
||||
@@ -159,7 +159,9 @@ if ($id > 0) {
|
||||
print $fac->error."<br>";
|
||||
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)
|
||||
);
|
||||
|
||||
@@ -719,7 +719,8 @@ while ($i < $imaxinloop) {
|
||||
}
|
||||
|
||||
if (!empty($arrayfields['t.status']['checked'])) {
|
||||
print '<td class="nowrap right">' . $tva_static->getLibStatut(5, $obj->alreadypayed) . '</td>';
|
||||
$totalallpayments = $obj->alreadypayed;
|
||||
print '<td class="nowrap right">' . $tva_static->getLibStatut(5, $totalallpayments) . '</td>';
|
||||
if (!$i) {
|
||||
$totalarray['nbfield']++;
|
||||
}
|
||||
|
||||
@@ -2451,7 +2451,16 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi
|
||||
} else {
|
||||
$morehtmlstatus .= '<span class="statusrefbuy">'.$object->getLibStatut(6, 1).'</span>';
|
||||
}
|
||||
} 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);
|
||||
|
||||
Reference in New Issue
Block a user