« Back to History
payment_detail_entry.php
|
20261119_140743.php
Initial Domain Snapshot
Copy Code
<?php /* ============================================================================ Payment Detail Entry Purpose: Manual payment entry into payments table Supports: Employee / Karigar / Other (custom name) ============================================================================ */ $page_title = 'Payment Detail Entry'; /* 0️⃣ AUTH + BOOTSTRAP (MANDATORY) */ require_once __DIR__ . '/modules/auth/page_acl.php'; require_once __DIR__ . '/modules/activity/activity_logger.php'; $ctx = page_require_access('payment_detail_entry'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; $user = $ctx['user'] ?? null; $user_id = (int)($user['id'] ?? 0); function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } /* ---------------- CSRF ---------------- */ if (session_status() !== PHP_SESSION_ACTIVE) session_start(); if (empty($_SESSION['csrf_token'])) { $_SESSION['csrf_token'] = bin2hex(random_bytes(16)); } function csrf_field(){ echo '<input type="hidden" name="csrf_token" value="'.h($_SESSION['csrf_token']).'">'; } function check_csrf(){ if (($_POST['csrf_token'] ?? '') !== ($_SESSION['csrf_token'] ?? '')) { http_response_code(403); exit('Bad CSRF'); } } /* ---------------- AJAX: EMPLOYEE / KARIGAR ---------------- */ if (isset($_GET['ajax']) && $_GET['ajax']==='employees') { $st = $pdo->prepare(" SELECT id, name FROM company_employee_master WHERE company_id=? ORDER BY name "); $st->execute([$company_id]); header('Content-Type: application/json'); echo json_encode($st->fetchAll(PDO::FETCH_ASSOC)); exit; } if (isset($_GET['ajax']) && $_GET['ajax']==='karigars') { $st = $pdo->prepare(" SELECT id, karigar_name FROM loom_karigar_master WHERE company_id=? AND COALESCE(is_active,1)=1 ORDER BY karigar_name "); $st->execute([$company_id]); header('Content-Type: application/json'); echo json_encode($st->fetchAll(PDO::FETCH_ASSOC)); exit; } /* ---------------- SAVE ---------------- */ if ($_SERVER['REQUEST_METHOD']==='POST') { check_csrf(); $person_type = $_POST['person_type'] ?? ''; $person_id = (int)($_POST['person_id'] ?? 0); $other_name = trim($_POST['other_name'] ?? ''); $payment_type = $_POST['payment_type'] ?? ''; $amount = (float)($_POST['amount'] ?? 0); $pay_date = $_POST['payment_date'] ?? date('Y-m-d'); $pay_mode = $_POST['payment_mode'] ?? 'CASH'; $remark = trim($_POST['remark'] ?? ''); if (!in_array($person_type,['employee','karigar','other'],true)) { exit('Invalid person type'); } if (!in_array($payment_type,['salary','extra','other'],true)) { exit('Invalid payment type'); } if ($amount <= 0) exit('Invalid amount'); if ($person_type === 'employee' || $person_type === 'karigar') { if ($person_id <= 0) exit('Invalid person'); } if ($person_type === 'other') { if ($other_name === '') exit('Paid To name required'); $person_id = 0; $remark = 'Paid To: '.$other_name.($remark ? ' | '.$remark : ''); } $pdo->prepare(" INSERT INTO payments (company_id, person_type, person_id, payment_type, amount, payment_date, payment_mode, remark, created_by, created_at) VALUES (?,?,?,?,?,?,?,?,?,NOW()) ")->execute([ $company_id, $person_type, $person_id, $payment_type, $amount, $pay_date, $pay_mode, $remark, $user_id ]); activity_log([ 'company_id' => $company_id ?? 0, 'user_id' => $user['id'] ?? ($_SESSION['user_id'] ?? 0), 'module' => 'payment', 'action_name' => 'create', 'entity_type' => 'payment_detail', 'entity_id' => (int)$pdo->lastInsertId(), 'remarks' => 'Payment detail created' ]); header("Location: payment_detail_entry.php?done=1"); exit; } /* ---------------- UI ---------------- */ require_once __DIR__ . '/partials/header.php'; ?> <div class="container py-4"> <div class="card border-0 shadow-sm"> <div class="card-header bg-primary text-white py-3"> <h5 class="mb-0"><i class="bi bi-pencil-square me-2"></i>Payment Detail Entry</h5> </div> <div class="card-body p-4"> <?php if (isset($_GET['done'])): ?> <div class="alert alert-success alert-dismissible fade show" role="alert"> <i class="bi bi-check-circle-fill me-2"></i> Payment detail saved successfully. <button type="button" class="btn-close" data-bs-dismiss="alert"></button> </div> <?php endif; ?> <form method="post"> <?php csrf_field(); ?> <div class="row mb-4"> <div class="col-md-12"> <label class="form-label fw-bold text-muted small text-uppercase mb-2">Person Type</label> <div class="btn-group w-100" role="group"> <input type="radio" class="btn-check" name="person_type" id="typeEmp" value="employee" checked autocomplete="off"> <label class="btn btn-outline-primary py-2" for="typeEmp"> <i class="bi bi-person-badge me-2"></i>Employee </label> <input type="radio" class="btn-check" name="person_type" id="typeKar" value="karigar" autocomplete="off"> <label class="btn btn-outline-primary py-2" for="typeKar"> <i class="bi bi-hammer me-2"></i>Karigar </label> <input type="radio" class="btn-check" name="person_type" id="typeOther" value="other" autocomplete="off"> <label class="btn btn-outline-primary py-2" for="typeOther"> <i class="bi bi-three-dots me-2"></i>Other </label> </div> </div> </div> <div class="row g-3 mb-3"> <div id="employeeBox" class="col-md-6"> <label class="form-label small fw-bold">Select Employee</label> <select name="person_id" id="employeeSelect" class="form-select border-primary-subtle shadow-sm"> <option value="">Select Employee</option> </select> </div> <div id="karigarBox" class="col-md-6" style="display:none"> <label class="form-label small fw-bold">Select Karigar</label> <select name="person_id" id="karigarSelect" class="form-select border-primary-subtle shadow-sm"> <option value="">Select Karigar</option> </select> </div> <div id="otherBox" class="col-md-6" style="display:none"> <label class="form-label small fw-bold">Paid To (Name)</label> <input type="text" name="other_name" class="form-control border-primary-subtle shadow-sm" placeholder="Enter full name"> </div> <div class="col-md-3"> <label class="form-label small fw-bold">Payment Type</label> <select name="payment_type" class="form-select"> <option value="salary">Salary</option> <option value="extra">Extra</option> <option value="other">Other</option> </select> </div> <div class="col-md-3"> <label class="form-label small fw-bold text-success">Amount</label> <div class="input-group"> <span class="input-group-text bg-success-subtle border-success-subtle text-success fw-bold">₹</span> <input type="number" step="0.01" name="amount" class="form-control fw-bold text-end border-success-subtle"> </div> </div> </div> <div class="row g-3 align-items-end"> <div class="col-md-3"> <label class="form-label small fw-bold">Date</label> <input type="date" name="payment_date" class="form-control" value="<?= date('Y-m-d') ?>"> </div> <div class="col-md-3"> <label class="form-label small fw-bold">Payment Mode</label> <select name="payment_mode" class="form-select fw-bold border-secondary-subtle"> <option>CASH</option> <option selected>BANK</option> <option>UPI</option> <option>CHEQUE</option> </select> </div> <div class="col-md-4"> <label class="form-label small fw-bold">Remark</label> <input type="text" name="remark" class="form-control" placeholder="Optional notes..."> </div> <div class="col-md-2"> <button type="submit" class="btn btn-success btn-lg w-100 shadow-sm"> <i class="bi bi-save me-2"></i>Save Entry </button> </div> </div> </form> </div> </div> </div> <script> function togglePersonType(type) { const boxes = { 'employee': document.getElementById('employeeBox'), 'karigar': document.getElementById('karigarBox'), 'other': document.getElementById('otherBox') }; // Sabko hide karo aur inputs disable karo Object.keys(boxes).forEach(key => { boxes[key].style.display = 'none'; boxes[key].querySelectorAll('select, input').forEach(i => i.disabled = true); }); // Selected wale ko show karo aur enable karo if (boxes[type]) { boxes[type].style.display = 'block'; boxes[type].querySelectorAll('select, input').forEach(i => i.disabled = false); } } document.querySelectorAll('input[name="person_type"]').forEach(radio => { radio.addEventListener('change', (e) => togglePersonType(e.target.value)); }); // Initial call togglePersonType('employee'); </script> <script> const empBox = document.getElementById('employeeBox'); const karBox = document.getElementById('karigarBox'); const otherBox = document.getElementById('otherBox'); const empSel = document.getElementById('employeeSelect'); const karSel = document.getElementById('karigarSelect'); function loadEmployees(){ fetch('payment_detail_entry.php?ajax=employees') .then(r=>r.json()) .then(list=>{ empSel.innerHTML='<option value="">Select Employee</option>'; list.forEach(e=>{ let o=document.createElement('option'); o.value=e.id; o.textContent=e.name; empSel.appendChild(o); }); }); } function loadKarigars(){ fetch('payment_detail_entry.php?ajax=karigars') .then(r=>r.json()) .then(list=>{ karSel.innerHTML='<option value="">Select Karigar</option>'; list.forEach(k=>{ let o=document.createElement('option'); o.value=k.id; o.textContent=k.karigar_name; karSel.appendChild(o); }); }); } function toggle(type){ if(type==='employee'){ empBox.style.display=''; karBox.style.display='none'; otherBox.style.display='none'; empSel.disabled=false; karSel.disabled=true; } else if(type==='karigar'){ empBox.style.display='none'; karBox.style.display=''; otherBox.style.display='none'; empSel.disabled=true; karSel.disabled=false; } else{ empBox.style.display='none'; karBox.style.display='none'; otherBox.style.display=''; empSel.disabled=true; karSel.disabled=true; } } document.querySelectorAll('input[name="person_type"]').forEach(r=>{ r.addEventListener('change',()=>toggle(r.value)); }); toggle('employee'); loadEmployees(); loadKarigars(); </script> <?php require_once __DIR__ . '/partials/footer.php'; ?>