update
This commit is contained in:
parent
27f00e43a7
commit
3572f90b24
24 changed files with 290 additions and 257 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue