feat: Phase 5.9 Materialliste API + DB + 5.8 Vorbereitung
All checks were successful
Deploy bericht / deploy (push) Successful in 1s
All checks were successful
Deploy bericht / deploy (push) Successful in 1s
- Neue Tabelle llx_bericht_material (element_type, fk_element, label, qty, unit, note, fk_user_creat, datec) via Migration - api/materials.php: GET list, POST anlegen, DELETE löschen Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> [deploy]
This commit is contained in:
parent
dbddee7791
commit
c8f7d7d527
2 changed files with 85 additions and 0 deletions
72
api/materials.php
Normal file
72
api/materials.php
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
/* GET /api/materials.php?element_type=order&element_id=X — Liste
|
||||
* POST /api/materials.php?element_type=order&element_id=X — Body { label, qty, unit, note } → anlegen
|
||||
* DELETE /api/materials.php?id=X — löschen
|
||||
*/
|
||||
require_once __DIR__.'/_inc.php';
|
||||
|
||||
api_authenticate();
|
||||
global $db, $user;
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
if ($method === 'DELETE' || ($method === 'POST' && ($_GET['delete'] ?? '') === '1')) {
|
||||
if (!$user->hasRight('bericht', 'delete')) api_fail('Permission denied', 403);
|
||||
$id = (int) ($_GET['id'] ?? 0);
|
||||
if (!$id) api_fail('id fehlt');
|
||||
if (!$db->query("DELETE FROM ".$db->prefix()."bericht_material WHERE rowid = ".$id)) api_fail($db->lasterror(), 500);
|
||||
api_ok();
|
||||
}
|
||||
|
||||
$el_type = (string) ($_GET['element_type'] ?? 'order');
|
||||
$el_id = (int) ($_GET['element_id'] ?? 0);
|
||||
if (!$el_id) api_fail('element_id erforderlich');
|
||||
if (!in_array($el_type, array('order', 'invoice', 'propal'), true)) api_fail('element_type ungültig');
|
||||
|
||||
if ($method === 'GET') {
|
||||
$sql = "SELECT rowid, label, qty, unit, note, fk_user_creat, datec"
|
||||
." FROM ".$db->prefix()."bericht_material"
|
||||
." WHERE element_type = '".$db->escape($el_type)."' AND fk_element = ".$el_id
|
||||
." ORDER BY datec DESC, rowid DESC";
|
||||
$res = $db->query($sql);
|
||||
if (!$res) api_fail($db->lasterror(), 500);
|
||||
$items = array();
|
||||
while ($o = $db->fetch_object($res)) {
|
||||
$items[] = array(
|
||||
'id' => (int) $o->rowid,
|
||||
'label' => $o->label,
|
||||
'qty' => (float) $o->qty,
|
||||
'unit' => $o->unit,
|
||||
'note' => $o->note,
|
||||
'datec' => $db->jdate($o->datec),
|
||||
);
|
||||
}
|
||||
api_ok(array('materials' => $items, 'count' => count($items)));
|
||||
}
|
||||
|
||||
if ($method === 'POST') {
|
||||
if (!$user->hasRight('bericht', 'write')) api_fail('Permission denied', 403);
|
||||
$in = api_input();
|
||||
$label = trim((string) ($in['label'] ?? ''));
|
||||
$qty = (float) ($in['qty'] ?? 1);
|
||||
$unit = trim((string) ($in['unit'] ?? 'Stk'));
|
||||
$note = trim((string) ($in['note'] ?? ''));
|
||||
if (empty($label)) api_fail('label erforderlich');
|
||||
|
||||
$sql = "INSERT INTO ".$db->prefix()."bericht_material "
|
||||
."(element_type, fk_element, label, qty, unit, note, fk_user_creat, datec) VALUES ("
|
||||
."'".$db->escape($el_type)."',"
|
||||
.$el_id.","
|
||||
."'".$db->escape($label)."',"
|
||||
.((float) $qty).","
|
||||
."'".$db->escape($unit)."',"
|
||||
.($note ? "'".$db->escape($note)."'" : "NULL").","
|
||||
.((int) $user->id).","
|
||||
."'".$db->idate(dol_now())."'"
|
||||
.")";
|
||||
if (!$db->query($sql)) api_fail($db->lasterror(), 500);
|
||||
$id = $db->last_insert_id($db->prefix()."bericht_material");
|
||||
api_ok(array('id' => (int) $id));
|
||||
}
|
||||
|
||||
api_fail('Methode nicht unterstützt', 405);
|
||||
|
|
@ -160,6 +160,19 @@ class modBericht extends DolibarrModules
|
|||
// Phase 5.3: Versionierung
|
||||
"ALTER TABLE ".$this->db->prefix()."bericht ADD COLUMN version INT DEFAULT 1",
|
||||
"ALTER TABLE ".$this->db->prefix()."bericht ADD COLUMN fk_bericht_parent INT DEFAULT NULL",
|
||||
// Phase 5.9: Materialliste pro Auftrag
|
||||
"CREATE TABLE IF NOT EXISTS ".$this->db->prefix()."bericht_material ("
|
||||
."rowid INT AUTO_INCREMENT PRIMARY KEY,"
|
||||
."element_type VARCHAR(32) NOT NULL,"
|
||||
."fk_element INT NOT NULL,"
|
||||
."label VARCHAR(255) NOT NULL,"
|
||||
."qty FLOAT DEFAULT 1,"
|
||||
."unit VARCHAR(16) DEFAULT 'Stk',"
|
||||
."note TEXT DEFAULT NULL,"
|
||||
."fk_user_creat INT NOT NULL,"
|
||||
."datec DATETIME NOT NULL,"
|
||||
."INDEX idx_bm_element (element_type, fk_element)"
|
||||
.") ENGINE=innodb",
|
||||
);
|
||||
foreach ($migrations as $sql) {
|
||||
// Errors ignorieren — Spalten existieren ggf. schon
|
||||
|
|
|
|||
Loading…
Reference in a new issue