diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 7f5b33ee73a..973b54470c0 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -3222,8 +3222,9 @@ else if ($id > 0 || ! empty($ref)) $form->form_date($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->date_lim_reglement, 'paymentterm'); } else { print dol_print_date($object->date_lim_reglement, 'daytext'); - if ($object->date_lim_reglement < ($now - $conf->facture->client->warning_delay) && ! $object->paye && $object->statut == 1 && ! isset($object->am)) + if ($object->hasDelay()) { print img_warning($langs->trans('Late')); + } } } else { print ' '; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index dbbc1d88212..5533f70a919 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3236,11 +3236,15 @@ class Facture extends CommonInvoice $response->url=DOL_URL_ROOT.'/compta/facture/list.php?search_status=1'; $response->img=img_object($langs->trans("Bills"),"bill"); + $generic_facture = new Facture($this->db); + while ($obj=$this->db->fetch_object($resql)) { + $generic_facture->date_lim_reglement = $this->db->jdate($obj->datefin); + $response->nbtodo++; - if ($this->db->jdate($obj->datefin) < ($now - $conf->facture->client->warning_delay)) { + if ($generic_facture->hasDelay()) { $response->nbtodolate++; } } @@ -3697,6 +3701,25 @@ class Facture extends CommonInvoice return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); } + + /** + * Is the customer invoice delayed? + * + * @return bool + */ + public function hasDelay() + { + global $conf; + + $now = dol_now(); + + //Paid invoices have status STATUS_CLOSED + if (!$this->statut != Facture::STATUS_VALIDATED) { + return false; + } + + return $this->date_lim_reglement < ($now - $conf->facture->client->warning_delay); + } } /** diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index faefe63d9af..3aefeeefd36 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -378,6 +378,8 @@ if ($resql) $facturestatic->id=$objp->facid; $facturestatic->ref=$objp->facnumber; $facturestatic->type=$objp->type; + $facturestatic->statut = $objp->fk_statut; + $facturestatic->date_lim_reglement = $db->jdate($objp->datelimite); $notetoshow=dol_string_nohtmltag(($user->societe_id>0?$objp->note_public:$objp->note),1); $paiement = $facturestatic->getSommePaiement(); @@ -417,7 +419,7 @@ if ($resql) // Date limit print '
| '; - if ($date_limit < ($now - $conf->facture->client->warning_delay) && ! $objp->paye && $objp->fk_statut == 1) print img_warning($langs->trans("Late")); + if ($facturestatic->hasDelay()) { + print img_warning($langs->trans("Late")); + } print ' | '; // PDF Picto diff --git a/htdocs/compta/facture/prelevement.php b/htdocs/compta/facture/prelevement.php index be78b422fe6..78a93d7da0d 100644 --- a/htdocs/compta/facture/prelevement.php +++ b/htdocs/compta/facture/prelevement.php @@ -356,7 +356,9 @@ if ($object->id > 0) else { print dol_print_date($object->date_lim_reglement,'daytext'); - if ($object->date_lim_reglement < ($now - $conf->facture->client->warning_delay) && ! $object->paye && $object->statut == Facture::STATUS_VALIDATED && ! isset($object->am)) print img_warning($langs->trans('Late')); + if ($object->hasDelay()) { + print img_warning($langs->trans('Late')); + } } } else diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php index 11296bda93e..6a1f3b15028 100644 --- a/htdocs/compta/index.php +++ b/htdocs/compta/index.php @@ -358,11 +358,15 @@ if (! empty($conf->facture->enabled) && $user->rights->facture->lire) $facturestatic->total_ht=$obj->total_ht; $facturestatic->total_tva=$obj->total_tva; $facturestatic->total_ttc=$obj->total_ttc; + $facturestatic->statut = $obj->fk_statut; + $facturestatic->date_lim_reglement = $db->jdate($obj->datelimite); $facturestatic->type=$obj->type; print $facturestatic->getNomUrl(1,''); print ''; print ''; - if ($obj->fk_statut == 1 && ! $obj->paye && $db->jdate($obj->datelimite) < ($now - $conf->facture->client->warning_delay)) print img_warning($langs->trans("Late")); + if ($facturestatic->hasDelay()) { + print img_warning($langs->trans("Late")); + } print ' | '; print ''; print ''; - if ($db->jdate($obj->datelimite) < ($now - $conf->facture->client->warning_delay)) print img_warning($langs->trans("Late")); + if ($facturestatic->hasDelay()) { + print img_warning($langs->trans("Late")); + } print ' | '; print '