2020-10-15 15:51:43 +06:30
|
|
|
<<<<<<< HEAD
|
2020-10-15 15:49:02 +06:30
|
|
|
import 'dart:ffi';
|
|
|
|
|
|
2020-10-15 15:51:43 +06:30
|
|
|
=======
|
2020-10-15 10:53:41 +06:30
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
|
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
2020-10-15 15:51:43 +06:30
|
|
|
>>>>>>> upstream/master
|
2020-10-15 15:49:02 +06:30
|
|
|
import 'package:fcs/data/services/services.dart';
|
2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/domain/entities/discount.dart';
|
|
|
|
|
import 'package:fcs/pages/main/model/base_model.dart';
|
2020-10-15 10:53:41 +06:30
|
|
|
import 'package:logging/logging.dart';
|
2020-06-26 16:04:40 +06:30
|
|
|
|
|
|
|
|
class DiscountModel extends BaseModel {
|
2020-10-15 10:53:41 +06:30
|
|
|
final log = Logger('DiscountModel');
|
|
|
|
|
|
|
|
|
|
StreamSubscription<QuerySnapshot> listener;
|
2020-06-26 16:04:40 +06:30
|
|
|
|
2020-10-15 15:51:43 +06:30
|
|
|
<<<<<<< HEAD
|
|
|
|
|
=======
|
2020-10-15 10:53:41 +06:30
|
|
|
List<Discount> discounts = [];
|
2020-06-26 16:04:40 +06:30
|
|
|
|
2020-10-15 15:51:43 +06:30
|
|
|
>>>>>>> upstream/master
|
2020-06-26 16:04:40 +06:30
|
|
|
void initUser(user) {
|
|
|
|
|
super.initUser(user);
|
2020-10-15 10:53:41 +06:30
|
|
|
_load();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_load() {
|
|
|
|
|
if (listener != null) listener.cancel();
|
|
|
|
|
try {
|
|
|
|
|
listener = Firestore.instance
|
|
|
|
|
.collection("/discounts")
|
|
|
|
|
.orderBy("code", descending: false)
|
|
|
|
|
.snapshots()
|
|
|
|
|
.listen((snaps) {
|
|
|
|
|
discounts.clear();
|
|
|
|
|
snaps.documents.forEach((d) {
|
|
|
|
|
discounts.add(Discount.fromMap(d.data, d.documentID));
|
|
|
|
|
});
|
|
|
|
|
notifyListeners();
|
|
|
|
|
});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
log.warning("error:$e");
|
|
|
|
|
}
|
2020-06-26 16:04:40 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
logout() async {
|
2020-10-15 10:53:41 +06:30
|
|
|
discounts = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> addDiscount(Discount discount) async {
|
|
|
|
|
return Services.instance.commonService.createDiscount(discount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> updateDiscount(Discount discount) async {
|
|
|
|
|
return Services.instance.commonService.updateDiscount(discount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> deleteDiscount(Discount discount) async {
|
|
|
|
|
return Services.instance.commonService.deleteDiscount(discount.id);
|
2020-06-26 16:04:40 +06:30
|
|
|
}
|
2020-10-15 15:49:02 +06:30
|
|
|
|
|
|
|
|
Future<void> addDiscount(Discount discount) {}
|
|
|
|
|
|
|
|
|
|
Future<void> updateDiscount(Discount discount) {}
|
|
|
|
|
|
|
|
|
|
Future<void> deleteCargoType(String id) {}
|
2020-06-26 16:04:40 +06:30
|
|
|
}
|