fix saving of stocks

This commit is contained in:
Patrick Alvin Alcala 2025-04-07 17:50:55 +08:00
parent e8d0f213e9
commit efe74f9711
2 changed files with 20 additions and 4 deletions

View file

@ -31,7 +31,7 @@ class _AddStockPageState extends State<AddStockPage> 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<AddStockPage> 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<AddStockPage> with WidgetsBindingObserver
_selectedMedicine = '';
_quantityController.dispose();
_dateController.dispose();
_priceController.dispose();
super.dispose();
}
@ -220,6 +233,8 @@ class _AddStockPageState extends State<AddStockPage> 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))

View file

@ -69,14 +69,15 @@ class Stocks {
}
}
Future<bool> postStock(String muuid, String name, String quantity) async {
Future<bool> 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 {