diff --git a/htdocs/compta/commande/fiche.php b/htdocs/compta/commande/fiche.php index a4d2fe31c50..f75f1611f0a 100644 --- a/htdocs/compta/commande/fiche.php +++ b/htdocs/compta/commande/fiche.php @@ -397,9 +397,12 @@ if ($id > 0 || ! empty($ref)) $sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid,'; $sql.= ' p.description as product_desc'; $sql.= ' FROM '.MAIN_DB_PREFIX."commandedet as l"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_rang as r ON r.fk_parent = l.fk_commande AND r.parenttype = '".$commande->element."'"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product=p.rowid'; $sql.= " WHERE l.fk_commande = ".$commande->id; - $sql.= " ORDER BY l.rang, l.rowid"; + $sql.= " AND r.fk_child = l.rowid"; + $sql.= " AND r.childtype = '".$commande->element."'"; + $sql.= " ORDER BY r.rang, l.rowid"; $resql = $db->query($sql); if ($resql) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index e8aa2923d37..464dfde64ac 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1775,7 +1775,7 @@ if ($_GET['action'] == 'create') $sql.= ' WHERE pt.fk_propal = '.$object->id; $sql.= " AND r.fk_child = pt.rowid"; $sql.= " AND r.childtype = '".$object->element."'"; - $sql.= ' ORDER BY pt.rang ASC, pt.rowid'; + $sql.= ' ORDER BY r.rang ASC, pt.rowid'; } // TODO deplacer dans la classe if ($_GET['origin'] == 'commande') @@ -1792,7 +1792,7 @@ if ($_GET['action'] == 'create') $sql.= ' WHERE pt.fk_commande = '.$object->id; $sql.= " AND r.fk_child = pt.rowid"; $sql.= " AND r.childtype = '".$object->element."'"; - $sql.= ' ORDER BY pt.rowid ASC'; + $sql.= ' ORDER BY r.rang ASC, pt.rowid'; } // TODO deplacer dans la classe if ($_GET['origin'] == 'contrat') diff --git a/htdocs/compta/propal.php b/htdocs/compta/propal.php index 2791c1cf2c0..bb3e0725b09 100644 --- a/htdocs/compta/propal.php +++ b/htdocs/compta/propal.php @@ -327,9 +327,13 @@ if ($id > 0 || ! empty($ref)) $sql.= ' p.rowid as prodid, p.label as product_label, p.ref, p.fk_product_type, '; $sql.= ' p.description as product_desc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt'; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_rang as r ON r.fk_parent = pt.fk_propal AND r.parenttype = '".$propal->element."'"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid'; $sql.= ' WHERE pt.fk_propal = '.$propal->id; - $sql.= ' ORDER BY pt.rang ASC, pt.rowid'; + $sql.= " AND r.fk_child = pt.rowid"; + $sql.= " AND r.childtype = '".$propal->element."'"; + $sql.= ' ORDER BY r.rang ASC, pt.rowid'; + $resql = $db->query($sql); if ($resql) {