Update: 2026-05-07 22:19:17
This commit is contained in:
108
musadaq-app/lib/features/companies/views/add_company_view.dart
Normal file
108
musadaq-app/lib/features/companies/views/add_company_view.dart
Normal file
@@ -0,0 +1,108 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../controllers/add_company_controller.dart';
|
||||
|
||||
class AddCompanyView extends StatelessWidget {
|
||||
const AddCompanyView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final controller = Get.put(AddCompanyController());
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('إضافة شركة', style: TextStyle(fontFamily: 'El Messiri')),
|
||||
centerTitle: true,
|
||||
backgroundColor: const Color(0xFF0F4C81),
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'بيانات الشركة الأساسية',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
_buildTextField(
|
||||
controller: controller.nameController,
|
||||
label: 'اسم الشركة',
|
||||
icon: Icons.business,
|
||||
isDark: isDark,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildTextField(
|
||||
controller: controller.tinController,
|
||||
label: 'الرقم الضريبي',
|
||||
icon: Icons.numbers,
|
||||
keyboardType: TextInputType.number,
|
||||
isDark: isDark,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildTextField(
|
||||
controller: controller.crnController,
|
||||
label: 'رقم السجل التجاري (اختياري)',
|
||||
icon: Icons.article,
|
||||
keyboardType: TextInputType.number,
|
||||
isDark: isDark,
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 54,
|
||||
child: Obx(
|
||||
() => ElevatedButton(
|
||||
onPressed: controller.isSubmitting.value ? null : controller.submit,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF0F4C81),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
|
||||
),
|
||||
child: controller.isSubmitting.value
|
||||
? const CircularProgressIndicator(color: Colors.white)
|
||||
: const Text(
|
||||
'حفظ وإضافة',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTextField({
|
||||
required TextEditingController controller,
|
||||
required String label,
|
||||
required IconData icon,
|
||||
TextInputType? keyboardType,
|
||||
required bool isDark,
|
||||
}) {
|
||||
return TextField(
|
||||
controller: controller,
|
||||
keyboardType: keyboardType,
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
prefixIcon: Icon(icon, color: const Color(0xFF0F4C81)),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: isDark ? Colors.white24 : Colors.grey.shade300),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: isDark ? Colors.white24 : Colors.grey.shade300),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: Color(0xFF0F4C81), width: 2),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: isDark ? Colors.white.withValues(alpha: 0.05) : Colors.white,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../controllers/companies_management_controller.dart';
|
||||
import 'add_company_view.dart';
|
||||
|
||||
class CompaniesManagementView extends StatelessWidget {
|
||||
const CompaniesManagementView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Put controller directly so we don't strictly need a binding for this nested route
|
||||
final controller = Get.put(CompaniesManagementController());
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('إدارة الشركات', style: TextStyle(fontFamily: 'El Messiri')),
|
||||
centerTitle: true,
|
||||
backgroundColor: const Color(0xFF0F4C81),
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
onPressed: () {
|
||||
Get.to(() => const AddCompanyView());
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Obx(() {
|
||||
if (controller.isLoading.value) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (controller.companies.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.business_center_outlined, size: 80, color: Colors.grey.shade400),
|
||||
const SizedBox(height: 16),
|
||||
const Text('لا يوجد شركات مسجلة', style: TextStyle(fontSize: 18, color: Colors.grey)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: controller.fetchCompanies,
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: controller.companies.length,
|
||||
itemBuilder: (context, index) {
|
||||
final company = controller.companies[index];
|
||||
return Card(
|
||||
elevation: 2,
|
||||
margin: const EdgeInsets.only(bottom: 16),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF0F4C81).withValues(alpha: 0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(Icons.business, color: Color(0xFF0F4C81)),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
company['name'] ?? 'شركة',
|
||||
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuButton(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
itemBuilder: (context) => [
|
||||
const PopupMenuItem(value: 'edit', child: Text('تعديل البيانات')),
|
||||
const PopupMenuItem(value: 'employees', child: Text('إدارة الموظفين')),
|
||||
const PopupMenuItem(value: 'delete', child: Text('حذف الشركة', style: TextStyle(color: Colors.red))),
|
||||
],
|
||||
onSelected: (value) {
|
||||
if (value == 'delete') {
|
||||
_confirmDelete(context, controller, company['id']);
|
||||
} else {
|
||||
Get.snackbar('قريباً', 'الواجهة قيد البرمجة');
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
_buildDetailChip(Icons.numbers, company['tax_identification_number'] ?? 'غير محدد', isDark),
|
||||
const SizedBox(width: 8),
|
||||
if (company['is_jofotara_connected'] == true || company['is_jofotara_connected'] == 1)
|
||||
_buildDetailChip(Icons.link, 'مرتبطة بجوفوتارا', isDark, color: const Color(0xFF10B981)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton.icon(
|
||||
onPressed: () => Get.snackbar('إحصائيات', 'عرض إحصائيات الشركة'),
|
||||
icon: const Icon(Icons.bar_chart, size: 18),
|
||||
label: const Text('الإحصائيات'),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDetailChip(IconData icon, String text, bool isDark, {Color? color}) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: (color ?? Colors.grey).withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, size: 14, color: color ?? (isDark ? Colors.white70 : Colors.black54)),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: color ?? (isDark ? Colors.white70 : Colors.black87),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _confirmDelete(BuildContext context, CompaniesManagementController controller, String id) {
|
||||
Get.defaultDialog(
|
||||
title: 'حذف الشركة',
|
||||
middleText: 'هل أنت متأكد من رغبتك في حذف هذه الشركة نهائياً؟',
|
||||
textConfirm: 'حذف',
|
||||
textCancel: 'إلغاء',
|
||||
confirmTextColor: Colors.white,
|
||||
buttonColor: Colors.red,
|
||||
onConfirm: () {
|
||||
Get.back();
|
||||
controller.deleteCompany(id);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user