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 medTypeUUID = await _refTypes.getUUID(_selectedType);
|
||||||
final medManufacturerUUID = await _refManufacturer.getUUID(_selectedManufacturer);
|
final medManufacturerUUID = await _refManufacturer.getUUID(_selectedManufacturer);
|
||||||
|
|
||||||
await _refMedicines.postMedicine(
|
final posted = await _refMedicines.postMedicine(
|
||||||
uuid, medName, medManufacturerUUID, medGenericUUID, medTypeUUID, encrpytedBarcode);
|
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 {
|
} else {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
showNotification(context, 'Error: No Internet Connection', false);
|
showNotification(context, 'Error: No Internet Connection', false);
|
||||||
|
|
|
||||||
|
|
@ -28,17 +28,20 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
||||||
late String imageUrl = '';
|
late String imageUrl = '';
|
||||||
late List _stockList = [];
|
late List _stockList = [];
|
||||||
late List _cartList = [];
|
late List _cartList = [];
|
||||||
// late final List _medicinesList = [];
|
|
||||||
|
|
||||||
Future<void> _getURL() async {
|
Future<String> _getURL(String imageName) async {
|
||||||
final image = await _storage.getImageURL('ref_medicines_images', '91ba5229-244b-4377-ba4e-9de57b9ba4df.webp');
|
final image = await _storage.getImageURL('ref_medicines_images', '$imageName.webp');
|
||||||
setState(() {
|
return image;
|
||||||
imageUrl = image;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _getAllStocks() async {
|
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 {
|
Future<String> _getCurrentUserId() async {
|
||||||
|
|
@ -79,7 +82,7 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
||||||
await _getAllStocks();
|
await _getAllStocks();
|
||||||
await _getCarts();
|
await _getCarts();
|
||||||
// // // await _getAllMedicines();
|
// // // await _getAllMedicines();
|
||||||
await _getURL();
|
// await _getURL();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -100,7 +103,7 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: CustomerPagebackgroundWidget(
|
body: CustomerPagebackgroundWidget(
|
||||||
height: MediaQuery.of(context).size.height + 800,
|
height: MediaQuery.of(context).size.height + 200,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Column(
|
Column(
|
||||||
|
|
@ -121,13 +124,13 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const Gap(32),
|
const Gap(32),
|
||||||
const IndicatorWidget(text: 'All Stocks'),
|
const IndicatorWidget(text: 'Prescribed Medicines'),
|
||||||
const Gap(8),
|
const Gap(8),
|
||||||
SingleChildScrollView(
|
SingleChildScrollView(
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
if (imageUrl.isEmpty)
|
if (_stockList.isEmpty)
|
||||||
const Row(
|
const Row(
|
||||||
children: [
|
children: [
|
||||||
ItemCardWidget(
|
ItemCardWidget(
|
||||||
|
|
@ -159,7 +162,7 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
||||||
else
|
else
|
||||||
for (var item in _stockList)
|
for (var item in _stockList)
|
||||||
ItemCardWidget(
|
ItemCardWidget(
|
||||||
imageUrl: imageUrl,
|
imageUrl: item['uuid'],
|
||||||
text: item['medicine_name'].toString(),
|
text: item['medicine_name'].toString(),
|
||||||
subtext: item['generic_name'].toString(),
|
subtext: item['generic_name'].toString(),
|
||||||
price: item['price'].toDouble(),
|
price: item['price'].toDouble(),
|
||||||
|
|
@ -169,137 +172,185 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
const Gap(16),
|
const Gap(16),
|
||||||
const IndicatorWidget(text: 'For Fever'),
|
const IndicatorWidget(text: 'All Stocks'),
|
||||||
const Gap(8),
|
const Gap(8),
|
||||||
SingleChildScrollView(
|
SingleChildScrollView(
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
ItemCardWidget(
|
if (_stockList.isEmpty)
|
||||||
imageUrl: imageUrl,
|
const Row(
|
||||||
text: 'sample',
|
children: [
|
||||||
subtext: 'generic_name',
|
ItemCardWidget(
|
||||||
price: 500,
|
imageUrl: 'imageUrl',
|
||||||
quantity: 0,
|
text: 'item[medicine_name]',
|
||||||
isLoading: imageUrl.isEmpty,
|
subtext: 'item[generic_name]',
|
||||||
cart: 2),
|
price: 123,
|
||||||
ItemCardWidget(
|
quantity: 123,
|
||||||
imageUrl: imageUrl,
|
isLoading: true,
|
||||||
text: 'sample',
|
cart: 0),
|
||||||
subtext: 'generic_name',
|
ItemCardWidget(
|
||||||
price: 500,
|
imageUrl: 'imageUrl',
|
||||||
quantity: 15,
|
text: 'item[medicine_name]',
|
||||||
isLoading: imageUrl.isEmpty,
|
subtext: 'item[generic_name]',
|
||||||
cart: 0),
|
price: 123,
|
||||||
ItemCardWidget(
|
quantity: 123,
|
||||||
imageUrl: imageUrl,
|
isLoading: true,
|
||||||
text: 'sample',
|
cart: 0),
|
||||||
subtext: 'generic_name',
|
ItemCardWidget(
|
||||||
price: 500,
|
imageUrl: 'imageUrl',
|
||||||
quantity: 15,
|
text: 'item[medicine_name]',
|
||||||
isLoading: imageUrl.isEmpty,
|
subtext: 'item[generic_name]',
|
||||||
cart: 0),
|
price: 123,
|
||||||
],
|
quantity: 123,
|
||||||
)),
|
isLoading: true,
|
||||||
const Gap(16),
|
cart: 0)
|
||||||
const IndicatorWidget(text: 'For Headaches'),
|
],
|
||||||
const Gap(8),
|
)
|
||||||
SingleChildScrollView(
|
else
|
||||||
scrollDirection: Axis.horizontal,
|
for (var item in _stockList)
|
||||||
child: Row(
|
ItemCardWidget(
|
||||||
children: [
|
imageUrl: item['uuid'].toString(),
|
||||||
ItemCardWidget(
|
text: item['medicine_name'].toString(),
|
||||||
imageUrl: imageUrl,
|
subtext: item['generic_name'].toString(),
|
||||||
text: 'sample',
|
price: item['price'].toDouble(),
|
||||||
subtext: 'generic_name',
|
quantity: item['quantity'].toDouble(),
|
||||||
price: 500,
|
isLoading: false,
|
||||||
quantity: 15,
|
cart: 0),
|
||||||
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),
|
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
|
// 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 = {
|
final medicine = {
|
||||||
'ref_medicines_uuid': uuid,
|
'ref_medicines_uuid': uuid,
|
||||||
'medicine_name': name,
|
'medicine_name': name,
|
||||||
'ref_manufactorers_uuid': muuid,
|
'ref_manufacturers_uuid': muuid,
|
||||||
'ref_generic_names_uuid': guuid,
|
'ref_generic_names_uuid': guuid,
|
||||||
'ref_types_uuid': tuuid,
|
'ref_types_uuid': tuuid,
|
||||||
'barcode': barcode
|
'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 {
|
Future<String> getUUID(String name) async {
|
||||||
try {
|
try {
|
||||||
final medUUID = await _supabase.from('ref_medicines').select('ref_medicines_uuid').eq('medicine_name', name);
|
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