Update: 2026-05-16 01:40:56

This commit is contained in:
Hamza-Ayed
2026-05-16 01:40:56 +03:00
parent aceb7d324f
commit 9ad361e992
4 changed files with 126 additions and 25 deletions

View File

@@ -47,18 +47,33 @@ try {
$plan = $stmt->fetch();
if ($plan) {
$cycle = $payment['billing_cycle'] ?? 'annual';
$startDate = date('Y-m-d H:i:s');
$endDate = date('Y-m-d H:i:s', strtotime('+30 days'));
if ($cycle === 'monthly') {
$endDate = date('Y-m-d H:i:s', strtotime('+30 days'));
$maxInvoices = (int)$plan['max_invoices_month'];
$price = (float)($plan['price_monthly_jod'] ?? $plan['price_jod']);
} else {
$endDate = date('Y-m-d H:i:s', strtotime('+1 year'));
// Annual gets 12x the monthly quota
$maxInvoices = (int)($plan['max_invoices_month'] * 12);
$price = (float)($plan['price_annual_jod'] ?? ($plan['price_jod'] * 10));
}
$stmt = $db->prepare("
INSERT INTO subscriptions (tenant_id, plan_id, max_companies, max_invoices_per_month, max_users, price_jod, status, current_period_start, current_period_end, updated_at)
VALUES (:t_id, :p_id, :max_c, :max_i, :max_u, :price, 'active', :start, :end, NOW())
INSERT INTO subscriptions (
tenant_id, plan_id, max_companies, max_invoices_per_month, max_users,
price_jod, billing_cycle, status, current_period_start, current_period_end, updated_at
)
VALUES (:t_id, :p_id, :max_c, :max_i, :max_u, :price, :cycle, 'active', :start, :end, NOW())
ON DUPLICATE KEY UPDATE
plan_id = VALUES(plan_id),
max_companies = VALUES(max_companies),
max_invoices_per_month = VALUES(max_invoices_per_month),
max_users = VALUES(max_users),
price_jod = VALUES(price_jod),
billing_cycle = VALUES(billing_cycle),
status = 'active',
current_period_start = VALUES(current_period_start),
current_period_end = VALUES(current_period_end),
@@ -68,9 +83,10 @@ try {
't_id' => $payment['tenant_id'],
'p_id' => $plan['id'],
'max_c' => $plan['max_companies'],
'max_i' => $plan['max_invoices_month'],
'max_i' => $maxInvoices,
'max_u' => $plan['max_users'],
'price' => $plan['price_jod'],
'price' => $price,
'cycle' => $cycle,
'start' => $startDate,
'end' => $endDate
]);

View File

@@ -11,6 +11,7 @@ class SubscriptionController extends GetxController {
var isLoading = true.obs;
var isCreatingPayment = false.obs;
var activePaymentRequest = Rxn<Map<String, dynamic>>();
var isAnnual = true.obs; // Toggle between Monthly and Annual
@override
void onInit() {
@@ -69,7 +70,11 @@ class SubscriptionController extends GetxController {
Future<Map<String, dynamic>?> createPaymentRequest(String planId) async {
try {
isCreatingPayment.value = true;
final res = await DioClient().client.post('payments/create', data: {'plan_id': planId});
final cycle = isAnnual.value ? 'annual' : 'monthly';
final res = await DioClient().client.post('payments/create', data: {
'plan_id': planId,
'billing_cycle': cycle,
});
if (res.data['success'] == true && res.data['data'] != null) {
final result = Map<String, dynamic>.from(res.data['data']);
activePaymentRequest.value = result;

View File

@@ -44,25 +44,93 @@ class SubscriptionView extends StatelessWidget {
// Plans Header
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Icon(Icons.diamond_rounded, color: Color(0xFFD4AF37), size: 22),
const SizedBox(width: 8),
Text(
'اختر باقتك',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: isDark ? Colors.white : const Color(0xFF0F172A),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Icon(Icons.diamond_rounded, color: Color(0xFFD4AF37), size: 22),
const SizedBox(width: 8),
Text(
'اختر باقتك',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: isDark ? Colors.white : const Color(0xFF0F172A),
),
),
],
),
const SizedBox(height: 4),
Text(
'ادفع عبر CliQ — بدون عمولة!',
style: TextStyle(fontSize: 13, color: isDark ? Colors.white38 : Colors.grey),
),
],
),
],
),
const SizedBox(height: 4),
Text(
'ادفع عبر CliQ — بدون عمولة!',
style: TextStyle(fontSize: 13, color: isDark ? Colors.white38 : Colors.grey),
const SizedBox(height: 20),
// Toggle
Container(
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: isDark ? Colors.white.withOpacity(0.05) : Colors.black.withOpacity(0.05),
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
Expanded(
child: GestureDetector(
onTap: () => controller.isAnnual.value = false,
child: Obx(() => Container(
padding: const EdgeInsets.symmetric(vertical: 10),
decoration: BoxDecoration(
color: !controller.isAnnual.value ? const Color(0xFF0F4C81) : Colors.transparent,
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: Text(
'دفع شهري',
style: TextStyle(
color: !controller.isAnnual.value ? Colors.white : (isDark ? Colors.white60 : Colors.black54),
fontWeight: FontWeight.bold,
fontSize: 13,
),
),
),
)),
),
),
Expanded(
child: GestureDetector(
onTap: () => controller.isAnnual.value = true,
child: Obx(() => Container(
padding: const EdgeInsets.symmetric(vertical: 10),
decoration: BoxDecoration(
color: controller.isAnnual.value ? const Color(0xFF0F4C81) : Colors.transparent,
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: Text(
'دفع سنوي (توفير ✨)',
style: TextStyle(
color: controller.isAnnual.value ? Colors.white : (isDark ? Colors.white60 : Colors.black54),
fontWeight: FontWeight.bold,
fontSize: 13,
),
),
),
)),
),
),
],
),
),
const SizedBox(height: 16),
const SizedBox(height: 20),
// Plans Grid
...controller.plans.map((plan) => _buildPlanCard(plan, controller, isDark)),
@@ -228,9 +296,19 @@ class SubscriptionView extends StatelessWidget {
Widget _buildPlanCard(Map<String, dynamic> plan, SubscriptionController ctrl, bool isDark) {
final isPopular = plan['is_popular'] == true;
final price = (plan['price_jod'] ?? 0).toString();
final features = (plan['features'] as List?)?.cast<String>() ?? [];
final nameAr = plan['name_ar'] ?? plan['name_en'] ?? 'باقة';
return Obx(() {
final bool annual = ctrl.isAnnual.value;
final price = annual
? (plan['price_annual_jod'] ?? (plan['price_jod'] * 10)).toString()
: (plan['price_monthly_jod'] ?? plan['price_jod']).toString();
final features = (plan['features'] as List?)?.cast<String>() ?? [];
final invoiceLimit = annual
? (plan['max_invoices_month'] * 12).toString()
: (plan['max_invoices_month']).toString();
final cycleText = annual ? 'سنة' : 'شهر';
return Container(
margin: const EdgeInsets.only(bottom: 16),
@@ -271,7 +349,7 @@ class SubscriptionView extends StatelessWidget {
text: TextSpan(
children: [
TextSpan(text: price, style: TextStyle(fontSize: 28, fontWeight: FontWeight.w900, color: isDark ? const Color(0xFF5EEAD4) : const Color(0xFF0F4C81))),
TextSpan(text: ' JOD', style: TextStyle(fontSize: 12, color: isDark ? Colors.white38 : Colors.grey)),
TextSpan(text: ' JOD / $cycleText', style: TextStyle(fontSize: 12, color: isDark ? Colors.white38 : Colors.grey)),
],
),
),
@@ -302,7 +380,7 @@ class SubscriptionView extends StatelessWidget {
children: [
_buildPlanStat(Icons.business, '${plan['max_companies'] ?? 0} شركات'),
const SizedBox(width: 8),
_buildPlanStat(Icons.receipt_long, '${plan['max_invoices_month'] ?? 0} فاتورة/سنة'),
_buildPlanStat(Icons.receipt_long, '$invoiceLimit فاتورة/$cycleText'),
const SizedBox(width: 8),
_buildPlanStat(Icons.people, '${plan['max_users'] ?? 0} مستخدمين'),
],
@@ -338,6 +416,7 @@ class SubscriptionView extends StatelessWidget {
],
),
);
});
}
Widget _buildPlanStat(IconData icon, String text) {

View File

@@ -1868,7 +1868,8 @@
<!-- Invoices -->
<div class="usage-card">
<div style="display:flex; justify-content:space-between; margin-bottom:6px;">
<span style="font-weight:700; color:var(--text-1); font-size:14px;">📄 رصيد الفواتير (سنوي)</span>
<span style="font-weight:700; color:var(--text-1); font-size:14px;">📄 رصيد الفواتير
<span x-text="subscription?.billing_cycle === 'monthly' ? '(شهري)' : '(سنوي)'"></span></span>
<span class="num-font" style="font-weight:700; color:var(--green-mid);"
x-text="(subscription?.invoices?.used || 0) + ' من ' + (subscription?.invoices?.limit || 0)"></span>
</div>