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

25 lines
847 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_name']) || empty($data['start_date']) || empty($data['end_date'])) {
http_response_code(400);
echo json_encode(['success' => false, 'error' => 'Missing required fields.']);
exit;
}
$pdo = db();
try {
$stmt = $pdo->prepare("INSERT INTO accounting_periods (period_name, start_date, end_date) VALUES (?, ?, ?)");
$stmt->execute([$data['period_name'], $data['start_date'], $data['end_date']]);
echo json_encode(['success' => true, 'message' => 'Accounting period created successfully.']);
} catch (PDOException $e) {
http_response_code(500);
echo json_encode(['success' => false, 'error' => 'Database error: ' . $e->getMessage()]);
}