« Back to History
page_production_entry_template.php
|
20260721_154033.php
Initial Bulk Import
Copy Code
<?php /* ============================================================================= File: page_production_entry_template.php Purpose: Reusable ERP page template for Production / Reports etc. - Uses header/footer includes for auth and global assets - Styling comes from /erp/public/assets/css/main.css?v=YYYYMMDD - No inline <style> blocks (per project rule) - DB credentials expected in config.php and core/db.php will require it Notes: * Header (erp/partials/header.php) must perform session-based auth and role checks * Footer (erp/partials/footer.php) must load global JS and close tags * Make any page-specific CSS additions in main.css with a clearly namespaced comment */ // [TOP] required includes require_once __DIR__ . '/erp/partials/header.php'; // header must enforce auth require_once __DIR__ . '/core/db.php'; // core/db.php should require config.php $page_title = 'Production Entries'; $company_id = $_SESSION['company_id'] ?? null; // filters $filter_date_from = $_GET['date_from'] ?? ''; $filter_date_to = $_GET['date_to'] ?? ''; $filter_machine = $_GET['machine_no'] ?? ''; $filter_karigar = $_GET['karigar_id'] ?? ''; $filter_quality = $_GET['quality_id'] ?? ''; $search_query = $_GET['q'] ?? ''; // ------------------- EXPORT CSV ------------------- if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_POST['action'] === 'export_csv') { header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=production_entries_' . date('Ymd_His') . '.csv'); $out = fopen('php://output', 'w'); fputcsv($out, ['ID','Date','Shift','Machine No','Karigar','Quality','Meters','Remarks']); $sql = "SELECT pe.id, pe.entry_date, pe.shift, pe.machine_no, k.name AS karigar_name, q.quality_name, pe.meters, pe.remarks FROM loom_production_entry pe LEFT JOIN loom_karigar_master k ON k.id = pe.karigar_id LEFT JOIN quality_rates q ON q.id = pe.quality_id WHERE pe.company_id = :company_id"; $params = [':company_id' => $company_id]; $stmt = $pdo->prepare($sql); $stmt->execute($params); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { fputcsv($out, [$row['id'],$row['entry_date'],$row['shift'],$row['machine_no'],$row['karigar_name'],$row['quality_name'],$row['meters'],$row['remarks']]); } fclose($out); exit; } // ------------------- MAIN FETCH ------------------- $per_page = 50; $page = max(1, intval($_GET['page'] ?? 1)); $offset = ($page - 1) * $per_page; $base_sql = "SELECT pe.id, pe.entry_date, pe.shift, pe.machine_no, k.name AS karigar_name, q.quality_name, pe.meters, pe.remarks FROM loom_production_entry pe LEFT JOIN loom_karigar_master k ON k.id = pe.karigar_id LEFT JOIN quality_rates q ON q.id = pe.quality_id WHERE pe.company_id = :company_id AND COALESCE(pe.archived,0) = 0"; $params = [':company_id' => $company_id]; $count_sql = "SELECT COUNT(1) FROM (" . $base_sql . ") tmp"; $count_stmt = $pdo->prepare($count_sql); $count_stmt->execute($params); $total_rows = (int)$count_stmt->fetchColumn(); $base_sql .= ' ORDER BY pe.entry_date DESC, pe.machine_no ASC LIMIT :lim OFFSET :off'; $stmt = $pdo->prepare($base_sql); $stmt->bindValue(':company_id', $company_id); $stmt->bindValue(':lim', (int)$per_page, PDO::PARAM_INT); $stmt->bindValue(':off', (int)$offset, PDO::PARAM_INT); $stmt->execute(); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); ?> <div class="wrap"> <div class="card"> <div class="card-header"> <h2><?php echo htmlspecialchars($page_title); ?></h2> <form method="get" class="inline-form"> <input type="date" name="date_from" value="<?php echo htmlspecialchars($filter_date_from); ?>" /> <input type="date" name="date_to" value="<?php echo htmlspecialchars($filter_date_to); ?>" /> <input type="text" name="q" placeholder="Search karigar / quality" value="<?php echo htmlspecialchars($search_query); ?>" /> <button type="submit" class="btn">Filter</button> </form> <form method="post" style="display:inline-block;margin-left:8px"> <input type="hidden" name="action" value="export_csv" /> <button type="submit" class="btn">Export CSV</button> </form> </div> <div class="card-content"> <table class="table"> <thead> <tr> <th>Date</th><th>Shift</th><th>Machine</th><th>Karigar</th> <th>Quality</th><th>Meters</th><th>Remarks</th><th>Actions</th> </tr> </thead> <tbody> <?php if (empty($rows)): ?> <tr><td colspan="8">No records found.</td></tr> <?php else: foreach ($rows as $r): ?> <tr> <td><?php echo htmlspecialchars($r['entry_date']); ?></td> <td><?php echo htmlspecialchars($r['shift']); ?></td> <td><?php echo htmlspecialchars($r['machine_no']); ?></td> <td><?php echo htmlspecialchars($r['karigar_name']); ?></td> <td><?php echo htmlspecialchars($r['quality_name']); ?></td> <td><?php echo htmlspecialchars($r['meters']); ?></td> <td><?php echo htmlspecialchars($r['remarks']); ?></td> <td> <a class="btn" href="/erp/production_entry_edit.php?id=<?php echo (int)$r['id']; ?>">Edit</a> </td> </tr> <?php endforeach; endif; ?> </tbody> </table> </div> </div> </div> <?php require_once __DIR__ . '/erp/partials/footer.php'; ?>