Update: 2026-05-08 01:15:44

This commit is contained in:
Hamza-Ayed
2026-05-08 01:15:44 +03:00
parent 1a6ed52a52
commit 928e8e27e3
10 changed files with 991 additions and 4 deletions

View File

@@ -79,6 +79,20 @@ class InvoiceDetailView extends StatelessWidget {
// ─── Action Buttons ───
if (status == 'extracted') ...[
SizedBox(
height: 52,
child: ElevatedButton.icon(
onPressed: () => _showEditDialog(context, inv, controller),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF3B82F6),
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
icon: const Icon(Icons.edit_note_rounded),
label: const Text('تعديل بيانات الفاتورة', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
),
),
const SizedBox(height: 12),
SizedBox(
height: 52,
child: ElevatedButton.icon(
@@ -568,4 +582,128 @@ class InvoiceDetailView extends StatelessWidget {
if (num == num.truncateToDouble()) return num.toStringAsFixed(0);
return num.toStringAsFixed(3);
}
void _showEditDialog(BuildContext context, Map inv, InvoiceDetailController controller) {
final invNumC = TextEditingController(text: inv['invoice_number']?.toString() ?? '');
final invDateC = TextEditingController(text: inv['invoice_date']?.toString() ?? '');
final supplierNameC = TextEditingController(text: inv['supplier_name']?.toString() ?? '');
final supplierTinC = TextEditingController(text: inv['supplier_tin']?.toString() ?? '');
final supplierAddressC = TextEditingController(text: inv['supplier_address']?.toString() ?? '');
final buyerNameC = TextEditingController(text: inv['buyer_name']?.toString() ?? '');
final buyerTinC = TextEditingController(text: inv['buyer_tin']?.toString() ?? '');
final subtotalC = TextEditingController(text: inv['subtotal']?.toString() ?? '0');
final taxC = TextEditingController(text: inv['tax_amount']?.toString() ?? '0');
final discountC = TextEditingController(text: inv['discount_total']?.toString() ?? '0');
final grandC = TextEditingController(text: inv['grand_total']?.toString() ?? '0');
Get.to(() => Scaffold(
appBar: AppBar(
title: const Text('تعديل الفاتورة', style: TextStyle(fontWeight: FontWeight.bold)),
backgroundColor: const Color(0xFF3B82F6),
foregroundColor: Colors.white,
actions: [
Obx(() => controller.isSaving.value
? const Padding(padding: EdgeInsets.all(16), child: SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white)))
: IconButton(
icon: const Icon(Icons.save_rounded),
onPressed: () {
controller.updateInvoice({
'invoice_number': invNumC.text,
'invoice_date': invDateC.text,
'supplier_name': supplierNameC.text,
'supplier_tin': supplierTinC.text,
'supplier_address': supplierAddressC.text,
'buyer_name': buyerNameC.text,
'buyer_tin': buyerTinC.text,
'subtotal': subtotalC.text,
'tax_amount': taxC.text,
'discount_total': discountC.text,
'grand_total': grandC.text,
}).then((_) => Get.back());
},
),
),
],
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('معلومات الفاتورة', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
const SizedBox(height: 16),
_editRow('رقم الفاتورة', invNumC, Icons.numbers),
_editRow('تاريخ الفاتورة', invDateC, Icons.calendar_today),
const Divider(height: 32),
const Text('بيانات المورّد', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
const SizedBox(height: 16),
_editRow('اسم المورّد', supplierNameC, Icons.store),
_editRow('الرقم الضريبي', supplierTinC, Icons.badge),
_editRow('العنوان', supplierAddressC, Icons.location_on),
const Divider(height: 32),
const Text('بيانات العميل', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
const SizedBox(height: 16),
_editRow('اسم العميل', buyerNameC, Icons.person),
_editRow('الرقم الضريبي للعميل', buyerTinC, Icons.badge),
const Divider(height: 32),
const Text('المبالغ', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
const SizedBox(height: 16),
_editRow('المبلغ قبل الضريبة', subtotalC, Icons.attach_money, isNumeric: true),
_editRow('الخصم', discountC, Icons.discount, isNumeric: true),
_editRow('الضريبة', taxC, Icons.percent, isNumeric: true),
_editRow('الإجمالي', grandC, Icons.payments, isNumeric: true),
const SizedBox(height: 32),
SizedBox(
width: double.infinity,
height: 52,
child: ElevatedButton.icon(
onPressed: () {
controller.updateInvoice({
'invoice_number': invNumC.text,
'invoice_date': invDateC.text,
'supplier_name': supplierNameC.text,
'supplier_tin': supplierTinC.text,
'supplier_address': supplierAddressC.text,
'buyer_name': buyerNameC.text,
'buyer_tin': buyerTinC.text,
'subtotal': subtotalC.text,
'tax_amount': taxC.text,
'discount_total': discountC.text,
'grand_total': grandC.text,
}).then((_) => Get.back());
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF10B981),
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
icon: const Icon(Icons.save),
label: const Text('حفظ التعديلات', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
),
),
const SizedBox(height: 40),
],
),
),
));
}
Widget _editRow(String label, TextEditingController ctrl, IconData icon, {bool isNumeric = false}) {
return Padding(
padding: const EdgeInsets.only(bottom: 14),
child: TextField(
controller: ctrl,
textDirection: TextDirection.rtl,
keyboardType: isNumeric ? const TextInputType.numberWithOptions(decimal: true) : TextInputType.text,
decoration: InputDecoration(
labelText: label,
prefixIcon: Icon(icon, size: 20),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
contentPadding: const EdgeInsets.symmetric(horizontal: 14, vertical: 14),
filled: true,
fillColor: Colors.grey.shade50,
),
),
);
}
}