<!doctype html>
<html lang="ar" dir="rtl">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>تفاصيل الفرع</title>
  <style>
    :root{
      --bg:#f6f7fb;
      --card:#ffffff;
      --text:#111827;
      --muted:#6b7280;
      --border:#e5e7eb;
      --shadow:0 10px 25px rgba(0,0,0,.06);
      --btn:#111827;
      --btnText:#ffffff;
      --btn2Bg:#ffffff;
      --btn2Text:#111827;
      --btn2Border:#d1d5db;

      --primary:#2563eb;
      --primaryText:#ffffff;

      --danger:#dc2626;
      --dangerText:#ffffff;
    }
    *{box-sizing:border-box}
    body{font-family:Arial, sans-serif;margin:32px;background:var(--bg);color:var(--text)}
    .container{max-width:1200px;margin:0 auto}

    .bar{display:flex;justify-content:space-between;align-items:flex-start;gap:12px;margin-bottom:16px;flex-wrap:wrap}
    .title{font-weight:900;font-size:18px}
    .subtitle{color:var(--muted);font-size:13px;margin-top:4px}

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

    .btn{
      padding:10px 12px;border-radius:12px;background:var(--btn);color:var(--btnText);
      border:0;cursor:pointer;font-weight:900;font-size:13px;line-height:1;
    }
    .btn2{
      padding:10px 12px;border-radius:12px;background:var(--btn2Bg);color:var(--btn2Text);
      border:1px solid var(--btn2Border);cursor:pointer;text-decoration:none;
      font-weight:900;font-size:13px;line-height:1;display:inline-flex;align-items:center;gap:8px;
    }
    .active{background:#111827;color:#fff;border-color:#111827}
    .btn:hover{opacity:.95}

    .btnHome{
      padding:10px 12px;border-radius:12px;background:var(--primary);color:var(--primaryText);
      border:1px solid rgba(0,0,0,.08);cursor:pointer;text-decoration:none;
      font-weight:900;font-size:13px;line-height:1;display:inline-flex;align-items:center;gap:8px;
    }
    .btnLogout{
      padding:10px 12px;border-radius:12px;background:var(--danger);color:var(--dangerText);
      border:0;cursor:pointer;font-weight:900;font-size:13px;line-height:1;
    }

    .card{
      background:var(--card);border:1px solid var(--border);border-radius:14px;
      box-shadow:var(--shadow);padding:16px;margin-bottom:14px;
    }

    /* KPI */
    .kpiHead{display:flex;justify-content:space-between;align-items:flex-end;gap:10px;flex-wrap:wrap;margin-bottom:10px}
    .kpiHead .h{font-weight:900}
    .kpiHead .hint{color:var(--muted);font-size:12px;font-weight:800}

    .kpiGrid{
      display:grid;
      grid-template-columns: repeat(4, 1fr);
      gap:12px;
    }
    @media (max-width: 1100px){ .kpiGrid{grid-template-columns: repeat(3, 1fr);} }
    @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:14px;
      padding:14px;
      background:#fff;
    }
    .kpi .t{color:var(--muted);font-size:12px;font-weight:900}
    .kpi .v{margin-top:8px;font-size:18px;font-weight:900}

    /* Filters */
    .grid{
      display:grid;
      grid-template-columns: 1fr 0.7fr 0.7fr auto;
      gap:12px;
      align-items:end;
    }
    @media (max-width: 980px){ .grid{grid-template-columns: 1fr 1fr;} }
    @media (max-width: 560px){ .grid{grid-template-columns: 1fr;} }

    label{display:block;font-size:12px;color:var(--muted);font-weight:900;margin-bottom:6px}
    input{
      width:100%;
      padding:11px 12px;
      border:1px solid var(--border);
      border-radius:12px;
      outline:none;
      font-size:14px;
      background:#fff;
    }
    input:focus{border-color:#9ca3af;box-shadow:0 0 0 3px rgba(156,163,175,.22)}

    .tableWrap{overflow:auto;border-radius:12px;border:1px solid var(--border)}
    table{width:100%;border-collapse:collapse;min-width:980px;background:#fff}
    th,td{padding:12px;border-bottom:1px solid var(--border);text-align:right;vertical-align:middle}
    th{background:#f9fafb;font-weight:900;font-size:15px;white-space:nowrap}
    td{font-size:13px}
    .num{font-weight:900}
  </style>
</head>
<body>
<div class="container">

  <!-- ✅ شريط علوي موحد مثل باقي الصفحات -->
  <div class="bar">
    <div>
      <div class="title">تفاصيل الفرع: <?php echo e($branch->branch_no); ?> - <?php echo e($branch->name); ?></div>
      <div class="subtitle">مبيعات + ضريبة + آخر الفواتير</div>
    </div>

    <div class="navRow">
      <a class="btnHome" href="<?php echo e(route('dashboard.sales')); ?>">الرئيسية</a>

      <a class="btn2 active" href="<?php echo e(route('dashboard.sales')); ?>">المبيعات</a>
      <a class="btn2" href="<?php echo e(route('purchases.index')); ?>">المشتريات</a>
      <a class="btn2" href="<?php echo e(route('expenses.index')); ?>">المصروفات</a>
      <a class="btn2" href="<?php echo e(route('dashboard.reports')); ?>">التقارير</a>
      <a class="btn2" href="<?php echo e(route('settings.index')); ?>">الإعدادات</a>

      <?php if(auth()->check() && (auth()->user()->role ?? 'user') === 'admin'): ?>
        <a class="btn2" href="<?php echo e(route('branches.index')); ?>">إدارة الفروع</a>
        <a class="btn2" href="<?php echo e(route('users.index')); ?>">إدارة المستخدمين</a>
      <?php endif; ?>

      <form method="POST" action="<?php echo e(route('logout')); ?>" style="display:inline">
        <?php echo csrf_field(); ?>
        <button class="btnLogout" type="submit">خروج</button>
      </form>
    </div>
  </div>

  
  <div class="card">
    <div class="kpiHead">
      <div class="h">ملخص الفرع</div>
      <div class="hint">
        الفتره المحددة تتأثر بـ (من/إلى). اليوم/الشهر/الإجمالي ثابتة.
      </div>
    </div>

    <div class="kpiGrid">
      <div class="kpi"><div class="t">مبيعات اليوم</div><div class="v"><?php echo e(number_format($totalToday,2)); ?></div></div>
      <div class="kpi"><div class="t">ضريبة اليوم</div><div class="v"><?php echo e(number_format($totalTodayTax,2)); ?></div></div>

      <div class="kpi"><div class="t">مبيعات الشهر</div><div class="v"><?php echo e(number_format($totalMonth,2)); ?></div></div>
      <div class="kpi"><div class="t">ضريبة الشهر</div><div class="v"><?php echo e(number_format($totalMonthTax,2)); ?></div></div>

      <div class="kpi"><div class="t">مبيعات الفترة</div><div class="v"><?php echo e(number_format($totalRange,2)); ?></div></div>
      <div class="kpi"><div class="t">ضريبة الفترة</div><div class="v"><?php echo e(number_format($totalRangeTax,2)); ?></div></div>

      <div class="kpi"><div class="t">الإجمالي الكلي</div><div class="v"><?php echo e(number_format($totalAll,2)); ?></div></div>
      <div class="kpi"><div class="t">ضريبة الإجمالي</div><div class="v"><?php echo e(number_format($totalAllTax,2)); ?></div></div>
    </div>
  </div>

  
  <div class="card">
    <form method="GET" action="<?php echo e(route('dashboard.branch.details', ['branchId'=>$branchId])); ?>">
      <div class="grid">
        <div>
          <label>بحث برقم الفاتورة</label>
          <input type="text" name="q" value="<?php echo e($q); ?>" placeholder="مثال: 1002">
        </div>
        <div>
          <label>من تاريخ</label>
          <input type="date" name="from" value="<?php echo e($from); ?>">
        </div>
        <div>
          <label>إلى تاريخ</label>
          <input type="date" name="to" value="<?php echo e($to); ?>">
        </div>
        <div style="display:flex;gap:8px;flex-wrap:wrap;justify-content:flex-end">
          <button class="btn" type="submit">تطبيق</button>
          <a class="btn2" href="<?php echo e(route('dashboard.branch.details', ['branchId'=>$branchId])); ?>">مسح</a>
        </div>
      </div>
    </form>
  </div>

  
  <div class="card">
    <div style="font-weight:900;margin-bottom:10px">آخر 200 فاتورة</div>

    <div class="tableWrap">
      <table>
        <thead>
          <tr>
            <th>ID</th>
            <th>رقم الفاتورة</th>
            <th>تاريخ الفاتورة</th>
            <th>الإجمالي</th>
            <th>طريقة الدفع</th>
            <th>الموظف</th>
          </tr>
        </thead>
        <tbody>
          <?php $__currentLoopData = $invoices; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $inv): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <tr>
              <td><?php echo e($inv->id); ?></td>
              <td class="num"><?php echo e($inv->bill_no); ?></td>
              <td><?php echo e(\Carbon\Carbon::parse($inv->bill_date)->format('Y-m-d H:i')); ?></td>
              <td class="num"><?php echo e(number_format($inv->grand_total,2)); ?></td>
              <td><?php echo e($inv->payment_mode ?? '-'); ?></td>
              <td><?php echo e($inv->operator ?? '-'); ?></td>
            </tr>
          <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </tbody>
      </table>
    </div>

  </div>

</div>
</body>
</html>
<?php /**PATH /home/ksaad26/laravel/laundry-dashboard/resources/views/branch_details.blade.php ENDPATH**/ ?>