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:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -31,7 +31,10 @@ composer.phar
|
|||||||
composer.lock
|
composer.lock
|
||||||
|
|
||||||
# Backup
|
# Backup
|
||||||
*.sql
|
|
||||||
*.bak
|
*.bak
|
||||||
backup/
|
backup/
|
||||||
|
|
||||||
|
# SQL files (exclude backup, but allow migrations)
|
||||||
|
*.sql
|
||||||
|
!migrations/*.sql
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ composer dump-autoload --optimize
|
|||||||
Masuk ke: **Website -> api.btekno.cloud -> Settings -> Configuration**
|
Masuk ke: **Website -> api.btekno.cloud -> Settings -> Configuration**
|
||||||
|
|
||||||
Ganti isi configuration dengan:
|
Ganti isi configuration dengan:
|
||||||
|
|
||||||
```nginx
|
```nginx
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
@@ -128,6 +129,7 @@ composer dump-autoload --optimize
|
|||||||
```
|
```
|
||||||
|
|
||||||
**Cek PHP socket path:**
|
**Cek PHP socket path:**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Cek PHP version yang digunakan
|
# Cek PHP version yang digunakan
|
||||||
php -v
|
php -v
|
||||||
|
|||||||
@@ -2,10 +2,14 @@
|
|||||||
|
|
||||||
## Error: "Unknown column 't.amount' in 'SELECT'"
|
## Error: "Unknown column 't.amount' in 'SELECT'"
|
||||||
|
|
||||||
### Kemungkinan Penyebab:
|
### Root Cause:
|
||||||
|
**Kolom di database adalah `price`, bukan `amount`!**
|
||||||
|
|
||||||
|
Database production menggunakan kolom `price` di tabel `tariffs`, tapi code menggunakan `amount`. Ini menyebabkan mismatch.
|
||||||
|
|
||||||
|
### Kemungkinan Penyebab Lain:
|
||||||
1. **OPcache belum di-clear** - PHP masih menggunakan file lama
|
1. **OPcache belum di-clear** - PHP masih menggunakan file lama
|
||||||
2. **Struktur database berbeda** - Kolom `amount` mungkin tidak ada atau nama berbeda
|
2. **File belum ter-update** - Meskipun sudah `git pull`, file mungkin belum benar-benar ter-update
|
||||||
3. **File belum ter-update** - Meskipun sudah `git pull`, file mungkin belum benar-benar ter-update
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -65,7 +69,7 @@ SELECT
|
|||||||
e.gate_code,
|
e.gate_code,
|
||||||
e.category,
|
e.category,
|
||||||
COUNT(*) as total_count,
|
COUNT(*) as total_count,
|
||||||
COALESCE(t.amount, 0) as tariff_amount
|
COALESCE(t.price, 0) as tariff_amount
|
||||||
FROM entry_events e
|
FROM entry_events e
|
||||||
INNER JOIN locations l ON e.location_code = l.code AND l.is_active = 1
|
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
|
INNER JOIN gates g ON e.location_code = g.location_code
|
||||||
@@ -80,7 +84,7 @@ GROUP BY
|
|||||||
e.location_code,
|
e.location_code,
|
||||||
e.gate_code,
|
e.gate_code,
|
||||||
e.category,
|
e.category,
|
||||||
COALESCE(t.amount, 0)
|
COALESCE(t.price, 0)
|
||||||
LIMIT 5;
|
LIMIT 5;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ try {
|
|||||||
e.gate_code,
|
e.gate_code,
|
||||||
e.category,
|
e.category,
|
||||||
COUNT(*) as total_count,
|
COUNT(*) as total_count,
|
||||||
COALESCE(t.amount, 0) as tariff_amount
|
COALESCE(t.price, 0) as tariff_amount
|
||||||
FROM entry_events e
|
FROM entry_events e
|
||||||
INNER JOIN locations l ON e.location_code = l.code AND l.is_active = 1
|
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
|
INNER JOIN gates g ON e.location_code = g.location_code
|
||||||
@@ -107,7 +107,7 @@ try {
|
|||||||
e.location_code,
|
e.location_code,
|
||||||
e.gate_code,
|
e.gate_code,
|
||||||
e.category,
|
e.category,
|
||||||
COALESCE(t.amount, 0)
|
COALESCE(t.price, 0)
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
";
|
";
|
||||||
|
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ class RetribusiWriteService
|
|||||||
public function getTariff(string $locationCode, string $gateCode, string $category): ?array
|
public function getTariff(string $locationCode, string $gateCode, string $category): ?array
|
||||||
{
|
{
|
||||||
$stmt = $this->db->prepare(
|
$stmt = $this->db->prepare(
|
||||||
'SELECT location_code, gate_code, category, amount
|
'SELECT location_code, gate_code, category, price
|
||||||
FROM tariffs
|
FROM tariffs
|
||||||
WHERE location_code = ? AND gate_code = ? AND category = ?
|
WHERE location_code = ? AND gate_code = ? AND category = ?
|
||||||
LIMIT 1'
|
LIMIT 1'
|
||||||
@@ -256,7 +256,7 @@ class RetribusiWriteService
|
|||||||
public function createTariff(array $data): array
|
public function createTariff(array $data): array
|
||||||
{
|
{
|
||||||
$stmt = $this->db->prepare(
|
$stmt = $this->db->prepare(
|
||||||
'INSERT INTO tariffs (location_code, gate_code, category, amount)
|
'INSERT INTO tariffs (location_code, gate_code, category, price)
|
||||||
VALUES (?, ?, ?, ?)'
|
VALUES (?, ?, ?, ?)'
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -264,7 +264,7 @@ class RetribusiWriteService
|
|||||||
$data['location_code'],
|
$data['location_code'],
|
||||||
$data['gate_code'],
|
$data['gate_code'],
|
||||||
$data['category'],
|
$data['category'],
|
||||||
(int) $data['amount']
|
(int) $data['price']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $this->getTariff($data['location_code'], $data['gate_code'], $data['category']);
|
return $this->getTariff($data['location_code'], $data['gate_code'], $data['category']);
|
||||||
@@ -285,9 +285,9 @@ class RetribusiWriteService
|
|||||||
$updates = [];
|
$updates = [];
|
||||||
$params = [];
|
$params = [];
|
||||||
|
|
||||||
if (isset($data['amount'])) {
|
if (isset($data['price'])) {
|
||||||
$updates[] = 'amount = ?';
|
$updates[] = 'price = ?';
|
||||||
$params[] = (int) $data['amount'];
|
$params[] = (int) $data['price'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($updates)) {
|
if (empty($updates)) {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class DailySummaryService
|
|||||||
e.gate_code,
|
e.gate_code,
|
||||||
e.category,
|
e.category,
|
||||||
COUNT(*) as total_count,
|
COUNT(*) as total_count,
|
||||||
COALESCE(t.amount, 0) as tariff_amount
|
COALESCE(t.price, 0) as tariff_amount
|
||||||
FROM entry_events e
|
FROM entry_events e
|
||||||
INNER JOIN locations l ON e.location_code = l.code AND l.is_active = 1
|
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
|
INNER JOIN gates g ON e.location_code = g.location_code
|
||||||
@@ -58,7 +58,7 @@ class DailySummaryService
|
|||||||
e.location_code,
|
e.location_code,
|
||||||
e.gate_code,
|
e.gate_code,
|
||||||
e.category,
|
e.category,
|
||||||
COALESCE(t.amount, 0)
|
COALESCE(t.price, 0)
|
||||||
";
|
";
|
||||||
|
|
||||||
$stmt = $this->db->prepare($sql);
|
$stmt = $this->db->prepare($sql);
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class HourlySummaryService
|
|||||||
e.gate_code,
|
e.gate_code,
|
||||||
e.category,
|
e.category,
|
||||||
COUNT(*) as total_count,
|
COUNT(*) as total_count,
|
||||||
COALESCE(t.amount, 0) as tariff_amount
|
COALESCE(t.price, 0) as tariff_amount
|
||||||
FROM entry_events e
|
FROM entry_events e
|
||||||
INNER JOIN locations l ON e.location_code = l.code AND l.is_active = 1
|
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
|
INNER JOIN gates g ON e.location_code = g.location_code
|
||||||
@@ -61,7 +61,7 @@ class HourlySummaryService
|
|||||||
e.location_code,
|
e.location_code,
|
||||||
e.gate_code,
|
e.gate_code,
|
||||||
e.category,
|
e.category,
|
||||||
COALESCE(t.amount, 0)
|
COALESCE(t.price, 0)
|
||||||
";
|
";
|
||||||
|
|
||||||
$stmt = $this->db->prepare($sql);
|
$stmt = $this->db->prepare($sql);
|
||||||
|
|||||||
@@ -281,15 +281,15 @@ class Validator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Amount: required for POST, optional for update
|
// Price: required for POST, optional for update
|
||||||
if (isset($data['amount'])) {
|
if (isset($data['price'])) {
|
||||||
if (!is_int($data['amount']) && !is_numeric($data['amount'])) {
|
if (!is_int($data['price']) && !is_numeric($data['price'])) {
|
||||||
$errors['amount'] = 'Must be an integer';
|
$errors['price'] = 'Must be an integer';
|
||||||
} elseif ((int) $data['amount'] < 0) {
|
} elseif ((int) $data['price'] < 0) {
|
||||||
$errors['amount'] = 'Must be >= 0';
|
$errors['price'] = 'Must be >= 0';
|
||||||
}
|
}
|
||||||
} elseif (!$isUpdate) {
|
} elseif (!$isUpdate) {
|
||||||
$errors['amount'] = 'Field is required';
|
$errors['price'] = 'Field is required';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $errors;
|
return $errors;
|
||||||
|
|||||||
Reference in New Issue
Block a user