From bf24cc31474ae5ab2473e428ed2282885753375e Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Fri, 1 Apr 2005 17:55:55 +0000 Subject: [PATCH] Mise aux normes SQL --- htdocs/compta/index.php | 83 +++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 32 deletions(-) diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php index bbfe8ce70b8..83b0bcc5dbb 100644 --- a/htdocs/compta/index.php +++ b/htdocs/compta/index.php @@ -110,9 +110,11 @@ if ($conf->facture->enabled) $sql .= " AND f.fk_soc = $socidp"; } - if ( $db->query($sql) ) + $resql = $db->query($sql); + + if ( $resql ) { - $num = $db->num_rows(); + $num = $db->num_rows($resql); $i = 0; if ($num) @@ -123,7 +125,7 @@ if ($conf->facture->enabled) $var = True; while ($i < $num && $i < 20) { - $obj = $db->fetch_object(); + $obj = $db->fetch_object($resql); $var=!$var; print ''.img_object($langs->trans("ShowBill"),"bill").' '.$obj->facnumber.''; print ''.img_object($langs->trans("Showcompany"),"company").' '.$obj->nom.''; @@ -132,6 +134,7 @@ if ($conf->facture->enabled) print "
"; } + $db->free($resql); } else { @@ -151,9 +154,11 @@ if ($user->societe_id == 0) $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as c, ".MAIN_DB_PREFIX."c_chargesociales as cc"; $sql .= " WHERE c.fk_type = cc.id AND c.paye=0"; - if ( $db->query($sql) ) + $resql = $db->query($sql); + + if ( $resql ) { - $num = $db->num_rows(); + $num = $db->num_rows($resql); if ($num) { print ''; @@ -163,7 +168,7 @@ if ($user->societe_id == 0) $var = True; while ($i < $num) { - $obj = $db->fetch_object(); + $obj = $db->fetch_object($resql); $var = !$var; print ""; print ''; @@ -173,6 +178,7 @@ if ($user->societe_id == 0) } print '
'.$obj->libelle.'

'; } + $db->free($resql); } else { @@ -191,9 +197,11 @@ $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."bookmark as b"; $sql .= " WHERE b.fk_soc = s.idp AND b.fk_user = ".$user->id; $sql .= " ORDER BY lower(s.nom) ASC"; -if ( $db->query($sql) ) +$resql = $db->query($sql); + +if ( $resql ) { - $num = $db->num_rows(); + $num = $db->num_rows($resql); $i = 0; if ($num) { @@ -202,7 +210,7 @@ if ( $db->query($sql) ) $var = True; while ($i < $num) { - $obj = $db->fetch_object(); + $obj = $db->fetch_object($resql); $var = !$var; print ""; print ''.$obj->nom.''; @@ -212,8 +220,12 @@ if ( $db->query($sql) ) } print ''; } + $db->free($resql); +} +else +{ + dolibarr_print_error($db); } - print ''; @@ -237,9 +249,11 @@ if ($conf->commande->enabled && $user->rights->commande->lire) $sql .= " AND p.fk_soc = $socidp"; } - if ( $db->query($sql) ) + $resql = $db->query($sql); + + if ( $resql ) { - $num = $db->num_rows(); + $num = $db->num_rows($resql); if ($num) { $i = 0; @@ -253,26 +267,29 @@ if ($conf->commande->enabled && $user->rights->commande->lire) while ($i < $num) { $var=!$var; - $obj = $db->fetch_object(); - if ($obj->total_ht-$obj->tot_fht) { - print ""; - print "rowid\">".img_object($langs->trans("ShowOrder"),"order").' '; - print "rowid\">".$obj->ref.''; - - print ''.img_object($langs->trans("ShowCompany"),"company").' '; - print ''.$obj->nom.''; - print ''.price($obj->total_ht-$obj->tot_fht).''; - print ''.price($obj->total_ttc-$obj->tot_fttc).''; - $tot_ht += $obj->total_ht-$obj->tot_fht; - $tot_ttc += $obj->total_ttc-$obj->tot_fttc; - } - $i++; + $obj = $db->fetch_object($resql); + if ($obj->total_ht-$obj->tot_fht) + { + print ""; + print "rowid\">".img_object($langs->trans("ShowOrder"),"order").' '; + print "rowid\">".$obj->ref.''; + + print ''.img_object($langs->trans("ShowCompany"),"company").' '; + print ''.$obj->nom.''; + print ''.price($obj->total_ht-$obj->tot_fht).''; + print ''.price($obj->total_ttc-$obj->tot_fttc).''; + $tot_ht += $obj->total_ht-$obj->tot_fht; + $tot_ttc += $obj->total_ttc-$obj->tot_fttc; + } + $i++; } print ''.$langs->trans("Total").'   (Reste à facturer : '.price($tot_ttc).')'.price($tot_ht)."".price($tot_ttc).""; print "
"; } + $db->free($resql); } - else { + else + { dolibarr_print_error($db); } } @@ -295,9 +312,11 @@ if ($conf->facture->enabled) } $sql .= " GROUP BY f.facnumber, f.rowid, s.nom, s.idp, f.total, f.total_ttc"; - if ( $db->query($sql) ) + $resql = $db->query($sql); + + if ( $resql ) { - $num = $db->num_rows(); + $num = $db->num_rows($resql); $i = 0; if ($num) @@ -309,7 +328,7 @@ if ($conf->facture->enabled) $total_ttc = $totalam = $total = 0; while ($i < $num) { - $obj = $db->fetch_object(); + $obj = $db->fetch_object($resql); if ($i < 20) { @@ -321,7 +340,7 @@ if ($conf->facture->enabled) print ''.price($obj->am).''; } $total_ttc += $obj->total_ttc; - $total += $obj->total; + $total += $obj->total; $totalam += $obj->am; $i++; } @@ -329,7 +348,7 @@ if ($conf->facture->enabled) print ''.$langs->trans("Total").'   ('.$langs->trans("RemainderToTake").': '.price($total_ttc-$totalam).')'.price($total)."".price($total_ttc)."".price($totalam).""; print "
"; } - $db->free(); + $db->free($resql); } else {