Skip to content

Commit 740ad5b

Browse files
alexandre-janniauxeldy
authored andcommitted
purchasesjournal: fix empty IN () SQL request
`WHERE xx IN ()` is not allowed in PostgreSQL queries, and result in the following fatal error: GROUP BY fk_facture_fourn 33 DoliDBPgsql::query SQL Error message: ERROR: 42601: syntax error at or near ")" LINE 10: AND fk_facture_fourn IN () ^ We can check whether we have valid invoices before running the query, since the query will only check whether the invoices are complete or not. It also fixes the following error on the development PHP output. Fatal error: Uncaught TypeError: pg_num_rows(): Argument #1 ($result) must be of type PgSql\Result, bool given in /var/www/html/core/db/pgsql.class.php:654 Stack trace: #0 /var/www/html/core/db/pgsql.class.php(654): pg_num_rows(false) #1 /var/www/html/accountancy/journal/purchasesjournal.php(418): DoliDBPgsql->num_rows(false) #2 {main} thrown in /var/www/html/core/db/pgsql.class.php on line 654 Fixes Dolibarr#32374
1 parent 1def03d commit 740ad5b

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

htdocs/accountancy/journal/purchasesjournal.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -399,34 +399,34 @@
399399
}
400400
}
401401
*/
402+
402403
// New way, single query, load all unbound lines
403-
$sql = "
404-
SELECT
405-
fk_facture_fourn,
406-
COUNT(fd.rowid) as nb
407-
FROM
408-
" . MAIN_DB_PREFIX . "facture_fourn_det as fd
409-
WHERE
410-
fd.product_type <= 2
411-
AND fd.fk_code_ventilation <= 0
412-
AND fd.total_ttc <> 0
413-
AND fk_facture_fourn IN (".$db->sanitize(implode(",", array_keys($tabfac))).")
414-
GROUP BY fk_facture_fourn
415-
";
416-
$resql = $db->query($sql);
417-
418-
$num = $db->num_rows($resql);
419-
$i = 0;
420-
while ($i < $num) {
421-
$obj = $db->fetch_object($resql);
422-
if ($obj->nb > 0) {
423-
$errorforinvoice[$obj->fk_facture_fourn] = 'somelinesarenotbound';
404+
if (!empty($tabfac)) {
405+
$sql = "
406+
SELECT
407+
fk_facture_fourn,
408+
COUNT(fd.rowid) as nb
409+
FROM
410+
" . MAIN_DB_PREFIX . "facture_fourn_det as fd
411+
WHERE
412+
fd.product_type <= 2
413+
AND fd.fk_code_ventilation <= 0
414+
AND fd.total_ttc <> 0
415+
AND fk_facture_fourn IN (".$db->sanitize(implode(",", array_keys($tabfac))).")
416+
GROUP BY fk_facture_fourn
417+
";
418+
$resql = $db->query($sql);
419+
420+
$num = $db->num_rows($resql);
421+
$i = 0;
422+
while ($i < $num) {
423+
$obj = $db->fetch_object($resql);
424+
if ($obj->nb > 0) {
425+
$errorforinvoice[$obj->fk_facture_fourn] = 'somelinesarenotbound';
426+
}
427+
$i++;
424428
}
425-
$i++;
426429
}
427-
//var_dump($errorforinvoice);exit;
428-
429-
430430

431431
// Bookkeeping Write
432432
if ($action == 'writebookkeeping' && !$error && $user->hasRight('accounting', 'bind', 'write')) {

0 commit comments

Comments
 (0)