87 lines
3.0 KiB
PHP
87 lines
3.0 KiB
PHP
<?php
|
|
require_once 'config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
|
|
// Create users table
|
|
$sql_users = "
|
|
CREATE TABLE IF NOT EXISTS users (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
name VARCHAR(255) NOT NULL,
|
|
email VARCHAR(255) NOT NULL UNIQUE,
|
|
password VARCHAR(255) NOT NULL,
|
|
role ENUM('Wajib Pajak', 'Petugas Pajak', 'Pimpinan', 'Super Administrator') NOT NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
) ENGINE=INNODB;
|
|
";
|
|
$pdo->exec($sql_users);
|
|
echo "Table 'users' created successfully (if it didn't exist).<br>";
|
|
|
|
// Inser dummy users
|
|
$users = [
|
|
[
|
|
'name' => 'Admin',
|
|
'email' => 'admin@sarmikab.go.id',
|
|
'password' => password_hash('admin123', PASSWORD_DEFAULT),
|
|
'role' => 'Super Administrator'
|
|
],
|
|
[
|
|
'name' => 'Petugas Pajak',
|
|
'email' => 'petugas@sarmikab.go.id',
|
|
'password' => password_hash('petugas123', PASSWORD_DEFAULT),
|
|
'role' => 'Petugas Pajak'
|
|
],
|
|
[
|
|
'name' => 'Wajib Pajak Contoh',
|
|
'email' => 'wajibpajak@example.com',
|
|
'password' => password_hash('wajibpajak123', PASSWORD_DEFAULT),
|
|
'role' => 'Wajib Pajak'
|
|
],
|
|
[
|
|
'name' => 'Pimpinan',
|
|
'email' => 'pimpinan@sarmikab.go.id',
|
|
'password' => password_hash('pimpinan123', PASSWORD_DEFAULT),
|
|
'role' => 'Pimpinan'
|
|
]
|
|
];
|
|
|
|
$stmt = $pdo->prepare("INSERT INTO users (name, email, password, role) VALUES (:name, :email, :password, :role)");
|
|
|
|
foreach ($users as $user) {
|
|
// Check if user exists
|
|
$check_stmt = $pdo->prepare("SELECT id FROM users WHERE email = :email");
|
|
$check_stmt->execute(['email' => $user['email']]);
|
|
if ($check_stmt->fetch()) {
|
|
echo "User with email {$user['email']} already exists. Skipping.<br>";
|
|
} else {
|
|
$stmt->execute($user);
|
|
echo "User with email {$user['email']} inserted successfully.<br>";
|
|
}
|
|
}
|
|
|
|
// Create tax_reports table
|
|
$sql_tax_reports = "
|
|
CREATE TABLE IF NOT EXISTS tax_reports (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
user_id INT NOT NULL,
|
|
tax_type VARCHAR(100) NOT NULL,
|
|
period_month INT NOT NULL,
|
|
period_year INT NOT NULL,
|
|
gross_revenue DECIMAL(15, 2) NOT NULL,
|
|
tax_amount DECIMAL(15, 2) NOT NULL,
|
|
status ENUM('pending', 'approved', 'rejected') NOT NULL DEFAULT 'pending',
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
|
) ENGINE=INNODB;
|
|
";
|
|
$pdo->exec($sql_tax_reports);
|
|
echo "Table 'tax_reports' created successfully (if it didn't exist).<br>";
|
|
|
|
echo "<hr>Database setup complete!";
|
|
|
|
} catch (PDOException $e) {
|
|
die("DB ERROR: " . $e->getMessage());
|
|
}
|