37241-vm/api/accounting_periods_close.php
2026-01-03 08:40:36 +00:00

30 lines
895 B
PHP

<?php
header('Content-Type: application/json');
require_once __DIR__ . '../../db/config.php';
$data = json_decode(file_get_contents('php://input'), true);
if (empty($data['period_id'])) {
http_response_code(400);
echo json_encode(['success' => false, 'error' => 'Missing period_id.']);
exit;
}
$pdo = db();
try {
$stmt = $pdo->prepare("UPDATE accounting_periods SET status = 'closed' WHERE id = ?");
$stmt->execute([$data['period_id']]);
if ($stmt->rowCount() > 0) {
echo json_encode(['success' => true, 'message' => 'Accounting period closed successfully.']);
} else {
http_response_code(404);
echo json_encode(['success' => false, 'error' => 'Accounting period not found.']);
}
} catch (PDOException $e) {
http_response_code(500);
echo json_encode(['success' => false, 'error' => 'Database error: ' . $e->getMessage()]);
}