313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
|
}
// Y'a sûrement moyen d'améliorer tout ça pour que le maximum de travail
// soit fait au niveau du SQL, mais pour le moment ça marche
$res = $db->prepare('SELECT compte, debit, credit, (SELECT position FROM compta_comptes WHERE id = compte) AS position
FROM
(SELECT compte_debit AS compte, SUM(montant) AS debit, NULL AS credit
FROM compta_journal WHERE id_exercice = 1 GROUP BY compte_debit
UNION
SELECT compte_credit AS compte, NULL AS debit, SUM(montant) AS credit
FROM compta_journal WHERE id_exercice = 1 GROUP BY compte_credit)
WHERE compte IN (SELECT id FROM compta_comptes WHERE position IN ('.implode(', ', $include).'))
ORDER BY base64(compte) COLLATE BINARY ASC;'
)->execute();
while ($row = $res->fetchArray(SQLITE3_NUM))
{
list($compte, $debit, $credit, $position) = $row;
|
|
|
|
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
|
}
// Y'a sûrement moyen d'améliorer tout ça pour que le maximum de travail
// soit fait au niveau du SQL, mais pour le moment ça marche
$res = $db->prepare('SELECT compte, debit, credit, (SELECT position FROM compta_comptes WHERE id = compte) AS position
FROM
(SELECT compte_debit AS compte, SUM(montant) AS debit, NULL AS credit
FROM compta_journal WHERE id_exercice = '.(int)$exercice.' GROUP BY compte_debit
UNION
SELECT compte_credit AS compte, NULL AS debit, SUM(montant) AS credit
FROM compta_journal WHERE id_exercice = '.(int)$exercice.' GROUP BY compte_credit)
WHERE compte IN (SELECT id FROM compta_comptes WHERE position IN ('.implode(', ', $include).'))
ORDER BY base64(compte) COLLATE BINARY ASC;'
)->execute();
while ($row = $res->fetchArray(SQLITE3_NUM))
{
list($compte, $debit, $credit, $position) = $row;
|