subtotaltitle/ajax/get_sections.php

33 lines
1.1 KiB
PHP
Executable file

<?php
define('NOTOKENRENEWAL', 1);
require '../../../main.inc.php';
require_once __DIR__.'/../lib/subtotaltitle.lib.php';
$facture_id = GETPOST('facture_id', 'int');
subtotaltitle_debug_log('🔄 get_sections: facture=' . $facture_id);
if (!$facture_id) {
echo json_encode(array('success' => false, 'error' => 'Missing facture_id'));
exit;
}
// Hole ALLE Sections
$sql = "SELECT s.rowid, s.title, s.line_order, ";
$sql .= " (SELECT COUNT(*) FROM ".MAIN_DB_PREFIX."facture_lines_manager p WHERE p.parent_section = s.rowid) as product_count";
$sql .= " FROM ".MAIN_DB_PREFIX."facture_lines_manager s";
$sql .= " WHERE s.fk_facture = ".(int)$facture_id;
$sql .= " AND s.line_type = 'section'";
$sql .= " ORDER BY s.line_order";
$resql = $db->query($sql);
$sections = array();
while ($obj = $db->fetch_object($resql)) {
$sections[] = array(
'id' => $obj->rowid,
'title' => $obj->title,
'line_order' => $obj->line_order,
'is_empty' => ($obj->product_count == 0)
);
}
echo json_encode(array('success' => true, 'sections' => $sections));