update
This commit is contained in:
parent
27f00e43a7
commit
3572f90b24
24 changed files with 290 additions and 257 deletions
|
|
@ -44,13 +44,4 @@ class RefGenericNames {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List> getSample() async {
|
||||
try {
|
||||
final data = await _supabase.from('ref_generic_names').select('''generic_name, ref_categories(category_name)''');
|
||||
return data.toList();
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,41 @@
|
|||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class RefManufactorers {
|
||||
final SupabaseClient _supabase = Supabase.instance.client;
|
||||
|
||||
Future<List> getList() async {
|
||||
final data = await _supabase
|
||||
.from('ref_manufactorers')
|
||||
.select('manufactorer_name')
|
||||
.order('manufactorer_name', ascending: true);
|
||||
return data.toList();
|
||||
try {
|
||||
final data = await _supabase
|
||||
.from('ref_manufactorers')
|
||||
.select('manufactorer_name')
|
||||
.order('manufactorer_name', ascending: true);
|
||||
return data.toList();
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> getUUID(String name) async {
|
||||
final data =
|
||||
await _supabase.from('ref_manufactorers').select('ref_manufactorers_uuid').eq('manufactorer_name', name);
|
||||
return data.first['ref_manufactorers_uuid'].toString();
|
||||
try {
|
||||
final data =
|
||||
await _supabase.from('ref_manufactorers').select('ref_manufactorers_uuid').eq('manufactorer_name', name);
|
||||
return data.first['ref_manufactorers_uuid'].toString();
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> postManufactorer(String name, String address) async {
|
||||
try {
|
||||
final genericUUID = Uuid().v4();
|
||||
|
||||
await _supabase
|
||||
.from('ref_manufactorers')
|
||||
.insert({'ref_manufactorers_uuid': genericUUID, 'manufactorer_name': name, 'manufactorer_address': address});
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,37 +4,48 @@ class RefMedicines {
|
|||
final SupabaseClient _supabase = Supabase.instance.client;
|
||||
|
||||
Future<List> getList() async {
|
||||
final data = await _supabase.from('ref_medicines').select('medicine_name').order('medicine_name', ascending: true);
|
||||
return data.toList();
|
||||
}
|
||||
|
||||
Future<List> getList2() async {
|
||||
final data = await _supabase
|
||||
.from('ref_medicines')
|
||||
.select('medicine_name, ref_manufactorers(manufactorer_name)')
|
||||
.order('medicine_name', ascending: true);
|
||||
return data.toList();
|
||||
try {
|
||||
final data = await _supabase
|
||||
.from('ref_medicines')
|
||||
.select('medicine_name, ref_manufactorers(manufactorer_name)')
|
||||
.order('medicine_name', ascending: true);
|
||||
return data.toList();
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Future<List> getListWithUUID() async {
|
||||
final data = await _supabase
|
||||
.from('ref_medicines')
|
||||
.select('ref_medicines_uuid, medicine_name')
|
||||
.order('medicine_name', ascending: true);
|
||||
return data.toList();
|
||||
try {
|
||||
final data = await _supabase
|
||||
.from('ref_medicines')
|
||||
.select('ref_medicines_uuid, medicine_name')
|
||||
.order('medicine_name', ascending: true);
|
||||
return data.toList();
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> getUUID(String name) async {
|
||||
final data = await _supabase.from('ref_medicines').select('ref_medicines_uuid').eq('medicine_name', name);
|
||||
return data.first['ref_medicines_uuid'];
|
||||
try {
|
||||
final data = await _supabase.from('ref_medicines').select('ref_medicines_uuid').eq('medicine_name', name);
|
||||
return data.first['ref_medicines_uuid'];
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> getBarcode(String name) async {
|
||||
final data = await _supabase.from('ref_medicines').select('barcode').eq('medicine_name', name);
|
||||
return data.first['barcode'];
|
||||
try {
|
||||
final data = await _supabase.from('ref_medicines').select('barcode').eq('medicine_name', name);
|
||||
return data.first['barcode'];
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> postMedicine(String uuid, String name, String muuid, String guuid, String tuuid, String barcode) async {
|
||||
Future<bool> postMedicine(String uuid, String name, String muuid, String guuid, String tuuid, String barcode) async {
|
||||
final medicine = {
|
||||
'ref_medicines_uuid': uuid,
|
||||
'medicine_name': name,
|
||||
|
|
@ -44,6 +55,11 @@ class RefMedicines {
|
|||
'barcode': barcode
|
||||
};
|
||||
|
||||
await _supabase.from('ref_medicines').insert(medicine);
|
||||
try {
|
||||
await _supabase.from('ref_medicines').insert(medicine);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,18 +5,31 @@ class RefTypes {
|
|||
final SupabaseClient _supabase = Supabase.instance.client;
|
||||
|
||||
Future<List> getList() async {
|
||||
final data = await _supabase.from('ref_types').select('type_name').order('type_name', ascending: true);
|
||||
return data.toList();
|
||||
try {
|
||||
final data = await _supabase.from('ref_types').select('type_name').order('type_name', ascending: true);
|
||||
return data.toList();
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> getUUID(String name) async {
|
||||
final data = await _supabase.from('ref_types').select('ref_types_uuid').eq('type_name', name);
|
||||
return data.first['ref_types_uuid'].toString();
|
||||
try {
|
||||
final data = await _supabase.from('ref_types').select('ref_types_uuid').eq('type_name', name);
|
||||
return data.first['ref_types_uuid'].toString();
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> postType(String name) async {
|
||||
Future<bool> postType(String name) async {
|
||||
final typeUUID = Uuid().v4();
|
||||
|
||||
await _supabase.from('ref_types').insert({'ref_types_uuid': typeUUID, 'type_name': name});
|
||||
try {
|
||||
await _supabase.from('ref_types').insert({'ref_types_uuid': typeUUID, 'type_name': name});
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,31 +9,39 @@ class Stocks {
|
|||
Future<List> getList() async {
|
||||
List<Map<String, dynamic>> stockData = [];
|
||||
|
||||
final data =
|
||||
await _supabase.from('stocks').select('ref_medicines(medicine_name), expiration_date, quantity, price');
|
||||
try {
|
||||
final data =
|
||||
await _supabase.from('stocks').select('ref_medicines(medicine_name), expiration_date, quantity, price');
|
||||
|
||||
for (var item in data) {
|
||||
stockData.add({
|
||||
'medicine_name': item['ref_medicines']['medicine_name'],
|
||||
'quantity': item['quantity'].toString(),
|
||||
'expiration_date': item['expiration_date'],
|
||||
'price': item['price'],
|
||||
});
|
||||
for (var item in data) {
|
||||
stockData.add({
|
||||
'medicine_name': item['ref_medicines']['medicine_name'],
|
||||
'quantity': item['quantity'].toString(),
|
||||
'expiration_date': item['expiration_date'],
|
||||
'price': item['price'],
|
||||
});
|
||||
}
|
||||
|
||||
return stockData;
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return stockData;
|
||||
}
|
||||
|
||||
Future<String> getUUID(String name) async {
|
||||
final medUUID = await _supabase.from('ref_medicines').select('ref_medicines_uuid').eq('medicine_name', name);
|
||||
final data = await _supabase
|
||||
.from('stocks')
|
||||
.select('stocks_uuid')
|
||||
.eq('ref_medicines_uuid', medUUID.first['ref_medicines_uuid']);
|
||||
return data.first['stocks_uuid'].toString();
|
||||
try {
|
||||
final medUUID = await _supabase.from('ref_medicines').select('ref_medicines_uuid').eq('medicine_name', name);
|
||||
final data = await _supabase
|
||||
.from('stocks')
|
||||
.select('stocks_uuid')
|
||||
.eq('ref_medicines_uuid', medUUID.first['ref_medicines_uuid']);
|
||||
return data.first['stocks_uuid'].toString();
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> postStock(String muuid, String name, String quantity) async {
|
||||
Future<bool> postStock(String muuid, String name, String quantity) async {
|
||||
final uuid = Uuid().v4();
|
||||
|
||||
final stock = {
|
||||
|
|
@ -43,15 +51,29 @@ class Stocks {
|
|||
'quantity': quantity,
|
||||
};
|
||||
|
||||
await _supabase.from('stocks').insert(stock);
|
||||
try {
|
||||
await _supabase.from('stocks').insert(stock);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> getQuantity(String uuid) async {
|
||||
final data = await _supabase.from('stocks').select('quantity').eq('stocks_uuid', uuid);
|
||||
return data.first['quantity'].toString();
|
||||
try {
|
||||
final data = await _supabase.from('stocks').select('quantity').eq('stocks_uuid', uuid);
|
||||
return data.first['quantity'].toString();
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateStock(String uuid, String column, String value) async {
|
||||
await _supabase.from('stocks').update({column: value}).eq('stocks_uuid', uuid).select();
|
||||
Future<bool> updateStock(String uuid, String column, String value) async {
|
||||
try {
|
||||
await _supabase.from('stocks').update({column: value}).eq('stocks_uuid', uuid).select();
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,69 +1,47 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:pharmacy_mobile/widgets/snackbar_widget.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
class Storage {
|
||||
final SupabaseClient _supabase = Supabase.instance.client;
|
||||
|
||||
Future<String> createBucket(String name) async {
|
||||
Future<bool> createBucket(String name) async {
|
||||
try {
|
||||
final response = await _supabase.storage.createBucket(name);
|
||||
return response;
|
||||
} catch (e, stackTrace) {
|
||||
log('Error creating bucket: $e', stackTrace: stackTrace);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List> getList() async {
|
||||
try {
|
||||
final response = await _supabase.storage.listBuckets();
|
||||
return response;
|
||||
} catch (e, stackTrace) {
|
||||
log('Error getting list: $e', stackTrace: stackTrace);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> uploadFile(XFile image, String name) async {
|
||||
try {
|
||||
final imageString = await image.readAsString(encoding: utf8);
|
||||
final imageFile = File(imageString);
|
||||
await _supabase.storage.from('images').upload(name, imageFile);
|
||||
log('upload Complete');
|
||||
return response.isNotEmpty;
|
||||
} catch (e) {
|
||||
log('Error getting list: $e');
|
||||
rethrow;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> uploadImage(BuildContext context, String storage, Uint8List image, String name) async {
|
||||
Future<bool> uploadImage(BuildContext context, String storage, Uint8List image, String name) async {
|
||||
try {
|
||||
final imageBytes = image;
|
||||
final imagePath = name;
|
||||
|
||||
await _supabase.storage.from(storage).uploadBinary(imagePath, imageBytes);
|
||||
final imageUrl = _supabase.storage.from(storage).getPublicUrl(imagePath);
|
||||
return imageUrl;
|
||||
return imageUrl.isNotEmpty;
|
||||
} catch (e) {
|
||||
// ignore: use_build_context_synchronously
|
||||
showNotification(context, 'Error uploading image: $e', false);
|
||||
rethrow;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<Uint8List> downloadImage(String storage, String name) async {
|
||||
final Uint8List file = await _supabase.storage.from(storage).download(name);
|
||||
return file;
|
||||
try {
|
||||
final Uint8List file = await _supabase.storage.from(storage).download(name);
|
||||
return file;
|
||||
} catch (e) {
|
||||
return Uint8List(0);
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> getPublicURL(String storage, String name) async {
|
||||
final String file = _supabase.storage.from(storage).getPublicUrl(name);
|
||||
return file;
|
||||
try {
|
||||
final String file = _supabase.storage.from(storage).getPublicUrl(name);
|
||||
return file;
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue