Fix: Change 'amount' to 'price' to match database schema - Database uses 'price' column, not 'amount' - Update all queries in DailySummaryService, HourlySummaryService - Update RetribusiWriteService (SELECT, INSERT, UPDATE) - Update Validator to use 'price' field - Update check_database.php and TROUBLESHOOTING.md
This commit is contained in:
@@ -236,7 +236,7 @@ class RetribusiWriteService
|
||||
public function getTariff(string $locationCode, string $gateCode, string $category): ?array
|
||||
{
|
||||
$stmt = $this->db->prepare(
|
||||
'SELECT location_code, gate_code, category, amount
|
||||
'SELECT location_code, gate_code, category, price
|
||||
FROM tariffs
|
||||
WHERE location_code = ? AND gate_code = ? AND category = ?
|
||||
LIMIT 1'
|
||||
@@ -256,7 +256,7 @@ class RetribusiWriteService
|
||||
public function createTariff(array $data): array
|
||||
{
|
||||
$stmt = $this->db->prepare(
|
||||
'INSERT INTO tariffs (location_code, gate_code, category, amount)
|
||||
'INSERT INTO tariffs (location_code, gate_code, category, price)
|
||||
VALUES (?, ?, ?, ?)'
|
||||
);
|
||||
|
||||
@@ -264,7 +264,7 @@ class RetribusiWriteService
|
||||
$data['location_code'],
|
||||
$data['gate_code'],
|
||||
$data['category'],
|
||||
(int) $data['amount']
|
||||
(int) $data['price']
|
||||
]);
|
||||
|
||||
return $this->getTariff($data['location_code'], $data['gate_code'], $data['category']);
|
||||
@@ -285,9 +285,9 @@ class RetribusiWriteService
|
||||
$updates = [];
|
||||
$params = [];
|
||||
|
||||
if (isset($data['amount'])) {
|
||||
$updates[] = 'amount = ?';
|
||||
$params[] = (int) $data['amount'];
|
||||
if (isset($data['price'])) {
|
||||
$updates[] = 'price = ?';
|
||||
$params[] = (int) $data['price'];
|
||||
}
|
||||
|
||||
if (empty($updates)) {
|
||||
|
||||
@@ -43,7 +43,7 @@ class DailySummaryService
|
||||
e.gate_code,
|
||||
e.category,
|
||||
COUNT(*) as total_count,
|
||||
COALESCE(t.amount, 0) as tariff_amount
|
||||
COALESCE(t.price, 0) as tariff_amount
|
||||
FROM entry_events e
|
||||
INNER JOIN locations l ON e.location_code = l.code AND l.is_active = 1
|
||||
INNER JOIN gates g ON e.location_code = g.location_code
|
||||
@@ -58,7 +58,7 @@ class DailySummaryService
|
||||
e.location_code,
|
||||
e.gate_code,
|
||||
e.category,
|
||||
COALESCE(t.amount, 0)
|
||||
COALESCE(t.price, 0)
|
||||
";
|
||||
|
||||
$stmt = $this->db->prepare($sql);
|
||||
|
||||
@@ -45,7 +45,7 @@ class HourlySummaryService
|
||||
e.gate_code,
|
||||
e.category,
|
||||
COUNT(*) as total_count,
|
||||
COALESCE(t.amount, 0) as tariff_amount
|
||||
COALESCE(t.price, 0) as tariff_amount
|
||||
FROM entry_events e
|
||||
INNER JOIN locations l ON e.location_code = l.code AND l.is_active = 1
|
||||
INNER JOIN gates g ON e.location_code = g.location_code
|
||||
@@ -61,7 +61,7 @@ class HourlySummaryService
|
||||
e.location_code,
|
||||
e.gate_code,
|
||||
e.category,
|
||||
COALESCE(t.amount, 0)
|
||||
COALESCE(t.price, 0)
|
||||
";
|
||||
|
||||
$stmt = $this->db->prepare($sql);
|
||||
|
||||
@@ -281,15 +281,15 @@ class Validator
|
||||
}
|
||||
}
|
||||
|
||||
// Amount: required for POST, optional for update
|
||||
if (isset($data['amount'])) {
|
||||
if (!is_int($data['amount']) && !is_numeric($data['amount'])) {
|
||||
$errors['amount'] = 'Must be an integer';
|
||||
} elseif ((int) $data['amount'] < 0) {
|
||||
$errors['amount'] = 'Must be >= 0';
|
||||
// Price: required for POST, optional for update
|
||||
if (isset($data['price'])) {
|
||||
if (!is_int($data['price']) && !is_numeric($data['price'])) {
|
||||
$errors['price'] = 'Must be an integer';
|
||||
} elseif ((int) $data['price'] < 0) {
|
||||
$errors['price'] = 'Must be >= 0';
|
||||
}
|
||||
} elseif (!$isUpdate) {
|
||||
$errors['amount'] = 'Field is required';
|
||||
$errors['price'] = 'Field is required';
|
||||
}
|
||||
|
||||
return $errors;
|
||||
|
||||
Reference in New Issue
Block a user