diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php
index 1ca81169cfb..15f1a7c8abe 100644
--- a/htdocs/compta/facture/card.php
+++ b/htdocs/compta/facture/card.php
@@ -5377,7 +5377,8 @@ if ($action == 'create') {
}
}
- $sumofpayment = $object->getSommePaiement();
+ $sumofpayment = $totalpaye;
+ $sumofpaymentall = $totalpaye + $totalcreditnotes + $totaldeposits;
// Reverse back money or convert to reduction
if ($object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_SITUATION) {
@@ -5401,8 +5402,8 @@ if ($action == 'create') {
print 'id.'&action=converttoreduc" title="'.dol_escape_htmltag($langs->trans("ConfirmConvertToReduc2")).'">'.$langs->trans('ConvertToReduc').'';
}
// For deposit invoice
- if ($object->type == Facture::TYPE_DEPOSIT && $usercancreate && $object->statut > 0 && empty($discount->id)) {
- if (price2num($object->total_ttc, 'MT') == price2num($sumofpayment, 'MT')) {
+ if ($object->type == Facture::TYPE_DEPOSIT && $usercancreate && $object->statut > Facture::STATUS_DRAFT && empty($discount->id)) {
+ if (price2num($object->total_ttc, 'MT') == price2num($sumofpaymentall, 'MT')) {
// We can close a down payment only if paid amount is same than amount of down payment (by definition)
print 'id.'&action=converttoreduc">'.$langs->trans('ConvertToReduc').'';
} else {
@@ -5415,7 +5416,7 @@ if ($action == 'create') {
if (($object->statut == Facture::STATUS_VALIDATED && $object->paye == 0 && $usercanissuepayment
&& (($object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT && $resteapayer <= 0) || ($object->type == Facture::TYPE_CREDIT_NOTE && $resteapayer >= 0) || ($object->type == Facture::TYPE_DEPOSIT && $object->total_ttc > 0)))
) {
- if ($object->type == Facture::TYPE_DEPOSIT && price2num($object->total_ttc, 'MT') != price2num($sumofpayment, 'MT')) {
+ if ($object->type == Facture::TYPE_DEPOSIT && price2num($object->total_ttc, 'MT') != price2num($sumofpaymentall, 'MT')) {
// We can close a down payment only if paid amount is same than amount of down payment (by definition)
print ''.$langs->trans('ClassifyPaid').'';
} else {