« Back to History
yarn_stock_old.php
|
20260721_154034.php
Initial Bulk Import
Copy Code
<?php /* ========================================================= File: /erp/yarn_stock.php Purpose: Stock = IN - OUT (by type) + All Reports view + CSV + PDF + print-clean Notes: Zari -> Metalic Stock Report Kasab -> Zari Kasab Stock Report ========================================================= */ error_reporting(E_ALL); ini_set('display_errors', 1); /* ---- Header include toggle (skip header/footer only for print=1) ---- */ $print_only = (isset($_GET['print']) && (int)$_GET['print'] === 1); $USE_HEADER = !$print_only; /* ---- Auth + scope (AUTH FILES UNTOUCHED) ---- */ require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('yarn_entry'); // same ACL as entry $company_id = (int)($ctx['company_id'] ?? 0); $u = $ctx['user'] ?? null; /* ---- PDO bootstrap (robust) ---- */ $pdo = $ctx['pdo'] ?? null; if (!($pdo instanceof PDO)) { $tryInclude = function(string $path) use (&$pdo) { @include_once $path; if ($pdo instanceof PDO) return true; if (isset($db) && $db instanceof PDO) { $pdo = $db; return true; } if (isset($dbh) && $dbh instanceof PDO) { $pdo = $dbh; return true; } if (isset($conn) && $conn instanceof PDO){ $pdo = $conn; return true; } return false; }; foreach ([__DIR__.'/core/db.php', __DIR__.'/db.php', __DIR__.'/config/db.php', __DIR__.'/config.php'] as $p) { if (is_file($p) && $tryInclude($p)) { break; } } if (!($pdo instanceof PDO)) { $constSets = [['DB_HOST','DB_NAME','DB_USER','DB_PASS'],['DB_HOSTNAME','DB_DATABASE','DB_USERNAME','DB_PASSWORD']]; foreach ($constSets as $cs) { [$H,$N,$U,$P] = $cs; if (defined($H)&&defined($N)&&defined($U)&&defined($P)) { try { $pdo = new PDO( 'mysql:host='.constant($H).';dbname='.constant($N).';charset=utf8mb4', constant($U), constant($P), [ PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE=>PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES=>false, ] ); break; } catch (Throwable $e) { error_log('[yarn_stock] PDO build failed: '.$e->getMessage()); } } } } if (!($pdo instanceof PDO)) { http_response_code(500); exit('DB bootstrap failed.'); } } /* ---- Schema helpers (page-local) ---- */ function table_cols(PDO $pdo, string $t): array { static $cache = []; if (isset($cache[$t])) return $cache[$t]; try { $rows = $pdo->query("DESCRIBE `$t`")->fetchAll(PDO::FETCH_ASSOC); $cache[$t] = array_map(fn($r)=>$r['Field'], $rows); } catch (Throwable $e) { $cache[$t] = []; } return $cache[$t]; } function has_col(PDO $pdo, string $t, string $c): bool { return in_array($c, table_cols($pdo,$t), true); } function table_exists(PDO $pdo, string $t): bool { try { $pdo->query("SELECT 1 FROM `$t` LIMIT 1"); return true; } catch(Throwable $e){ return false; } } /* Resolve company name (prefer header-provided; fallback DB; never show ID) */ function resolve_company_name(PDO $pdo, $u, int $company_id): string { if (isset($GLOBALS['company']['name']) && $GLOBALS['company']['name']) return (string)$GLOBALS['company']['name']; if (is_array($u) && !empty($u['company_name'])) return (string)$u['company_name']; foreach (['companies','company','company_master'] as $tbl) { if (table_exists($pdo, $tbl) && has_col($pdo,$tbl,'name')) { try { $st=$pdo->prepare("SELECT name FROM `$tbl` WHERE id=? LIMIT 1"); $st->execute([$company_id]); if($r=$st->fetch()){ return (string)$r['name']; } } catch(Throwable $e){} } } return 'Company'; } /* Human label mapping for stock types */ function stock_display_label(string $stype): string { $s = ucfirst(strtolower(trim($stype))); switch ($s) { case 'Zari': return 'Metalic Stock Report'; case 'Kasab': return 'Zari Kasab Stock Report'; default: return ($s === 'Yarn') ? 'Yarn Stock Report' : ($s.' Yarn Stock Report'); } } /* Decide which tables to use for a given stock type */ function in_out_tables_for(PDO $pdo, string $stock_type): array { $stock_type = ucfirst(strtolower($stock_type)); $unified = table_exists($pdo,'yarn_in') && has_col($pdo,'yarn_in','stock_type') && table_exists($pdo,'yarn_out') && has_col($pdo,'yarn_out','stock_type'); if ($unified) return ['yarn_in','yarn_out', true]; switch ($stock_type) { case 'Tfo': return ['tfo_in','tfo_out', false]; case 'Tpm': return ['tpm_in','tpm_out', false]; case 'Zari': return ['zari_in','zari_out', false]; case 'Kasab':return ['kasab_in','kasab_out',false]; default: return ['yarn_in','yarn_out', false]; } } /* ---- SORT HELPER (rows array) ---- */ function sort_rows(array $rows, string $key, string $dir = 'desc'): array { $dir = ($dir === 'asc') ? 1 : -1; usort($rows, function ($a, $b) use ($key, $dir) { $va = $a[$key] ?? 0; $vb = $b[$key] ?? 0; if (is_numeric($va) && is_numeric($vb)) { return ($va <=> $vb) * $dir; } return strcmp((string)$va, (string)$vb) * $dir; }); return $rows; } /* ---- Filters (including new ones) ---- */ $flt_type = trim($_GET['yarn_type'] ?? ''); $flt_comp = trim($_GET['company'] ?? ''); $flt_denier = trim($_GET['denier'] ?? ''); $flt_color = trim($_GET['color'] ?? ''); $view = strtolower(trim($_GET['view'] ?? 'single')); // 'single' or 'all' $flt_stock_type = trim($_GET['stock_type'] ?? 'Yarn'); // All, Yarn, TFO, TPM, Zari, Kasab if ($flt_stock_type === '') $flt_stock_type = 'Yarn'; $flt_show_zero = trim($_GET['show_zero'] ?? 'with_zero'); // 'with_zero' | 'without_zero' /* ---- Sorting (DEFAULT = Weight DESC) ---- */ $sort = trim($_GET['sort'] ?? 'cur_weight'); $dir = strtolower(trim($_GET['dir'] ?? 'desc')); if (!in_array($dir, ['asc','desc'], true)) { $dir = 'desc'; } /* ---- Dropdown options from yarn_company_data (Yarn only) ---- */ function fetchDistinct(PDO $pdo, $company_id, $col, $parents=[], $stock_type_filter=null) { $map = ['yarn_type'=>'yarn_types','company'=>'company_name','denier'=>'denier','color'=>'color']; $filters = ['company_id = :cid']; $params = [':cid'=>$company_id]; if ($stock_type_filter && in_array('stock_type', table_cols($pdo,'yarn_company_data'), true)) { if (strtolower($stock_type_filter) !== 'all') { $filters[] = 'TRIM(stock_type) = TRIM(:_st)'; $params[':_st'] = $stock_type_filter; } } foreach (['yarn_type'=>'yt','company'=>'co','denier'=>'de'] as $k => $tag) { if (!empty($parents[$k])) { $filters[]="`{$map[$k]}`= :$k"; $params[":$k"]=$parents[$k]; } } $sql="SELECT DISTINCT `{$map[$col]}` AS v FROM yarn_company_data WHERE ".implode(' AND ', $filters)." ORDER BY v"; $st=$pdo->prepare($sql); $st->execute($params); $out=[]; while($r=$st->fetch()){ if($r['v']!=='') $out[]=$r['v']; } return $out; } $opts_type = fetchDistinct($pdo, $company_id, 'yarn_type', [], ($flt_stock_type?:null)); $opts_comp = fetchDistinct($pdo, $company_id, 'company', ['yarn_type'=>$flt_type], ($flt_stock_type?:null)); $opts_denier = fetchDistinct($pdo, $company_id, 'denier', ['yarn_type'=>$flt_type,'company'=>$flt_comp], ($flt_stock_type?:null)); $opts_color = fetchDistinct($pdo, $company_id, 'color', ['yarn_type'=>$flt_type,'company'=>$flt_comp,'denier'=>$flt_denier], ($flt_stock_type?:null)); /* ---- Aggregator (schema-aware) Supports $stock_type === 'All' to combine results across types, and $hide_zero to exclude rows where both boxes and weight are zero. */ function build_stock(PDO $pdo, int $company_id, array $filters, string $stock_type, bool $hide_zero=false): array { $stock_type = ucfirst(strtolower($stock_type)); $types_to_process = []; if (strtolower($stock_type) === 'all') { $types_to_process = ['Yarn','TFO','TPM','Zari','Kasab']; } else { $types_to_process = [$stock_type]; } $merged_rows = []; $tot_boxes = 0.0; $tot_weight = 0.0; foreach ($types_to_process as $stype) { [$in_tbl, $out_tbl, $use_stock_type] = in_out_tables_for($pdo, $stype); $where_in = ["company_id = :cid_in"]; $params_in = [':cid_in'=>$company_id]; $where_out = ["company_id = :cid_out"]; $params_out = [':cid_out'=>$company_id]; if ($use_stock_type) { $where_in[] = "stock_type = :stype_in"; $where_out[] = "stock_type = :stype_out"; $params_in[':stype_in'] = ucfirst(strtolower($stype)); $params_out[':stype_out'] = ucfirst(strtolower($stype)); } foreach (['yarn_type'=>'yt','company'=>'co','denier'=>'de','color'=>'cl'] as $col => $tag) { if (($filters[$col] ?? '') !== '') { $where_in[] = "$col = :{$tag}_in"; $params_in[":{$tag}_in"] = $filters[$col]; $where_out[] = "$col = :{$tag}_out"; $params_out[":{$tag}_out"] = $filters[$col]; } } $sql = " SELECT i.yarn_type, i.company, i.denier, i.color, i.boxes_in, i.weight_in, COALESCE(o.boxes_out,0) AS boxes_out, COALESCE(o.weight_out,0) AS weight_out FROM (SELECT yarn_type, company, denier, color, SUM(boxes) AS boxes_in, SUM(weight) AS weight_in FROM `$in_tbl` WHERE ".implode(' AND ', $where_in)." GROUP BY yarn_type, company, denier, color) i LEFT JOIN (SELECT yarn_type, company, denier, color, SUM(boxes) AS boxes_out, SUM(weight) AS weight_out FROM `$out_tbl` WHERE ".implode(' AND ', $where_out)." GROUP BY yarn_type, company, denier, color) o ON i.yarn_type=o.yarn_type AND i.company=o.company AND i.denier=o.denier AND i.color=o.color ORDER BY i.yarn_type, i.company, i.denier, i.color "; $st = $pdo->prepare($sql); $st->execute($params_in + $params_out); $rows = $st->fetchAll(); foreach ($rows as $r) { $cur_boxes = max(0,(float)$r['boxes_in'] - (float)$r['boxes_out']); $cur_weight = max(0,(float)$r['weight_in'] - (float)$r['weight_out']); $avg = $cur_boxes>0 ? $cur_weight/$cur_boxes : 0.0; if ($hide_zero && $cur_boxes==0 && $cur_weight==0) { continue; } $status = 'OK'; if($cur_boxes==0 && $cur_weight>0) $status='Check'; if($cur_boxes==0 && $cur_weight==0) $status='Empty'; $merged_rows[] = [ 'stock_type' => $stype, 'yarn_type' => $r['yarn_type'], 'company' => $r['company'], 'denier' => $r['denier'], 'color' => $r['color'], 'cur_boxes' => $cur_boxes, 'cur_weight' => $cur_weight, 'avg_per_box' => $avg, 'status' => $status, '_boxes_in' => (float)$r['boxes_in'], '_weight_in' => (float)$r['weight_in'], '_boxes_out' => (float)$r['boxes_out'], '_weight_out' => (float)$r['weight_out'], ]; $tot_boxes += $cur_boxes; $tot_weight += $cur_weight; } } $tot_avg = $tot_boxes>0 ? $tot_weight/$tot_boxes : 0.0; /* ---- APPLY SORTING (DEFAULT = cur_weight DESC) ---- */ $sortKey = trim($_GET['sort'] ?? 'cur_weight'); $sortDir = strtolower(trim($_GET['dir'] ?? 'desc')); if (!in_array($sortDir, ['asc','desc'], true)) $sortDir = 'desc'; $merged_rows = sort_rows($merged_rows, $sortKey, $sortDir); return ['rows'=>$merged_rows, 'tot_boxes'=>$tot_boxes, 'tot_weight'=>$tot_weight, 'tot_avg'=>$tot_avg]; } /* ---------- CSV export ---------- */ if (isset($_GET['export']) && $_GET['export'] === 'csv') { $today = date('Y-m-d'); $view_q = strtolower(trim($_GET['view'] ?? 'single')); $flt_type = trim($_GET['yarn_type'] ?? ''); $flt_comp = trim($_GET['company'] ?? ''); $flt_denier = trim($_GET['denier'] ?? ''); $flt_color = trim($_GET['color'] ?? ''); $flt_stock_type = trim($_GET['stock_type'] ?? 'Yarn'); $flt_show_zero = trim($_GET['show_zero'] ?? 'with_zero'); $hide_zero = ($flt_show_zero === 'without_zero'); $filename = ($view_q==='all') ? "all_stock_$today.csv" : "yarn_stock_$today.csv"; header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename="'.$filename.'"'); $out = fopen('php://output', 'w'); if ($view_q === 'all') { fputcsv($out, ['Stock Type','Yarn Type','Company','Denier','Color','Current Boxes','Current Weight','AVG/Box','Status']); // build_stock will handle 'All' internally $b = build_stock($pdo, $company_id, ['yarn_type'=>$flt_type,'company'=>$flt_comp,'denier'=>$flt_denier,'color'=>$flt_color], 'All', $hide_zero); foreach ($b['rows'] as $v) { fputcsv($out, [ $v['stock_type'], $v['yarn_type'], $v['company'], $v['denier'], $v['color'], number_format($v['cur_boxes'],3,'.',''), number_format($v['cur_weight'],3,'.',''), number_format($v['avg_per_box'],3,'.',''), $v['status'] ]); } fputcsv($out, ['TOTAL','','','','', number_format($b['tot_boxes'],3,'.',''), number_format($b['tot_weight'],3,'.',''), '', '']); } else { $b = build_stock($pdo, $company_id, ['yarn_type'=>$flt_type,'company'=>$flt_comp,'denier'=>$flt_denier,'color'=>$flt_color], $flt_stock_type, $hide_zero); fputcsv($out, ['Stock Type','Yarn Type','Company','Denier','Color','Current Boxes','Current Weight','AVG/Box','Status']); foreach ($b['rows'] as $v) { fputcsv($out, [ $v['stock_type'], $v['yarn_type'], $v['company'], $v['denier'], $v['color'], number_format($v['cur_boxes'],3,'.',''), number_format($v['cur_weight'],3,'.',''), number_format($v['avg_per_box'],3,'.',''), $v['status'] ]); } fputcsv($out, ['TOTAL','','','','', number_format($b['tot_boxes'],3,'.',''), number_format($b['tot_weight'],3,'.',''), '', '']); } fclose($out); exit; } /* ---------- PDF export (respect filters, render per-type headings/separators) ---------- */ if (isset($_GET['export']) && $_GET['export'] === 'pdf') { $companyName = resolve_company_name($pdo, $u, $company_id); $todayHuman = date('d M Y'); $flt_stock_type = trim($_GET['stock_type'] ?? 'All'); if ($flt_stock_type === '') $flt_stock_type = 'All'; $flt_show_zero = trim($_GET['show_zero'] ?? 'with_zero'); $hide_zero = ($flt_show_zero === 'without_zero'); ob_start(); ?> <!doctype html> <html><head><meta charset="utf-8"> <style> body{font-family:DejaVu Sans,Arial,Helvetica,sans-serif;font-size:12px;color:#202124;margin:18px} table{width:100%;border-collapse:collapse;margin-top:8px} th,td{border:1px solid #ddd;padding:6px 8px;text-align:left} th{background:#f6f8fa} .center{text-align:center} .right{text-align:right} h1,h2{margin:0;padding:0} .meta{margin:8px 0 18px;color:#444} .section-title{font-size:16px;text-align:center;margin:18px 0 8px;padding-top:8px;border-top:2px solid #444} hr.section-sep{border:0;border-top:2px solid #ccc;margin:18px 0} </style> </head><body> <h1 class="center"><?=htmlspecialchars($companyName)?> Stock Report</h1> <div class="meta center">Date: <?=htmlspecialchars($todayHuman)?> | Stock Type: <?=htmlspecialchars($flt_stock_type)?> | Show Zero: <?=htmlspecialchars($flt_show_zero)?></div> <?php $types = (strtolower($flt_stock_type) === 'all') ? ['Yarn','TFO','TPM','Zari','Kasab'] : [ $flt_stock_type ]; foreach ($types as $stype): $b_section = build_stock($pdo, $company_id, ['yarn_type'=>trim($_GET['yarn_type'] ?? ''),'company'=>trim($_GET['company'] ?? ''),'denier'=>trim($_GET['denier'] ?? ''),'color'=>trim($_GET['color'] ?? '')], $stype, $hide_zero); $label = stock_display_label($stype); ?> <h2 class="section-title"><?=htmlspecialchars($label)?></h2> <div style="text-align:center;margin-bottom:6px">Total Boxes: <b><?=number_format($b_section['tot_boxes'],3)?></b> Total Weight (kg): <b><?=number_format($b_section['tot_weight'],3)?></b></div> <table> <thead><tr> <th>Yarn Type</th><th>Company</th><th>Denier</th><th>Color</th> <th class="right">Boxes</th><th class="right">Weight (kg)</th><th class="right">AVG/Box</th><th>Status</th> </tr></thead> <tbody> <?php if (empty($b_section['rows'])): ?> <tr><td colspan="8" class="center">No data for <?=htmlspecialchars($stype)?></td></tr> <?php else: foreach($b_section['rows'] as $v): ?> <tr> <td><?=htmlspecialchars($v['yarn_type'])?></td> <td><?=htmlspecialchars($v['company'])?></td> <td><?=htmlspecialchars($v['denier'])?></td> <td><?=htmlspecialchars($v['color'])?></td> <td class="right"><?=number_format($v['cur_boxes'],3)?></td> <td class="right"><?=number_format($v['cur_weight'],3)?></td> <td class="right"><?=number_format($v['avg_per_box'],3)?></td> <td><?=htmlspecialchars($v['status'])?></td> </tr> <?php endforeach; endif; ?> </tbody> </table> <?php if (strtolower($flt_stock_type) === 'all'): ?> <hr class="section-sep"> <?php endif; ?> <?php endforeach; ?> <div style="margin-top:12px;text-align:center">Generated on <?=htmlspecialchars($todayHuman)?></div> </body></html> <?php $html = ob_get_clean(); // Try dompdf if available, else render HTML $dompdf_ok = false; foreach (['/vendor/autoload.php','/lib/dompdf/autoload.inc.php'] as $rel) { $p = __DIR__.$rel; if (is_file($p)) { require_once $p; $dompdf_ok = true; break; } } if (class_exists('\\Dompdf\\Dompdf')) $dompdf_ok = true; if ($dompdf_ok) { $dompdf = new \Dompdf\Dompdf(['isRemoteEnabled'=>true,'isHtml5ParserEnabled'=>true]); $dompdf->loadHtml($html); $dompdf->setPaper('A4','portrait'); $dompdf->render(); $dompdf->stream('stock-report-'.date('Y-m-d').'.pdf', ['Attachment'=>true]); exit; } else { header('Content-Type: text/html; charset=utf-8'); echo $html; exit; } } /* ---- Page heading dates ---- */ $todayPrint = date('d M Y'); $companyName = resolve_company_name($pdo, $u, $company_id); /* ---- Render page (print-only will skip header/footer) ---- */ ?><!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Yarn Stock Report</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <?php if (!$print_only): ?> <link rel="stylesheet" href="/erp/public/assets/css/main.css?v=<?=date('Ymd')?>"> <?php else: ?> <style> /* minimal print styles for print-only window */ body{font-family:Arial,Helvetica,sans-serif;font-size:12px;color:#202124;margin:18px} table{width:100%;border-collapse:collapse;margin-top:8px} th,td{border:1px solid #ddd;padding:6px 8px;text-align:left} th{background:#f6f8fa} .center{text-align:center} .right{text-align:right} </style> <?php endif; ?> </head> <body> <?php if ($USE_HEADER) { $header_path = __DIR__ . '/partials/header.php'; if (file_exists($header_path)) include $header_path; } ?> <div class="wrap" style="max-width:1100px;margin:18px auto;padding:12px"> <div class="card"> <div style="display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap"> <h2 style="margin:0">Yarn Stock Reports</h2> <div> <a class="btn" href="?<?=http_build_query(array_merge($_GET,['view'=>'single','print'=>0]))?>">Single View</a> <a class="btn" href="?<?=http_build_query(array_merge($_GET,['view'=>'all','print'=>0]))?>">All Reports</a> </div> </div> <!-- FILTERS --> <form method="get" id="fltForm" style="margin-top:12px;display:flex;gap:10px;flex-wrap:wrap;align-items:center"> <input type="hidden" name="view" value="<?=htmlspecialchars($view)?>"> <label>Stock Type <select name="stock_type" onchange="this.form.submit()"> <?php foreach(['All','Yarn','TFO','TPM','Zari','Kasab'] as $s): $sel = ($s===$flt_stock_type)?'selected':''; ?> <option <?=$sel?>><?=htmlspecialchars($s)?></option> <?php endforeach; ?> </select> </label> <label>Yarn Type <select name="yarn_type" onchange="this.form.submit()"> <option value="">— All —</option> <?php foreach($opts_type as $v){ $sel=($v===$flt_type)?'selected':''; echo "<option value=\"".htmlspecialchars($v)."\" $sel>".htmlspecialchars($v)."</option>"; } ?> </select> </label> <label>Company <select name="company" onchange="this.form.submit()"> <option value="">— All —</option> <?php foreach($opts_comp as $v){ $sel=($v===$flt_comp)?'selected':''; echo "<option value=\"".htmlspecialchars($v)."\" $sel>".htmlspecialchars($v)."</option>"; } ?> </select> </label> <label>Denier <select name="denier" onchange="this.form.submit()"> <option value="">— All —</option> <?php foreach($opts_denier as $v){ $sel=($v===$flt_denier)?'selected':''; echo "<option value=\"".htmlspecialchars($v)."\" $sel>".htmlspecialchars($v)."</option>"; } ?> </select> </label> <label>Color <select name="color" onchange="this.form.submit()"> <option value="">— All —</option> <?php foreach($opts_color as $v){ $sel=($v===$flt_color)?'selected':''; echo "<option value=\"".htmlspecialchars($v)."\" $sel>".htmlspecialchars($v)."</option>"; } ?> </select> </label> <label>Show Zero <select name="show_zero" onchange="this.form.submit()"> <option value="with_zero" <?=($flt_show_zero==='with_zero')?'selected':''?>>With Zero</option> <option value="without_zero" <?=($flt_show_zero==='without_zero')?'selected':''?>>Without Zero</option> </select> </label> <div style="display:flex;gap:8px;align-items:center"> <button class="btn primary" type="submit">Apply</button> <a class="btn ghost" href="?<?=http_build_query(array_merge($_GET,['export'=>'csv']))?>">Export CSV</a> <a class="btn" href="?<?=http_build_query(array_merge($_GET,['export'=>'pdf']))?>" target="_blank">Export PDF</a> <a class="btn" href="?<?=http_build_query(array_merge($_GET,['print'=>1]))?>" target="_blank">Print (clean)</a> </div> </form> <?php $hide_zero = ($flt_show_zero === 'without_zero'); ?> <div style="margin-top:14px"> <div><strong><?=htmlspecialchars($companyName)?> </strong>Stock Report (<?=htmlspecialchars($todayPrint)?>)</div> </div> <!-- TABLES per stock type (if All) --> <?php $types = (strtolower($flt_stock_type) === 'all') ? ['Yarn','TFO','TPM','Zari','Kasab'] : [ $flt_stock_type ]; foreach ($types as $stype): $b_section = build_stock($pdo, $company_id, ['yarn_type'=>$flt_type,'company'=>$flt_comp,'denier'=>$flt_denier,'color'=>$flt_color], $stype, $hide_zero); $label = stock_display_label($stype); ?> <div style="margin-top:18px"> <h3 style="margin:0;padding:8px 0;border-top:2px solid #ddd;text-align:center;"><?=htmlspecialchars($label)?></h3> <div style="margin:6px 0">Total Boxes: <b><?=number_format($b_section['tot_boxes'],3)?></b> Total Weight (kg): <b><?=number_format($b_section['tot_weight'],3)?></b></div> </div> <table class="stock-table" style="margin-top:6px"> <thead> <tr> <th>Yarn Type</th><th>Company</th><th>Denier</th><th>Color</th> <th style="text-align:right">Boxes</th><th style="text-align:right">Weight (kg)</th><th style="text-align:right">AVG/Box</th><th>Status</th> </tr> </thead> <tbody> <?php if(empty($b_section['rows'])): ?> <tr><td colspan="8" style="color:#777">No data for <?=htmlspecialchars($stype)?></td></tr> <?php else: foreach($b_section['rows'] as $v): $pillClass='pill ok'; if($v['status']==='Check') $pillClass='pill warn'; if($v['status']==='Empty') $pillClass='pill bad'; ?> <tr data-boxes-in="<?=htmlspecialchars($v['_boxes_in'])?>" data-weight-in="<?=htmlspecialchars($v['_weight_in'])?>" data-boxes-out="<?=htmlspecialchars($v['_boxes_out'])?>" data-weight-out="<?=htmlspecialchars($v['_weight_out'])?>"> <td><?=htmlspecialchars($v['yarn_type'])?></td> <td><?=htmlspecialchars($v['company'])?></td> <td><?=htmlspecialchars($v['denier'])?></td> <td><?=htmlspecialchars($v['color'])?></td> <td style="text-align:right"><?=number_format($v['cur_boxes'],3)?></td> <td style="text-align:right"><?=number_format($v['cur_weight'],3)?></td> <td style="text-align:right"><?=number_format($v['avg_per_box'],3)?></td> <td><span class="<?= $pillClass ?>"><?=htmlspecialchars($v['status'])?></span></td> </tr> <?php endforeach; endif; ?> </tbody> </table> <?php if (strtolower($flt_stock_type) === 'all'): ?> <div style="height:18px;border-bottom:2px solid #eee;margin:18px 0"></div> <?php endif; ?> <?php endforeach; ?> </div> </div> <?php if ($USE_HEADER) { $footer_path = __DIR__ . '/partials/footer.php'; if (file_exists($footer_path)) include $footer_path; } ?> </body> </html>