setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "

🛠️ Engine Database Installer - PT Info Hadir Digital

"; echo "
"; // LIST NAMA DATABASE YANG AKAN DIBUAT $databases = ['infe8543_db_infohadir', 'infe8543_db_laristock', 'infe8543_db_kasir']; foreach ($databases as $db) { $pdo->exec("CREATE DATABASE IF NOT EXISTS `$db` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"); echo "💾 Database $db berhasil dibuat atau sudah tersedia.
"; } echo "
⚙️ Memulai penyusunan struktur tabel internal...

"; // ========================================================================= // 2. STRUKTUR TABEL DATABASE 1: db_infohadir (Aplikasi Absensi) // ========================================================================= $pdo->exec("USE `infe8543_db_infohadir`;"); $pdo->exec("CREATE TABLE IF NOT EXISTS `companies` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `code` varchar(20) NOT NULL UNIQUE, `address` text DEFAULT NULL, `email` varchar(200) NOT NULL, `status` enum('pending','active','banned') DEFAULT 'active', `created_at` timestamp NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`) ) ENGINE=InnoDB;"); $pdo->exec("CREATE TABLE IF NOT EXISTS `branches` ( `id` int(11) NOT NULL AUTO_INCREMENT, `company_id` int(11) NOT NULL, `name` varchar(100) NOT NULL, `latitude` decimal(10,8) NOT NULL, `longitude` decimal(11,8) NOT NULL, `radius_meter` int(11) DEFAULT 100, PRIMARY KEY (`id`) ) ENGINE=InnoDB;"); $pdo->exec("CREATE TABLE IF NOT EXISTS `employees` ( `id` int(11) NOT NULL AUTO_INCREMENT, `company_id` int(11) NOT NULL, `branch_id` int(11) DEFAULT NULL, `nik` varchar(20) DEFAULT NULL, `name` varchar(100) NOT NULL, `email` varchar(100) NOT NULL UNIQUE, `password` varchar(255) NOT NULL, `position` varchar(100) DEFAULT NULL, `salary_basic` decimal(12,2) NOT NULL DEFAULT 0.00, `status` enum('active','resign') DEFAULT 'active', PRIMARY KEY (`id`) ) ENGINE=InnoDB;"); $pdo->exec("CREATE TABLE IF NOT EXISTS `attendances` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `company_id` int(11) NOT NULL, `employee_id` int(11) NOT NULL, `branch_id` int(11) DEFAULT NULL, `date` date NOT NULL, `check_in` datetime DEFAULT NULL, `check_in_lat` decimal(10,8) DEFAULT NULL, `check_in_lng` decimal(11,8) DEFAULT NULL, `check_in_photo` varchar(255) DEFAULT NULL, `check_in_ip` varchar(45) DEFAULT NULL, `check_out` datetime DEFAULT NULL, `check_out_lat` decimal(10,8) DEFAULT NULL, `check_out_lng` decimal(11,8) DEFAULT NULL, `check_out_photo` varchar(255) DEFAULT NULL, `check_out_ip` varchar(45) DEFAULT NULL, `status` enum('present','late','leave','sick','absent') DEFAULT 'present', `total_work_minutes` int(11) DEFAULT 0, PRIMARY KEY (`id`) ) ENGINE=InnoDB;"); echo "✅ [dinfe8543_b_infohadir] Tabel companies, branches, employees, dan attendances siap.
"; // ========================================================================= // 3. STRUKTUR TABEL DATABASE 2: db_laristock (Manajemen Stok) // ========================================================================= $pdo->exec("USE `infe8543_db_laristock`;"); $pdo->exec("CREATE TABLE IF NOT EXISTS `products` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `company_id` int(11) NOT NULL COMMENT 'ID dari infe8543_db_infohadir', `barcode` varchar(50) NOT NULL, `name` varchar(150) NOT NULL, `price_buy` decimal(12,2) NOT NULL DEFAULT 0.00, `price_sell` decimal(12,2) NOT NULL DEFAULT 0.00, `stock_minimum` int(11) DEFAULT 5, PRIMARY KEY (`id`), UNIQUE KEY `unique_barcode_company` (`company_id`, `barcode`) ) ENGINE=InnoDB;"); $pdo->exec("CREATE TABLE IF NOT EXISTS `stock_mutations` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `company_id` int(11) NOT NULL, `product_barcode` varchar(50) NOT NULL, `quantity` int(11) NOT NULL, `type` enum('in','out') NOT NULL, `notes` text DEFAULT NULL, `created_at` timestamp NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`) ) ENGINE=InnoDB;"); echo "✅ [dinfe8543_b_laristock] Tabel products dan stock_mutations siap.
"; // ========================================================================= // 4. STRUKTUR TABEL DATABASE 3: db_kasir (Point of Sale) // ========================================================================= $pdo->exec("USE `infe8543_db_kasir`;"); $pdo->exec("CREATE TABLE IF NOT EXISTS `sales_transactions` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `company_id` int(11) NOT NULL, `employee_id` int(11) NOT NULL, `invoice_number` varchar(50) NOT NULL UNIQUE, `total_item` int(11) NOT NULL DEFAULT 0, `total_price` decimal(12,2) NOT NULL DEFAULT 0.00, `cash_received` decimal(12,2) NOT NULL DEFAULT 0.00, `change_amount` decimal(12,2) NOT NULL DEFAULT 0.00, `payment_method` enum('cash','qris','transfer') NOT NULL DEFAULT 'cash', `created_at` timestamp NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`) ) ENGINE=InnoDB;"); $pdo->exec("CREATE TABLE IF NOT EXISTS `sales_transaction_details` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `transaction_id` bigint(20) NOT NULL, `product_barcode` varchar(50) NOT NULL, `product_name` varchar(150) NOT NULL, `price_sell` decimal(12,2) NOT NULL DEFAULT 0.00, `quantity` int(11) NOT NULL DEFAULT 1, `subtotal` decimal(12,2) NOT NULL DEFAULT 0.00, PRIMARY KEY (`id`) ) ENGINE=InnoDB;"); echo "✅ [db_kasir] Tabel sales_transactions dan sales_transaction_details siap.
"; echo "

🎉 INSTALASI CLUSTER DATABASE BERHASIL SEMPURNA!

"; echo "

Catatan: Harap segera hapus file setup-db.php ini dari server hosting demi alasan keamanan siber.

"; } catch (PDOException $e) { die("

❌ INSTALASI GAGAL:

" . $e->getMessage()); } ?>