- PaginationHelper.php: parseParams() + paginate() - DRY backend pagination logika - Pagination.jsx: frontend strankovaci komponenta (prev/next/cisla/info) - CSS: .admin-pagination styly v admin.css - Refaktor handleru: offers, orders, invoices, projects pouzivaji PaginationHelper - Default 25 zaznamu na stranku (misto 500), max 500 - Frontend: page state + reset na search/filter zmenu - useListData: pagination data v response Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
93 lines
2.8 KiB
PHP
93 lines
2.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* BOHA Automation - Orders CRUD API
|
|
*
|
|
* GET /api/admin/orders.php - List orders
|
|
* GET /api/admin/orders.php?action=detail&id=X - Get order detail
|
|
* POST /api/admin/orders.php - Create order from quotation
|
|
* PUT /api/admin/orders.php?id=X - Update order status/notes
|
|
* DELETE /api/admin/orders.php?id=X - Delete order + project
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once dirname(__DIR__) . '/config.php';
|
|
require_once dirname(__DIR__) . '/includes/JWTAuth.php';
|
|
require_once dirname(__DIR__) . '/includes/AuditLog.php';
|
|
require_once dirname(__DIR__) . '/includes/PaginationHelper.php';
|
|
require_once __DIR__ . '/handlers/orders-handlers.php';
|
|
|
|
setCorsHeaders();
|
|
setSecurityHeaders();
|
|
setNoCacheHeaders();
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
$authData = JWTAuth::requireAuth();
|
|
AuditLog::setUser($authData['user_id'], $authData['user']['username'] ?? 'unknown');
|
|
|
|
$method = $_SERVER['REQUEST_METHOD'];
|
|
$action = $_GET['action'] ?? '';
|
|
$id = isset($_GET['id']) ? (int) $_GET['id'] : null;
|
|
|
|
try {
|
|
$pdo = db();
|
|
|
|
switch ($method) {
|
|
case 'GET':
|
|
requirePermission($authData, 'orders.view');
|
|
switch ($action) {
|
|
case 'detail':
|
|
if (!$id) {
|
|
errorResponse('ID objednávky je povinné');
|
|
}
|
|
handleGetDetail($pdo, $id);
|
|
break;
|
|
case 'attachment':
|
|
if (!$id) {
|
|
errorResponse('ID objednávky je povinné');
|
|
}
|
|
handleGetAttachment($pdo, $id);
|
|
break;
|
|
default:
|
|
handleGetList($pdo);
|
|
}
|
|
break;
|
|
|
|
case 'POST':
|
|
requirePermission($authData, 'orders.create');
|
|
handleCreateOrder($pdo);
|
|
break;
|
|
|
|
case 'PUT':
|
|
requirePermission($authData, 'orders.edit');
|
|
if (!$id) {
|
|
errorResponse('ID objednávky je povinné');
|
|
}
|
|
handleUpdateOrder($pdo, $id);
|
|
break;
|
|
|
|
case 'DELETE':
|
|
requirePermission($authData, 'orders.delete');
|
|
if (!$id) {
|
|
errorResponse('ID objednávky je povinné');
|
|
}
|
|
handleDeleteOrder($pdo, $id);
|
|
break;
|
|
|
|
default:
|
|
errorResponse('Metoda není povolena', 405);
|
|
}
|
|
} catch (PDOException $e) {
|
|
error_log('Orders API error: ' . $e->getMessage());
|
|
if (DEBUG_MODE) {
|
|
errorResponse('Chyba databáze: ' . $e->getMessage(), 500);
|
|
} else {
|
|
errorResponse('Chyba databáze', 500);
|
|
}
|
|
}
|
|
|
|
// --- Valid status transitions ---
|
|
|
|
/** @return list<string> */
|