Inventory Management | Customer Management | Invoice Management Done | Commodity Rate Sync Done

This commit is contained in:
2026-08-20 20:35:41 +05:30
parent ba9a9fd8a4
commit 5f620022f3
101 changed files with 9091 additions and 240 deletions

View File

@@ -3,38 +3,69 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lucide_icons/lucide_icons.dart';
import '../../../../core/theme/nature_colors.dart';
import '../../../inventory/presentation/product_list_screen.dart';
import '../../../inventory/presentation/quick_adjust_stock_screen.dart';
import '../../../inventory/presentation/uoms_list_screen.dart';
import '../../../sales/presentation/customers_list_screen.dart';
import '../../../sales/presentation/invoices_list_screen.dart';
import '../../providers/business_provider.dart';
import '../widgets/business_profile_form_sheet.dart';
class BusinessHubScreen extends ConsumerWidget {
const BusinessHubScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final businessState = ref.watch(businessProfileProvider);
final profile = businessState.value;
final title = (profile?.businessName != null && profile!.businessName.isNotEmpty)
? profile.businessName
: 'Business Overview';
final subtitle = (profile?.address != null && profile!.address!.isNotEmpty)
? profile.address!
: 'Manage your inventory and stock';
final featureState = ref.watch(businessFeatureProvider).value;
final bool showInventory = featureState?.inventoryManagement ?? false;
final bool showSales = featureState?.salesManagement ?? false;
return SingleChildScrollView(
padding: const EdgeInsets.all(24.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary.withOpacity(0.1),
borderRadius: BorderRadius.circular(16),
border: Border.all(color: Theme.of(context).colorScheme.primary.withOpacity(0.2)),
),
child: Row(
children: [
Icon(LucideIcons.briefcase, color: Theme.of(context).colorScheme.primary, size: 32),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Business Overview', style: Theme.of(context).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.bold)),
const Text('Manage your inventory and stock', style: TextStyle(color: Colors.grey)),
],
InkWell(
onTap: () {
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (context) => const BusinessProfileFormSheet(),
);
},
borderRadius: BorderRadius.circular(16),
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary.withOpacity(0.1),
borderRadius: BorderRadius.circular(16),
border: Border.all(color: Theme.of(context).colorScheme.primary.withOpacity(0.2)),
),
child: Row(
children: [
Icon(LucideIcons.briefcase, color: Theme.of(context).colorScheme.primary, size: 32),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title, style: Theme.of(context).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.bold)),
Text(subtitle, style: const TextStyle(color: Colors.grey)),
],
),
),
),
],
],
),
),
),
const SizedBox(height: 24),
@@ -46,56 +77,68 @@ class BusinessHubScreen extends ConsumerWidget {
physics: const NeverScrollableScrollPhysics(),
childAspectRatio: 1.2,
children: [
_buildActionCard(
context,
'Products Catalog',
'View all products',
LucideIcons.packageSearch,
Colors.blue,
() => Navigator.push(context, MaterialPageRoute(builder: (_) => const ProductListScreen())),
),
_buildActionCard(
context,
'Adjust Stock',
'Add or reduce inventory',
LucideIcons.arrowRightLeft,
Colors.orange,
() {
// TODO: Navigate to Stock Adjustment
},
),
_buildActionCard(
context,
'Sales & Invoices',
'Coming in Phase 2',
LucideIcons.receipt,
Colors.green,
() {},
),
_buildActionCard(
context,
'Customers',
'Coming in Phase 2',
LucideIcons.users,
NatureColors.getColor('RECEIVABLES'),
() {},
),
if (showInventory) ...[
_buildActionCard(
context,
'Products Catalog',
'View all products',
LucideIcons.packageSearch,
Colors.blue,
() => Navigator.push(context, MaterialPageRoute(builder: (_) => const ProductListScreen())),
),
_buildActionCard(
context,
'Adjust Stock',
'Quick Stock Edit',
LucideIcons.arrowRightLeft,
Colors.orange,
() => Navigator.push(context, MaterialPageRoute(builder: (_) => const QuickAdjustStockScreen())),
),
_buildActionCard(
context,
'Units of Measure',
'Manage measurements',
LucideIcons.ruler,
Colors.purple,
() => Navigator.push(context, MaterialPageRoute(builder: (_) => const UomsListScreen())),
),
],
if (showSales) ...[
_buildActionCard(
context,
'Sales & Invoices',
'Create invoices',
LucideIcons.receipt,
Colors.green,
() => Navigator.push(context, MaterialPageRoute(builder: (_) => const InvoicesListScreen())),
),
_buildActionCard(
context,
'Customers',
'Manage clients',
LucideIcons.users,
NatureColors.getColor('RECEIVABLES'),
() => Navigator.push(context, MaterialPageRoute(builder: (_) => const CustomersListScreen())),
),
],
],
),
const SizedBox(height: 32),
Text('Low Stock Alerts', style: Theme.of(context).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.bold)),
const SizedBox(height: 16),
// Placeholder for low stock items
Container(
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
color: Colors.grey.withOpacity(0.05),
borderRadius: BorderRadius.circular(16),
if (showInventory) ...[
const SizedBox(height: 32),
Text('Low Stock Alerts', style: Theme.of(context).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.bold)),
const SizedBox(height: 16),
// Placeholder for low stock items
Container(
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
color: Colors.grey.withOpacity(0.05),
borderRadius: BorderRadius.circular(16),
),
child: const Center(
child: Text('All products are adequately stocked.', style: TextStyle(color: Colors.grey)),
),
),
child: const Center(
child: Text('All products are adequately stocked.', style: TextStyle(color: Colors.grey)),
),
),
],
],
),
);

View File

@@ -25,6 +25,13 @@ class _BusinessSettingsScreenState extends ConsumerState<BusinessSettingsScreen>
_taxIncludedInPrice = profile.taxIncludedInPrice ?? false;
});
}
final feature = ref.read(businessFeatureProvider).value;
if (feature != null) {
setState(() {
_inventoryEnabled = feature.inventoryManagement;
_salesEnabled = feature.salesManagement;
});
}
});
}
@@ -45,17 +52,76 @@ class _BusinessSettingsScreenState extends ConsumerState<BusinessSettingsScreen>
title: const Text('Inventory Management'),
subtitle: const Text('Track stock levels, multiple locations, and products'),
value: _inventoryEnabled,
onChanged: (val) => setState(() => _inventoryEnabled = val),
onChanged: (val) {
setState(() => _inventoryEnabled = val);
_saveFeatures();
},
secondary: const Icon(LucideIcons.package),
),
SwitchListTile(
title: const Text('Sales & POS'),
subtitle: const Text('Enable point of sale, invoicing, and receivables'),
value: _salesEnabled,
onChanged: (val) => setState(() => _salesEnabled = val),
onChanged: (val) {
setState(() => _salesEnabled = val);
_saveFeatures();
},
secondary: const Icon(LucideIcons.shoppingCart),
),
const SizedBox(height: 32),
const Text('Inventory Strategy', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.grey)),
const SizedBox(height: 16),
Consumer(
builder: (context, ref, child) {
final featureState = ref.watch(businessFeatureProvider);
final currentStrategy = featureState.value?.bomReductionStrategy ?? 'COMPONENTS_ONLY';
final deductParentStock = currentStrategy == 'PARENT_AND_COMPONENTS';
final stockDeductionOnInvoice = featureState.value?.stockDeductionOnInvoice ?? true;
return Column(
children: [
SwitchListTile(
title: const Text('Deduct Parent Stock on BOM Sale'),
subtitle: const Text('If enabled, selling an assembled product reduces both parent and component stock.'),
value: deductParentStock,
secondary: const Icon(LucideIcons.gitMerge),
onChanged: (val) {
if (featureState.value != null) {
final newStrategy = val ? 'PARENT_AND_COMPONENTS' : 'COMPONENTS_ONLY';
final updated = featureState.value!.copyWith(bomReductionStrategy: newStrategy);
ref.read(businessFeatureProvider.notifier).updateFeatures(updated);
}
},
),
SwitchListTile(
title: const Text('Stock Deduction on Invoice'),
subtitle: const Text('If enabled, finalizing an invoice automatically deducts product stock. Turn off for a two-step fulfillment process.'),
value: stockDeductionOnInvoice,
secondary: const Icon(LucideIcons.boxes),
onChanged: (val) {
if (featureState.value != null) {
final updated = featureState.value!.copyWith(stockDeductionOnInvoice: val);
ref.read(businessFeatureProvider.notifier).updateFeatures(updated);
}
},
),
SwitchListTile(
title: const Text('Use EAN/Barcode for Scanner'),
subtitle: const Text('If disabled, the barcode scanner will search using the SKU field instead.'),
value: (featureState.value?.barcodeSource ?? 'SKU') == 'BARCODE',
secondary: const Icon(LucideIcons.scanLine),
onChanged: (val) {
if (featureState.value != null) {
final updated = featureState.value!.copyWith(barcodeSource: val ? 'BARCODE' : 'SKU');
ref.read(businessFeatureProvider.notifier).updateFeatures(updated);
}
},
),
],
);
}
),
const SizedBox(height: 32),
const Text('Pricing & Taxation', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.grey)),
const SizedBox(height: 16),
SwitchListTile(
@@ -80,4 +146,15 @@ class _BusinessSettingsScreenState extends ConsumerState<BusinessSettingsScreen>
ref.read(businessProfileProvider.notifier).updateProfile(updated);
}
}
void _saveFeatures() {
final featureState = ref.read(businessFeatureProvider).value;
if (featureState != null) {
final updated = featureState.copyWith(
inventoryManagement: _inventoryEnabled,
salesManagement: _salesEnabled,
);
ref.read(businessFeatureProvider.notifier).updateFeatures(updated);
}
}
}

View File

@@ -0,0 +1,288 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../domain/business_profile.dart';
import '../../providers/business_provider.dart';
import '../../providers/indian_states_provider.dart';
class BusinessProfileFormSheet extends ConsumerStatefulWidget {
const BusinessProfileFormSheet({super.key});
@override
ConsumerState<BusinessProfileFormSheet> createState() => _BusinessProfileFormSheetState();
}
class _BusinessProfileFormSheetState extends ConsumerState<BusinessProfileFormSheet> {
final _formKey = GlobalKey<FormState>();
late TextEditingController _businessNameController;
late TextEditingController _addressController;
late TextEditingController _contactPersonController;
late TextEditingController _contactNumberController;
late TextEditingController _emailController;
late TextEditingController _panController;
late TextEditingController _gstinController;
int? _selectedStateId;
bool _isLoading = false;
@override
void initState() {
super.initState();
final profile = ref.read(businessProfileProvider).value;
_businessNameController = TextEditingController(text: profile?.businessName ?? '');
_addressController = TextEditingController(text: profile?.address ?? '');
_contactPersonController = TextEditingController(text: profile?.contactPerson ?? '');
_contactNumberController = TextEditingController(text: profile?.contactNumber ?? '');
_emailController = TextEditingController(text: profile?.emailId ?? '');
_panController = TextEditingController(text: profile?.panNumber ?? '');
_gstinController = TextEditingController(text: profile?.gstin ?? '');
_selectedStateId = profile?.stateId;
}
@override
void dispose() {
_businessNameController.dispose();
_addressController.dispose();
_contactPersonController.dispose();
_contactNumberController.dispose();
_emailController.dispose();
_panController.dispose();
_gstinController.dispose();
super.dispose();
}
Future<void> _submit() async {
if (!_formKey.currentState!.validate()) return;
setState(() => _isLoading = true);
try {
final existingProfile = ref.read(businessProfileProvider).value;
final profile = BusinessProfile(
id: existingProfile?.id,
userId: existingProfile?.userId,
businessName: _businessNameController.text.trim(),
address: _addressController.text.trim(),
stateId: _selectedStateId,
contactPerson: _contactPersonController.text.trim(),
contactNumber: _contactNumberController.text.trim(),
emailId: _emailController.text.trim(),
panNumber: _panController.text.trim().toUpperCase(),
gstin: _gstinController.text.trim().toUpperCase(),
);
await ref.read(businessProfileProvider.notifier).updateProfile(profile);
if (mounted) {
Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Business profile updated successfully')),
);
}
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error: $e')),
);
}
} finally {
if (mounted) setState(() => _isLoading = false);
}
}
@override
Widget build(BuildContext context) {
final statesState = ref.watch(indianStatesProvider);
return Container(
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
),
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: DraggableScrollableSheet(
initialChildSize: 0.9,
minChildSize: 0.5,
maxChildSize: 0.95,
expand: false,
builder: (context, scrollController) {
return Column(
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('Business Profile', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
IconButton(
icon: const Icon(Icons.close),
onPressed: () => Navigator.pop(context),
),
],
),
),
const Divider(height: 1),
Expanded(
child: Form(
key: _formKey,
child: ListView(
controller: scrollController,
padding: const EdgeInsets.all(16),
children: [
TextFormField(
controller: _businessNameController,
decoration: InputDecoration(labelText: 'Company Name', border: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none),
enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none),
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: const BorderSide(color: Colors.blue, width: 2)),
contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
filled: true,
fillColor: Colors.grey[100]),
validator: (v) => v == null || v.isEmpty ? 'Company name is required' : null,
),
const SizedBox(height: 16),
TextFormField(
controller: _addressController,
decoration: InputDecoration(labelText: 'Address', border: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none),
enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none),
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: const BorderSide(color: Colors.blue, width: 2)),
contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
filled: true,
fillColor: Colors.grey[100]),
maxLines: 2,
),
const SizedBox(height: 16),
statesState.when(
data: (states) {
return DropdownButtonFormField<int>(
value: _selectedStateId,
decoration: InputDecoration(labelText: 'State', border: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none),
enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none),
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: const BorderSide(color: Colors.blue, width: 2)),
contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
filled: true,
fillColor: Colors.grey[100]),
items: states.map((s) {
return DropdownMenuItem(
value: s.id,
child: Text('${s.name} (${s.gstCode})'),
);
}).toList(),
onChanged: (val) {
setState(() {
_selectedStateId = val;
});
},
);
},
loading: () => const Center(
child: Padding(
padding: EdgeInsets.all(16.0),
child: CircularProgressIndicator(),
),
),
error: (e, stack) => Text('Failed to load states: $e', style: const TextStyle(color: Colors.red)),
),
const SizedBox(height: 16),
TextFormField(
controller: _contactPersonController,
decoration: InputDecoration(labelText: 'Contact Person', border: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none),
enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none),
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: const BorderSide(color: Colors.blue, width: 2)),
contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
filled: true,
fillColor: Colors.grey[100]),
),
const SizedBox(height: 16),
TextFormField(
controller: _contactNumberController,
decoration: InputDecoration(labelText: 'Contact Number', border: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none),
enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none),
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: const BorderSide(color: Colors.blue, width: 2)),
contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
filled: true,
fillColor: Colors.grey[100]),
keyboardType: TextInputType.phone,
),
const SizedBox(height: 16),
TextFormField(
controller: _emailController,
decoration: InputDecoration(labelText: 'Email ID', border: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none),
enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none),
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: const BorderSide(color: Colors.blue, width: 2)),
contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
filled: true,
fillColor: Colors.grey[100]),
keyboardType: TextInputType.emailAddress,
),
const SizedBox(height: 16),
TextFormField(
controller: _panController,
textCapitalization: TextCapitalization.characters,
decoration: InputDecoration(labelText: 'PAN Number', border: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none),
enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none),
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: const BorderSide(color: Colors.blue, width: 2)),
contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
filled: true,
fillColor: Colors.grey[100]),
validator: (v) {
if (v != null && v.isNotEmpty) {
final regex = RegExp(r'^[A-Z]{5}[0-9]{4}[A-Z]{1}$');
if (!regex.hasMatch(v.toUpperCase())) {
return 'Invalid PAN format';
}
}
return null;
},
),
const SizedBox(height: 16),
TextFormField(
controller: _gstinController,
textCapitalization: TextCapitalization.characters,
decoration: InputDecoration(labelText: 'GSTIN', border: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none),
enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: BorderSide.none),
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(16), borderSide: const BorderSide(color: Colors.blue, width: 2)),
contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
filled: true,
fillColor: Colors.grey[100]),
validator: (v) {
if (v != null && v.isNotEmpty) {
final regex = RegExp(r'^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$');
if (!regex.hasMatch(v.toUpperCase())) {
return 'Invalid GSTIN format';
}
}
return null;
},
),
const SizedBox(height: 24),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: _isLoading ? null : _submit,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
child: _isLoading
? const SizedBox(height: 20, width: 20, child: CircularProgressIndicator(color: Colors.white, strokeWidth: 2))
: const Text('Save Business Profile', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
),
),
const SizedBox(height: 32),
],
),
),
),
],
);
},
),
);
}
}