« Back to History
emp_bank.php
|
20260920_164915.php
Initial Domain Snapshot
Copy Code
<?php /* ============================================================================ File: /erp/employee_bank_data.php Title: Employee Bank Data — CRUD (UI adjusted) Mod: Header menu added; Import UI removed; Delete button removed; Edit -> opens form with Save Scope: Page-local only; Multi-company aware; No global/base edits. ============================================================================ */ header('X-Frame-Options: SAMEORIGIN'); error_reporting(E_ALL); ini_set('display_errors','1'); /* [0] Auth + DB */ require __DIR__ . '/modules/auth/auth.php'; require_login(); $u = auth_user(); $COMPANY_ID = (int)$u['company_id']; $USER_ID = (int)$u['id']; $pdo = $GLOBALS['pdo'] ?? null; if (!$pdo) { require __DIR__ . '/core/db.php'; } /* [1] Helpers */ function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } function gv($k,$d=null){ return isset($_GET[$k])?trim((string)$_GET[$k]):$d; } function pv($k,$d=null){ return isset($_POST[$k])?trim((string)$_POST[$k]):$d; } function jexit($arr,$code=200){ if (!headers_sent()){ header('Content-Type: application/json; charset=utf-8'); http_response_code($code); } echo json_encode($arr, JSON_UNESCAPED_UNICODE); exit; } /* ---------- Department filter from GET ---------- */ $F_dept = isset($_GET['f_dept']) ? trim((string)$_GET['f_dept']) : ''; /* [2] Minimal XLSX reader (kept for backend import support) */ class MiniXLSX { public static function rows($path){ if(!class_exists('ZipArchive')) throw new Exception('ZipArchive not enabled; cannot read .xlsx'); $zip = new ZipArchive(); if($zip->open($path)!==TRUE) throw new Exception('Unable to open .xlsx'); $sharedStrings = []; $ssXml = $zip->getFromName('xl/sharedStrings.xml'); if($ssXml){ $ss = simplexml_load_string($ssXml); foreach($ss->si as $si){ $t = ''; foreach($si->t as $node) $t .= (string)$node; if($t===''){ foreach($si->r as $r){ $t .= (string)$r->t; } } $sharedStrings[] = (string)$t; } } $sheetXml = $zip->getFromName('xl/worksheets/sheet1.xml'); if(!$sheetXml) $sheetXml = $zip->getFromName('xl/worksheets/sheet0.xml'); if(!$sheetXml) throw new Exception('Could not find sheet1.xml in .xlsx'); $sheet = simplexml_load_string($sheetXml); $rows = []; foreach($sheet->sheetData->row as $row){ $cells=[]; $maxCol = 0; foreach($row->c as $c){ $r = (string)$c['r']; // A1 $col = preg_replace('/\d+/', '', $r); $colIndex = self::colToIndex($col); $v = (string)$c->v; $t = (string)$c['t']; $val = ($t==='s') ? ($sharedStrings[(int)$v] ?? '') : $v; $cells[$colIndex] = $val; if($colIndex>$maxCol) $maxCol = $colIndex; } $line = []; for($i=0;$i<=$maxCol;$i++){ $line[] = $cells[$i] ?? ''; } $rows[] = $line; } $zip->close(); return $rows; } private static function colToIndex($col){ $col = strtoupper($col); $len = strlen($col); $num = 0; for($i=0;$i<$len;$i++){ $num = $num*26 + (ord($col[$i])-64); } return $num-1; } } /* [3] Employee map builder: (department_name + employee_name) -> employee_id */ function build_employee_map(PDO $pdo, int $company_id){ $sql = "SELECT e.id, e.name AS employee_name, COALESCE(d.name,'') AS department_name FROM company_employee_master e LEFT JOIN company_departments d ON d.id = e.department_id AND d.company_id = e.company_id WHERE e.company_id = ?"; $st = $pdo->prepare($sql); $st->execute([$company_id]); $map = []; while($r = $st->fetch(PDO::FETCH_ASSOC)){ $dept = strtolower(trim((string)$r['department_name'])); $ename= strtolower(trim((string)$r['employee_name'])); if($ename==='') continue; $key = $dept.'|'.$ename; // strict key: dept + name $map[$key] = (int)$r['id']; } return $map; } /* --- load employees for picker (id, name, department) NOTE: keep create/edit selects showing all employees (so UX is predictable). */ $employees = []; $est = $pdo->prepare("SELECT e.id, e.name AS employee_name, COALESCE(d.name,'') AS department_name FROM company_employee_master e LEFT JOIN company_departments d ON d.id=e.department_id AND d.company_id=e.company_id WHERE e.company_id = ? ORDER BY e.name ASC"); $est->execute([$COMPANY_ID]); while($er = $est->fetch(PDO::FETCH_ASSOC)){ $employees[] = $er; } /* ---------- Load departments for filter dropdown ---------- */ $DEPARTMENTS = []; try{ $dstmt = $pdo->prepare("SELECT id, name FROM company_departments WHERE company_id = ? ORDER BY name ASC"); $dstmt->execute([$COMPANY_ID]); $DEPARTMENTS = $dstmt->fetchAll(PDO::FETCH_ASSOC); } catch(Throwable $e){ // ignore if table absent } /* [4] CRUD actions (unchanged) */ $act = gv('act'); if ($act === 'create' && $_SERVER['REQUEST_METHOD']==='POST'){ $employee_id = (int)pv('employee_id',0); $acno = pv('beneficiary_ac_number',''); $ben_name = pv('beneficiary_name',''); $ifsc = strtoupper(pv('ifsc_code','')); $entry_name = pv('entry_name',''); $department_name = pv('department_name',''); $employee_name = pv('employee_name',''); $mobile = pv('mobile',''); $email = pv('email',''); $address1 = pv('address1',''); $address2 = pv('address2',''); $address3 = pv('address3',''); $address4 = pv('address4',''); if(!$employee_id || $acno==='' || $ben_name==='' || $ifsc===''){ jexit(['ok'=>false,'msg'=>'employee_id, A/c number, beneficiary name and IFSC are required.']); } $sql = "INSERT INTO employee_bank_data (company_id, employee_id, beneficiary_ac_number, beneficiary_name, ifsc_code, entry_name, department_name, employee_name, mobile, email, address1, address2, address3, address4, created_at) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW())"; $st = $pdo->prepare($sql); $st->execute([$COMPANY_ID,$employee_id,$acno,$ben_name,$ifsc,$entry_name,$department_name,$employee_name,$mobile,$email,$address1,$address2,$address3,$address4]); jexit(['ok'=>true,'msg'=>'Saved']); } if ($act === 'update' && $_SERVER['REQUEST_METHOD']==='POST'){ $id = (int)pv('id',0); $employee_id = (int)pv('employee_id',0); $acno = pv('beneficiary_ac_number',''); $ben_name = pv('beneficiary_name',''); $ifsc = strtoupper(pv('ifsc_code','')); $entry_name = pv('entry_name',''); $department_name = pv('department_name',''); $employee_name = pv('employee_name',''); $mobile = pv('mobile',''); $email = pv('email',''); $address1 = pv('address1',''); $address2 = pv('address2',''); $address3 = pv('address3',''); $address4 = pv('address4',''); if(!$id || !$employee_id || $acno==='' || $ben_name==='' || $ifsc===''){ jexit(['ok'=>false,'msg'=>'All required fields must be filled.']); } $sql = "UPDATE employee_bank_data SET employee_id=?, beneficiary_ac_number=?, beneficiary_name=?, ifsc_code=?, entry_name=?, department_name=?, employee_name=?, mobile=?, email=?, address1=?, address2=?, address3=?, address4=?, updated_at=NOW() WHERE id=? AND company_id=?"; $st = $pdo->prepare($sql); $st->execute([$employee_id,$acno,$ben_name,$ifsc,$entry_name,$department_name,$employee_name,$mobile,$email,$address1,$address2,$address3,$address4,$id,$COMPANY_ID]); jexit(['ok'=>true,'msg'=>'Updated']); } /* keep delete server API in backend if you ever want to and because server logic unchanged; but per request we will remove Delete buttons from UI */ if ($act === 'delete' && $_SERVER['REQUEST_METHOD']==='POST'){ $id = (int)pv('id',0); if(!$id) jexit(['ok'=>false,'msg'=>'Missing id']); $st = $pdo->prepare("DELETE FROM employee_bank_data WHERE id=? AND company_id=?"); $st->execute([$id,$COMPANY_ID]); jexit(['ok'=>true,'msg'=>'Deleted']); } /* [5] Bulk IMPORT backend kept (not exposed in UI) */ if ($act === 'bulk_import' && $_SERVER['REQUEST_METHOD']==='POST'){ if(empty($_FILES['file']['tmp_name'])) jexit(['ok'=>false,'msg'=>'Please choose a CSV/XLSX file.']); $tmp = $_FILES['file']['tmp_name']; $name = $_FILES['file']['name']; $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION)); $rows = []; try{ if($ext==='csv'){ $fh = fopen($tmp,'r'); if(!$fh) throw new Exception('Cannot open CSV'); while(($r = fgetcsv($fh))!==false){ $rows[] = $r; } fclose($fh); } elseif($ext==='xlsx'){ $rows = MiniXLSX::rows($tmp); } else { throw new Exception('Unsupported file type: use .csv or .xlsx'); } } catch(Exception $e){ jexit(['ok'=>false,'msg'=>'Read error: '.$e->getMessage()]); } if(count($rows)<2) jexit(['ok'=>false,'msg'=>'File seems empty / no data rows found.']); // Map headers (case-insensitive) $hdr = array_map('strtolower', array_map('trim', $rows[0])); $idx = []; foreach($hdr as $i=>$hname){ $idx[$hname] = $i; } // Required headers $need = ['department_name','employee_name','beneficiary_ac_number','beneficiary_name','ifsc_code']; $ok = true; foreach($need as $k){ if(!isset($idx[$k])) $ok=false; } if(!$ok){ jexit(['ok'=>false,'msg'=>'Header must include: department_name, employee_name, beneficiary_ac_number, beneficiary_name, ifsc_code']); } // Optional headers $opt = [ 'entry_name'=>null,'mobile'=>null,'email'=>null, 'address1'=>null,'address2'=>null,'address3'=>null,'address4'=>null ]; foreach($opt as $k=>$v){ $opt[$k] = $idx[$k] ?? null; } // Build employee map $emap = build_employee_map($pdo, $COMPANY_ID); // Prepared statements (upsert by company_id + employee_id) $sel = $pdo->prepare("SELECT id FROM employee_bank_data WHERE company_id=? AND employee_id=?"); $ins = $pdo->prepare("INSERT INTO employee_bank_data (company_id, employee_id, beneficiary_ac_number, beneficiary_name, ifsc_code, entry_name, department_name, employee_name, mobile, email, address1, address2, address3, address4, created_at) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW())"); $upd = $pdo->prepare("UPDATE employee_bank_data SET beneficiary_ac_number=?, beneficiary_name=?, ifsc_code=?, entry_name=?, department_name=?, employee_name=?, mobile=?, email=?, address1=?, address2=?, address3=?, address4=?, updated_at=NOW() WHERE company_id=? AND employee_id=?"); $inserted=0; $updated=0; $skipped=0; $errors=[]; for($r=1;$r<count($rows);$r++){ $row = $rows[$r]; if(count($row)==1 && trim($row[0])===''){ $skipped++; continue; } $dept = trim((string)($row[$idx['department_name']] ?? '')); $ename= trim((string)($row[$idx['employee_name']] ?? '')); if($dept==='' || $ename===''){ $skipped++; $errors[]="Row ".($r+1).": department_name/employee_name missing"; continue; } $key = strtolower($dept).'|'.strtolower($ename); if(!isset($emap[$key])){ $skipped++; $errors[]="Row ".($r+1).": Employee not found for '{$dept} + {$ename}'"; continue; } $employee_id = (int)$emap[$key]; $acno = trim((string)($row[$idx['beneficiary_ac_number']] ?? '')); $ben_name = trim((string)($row[$idx['beneficiary_name']] ?? '')); $ifsc = strtoupper(trim((string)($row[$idx['ifsc_code']] ?? ''))); if($acno==='' || $ben_name==='' || $ifsc===''){ $skipped++; $errors[]="Row ".($r+1).": missing A/c, beneficiary name or IFSC"; continue; } $entry_name = ($opt['entry_name']!==null)? trim((string)$row[$opt['entry_name']]) : ''; $mobile = ($opt['mobile']!==null)? trim((string)$row[$opt['mobile']]) : ''; $email = ($opt['email']!==null)? trim((string)$row[$opt['email']]) : ''; $address1 = ($opt['address1']!==null)? trim((string)$row[$opt['address1']]) : ''; $address2 = ($opt['address2']!==null)? trim((string)$row[$opt['address2']]) : ''; $address3 = ($opt['address3']!==null)? trim((string)$row[$opt['address3']]) : ''; $address4 = ($opt['address4']!==null)? trim((string)$row[$opt['address4']]) : ''; try{ $sel->execute([$COMPANY_ID,$employee_id]); if($sel->fetch()){ $upd->execute([$acno,$ben_name,$ifsc,$entry_name,$dept,$ename,$mobile,$email,$address1,$address2,$address3,$address4,$COMPANY_ID,$employee_id]); $updated++; } else { $ins->execute([$COMPANY_ID,$employee_id,$acno,$ben_name,$ifsc,$entry_name,$dept,$ename,$mobile,$email,$address1,$address2,$address3,$address4]); $inserted++; } }catch(Exception $e){ $errors[]="Row ".($r+1).": ".$e->getMessage(); $skipped++; } } jexit(['ok'=>true,'msg'=>"Import done: inserted=$inserted, updated=$updated, skipped=$skipped", 'errors'=>$errors]); } /* [6] Fetch list (with simple search) */ $q = trim((string)gv('q','')); $where = " WHERE company_id = :cid "; $params = [':cid'=>$COMPANY_ID]; if($q!==''){ $where .= " AND (employee_name LIKE :q OR department_name LIKE :q OR beneficiary_name LIKE :q OR ifsc_code LIKE :q OR beneficiary_ac_number LIKE :q OR employee_id LIKE :q)"; $params[':q'] = "%$q%"; } if ($F_dept !== '') { // exact match department filter (department name) $where .= " AND COALESCE(department_name,'') = :f_dept "; $params[':f_dept'] = $F_dept; } $sqlList = "SELECT id, employee_id, department_name, employee_name, beneficiary_ac_number, beneficiary_name, ifsc_code, entry_name, mobile, email, address1, address2, address3, address4, created_at, updated_at FROM employee_bank_data $where ORDER BY id DESC LIMIT 200"; $st = $pdo->prepare($sqlList); $st->execute($params); $rows = $st->fetchAll(PDO::FETCH_ASSOC); /* [7] Single fetch for edit */ if ($act==='get' && $_SERVER['REQUEST_METHOD']==='GET'){ $id = (int)gv('id',0); $stg = $pdo->prepare("SELECT * FROM employee_bank_data WHERE id=? AND company_id=?"); $stg->execute([$id,$COMPANY_ID]); $one = $stg->fetch(PDO::FETCH_ASSOC); if(!$one) jexit(['ok'=>false,'msg'=>'Not found'],404); jexit(['ok'=>true,'data'=>$one]); } ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Employee Bank Data</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> :root{ --bg: #f0fdf4; /* light mint */ --topbar: #2b2b2b; --nav-bg: #ffffff; --panel: #ffffff; --fg: #0f172a; --muted: #6b7280; --bd: #e6eef0; --chip-bg: #f3faf5; --brand: #16a34a; --brand-dark: #13803d; --danger: #c62828; --shadow: 0 6px 18px rgba(15,23,42,0.04); --radius: 12px; --nav-link:#0f172a; --nav-active:#0b7a3f; } *{box-sizing:border-box} html,body{height:100%} body{margin:0;font-family:Inter,system-ui,-apple-system,Segoe UI,Roboto,Arial;background:var(--bg);color:var(--fg);-webkit-font-smoothing:antialiased} .topbar{height:8px;background:var(--topbar);width:100%;position:fixed;top:0;left:0;z-index:30} /* simple header menu */ .navwrap{background:var(--nav-bg);border-bottom:1px solid var(--bd);position:fixed;top:8px;left:0;right:0;z-index:25} .nav{max-width:1200px;margin:0 auto;display:flex;gap:16px;align-items:center;padding:10px 20px} .nav a{color:var(--nav-link);text-decoration:none;padding:8px 12px;border-radius:8px;font-weight:600} .nav a.active{background:var(--chip-bg);color:var(--nav-active)} .wrap{max-width:1200px;margin:120px auto 40px;padding:20px} /* push down for header */ h1{margin:0 0 12px;font-size:20px;color:var(--brand-dark)} .card{background:var(--panel);border:1px solid var(--bd);border-radius:12px;padding:16px;margin-bottom:16px;box-shadow:var(--shadow)} .row{display:flex;gap:12px;flex-wrap:wrap;align-items:flex-start} .field{flex:1 1 220px;display:flex;flex-direction:column} .field label{font-size:13px;color:var(--muted);margin-bottom:6px} input[type="text"], input[type="number"], input[type="email"], select{ background:#fff;color:var(--fg);border:1px solid var(--bd);padding:10px;border-radius:8px;font-size:14px; } .actions{display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-top:12px} button,.btn{background:var(--brand);color:#fff;border:none;padding:8px 12px;border-radius:8px;cursor:pointer;font-weight:600} .btn2{background:#0ea5a2} .btn3{background:#0b7a3f} .btn4{background:var(--danger)} .tbl{width:100%;border-collapse:collapse;font-size:14px} .tbl th,.tbl td{border-bottom:1px solid var(--bd);padding:8px;text-align:left;vertical-align:top} .tbl th{font-weight:700;color:var(--fg);font-size:13px} .muted{color:var(--muted);font-size:13px} .tag{background:var(--chip-bg);padding:4px 8px;border-radius:999px;border:1px solid var(--bd);font-size:13px} .small{font-size:13px;color:var(--muted)} .note{font-size:13px;color:var(--muted)} .emp-select{width:100%;padding:10px;border-radius:8px;border:1px solid var(--bd);background:#fff} .nav-right{margin-left:auto;display:flex;gap:10px;align-items:center} @media (max-width:900px){ .row{flex-direction:column} .field{flex:1 1 auto} .wrap{margin-top:160px} } </style> <script> async function api(act, data, method='POST'){ const res = await fetch('?act='+encodeURIComponent(act), { method, body: (data instanceof FormData)? data : new URLSearchParams(data), }); return await res.json(); } async function saveCreate(){ const f = document.getElementById('f-create'); const data = new FormData(f); // include current f_dept from outer select to preserve state after reload const fd = document.querySelector('select[name="f_dept"]'); if(fd) data.set('f_dept', fd.value); const r = await api('create', data); alert(r.msg || (r.ok?'Saved':'Error')); if(r.ok) { // reload but keep department filter in query so list remains filtered const url = new URL(location.href); if(fd && fd.value) url.searchParams.set('f_dept', fd.value); location.href = url.toString(); } } async function loadEdit(id){ const r = await fetch('?act=get&id='+id); const j = await r.json(); if(!j.ok){ alert(j.msg||'Not found'); return; } const x=j.data; document.getElementById('e_id').value = x.id; // set employee select by value const sel = document.getElementById('e_employee_select'); if(sel){ sel.value = x.employee_id; sel.dispatchEvent(new Event('change')); } document.getElementById('e_beneficiary_ac_number').value = x.beneficiary_ac_number||''; document.getElementById('e_beneficiary_name').value = x.beneficiary_name||''; document.getElementById('e_ifsc_code').value = x.ifsc_code||''; document.getElementById('e_entry_name').value = x.entry_name||''; document.getElementById('e_mobile').value = x.mobile||''; document.getElementById('e_email').value = x.email||''; document.getElementById('e_address1').value = x.address1||''; document.getElementById('e_address2').value = x.address2||''; document.getElementById('e_address3').value = x.address3||''; document.getElementById('e_address4').value = x.address4||''; // department & employee_name fields: override if we have values from record document.getElementById('e_department_name').value = x.department_name||document.getElementById('e_department_name').value||''; document.getElementById('e_employee_name').value = x.employee_name||document.getElementById('e_employee_name').value||''; // preserve department filter in hidden input (if present) const fd = document.querySelector('select[name="f_dept"]'); if(fd){ const hidden = document.querySelector('input[name="f_dept"][form="f-edit"]'); if(hidden) hidden.value = fd.value; } document.getElementById('editCard').scrollIntoView({behavior:'smooth'}); } async function saveEdit(){ const f = document.getElementById('f-edit'); const data = new FormData(f); // include current f_dept from outer select to preserve state after reload const fd = document.querySelector('select[name="f_dept"]'); if(fd) data.set('f_dept', fd.value); const r = await api('update', data); alert(r.msg || (r.ok?'Saved':'Error')); if(r.ok){ const url = new URL(location.href); if(fd && fd.value) url.searchParams.set('f_dept', fd.value); location.href = url.toString(); } } // Delete UI removed — backend endpoint still exists but not reachable from UI document.addEventListener('DOMContentLoaded', function(){ // Employee select -> autofill dept & name (create) const selC = document.getElementById('create_employee_select'); if(selC){ selC.addEventListener('change', function(){ const opt = selC.options[selC.selectedIndex]; const dept = opt ? (opt.getAttribute('data-dept') || '') : ''; const ename = opt ? (opt.getAttribute('data-name') || '') : ''; if(document.getElementById('department_name')) document.getElementById('department_name').value = dept; if(document.getElementById('employee_name')) document.getElementById('employee_name').value = ename; }); } // Employee select -> autofill dept & name (edit) const selE = document.getElementById('e_employee_select'); if(selE){ selE.addEventListener('change', function(){ const opt = selE.options[selE.selectedIndex]; const dept = opt ? (opt.getAttribute('data-dept') || '') : ''; const ename = opt ? (opt.getAttribute('data-name') || '') : ''; if(document.getElementById('e_department_name')) document.getElementById('e_department_name').value = dept; if(document.getElementById('e_employee_name')) document.getElementById('e_employee_name').value = ename; }); } }); </script> </head> <body> <div class="topbar" aria-hidden="true"></div> <!-- Header menu (simple, presentational) --> <div class="navwrap" role="navigation" aria-label="Main menu"> <div class="nav"> <a href="/erp/dashboard.php">Dashboard</a> <a href="/erp/employee_list.php">Employees</a> <a class="active" href="/erp/employee_bank_data.php">Employee Bank Data</a> <div class="nav-right"> <a href="/erp/settings.php">Settings</a> <a href="/modules/auth/logout.php">Logout</a> </div> </div> </div> <div class="wrap"> <h1>Employee Bank Data</h1> <!-- CREATE --> <div class="card"> <div class="row"> <div class="field"> <label>Select Employee</label> <select id="create_employee_select" name="employee_id" form="f-create" class="emp-select" required> <option value="">— Choose employee —</option> <?php foreach($employees as $e): $label = trim($e['employee_name'] . ($e['department_name']? " — {$e['department_name']}" : '')); ?> <option value="<?= (int)$e['id'] ?>" data-dept="<?= h($e['department_name']) ?>" data-name="<?= h($e['employee_name']) ?>"><?= h($label) ?></option> <?php endforeach; ?> </select> </div> <div class="field"><label>Department</label><input type="text" form="f-create" name="department_name" id="department_name" placeholder="auto-filled or editable"></div> <div class="field"><label>Employee Name</label><input type="text" form="f-create" name="employee_name" id="employee_name" placeholder="auto-filled or editable"></div> <div class="field"><label>Beneficiary A/c Number</label><input type="text" form="f-create" name="beneficiary_ac_number" required></div> <div class="field"><label>Beneficiary Name</label><input type="text" form="f-create" name="beneficiary_name" required></div> <div class="field"><label>IFSC Code</label><input type="text" form="f-create" name="ifsc_code" maxlength="11" required></div> <div class="field"><label>Entry Name</label><input type="text" form="f-create" name="entry_name"></div> <div class="field"><label>Mobile</label><input type="text" form="f-create" name="mobile"></div> <div class="field"><label>Email</label><input type="email" form="f-create" name="email"></div> <div class="field"><label>Address 1</label><input type="text" form="f-create" name="address1"></div> <div class="field"><label>Address 2</label><input type="text" form="f-create" name="address2"></div> <div class="field"><label>Address 3</label><input type="text" form="f-create" name="address3"></div> <div class="field"><label>Address 4</label><input type="text" form="f-create" name="address4"></div> </div> <div class="actions" style="margin-top:14px;"> <form id="f-create" onsubmit="event.preventDefault(); saveCreate();" enctype="multipart/form-data"></form> <!-- include hidden f_dept so POST can preserve the filter state if desired --> <input type="hidden" name="f_dept" value="<?= h($F_dept) ?>" form="f-create"> <button onclick="saveCreate()">Add Bank Detail</button> <div class="note" style="margin-left:8px">Pick employee from the list — department and name auto-filled.</div> </div> </div> <!-- EDIT (appears when Edit clicked) --> <div class="card" id="editCard"> <div class="row"> <input type="hidden" id="e_id" name="id" form="f-edit"> <div class="field"> <label>Select Employee</label> <select id="e_employee_select" name="employee_id" form="f-edit" class="emp-select" required> <option value="">— Choose employee —</option> <?php foreach($employees as $e): $label = trim($e['employee_name'] . ($e['department_name']? " — {$e['department_name']}" : '')); ?> <option value="<?= (int)$e['id'] ?>" data-dept="<?= h($e['department_name']) ?>" data-name="<?= h($e['employee_name']) ?>"><?= h($label) ?></option> <?php endforeach; ?> </select> </div> <div class="field"><label>Department</label><input type="text" id="e_department_name" name="department_name" form="f-edit"></div> <div class="field"><label>Employee Name</label><input type="text" id="e_employee_name" name="employee_name" form="f-edit"></div> <div class="field"><label>Beneficiary A/c Number</label><input type="text" id="e_beneficiary_ac_number" name="beneficiary_ac_number" form="f-edit" required></div> <div class="field"><label>Beneficiary Name</label><input type="text" id="e_beneficiary_name" name="beneficiary_name" form="f-edit" required></div> <div class="field"><label>IFSC Code</label><input type="text" id="e_ifsc_code" name="ifsc_code" maxlength="11" form="f-edit" required></div> <div class="field"><label>Entry Name</label><input type="text" id="e_entry_name" name="entry_name" form="f-edit"></div> <div class="field"><label>Mobile</label><input type="text" id="e_mobile" name="mobile" form="f-edit"></div> <div class="field"><label>Email</label><input type="email" id="e_email" name="email" form="f-edit"></div> <div class="field"><label>Address 1</label><input type="text" id="e_address1" name="address1" form="f-edit"></div> <div class="field"><label>Address 2</label><input type="text" id="e_address2" name="address2" form="f-edit"></div> <div class="field"><label>Address 3</label><input type="text" id="e_address3" name="address3" form="f-edit"></div> <div class="field"><label>Address 4</label><input type="text" id="e_address4" name="address4" form="f-edit"></div> </div> <div class="actions" style="margin-top:12px"> <form id="f-edit" onsubmit="event.preventDefault(); saveEdit();"></form> <!-- include hidden f_dept so update can preserve list filter on redirect --> <input type="hidden" name="f_dept" value="<?= h($F_dept) ?>" form="f-edit"> <!-- Save button (sends to update API). Update option hidden as requested --> <button class="btn3" onclick="saveEdit()">Save changes</button> <div class="note" style="margin-left:8px">Use the list “Edit” button to load a row here. Save to apply changes.</div> </div> </div> <!-- LIST & SEARCH --> <div class="card"> <form method="get" class="row" style="align-items:flex-end;"> <div class="field" style="flex:2"> <label>Search</label> <input type="text" name="q" value="<?=h($q)?>" placeholder="dept / employee / IFSC / A/c / employee_id"> </div> <div class="field"> <label>Department</label> <select name="f_dept" style="padding:10px;border-radius:8px;border:1px solid #e6eef0"> <option value="">All Departments</option> <?php foreach($DEPARTMENTS as $d): $sel = ($F_dept !== '' && $F_dept === $d['name']) ? 'selected' : ''; ?> <option value="<?=h($d['name'])?>" <?=$sel?>><?=h($d['name'])?></option> <?php endforeach; ?> </select> </div> <div class="actions"> <button class="btn">Filter</button> <a class="btn" href="?">Reset</a> </div> </form> <div style="overflow:auto; margin-top:12px;"> <table class="tbl" role="table" aria-label="Employee bank data"> <thead> <tr> <th>ID</th> <th>Employee</th> <th>Department</th> <th>Beneficiary A/c</th> <th>Beneficiary Name</th> <th>IFSC</th> <th>Mobile</th> <th>Email</th> <th>Entry</th> <th>Created</th> <th>Updated</th> <th>Actions</th> </tr> </thead> <tbody> <?php if(!$rows): ?> <tr><td colspan="12" class="muted">No rows.</td></tr> <?php else: foreach($rows as $r): ?> <tr> <td><?=h($r['id'])?></td> <td><strong><?=h($r['employee_name'] ?: ('#' . (int)$r['employee_id']))?></strong></td> <td class="muted"><?=h($r['department_name'])?></td> <td><?=h($r['beneficiary_ac_number'])?></td> <td><?=h($r['beneficiary_name'])?></td> <td><?=h($r['ifsc_code'])?></td> <td><?=h($r['mobile'])?></td> <td><?=h($r['email'])?></td> <td><?=h($r['entry_name'])?></td> <td class="muted"><?=h($r['created_at'])?></td> <td class="muted"><?=h($r['updated_at'] ?? '')?></td> <td> <!-- Only Edit is shown; Delete removed from UI --> <button onclick="loadEdit(<?= (int)$r['id']?>)">Edit</button> </td> </tr> <?php endforeach; endif; ?> </tbody> </table> </div> </div> </div> </body> </html>