SELECT
    E.DO_Piece           AS NumeroFacture,
    E.DO_Date,
    E.DO_Tiers,
    E.DE_No              AS Depot,
    E.DO_NetAPayer,
    E.DO_MontantRegle,
    (E.DO_NetAPayer - ISNULL(E.DO_MontantRegle,0)) AS ResteAPayer,

    L.DL_No,
    L.AR_Ref,
    L.DL_Design,
    L.DL_Qte,
    L.DL_PrixUnitaire,
    L.DL_MontantHT,
    L.DL_Taxe1
FROM dbo.F_DOCENTETE E
JOIN dbo.F_DOCLIGNE  L
  ON L.DO_Domaine = E.DO_Domaine
 AND L.DO_Type    = E.DO_Type
 AND L.DO_Piece   = E.DO_Piece
WHERE E.DO_Domaine = 0
  AND E.DO_Type    = 6   -- Factures
  AND ISNULL(E.DO_MontantRegle,0) < ISNULL(E.DO_NetAPayer,0)
ORDER BY E.DO_Date DESC, E.DO_Piece, L.DL_No;
