fix saving and display of stocks
This commit is contained in:
parent
6c5e9f84d7
commit
e8d0f213e9
5 changed files with 255 additions and 138 deletions
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