<!doctype html>
<html lang="ar" dir="rtl" data-theme="dim">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>المشتريات</title>

  <style>
  :root{ /* default = dim */
    --bg:#121826;
    --surface:#101827;
    --card:#151e30;
    --card2:#0f1a33;

    --text:#e5e7eb;
    --muted:#9ca3af;

    --border:rgba(255,255,255,.10);
    --border2:rgba(255,255,255,.14);
    --shadow:0 18px 40px rgba(0,0,0,.22);

    --primary:#6366f1;
    --primary2:#4f46e5;
    --success:#22c55e;
    --warning:#f59e0b;
    --danger:#ef4444;

    --input:#0b1327;
    --inputBorder:rgba(255,255,255,.12);
    --inputFocus:rgba(99,102,241,.35);

    --tableHead:rgba(255,255,255,.05);
    --rowHover:rgba(99,102,241,.08);
  }

  html[data-theme="dark"]{
    --bg:#070b14;
    --surface:#0b1220;
    --card:#0f172a;
    --card2:#0b1327;
  }

  html[data-theme="light"]{
    --bg:#ffffff;
    --surface:#ffffff;
    --card:#ffffff;
    --card2:#ffffff;

    --text:#111827;
    --muted:#6b7280;

    --border:rgba(17,24,39,.10);
    --border2:rgba(17,24,39,.14);
    --shadow:0 12px 28px rgba(0,0,0,.10);

    --primary:#111827;
    --primary2:#111827;

    --success:#16a34a;
    --warning:#d97706;
    --danger:#dc2626;

    --input:#ffffff;
    --inputBorder:rgba(17,24,39,.14);
    --inputFocus:rgba(17,24,39,.12);

    --tableHead:rgba(17,24,39,.03);
    --rowHover:rgba(17,24,39,.03);
  }

  *{box-sizing:border-box}

  body{
    font-family:Arial, sans-serif;
    margin:0;
    background:var(--bg);
    color:var(--text);
    padding:22px;
  }

  html[data-theme="dim"] body,
  html[data-theme="dark"] body{
    background:linear-gradient(180deg, var(--bg), var(--bg));
  }

  .container{max-width:1200px;margin:0 auto}

  /* Header */
  .pageHeader{
    background:linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.02));
    border:1px solid var(--border);
    border-radius:18px;
    box-shadow:var(--shadow);
    padding:16px 16px 12px;
    margin-bottom:14px;
  }
  html[data-theme="light"] .pageHeader{
    background:#ffffff;
    border-color:rgba(17,24,39,.10);
    box-shadow:0 12px 28px rgba(0,0,0,.08);
  }

  .headerTop{
    display:flex;align-items:flex-start;justify-content:space-between;gap:12px;flex-wrap:wrap
  }
  .title{font-weight:900;font-size:18px;letter-spacing:.2px}
  .subtitle{color:var(--muted);font-size:13px;margin-top:6px;line-height:1.6}

  .navRow{
    display:flex;gap:8px;flex-wrap:nowrap;overflow:auto;max-width:100%;
    padding-top:10px;padding-bottom:6px;-webkit-overflow-scrolling:touch;align-items:center
  }
  .navRow > *{flex:0 0 auto; white-space:nowrap;}

  /* Buttons */
  .btn{
    padding:10px 12px;border-radius:12px;border:1px solid transparent;
    cursor:pointer;font-weight:900;font-size:13px;line-height:1;
    display:inline-flex;align-items:center;gap:8px;text-decoration:none;
    transition:transform .05s ease, opacity .15s ease, border-color .15s ease;
    user-select:none;
  }
  .btn:active{transform:translateY(1px)}

  .btnPrimary{
    background:linear-gradient(180deg, var(--primary), var(--primary2));
    color:#fff;border-color:rgba(255,255,255,.10)
  }
  html[data-theme="light"] .btnPrimary{
    background:#111827; color:#fff; border-color:rgba(17,24,39,.12);
  }

  .btnGhost{
    background:rgba(255,255,255,.03);
    color:var(--text);
    border-color:var(--border2)
  }
  html[data-theme="light"] .btnGhost{
    background:#ffffff;
    border-color:rgba(17,24,39,.12);
  }
  .btnGhost:hover{border-color:rgba(255,255,255,.18)}
  html[data-theme="light"] .btnGhost:hover{border-color:rgba(17,24,39,.20)}

  .btnDanger{
    background:rgba(239,68,68,.14);
    color:#fff;border-color:rgba(239,68,68,.35)
  }
  html[data-theme="light"] .btnDanger{
    background:#ffffff;
    color:#dc2626;
    border-color:rgba(220,38,38,.25);
  }
  .btnDanger:hover{opacity:.95}

  .activeTab{
    background:rgba(99,102,241,.20);
    border-color:rgba(99,102,241,.55);
    color:#fff;
  }
  html[data-theme="light"] .activeTab{
    background:rgba(17,24,39,.05);
    border-color:rgba(17,24,39,.18);
    color:#111827;
  }

  /* Cards */
  .card{
    background:linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,.02));
    border:1px solid var(--border);
    border-radius:18px;
    box-shadow:var(--shadow);
    padding:16px;
    margin-bottom:14px;
  }
  html[data-theme="light"] .card{
    background:#ffffff;
    border-color:rgba(17,24,39,.10);
    box-shadow:0 12px 28px rgba(0,0,0,.08);
  }

  /* Alerts */
  .alert{padding:12px;border-radius:14px;border:1px solid;font-weight:900;margin-bottom:14px}
  .alert.ok{background:rgba(34,197,94,.14);border-color:rgba(34,197,94,.35);color:var(--text)}
  .alert.err{background:rgba(239,68,68,.14);border-color:rgba(239,68,68,.35);color:var(--text)}
  html[data-theme="light"] .alert.ok{background:#ecfdf3;border-color:#bbf7d0;color:#166534}
  html[data-theme="light"] .alert.err{background:#fef2f2;border-color:#fecaca;color:#991b1b}

  /* Forms */
  label{display:block;font-size:12px;color:var(--muted);font-weight:900;margin-bottom:6px}
  input,select{
    width:100%;
    padding:11px 12px;
    border:1px solid var(--inputBorder);
    border-radius:12px;
    outline:none;
    font-size:14px;
    background:var(--input);
    color:var(--text);
  }
  input:focus,select:focus{
    border-color:rgba(99,102,241,.55);
    box-shadow:0 0 0 3px var(--inputFocus);
  }
  html[data-theme="light"] input:focus,
  html[data-theme="light"] select:focus{
    border-color:rgba(17,24,39,.22);
    box-shadow:0 0 0 3px rgba(17,24,39,.08);
  }

  .grid{
    display:grid;
    grid-template-columns: 1fr 1fr 1fr 1fr 0.7fr;
    gap:12px;
    align-items:end;
  }
  @media (max-width: 980px){
    body{padding:16px}
    .grid{grid-template-columns: 1fr 1fr;}
  }
  @media (max-width: 560px){ .grid{grid-template-columns: 1fr;} }

  .hr{height:1px;background:var(--border);margin:14px 0}

  .kpiGrid{display:grid;grid-template-columns: repeat(4, 1fr);gap:10px;margin-top:12px}
  @media (max-width: 980px){ .kpiGrid{grid-template-columns: repeat(2, 1fr);} }
  @media (max-width: 560px){ .kpiGrid{grid-template-columns: 1fr;} }

  .kpi{
    border:1px solid var(--border);
    border-radius:16px;
    padding:14px;
    background:rgba(255,255,255,.02);
  }
  html[data-theme="light"] .kpi{
    background:#ffffff;
    border-color:rgba(17,24,39,.10);
  }
  .kpi .t{color:var(--muted);font-size:12px;font-weight:900}
  .kpi .v{margin-top:8px;font-size:16px;font-weight:900}

  .lineGrid{
    display:grid;
    grid-template-columns: 1.6fr 0.5fr 0.6fr auto;
    gap:10px;
    align-items:end;
    margin-top:10px;
  }
  @media (max-width: 980px){ .lineGrid{grid-template-columns: 1fr 1fr;} }
  @media (max-width: 560px){ .lineGrid{grid-template-columns: 1fr;} }

  .small{color:var(--muted);font-size:12px;font-weight:800}

  /* Table */
  .tableWrap{
    overflow:auto;
    border-radius:14px;
    border:1px solid var(--border);
    background:rgba(0,0,0,.10);
    margin-top:12px;
  }
  html[data-theme="light"] .tableWrap{
    background:#ffffff;
    border-color:rgba(17,24,39,.10);
  }

  table{
    width:100%;
    border-collapse:separate;
    border-spacing:0;
    min-width:1050px;
  }
  thead th{
    position:sticky;top:0;z-index:2;
    background:var(--tableHead);
    border-bottom:1px solid var(--border);
    padding:12px 12px;
    font-weight:900;
    font-size:13px;
    white-space:nowrap;
    text-align:right;
  }
  tbody td{
    padding:12px 12px;
    border-bottom:1px solid rgba(255,255,255,.06);
    font-size:13px;
    vertical-align:middle;
  }
  html[data-theme="light"] tbody td{
    border-bottom:1px solid rgba(17,24,39,.08);
  }
  tbody tr:hover td{background:var(--rowHover)}
  .num{font-weight:900}

  .rowActions{display:flex;gap:8px;flex-wrap:wrap;justify-content:flex-end;margin-top:12px}

  .miniDanger{
    background:rgba(239,68,68,.14);color:#fff;border:1px solid rgba(239,68,68,.35);
    padding:8px 10px;border-radius:12px;cursor:pointer;font-weight:900;font-size:12px;
  }
  html[data-theme="light"] .miniDanger{
    background:#ffffff;color:#dc2626;border-color:rgba(220,38,38,.25);
  }
</style>


  <!-- ✅ Apply saved theme ASAP (avoid flash) -->
  <script>
    (function(){
      const themes = ["light","dim","dark"];
      const key = "ui_theme";
      const saved = localStorage.getItem(key);
      const t = (saved && themes.includes(saved)) ? saved : "dim";
      document.documentElement.setAttribute("data-theme", t);
    })();
  </script>
</head>

<body>
<div class="container">


  <div class="pageHeader">
    <div class="headerTop">
      <div>
        <div class="title">المشتريات</div>
        <div class="subtitle">فاتورة واحدة = عدة أصناف</div>
      </div>

      <div class="navRow">
        <a class="btn btnPrimary" href="{{ route('dashboard') }}">الرئيسية</a>

        <a class="btn btnGhost" href="{{ route('dashboard.sales') }}">المبيعات</a>
        <a class="btn btnGhost activeTab" href="{{ route('purchases.index') }}">المشتريات</a>
        <a class="btn btnGhost" href="{{ route('expenses.index') }}">المصروفات</a>

        <a class="btn btnGhost" href="{{ route('dashboard.reports') }}">التقارير</a>
        <a class="btn btnGhost" href="{{ route('settings.index') }}">الإعدادات</a>

        @if(auth()->check() && (auth()->user()->role ?? 'user') === 'admin')
          <a class="btn btnGhost" href="{{ route('branches.index') }}">إدارة الفروع</a>
          <a class="btn btnGhost" href="{{ route('users.index') }}">إدارة المستخدمين</a>
        @endif

        <button class="btn btnGhost" type="button" id="themeBtn">🎨 المظهر</button>

        <form method="POST" action="{{ route('logout') }}" style="display:inline">
          @csrf
          <button class="btn btnDanger" type="submit">خروج</button>
        </form>
      </div>
    </div>
  </div>

  <div class="card">
    <div class="navRow">
      <a class="btn btnGhost activeTab" href="{{ route('purchases.index', ['branch_id' => $branchId]) }}">إضافة فاتورة</a>
      <a class="btn btnGhost" href="{{ route('purchases.invoices', ['branch_id' => $branchId]) }}">فواتير المشتريات</a>
    </div>
  </div>

  @if(session('ok'))    <div class="alert ok">{{ session('ok') }}</div> @endif
  @if(session('error')) <div class="alert err">{{ session('error') }}</div> @endif
  @if($errors->any())   <div class="alert err">{{ $errors->first() }}</div> @endif

  <div class="card">
    <div style="font-weight:900;margin-bottom:10px">بيانات الفاتورة</div>

    <form method="POST" action="{{ route('purchases.store') }}" id="purchaseForm">
      @csrf

      <div class="grid">
        <div>
          <label>الفرع</label>
          <select name="branch_id" id="branch_id" required>
            <option value="">اختر</option>
            @foreach($branches as $b)
              <option value="{{ $b->id }}" @selected((int)old('branch_id', $branchId) === (int)$b->id)>
                {{ $b->branch_no }} - {{ $b->name }}
              </option>
            @endforeach
          </select>
        </div>

        <div>
          <label>المورد</label>
          <select name="supplier_id" id="supplier_id" required>
            <option value="">اختر</option>
            @foreach($suppliers as $s)
              <option value="{{ $s->id }}" @selected((int)old('supplier_id') === (int)$s->id)>
                {{ $s->name }}
              </option>
            @endforeach
          </select>
        </div>

        <div>
          <label>رقم فاتورة المورد (إجباري)</label>
          <input type="text" name="supplier_bill_no" id="supplier_bill_no" value="{{ old('supplier_bill_no') }}" required>
        </div>

        <div>
          <label>تاريخ فاتورة المورد</label>
          <input type="date" name="bill_date" id="bill_date" value="{{ old('bill_date') }}">
        </div>

        <div>
          <label>الضريبة %</label>
          <input type="number" step="0.01" name="vat_rate" id="vat_rate" value="{{ old('vat_rate', 15) }}" required>
        </div>
      </div>

      <div class="kpiGrid">
        <div class="kpi"><div class="t">عدد الأصناف</div><div class="v"><span id="kpi_items_count">0</span></div></div>
        <div class="kpi"><div class="t">الإجمالي قبل الضريبة</div><div class="v"><span id="kpi_subtotal">0.00</span></div></div>
        <div class="kpi"><div class="t">قيمة الضريبة</div><div class="v"><span id="kpi_vat">0.00</span></div></div>
        <div class="kpi"><div class="t">الإجمالي شامل</div><div class="v"><span id="kpi_total">0.00</span></div></div>
      </div>

      <div class="hr"></div>

      <div style="display:flex;justify-content:space-between;align-items:center;gap:10px;flex-wrap:wrap">
        <div style="font-weight:900;">إضافة صنف للفاتورة</div>
        <div class="small">السعر المدخل: شامل الضريبة</div>
      </div>

      <div class="lineGrid">
        <div>
          <label>الصنف</label>
          <select id="line_item_id">
            <option value="">اختر</option>
            @foreach($items as $it)
              <option value="{{ $it->id }}" data-default-gross="{{ (float)($it->default_price_gross ?? 0) }}">
                {{ $it->name }}
              </option>
            @endforeach
          </select>
        </div>

        <div>
          <label>الكمية</label>
          <input type="number" step="0.01" min="0.01" id="line_qty" value="1">
        </div>

        <div>
          <label>سعر شامل الضريبة</label>
          <input type="number" step="0.01" min="0" id="line_price_gross">
        </div>

        <div style="display:flex;gap:8px;flex-wrap:wrap;justify-content:flex-end">
          <button class="btn btnGhost" type="button" id="addLineBtn">إضافة</button>
          <button class="btn btnGhost" type="button" id="clearLinesBtn">مسح الأصناف</button>
        </div>
      </div>

      <div class="tableWrap">
        <table id="itemsTable">
          <thead>
            <tr>
              <th>#</th>
              <th>الصنف</th>
              <th>الكمية</th>
              <th>سعر شامل</th>
              <th>قبل الضريبة</th>
              <th>الضريبة</th>
              <th>الإجمالي</th>
              <th>حذف</th>
            </tr>
          </thead>
          <tbody id="itemsTbody">
            <tr id="emptyRow">
              <td colspan="8" style="text-align:center;color:var(--muted);font-weight:900;padding:16px">
                لم يتم إضافة أصناف بعد
              </td>
            </tr>
          </tbody>
        </table>
      </div>

      <!-- ✅ رسالة التحقق (تظهر فقط عند محاولة الحفظ بدون أصناف) -->
      <div id="formMsg" class="alert err" style="display:none">أضف صنف واحد على الأقل</div>

      <div class="rowActions">
        <button class="btn btnPrimary" type="submit">حفظ كامل الفاتورة</button>
      </div>

      <div class="small" style="margin-top:10px">أضف صنف واحد على الأقل</div>
    </form>
  </div>

</div>

<script>
/* ===== Theme Toggle (مثل المبيعات) ===== */
(function(){
  const themes = ["light","dim","dark"];
  const key = "ui_theme";
  const html = document.documentElement;
  const btn = document.getElementById("themeBtn");

  function label(t){
    if(t === "light") return "☀️ فاتح";
    if(t === "dark") return "🌙 داكن";
    return "🌗 مريح";
  }

  function apply(t){
    html.setAttribute("data-theme", t);
    localStorage.setItem(key, t);
    if(btn) btn.textContent = "🎨 " + label(t);
  }

  const saved = localStorage.getItem(key);
  const t = (saved && themes.includes(saved)) ? saved : (html.getAttribute("data-theme") || "dim");
  apply(t);

  if(btn){
    btn.addEventListener("click", function(){
      const cur = html.getAttribute("data-theme") || "dim";
      const idx = themes.indexOf(cur);
      const next = themes[(idx + 1) % themes.length];
      apply(next);
    });
  }
})();

/* ===== Purchases Logic (كما هو) ===== */
(function(){
  const form = document.getElementById('purchaseForm');
  const tbody = document.getElementById('itemsTbody');
  const vatRateEl = document.getElementById('vat_rate');

  const lineItemEl = document.getElementById('line_item_id');
  const lineQtyEl = document.getElementById('line_qty');
  const linePriceEl = document.getElementById('line_price_gross');

  const addLineBtn = document.getElementById('addLineBtn');
  const clearLinesBtn = document.getElementById('clearLinesBtn');

  const kpiCount = document.getElementById('kpi_items_count');
  const kpiSubtotal = document.getElementById('kpi_subtotal');
  const kpiVat = document.getElementById('kpi_vat');
  const kpiTotal = document.getElementById('kpi_total');

  const formMsg = document.getElementById('formMsg');

  let idx = 0;

  function num(v){ v = parseFloat(v); return isNaN(v) ? 0 : v; }
  function round2(v){ return Math.round((v + Number.EPSILON) * 100) / 100; }
  function fmt(v){ return round2(v).toFixed(2); }
  function vatDiv(){ const r = num(vatRateEl.value); return 1 + (r / 100); }

  function computeLine(qty, priceGross){
    const div = vatDiv();
    const lineTotal = qty * priceGross;
    const lineSub = div > 0 ? (lineTotal / div) : lineTotal;
    const lineVat = lineTotal - lineSub;
    return { sub: round2(lineSub), vat: round2(lineVat), total: round2(lineTotal) };
  }

  function renumber(){
    const rows = tbody.querySelectorAll('tr[data-row="1"]');
    rows.forEach((tr, i) => tr.querySelector('.cell-no').textContent = String(i+1));
  }

  function recalcAll(){
    let count=0, subtotal=0, vat=0, total=0;
    const rows = tbody.querySelectorAll('tr[data-row="1"]');
    rows.forEach(tr=>{
      count++;
      subtotal += num(tr.querySelector('.cell-sub').textContent);
      vat      += num(tr.querySelector('.cell-vat').textContent);
      total    += num(tr.querySelector('.cell-total').textContent);
    });
    kpiCount.textContent = String(count);
    kpiSubtotal.textContent = fmt(subtotal);
    kpiVat.textContent = fmt(vat);
    kpiTotal.textContent = fmt(total);
  }

  function hasLines(){
    return tbody.querySelectorAll('tr[data-row="1"]').length > 0;
  }

  function showMsg(){
    if (!formMsg) return;
    formMsg.textContent = 'أضف صنف واحد على الأقل';
    formMsg.style.display = 'block';
    formMsg.scrollIntoView({ behavior: 'smooth', block: 'start' });
  }

  function hideMsg(){
    if (!formMsg) return;
    formMsg.style.display = 'none';
  }

  function addLine(){
    const itemId = lineItemEl.value;
    const opt = lineItemEl.options[lineItemEl.selectedIndex];
    const itemName = opt ? opt.text : '';

    const qty = num(lineQtyEl.value);
    const priceGross = num(linePriceEl.value);

    if (!itemId) { alert('اختر الصنف'); return; }
    if (qty <= 0) { alert('الكمية غير صحيحة'); return; }
    if (priceGross < 0) { alert('السعر غير صحيح'); return; }

    hideMsg();

    const emptyRow = document.getElementById('emptyRow');
    if (emptyRow) emptyRow.remove();

    const c = computeLine(qty, priceGross);
    const tr = document.createElement('tr');
    tr.dataset.row = '1';

    tr.innerHTML = `
      <td class="num cell-no">0</td>
      <td style="font-weight:900">
        ${escapeHtml(itemName)}
        <input type="hidden" name="items[${idx}][item_id]" value="${escapeAttr(itemId)}">
      </td>
      <td><input type="number" step="0.01" min="0.01" name="items[${idx}][qty]" value="${fmt(qty)}" class="qtyInput" style="width:120px"></td>
      <td><input type="number" step="0.01" min="0" name="items[${idx}][price_gross]" value="${fmt(priceGross)}" class="priceInput" style="width:140px"></td>
      <td class="num cell-sub">${fmt(c.sub)}</td>
      <td class="num cell-vat">${fmt(c.vat)}</td>
      <td class="num cell-total">${fmt(c.total)}</td>
      <td><button type="button" class="miniDanger">حذف</button></td>
    `;

    tr.querySelector('.miniDanger').addEventListener('click', ()=>{
      tr.remove();
      if (tbody.querySelectorAll('tr[data-row="1"]').length === 0) {
        tbody.innerHTML = `<tr id="emptyRow"><td colspan="8" style="text-align:center;color:var(--muted);font-weight:900;padding:16px">لم يتم إضافة أصناف بعد</td></tr>`;
        idx = 0;
      }
      renumber();
      recalcAll();
    });

    const qtyInput = tr.querySelector('.qtyInput');
    const priceInput = tr.querySelector('.priceInput');

    function recalcRow(){
      const q = num(qtyInput.value);
      const p = num(priceInput.value);
      const cc = computeLine(q, p);
      tr.querySelector('.cell-sub').textContent = fmt(cc.sub);
      tr.querySelector('.cell-vat').textContent = fmt(cc.vat);
      tr.querySelector('.cell-total').textContent = fmt(cc.total);
      recalcAll();
    }
    qtyInput.addEventListener('input', recalcRow);
    priceInput.addEventListener('input', recalcRow);

    tbody.appendChild(tr);
    idx++;
    renumber();
    recalcAll();

    lineItemEl.value = '';
    lineQtyEl.value = '1';
    linePriceEl.value = '';
  }

  lineItemEl.addEventListener('change', ()=>{
    const opt = lineItemEl.options[lineItemEl.selectedIndex];
    const def = opt ? num(opt.getAttribute('data-default-gross')) : 0;
    if (def > 0 && (linePriceEl.value === '' || num(linePriceEl.value) === 0)) {
      linePriceEl.value = def.toFixed(2);
    }
  });

  addLineBtn.addEventListener('click', addLine);

  clearLinesBtn.addEventListener('click', ()=>{
    if (!confirm('مسح كل الأصناف من الفاتورة؟')) return;
    tbody.innerHTML = `<tr id="emptyRow"><td colspan="8" style="text-align:center;color:var(--muted);font-weight:900;padding:16px">لم يتم إضافة أصناف بعد</td></tr>`;
    idx = 0;
    recalcAll();
  });

  vatRateEl.addEventListener('input', ()=>{
    const rows = tbody.querySelectorAll('tr[data-row="1"]');
    rows.forEach(tr=>{
      const q = num(tr.querySelector('.qtyInput').value);
      const p = num(tr.querySelector('.priceInput').value);
      const cc = computeLine(q, p);
      tr.querySelector('.cell-sub').textContent = fmt(cc.sub);
      tr.querySelector('.cell-vat').textContent = fmt(cc.vat);
      tr.querySelector('.cell-total').textContent = fmt(cc.total);
    });
    recalcAll();
  });

  form.addEventListener('submit', function(e){
    if (!hasLines()){
      e.preventDefault();
      showMsg();
    } else {
      hideMsg();
    }
  });

  function escapeHtml(str){
    return String(str ?? '')
      .replaceAll('&','&amp;')
      .replaceAll('<','&lt;')
      .replaceAll('>','&gt;')
      .replaceAll('"','&quot;')
      .replaceAll("'","&#039;");
  }
  function escapeAttr(str){ return escapeHtml(str).replaceAll('`','&#096;'); }

  recalcAll();
})();
</script>

</body>
</html>
