add suppliers and distributors
This commit is contained in:
parent
9cf3934f6f
commit
77fae74302
11 changed files with 426 additions and 33 deletions
|
|
@ -9,9 +9,11 @@ import 'package:pharmacy_mobile/blocs/caches/typelist/functions/cache_gettypelis
|
|||
import 'package:pharmacy_mobile/functions/barcode_scan_function.dart';
|
||||
import 'package:pharmacy_mobile/functions/checkresult_function.dart';
|
||||
import 'package:pharmacy_mobile/tables/ref_categories.dart';
|
||||
import 'package:pharmacy_mobile/tables/ref_distributors.dart';
|
||||
import 'package:pharmacy_mobile/tables/ref_generic_names.dart';
|
||||
import 'package:pharmacy_mobile/tables/ref_manufacturers.dart';
|
||||
import 'package:pharmacy_mobile/tables/ref_medicines.dart';
|
||||
import 'package:pharmacy_mobile/tables/ref_suppliers.dart';
|
||||
import 'package:pharmacy_mobile/tables/ref_types.dart';
|
||||
import 'package:pharmacy_mobile/tables/storage.dart';
|
||||
import 'package:pharmacy_mobile/widgets/button_widget.dart';
|
||||
|
|
@ -44,18 +46,24 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
final _refTypes = RefTypes();
|
||||
final _refManufacturer = RefManufacturers();
|
||||
final _refMedicines = RefMedicines();
|
||||
final _refDistributors = RefDistributors();
|
||||
final _refSuppliers = RefSuppliers();
|
||||
final _storage = Storage();
|
||||
final _nameController = TextEditingController();
|
||||
final _barcodeController = TextEditingController();
|
||||
bool _isLoading = false;
|
||||
|
||||
late bool _isLoading = false;
|
||||
late List _genericNameList = [];
|
||||
late String _selectedGeneric = '';
|
||||
late String _selectedCategory = '';
|
||||
late List _typeList = [];
|
||||
late String _selectedType = '';
|
||||
late List _manufacturerList = [];
|
||||
late List _distributorList = [];
|
||||
late List _supplierList = [];
|
||||
late String _selectedManufacturer = '';
|
||||
late String _selectedDistributor = '';
|
||||
late final String _selectedSupplier = '';
|
||||
late String uuid = '';
|
||||
late bool imageUploaded = false;
|
||||
late String imageUrl = '';
|
||||
|
|
@ -100,13 +108,27 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> _getManufacturer() async {
|
||||
Future<void> _getManufacturers() async {
|
||||
_manufacturerList = await _refManufacturer.getList();
|
||||
setState(() {
|
||||
checkResult(context, _manufacturerList, 'Manufacturer');
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _getDistributors() async {
|
||||
_distributorList = await _refDistributors.getList();
|
||||
setState(() {
|
||||
checkResult(context, _distributorList, 'Distributor');
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _getSuppliers() async {
|
||||
_supplierList = await _refSuppliers.getList();
|
||||
setState(() {
|
||||
checkResult(context, _supplierList, 'Supplier');
|
||||
});
|
||||
}
|
||||
|
||||
Future<bool> _getManufacturerCache() async {
|
||||
final cache = await cacheGetManufacturerList(context);
|
||||
|
||||
|
|
@ -120,28 +142,47 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
}
|
||||
|
||||
void autoRun() async {
|
||||
final generics = await _getGenericsCache();
|
||||
final types = await _getTypesCache();
|
||||
final manufacturers = await _getManufacturerCache();
|
||||
// final generics = await _getGenericsCache();
|
||||
// final types = await _getTypesCache();
|
||||
// final manufacturers = await _getManufacturerCache();
|
||||
|
||||
if (!generics || !types || !manufacturers) {
|
||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||
await _getGenerics();
|
||||
await _getTypes();
|
||||
await _getManufacturer();
|
||||
} else {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: No Internet Connection', false);
|
||||
// if (!generics || !types || !manufacturers) {
|
||||
// if (await InternetConnectionChecker.instance.hasConnection) {
|
||||
// await _getGenerics();
|
||||
// await _getTypes();
|
||||
// await _getManufacturers();
|
||||
// await _getDistributors();
|
||||
// } else {
|
||||
// if (mounted) {
|
||||
// showNotification(context, 'Error: No Internet Connection', false);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
context.pop();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// if (mounted) {
|
||||
// context.pop();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// setState(() {});
|
||||
// }
|
||||
|
||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||
await _getGenerics();
|
||||
await _getTypes();
|
||||
await _getManufacturers();
|
||||
await _getDistributors();
|
||||
await _getSuppliers();
|
||||
} else {
|
||||
setState(() {});
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: No Internet Connection', false);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
context.pop();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -161,6 +202,10 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
_selectedManufacturer = manufacturer;
|
||||
}
|
||||
|
||||
void _updateDistributor(dynamic distributor) {
|
||||
_selectedDistributor = distributor;
|
||||
}
|
||||
|
||||
Future<void> _scanBarcode() async {
|
||||
// String? barcode = await SimpleBarcodeScanner.scanBarcode(
|
||||
// context,
|
||||
|
|
@ -190,9 +235,11 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
final medGenericUUID = await _refGenericNames.getUUID(_selectedGeneric);
|
||||
final medTypeUUID = await _refTypes.getUUID(_selectedType);
|
||||
final medManufacturerUUID = await _refManufacturer.getUUID(_selectedManufacturer);
|
||||
final medDistributorUUID = await _refDistributors.getUUID(_selectedDistributor);
|
||||
final medSupplierUUID = await _refSuppliers.getUUID(_selectedSupplier);
|
||||
|
||||
final posted = await _refMedicines.postMedicine(
|
||||
uuid, medName, medManufacturerUUID, medGenericUUID, medTypeUUID, encrpytedBarcode);
|
||||
uuid, medName, medManufacturerUUID, medGenericUUID, medTypeUUID, encrpytedBarcode, medDistributorUUID, medSupplierUUID);
|
||||
|
||||
if (posted) {
|
||||
if (mounted) {
|
||||
|
|
@ -340,6 +387,13 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
onChanged: _updateManufacturer,
|
||||
),
|
||||
const Gap(16),
|
||||
DropDownWidget(
|
||||
label: 'Distributor',
|
||||
list: _distributorList,
|
||||
listTitle: 'distributor_name',
|
||||
onChanged: _updateDistributor,
|
||||
),
|
||||
const Gap(16),
|
||||
InputFormWidget(label: 'Barcode', controller: _barcodeController),
|
||||
ScanbarcodeWidget(onTap: _scanBarcode),
|
||||
const Gap(16),
|
||||
|
|
@ -367,11 +421,11 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
// else
|
||||
// ButtonWidget(text: 'Save Medicine', onPressed: _saveMedicine)
|
||||
if (uploaded)
|
||||
ButtonWithProgressWidget(
|
||||
trigger: _isLoading,
|
||||
progressText: 'Adding Medicine',
|
||||
buttonText: 'Save',
|
||||
onPressed: _saveMedicine)
|
||||
ButtonWithProgressWidget(
|
||||
trigger: _isLoading,
|
||||
progressText: 'Adding Medicine',
|
||||
buttonText: 'Save',
|
||||
onPressed: _saveMedicine)
|
||||
])
|
||||
])))
|
||||
]))));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue