« Back to History
mesr_final_yarn_conume_report2.php
|
20260722_120325.php
Initial Domain Snapshot
Copy Code
<?php error_reporting(E_ALL); ini_set('display_errors', 1); require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('yarn_entry'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; /* ========================= MONTH & FILTER HANDLING ========================= */ $input_month = $_GET['month'] ?? date('Y-m'); $selected_month = date('Y-m-01', strtotime($input_month)); $prev_month = date('Y-m-01', strtotime($selected_month . ' -1 month')); $start_date = date('Y-m-01', strtotime($selected_month)); $end_date = date('Y-m-t', strtotime($selected_month)); // Exclude list handle karna $exclude_names = $_GET['exclude'] ?? []; /* ========================= 1. MASTER MAPPING ========================= */ $specific_map = []; $generic_map = []; $master_stmt = $pdo->prepare(" SELECT technical_name, denier, color FROM yarn_master WHERE company_id = ? AND is_active = 1 "); $master_stmt->execute([$company_id]); $all_master_rows = $master_stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($all_master_rows as $m) { $d = strtoupper(trim($m['denier'])); $c = strtoupper(trim($m['color'])); $tech = trim($m['technical_name']); if ($c !== '') { $specific_map[$d . '|' . $c] = $tech; } else { $generic_map[$d] = $tech; } } /* ========================= 2. OPENING & CLOSING ========================= */ $stmt = $pdo->prepare(" SELECT technical_name, total_weight FROM yarn_monthly_closing WHERE month = ? AND company_id = ? "); $stmt->execute([$prev_month, $company_id]); $opening_stock = $stmt->fetchAll(PDO::FETCH_KEY_PAIR); $stmt->execute([$selected_month, $company_id]); $closing_stock = $stmt->fetchAll(PDO::FETCH_KEY_PAIR); /* ========================= 3. INWARD PROCESSING ========================= */ $inward_summary = []; $orphan_inwards = []; $tables = ['yarn_in', 'tfo_in', 'zari_in']; foreach ($tables as $table) { $st = $pdo->prepare(" SELECT denier, color, SUM(weight) as total_weight FROM `$table` WHERE company_id = :cid AND txn_date BETWEEN :start AND :end GROUP BY denier, color "); $st->execute([ ':cid' => $company_id, ':start' => $start_date, ':end' => $end_date ]); while ($row = $st->fetch(PDO::FETCH_ASSOC)) { $d = strtoupper(trim($row['denier'])); $c = strtoupper(trim($row['color'])); $weight = (float)$row['total_weight']; $target_tech_name = $specific_map[$d . '|' . $c] ?? $generic_map[$d] ?? null; if ($target_tech_name) { $inward_summary[$target_tech_name] = ($inward_summary[$target_tech_name] ?? 0) + $weight; } else { $orphan_inwards["$d | $c"] = ($orphan_inwards["$d | $c"] ?? 0) + $weight; } } } require_once __DIR__ . '/partials/header.php'; ?> <style> .print-only { display:none; } @media print { @page { size:auto; margin:10mm; } .d-print-none{ display:none !important; } .print-only{ display:block !important; } .table{ width:100% !important; border-collapse:collapse !important; border:1px solid #000 !important; } .table th,.table td{ border:1px solid #000 !important; padding:5px !important; color:#000 !important; } .table-dark{ background:#f2f2f2 !important; color:#000 !important; } tfoot tr{ background:#f2f2f2 !important; font-weight:bold !important; } } /* Select2 style adjustment for Bootstrap */ .select2-container--bootstrap-5 .select2-selection { border-radius: 0.375rem; } </style> <div class="container-fluid py-4"> <div class="print-only text-center mb-4"> <h2 class="mb-1">Final Yarn Consumption Report</h2> <h4 class="text-secondary">Month: <?= date('F Y', strtotime($selected_month)) ?></h4> <hr style="border:1px solid #000;"> </div> <div class="card shadow-sm mb-4 border-0 d-print-none"> <div class="card-body bg-light"> <form method="GET" class="row g-3 align-items-end"> <div class="col-md-3"> <label class="form-label fw-bold small">Select Month</label> <input type="month" name="month" class="form-control" value="<?= date('Y-m', strtotime($selected_month)) ?>"> </div> <div class="col-md-6"> <label class="form-label fw-bold small">Exclude Technical Names</label> <select name="exclude[]" class="form-select select2" multiple data-placeholder="Choose names to exclude..."> <?php $all_names = array_unique(array_column($all_master_rows, 'technical_name')); sort($all_names); foreach($all_names as $name): $selected = in_array($name, $exclude_names) ? 'selected' : ''; ?> <option value="<?= htmlspecialchars($name) ?>" <?= $selected ?>><?= htmlspecialchars($name) ?></option> <?php endforeach; ?> </select> </div> <div class="col-md-3 d-flex gap-2"> <button type="submit" class="btn btn-primary w-100">Generate</button> <button type="button" onclick="window.print()" class="btn btn-outline-dark w-100">Print</button> </div> </form> </div> </div> <div class="card shadow-sm border-0"> <div class="table-responsive"> <table class="table table-bordered align-middle mb-0"> <thead class="table-light text-center small fw-bold"> <tr> <th class="text-start py-3">TECHNICAL NAME</th> <th style="width:15%">OPENING (A)</th> <th style="width:15%">INWARD (B)</th> <th style="width:15%">CLOSING (C)</th> <th style="width:15%" class="table-secondary">NET CONSUMPTION</th> </tr> </thead> <tbody> <?php $gt = ['op'=>0, 'in'=>0, 'cl'=>0, 'con'=>0]; foreach ($all_names as $name): // Skip logic: Agar ye name exclude array me hai to loop continue kar do if (in_array($name, $exclude_names)) continue; $op = (float)($opening_stock[$name] ?? 0); $in = (float)($inward_summary[$name] ?? 0); $cl = (float)($closing_stock[$name] ?? 0); $con = ($op + $in) - $cl; if ($op == 0 && $in == 0 && $cl == 0) continue; $gt['op'] += $op; $gt['in'] += $in; $gt['cl'] += $cl; $gt['con'] += $con; ?> <tr> <td class="fw-bold px-3 small text-uppercase"><?= htmlspecialchars($name) ?></td> <td class="text-end px-3"><?= number_format($op, 3) ?></td> <td class="text-end px-3 text-success font-monospace">+ <?= number_format($in, 3) ?></td> <td class="text-end px-3 text-danger font-monospace">- <?= number_format($cl, 3) ?></td> <td class="text-end px-3 fw-bold bg-light"><?= number_format($con, 3) ?></td> </tr> <?php endforeach; ?> </tbody> <tfoot class="bg-light fw-bold text-end"> <tr style="border-top:2px solid #000;"> <td class="text-center py-2">GRAND TOTALS</td> <td class="px-3"><?= number_format($gt['op'], 3) ?></td> <td class="px-3 text-success"><?= number_format($gt['in'], 3) ?></td> <td class="px-3 text-danger"><?= number_format($gt['cl'], 3) ?></td> <td class="px-3 text-primary"><?= number_format($gt['con'], 3) ?></td> </tr> </tfoot> </table> </div> </div> <?php if (!empty($orphan_inwards)): ?> <div class="mt-4 d-print-none"> <div class="alert alert-warning border-0 shadow-sm small"> <h6 class="fw-bold">⚠️ Check Master: These yarns are inward but not mapped</h6> <div class="d-flex flex-wrap gap-3"> <?php foreach ($orphan_inwards as $k => $v): ?> <span class="badge bg-white text-dark border p-2"> <?= htmlspecialchars($k) ?> : <?= number_format($v, 3) ?> </span> <?php endforeach; ?> </div> </div> </div> <?php endif; ?> </div> <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" /> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script> <script> $(document).ready(function() { $('.select2').select2({ theme: "classic", width: '100%' }); }); </script> <?php require_once __DIR__ . '/partials/footer.php'; ?>