« Back to History
gray_jobwork_issue.php
|
20260722_120325.php
Initial Domain Snapshot
Copy Code
<?php ob_start(); require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('gray_receive_entry'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; $success = isset($_GET['success']); $last_date = $_GET['last_date'] ?? ''; $inserted_id = $_GET['id'] ?? ''; // ===== AJAX ENDPOINT: FETCH GRAY ID DETAILS ===== if (isset($_GET['action']) && $_GET['action'] === 'get_gray_details') { header('Content-Type: application/json'); $gray_id = (int)($_GET['gray_id'] ?? 0); try { $stmt = $pdo->prepare(" SELECT gr.*, m.mill_name, q.quality_name FROM gray_receive gr LEFT JOIN mill_master m ON gr.mill_id = m.id LEFT JOIN fabric_quality_master q ON gr.quality_id = q.id WHERE gr.company_id = :cid AND gr.gray_id = :gid LIMIT 1 "); $stmt->execute([':cid' => $company_id, ':gid' => $gray_id]); $details = $stmt->fetch(PDO::FETCH_ASSOC); if ($details) { echo json_encode(['success' => true, 'data' => $details]); } else { echo json_encode(['success' => false, 'message' => 'Gray ID not found or invalid']); } } catch (Exception $e) { echo json_encode(['success' => false, 'message' => 'Database error']); } exit(); } // ===== POST PROCESSING ===== if ($_SERVER['REQUEST_METHOD'] === 'POST') { $raw_date = $_POST['issue_date'] ?? ''; $d = DateTime::createFromFormat('d-m-Y', $raw_date); $issue_date = $d ? $d->format('Y-m-d') : date('Y-m-d'); try { $pdo->beginTransaction(); $stmt = $pdo->prepare(" INSERT INTO job_work_issue (company_id, gray_id, meter, taka, issue_date, job_worker_id, process_type_id, challan_no, vehicle_no, remarks, status) VALUES (:cid, :gray_id, :meter, :taka, :issue_date, :job_worker_id, :process_type_id, :challan_no, :vehicle_no, :remarks, 'issued') "); $stmt->execute([ ':cid' => $company_id, ':gray_id' => $_POST['gray_id'], ':meter' => $_POST['meter'], ':taka' => $_POST['taka'], ':issue_date' => $issue_date, ':job_worker_id' => $_POST['job_worker_id'], ':process_type_id' => $_POST['process_type_id'], ':challan_no' => $_POST['challan_no'], ':vehicle_no' => $_POST['vehicle_no'], ':remarks' => $_POST['remarks'] ?? '' ]); $issue_id = $pdo->lastInsertId(); if (file_exists(__DIR__ . '/helpers/activity_helper.php')) { require_once __DIR__ . '/helpers/activity_helper.php'; log_activity([ 'activity_type' => 'entry', 'module_name' => 'gray_jobwork_issue', 'action_name' => 'add_save', 'activity_note' => "Gray ID: {$_POST['gray_id']}, Meter: {$_POST['meter']}, Taka: {$_POST['taka']}, Worker: {$_POST['job_worker_id']}, Process: {$_POST['process_type_id']}, Challan: {$_POST['challan_no']}", 'reference_id' => $issue_id, ]); } $pdo->commit(); header("Location: gray_jobwork_issue.php?success=1&id=$issue_id&last_date=" . urlencode($raw_date)); exit(); } catch (Exception $e) { if ($pdo->inTransaction()) $pdo->rollBack(); die("System Error: " . $e->getMessage()); } } require_once __DIR__ . '/partials/header.php'; // Fetch Dropdown Masters $process_types = $pdo->prepare("SELECT id, type_name FROM jobwork_types WHERE company_id = ? AND is_active = 'YES' ORDER BY sort_order"); $process_types->execute([$company_id]); $process_types = $process_types->fetchAll(PDO::FETCH_ASSOC); $job_workers = $pdo->prepare("SELECT id, party_name FROM job_work_party_master WHERE company_id = ? AND is_active = 1 ORDER BY party_name"); $job_workers->execute([$company_id]); $job_workers = $job_workers->fetchAll(PDO::FETCH_ASSOC); ?> <div class="container-fluid mt-3"> <div class="card p-3 shadow-sm border-0"> <div class="d-flex justify-content-between align-items-center mb-3"> <h5 class="m-0 text-primary fw-bold">Gray Jobwork Issue Entry</h5> </div> <?php if($success): ?> <div class="alert alert-success alert-dismissible fade show border-0 shadow-sm py-2"> <strong>Success!</strong> Issue Saved Entry ID: <?= htmlspecialchars($inserted_id) ?> <button type="button" class="btn-close" data-bs-dismiss="alert"></button> </div> <?php endif; ?> <form method="POST" id="issueForm" autocomplete="off"> <!-- SECTION 1: Gray ID Lookup & Verification --> <div class="bg-light p-3 rounded mb-3 border border-light-subtle"> <div class="row g-3 align-items-end"> <div class="col-md-2"> <label class="form-label small fw-bold text-danger">Enter Gray ID</label> <div class="input-group"> <input type="number" id="gray_id" name="gray_id" class="form-control fw-bold border-danger" required> <button type="button" id="btnFetchDetails" class="btn btn-danger fw-bold">FETCH</button> </div> </div> <div class="col-md-3"> <label class="form-label small fw-bold text-secondary">Mill Name</label> <input type="text" id="disp_mill" class="form-control text-muted" readonly disabled> </div> <div class="col-md-3"> <label class="form-label small fw-bold text-secondary">Quality</label> <input type="text" id="disp_quality" class="form-control text-muted" readonly disabled> </div> <div class="col-md-2"> <label class="form-label small fw-bold text-primary">Issue Meter</label> <input type="number" step="0.01" id="meter" name="meter" class="form-control fw-bold border-primary text-primary" required> </div> <div class="col-md-2"> <label class="form-label small fw-bold text-primary">Issue Taka</label> <input type="number" id="taka" name="taka" class="form-control fw-bold border-primary text-primary text-center" required> </div> </div> </div> <!-- SECTION 2: Issue Entry Details --> <div class="row g-3"> <div class="col-md-2"> <label class="form-label small fw-bold">Issue Date</label> <input type="text" id="issue_date" name="issue_date" class="form-control" value="<?= htmlspecialchars($last_date) ?>" required> </div> <div class="col-md-3"> <label class="form-label small fw-bold">Job Worker / Mill</label> <select id="job_worker_id" name="job_worker_id" required> <option value="">Select Job Worker / Mill</option> <?php foreach($job_workers as $jw): ?> <option value="<?= $jw['id'] ?>"><?= htmlspecialchars($jw['party_name']) ?></option> <?php endforeach; ?> </select> </div> <div class="col-md-3"> <label class="form-label small fw-bold">Process Type</label> <select id="process_type_id" name="process_type_id" required> <option value="">Select Process</option> <?php foreach($process_types as $pt): ?> <option value="<?= $pt['id'] ?>"><?= htmlspecialchars($pt['type_name']) ?></option> <?php endforeach; ?> </select> </div> <div class="col-md-2"> <label class="form-label small fw-bold">Challan No</label> <input type="text" name="challan_no" class="form-control" required> </div> <div class="col-md-2"> <label class="form-label small fw-bold">Vehicle No</label> <input type="text" name="vehicle_no" class="form-control"> </div> <div class="col-md-9"> <label class="form-label small fw-bold">Remarks / Notes</label> <input type="text" name="remarks" class="form-control"> </div> <div class="col-md-3 d-flex align-items-end"> <button type="submit" id="saveBtn" class="btn btn-primary w-100 fw-bold py-2">SAVE JOBWORK ISSUE</button> </div> </div> </form> </div> </div> <link href="https://cdn.jsdelivr.net/npm/tom-select/dist/css/tom-select.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/tom-select/dist/js/tom-select.complete.min.js"></script> <script> const tsWorker = new TomSelect("#job_worker_id", { create: false }); const tsProcess = new TomSelect("#process_type_id", { create: false }); const dateInp = document.getElementById('issue_date'); if(!dateInp.value) { const d = new Date(); dateInp.value = String(d.getDate()).padStart(2,'0')+'-'+String(d.getMonth()+1).padStart(2,'0')+'-'+d.getFullYear(); } function fetchGrayDetails() { const grayId = document.getElementById('gray_id').value; if(!grayId) return; fetch(`gray_jobwork_issue.php?action=get_gray_details&gray_id=${grayId}`) .then(res => res.json()) .then(res => { if(res.success) { document.getElementById('disp_mill').value = res.data.mill_name || ''; document.getElementById('disp_quality').value = res.data.quality_name || ''; // Fetch defaults details to editable input boxes so they can be changed document.getElementById('meter').value = res.data.grey_mts || ''; document.getElementById('taka').value = res.data.taka || ''; } else { alert(res.message); clearGrayDisplay(); } }) .catch(err => { console.error(err); alert('Error communicating with the server'); }); } function clearGrayDisplay() { document.getElementById('disp_mill').value = ''; document.getElementById('disp_quality').value = ''; document.getElementById('meter').value = ''; document.getElementById('taka').value = ''; } document.getElementById('btnFetchDetails').addEventListener('click', fetchGrayDetails); document.getElementById('gray_id').addEventListener('blur', fetchGrayDetails); const inputs = Array.from(document.querySelectorAll('#issueForm input, #issueForm select, #issueForm button')); inputs.forEach((input, i) => { input.addEventListener('keydown', (e) => { if (e.key === 'Enter') { if (input.tomselect && input.tomselect.isOpen) return; e.preventDefault(); const next = inputs[i + 1]; if (next) next.focus(); } }); }); window.onload = () => setTimeout(() => document.getElementById('gray_id').focus(), 200); </script> <?php require_once __DIR__ . '/partials/footer.php'; ob_end_flush(); ?>