fix saving and display of stocks
This commit is contained in:
parent
6c5e9f84d7
commit
e8d0f213e9
5 changed files with 255 additions and 138 deletions
|
|
@ -190,8 +190,20 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
final medTypeUUID = await _refTypes.getUUID(_selectedType);
|
||||
final medManufacturerUUID = await _refManufacturer.getUUID(_selectedManufacturer);
|
||||
|
||||
await _refMedicines.postMedicine(
|
||||
final posted = await _refMedicines.postMedicine(
|
||||
uuid, medName, medManufacturerUUID, medGenericUUID, medTypeUUID, encrpytedBarcode);
|
||||
|
||||
if (posted) {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Medicine Added Successfully', true);
|
||||
setState(() => _isLoading = false);
|
||||
context.pop();
|
||||
}
|
||||
} else {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: Medicine Not Added', false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: No Internet Connection', false);
|
||||
|
|
|
|||
|
|
@ -28,17 +28,20 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
|||
late String imageUrl = '';
|
||||
late List _stockList = [];
|
||||
late List _cartList = [];
|
||||
// late final List _medicinesList = [];
|
||||
|
||||
Future<void> _getURL() async {
|
||||
final image = await _storage.getImageURL('ref_medicines_images', '91ba5229-244b-4377-ba4e-9de57b9ba4df.webp');
|
||||
setState(() {
|
||||
imageUrl = image;
|
||||
});
|
||||
Future<String> _getURL(String imageName) async {
|
||||
final image = await _storage.getImageURL('ref_medicines_images', '$imageName.webp');
|
||||
return image;
|
||||
}
|
||||
|
||||
Future<void> _getAllStocks() async {
|
||||
_stockList = await _stocks.getList();
|
||||
_stockList = await _stocks.getListWithUUID();
|
||||
if (_stockList.isNotEmpty) {
|
||||
for (int i = 0; i < _stockList.length; i++) {
|
||||
_stockList[i]['uuid'] = await _getURL(_stockList[i]['uuid']);
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> _getCurrentUserId() async {
|
||||
|
|
@ -79,7 +82,7 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
|||
await _getAllStocks();
|
||||
await _getCarts();
|
||||
// // // await _getAllMedicines();
|
||||
await _getURL();
|
||||
// await _getURL();
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -100,7 +103,7 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
|||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: CustomerPagebackgroundWidget(
|
||||
height: MediaQuery.of(context).size.height + 800,
|
||||
height: MediaQuery.of(context).size.height + 200,
|
||||
child: Column(
|
||||
children: [
|
||||
Column(
|
||||
|
|
@ -121,13 +124,13 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
|||
),
|
||||
),
|
||||
const Gap(32),
|
||||
const IndicatorWidget(text: 'All Stocks'),
|
||||
const IndicatorWidget(text: 'Prescribed Medicines'),
|
||||
const Gap(8),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
if (imageUrl.isEmpty)
|
||||
if (_stockList.isEmpty)
|
||||
const Row(
|
||||
children: [
|
||||
ItemCardWidget(
|
||||
|
|
@ -159,7 +162,7 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
|||
else
|
||||
for (var item in _stockList)
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
imageUrl: item['uuid'],
|
||||
text: item['medicine_name'].toString(),
|
||||
subtext: item['generic_name'].toString(),
|
||||
price: item['price'].toDouble(),
|
||||
|
|
@ -169,137 +172,185 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
|||
],
|
||||
)),
|
||||
const Gap(16),
|
||||
const IndicatorWidget(text: 'For Fever'),
|
||||
const IndicatorWidget(text: 'All Stocks'),
|
||||
const Gap(8),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 0,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 2),
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 0),
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 0),
|
||||
],
|
||||
)),
|
||||
const Gap(16),
|
||||
const IndicatorWidget(text: 'For Headaches'),
|
||||
const Gap(8),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
if (_stockList.isEmpty)
|
||||
const Row(
|
||||
children: [
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
imageUrl: 'imageUrl',
|
||||
text: 'item[medicine_name]',
|
||||
subtext: 'item[generic_name]',
|
||||
price: 123,
|
||||
quantity: 123,
|
||||
isLoading: true,
|
||||
cart: 0),
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
imageUrl: 'imageUrl',
|
||||
text: 'item[medicine_name]',
|
||||
subtext: 'item[generic_name]',
|
||||
price: 123,
|
||||
quantity: 123,
|
||||
isLoading: true,
|
||||
cart: 0),
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 0),
|
||||
],
|
||||
)),
|
||||
const Gap(16),
|
||||
const IndicatorWidget(text: 'For Colds and Coughes'),
|
||||
const Gap(8),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 0),
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 0),
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 0),
|
||||
],
|
||||
)),
|
||||
const Gap(16),
|
||||
const IndicatorWidget(text: 'For Infection and Irritations'),
|
||||
const Gap(8),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 0),
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 0),
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
imageUrl: 'imageUrl',
|
||||
text: 'item[medicine_name]',
|
||||
subtext: 'item[generic_name]',
|
||||
price: 123,
|
||||
quantity: 123,
|
||||
isLoading: true,
|
||||
cart: 0)
|
||||
],
|
||||
)
|
||||
else
|
||||
for (var item in _stockList)
|
||||
ItemCardWidget(
|
||||
imageUrl: item['uuid'].toString(),
|
||||
text: item['medicine_name'].toString(),
|
||||
subtext: item['generic_name'].toString(),
|
||||
price: item['price'].toDouble(),
|
||||
quantity: item['quantity'].toDouble(),
|
||||
isLoading: false,
|
||||
cart: 0),
|
||||
],
|
||||
)),
|
||||
// const Gap(16),
|
||||
// const IndicatorWidget(text: 'For Fever'),
|
||||
// const Gap(8),
|
||||
// SingleChildScrollView(
|
||||
// scrollDirection: Axis.horizontal,
|
||||
// child: Row(
|
||||
// children: [
|
||||
// ItemCardWidget(
|
||||
// imageUrl: imageUrl,
|
||||
// text: 'sample',
|
||||
// subtext: 'generic_name',
|
||||
// price: 500,
|
||||
// quantity: 0,
|
||||
// isLoading: imageUrl.isEmpty,
|
||||
// cart: 2),
|
||||
// ItemCardWidget(
|
||||
// imageUrl: imageUrl,
|
||||
// text: 'sample',
|
||||
// subtext: 'generic_name',
|
||||
// price: 500,
|
||||
// quantity: 15,
|
||||
// isLoading: imageUrl.isEmpty,
|
||||
// cart: 0),
|
||||
// ItemCardWidget(
|
||||
// imageUrl: imageUrl,
|
||||
// text: 'sample',
|
||||
// subtext: 'generic_name',
|
||||
// price: 500,
|
||||
// quantity: 15,
|
||||
// isLoading: imageUrl.isEmpty,
|
||||
// cart: 0),
|
||||
// ],
|
||||
// )),
|
||||
// const Gap(16),
|
||||
// const IndicatorWidget(text: 'For Headaches'),
|
||||
// const Gap(8),
|
||||
// SingleChildScrollView(
|
||||
// scrollDirection: Axis.horizontal,
|
||||
// child: Row(
|
||||
// children: [
|
||||
// ItemCardWidget(
|
||||
// imageUrl: imageUrl,
|
||||
// text: 'sample',
|
||||
// subtext: 'generic_name',
|
||||
// price: 500,
|
||||
// quantity: 15,
|
||||
// isLoading: imageUrl.isEmpty,
|
||||
// cart: 0),
|
||||
// ItemCardWidget(
|
||||
// imageUrl: imageUrl,
|
||||
// text: 'sample',
|
||||
// subtext: 'generic_name',
|
||||
// price: 500,
|
||||
// quantity: 15,
|
||||
// isLoading: imageUrl.isEmpty,
|
||||
// cart: 0),
|
||||
// ItemCardWidget(
|
||||
// imageUrl: imageUrl,
|
||||
// text: 'sample',
|
||||
// subtext: 'generic_name',
|
||||
// price: 500,
|
||||
// quantity: 15,
|
||||
// isLoading: imageUrl.isEmpty,
|
||||
// cart: 0),
|
||||
// ],
|
||||
// )),
|
||||
// const Gap(16),
|
||||
// const IndicatorWidget(text: 'For Colds and Coughes'),
|
||||
// const Gap(8),
|
||||
// SingleChildScrollView(
|
||||
// scrollDirection: Axis.horizontal,
|
||||
// child: Row(
|
||||
// children: [
|
||||
// ItemCardWidget(
|
||||
// imageUrl: imageUrl,
|
||||
// text: 'sample',
|
||||
// subtext: 'generic_name',
|
||||
// price: 500,
|
||||
// quantity: 15,
|
||||
// isLoading: imageUrl.isEmpty,
|
||||
// cart: 0),
|
||||
// ItemCardWidget(
|
||||
// imageUrl: imageUrl,
|
||||
// text: 'sample',
|
||||
// subtext: 'generic_name',
|
||||
// price: 500,
|
||||
// quantity: 15,
|
||||
// isLoading: imageUrl.isEmpty,
|
||||
// cart: 0),
|
||||
// ItemCardWidget(
|
||||
// imageUrl: imageUrl,
|
||||
// text: 'sample',
|
||||
// subtext: 'generic_name',
|
||||
// price: 500,
|
||||
// quantity: 15,
|
||||
// isLoading: imageUrl.isEmpty,
|
||||
// cart: 0),
|
||||
// ],
|
||||
// )),
|
||||
// const Gap(16),
|
||||
// const IndicatorWidget(text: 'For Infection and Irritations'),
|
||||
// const Gap(8),
|
||||
// SingleChildScrollView(
|
||||
// scrollDirection: Axis.horizontal,
|
||||
// child: Row(
|
||||
// children: [
|
||||
// ItemCardWidget(
|
||||
// imageUrl: imageUrl,
|
||||
// text: 'sample',
|
||||
// subtext: 'generic_name',
|
||||
// price: 500,
|
||||
// quantity: 15,
|
||||
// isLoading: imageUrl.isEmpty,
|
||||
// cart: 0),
|
||||
// ItemCardWidget(
|
||||
// imageUrl: imageUrl,
|
||||
// text: 'sample',
|
||||
// subtext: 'generic_name',
|
||||
// price: 500,
|
||||
// quantity: 15,
|
||||
// isLoading: imageUrl.isEmpty,
|
||||
// cart: 0),
|
||||
// ItemCardWidget(
|
||||
// imageUrl: imageUrl,
|
||||
// text: 'sample',
|
||||
// subtext: 'generic_name',
|
||||
// price: 500,
|
||||
// quantity: 15,
|
||||
// isLoading: imageUrl.isEmpty,
|
||||
// cart: 0),
|
||||
// ],
|
||||
// )),
|
||||
],
|
||||
)
|
||||
],
|
||||
|
|
|
|||
27
lib/tables/prescriptions.dart
Normal file
27
lib/tables/prescriptions.dart
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class Prescriptions {
|
||||
final SupabaseClient _supabase = Supabase.instance.client;
|
||||
|
||||
Future<List> getPrescriptions(String uuid) async {
|
||||
try {
|
||||
final data = await _supabase.from('prescriptions').select('prescriptions_uuid').eq('user_id', uuid);
|
||||
return data.toList();
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> postPrescription(String userId, String medicineUuid) async {
|
||||
try {
|
||||
final prescriptionUUID = Uuid().v4();
|
||||
await _supabase
|
||||
.from('prescriptions')
|
||||
.insert({'prescriptions_uuid': prescriptionUUID, 'user_id': userId, 'ref_medicine_uuid': medicineUuid});
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -90,7 +90,7 @@ class RefMedicines {
|
|||
final medicine = {
|
||||
'ref_medicines_uuid': uuid,
|
||||
'medicine_name': name,
|
||||
'ref_manufactorers_uuid': muuid,
|
||||
'ref_manufacturers_uuid': muuid,
|
||||
'ref_generic_names_uuid': guuid,
|
||||
'ref_types_uuid': tuuid,
|
||||
'barcode': barcode
|
||||
|
|
|
|||
|
|
@ -29,6 +29,33 @@ class Stocks {
|
|||
}
|
||||
}
|
||||
|
||||
Future<List> getListWithUUID() async {
|
||||
List<Map<String, dynamic>> stockData = [];
|
||||
|
||||
try {
|
||||
final data = await _supabase
|
||||
.from('stocks')
|
||||
.select(
|
||||
'ref_medicines_uuid, ref_medicines(medicine_name, ref_generic_names(generic_name)), expiration_date, quantity, price')
|
||||
.order('ref_medicines(medicine_name)', ascending: true);
|
||||
|
||||
for (var item in data) {
|
||||
stockData.add({
|
||||
'uuid': item['ref_medicines_uuid'],
|
||||
'medicine_name': item['ref_medicines']['medicine_name'],
|
||||
'generic_name': item['ref_medicines']['ref_generic_names']['generic_name'],
|
||||
'expiration_date': item['expiration_date'],
|
||||
'quantity': item['quantity'],
|
||||
'price': item['price'],
|
||||
});
|
||||
}
|
||||
|
||||
return stockData;
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> getUUID(String name) async {
|
||||
try {
|
||||
final medUUID = await _supabase.from('ref_medicines').select('ref_medicines_uuid').eq('medicine_name', name);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue