diff --git a/htdocs/adherents/card_subscriptions.php b/htdocs/adherents/card_subscriptions.php index 87f1b3f14d99e1f8fa29d4e90b915f8da16bc675..71fd6f3caa11416ef1efba49c27da68aa13b67cc 100644 --- a/htdocs/adherents/card_subscriptions.php +++ b/htdocs/adherents/card_subscriptions.php @@ -621,7 +621,9 @@ if ($rowid > 0) if ($object->datefin) { print dol_print_date($object->datefin,'day'); - if ($object->datefin < ($now - $conf->adherent->cotisation->warning_delay) && $object->statut > 0) print " ".img_warning($langs->trans("Late")); // Affiche picto retard uniquement si non brouillon et non resilie + if ($object->hasDelay()) { + print " ".img_warning($langs->trans("Late")); + } } else { diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 58bb828302946d33052e03c260a33a81fb6e6f9d..d83664fd39289a26c1a31deb8a395adf519186bf 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -1741,7 +1741,7 @@ class Adherent extends CommonObject $now=dol_now(); - $sql = "SELECT a.rowid, a.datefin"; + $sql = "SELECT a.rowid, a.datefin, a.statut"; $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a"; $sql.= " WHERE a.statut = 1"; $sql.= " AND a.entity IN (".getEntity('adherent', 1).")"; @@ -1758,11 +1758,16 @@ class Adherent extends CommonObject $response->url=DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&statut=1'; $response->img=img_object($langs->trans("Members"),"user"); + $adherentstatic = new Adherent($this->db); + while ($obj=$this->db->fetch_object($resql)) { $response->nbtodo++; - if ($this->db->jdate($obj->datefin) < ($now - $conf->adherent->cotisation->warning_delay)) { + $adherentstatic->datefin = $this->db->jdate($obj->datefin); + $adherentstatic->statut = $obj->statut; + + if ($adherentstatic->hasDelay()) { $response->nbtodolate++; } } @@ -1974,4 +1979,18 @@ class Adherent extends CommonObject return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); } + public function hasDelay() + { + global $conf; + + //Only valid members + if ($this->statut <= 0) { + return false; + } + + $now = dol_now(); + + return $this->datefin < ($now - $conf->adherent->cotisation->warning_delay); + } + } diff --git a/htdocs/adherents/list.php b/htdocs/adherents/list.php index 1cf2a8e5e098409307cf1b819209306829a3cd60..9799ea2ecef753f3a2b26991c4fdde18abce6937 100644 --- a/htdocs/adherents/list.php +++ b/htdocs/adherents/list.php @@ -271,6 +271,8 @@ if ($resql) $memberstatic->ref=$objp->rowid; $memberstatic->lastname=$objp->lastname; $memberstatic->firstname=$objp->firstname; + $memberstatic->statut=$objp->statut; + $memberstatic->datefin= $datefin; if (! empty($objp->fk_soc)) { $memberstatic->socid = $objp->fk_soc; @@ -325,7 +327,9 @@ if ($resql) { print '<td align="center" class="nowrap">'; print dol_print_date($datefin,'day'); - if ($datefin < ($now - $conf->adherent->cotisation->warning_delay) && $objp->statut > 0) print " ".img_warning($langs->trans("SubscriptionLate")); + if ($memberstatic->hasDelay()) { + print " ".img_warning($langs->trans("SubscriptionLate")); + } print '</td>'; } else diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index b4336936181c9ff44e562d882e1b6bd4b7b73d1a..9d793e16ba080814572d6fe4f34cfff8330878f5 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -882,7 +882,7 @@ class ActionComm extends CommonObject $resql=$this->db->query($sql); if ($resql) { - $now = dol_now(); + $agenda_static = new ActionComm($this->db); $response = new WorkboardResponse(); $response->warning_delay = $conf->actions->warning_delay/60/60/24; @@ -895,7 +895,9 @@ class ActionComm extends CommonObject { $response->nbtodo++; - if (isset($obj->dp) && $this->db->jdate($obj->dp) < ($now - $conf->actions->warning_delay)) { + $agenda_static->datep = $this->db->jdate($obj->dp); + + if ($agenda_static->hasDelay()) { $response->nbtodolate++; } } @@ -1361,5 +1363,19 @@ class ActionComm extends CommonObject return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); } + /** + * Is the action delayed? + * + * @return bool + */ + public function hasDelay() + { + global $conf; + + $now = dol_now(); + + return $this->datep && ($this->datep < ($now - $conf->actions->warning_delay)); + } + } diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 4a037ba486a1b0437c9a2b12095b77c559cdcf95..d6d93c17bd8eb8bc6ceeea5e3f9eb488f8abf2f2 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2846,7 +2846,7 @@ class Commande extends CommonOrder $clause = " WHERE"; - $sql = "SELECT c.rowid, c.date_creation as datec, c.date_livraison as delivery_date, c.fk_statut"; + $sql = "SELECT c.rowid, c.date_creation as datec, c.date_commande, c.date_livraison as delivery_date, c.fk_statut"; $sql.= " FROM ".MAIN_DB_PREFIX."commande as c"; if (!$user->rights->societe->client->voir && !$user->societe_id) { @@ -2862,21 +2862,22 @@ class Commande extends CommonOrder $resql=$this->db->query($sql); if ($resql) { - $now=dol_now(); - $response = new WorkboardResponse(); $response->warning_delay=$conf->commande->client->warning_delay/60/60/24; $response->label=$langs->trans("OrdersToProcess"); $response->url=DOL_URL_ROOT.'/commande/list.php?viewstatut=-3'; $response->img=img_object($langs->trans("Orders"),"order"); + $generic_commande = new Commande($this->db); + while ($obj=$this->db->fetch_object($resql)) { - $response->nbtodo++; + $response->nbtodo++; - $date_to_test = empty($obj->delivery_date) ? $obj->datec : $obj->delivery_date; + $generic_commande->statut = $obj->fk_statut; + $generic_commande->date_livraison = $obj->delivery_date; - if ($obj->fk_statut != 3 && $this->db->jdate($date_to_test) < ($now - $conf->commande->client->warning_delay)) { + if ($generic_commande->hasDelay()) { $response->nbtodolate++; } } @@ -3341,6 +3342,24 @@ class Commande extends CommonOrder return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); } + + /** + * Is the customer order delayed? + * + * @return bool + */ + public function hasDelay() + { + global $conf; + + if (!($this->statut > Commande::STATUS_DRAFT) && ($this->statut < Commande::STATUS_CLOSED)) { + return false; + } + + $now = dol_now(); + + return max($this->date_commande, $this->date_livraison) < ($now - $conf->commande->client->warning_delay); + } } diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 6af44d4a7d6c9cc32215aca0250277fa91b5bf7a..1c2f34c09310158dfb8c6d105e5efb67fc67a563 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -357,9 +357,11 @@ if ($resql) $var=!$var; print '<tr '.$bc[$var].'>'; print '<td class="nowrap">'; - $generic_commande->id=$objp->rowid; $generic_commande->ref=$objp->ref; + $generic_commande->statut = $objp->fk_statut; + $generic_commande->date_commande = $db->jdate($objp->date_commande); + $generic_commande->date_livraison = $db->jdate($objp->date_delivery); $generic_commande->ref_client = $objp->ref_client; $generic_commande->total_ht = $objp->total_ht; $generic_commande->total_tva = $objp->total_tva; @@ -444,8 +446,9 @@ if ($resql) // warning late icon print '<td style="min-width: 20px" class="nobordernopadding nowrap">'; - if (($objp->fk_statut > 0) && ($objp->fk_statut < 3) && max($db->jdate($objp->date_commande),$db->jdate($objp->date_delivery)) < ($now - $conf->commande->client->warning_delay)) - print img_picto($langs->trans("Late"),"warning"); + if ($generic_commande->hasDelay()) { + print img_picto($langs->trans("Late"), "warning"); + } if(!empty($objp->note_private)) { print ' <span class="note">'; diff --git a/htdocs/commande/orderstoinvoice.php b/htdocs/commande/orderstoinvoice.php index cb3ede38f2488f4485608ab868b2e10e2928c0fc..2896a6e22c61835b6afd0f62b7100ef440666237 100644 --- a/htdocs/commande/orderstoinvoice.php +++ b/htdocs/commande/orderstoinvoice.php @@ -640,6 +640,9 @@ if (($action != 'create' && $action != 'add') || ($action == 'create' && $error) $generic_commande->id=$objp->rowid; $generic_commande->ref=$objp->ref; + $generic_commande->statut = $objp->fk_statut; + $generic_commande->date_commande = $db->jdate($objp->date_commande); + $generic_commande->date_livraison = $db->jdate($objp->date_livraison); print '<table class="nobordernopadding"><tr class="nocellnopadd">'; print '<td class="nobordernopadding nowrap">'; @@ -647,7 +650,9 @@ if (($action != 'create' && $action != 'add') || ($action == 'create' && $error) print '</td>'; print '<td width="20" class="nobordernopadding nowrap">'; - if (($objp->fk_statut > 0) && ($objp->fk_statut < 3) && $db->jdate($objp->date_valid) < ($now - $conf->commande->client->warning_delay)) print img_picto($langs->trans("Late"),"warning"); + if ($generic_commande->hasDelay()) { + print img_picto($langs->trans("Late"),"warning"); + } print '</td>'; print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">'; diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 887fc57f0894146a4a09e57d1a699225b31ab28e..8c5a2a727b24192e25a953be3a010f7e167294bd 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -1148,6 +1148,10 @@ class AccountLine extends CommonObject var $ref; var $datec; var $dateo; + + /** + * Value date + */ var $datev; var $amount; var $label; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index a4a3c8a1e83c4ba026ab9b1192b08cb63d0df66d..72583386d80680dc59978cc74d84d1c407819c55 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -3223,8 +3223,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 2d70166a49f0c703cf0a6da077be75b77d0a86c6..98afb750fd680c640c36ebc1836501354e3a7a9b 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3246,11 +3246,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++; } } @@ -3707,6 +3711,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 d88f72f171e3be2b09661e770a15e3877857a08b..6a1e7894701ab91f1f18b31748c384451242207e 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -379,6 +379,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(); @@ -418,7 +420,7 @@ if ($resql) // Date limit print '<td align="center" class="nowrap">'.dol_print_date($datelimit,'day'); - if ($datelimit < ($now - $conf->facture->client->warning_delay) && ! $objp->paye && $objp->fk_statut == 1 && ! $paiement) + if ($facturestatic->hasDelay()) { print img_warning($langs->trans('Late')); } diff --git a/htdocs/compta/facture/mergepdftool.php b/htdocs/compta/facture/mergepdftool.php index 5acca49d1b12f2ef14381c58b6c7b6fb872e1d8b..498d6051f97571c1a105beeb5f271c44d306f709 100644 --- a/htdocs/compta/facture/mergepdftool.php +++ b/htdocs/compta/facture/mergepdftool.php @@ -734,6 +734,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); print '<table class="nobordernopadding"><tr class="nocellnopadd">'; @@ -744,7 +746,9 @@ if ($resql) // Warning picto print '<td width="20" class="nobordernopadding nowrap">'; - 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 '</td>'; // PDF Picto diff --git a/htdocs/compta/facture/prelevement.php b/htdocs/compta/facture/prelevement.php index be78b422fe63647e4a253390b15506496c183702..78a93d7da0d655ed035f9749155f776c7c24a9a8 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 5fb1d638a883ad2beb94ac26200f6b87356eff4a..5b0e8ec288dcfd4e9a669216b9565be53f450d22 100644 --- a/htdocs/compta/index.php +++ b/htdocs/compta/index.php @@ -359,11 +359,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 '</td>'; print '<td width="20" class="nobordernopadding nowrap">'; - 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 '</td>'; print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">'; $filename=dol_sanitizeFileName($obj->facnumber); @@ -801,10 +805,14 @@ if (! empty($conf->facture->enabled) && $user->rights->facture->lire) $facturestatic->total_tva=$obj->total_tva; $facturestatic->total_ttc=$obj->total_ttc; $facturestatic->type=$obj->type; + $facturestatic->statut = $obj->fk_statut; + $facturestatic->date_lim_reglement = $db->jdate($obj->datelimite); print $facturestatic->getNomUrl(1,''); print '</td>'; print '<td width="20" class="nobordernopadding nowrap">'; - 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 '</td>'; print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">'; $filename=dol_sanitizeFileName($obj->facnumber); diff --git a/htdocs/compta/paiement/cheque/class/remisecheque.class.php b/htdocs/compta/paiement/cheque/class/remisecheque.class.php index df401f4c35d5733467af423b90d1d0a2c196287f..3ed2ad7711c7f82cfc3bf17794902ac367175cbf 100644 --- a/htdocs/compta/paiement/cheque/class/remisecheque.class.php +++ b/htdocs/compta/paiement/cheque/class/remisecheque.class.php @@ -44,6 +44,13 @@ class RemiseCheque extends CommonObject var $errno; public $statut; + public $amount; + public $date_bordereau; + public $account_id; + public $account_label; + public $author_id; + public $nbcheque; + public $number; /** * Constructor diff --git a/htdocs/core/boxes/box_factures.php b/htdocs/core/boxes/box_factures.php index d04c3e48a3bf8e9c10ec555b11157b8c148ced18..f50bff34a863e4f60bd323ed499f1cfe79b633c2 100644 --- a/htdocs/core/boxes/box_factures.php +++ b/htdocs/core/boxes/box_factures.php @@ -108,12 +108,18 @@ class box_factures extends ModeleBoxes $facturestatic->total_ht = $objp->total_ht; $facturestatic->total_tva = $objp->total_tva; $facturestatic->total_ttc = $objp->total_ttc; + $facturestatic->statut = $objp->fk_statut; + $facturestatic->date_lim_reglement = $db->jdate($objp->datelimite); + $societestatic->id = $objp->socid; $societestatic->name = $objp->name; $societestatic->code_client = $objp->code_client; + $late = ''; - if ($objp->paye == 0 && ($objp->fk_statut != 2 && $objp->fk_statut != 3) && $datelimite < ($now - $conf->facture->client->warning_delay)) { $late = img_warning(sprintf($l_due_date,dol_print_date($datelimite,'day')));} + if ($facturestatic->hasDelay()) { + $late = img_warning(sprintf($l_due_date,dol_print_date($datelimite,'day'))); + } $this->info_box_contents[$line][] = array( 'td' => 'align="left"', diff --git a/htdocs/core/boxes/box_factures_fourn.php b/htdocs/core/boxes/box_factures_fourn.php index 2f31fa61f786d23ac41a2e42662119a6819831b6..7c90bb696833112b34a67c816bf1a08dacca5838 100644 --- a/htdocs/core/boxes/box_factures_fourn.php +++ b/htdocs/core/boxes/box_factures_fourn.php @@ -93,7 +93,6 @@ class box_factures_fourn extends ModeleBoxes if ($result) { $num = $db->num_rows($result); - $now=dol_now(); $line = 0; $l_due_date = $langs->trans('Late').' ('.$langs->trans('DateEcheance').': %s)'; @@ -108,6 +107,8 @@ class box_factures_fourn extends ModeleBoxes $facturestatic->total_ht = $objp->total_ht; $facturestatic->total_tva = $objp->total_tva; $facturestatic->total_ttc = $objp->total_ttc; + $facturestatic->date_echeance = $datelimite; + $facturestatic->statut = $objp->fk_statut; $thirdpartytmp->id = $objp->socid; $thirdpartytmp->name = $objp->name; $thirdpartytmp->fournisseur = 1; @@ -115,7 +116,10 @@ class box_factures_fourn extends ModeleBoxes $thirdpartytmp->logo = $objp->logo; $late = ''; - if ($objp->paye == 0 && $datelimite && $datelimite < ($now - $conf->facture->fournisseur->warning_delay)) $late=img_warning(sprintf($l_due_date, dol_print_date($datelimite,'day'))); + + if ($facturestatic->hasDelay()) { + $late=img_warning(sprintf($l_due_date, dol_print_date($datelimite,'day'))); + } $this->info_box_contents[$line][] = array( 'td' => 'align="left"', diff --git a/htdocs/core/boxes/box_factures_fourn_imp.php b/htdocs/core/boxes/box_factures_fourn_imp.php index ecea4a27fd1a1f282123651725ba6c7bc34e4407..9bf302b2e1844171723152ac11c74c6560c309bb 100644 --- a/htdocs/core/boxes/box_factures_fourn_imp.php +++ b/htdocs/core/boxes/box_factures_fourn_imp.php @@ -86,11 +86,12 @@ class box_factures_fourn_imp extends ModeleBoxes if ($result) { $num = $db->num_rows($result); - $now=dol_now(); $line = 0; $l_due_date = $langs->trans('Late').' ('.$langs->trans('DateEcheance').': %s)'; + $facturestatic = new FactureFournisseur($db); + while ($line < $num) { $objp = $db->fetch_object($result); @@ -99,9 +100,13 @@ class box_factures_fourn_imp extends ModeleBoxes $thirdpartytmp->name = $objp->name; $thirdpartytmp->code_client = $objp->code_client; $thirdpartytmp->logo = $objp->logo; + $facturestatic->date_echeance = $datelimite; + $facturestatic->statut = $objp->fk_statut; $late=''; - if ($datelimite && $datelimite < ($now - $conf->facture->fournisseur->warning_delay)) $late=img_warning(sprintf($l_due_date,dol_print_date($datelimite,'day'))); + if ($facturestatic->hasDelay()) { + $late=img_warning(sprintf($l_due_date,dol_print_date($datelimite,'day'))); + } $tooltip = $langs->trans('SupplierInvoice') . ': ' . ($objp->ref?$objp->ref:$objp->facid) . '<br>' . $langs->trans('RefSupplier') . ': ' . $objp->ref_supplier; $this->info_box_contents[$line][] = array( diff --git a/htdocs/core/boxes/box_factures_imp.php b/htdocs/core/boxes/box_factures_imp.php index 42e889138cc4e402a2c81cb534dd62fb7fa9d4be..63ce986e18139478688594fd957ac4458747d914 100644 --- a/htdocs/core/boxes/box_factures_imp.php +++ b/htdocs/core/boxes/box_factures_imp.php @@ -108,6 +108,8 @@ class box_factures_imp extends ModeleBoxes $facturestatic->total_ht = $objp->total_ht; $facturestatic->total_tva = $objp->total_tva; $facturestatic->total_ttc = $objp->total_ttc; + $facturestatic->statut = $objp->fk_statut; + $facturestatic->date_lim_reglement = $db->jdate($objp->datelimite); $societestatic->id = $objp->socid; $societestatic->name = $objp->name; $societestatic->client = 1; @@ -115,7 +117,9 @@ class box_factures_imp extends ModeleBoxes $societestatic->logo = $objp->logo; $late=''; - if ($datelimite < ($now - $conf->facture->client->warning_delay)) $late = img_warning(sprintf($l_due_date,dol_print_date($datelimite,'day'))); + if ($facturestatic->hasDelay()) { + $late = img_warning(sprintf($l_due_date,dol_print_date($datelimite,'day'))); + } $this->info_box_contents[$line][] = array( 'td' => 'align="left"', diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 9bd341e357ce63d5a770fe560c50581d8ee57b79..5e207f0b4b613de1ed4ff5d62f20b713beaa1622 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -72,7 +72,11 @@ class CommandeFournisseur extends CommonOrder var $date_approve; var $date_approve2; // Used when SUPPLIER_ORDER_DOUBLE_APPROVAL is set var $date_commande; - var $date_livraison; // Date livraison souhaitee + + /** + * Delivery date + */ + var $date_livraison; var $total_ht; var $total_tva; var $total_localtax1; // Total Local tax 1 @@ -2292,7 +2296,7 @@ class CommandeFournisseur extends CommonOrder $resql=$this->db->query($sql); if ($resql) { - $now=dol_now(); + $commandestatic = new CommandeFournisseur($this->db); $response = new WorkboardResponse(); $response->warning_delay=$conf->commande->fournisseur->warning_delay/60/60/24; @@ -2304,8 +2308,11 @@ class CommandeFournisseur extends CommonOrder { $response->nbtodo++; - $date_to_test = empty($obj->delivery_date) ? $obj->datec : $obj->delivery_date; - if ($obj->fk_statut != 3 && $this->db->jdate($date_to_test) < ($now - $conf->commande->fournisseur->warning_delay)) { + $commandestatic->date_livraison = $this->db->jdate($obj->delivery_date); + $commandestatic->date_commande = $this->db->jdate($obj->datec); + $commandestatic->statut = $obj->fk_statut; + + if ($commandestatic->hasDelay()) { $response->nbtodolate++; } } @@ -2447,6 +2454,21 @@ class CommandeFournisseur extends CommonOrder return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); } + + /** + * Is the supplier order delayed? + * + * @return bool + */ + public function hasDelay() + { + global $conf; + + $now = dol_now(); + $date_to_test = empty($this->date_livraison) ? $this->date_commande : $this->date_livraison; + + return ($this->statut != 3) && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay); + } } diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 5e24417f61851ebb9e115190221129c04e715072..c82f3c01941bee1e003306a168df35327353ce66 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -63,7 +63,12 @@ class FactureFournisseur extends CommonInvoice * @see FactureFournisseur::STATUS_DRAFT, FactureFournisseur::STATUS_VALIDATED, FactureFournisseur::STATUS_PAID, FactureFournisseur::STATUS_ABANDONED */ var $statut; - //! 1 si facture payee COMPLETEMENT, 0 sinon (ce champ ne devrait plus servir car insuffisant) + + /** + * Set to 1 if the invoice is completely paid, otherwise is 0 + * @var int + * @deprecated Use statuses stored in self::statut + */ var $paye; var $author; @@ -1409,7 +1414,7 @@ class FactureFournisseur extends CommonInvoice { global $conf, $user, $langs; - $sql = 'SELECT ff.rowid, ff.date_lim_reglement as datefin'; + $sql = 'SELECT ff.rowid, ff.date_lim_reglement as datefin, ff.fk_statut'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as ff'; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= ' WHERE ff.paye=0'; @@ -1430,10 +1435,16 @@ class FactureFournisseur extends CommonInvoice $response->url=DOL_URL_ROOT.'/fourn/facture/list.php?filtre=paye:0'; $response->img=img_object($langs->trans("Bills"),"bill"); + $facturestatic = new FactureFournisseur($this->db); + while ($obj=$this->db->fetch_object($resql)) { $response->nbtodo++; - if (! empty($obj->datefin) && $this->db->jdate($obj->datefin) < ($now - $conf->facture->fournisseur->warning_delay)) { + + $facturestatic->date_echeance = $this->db->jdate($obj->datefin); + $facturestatic->statut = $obj->fk_statut; + + if ($facturestatic->hasDelay()) { $response->nbtodolate++; } } @@ -1822,6 +1833,24 @@ class FactureFournisseur extends CommonInvoice return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); } + + /** + * Is the payment of the supplier invoice having a delay? + * + * @return bool + */ + public function hasDelay() + { + global $conf; + + $now = dol_now(); + + if (!$this->date_echeance) { + return false; + } + + return ($this->statut == self::STATUS_VALIDATED) && ($this->date_echeance < ($now - $conf->facture->fournisseur->warning_delay)); + } } diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 6032a7a5036ba6b59b952b524aca1d13c8ba16d5..b0629909ac0e166a6de3b195b2c3bbd53a38452e 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -1905,7 +1905,9 @@ else // Due date print '<tr><td>'.$form->editfieldkey("DateMaxPayment",'date_lim_reglement',$object->date_echeance,$object,$form_permission,'datepicker').'</td><td colspan="3">'; print $form->editfieldval("DateMaxPayment",'date_lim_reglement',$object->date_echeance,$object,$form_permission,'datepicker'); - if ($action != 'editdate_lim_reglement' && $object->statut < FactureFournisseur::STATUS_CLOSED && $object->date_echeance && $object->date_echeance < ($now - $conf->facture->fournisseur->warning_delay)) print img_warning($langs->trans('Late')); + if ($action != 'editdate_lim_reglement' && $object->hasDelay()) { + print img_warning($langs->trans('Late')); + } print '</td>'; // Conditions de reglement par defaut diff --git a/htdocs/fourn/facture/impayees.php b/htdocs/fourn/facture/impayees.php index 83d4b830c5f43f371255a1336d47b52b998d9b68..dbe235cdebc62e5d493e3cb67f3c6c2399d45c5c 100644 --- a/htdocs/fourn/facture/impayees.php +++ b/htdocs/fourn/facture/impayees.php @@ -230,6 +230,9 @@ if ($user->rights->fournisseur->facture->lire) { $objp = $db->fetch_object($resql); + $facturestatic->statut = $objp->fk_statut; + $facturestatic->date_echeance = $db->jdate($objp->datelimite); + $var=!$var; print "<tr ".$bc[$var].">"; @@ -245,7 +248,9 @@ if ($user->rights->fournisseur->facture->lire) print '<td class="nowrap" align="center">'.dol_print_date($db->jdate($objp->df),'day')."</td>\n"; print '<td class="nowrap" align="center">'.dol_print_date($db->jdate($objp->datelimite),'day'); - if ($objp->datelimite && $db->jdate($objp->datelimite) < ($now - $conf->facture->fournisseur->warning_delay) && ! $objp->paye && $objp->fk_statut == 1) print img_warning($langs->trans("Late")); + if ($facturestatic->hasDelay()) { + print img_warning($langs->trans("Late")); + } print "</td>\n"; print '<td>'; diff --git a/htdocs/fourn/facture/list.php b/htdocs/fourn/facture/list.php index dc8adddec396d2194ca2cc3d158e932fb35470ad..f5ed63108a68b7c61a8d5c0fefcb4615ea66a9bf 100644 --- a/htdocs/fourn/facture/list.php +++ b/htdocs/fourn/facture/list.php @@ -323,6 +323,10 @@ if ($resql) while ($i < min($num,$limit)) { $obj = $db->fetch_object($resql); + + $facturestatic->date_echeance = $db->jdate($obj->date_echeance); + $facturestatic->statut = $obj->fk_statut; + $var=!$var; print "<tr ".$bc[$var].">"; @@ -342,7 +346,9 @@ if ($resql) print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($obj->datef),'day').'</td>'; print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($obj->date_echeance),'day'); - if (($obj->paye == 0) && ($obj->fk_statut > 0) && $obj->date_echeance && $db->jdate($obj->date_echeance) < ($now - $conf->facture->fournisseur->warning_delay)) print img_picto($langs->trans("Late"),"warning"); + if ($facturestatic->hasDelay()) { + print img_picto($langs->trans("Late"),"warning"); + } print '</td>'; print '<td>'.dol_trunc($obj->libelle,36).'</td>'; print '<td>'; diff --git a/htdocs/societe/societecontact.php b/htdocs/societe/societecontact.php index 928424b1d8be00fe1a5c29f7bcfd0da557242909..4d2382e6eee174df387d2625afe67d5543cb27c3 100644 --- a/htdocs/societe/societecontact.php +++ b/htdocs/societe/societecontact.php @@ -246,6 +246,8 @@ if ($id > 0 || ! empty($ref)) $memberstatic->ref=$objp->rowid; $memberstatic->lastname=$objp->lastname; $memberstatic->firstname=$objp->firstname; + $memberstatic->statut=$objp->statut; + $memberstatic->datefin=$db->jdate($objp->datefin); $companyname=$objp->company; @@ -290,7 +292,9 @@ if ($id > 0 || ! empty($ref)) { print '<td align="center" class="nowrap">'; print dol_print_date($datefin,'day'); - if ($datefin < ($now - $conf->adherent->cotisation->warning_delay) && $objp->statut > 0) print " ".img_warning($langs->trans("SubscriptionLate")); + if ($memberstatic->hasDelay()) { + print " ".img_warning($langs->trans("SubscriptionLate")); + } print '</td>'; } else