« Back to History
pissing_entry_advance.php
|
20260722_120325.php
Initial Domain Snapshot
Copy Code
<?php /* ============================================================================= File: pissing_entry_advance.php Purpose: Advance Pissing Entry ============================================================================= */ header('X-Frame-Options: SAMEORIGIN'); error_reporting(E_ALL); ini_set('display_errors', '1'); /* -------------------- AUTH + DB -------------------- */ require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('pissing_entry_advance'); $u = $ctx['user'] ?? null; $company_id = (int)($ctx['company_id'] ?? 0); $user_id = (int)($u['id'] ?? 0); $pdo = $ctx['pdo'] ?? null; if (!($pdo instanceof PDO)) { require __DIR__ . '/core/db.php'; } /* -------------------- Helpers -------------------- */ function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } function pv($k,$d=null){ return $_POST[$k] ?? $d; } /* -------------------- Employees (Pissing only) -------------------- */ $employees = []; $st = $pdo->prepare(" SELECT id, name FROM company_employee_master WHERE company_id = ? AND designation_name = 'Pissing' ORDER BY name "); $st->execute([$company_id]); $employees = $st->fetchAll(PDO::FETCH_ASSOC); /* -------------------- Pissing Qualities -------------------- */ $qualities = []; $st = $pdo->prepare(" SELECT id, quality FROM pissing_quality WHERE company_id = ? AND is_active = 1 ORDER BY quality "); $st->execute([$company_id]); $qualities = $st->fetchAll(PDO::FETCH_ASSOC); /* -------------------- SAVE -------------------- */ $msg = ''; $err = ''; if ($_SERVER['REQUEST_METHOD']==='POST' && pv('act')==='save') { $entry_date = pv('entry_date', date('Y-m-d')); $beam_no = trim(pv('beam_no','')); $machine_no = trim(pv('machine_no','')); $machine_type = trim(pv('machine_type','loom')); $quality_id = (int)pv('quality_id',0); $employee_id = (int)pv('employee_id',0); if ($beam_no==='') { $err = 'Beam No required'; } elseif ($quality_id<=0) { $err = 'Pissing Quality required'; } elseif ($employee_id<=0) { $err = 'Employee required'; } if (!$err) { try { /* Resolve names */ $qname = ''; $ename = ''; foreach ($qualities as $q) { if ((int)$q['id'] === $quality_id) { $qname = $q['quality']; // ✅ FIXED break; } } foreach ($employees as $e) { if ((int)$e['id'] === $employee_id) { $ename = $e['name']; break; } } if ($qname==='') { throw new Exception('Invalid Quality selected'); } if ($ename==='') { throw new Exception('Invalid Employee selected'); } $ins = $pdo->prepare(" INSERT INTO pissing_entry (company_id, entry_date, beam_no, machine_no, machine_type, pissing_type, employee_id, employee_name, created_by, created_at) VALUES (:cid,:dt,:beam,:mach,:mtype,:ptype,:eid,:ename,:uid,NOW()) "); $ins->execute([ ':cid' => $company_id, ':dt' => $entry_date, ':beam' => $beam_no, ':mach' => $machine_no ?: null, ':mtype' => $machine_type, ':ptype' => $qname, ':eid' => $employee_id, ':ename' => $ename, ':uid' => $user_id ]); $msg = 'Advance Pissing Entry saved successfully.'; $_POST = []; } catch (Throwable $e) { $err = $e->getMessage(); } } } /* -------------------- Recent Entries -------------------- */ $rows = []; $st = $pdo->prepare(" SELECT entry_date, beam_no, machine_no, machine_type, pissing_type, employee_name FROM pissing_entry WHERE company_id = ? ORDER BY id DESC LIMIT 100 "); $st->execute([$company_id]); $rows = $st->fetchAll(PDO::FETCH_ASSOC); ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Pissing Entry – Advance</title> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <?php require_once __DIR__.'/partials/header.php'; ?> <div class="wrap"> <div class="card"> <h1>Pissing Entry – Advance</h1> <div class="muted">Full Jog / Half Jog / Cut Beam Allowed</div> </div> <?php if($msg): ?><div class="notice success"><?=h($msg)?></div><?php endif; ?> <?php if($err): ?><div class="notice error"><?=h($err)?></div><?php endif; ?> <form method="post" class="card form-cols-4"> <input type="hidden" name="act" value="save"> <div> <label>Date</label> <input type="date" name="entry_date" value="<?=h(pv('entry_date',date('Y-m-d')))?>"> </div> <div> <label>Beam No</label> <input type="text" name="beam_no" value="<?=h(pv('beam_no'))?>"> </div> <div> <label>Machine Type</label> <select name="machine_type"> <option value="loom">LOOM</option> <option value="rapier">RAPIER</option> <option value="other">OTHER</option> </select> </div> <div> <label>Machine No (optional)</label> <input type="text" name="machine_no" value="<?=h(pv('machine_no'))?>"> </div> <div> <label>Pissing / Beam Quality</label> <select name="quality_id"> <option value="">-- Select Quality --</option> <?php foreach($qualities as $q): ?> <option value="<?=$q['id']?>" <?=((int)pv('quality_id')===(int)$q['id'])?'selected':''?>> <?=h($q['quality'])?> </option> <?php endforeach; ?> </select> </div> <div> <label>Employee</label> <select name="employee_id"> <option value="">-- Select Employee --</option> <?php foreach($employees as $e): ?> <option value="<?=$e['id']?>" <?=((int)pv('employee_id')===(int)$e['id'])?'selected':''?>> <?=h($e['name'])?> </option> <?php endforeach; ?> </select> </div> <div class="form-actions"> <button class="btn btn-primary">Save Advance Entry</button> </div> </form> <div class="card"> <h3>Recent Entries</h3> <table class="table"> <thead> <tr> <th>Date</th> <th>Beam</th> <th>Machine</th> <th>Type</th> <th>Quality</th> <th>Employee</th> </tr> </thead> <tbody> <?php foreach($rows as $r): ?> <tr> <td><?=h($r['entry_date'])?></td> <td><?=h($r['beam_no'])?></td> <td><?=h($r['machine_no'])?></td> <td><?=h(strtoupper($r['machine_type']))?></td> <td><?=h($r['pissing_type'])?></td> <td><?=h($r['employee_name'])?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> <?php require_once __DIR__.'/partials/footer.php'; ?> </body> </html>