« Back to History
bank_details.php
|
20260721_154033.php
Initial Bulk Import
Copy Code
<?php error_reporting(E_ALL); ini_set('display_errors', 1); require __DIR__ . '/../modules/auth/auth.php'; require_login(); $u = auth_user(); $pdo = $GLOBALS['pdo'] ?? null; if (!$pdo instanceof PDO) { require __DIR__ . '/../core/db.php'; $pdo = $GLOBALS['pdo'] ?? null; } if (!$pdo instanceof PDO) { http_response_code(500); exit('DB not available'); } $company_id = (int)($u['company_id'] ?? 0); $user_id = (int)($u['id'] ?? 0); function h($value): string { return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); } function table_has_column(PDO $pdo, string $table, string $column): bool { try { $st = $pdo->prepare("SHOW COLUMNS FROM `$table` LIKE ?"); $st->execute([$column]); return (bool)$st->fetch(PDO::FETCH_ASSOC); } catch (Throwable $e) { return false; } } function resolve_employee_row(PDO $pdo, int $company_id, int $user_id): ?array { try { if (table_has_column($pdo, 'users', 'employee_id')) { $st = $pdo->prepare( "SELECT cem.id, cem.name, cem.account_number, cem.beneficiary_name, cem.ifsc FROM company_employee_master cem JOIN users u ON u.company_id = cem.company_id AND u.employee_id = cem.id WHERE u.id = ? AND cem.company_id = ? LIMIT 1" ); $st->execute([$user_id, $company_id]); $row = $st->fetch(PDO::FETCH_ASSOC); if ($row) { return $row; } } $st = $pdo->prepare( "SELECT cem.id, cem.name, cem.account_number, cem.beneficiary_name, cem.ifsc FROM company_employee_master cem JOIN users u ON u.company_id = cem.company_id WHERE u.id = ? AND cem.company_id = ? AND TRIM(LOWER(cem.name)) = TRIM(LOWER(u.name)) ORDER BY cem.id DESC LIMIT 1" ); $st->execute([$user_id, $company_id]); $row = $st->fetch(PDO::FETCH_ASSOC); return $row ?: null; } catch (Throwable $e) { return null; } } $employee = resolve_employee_row($pdo, $company_id, $user_id); $message = ''; $error = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!$employee) { $error = 'Employee record not linked with your login.'; } else { $account_number = trim((string)($_POST['account_number'] ?? '')); $beneficiary_name = trim((string)($_POST['beneficiary_name'] ?? '')); $ifsc = strtoupper(trim((string)($_POST['ifsc'] ?? ''))); if ($account_number === '' || $beneficiary_name === '' || $ifsc === '') { $error = 'All fields are required.'; } elseif (!preg_match('/^[0-9]+$/', $account_number)) { $error = 'Account number should contain digits only.'; } elseif (preg_match('/[0-9]/', $beneficiary_name)) { $error = 'Beneficiary name cannot contain numbers.'; } else { $st = $pdo->prepare( "UPDATE company_employee_master SET account_number = ?, beneficiary_name = ?, ifsc = ?, updated_at = NOW() WHERE id = ? AND company_id = ? LIMIT 1" ); $st->execute([$account_number, $beneficiary_name, $ifsc, (int)$employee['id'], $company_id]); $message = 'Bank details updated.'; $employee = resolve_employee_row($pdo, $company_id, $user_id); } } } ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>Bank Details</title> <style> :root{--primary:#34A853;--bg:#F5FFF7;--card:#fff;--text:#202124;--border:#e5e7eb;--shadow:0 8px 20px rgba(0,0,0,.08)} *{box-sizing:border-box} body{margin:0;background:var(--bg);color:var(--text);font:14px/1.45 system-ui,-apple-system,Segoe UI,Roboto,Arial} .wrap{max-width:760px;margin:20px auto;padding:16px}.card{background:var(--card);border:1px solid var(--border);border-radius:16px;box-shadow:var(--shadow);padding:18px} .top{display:flex;justify-content:space-between;align-items:center;gap:10px;margin-bottom:12px}.link{color:#0b57d0;text-decoration:none;font-weight:600} label{display:block;margin:8px 0 6px;font-weight:600} input{width:100%;padding:10px;border:1px solid #d0d7de;border-radius:10px} .btn{padding:10px 16px;border:0;border-radius:10px;cursor:pointer;font-weight:600;background:var(--primary);color:#fff}.ok{margin:10px 0;background:#ecfdf5;border:1px solid #a7f3d0;color:#065f46;padding:8px;border-radius:10px}.err{margin:10px 0;background:#fee2e2;border:1px solid #fecaca;color:#7f1d1d;padding:8px;border-radius:10px} .small{color:#5F6368;font-size:13px} </style> </head> <body> <div class="wrap"> <div class="top"> <a class="link" href="/erp/public/employee_portal.php">← Dashboard</a> <div>Logged in: <b><?= h($u['name'] ?? 'User') ?></b></div> </div> <div class="card"> <h2 style="margin:0 0 8px">Add / Edit Bank Details</h2> <div class="small" style="margin-bottom:12px">Update your own account details linked with this login.</div> <?php if ($message): ?><div class="ok"><?= h($message) ?></div><?php endif; ?> <?php if ($error): ?><div class="err"><?= h($error) ?></div><?php endif; ?> <?php if (!$employee): ?> <div class="err">Employee record not linked with your login. Please contact admin.</div> <?php else: ?> <div class="small" style="margin-bottom:10px">Employee: <b><?= h($employee['name']) ?></b></div> <form method="post"> <label>Account Number</label> <input type="text" name="account_number" value="<?= h($_POST['account_number'] ?? $employee['account_number'] ?? '') ?>" required> <label>Beneficiary Name</label> <input type="text" name="beneficiary_name" value="<?= h($_POST['beneficiary_name'] ?? $employee['beneficiary_name'] ?? '') ?>" required> <label>IFSC</label> <input type="text" name="ifsc" value="<?= h($_POST['ifsc'] ?? $employee['ifsc'] ?? '') ?>" required> <div style="margin-top:12px"> <button class="btn" type="submit">Save Bank Details</button> </div> </form> <?php endif; ?> </div> </div> </body> </html>