« Back to History
mesr_yarn_out_report.php
|
20260721_154033.php
Initial Bulk Import
Copy Code
<?php error_reporting(E_ALL); ini_set('display_errors',1); require_once __DIR__ . '/../modules/auth/page_acl.php'; $ctx = page_require_access('mesr_yarn_out_report'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; function h($s){ return htmlspecialchars((string)$s,ENT_QUOTES,'UTF-8'); } /* =========================== FILTERS =========================== */ $from = $_GET['from'] ?? date('Y-m-01'); $to = $_GET['to'] ?? date('Y-m-d'); $type = $_GET['stock_type'] ?? 'Yarn'; $tables = [ 'Yarn' => 'yarn_out', 'TFO' => 'tfo_out', 'TPM' => 'tpm_out', 'Zari' => 'zari_out', 'Kasab' => 'kasab_out' ]; $selectedTypes = ($type === 'All') ? array_keys($tables) : [$type]; $grandBoxes=0; $grandWeight=0; $grandValue=0; $denierTotals=[]; require_once __DIR__ . '/../partials/header.php'; ?> <div class="container-fluid mt-4"> <div class="card shadow-sm border-0"> <div class="card-body"> <div class="no-print d-flex justify-content-between align-items-center flex-wrap mb-3"> <h2 class="mb-0">MESR Yarn OUT Report</h2> <div> <a class="btn btn-outline-secondary" href="?<?=http_build_query(array_merge($_GET,['print'=>1]))?>" target="_blank"> Print </a> </div> </div> <form method="get" class="no-print row g-2 align-items-end mb-4"> <div class="col-auto"> <label class="form-label">From</label> <input type="date" name="from" value="<?=h($from)?>" class="form-control"> </div> <div class="col-auto"> <label class="form-label">To</label> <input type="date" name="to" value="<?=h($to)?>" class="form-control"> </div> <div class="col-auto"> <label class="form-label">Stock Type</label> <select name="stock_type" class="form-select"> <?php foreach(['All','Yarn','TFO','TPM','Zari','Kasab'] as $opt): ?> <option <?=($type==$opt?'selected':'')?>><?=$opt?></option> <?php endforeach; ?> </select> </div> <div class="col-auto"> <button class="btn btn-primary">Apply</button> </div> </form> <?php foreach($selectedTypes as $st): $table = $tables[$st]; $sql=" SELECT t.denier, t.color, SUM(t.boxes) total_boxes, SUM(t.weight) total_weight, COALESCE(r.rate,0) rate FROM `$table` t LEFT JOIN yarn_rates r ON r.company_id = :cid AND r.denier COLLATE utf8mb4_unicode_ci = t.denier COLLATE utf8mb4_unicode_ci AND r.color COLLATE utf8mb4_unicode_ci = t.color COLLATE utf8mb4_unicode_ci WHERE t.company_id = :cid AND t.txn_date BETWEEN :from AND :to GROUP BY t.denier,t.color,r.rate ORDER BY t.denier,t.color "; $stmt=$pdo->prepare($sql); $stmt->execute([ ':cid'=>$company_id, ':from'=>$from, ':to'=>$to ]); $rows=$stmt->fetchAll(); if(empty($rows)) continue; $secBoxes=0; $secWeight=0; $secValue=0; ?> <div class="report-section mb-4"> <h3 class="border-top pt-3 h5"><?=$st?> OUT Report</h3> <div class="table-responsive"> <table class="table table-bordered table-striped table-sm"> <thead class="table-light"> <tr> <th>Denier</th> <th>Color</th> <th class="text-end">Boxes</th> <th class="text-end">Weight</th> <th class="text-end">Rate</th> <th class="text-end">Value</th> </tr> </thead> <tbody> <?php foreach($rows as $r): $boxes = round($r['total_boxes']); $weight = round($r['total_weight']); $rate = round($r['rate']); $value = round($weight * $rate); $secBoxes += $boxes; $secWeight += $weight; $secValue += $value; $grandBoxes += $boxes; $grandWeight += $weight; $grandValue += $value; if(!isset($denierTotals[$r['denier']])){ $denierTotals[$r['denier']] = ['boxes'=>0,'weight'=>0,'value'=>0]; } $denierTotals[$r['denier']]['boxes'] += $boxes; $denierTotals[$r['denier']]['weight'] += $weight; $denierTotals[$r['denier']]['value'] += $value; ?> <tr> <td><?=h($r['denier'])?></td> <td><?=h($r['color'])?></td> <td class="text-end"><?=number_format($boxes)?></td> <td class="text-end"><?=number_format($weight)?></td> <td class="text-end"><?=number_format($rate)?></td> <td class="text-end"><?=number_format($value)?></td> </tr> <?php endforeach; ?> </tbody> <tfoot> <tr> <th colspan="2" class="text-end">Section Total</th> <th class="text-end"><?=number_format($secBoxes)?></th> <th class="text-end"><?=number_format($secWeight)?></th> <th></th> <th class="text-end"><?=number_format($secValue)?></th> </tr> </tfoot> </table> </div> </div> <?php endforeach; ?> <?php if($type==='All' && !empty($denierTotals)): ?> <div class="report-section mb-4"> <h3 class="border-top pt-3 h5">Denier Wise Total</h3> <div class="table-responsive"> <table class="table table-bordered table-striped table-sm"> <thead class="table-light"> <tr> <th>Denier</th> <th class="text-end">Boxes</th> <th class="text-end">Weight</th> <th class="text-end">Value</th> </tr> </thead> <tbody> <?php foreach($denierTotals as $d=>$v): ?> <tr> <td><?=h($d)?></td> <td class="text-end"><?=number_format($v['boxes'])?></td> <td class="text-end"><?=number_format($v['weight'])?></td> <td class="text-end"><?=number_format($v['value'])?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> <?php endif; ?> <div class="report-section mb-4"> <h3 class="grand-total border-top pt-3">Grand Total</h3> <div class="table-responsive"> <table class="table table-bordered table-striped table-sm grand-total"> <tr> <th>Total Boxes</th> <th>Total Weight</th> <th>Total Value</th> </tr> <tr> <td><?=number_format($grandBoxes)?></td> <td><?=number_format($grandWeight)?></td> <td><?=number_format($grandValue)?></td> </tr> </table> </div> </div> </div> </div> </div> <?php require_once __DIR__ . '/../partials/footer.php'; ?>