Done Category, Product Catalogue, Customer, Vendor, Purchase Invoice Module
This commit is contained in:
@@ -12,7 +12,8 @@ class ReceivePaymentSheet extends ConsumerStatefulWidget {
|
||||
const ReceivePaymentSheet({super.key, required this.invoice});
|
||||
|
||||
@override
|
||||
ConsumerState<ReceivePaymentSheet> createState() => _ReceivePaymentSheetState();
|
||||
ConsumerState<ReceivePaymentSheet> createState() =>
|
||||
_ReceivePaymentSheetState();
|
||||
}
|
||||
|
||||
class _ReceivePaymentSheetState extends ConsumerState<ReceivePaymentSheet> {
|
||||
@@ -32,7 +33,7 @@ class _ReceivePaymentSheetState extends ConsumerState<ReceivePaymentSheet> {
|
||||
Widget build(BuildContext context) {
|
||||
final walletsState = ref.watch(walletProvider);
|
||||
final allWallets = walletsState.value ?? [];
|
||||
|
||||
|
||||
final wallets = allWallets.where((w) {
|
||||
if (_paymentMethod == 'Cash') {
|
||||
return w.nature == 'CASH';
|
||||
@@ -40,8 +41,10 @@ class _ReceivePaymentSheetState extends ConsumerState<ReceivePaymentSheet> {
|
||||
return w.nature == 'INCOME' || w.nature == 'SAVINGS';
|
||||
}
|
||||
}).toList();
|
||||
|
||||
if (wallets.isNotEmpty && (_selectedWalletId == null || !wallets.any((w) => w.id == _selectedWalletId))) {
|
||||
|
||||
if (wallets.isNotEmpty &&
|
||||
(_selectedWalletId == null ||
|
||||
!wallets.any((w) => w.id == _selectedWalletId))) {
|
||||
_selectedWalletId = wallets.first.id;
|
||||
}
|
||||
|
||||
@@ -63,8 +66,14 @@ class _ReceivePaymentSheetState extends ConsumerState<ReceivePaymentSheet> {
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text('Receive Payment', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
|
||||
IconButton(icon: const Icon(LucideIcons.x), onPressed: () => Navigator.pop(context)),
|
||||
const Text(
|
||||
'Receive Payment',
|
||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(LucideIcons.x),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
@@ -74,7 +83,10 @@ class _ReceivePaymentSheetState extends ConsumerState<ReceivePaymentSheet> {
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text('Receive Into Wallet', style: TextStyle(fontWeight: FontWeight.w600, color: Colors.grey)),
|
||||
const Text(
|
||||
'Receive Into Wallet',
|
||||
style: TextStyle(fontWeight: FontWeight.w600, color: Colors.grey),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
@@ -88,14 +100,19 @@ class _ReceivePaymentSheetState extends ConsumerState<ReceivePaymentSheet> {
|
||||
isExpanded: true,
|
||||
hint: const Text('Select Wallet'),
|
||||
items: wallets
|
||||
.map((w) => DropdownMenuItem(value: w.id, child: Text(w.name)))
|
||||
.map(
|
||||
(w) => DropdownMenuItem(value: w.id, child: Text(w.name)),
|
||||
)
|
||||
.toList(),
|
||||
onChanged: (val) => setState(() => _selectedWalletId = val),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text('Payment Method', style: TextStyle(fontWeight: FontWeight.w600, color: Colors.grey)),
|
||||
const Text(
|
||||
'Payment Method',
|
||||
style: TextStyle(fontWeight: FontWeight.w600, color: Colors.grey),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
@@ -129,36 +146,64 @@ class _ReceivePaymentSheetState extends ConsumerState<ReceivePaymentSheet> {
|
||||
backgroundColor: Colors.blue,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
),
|
||||
onPressed: _isLoading ? null : () async {
|
||||
final amount = double.tryParse(_amountCtrl.text) ?? 0;
|
||||
if (amount <= 0) return;
|
||||
|
||||
setState(() => _isLoading = true);
|
||||
try {
|
||||
await ref.read(invoicesProvider.notifier).addPayment(
|
||||
widget.invoice.id!,
|
||||
InvoicePayment(
|
||||
amount: amount,
|
||||
paymentMethod: _paymentMethod,
|
||||
walletId: _selectedWalletId,
|
||||
onPressed: _isLoading
|
||||
? null
|
||||
: () async {
|
||||
final amount = double.tryParse(_amountCtrl.text) ?? 0;
|
||||
if (amount <= 0) return;
|
||||
|
||||
setState(() => _isLoading = true);
|
||||
try {
|
||||
await ref
|
||||
.read(invoicesProvider.notifier)
|
||||
.addPayment(
|
||||
widget.invoice.id!,
|
||||
InvoicePayment(
|
||||
amount: amount,
|
||||
paymentMethod: _paymentMethod,
|
||||
walletId: _selectedWalletId,
|
||||
),
|
||||
);
|
||||
if (mounted) {
|
||||
Navigator.pop(
|
||||
context,
|
||||
true,
|
||||
); // true indicates success
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Payment Received Successfully!'),
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(e.toString())));
|
||||
setState(() => _isLoading = false);
|
||||
}
|
||||
}
|
||||
},
|
||||
child: _isLoading
|
||||
? const SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.white,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
)
|
||||
: const Text(
|
||||
'Confirm Payment',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
);
|
||||
if (mounted) {
|
||||
Navigator.pop(context, true); // true indicates success
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Payment Received Successfully!')));
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(e.toString())));
|
||||
setState(() => _isLoading = false);
|
||||
}
|
||||
}
|
||||
},
|
||||
child: _isLoading
|
||||
? const SizedBox(width: 24, height: 24, child: CircularProgressIndicator(color: Colors.white, strokeWidth: 2))
|
||||
: const Text('Confirm Payment', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
Reference in New Issue
Block a user