« Back to History
jobwork_send_entry.php
|
20260721_154032.php
Initial Bulk Import
Copy Code
<?php // 1. Error Reporting (For Debugging) ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); // 2. Load ERP Context require_once dirname(__DIR__) . '/modules/auth/page_acl.php'; $ctx = page_require_access('jobwork_send'); $pdo = $ctx['pdo']; $company_id = $ctx['company_id']; // 3. Handle AJAX Request for Yarn Data if (isset($_GET['action']) && $_GET['action'] === 'get_yarn_data') { header('Content-Type: application/json'); $stock_type = $_GET['type'] ?? ''; try { $st = $pdo->prepare(" SELECT DISTINCT yarn_types, company_name, denier, color FROM yarn_company_data WHERE company_id = ? AND stock_type = ? ORDER BY yarn_types, company_name "); $st->execute([$company_id, $stock_type]); echo json_encode($st->fetchAll(PDO::FETCH_ASSOC)); } catch (PDOException $e) { http_response_code(500); echo json_encode(['error' => $e->getMessage()]); } exit; } // 4. Include Header require_once dirname(__DIR__) . '/partials/header.php'; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Job Work Send Entry</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"> <style> body { background-color: #f8f9fa; font-family: 'Segoe UI', sans-serif; } .card { border: none; box-shadow: 0 4px 12px rgba(0,0,0,0.1); border-radius: 10px; margin-bottom: 20px; } .card-header { background: #fff; font-weight: bold; color: #007bff; border-bottom: 1px solid #eee; } .form-label { font-weight: 600; font-size: 13px; color: #555; text-transform: uppercase; } .summary-bar { background: #fff; border-top: 4px solid #28a745; padding: 20px; border-radius: 10px; box-shadow: 0 -5px 15px rgba(0,0,0,0.05); } .total-val { font-size: 1.5rem; font-weight: 800; color: #333; } </style> </head> <body> <form id="jobWorkForm" action="process_jobwork.php" method="POST"> <div class="card shadow-sm"> <div class="card-header"><i class="fas fa-file-invoice mr-2"></i> CHALLAN HEADER</div> <div class="card-body"> <div class="row"> <div class="col-md-3 mb-3"> <label class="form-label">Challan No *</label> <input type="number" name="challan_no" class="form-control" placeholder="No" required> </div> <div class="col-md-3 mb-3"> <label class="form-label">Challan Date</label> <input type="date" name="challan_date" class="form-control" value="<?= date('Y-m-d'); ?>" required> </div> <div class="col-md-6 mb-3"> <label class="form-label">Job Work Party</label> <select name="party_name" class="form-control" required> <option value="">-- Select Party --</option> <?php $st = $pdo->prepare("SELECT party_name FROM job_work_party WHERE company_id = ? AND status = 'Active' ORDER BY party_name"); $st->execute([$company_id]); while ($row = $st->fetch(PDO::FETCH_ASSOC)) { echo '<option value="' . htmlspecialchars($row['party_name']) . '">' . htmlspecialchars($row['party_name']) . '</option>'; } ?> </select> </div> </div> </div> </div> <div class="card shadow-sm"> <div class="card-header d-flex justify-content-between align-items-center"> <span>ITEM DETAILS</span> <button type="button" class="btn btn-primary btn-sm rounded-pill px-3" onclick="addRow()">+ Add Row</button> </div> <div class="table-responsive"> <table class="table mb-0" id="itemsTable"> <thead class="bg-light"> <tr> <th width="15%">Stock Type</th> <th>Description</th> <th width="12%" class="text-center">Boxes</th> <th width="15%" class="text-center">Weight (Kg)</th> <th width="80" class="text-center">Action</th> </tr> </thead> <tbody></tbody> </table> </div> </div> <div class="summary-bar mt-4 shadow"> <div class="row align-items-center"> <div class="col-md-3 text-center border-right"> <small class="text-muted d-block font-weight-bold">TOTAL BOXES</small> <span id="totalBoxes" class="total-val">0</span> </div> <div class="col-md-3 text-center border-right"> <small class="text-muted d-block font-weight-bold">TOTAL WEIGHT</small> <span id="totalWeight" class="total-val">0.00</span> </div> <div class="col-md-6 text-right"> <button type="submit" name="save_challan" class="btn btn-success btn-lg px-5 shadow"> <i class="fas fa-save mr-2"></i> SAVE & SEND </button> </div> </div> </div> </form> </div> <script> let rowCount = 0; function addRow() { const tbody = document.querySelector("#itemsTable tbody"); const id = rowCount++; const tr = document.createElement("tr"); tr.innerHTML = ` <td> <select name="items[${id}][stock_type]" class="form-control" onchange="fetchItems(this.value, ${id})" required> <option value="">Select</option> <option value="TPM">TPM</option><option value="Yarn">Yarn</option> <option value="Zari">Zari</option><option value="Kasab">Kasab</option> </select> </td> <td> <select id="sel_${id}" class="form-control" onchange="mapData(this, ${id})" required> <option value="">-- Choose Type --</option> </select> <input type="hidden" name="items[${id}][yarn_type]" id="yt_${id}"> <input type="hidden" name="items[${id}][company]" id="co_${id}"> <input type="hidden" name="items[${id}][denier]" id="de_${id}"> <input type="hidden" name="items[${id}][color]" id="cl_${id}"> </td> <td><input type="number" name="items[${id}][boxes]" class="form-control text-center box-input" oninput="calculate()" required></td> <td><input type="number" step="0.01" name="items[${id}][weight]" class="form-control text-center weight-input" oninput="calculate()" required></td> <td class="text-center"> <button type="button" class="btn btn-sm text-danger" onclick="this.closest('tr').remove(); calculate();"> <i class="fas fa-trash"></i> </button> </td> `; tbody.appendChild(tr); } async function fetchItems(type, id) { const sel = document.getElementById(`sel_${id}`); if(!type) return; sel.innerHTML = '<option value="">Loading...</option>'; try { const res = await fetch(`jobwork_send_entry.php?action=get_yarn_data&type=${type}`); const data = await res.json(); sel.innerHTML = '<option value="">-- Choose Item --</option>'; data.forEach((r, idx) => { const opt = document.createElement('option'); opt.value = idx; opt.textContent = `${r.yarn_types} | ${r.company_name} | ${r.denier}D | ${r.color}`; opt.dataset.yt = r.yarn_types; opt.dataset.co = r.company_name; opt.dataset.de = r.denier; opt.dataset.cl = r.color; sel.appendChild(opt); }); } catch(e) { console.error("AJAX Error:", e); } } function mapData(sel, id) { const opt = sel.selectedOptions[0]; if (!opt || opt.value === "") return; document.getElementById(`yt_${id}`).value = opt.dataset.yt; document.getElementById(`co_${id}`).value = opt.dataset.co; document.getElementById(`de_${id}`).value = opt.dataset.de; document.getElementById(`cl_${id}`).value = opt.dataset.cl; } function calculate() { let b = 0, w = 0; document.querySelectorAll(".box-input").forEach(i => b += Number(i.value || 0)); document.querySelectorAll(".weight-input").forEach(i => w += Number(i.value || 0)); document.getElementById("totalBoxes").innerText = b; document.getElementById("totalWeight").innerText = w.toFixed(2); } window.onload = addRow; </script> </body> <?php require_once dirname(__DIR__) . '/partials/footer.php'; ?> <?php require_once dirname(__DIR__) . '/partials/footer.php'; ?> </html>