<div class="content-wrapper android-finance-daily"><main class="afdc-main">
  <header class="afdc-head"><div><span>Daily Cashboxes</span><h1>الأرصدة اليومية</h1><p>الرقم النهائي لكل نسخة أو لجميع الصناديق.</p></div><i class="fa fa-archive"></i></header>
  <nav class="afdc-nav"><a href="finance_reports.php"><i class="fa fa-pie-chart"></i><span>الملخص</span></a><a class="is-active" href="finance_daily_balances.php"><i class="fa fa-archive"></i><span>الصناديق</span></a><a href="finance_payments.php"><i class="fa fa-exchange"></i><span>الحركة</span></a></nav>
  <?php if($msg): ?><div class="afdc-note"><?= h($msg) ?></div><?php endif; ?>
  <form class="afdc-filter" method="get" data-ua-android-native-layout><label><span>اليوم</span><input type="date" name="day" value="<?= h($day) ?>"></label><label><span>الصندوق</span><select name="account"><option value="all">جميع النسخ</option><?php foreach($allRows as $row): ?><option value="<?= h($row['account_key']) ?>" <?= $selected===$row['account_key']?'selected':'' ?>><?= h($row['account_name']) ?></option><?php endforeach; ?></select></label><button><i class="fa fa-search"></i> عرض</button></form>
  <section class="afdc-total"><span><?= $selected==='all'?'الرقم النهائي للجميع':'الرقم النهائي للصندوق' ?></span><strong dir="ltr"><?= number_format($totals['final'],2) ?></strong><div><b>المقبوضات <?= number_format($totals['income'],2) ?></b><b>المصروفات <?= number_format($totals['expenses'],2) ?></b><b>الصافي <?= number_format($totals['net'],2) ?></b></div></section>
  <section class="afdc-list"><?php foreach($rows as $row): ?><article><header><div><small><?= h($typeLabels[$row['account_type']] ?? $row['account_type']) ?></small><h2><?= h($row['account_name']) ?></h2></div><span class="<?= $row['closed']?'is-closed':'is-live' ?>"><?= $row['closed']?'مغلق':'مباشر' ?></span></header><strong dir="ltr"><?= number_format($row['final'],2) ?></strong><div><span>البداية<b><?= number_format($row['opening'],2) ?></b></span><span>المقبوضات<b><?= number_format($row['income'],2) ?></b></span><span>المصروفات<b><?= number_format($row['expenses'],2) ?></b></span></div></article><?php endforeach; ?><?php if(!$rows): ?><p class="afdc-empty">لا توجد صناديق مطابقة.</p><?php endif; ?></section>
  <?php if($day <= date('Y-m-d') && array_filter($allRows, static fn($row)=>!$row['closed'])): ?><form method="post" class="afdc-close"><?php if(function_exists('ua_csrf_field'))ua_csrf_field(); ?><input type="hidden" name="action" value="close_day"><button onclick="return confirm('إغلاق صناديق هذا اليوم؟')"><i class="fa fa-lock"></i> إغلاق اليوم الآن</button></form><?php endif; ?>
</main></div>
