37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
$response = ['success' => false, 'error' => 'Invalid request'];
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$projectId = $_POST['projectId'] ?? null;
|
|
$month = $_POST['month'] ?? null;
|
|
$amount = $_POST['amount'] ?? null;
|
|
|
|
if ($projectId && $month && $amount !== null) {
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("UPDATE billingMonthly SET amount = :amount WHERE projectId = :projectId AND month = :month");
|
|
$stmt->execute([
|
|
':amount' => $amount,
|
|
':projectId' => $projectId,
|
|
':month' => $month
|
|
]);
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
$response['success'] = true;
|
|
unset($response['error']);
|
|
} else {
|
|
$response['error'] = 'No record found to update.';
|
|
}
|
|
} catch (PDOException $e) {
|
|
$response['error'] = 'Database error: ' . $e->getMessage();
|
|
}
|
|
} else {
|
|
$response['error'] = 'Missing required fields.';
|
|
}
|
|
}
|
|
|
|
echo json_encode($response);
|