« Back to History
production_report_monthly.php
|
20260721_154033.php
Initial Bulk Import
Copy Code
<?php require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('production_report_monthly'); $pdo = $ctx['pdo'] ?? null; $company_id = (int)($ctx['company_id'] ?? 0); if (!$pdo) { require_once __DIR__ . '/core/db.php'; } if (!$pdo) { die('DB not available'); } /* ================= CSV EXPORT ================= */ if (isset($_GET['export']) && $_GET['export'] === 'csv') { $q = $pdo->prepare(" SELECT month, gp, butti, balaton, organza, cato_nic, np, total FROM production_data_by_month WHERE company_id = :cid ORDER BY STR_TO_DATE(CONCAT('01 ', month),'%d %M %Y') "); $q->execute([':cid' => $company_id]); header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename=production_monthly.csv'); $out = fopen('php://output','w'); fputcsv($out,['Month','GP','Butti','Balaton','Organza','Catonic','NP','Total']); while($r=$q->fetch(PDO::FETCH_ASSOC)){ fputcsv($out,$r); } fclose($out); exit; } /* ================= DATA ================= */ $q = $pdo->prepare(" SELECT month, gp, butti, balaton, organza, cato_nic, np, total FROM production_data_by_month WHERE company_id = :cid ORDER BY STR_TO_DATE(CONCAT('01 ', month),'%d %M %Y') "); $q->execute([':cid' => $company_id]); $rows = $q->fetchAll(PDO::FETCH_ASSOC); $labels=$gp=$butti=$balaton=$organza=$cato=$np=[]; foreach($rows as $r){ $labels[]=$r['month']; $gp[]=$r['gp']; $butti[]=$r['butti']; $balaton[]=$r['balaton']; $organza[]=$r['organza']; $cato[]=$r['cato_nic']; $np[]=$r['np']; } require_once __DIR__ . '/partials/header.php'; ?> <style> /* ===== PRINT ONLY FIX ===== */ @media print { @page { size: A4 landscape; margin: 10mm; } /* ERP header/footer hide ONLY in print */ header, footer, .topbar, .navbar, .card-actions, .no-print { display: none !important; } /* Show only report */ body * { visibility: hidden; } .print-area, .print-area * { visibility: visible; } .print-area { position: absolute; left: 0; top: 0; width: 100%; } table { font-size: 11px; } } </style> <div class="card print-area"> <div class="card-header"> <h3>Production — Month-wise Report</h3> <div class="card-actions no-print"> <a href="?export=csv" class="btn btn-sm">Export CSV</a> <button onclick="window.print()" class="btn btn-sm">Print / Save PDF</button> </div> </div> <div class="card-body"> <div style="max-width:1100px;height:280px;margin:0 auto 15px;"> <canvas id="prodChart"></canvas> </div> <div class="table-responsive"> <table class="table table-bordered table-striped"> <thead> <tr> <th>#</th> <th>Month</th> <th>GP</th> <th>Butti</th> <th>Balaton</th> <th>Organza</th> <th>Catonic</th> <th>NP</th> <th>Total</th> </tr> </thead> <tbody> <?php $i=1; foreach($rows as $r): ?> <tr> <td><?= $i++ ?></td> <td><?= htmlspecialchars($r['month']) ?></td> <td><?= number_format($r['gp'],0) ?></td> <td><?= number_format($r['butti'],0) ?></td> <td><?= number_format($r['balaton'],0) ?></td> <td><?= number_format($r['organza'],0) ?></td> <td><?= number_format($r['cato_nic'],0) ?></td> <td><?= number_format($r['np'],0) ?></td> <td><b><?= number_format($r['total'],0) ?></b></td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> <script> new Chart(document.getElementById('prodChart'),{ type:'bar', data:{ labels:<?=json_encode($labels)?>, datasets:[ {label:'GP',data:<?=json_encode($gp)?>,stack:'s'}, {label:'Butti',data:<?=json_encode($butti)?>,stack:'s'}, {label:'Balaton',data:<?=json_encode($balaton)?>,stack:'s'}, {label:'Organza',data:<?=json_encode($organza)?>,stack:'s'}, {label:'Catonic',data:<?=json_encode($cato)?>,stack:'s'}, {label:'NP',data:<?=json_encode($np)?>,stack:'s'} ] }, options:{ responsive:true, maintainAspectRatio:false, plugins:{ legend:{labels:{font:{size:10}}}, title:{display:true,text:'Month-wise production (meters)',font:{size:12}} }, scales:{x:{stacked:true},y:{stacked:true,beginAtZero:true}} } }); </script> <?php require_once __DIR__ . '/partials/footer.php'; ?>