« Back to History
entry_name_change.php
|
20261119_140743.php
Initial Domain Snapshot
Copy Code
<?php /* File: /erp/entry_name_change.php Title: Entry — Change Karigar (line-level + karigar-summary + bulk reassign) Updated: 2025-12-09 */ header('X-Frame-Options: SAMEORIGIN'); error_reporting(E_ALL); ini_set('display_errors','0'); if (isset($_GET['debug']) && $_GET['debug']=='1') ini_set('display_errors','1'); require __DIR__ . '/modules/auth/auth.php'; require_login(); $u = auth_user(); $COMPANY_ID = (int)($u['company_id'] ?? 0); $USER_ID = (int)($u['id'] ?? 0); function jexit($arr,$code=200){ if (!headers_sent()){ header('Content-Type: application/json; charset=utf-8'); http_response_code($code); } echo json_encode($arr, JSON_UNESCAPED_UNICODE); exit; } $pdo = $GLOBALS['pdo'] ?? null; if (!$pdo) { require __DIR__ . '/core/db.php'; } $pdo = $GLOBALS['pdo'] ?? null; if (!$pdo) jexit(['ok'=>false,'msg'=>'DB connect fail'],500); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $ENTRY_TABLE = 'production_entry'; /* ---------- helpers ---------- */ function month_period_to_range($month,$period){ $parts = explode('-',$month); if(count($parts)!=2) return null; $y=intval($parts[0]); $m=intval($parts[1]); if($m<1||$m>12) return null; if($period==='H1'){ $from = sprintf('%04d-%02d-01',$y,$m); $to = sprintf('%04d-%02d-15',$y,$m); } else { $from = sprintf('%04d-%02d-16',$y,$m); $dim = (int)date('t', strtotime("$y-$m-01")); $to = sprintf('%04d-%02d-%02d',$y,$m,$dim); } return [$from,$to]; } function fetch_khata_by_code($pdo,$company_id,$code){ $st=$pdo->prepare("SELECT id,code,machine_from,machine_to FROM khatas WHERE company_id=? AND code=? AND is_active=1 LIMIT 1"); $st->execute([$company_id,trim($code)]); return $st->fetch(PDO::FETCH_ASSOC); } function fetch_all_karigars_in_khata($pdo,$company_id,$khata_id){ $st=$pdo->prepare("SELECT id,karigar_name FROM loom_karigar_master WHERE company_id=? AND khata_id=? AND is_active=1 ORDER BY karigar_name"); $st->execute([$company_id,$khata_id]); return $st->fetchAll(PDO::FETCH_ASSOC); } /* ---------- AJAX router ---------- */ $act = $_GET['act'] ?? ''; if($act){ try{ switch($act){ case 'khata_list': { $st=$pdo->prepare("SELECT id,code,machine_from,machine_to FROM khatas WHERE company_id=? AND is_active=1 ORDER BY code"); $st->execute([$COMPANY_ID]); $rows=$st->fetchAll(PDO::FETCH_ASSOC); jexit(['ok'=>true,'khatas'=>$rows]); } case 'khata_karigars': { $kcode = trim($_GET['khata'] ?? ''); if(!$kcode) jexit(['ok'=>false,'msg'=>'Missing khata'],400); $kh = fetch_khata_by_code($pdo,$COMPANY_ID,$kcode); if(!$kh) jexit(['ok'=>false,'msg'=>'Khata not found'],404); $rows = fetch_all_karigars_in_khata($pdo,$COMPANY_ID,$kh['id']); jexit(['ok'=>true,'karigars'=>$rows,'khata'=>$kh]); } case 'fetch_entries': { $kcode = trim($_GET['khata'] ?? ''); $machine = (int)($_GET['machine'] ?? 0); $month = trim($_GET['month'] ?? ''); $period = trim($_GET['period'] ?? 'H1'); if(!$kcode || !$machine || !$month) jexit(['ok'=>false,'msg'=>'Missing params'],400); $kh = fetch_khata_by_code($pdo,$COMPANY_ID,$kcode); if(!$kh) jexit(['ok'=>false,'msg'=>'Khata not found'],404); $rng = month_period_to_range($month,$period); if(!$rng) jexit(['ok'=>false,'msg'=>'Invalid month/period'],400); list($from,$to) = $rng; $q = $pdo->prepare("SELECT id,taka_no,entry_date,machine_id,lines_json,quality_id,meter_total FROM {$ENTRY_TABLE} WHERE company_id=? AND khata_id=? AND machine_id=? AND entry_date BETWEEN ? AND ? ORDER BY entry_date ASC, id ASC"); $q->execute([$COMPANY_ID,(int)$kh['id'],$machine,$from,$to]); $rows = $q->fetchAll(PDO::FETCH_ASSOC); foreach($rows as &$r){ $r['lines'] = json_decode($r['lines_json'] ?? '[]', true); if(!is_array($r['lines'])) $r['lines'] = []; } jexit(['ok'=>true,'from'=>$from,'to'=>$to,'entries'=>$rows]); } case 'fetch_karigar_summary': { // aggregate per karigar totals for the selection $kcode = trim($_GET['khata'] ?? ''); $machine = (int)($_GET['machine'] ?? 0); $month = trim($_GET['month'] ?? ''); $period = trim($_GET['period'] ?? 'H1'); if(!$kcode || !$machine || !$month) jexit(['ok'=>false,'msg'=>'Missing params'],400); $kh = fetch_khata_by_code($pdo,$COMPANY_ID,$kcode); if(!$kh) jexit(['ok'=>false,'msg'=>'Khata not found'],404); $rng = month_period_to_range($month,$period); if(!$rng) jexit(['ok'=>false,'msg'=>'Invalid month/period'],400); list($from,$to) = $rng; $q = $pdo->prepare("SELECT id,lines_json FROM {$ENTRY_TABLE} WHERE company_id=? AND khata_id=? AND machine_id=? AND entry_date BETWEEN ? AND ?"); $q->execute([$COMPANY_ID,(int)$kh['id'],$machine,$from,$to]); $rows = $q->fetchAll(PDO::FETCH_ASSOC); $agg = []; foreach($rows as $r){ $lines = json_decode($r['lines_json'] ?? '[]', true); if(!is_array($lines)) continue; foreach($lines as $idx=>$ln){ $kid = (int)($ln['karigar_id'] ?? 0); $m = floatval($ln['meter'] ?? 0); if($kid<=0) continue; if(!isset($agg[$kid])) $agg[$kid] = ['karigar_id'=>$kid,'meter_total'=>0,'lines'=>[]]; $agg[$kid]['meter_total'] += $m; $agg[$kid]['lines'][] = ['entry_id'=>(int)$r['id'],'line_index'=>$idx,'meter'=>$m]; } } // fetch karigar names $kar_ids = array_keys($agg); $kar_map = []; if($kar_ids){ $place = implode(',', array_fill(0, count($kar_ids), '?')); $st = $pdo->prepare("SELECT id,karigar_name FROM loom_karigar_master WHERE company_id=? AND id IN ($place)"); $params = array_merge([$COMPANY_ID], $kar_ids); $st->execute($params); while($r=$st->fetch(PDO::FETCH_ASSOC)) $kar_map[(int)$r['id']] = $r['karigar_name']; } $out = []; foreach($agg as $kid=>$v){ $out[] = ['karigar_id'=>$kid,'karigar_name'=>($kar_map[$kid] ?? "K#{$kid}"),'meter_total'=>round($v['meter_total'],2),'lines'=>$v['lines'],'count_lines'=>count($v['lines'])]; } // sort by meter desc usort($out, function($a,$b){ return $b['meter_total'] <=> $a['meter_total']; }); jexit(['ok'=>true,'from'=>$from,'to'=>$to,'summary'=>$out]); } case 'preview_reassign_from': { // preview count for reassign all lines of source karigar to target for selected range (server-side safety) $in = json_decode(file_get_contents('php://input'), true); if(!$in || !isset($in['khata']) || !isset($in['machine']) || !isset($in['month']) || !isset($in['period']) || !isset($in['source_karigar']) || !isset($in['target_karigar'])) jexit(['ok'=>false,'msg'=>'Bad JSON'],400); $kcode = trim($in['khata']); $machine=(int)$in['machine']; $month=trim($in['month']); $period=trim($in['period']); $source=(int)$in['source_karigar']; $target=(int)$in['target_karigar']; if(!$kcode||!$machine||!$month||$source<=0||$target<=0) jexit(['ok'=>false,'msg'=>'Missing params'],400); $kh = fetch_khata_by_code($pdo,$COMPANY_ID,$kcode); if(!$kh) jexit(['ok'=>false,'msg'=>'Khata not found'],404); $rng = month_period_to_range($month,$period); if(!$rng) jexit(['ok'=>false,'msg'=>'Invalid month/period'],400); list($from,$to) = $rng; $q = $pdo->prepare("SELECT id,lines_json FROM {$ENTRY_TABLE} WHERE company_id=? AND khata_id=? AND machine_id=? AND entry_date BETWEEN ? AND ?"); $q->execute([$COMPANY_ID,(int)$kh['id'],$machine,$from,$to]); $rows = $q->fetchAll(PDO::FETCH_ASSOC); $cnt_lines=0; $cnt_entries=0; foreach($rows as $r){ $lines = json_decode($r['lines_json'] ?? '[]', true); if(!is_array($lines)) continue; $changed_in_entry = 0; foreach($lines as $ln) if(((int)($ln['karigar_id'] ?? 0)) === $source) { $cnt_lines++; $changed_in_entry++; } if($changed_in_entry) $cnt_entries++; } jexit(['ok'=>true,'preview'=>['entries'=>$cnt_entries,'lines'=>$cnt_lines,'from'=>$from,'to'=>$to]]); } case 'apply_reassign_from': { // change all lines with karigar_id = source -> target within selected range (khata,machine,month,period) $in = json_decode(file_get_contents('php://input'), true); if(!$in || !isset($in['khata']) || !isset($in['machine']) || !isset($in['month']) || !isset($in['period']) || !isset($in['source_karigar']) || !isset($in['target_karigar'])) jexit(['ok'=>false,'msg'=>'Bad JSON'],400); $kcode = trim($in['khata']); $machine=(int)$in['machine']; $month=trim($in['month']); $period=trim($in['period']); $source=(int)$in['source_karigar']; $target=(int)$in['target_karigar']; $note = trim($in['note'] ?? ''); if(!$kcode||!$machine||!$month||$source<=0||$target<=0) jexit(['ok'=>false,'msg'=>'Missing params'],400); $kh = fetch_khata_by_code($pdo,$COMPANY_ID,$kcode); if(!$kh) jexit(['ok'=>false,'msg'=>'Khata not found'],404); $rng = month_period_to_range($month,$period); if(!$rng) jexit(['ok'=>false,'msg'=>'Invalid month/period'],400); list($from,$to) = $rng; try{ $pdo->beginTransaction(); // get target name $s = $pdo->prepare("SELECT karigar_name FROM loom_karigar_master WHERE company_id=? AND id=? LIMIT 1"); $s->execute([$COMPANY_ID,$target]); $tr = $s->fetch(PDO::FETCH_ASSOC); $target_name = $tr? $tr['karigar_name'] : null; // lock relevant entries $sel = $pdo->prepare("SELECT id,lines_json FROM {$ENTRY_TABLE} WHERE company_id=? AND khata_id=? AND machine_id=? AND entry_date BETWEEN ? AND ? FOR UPDATE"); $sel->execute([$COMPANY_ID,(int)$kh['id'],$machine,$from,$to]); $rows = $sel->fetchAll(PDO::FETCH_ASSOC); if(!$rows){ $pdo->rollBack(); jexit(['ok'=>false,'msg'=>'No entries found'],404); } $total_changed = 0; $updated = []; foreach($rows as $r){ $eid = (int)$r['id']; $orig = json_decode($r['lines_json'] ?? '[]', true); if(!is_array($orig)) $orig = []; $changed=0; foreach($orig as $i=>&$ln){ if(((int)($ln['karigar_id'] ?? 0)) === $source){ $ln['karigar_id'] = $target; $changed++; } } unset($ln); if($changed>0){ $newjson = json_encode($orig, JSON_UNESCAPED_UNICODE); $upst = $pdo->prepare("UPDATE {$ENTRY_TABLE} SET lines_json=?, updated_at=NOW() WHERE id=? AND company_id=?"); $upst->execute([$newjson,$eid,$COMPANY_ID]); $total_changed += $changed; $updated[] = ['entry_id'=>$eid,'changed_lines'=>$changed]; // audit (best-effort) try{ $aud = $pdo->prepare("INSERT INTO production_entry_reassigns (company_id,entry_id,changed_count,source_karigar_id,target_karigar_id,target_karigar_name,changed_by,changed_at,note) VALUES (?,?,?,?,?,?,?,NOW(),?)"); $aud->execute([$COMPANY_ID,$eid,$changed,$source,$target,$target_name,$USER_ID,$note]); }catch(Throwable $ae){ error_log("entry_name_change: audit insert failed: ".$ae->getMessage()); } } } $pdo->commit(); jexit(['ok'=>true,'total_changed'=>$total_changed,'updated'=>$updated]); }catch(Throwable $e){ $pdo->rollBack(); jexit(['ok'=>false,'msg'=>'Reassign failed','detail'=>$e->getMessage()],500); } } default: jexit(['ok'=>false,'msg'=>'Unknown act'],404); } }catch(Throwable $e){ if(isset($_GET['debug']) && $_GET['debug']=='1') jexit(['ok'=>false,'msg'=>'Server error','detail'=>$e->getMessage()],500); jexit(['ok'=>false,'msg'=>'Server error'],500); } } /* ---------- frontend include (robust) ---------- */ $__header_paths = [ __DIR__ . '/partials/header.php', __DIR__ . '/erp/partials/header.php', __DIR__ . '/../erp/partials/header.php', __DIR__ . '/../../erp/partials/header.php', $_SERVER['DOCUMENT_ROOT'] . '/erp/partials/header.php', ]; $__header_included = false; foreach ($__header_paths as $__hp) { if ($__hp && file_exists($__hp)) { require_once $__hp; $__header_included=true; break; } } if (! $__header_included) { echo "<div style=\"padding:8px;background:#fff4e5;border:1px solid #ffddb5;margin:8px;border-radius:6px;color:#92400e;font-size:13px\">Header not found. Check ERP partials path.</div>\n"; } ?><!doctype html> <html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>Entry — Change Karigar (bulk & line)</title> <style> body{font-family:Inter,system-ui,Arial;margin:12px;background:#f8fafc;color:#0f172a} .container{width:98%;max-width:none;margin:6px auto;padding:14px} .card{background:#fff;padding:16px;border:1px solid #e6e9ee;border-radius:10px} .row{display:flex;gap:12px;align-items:end;flex-wrap:wrap} .input,select,button{padding:8px 10px;border-radius:8px;border:1px solid #e2e8f0;font-size:14px;background:#fff} .btn{background:#1f6feb;color:#fff;border:none;padding:8px 12px;border-radius:8px;cursor:pointer} .btn.ghost{background:#fff;color:#111;border:1px solid #e2e8f0} .flex{display:flex;gap:12px;align-items:center} .karigarBox{display:flex;gap:12px;flex-wrap:wrap;margin-top:12px} .kbox{min-width:220px;border:1px solid #eef2f5;padding:10px;border-radius:10px;background:#fff} .kbox .h{font-weight:800;margin-bottom:6px} .kbox .muted{font-size:13px;color:#6b7280} .placeholder{color:#6b7280;padding:12px} </style> </head><body> <div class="container"> <div class="card"> <h3 style="margin:0 0 10px 0">Change Karigar (summary & bulk reassign)</h3> <div class="row"> <div style="min-width:260px"><label>Khata</label><br><select id="khata" class="input full"><option>Loading…</option></select></div> <div><label>Machine</label><br><select id="machine" class="input small"><option value="">—</option></select></div> <div><label>Month</label><br><input id="month" class="input small" type="month" /></div> <div><label>Period</label><br><select id="period" class="input small"><option value="H1">H1</option><option value="H2">H2</option></select></div> <div style="display:flex;gap:6px;align-items:center"> <button id="btnLoad" class="btn">Load →</button> <button id="btnClear" class="btn ghost">Clear</button> </div> </div> <div style="margin-top:8px;color:#6b7280">Load summary to see karigar-wise totals. Use "Reassign" to move all lines of that karigar (for the selected machine & range) to another karigar.</div> <div id="summaryWrap" style="margin-top:12px"></div> <hr style="margin-top:12px"> <div><strong>Existing per-line editor</strong> — expanded view for fine-grained edits:</div> <div id="entriesWrap" style="margin-top:12px"></div> <!-- actions appear in each block --> </div> </div> <script> const $ = id => document.getElementById(id); async function fetchJSON(url,opt){ const resp = await fetch(url,opt); const text = await resp.text(); const ctype = (resp.headers.get('content-type')||'').toLowerCase(); if(ctype.indexOf('application/json') === -1){ const preview = text.slice(0,800).toLowerCase(); if(preview.indexOf('<form')!==-1) throw new Error('Session expired'); throw new Error('Invalid server response (not JSON)'); } const j = JSON.parse(text); if(!j.ok) throw new Error(j.msg || 'server returned ok=false'); return j; } async function loadInit(){ const kh = $('khata'); kh.innerHTML = '<option>Loading…</option>'; try{ const j = await fetchJSON('?act=khata_list'); kh.innerHTML = '<option value="">Select Khata</option>'; for(const k of j.khatas){ const o=document.createElement('option'); o.value=k.code; o.dataset.from=k.machine_from; o.dataset.to=k.machine_to; o.textContent=k.code + (k.machine_from && k.machine_to ? ` — ${k.machine_from}-${k.machine_to}` : ''); kh.appendChild(o); } }catch(e){ kh.innerHTML = '<option value="">(failed)</option>'; console.error(e); } } loadInit(); $('khata').addEventListener('change', (e)=>{ const opt = e.target.selectedOptions[0]; const ms = $('machine'); ms.innerHTML = '<option value="">—</option>'; if(!opt) return; const from = parseInt(opt.dataset.from||0)||0, to = parseInt(opt.dataset.to||0)||0; if(from && to && to>=from){ for(let i=from;i<=to;i++){ const o=document.createElement('option'); o.value=i; o.textContent=i; ms.appendChild(o); } } }); $('btnLoad').addEventListener('click', async ()=>{ const kh = $('khata').value.trim(), m = parseInt($('machine').value||0), mo = $('month').value, per = $('period').value; if(!kh||!m||!mo) return alert('Select khata, machine and month'); const wrap = $('summaryWrap'); wrap.innerHTML = '<div class="placeholder">Loading summary…</div>'; try{ const j = await fetchJSON(`?act=fetch_karigar_summary&khata=${encodeURIComponent(kh)}&machine=${m}&month=${encodeURIComponent(mo)}&period=${encodeURIComponent(per)}`); renderKarigarSummary(j.summary, kh, m, mo, per); // also load expanded per-line view const je = await fetchJSON(`?act=fetch_entries&khata=${encodeURIComponent(kh)}&machine=${m}&month=${encodeURIComponent(mo)}&period=${encodeURIComponent(per)}`); renderEntriesExpanded(je.entries); }catch(err){ wrap.innerHTML = `<div class="placeholder" style="color:#b91c1c">Error: ${err.message}</div>`; } }); function renderKarigarSummary(summary, kh, machine, month, period){ const wrap = $('summaryWrap'); wrap.innerHTML = ''; if(!summary || !summary.length){ wrap.innerHTML = '<div class="placeholder">No karigar data for selection.</div>'; return; } const box = document.createElement('div'); box.className='karigarBox'; summary.forEach(k=>{ const kb = document.createElement('div'); kb.className='kbox'; kb.innerHTML = `<div class="h">${escapeHtml(k.karigar_name)} <span style="font-weight:600;color:#0f172a">(${k.karigar_id})</span></div> <div class="muted">${k.count_lines} lines · ${k.meter_total} mtr</div> <div style="margin-top:8px"><button class="btn reassignBtn" data-kid="${k.karigar_id}">Reassign</button></div>`; // attach lines data on dataset for quick preview (not full details) kb.dataset.lines = JSON.stringify(k.lines || []); kb.dataset.kname = k.karigar_name; box.appendChild(kb); }); wrap.appendChild(box); // attach handlers document.querySelectorAll('.reassignBtn').forEach(btn=>{ btn.onclick = async (ev)=>{ const src = Number(btn.dataset.kid); // fetch karigars list to pick target try{ const khval = kh; const kar = await fetchJSON(`?act=khata_karigars&khata=${encodeURIComponent(khval)}`); // build simple modal-like prompt using select const targets = kar.karigars.filter(x=>Number(x.id)!==src); if(!targets.length) return alert('No target karigar available in this khata'); // create small chooser UI const sel = document.createElement('select'); sel.style.minWidth='220px'; targets.forEach(t=>{ const o=document.createElement('option'); o.value=t.id; o.textContent=t.karigar_name + ' ('+t.id+')'; sel.appendChild(o); }); const wrapper = document.createElement('div'); wrapper.style.padding='12px'; wrapper.innerHTML = `<div style="margin-bottom:8px">Reassign all lines of <strong>${escapeHtml(btn.parentElement.parentElement.dataset.kname || btn.dataset.kid)}</strong> to:</div>`; wrapper.appendChild(sel); const note = document.createElement('input'); note.placeholder='Optional note'; note.className='input'; note.style.display='block'; note.style.marginTop='8px'; wrapper.appendChild(note); const ok = document.createElement('button'); ok.className='btn'; ok.textContent='Preview'; const cancel = document.createElement('button'); cancel.className='btn ghost'; cancel.textContent='Cancel'; cancel.style.marginLeft='8px'; wrapper.appendChild(document.createElement('div')).style.marginTop='8px'; wrapper.appendChild(ok); wrapper.appendChild(cancel); // show small modal const modal = showInlineModal(wrapper); cancel.onclick = ()=>{ modal.remove(); }; ok.onclick = async ()=>{ const target = Number(sel.value); if(!target) return alert('Select target karigar'); // preview try{ ok.disabled = true; ok.textContent = 'Previewing…'; const resp = await fetch('?act=preview_reassign_from', { method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify({ khata: kh, machine: machine, month: month, period: period, source_karigar: src, target_karigar: target }) }); const pj = await resp.json(); if(!pj.ok) throw new Error(pj.msg||'Server error'); if(!confirm(`Preview: ${pj.preview.entries} entries affected, ${pj.preview.lines} lines will change. Proceed to apply?`)) { ok.disabled=false; ok.textContent='Preview'; return; } // apply ok.textContent = 'Applying…'; const ar = await fetch('?act=apply_reassign_from', { method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify({ khata: kh, machine: machine, month: month, period: period, source_karigar: src, target_karigar: target, note: note.value||'' }) }); const aj = await ar.json(); if(!aj.ok) throw new Error(aj.msg||'Server error'); alert('Reassign done. Total changed lines: ' + aj.total_changed); modal.remove(); // reload page summary & entries document.getElementById('btnLoad').click(); }catch(err){ alert('Failed: '+(err.message||err)); ok.disabled=false; ok.textContent='Preview'; } }; }catch(err){ alert('Failed to load karigars: '+err.message); } }; }); } /* existing expanded per-line rendering (same as previous version) */ function renderEntriesExpanded(entries){ const wrap = $('entriesWrap'); wrap.innerHTML = ''; if(!entries || entries.length===0){ wrap.innerHTML = '<div class="placeholder">No entries</div>'; return; } const container = document.createElement('div'); container.style.display='flex'; container.style.gap='12px'; container.style.flexWrap='wrap'; entries.forEach(entry=>{ const card = document.createElement('div'); card.style.minWidth='260px'; card.style.border='1px solid #eef2f5'; card.style.padding='10px'; card.style.borderRadius='8px'; card.style.background='#fff'; card.innerHTML = `<div style="font-weight:700">Entry #${entry.id} — Taka ${entry.taka_no}</div><div style="color:#6b7280">${entry.entry_date} · ${entry.meter_total} mtr</div>`; if(!entry.lines || !entry.lines.length){ card.appendChild(Object.assign(document.createElement('div'),{className:'placeholder',textContent:'No lines'})); } else { entry.lines.forEach((ln, idx)=>{ const row = document.createElement('div'); row.style.display='flex'; row.style.justifyContent='space-between'; row.style.alignItems='center'; row.style.padding='8px 0'; row.style.borderTop='1px solid #f1f5f9'; const left = document.createElement('div'); left.innerHTML = `<div style="font-weight:700">${ln.karigar_id||0}</div><div style="font-size:13px;color:#374151">${ln.date||entry.entry_date} · ${Number(ln.meter||0)}</div>`; const right = document.createElement('div'); right.style.display='flex'; right.style.gap='8px'; const cb = document.createElement('input'); cb.type='checkbox'; cb.className='lineSel'; cb.dataset.entry=entry.id; cb.dataset.idx=idx; cb.dataset.old=ln.karigar_id || 0; right.appendChild(cb); row.appendChild(left); row.appendChild(right); card.appendChild(row); }); } container.appendChild(card); }); wrap.appendChild(container); } /* small inline modal helper */ function showInlineModal(contentEl){ const overlay = document.createElement('div'); overlay.style.position='fixed'; overlay.style.left=0; overlay.style.top=0; overlay.style.right=0; overlay.style.bottom=0; overlay.style.background='rgba(10,10,10,0.3)'; overlay.style.display='flex'; overlay.style.alignItems='center'; overlay.style.justifyContent='center'; overlay.style.zIndex=9999; const panel = document.createElement('div'); panel.style.background='#fff'; panel.style.padding='14px'; panel.style.borderRadius='8px'; panel.style.minWidth='320px'; panel.style.maxWidth='90%'; panel.appendChild(contentEl); overlay.appendChild(panel); document.body.appendChild(overlay); overlay.remove = function(){ try{ document.body.removeChild(overlay); }catch(e){} }; return overlay; } function escapeHtml(s){ return String(s).replace(/[&<>"']/g, function(m){ return ({'&':'&','<':'<','>':'>','"':'"',"'":'''})[m]; }); } $('btnClear').addEventListener('click', ()=>{ $('khata').value=''; $('machine').innerHTML='<option value="">—</option>'; $('month').value=''; $('summaryWrap').innerHTML=''; $('entriesWrap').innerHTML=''; }); </script> </body></html> <?php /* footer include fallback */ $__footer_paths = [ __DIR__ . '/partials/footer.php', __DIR__ . '/erp/partials/footer.php', __DIR__ . '/../erp/partials/footer.php', __DIR__ . '/../../erp/partials/footer.php', $_SERVER['DOCUMENT_ROOT'] . '/erp/partials/footer.php', ]; foreach ($__footer_paths as $__fp) { if ($__fp && file_exists($__fp)) { require_once $__fp; break; } } ?>