107 lines
3.2 KiB
Dart
107 lines
3.2 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
||
|
|
import 'package:provider/provider.dart';
|
||
|
|
import '../providers/invoice_installment_screen.dart';
|
||
|
|
import '../providers/invoice_provider.dart';
|
||
|
|
import '../services/dio_client.dart';
|
||
|
|
import '../services/invoice_service.dart';
|
||
|
|
import 'invoice_detail_screen.dart';
|
||
|
|
|
||
|
|
|
||
|
|
class InvoiceScreen extends StatefulWidget {
|
||
|
|
const InvoiceScreen({super.key});
|
||
|
|
|
||
|
|
@override
|
||
|
|
State<InvoiceScreen> createState() => _InvoiceScreenState();
|
||
|
|
}
|
||
|
|
|
||
|
|
class _InvoiceScreenState extends State<InvoiceScreen> {
|
||
|
|
@override
|
||
|
|
void initState() {
|
||
|
|
super.initState();
|
||
|
|
|
||
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||
|
|
Provider.of<InvoiceProvider>(context, listen: false)
|
||
|
|
.loadInvoices(context);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
final provider = Provider.of<InvoiceProvider>(context);
|
||
|
|
|
||
|
|
if (provider.loading) {
|
||
|
|
return const Center(child: CircularProgressIndicator());
|
||
|
|
}
|
||
|
|
|
||
|
|
if (provider.invoices.isEmpty) {
|
||
|
|
return const Center(
|
||
|
|
child: Text("No invoices found", style: TextStyle(fontSize: 18)));
|
||
|
|
}
|
||
|
|
|
||
|
|
return ListView.builder(
|
||
|
|
padding: const EdgeInsets.all(16),
|
||
|
|
itemCount: provider.invoices.length,
|
||
|
|
itemBuilder: (_, i) {
|
||
|
|
final inv = provider.invoices[i];
|
||
|
|
|
||
|
|
return Card(
|
||
|
|
margin: const EdgeInsets.only(bottom: 12),
|
||
|
|
child: Padding(
|
||
|
|
padding: const EdgeInsets.all(14),
|
||
|
|
child: Column(
|
||
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
|
children: [
|
||
|
|
Text(
|
||
|
|
"Invoice ${inv['invoice_number'] ?? 'N/A'}",
|
||
|
|
style: const TextStyle(
|
||
|
|
fontSize: 18, fontWeight: FontWeight.bold),
|
||
|
|
),
|
||
|
|
|
||
|
|
const SizedBox(height: 6),
|
||
|
|
Text("Date: ${inv['invoice_date'] ?? 'N/A'}"),
|
||
|
|
Text("Status: ${inv['status'] ?? 'N/A'}"),
|
||
|
|
Text("Amount: ₹${inv['formatted_amount'] ?? '0'}"),
|
||
|
|
|
||
|
|
const SizedBox(height: 10),
|
||
|
|
|
||
|
|
Row(
|
||
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
|
|
children: [
|
||
|
|
OutlinedButton(
|
||
|
|
child: const Text("Invoice Details"),
|
||
|
|
onPressed: () {
|
||
|
|
Navigator.push(
|
||
|
|
context,
|
||
|
|
MaterialPageRoute(
|
||
|
|
builder: (_) => InvoiceDetailScreen(
|
||
|
|
invoiceId: inv['invoice_id'],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
},
|
||
|
|
),
|
||
|
|
|
||
|
|
OutlinedButton(
|
||
|
|
child: const Text("Installments"),
|
||
|
|
onPressed: () {
|
||
|
|
Navigator.push(
|
||
|
|
context,
|
||
|
|
MaterialPageRoute(
|
||
|
|
builder: (_) => InvoiceInstallmentScreen(
|
||
|
|
invoiceId: inv['invoice_id'],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
},
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
},
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|