'daily']); } if ($_SERVER['REQUEST_METHOD'] !== 'POST') { redirect_to('../reports.php', ['tab' => 'daily']); } $reportDate = trim((string) ($_POST['date'] ?? date('Y-m-d'))); $branch = trim((string) ($_POST['branch'] ?? '')); if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $reportDate)) { set_flash('danger', tr('تاريخ التقرير غير صالح.', 'Invalid report date.')); redirect_to('../reports.php', ['tab' => 'daily']); } try { $result = wablas_send_daily_report($reportDate, $branch !== '' ? $branch : null); if (!empty($result['success'])) { set_flash('success', tr('تم إرسال ملخص التقرير اليومي عبر واتساب.', 'Daily summary report sent via WhatsApp.')); } else { $error = (string) ($result['error'] ?? tr('تعذر إرسال التقرير عبر واتساب.', 'Could not send the WhatsApp report.')); set_flash('danger', tr('فشل إرسال التقرير عبر واتساب.', 'Failed to send the WhatsApp report.') . ' ' . $error); } } catch (Throwable $e) { set_flash('danger', tr('فشل إرسال التقرير عبر واتساب.', 'Failed to send the WhatsApp report.') . ' ' . $e->getMessage()); } redirect_to('../reports.php', [ 'tab' => 'daily', 'date' => $reportDate, 'branch' => $branch, ]);