update
This commit is contained in:
parent
d3a4b45603
commit
28cb4cac67
4 changed files with 101 additions and 9 deletions
|
|
@ -10,9 +10,11 @@ import 'package:pharmacy_mobile/widgets/dropdown_wrappermulti_widget.dart';
|
|||
import 'package:pharmacy_mobile/widgets/form_border_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/input_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/page_background_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/snackbar_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/text_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/title_widget.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:pharmacy_mobile/widgets/warning_widget.dart';
|
||||
|
||||
class DeleteStockPage extends StatefulWidget {
|
||||
const DeleteStockPage({super.key});
|
||||
|
|
@ -28,6 +30,10 @@ class _DeleteStockPageState extends State<DeleteStockPage> {
|
|||
|
||||
late List _stockList = [];
|
||||
late String _selectedStock = '';
|
||||
late bool _aboveQuantity = false;
|
||||
late bool _noStock = false;
|
||||
late double _serverQuantity = 0;
|
||||
late String _selectedUUID = '';
|
||||
|
||||
void _getStocks() async {
|
||||
_stockList = await _stocks.getList();
|
||||
|
|
@ -49,14 +55,49 @@ class _DeleteStockPageState extends State<DeleteStockPage> {
|
|||
_getQuantity(_selectedStock);
|
||||
}
|
||||
|
||||
// void _saveDeletion() async {
|
||||
// _stocks.deleteStock('uuid');
|
||||
// }
|
||||
void _saveDeletion() async {
|
||||
final newQuantity = _serverQuantity - double.parse(_quantityController.text);
|
||||
final newQuantityFixed = newQuantity.toStringAsFixed(0);
|
||||
// log(newQuantityFixed);
|
||||
try {
|
||||
_stocks.updateStock(_selectedUUID, 'quantity', newQuantityFixed);
|
||||
if (mounted) {
|
||||
showNotification(context, '$_selectedStock updated', true);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
context.pop();
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: $e', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _getQuantity(String name) async {
|
||||
final uuid = await _stocks.getUUID(name);
|
||||
final quantity = await _stocks.getQuantity(uuid);
|
||||
log(quantity);
|
||||
_serverQuantity = double.parse(quantity);
|
||||
_selectedUUID = uuid;
|
||||
}
|
||||
|
||||
void _setQuantity(dynamic quantity) async {
|
||||
if (_selectedStock.isEmpty) {
|
||||
_noStock = true;
|
||||
setState(() {});
|
||||
} else {
|
||||
_noStock = false;
|
||||
if (double.parse(quantity) > _serverQuantity) {
|
||||
_aboveQuantity = true;
|
||||
setState(() {});
|
||||
} else {
|
||||
_aboveQuantity = false;
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -95,9 +136,20 @@ class _DeleteStockPageState extends State<DeleteStockPage> {
|
|||
DropDownWidget(
|
||||
label: 'Stocks', list: _stockList, listTitle: 'medicine_name', onChanged: _updateStock),
|
||||
const Gap(16),
|
||||
InputWidget(label: 'Quantity', controller: _quantityController),
|
||||
InputWidget(label: 'Quantity', controller: _quantityController, onChanged: _setQuantity),
|
||||
const Gap(32),
|
||||
// ButtonWidget(text: 'Remove Stock', onPressed: (_) => {})
|
||||
if (_noStock)
|
||||
WarningWidget(
|
||||
text: 'Removing Disabled',
|
||||
warning: 'Quantity is above sssss',
|
||||
)
|
||||
else if (_aboveQuantity)
|
||||
WarningWidget(
|
||||
text: 'Removing Disabled',
|
||||
warning: 'Quantity is above stocked',
|
||||
)
|
||||
else
|
||||
ButtonWidget(text: 'Remove Stock', onPressed: _saveDeletion)
|
||||
])
|
||||
],
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue