diff --git a/htdocs/compta/fiche.php b/htdocs/compta/fiche.php index b9a6ab1bc12..151bbdcabbe 100644 --- a/htdocs/compta/fiche.php +++ b/htdocs/compta/fiche.php @@ -242,9 +242,10 @@ if ($socid > 0) print '
| facid\">".img_object($langs->trans("ShowBill"),"bill")." ".$objp->facnumber." | \n"; + print ''; + $facturestatic->id=$objp->facid; + $facturestatic->ref=$objp->facnumber; + $facturestatic->type=$objp->type; + print $facturestatic->getNomUrl(1); + print ' | '; if ($objp->df > 0) { print "".dolibarr_print_date($objp->df)." | \n"; diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index c3147eaf43f..cb763e65853 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -1012,7 +1012,7 @@ class Facture extends CommonObject } // Controle que facture source non deja remplacee par une autre - $idreplacement=$facreplaced->getIdReplacingInvoice(); + $idreplacement=$facreplaced->getIdReplacingInvoice('validated'); if ($idreplacement && $idreplacement != $rowid) { $facreplacement=new Facture($this->db); @@ -1791,14 +1791,20 @@ class Facture extends CommonObject /** * \brief Renvoie l'id de la facture qui la remplace - * \return int <0 si ko, 0 si aucune facture ne remplace, id facture sinon + * \param option filtre sur statut ('', 'validated', ...) + * \return int <0 si ko, 0 si aucune facture ne remplace, id facture sinon */ - function getIdReplacingInvoice() + function getIdReplacingInvoice($option='') { $sql = 'SELECT rowid'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture'; $sql.= ' WHERE fk_facture_source = '.$this->id; $sql.= ' AND type < 2'; + if ($option == 'validated') $sql.= ' AND fk_statut = 1'; + $sql.= ' ORDER BY fk_statut DESC'; // Au cas ou base corrompu et qu'il y a une + // facture de remplacement validee et une autre non + // on donne priorité à la validée. Ne devrait pas arriver + $resql=$this->db->query($sql); if ($resql) {