All checks were successful
Deploy netdiag / deploy (push) Successful in 13s
- Spalte c.tms in SELECT aufgenommen (Dolibarr-Änderungszeitstempel) - ORDER BY c.tms DESC statt date_commande DESC — zuletzt bearbeitete Aufträge stehen oben, passend zur App-Anzeige "bearb. <Datum>" - tms-Feld in der API-Antwort ergänzt - README: Hinweis auf Deploy-Pipeline ergänzt Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
121 lines
4.4 KiB
PHP
121 lines
4.4 KiB
PHP
<?php
|
|
/* Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/**
|
|
* \file netdiag/api/orders.php
|
|
* \ingroup netdiag
|
|
* \brief API-Endpunkt: Aufträge listen (?open=1&q=) oder Auftragsdetail (?id=).
|
|
*
|
|
* Auftragsstatus (Dolibarr commande.fk_statut):
|
|
* -1 = storniert, 0 = Entwurf, 1 = validiert, 2 = in Bearbeitung,
|
|
* 3 = abgeschlossen. "Aktiv" = Status 0/1/2.
|
|
*/
|
|
|
|
require_once __DIR__.'/netdiag_api.lib.php';
|
|
|
|
netdiag_api_bootstrap();
|
|
|
|
/** @var DoliDB $db */
|
|
|
|
$user = netdiag_api_authenticate($db);
|
|
|
|
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
|
|
$q = isset($_GET['q']) ? trim((string) $_GET['q']) : '';
|
|
$onlyopen = !empty($_GET['open']);
|
|
$limit = isset($_GET['limit']) ? min(200, max(1, (int) $_GET['limit'])) : 80;
|
|
|
|
$prefix = $db->prefix();
|
|
|
|
// ---- Auftragsdetail ----
|
|
if ($id > 0) {
|
|
$sql = "SELECT c.rowid, c.ref, c.ref_client, c.date_commande, c.fk_statut, c.note_public,";
|
|
$sql .= " s.rowid as socid, s.nom as socname, s.address, s.zip, s.town, s.phone, s.email";
|
|
$sql .= " FROM ".$prefix."commande as c";
|
|
$sql .= " LEFT JOIN ".$prefix."societe as s ON s.rowid = c.fk_soc";
|
|
$sql .= " WHERE c.rowid = ".((int) $id)." AND c.entity IN (".getEntity('commande').")";
|
|
$resql = $db->query($sql);
|
|
if (!$resql || !($obj = $db->fetch_object($resql))) {
|
|
netdiag_api_error('Auftrag nicht gefunden', 404);
|
|
}
|
|
$order = array(
|
|
'id' => (int) $obj->rowid,
|
|
'ref' => $obj->ref,
|
|
'refClient' => $obj->ref_client,
|
|
'date' => $db->jdate($obj->date_commande),
|
|
'status' => (int) $obj->fk_statut,
|
|
'open' => ((int) $obj->fk_statut >= 0 && (int) $obj->fk_statut < 3),
|
|
'note' => $obj->note_public,
|
|
'customer' => array(
|
|
'id' => (int) $obj->socid,
|
|
'name' => $obj->socname,
|
|
'address' => $obj->address,
|
|
'zip' => $obj->zip,
|
|
'town' => $obj->town,
|
|
'phone' => $obj->phone,
|
|
'email' => $obj->email,
|
|
),
|
|
);
|
|
$protocols = netdiag_api_protocol_list($db, ' AND p.fk_commande = '.((int) $id));
|
|
|
|
netdiag_api_respond(array('order' => $order, 'protocols' => $protocols));
|
|
}
|
|
|
|
// ---- Auftragsliste ----
|
|
$sql = "SELECT c.rowid, c.ref, c.ref_client, c.date_commande, c.tms, c.fk_statut, c.note_public,";
|
|
$sql .= " s.rowid as socid, s.nom as socname, s.address, s.zip, s.town,";
|
|
$sql .= " (SELECT COUNT(*) FROM ".$prefix."netdiag_protocol p WHERE p.fk_commande = c.rowid) as protocolcount";
|
|
$sql .= " FROM ".$prefix."commande as c";
|
|
$sql .= " LEFT JOIN ".$prefix."societe as s ON s.rowid = c.fk_soc";
|
|
$sql .= " WHERE c.entity IN (".getEntity('commande').")";
|
|
if ($onlyopen) {
|
|
// Aktive Aufträge: Entwurf / validiert / in Bearbeitung
|
|
$sql .= " AND c.fk_statut IN (0, 1, 2)";
|
|
}
|
|
if ($q !== '') {
|
|
$sql .= " AND (".natural_search(array('c.ref', 'c.ref_client', 's.nom', 's.town'), $q, 0, 1).")";
|
|
}
|
|
// Zuletzt bearbeitete zuerst — c.tms wird von Dolibarr bei jeder Änderung gesetzt
|
|
$sql .= " ORDER BY c.tms DESC, c.rowid DESC";
|
|
$sql .= $db->plimit($limit, 0);
|
|
|
|
$resql = $db->query($sql);
|
|
if (!$resql) {
|
|
netdiag_api_error('Datenbankfehler: '.$db->lasterror(), 500);
|
|
}
|
|
$orders = array();
|
|
while ($obj = $db->fetch_object($resql)) {
|
|
$orders[] = array(
|
|
'id' => (int) $obj->rowid,
|
|
'ref' => $obj->ref,
|
|
'refClient' => $obj->ref_client,
|
|
'date' => $db->jdate($obj->date_commande),
|
|
'tms' => $db->jdate($obj->tms),
|
|
'status' => (int) $obj->fk_statut,
|
|
'open' => ((int) $obj->fk_statut >= 0 && (int) $obj->fk_statut < 3),
|
|
'note' => $obj->note_public,
|
|
'protocolCount' => (int) $obj->protocolcount,
|
|
'customer' => array(
|
|
'id' => $obj->socid ? (int) $obj->socid : null,
|
|
'name' => $obj->socname,
|
|
'address' => $obj->address,
|
|
'zip' => $obj->zip,
|
|
'town' => $obj->town,
|
|
),
|
|
);
|
|
}
|
|
|
|
netdiag_api_respond(array('orders' => $orders));
|