[deploy] API: Schnell-Auftrag-Anlage + Kunden-Defaults + JWT 30 Tage
All checks were successful
Deploy bericht / deploy (push) Successful in 5s
All checks were successful
Deploy bericht / deploy (push) Successful in 5s
- POST /api/orders.php?action=create: legt Draft-Auftrag an, übernimmt Kunden-Defaults (Zahlungsbedingung, Zahlart, Bankkonto, Incoterms, Lieferadresse) und setzt Hauptansprechpartner als externen Kontakt. Titel wird in Extrafield options_auftragsbeschreibung abgelegt. - /api/customers.php: liefert cond_reglement_label + mode_reglement_label damit die PWA die übernommenen Defaults anzeigen kann. - JWT-TTL von 7 auf 30 Tage hochgesetzt — deckt Urlaubszeiten ab und verhindert häufiges Neu-Anmelden. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
062e5c1b50
commit
641e16a2bc
3 changed files with 99 additions and 1 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
* salt'ed mit "bericht-api-v1".
|
* salt'ed mit "bericht-api-v1".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('BERICHT_JWT_TTL')) define('BERICHT_JWT_TTL', 7 * 86400); // 7 Tage
|
if (!defined('BERICHT_JWT_TTL')) define('BERICHT_JWT_TTL', 30 * 86400); // 30 Tage
|
||||||
|
|
||||||
function bericht_jwt_secret()
|
function bericht_jwt_secret()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,18 @@ if (!$id) {
|
||||||
$soc = new Societe($db);
|
$soc = new Societe($db);
|
||||||
if ($soc->fetch($id) <= 0) api_fail('Kunde nicht gefunden', 404);
|
if ($soc->fetch($id) <= 0) api_fail('Kunde nicht gefunden', 404);
|
||||||
|
|
||||||
|
// Labels für Defaults ermitteln (werden beim Auftrag-Anlegen übernommen)
|
||||||
|
$cond_label = '';
|
||||||
|
if (!empty($soc->cond_reglement_id)) {
|
||||||
|
$rc = $db->query("SELECT libelle FROM ".$db->prefix()."c_payment_term WHERE rowid = ".((int) $soc->cond_reglement_id));
|
||||||
|
if ($rc && ($rco = $db->fetch_object($rc))) $cond_label = $rco->libelle;
|
||||||
|
}
|
||||||
|
$mode_label = '';
|
||||||
|
if (!empty($soc->mode_reglement_id)) {
|
||||||
|
$rm = $db->query("SELECT libelle FROM ".$db->prefix()."c_paiement WHERE id = ".((int) $soc->mode_reglement_id));
|
||||||
|
if ($rm && ($rmo = $db->fetch_object($rm))) $mode_label = $rmo->libelle;
|
||||||
|
}
|
||||||
|
|
||||||
// Aufträge des Kunden
|
// Aufträge des Kunden
|
||||||
$orders = array();
|
$orders = array();
|
||||||
$ro = $db->query("SELECT c.rowid, c.ref, c.date_commande, c.fk_statut, c.total_ttc"
|
$ro = $db->query("SELECT c.rowid, c.ref, c.date_commande, c.fk_statut, c.total_ttc"
|
||||||
|
|
@ -140,6 +152,10 @@ api_ok(array(
|
||||||
'email' => $soc->email,
|
'email' => $soc->email,
|
||||||
'siret' => $soc->idprof1 ?? '',
|
'siret' => $soc->idprof1 ?? '',
|
||||||
'vat' => $soc->tva_intra ?? '',
|
'vat' => $soc->tva_intra ?? '',
|
||||||
|
'cond_reglement_id' => (int) ($soc->cond_reglement_id ?? 0),
|
||||||
|
'cond_reglement_label' => $cond_label,
|
||||||
|
'mode_reglement_id' => (int) ($soc->mode_reglement_id ?? 0),
|
||||||
|
'mode_reglement_label' => $mode_label,
|
||||||
),
|
),
|
||||||
'orders' => $orders,
|
'orders' => $orders,
|
||||||
'invoices' => $invoices,
|
'invoices' => $invoices,
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,10 @@
|
||||||
* POST /api/orders.php?id=<id>&action=upload_photo
|
* POST /api/orders.php?id=<id>&action=upload_photo
|
||||||
* multipart: file=<binary> — fügt ein Foto zum Bericht des Auftrags hinzu
|
* multipart: file=<binary> — fügt ein Foto zum Bericht des Auftrags hinzu
|
||||||
* (legt automatisch einen Bericht an wenn keiner existiert)
|
* (legt automatisch einen Bericht an wenn keiner existiert)
|
||||||
|
* POST /api/orders.php?action=create
|
||||||
|
* JSON-Body: { socid, title, ref_client?, note_private?, date? }
|
||||||
|
* Legt einen Draft-Auftrag an und übernimmt Kunden-Defaults (Zahlungsbedingungen,
|
||||||
|
* Zahlart, Bankkonto, Incoterms, Lieferadresse, Default-Ansprechpartner).
|
||||||
*/
|
*/
|
||||||
require_once __DIR__.'/_inc.php';
|
require_once __DIR__.'/_inc.php';
|
||||||
|
|
||||||
|
|
@ -21,6 +25,84 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||||
$id = (int) ($_GET['id'] ?? 0);
|
$id = (int) ($_GET['id'] ?? 0);
|
||||||
$action = $_GET['action'] ?? '';
|
$action = $_GET['action'] ?? '';
|
||||||
|
|
||||||
|
/* ----- NEUEN AUFTRAG ANLEGEN ----- */
|
||||||
|
if ($action === 'create' && $_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
if (!$user->hasRight('commande', 'creer')) api_fail('Keine Berechtigung zum Anlegen von Aufträgen', 403);
|
||||||
|
|
||||||
|
$in = api_input();
|
||||||
|
$socid = (int) ($in['socid'] ?? 0);
|
||||||
|
$title = trim((string) ($in['title'] ?? ''));
|
||||||
|
$ref_client = trim((string) ($in['ref_client'] ?? ''));
|
||||||
|
$note_private = trim((string) ($in['note_private'] ?? ''));
|
||||||
|
$date = (int) ($in['date'] ?? 0);
|
||||||
|
if ($date <= 0) $date = dol_now();
|
||||||
|
|
||||||
|
if ($socid <= 0) api_fail('socid fehlt');
|
||||||
|
|
||||||
|
// Kundenstamm holen, um Defaults zu ziehen (wie Dolibarr-Web beim Auftrag-Anlegen)
|
||||||
|
$soc = new Societe($db);
|
||||||
|
if ($soc->fetch($socid) <= 0) api_fail('Kunde nicht gefunden', 404);
|
||||||
|
|
||||||
|
$cmd = new Commande($db);
|
||||||
|
$cmd->socid = $socid;
|
||||||
|
$cmd->date_commande = $date;
|
||||||
|
$cmd->date = $date;
|
||||||
|
$cmd->ref_client = $ref_client;
|
||||||
|
$cmd->note_private = $note_private;
|
||||||
|
|
||||||
|
// Kunden-Defaults übernehmen
|
||||||
|
if (!empty($soc->cond_reglement_id)) $cmd->cond_reglement_id = (int) $soc->cond_reglement_id;
|
||||||
|
if (!empty($soc->mode_reglement_id)) $cmd->mode_reglement_id = (int) $soc->mode_reglement_id;
|
||||||
|
if (!empty($soc->fk_account)) $cmd->fk_account = (int) $soc->fk_account;
|
||||||
|
if (!empty($soc->fk_incoterms)) $cmd->fk_incoterms = (int) $soc->fk_incoterms;
|
||||||
|
if (!empty($soc->location_incoterms)) $cmd->location_incoterms = $soc->location_incoterms;
|
||||||
|
if (!empty($soc->fk_delivery_address)) $cmd->fk_delivery_address = (int) $soc->fk_delivery_address;
|
||||||
|
|
||||||
|
// Titel des Auftrags in Extrafield "auftragsbeschreibung" ablegen (das Bericht-Modul nutzt dieses)
|
||||||
|
if ($title !== '') {
|
||||||
|
if (!is_array($cmd->array_options)) $cmd->array_options = array();
|
||||||
|
$cmd->array_options['options_auftragsbeschreibung'] = $title;
|
||||||
|
}
|
||||||
|
|
||||||
|
$newid = $cmd->create($user);
|
||||||
|
if ($newid <= 0) api_fail('Anlegen fehlgeschlagen: '.$cmd->error, 500);
|
||||||
|
|
||||||
|
// Hauptansprechpartner aus llx_socpeople als externen Kontakt hinzufügen (falls vorhanden)
|
||||||
|
$sql_c = "SELECT rowid FROM ".$db->prefix()."socpeople"
|
||||||
|
." WHERE fk_soc = ".((int) $socid)." AND statut = 1"
|
||||||
|
." ORDER BY rowid ASC LIMIT 1";
|
||||||
|
$rc = $db->query($sql_c);
|
||||||
|
if ($rc && ($oc = $db->fetch_object($rc))) {
|
||||||
|
$cmd->add_contact((int) $oc->rowid, 'CUSTOMER', 'external');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Für identische Response-Shape wie GET ?id= neu laden
|
||||||
|
$cmd->fetch($newid);
|
||||||
|
$cmd->fetch_thirdparty();
|
||||||
|
if (method_exists($cmd, 'fetch_optionals')) $cmd->fetch_optionals();
|
||||||
|
|
||||||
|
api_ok(array(
|
||||||
|
'order' => array(
|
||||||
|
'id' => (int) $cmd->id,
|
||||||
|
'ref' => $cmd->ref,
|
||||||
|
'date' => $cmd->date_commande,
|
||||||
|
'status' => (int) $cmd->statut,
|
||||||
|
'total' => (float) $cmd->total_ttc,
|
||||||
|
'note_private' => $cmd->note_private,
|
||||||
|
'auftragsbeschreibung' => $cmd->array_options['options_auftragsbeschreibung'] ?? '',
|
||||||
|
),
|
||||||
|
'customer' => array(
|
||||||
|
'id' => (int) ($cmd->thirdparty->id ?? 0),
|
||||||
|
'name' => $cmd->thirdparty->name ?? '',
|
||||||
|
'address' => $cmd->thirdparty->address ?? '',
|
||||||
|
'zip' => $cmd->thirdparty->zip ?? '',
|
||||||
|
'town' => $cmd->thirdparty->town ?? '',
|
||||||
|
'phone' => $cmd->thirdparty->phone ?? '',
|
||||||
|
'email' => $cmd->thirdparty->email ?? '',
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
/* ----- LISTE ----- */
|
/* ----- LISTE ----- */
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
// Filter: nur Aufträge des aktuellen Users (oder Admin sieht alle)
|
// Filter: nur Aufträge des aktuellen Users (oder Admin sieht alle)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue