Commit bf80fb97 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix(pricing): rebuild board offers UI with proper pagination, stats, and live preview

- Fixed crash: pagination used `total_pages` key but Pagination class returns `last_page`
- Board offers index: card-based layout with status indicators, usage counts, branch
  names (joined), days-until-expiry warnings, and stat summary at top
- Board offers form: two-column layout with live preview sidebar that shows real-time
  calculation examples, date validation warnings, and contextual help
- Model search now joins branches table and counts payment_request usage per offer
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 60733923
......@@ -47,23 +47,29 @@ class BoardOffer extends Model
$params = [];
if (!empty($filters['search'])) {
$where .= ' AND (`title_ar` LIKE ? OR `title_en` LIKE ? OR `board_decision_number` LIKE ?)';
$where .= ' AND (bo.`title_ar` LIKE ? OR bo.`title_en` LIKE ? OR bo.`board_decision_number` LIKE ?)';
$s = '%' . $filters['search'] . '%';
$params[] = $s;
$params[] = $s;
$params[] = $s;
}
if (($filters['is_active'] ?? '') !== '') {
$where .= ' AND `is_active` = ?';
$where .= ' AND bo.`is_active` = ?';
$params[] = (int) $filters['is_active'];
}
$countRow = $db->selectOne("SELECT COUNT(*) as cnt FROM `board_offers` WHERE {$where}", $params);
$countRow = $db->selectOne("SELECT COUNT(*) as cnt FROM `board_offers` bo WHERE {$where}", $params);
$total = (int) ($countRow['cnt'] ?? 0);
$offset = ($page - 1) * $perPage;
$data = $db->select(
"SELECT * FROM `board_offers` WHERE {$where} ORDER BY `effective_from` DESC LIMIT {$perPage} OFFSET {$offset}",
"SELECT bo.*, b.name_ar as branch_name,
(SELECT COUNT(*) FROM payment_requests pr WHERE pr.board_offer_id = bo.id AND pr.is_voided = 0) as usage_count
FROM `board_offers` bo
LEFT JOIN `branches` b ON b.id = bo.branch_id
WHERE {$where}
ORDER BY bo.`is_active` DESC, bo.`effective_from` DESC
LIMIT {$perPage} OFFSET {$offset}",
$params
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment