<div class="content-wrapper android-finance-reports"><main class="afr-main">
  <header class="afr-heading"><div><span>Billing & Accounting</span><h1>الفوترة والمحاسبة</h1><p>ملخص الفواتير والتحصيل والمصروفات والصناديق.</p></div><div class="afr-heading-icon"><i class="fa fa-balance-scale"></i></div></header>
  <nav class="afr-nav"><a class="is-active" href="finance_reports.php"><i class="fa fa-pie-chart"></i><span>الملخص</span></a><a href="invoices.php"><i class="fa fa-file-text-o"></i><span>الفواتير</span></a><a href="finance_payments.php"><i class="fa fa-exchange"></i><span>الحركة</span></a><a href="finance_daily_balances.php"><i class="fa fa-archive"></i><span>الصناديق</span></a></nav>
  <section class="afr-filter"><form method="get" data-ua-android-native-layout><label><span>من تاريخ</span><input type="date" name="start" value="<?=h($start)?>"></label><label><span>إلى تاريخ</span><input type="date" name="end" value="<?=h($end)?>"></label><button><i class="fa fa-filter"></i> تطبيق</button><a href="finance_reports.php">هذا الشهر</a></form></section>
  <section class="afr-stats"><article><i class="fa fa-file-text-o"></i><span>إجمالي الفواتير</span><strong dir="ltr"><?=number_format($sum_invoices,2)?></strong><small><?=$invoice_count?> فاتورة</small></article><article class="is-in"><i class="fa fa-arrow-down"></i><span>المقبوضات</span><strong dir="ltr"><?=number_format($sum_paid,2)?></strong><small><?=number_format($collection_rate,1)?>% تحصيل</small></article><article class="is-out"><i class="fa fa-hourglass-half"></i><span>الذمم المتبقية</span><strong dir="ltr"><?=number_format($sum_remaining,2)?></strong><small><?=$overdue_invoice_count?> متأخرة</small></article><article class="is-net"><i class="fa fa-line-chart"></i><span>صافي الحركة</span><strong dir="ltr"><?=number_format($net,2)?></strong><small>المصروفات: <?=number_format($sum_expenses,2)?></small></article></section>
  <section class="afr-section"><div class="afr-section-head"><div><span>Daily cashboxes</span><h2>صناديق اليوم</h2></div><a href="finance_daily_balances.php"><i class="fa fa-archive"></i></a></div><div class="afr-breakdown"><?php foreach($today_cashboxes as $box):?><div><span><?=h($box['account_name'])?> · <?=h($typeLabels[$box['account_type']]??$box['account_type'])?></span><strong dir="ltr"><?=number_format((float)$box['final'],2)?></strong></div><?php endforeach;?><?php if(!$today_cashboxes):?><p class="afr-empty">لا توجد صناديق مسجلة.</p><?php endif;?></div></section>
  <section class="afr-section"><div class="afr-section-head"><div><span>Collections by source</span><h2>التحصيل حسب النسخة</h2></div><i class="fa fa-sitemap"></i></div><div class="afr-breakdown"><?php foreach($by_source as $row):?><div><span><?=h($row['source_name'])?><small><?=(int)$row['payment_count']?> دفعة</small></span><strong dir="ltr"><?=number_format((float)$row['total'],2)?></strong></div><?php endforeach;?><?php if(!$by_source):?><p class="afr-empty">لا توجد بيانات.</p><?php endif;?></div></section>
  <section class="afr-section"><div class="afr-section-head"><div><span>Payment methods</span><h2>المقبوضات حسب الطريقة</h2></div><i class="fa fa-credit-card"></i></div><div class="afr-breakdown"><?php foreach($by_method as $row):?><div><span><?=h($row['label'])?></span><strong dir="ltr"><?=number_format((float)$row['total'],2)?></strong></div><?php endforeach;?><?php if(!$by_method):?><p class="afr-empty">لا توجد بيانات.</p><?php endif;?></div></section>
  <section class="afr-section"><div class="afr-section-head"><div><span>Expenses</span><h2>المصروفات حسب التصنيف</h2></div><i class="fa fa-tags"></i></div><div class="afr-breakdown is-expense"><?php foreach($by_category as $row):?><div><span><?=h($row['label'])?></span><strong dir="ltr"><?=number_format((float)$row['total'],2)?></strong></div><?php endforeach;?><?php if(!$by_category):?><p class="afr-empty">لا توجد بيانات.</p><?php endif;?></div></section>
  <details class="afr-daily"><summary><span><small>Last 14 days</small><b>الحركة اليومية</b></span><i class="fa fa-angle-down"></i></summary><div class="afr-daily-list"><?php foreach(array_reverse($daily_recent) as $row):?><article><time dir="ltr"><?=h($row['day'])?></time><div><span>مقبوضات<b dir="ltr"><?=number_format($row['in'],2)?></b></span><span>مصروفات<b dir="ltr"><?=number_format($row['out'],2)?></b></span><span>الصافي<b dir="ltr"><?=number_format($row['net'],2)?></b></span></div></article><?php endforeach;?></div></details>
</main></div>
