diff --git a/lib/pages/add_stock_page.dart b/lib/pages/add_stock_page.dart index ca5c8b1..fddb1e9 100644 --- a/lib/pages/add_stock_page.dart +++ b/lib/pages/add_stock_page.dart @@ -31,7 +31,7 @@ class _AddStockPageState extends State with WidgetsBindingObserver final _refMedicines = RefMedicines(); final _quantityController = TextEditingController(); final _dateController = TextEditingController(); - // final _barcodeController = TextEditingController(); + final _priceController = TextEditingController(); final _stocks = Stocks(); late bool _isLoading = false; @@ -94,8 +94,20 @@ class _AddStockPageState extends State with WidgetsBindingObserver final stockNameUUID = await _refMedicines.getUUID(_selectedMedicine); final stockQuantity = _quantityController.text; final stockExpiration = _dateController.text; + final price = _priceController.text; - await _stocks.postStock(stockNameUUID, stockExpiration, stockQuantity); + final success = await _stocks.postStock(stockNameUUID, stockExpiration, stockQuantity, price); + if (success) { + if (mounted) { + showNotification(context, 'Stock added successfully', true); + setState(() => _isLoading = false); + context.pop(); + } + } else { + if (mounted) { + showNotification(context, 'Error: Stock not added', false); + } + } } else { if (mounted) { showNotification(context, 'Error: No Internet Connection', false); @@ -136,6 +148,7 @@ class _AddStockPageState extends State with WidgetsBindingObserver _selectedMedicine = ''; _quantityController.dispose(); _dateController.dispose(); + _priceController.dispose(); super.dispose(); } @@ -220,6 +233,8 @@ class _AddStockPageState extends State with WidgetsBindingObserver controller: _dateController, value: selectedDate, ), + const Gap(16), + InputFormWidget(label: 'Price', controller: _priceController), const Gap(32), if (_isLoading) const Center(child: CircularProgressIndicator(color: Colors.white)) diff --git a/lib/tables/stocks.dart b/lib/tables/stocks.dart index d16caa9..20e5fed 100644 --- a/lib/tables/stocks.dart +++ b/lib/tables/stocks.dart @@ -69,14 +69,15 @@ class Stocks { } } - Future postStock(String muuid, String name, String quantity) async { + Future postStock(String muuid, String name, String quantity, String price) async { final uuid = Uuid().v4(); final stock = { - 'stock_uuid': uuid, + 'stocks_uuid': uuid, 'ref_medicines_uuid': muuid, 'expiration_date': name, 'quantity': quantity, + 'price': price }; try {