add carton api
This commit is contained in:
@@ -4,11 +4,8 @@ import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:fcs/data/services/services.dart';
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
import 'package:fcs/domain/entities/carton.dart';
|
||||
import 'package:fcs/domain/entities/cargo_type.dart';
|
||||
import 'package:fcs/domain/entities/package.dart';
|
||||
import 'package:fcs/domain/vo/message.dart';
|
||||
import 'package:fcs/domain/vo/shipment_status.dart';
|
||||
import 'package:fcs/domain/vo/delivery_address.dart';
|
||||
import 'package:fcs/helpers/paginator.dart';
|
||||
import 'package:fcs/pages/main/model/base_model.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
@@ -30,261 +27,6 @@ class CartonModel extends BaseModel {
|
||||
ShipmentStatus(
|
||||
status: "Delivered", date: DateTime(2020, 6, 15), done: false)
|
||||
];
|
||||
static List<Package> packages = [
|
||||
// PackageModel.packages[0],
|
||||
// PackageModel.packages[1],
|
||||
// PackageModel.packages[2]
|
||||
];
|
||||
|
||||
List<Carton> boxeList = [
|
||||
Carton(
|
||||
shipmentNumber: "A202",
|
||||
receiverNumber: "3",
|
||||
receiverName: "Ko Myo Min",
|
||||
boxNumber: "1",
|
||||
rate: 7,
|
||||
packageType: "General",
|
||||
weight: 75,
|
||||
status: "Packed",
|
||||
receiverAddress: '1 Bo Yar Nyunt St.\nDagon Tsp, Yangon',
|
||||
cargoDesc: "Clothes",
|
||||
desc: "Desc 1",
|
||||
cartonType: carton_from_packages,
|
||||
arrivedDate: DateTime(2020, 6, 1),
|
||||
width: 10,
|
||||
height: 10,
|
||||
length: 10,
|
||||
shipmentWeight: 6,
|
||||
packages: packages,
|
||||
shipmentHistory: statusHistory,
|
||||
deliveryAddress: DeliveryAddress(
|
||||
fullName: 'U Nyi Nyi',
|
||||
addressLine1: '154-19 64th Ave.',
|
||||
addressLine2: 'Flushing',
|
||||
city: 'NY',
|
||||
state: 'NY',
|
||||
phoneNumber: '+1 (292)215-2247'),
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous', weight: 30)
|
||||
]),
|
||||
Carton(
|
||||
shipmentNumber: "A203",
|
||||
receiverNumber: "3",
|
||||
receiverName: "Ko Myo Min",
|
||||
boxNumber: "2",
|
||||
rate: 7,
|
||||
packageType: "General",
|
||||
weight: 75,
|
||||
status: "Packed",
|
||||
cargoDesc: "Clothes",
|
||||
desc: "Desc 2",
|
||||
arrivedDate: DateTime(2020, 6, 1),
|
||||
width: 10,
|
||||
height: 20,
|
||||
length: 30,
|
||||
shipmentWeight: 36,
|
||||
shipmentHistory: statusHistory,
|
||||
packages: packages,
|
||||
receiverAddress: '1 Bo Yar Nyunt St.\nDagon Tsp, Yangon',
|
||||
cartonType: carton_from_shipments,
|
||||
deliveryAddress: DeliveryAddress(
|
||||
fullName: 'Mg Myo',
|
||||
addressLine1: '153-154 5th Thitsar.',
|
||||
addressLine2: 'South Okkalapa Township',
|
||||
city: 'Yangon',
|
||||
state: 'Myanmar',
|
||||
phoneNumber: '+09 95724 8750'),
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous', weight: 30)
|
||||
]),
|
||||
Carton(
|
||||
shipmentNumber: "A204",
|
||||
receiverNumber: "3",
|
||||
receiverName: "Ko Myo Min",
|
||||
boxNumber: "3",
|
||||
rate: 7,
|
||||
packageType: "General",
|
||||
weight: 75,
|
||||
cargoDesc: "Shoes",
|
||||
status: "Packed",
|
||||
desc: "Desc 3",
|
||||
cartonType: carton_mix_box,
|
||||
arrivedDate: DateTime(2020, 6, 1),
|
||||
width: 10,
|
||||
height: 10,
|
||||
length: 10,
|
||||
shipmentWeight: 6,
|
||||
shipmentHistory: statusHistory,
|
||||
packages: packages,
|
||||
receiverAddress: '1 Bo Yar Nyunt St.\nDagon Tsp, Yangon',
|
||||
deliveryAddress: DeliveryAddress(
|
||||
fullName: 'Mg Myo',
|
||||
addressLine1: '153-154 5th Thitsar.',
|
||||
addressLine2: 'South Okkalapa Township',
|
||||
city: 'Yangon',
|
||||
state: 'Myanmar',
|
||||
phoneNumber: '+09 95724 8750'),
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous', weight: 30)
|
||||
]),
|
||||
Carton(
|
||||
shipmentNumber: "A202",
|
||||
receiverNumber: "2",
|
||||
receiverName: "Ma Aye",
|
||||
boxNumber: "1",
|
||||
rate: 8,
|
||||
packageType: "Medicine",
|
||||
weight: 75,
|
||||
status: "Packed",
|
||||
cargoDesc: "Dietary supplement",
|
||||
desc: "Desc 4",
|
||||
arrivedDate: DateTime(2020, 6, 1),
|
||||
width: 10,
|
||||
height: 10,
|
||||
length: 10,
|
||||
shipmentWeight: 6,
|
||||
shipmentHistory: statusHistory,
|
||||
packages: packages,
|
||||
receiverAddress: '2 Shwe Taung Kyar St, Bahan Tsp, Yangon',
|
||||
deliveryAddress: DeliveryAddress(
|
||||
fullName: 'U Nyi Nyi',
|
||||
addressLine1: '154-19 64th Ave.',
|
||||
addressLine2: 'Flushing',
|
||||
city: 'NY',
|
||||
state: 'NY',
|
||||
phoneNumber: '+1 (292)215-2247'),
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous', weight: 30)
|
||||
]),
|
||||
Carton(
|
||||
shipmentNumber: "A202",
|
||||
receiverNumber: "2",
|
||||
receiverName: "Ma Aye",
|
||||
boxNumber: "3",
|
||||
rate: 7,
|
||||
packageType: "General",
|
||||
cargoDesc: "Handbags",
|
||||
weight: 75,
|
||||
status: "Arrived",
|
||||
arrivedDate: DateTime(2020, 6, 1),
|
||||
width: 10,
|
||||
height: 10,
|
||||
length: 10,
|
||||
shipmentWeight: 6,
|
||||
shipmentHistory: statusHistory,
|
||||
packages: packages,
|
||||
receiverAddress: '2 Shwe Taung Kyar St, Bahan Tsp, Yangon',
|
||||
deliveryAddress: DeliveryAddress(
|
||||
fullName: 'U Nyi Nyi',
|
||||
addressLine1: '154-19 64th Ave.',
|
||||
addressLine2: 'Flushing',
|
||||
city: 'NY',
|
||||
state: 'NY',
|
||||
phoneNumber: '+1 (292)215-2247'),
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous', weight: 30)
|
||||
]),
|
||||
Carton(
|
||||
shipmentNumber: "A202",
|
||||
receiverNumber: "2",
|
||||
receiverName: "Ma Aye",
|
||||
boxNumber: "2",
|
||||
rate: 7,
|
||||
packageType: "General",
|
||||
cargoDesc: "Handbags",
|
||||
weight: 75,
|
||||
status: "Shipped",
|
||||
arrivedDate: DateTime(2020, 6, 1),
|
||||
width: 10,
|
||||
height: 10,
|
||||
length: 10,
|
||||
shipmentWeight: 6,
|
||||
shipmentHistory: statusHistory,
|
||||
packages: packages,
|
||||
receiverAddress: '2 Shwe Taung Kyar St, Bahan Tsp, Yangon',
|
||||
deliveryAddress: DeliveryAddress(
|
||||
fullName: 'U Nyi Nyi',
|
||||
addressLine1: '154-19 64th Ave.',
|
||||
addressLine2: 'Flushing',
|
||||
city: 'NY',
|
||||
state: 'NY',
|
||||
phoneNumber: '+1 (292)215-2247'),
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous', weight: 30)
|
||||
]),
|
||||
Carton(
|
||||
shipmentNumber: "A201",
|
||||
receiverNumber: "1",
|
||||
receiverName: "Ko Wai",
|
||||
boxNumber: "1",
|
||||
rate: 9,
|
||||
packageType: "Dangerous",
|
||||
cargoDesc: "Phones and Scooters",
|
||||
weight: 75,
|
||||
status: "Delivered",
|
||||
arrivedDate: DateTime(2020, 5, 21),
|
||||
width: 10,
|
||||
height: 10,
|
||||
length: 10,
|
||||
shipmentWeight: 6,
|
||||
shipmentHistory: statusHistory,
|
||||
packages: packages,
|
||||
receiverAddress: '3 Kambzwza St, Bahan Tsp, Yangon',
|
||||
deliveryAddress: DeliveryAddress(
|
||||
fullName: 'U Nyi Nyi',
|
||||
addressLine1: '154-19 64th Ave.',
|
||||
addressLine2: 'Flushing',
|
||||
city: 'NY',
|
||||
state: 'NY',
|
||||
phoneNumber: '+1 (292)215-2247'),
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous', weight: 30)
|
||||
]),
|
||||
Carton(
|
||||
shipmentNumber: "A201",
|
||||
receiverNumber: "1",
|
||||
receiverName: "Ko Wai",
|
||||
boxNumber: "2",
|
||||
rate: 7,
|
||||
packageType: "General",
|
||||
cargoDesc: "Construction tools",
|
||||
weight: 75,
|
||||
status: "Delivered",
|
||||
arrivedDate: DateTime(2020, 5, 21),
|
||||
width: 10,
|
||||
height: 10,
|
||||
length: 10,
|
||||
shipmentWeight: 6,
|
||||
shipmentHistory: statusHistory,
|
||||
packages: packages,
|
||||
receiverAddress: '3 Kambzwza St, Bahan Tsp, Yangon',
|
||||
deliveryAddress: DeliveryAddress(
|
||||
fullName: 'U Nyi Nyi',
|
||||
addressLine1: '154-19 64th Ave.',
|
||||
addressLine2: 'Flushing',
|
||||
city: 'NY',
|
||||
state: 'NY',
|
||||
phoneNumber: '+1 (292)215-2247'),
|
||||
cargoTypes: [
|
||||
CargoType(name: 'General', weight: 25),
|
||||
CargoType(name: 'Medicine', weight: 20),
|
||||
CargoType(name: 'Dangerous', weight: 30)
|
||||
]),
|
||||
];
|
||||
|
||||
List<Carton> get completed {
|
||||
return boxes.where((e) => e.status == "Delivered").toList()
|
||||
@@ -314,6 +56,11 @@ class CartonModel extends BaseModel {
|
||||
}
|
||||
|
||||
List<String> cartonTypes = [carton_from_packages, carton_mix_box];
|
||||
List<String> cartonTypesInfo = [
|
||||
carton_from_packages,
|
||||
carton_mix_box,
|
||||
carton_from_shipments
|
||||
];
|
||||
|
||||
set selectedIndex(int index) {
|
||||
_selectedIndex = index;
|
||||
@@ -362,16 +109,20 @@ class CartonModel extends BaseModel {
|
||||
try {
|
||||
listener = Firestore.instance
|
||||
.collection("$path")
|
||||
.where("status",
|
||||
whereIn: [carton_packed_status, carton_shipped_status])
|
||||
.where("is_deleted", isEqualTo: false)
|
||||
.orderBy("created_at", descending: true)
|
||||
.snapshots()
|
||||
.listen((QuerySnapshot snapshot) {
|
||||
_boxes.clear();
|
||||
_boxes = snapshot.documents.map((documentSnapshot) {
|
||||
var s = Carton.fromMap(
|
||||
documentSnapshot.data, documentSnapshot.documentID);
|
||||
return s;
|
||||
}).toList();
|
||||
notifyListeners();
|
||||
});
|
||||
_boxes.clear();
|
||||
_boxes = snapshot.documents.map((documentSnapshot) {
|
||||
var s = Carton.fromMap(
|
||||
documentSnapshot.data, documentSnapshot.documentID);
|
||||
return s;
|
||||
}).toList();
|
||||
notifyListeners();
|
||||
});
|
||||
} catch (e) {
|
||||
log.warning("Error!! $e");
|
||||
}
|
||||
@@ -391,7 +142,7 @@ class CartonModel extends BaseModel {
|
||||
}
|
||||
|
||||
Future<void> loadMore() async {
|
||||
if (_delivered.ended) return;
|
||||
if (_delivered.ended || selectedIndex == 1) return;
|
||||
isLoading = true;
|
||||
notifyListeners();
|
||||
await _delivered.load(onFinished: () {
|
||||
@@ -401,6 +152,7 @@ class CartonModel extends BaseModel {
|
||||
}
|
||||
|
||||
Future<void> refresh() async {
|
||||
if (selectedIndex == 1) return;
|
||||
await _delivered.refresh(onFinished: () {
|
||||
notifyListeners();
|
||||
});
|
||||
@@ -428,6 +180,24 @@ class CartonModel extends BaseModel {
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<List<Carton>> getCartonsByFcsShipment(String fcsShipmentID) async {
|
||||
String path = "/$cartons_collection";
|
||||
var querySnap = await Firestore.instance
|
||||
.collection(path)
|
||||
.where("fcs_shipment_id", isEqualTo: fcsShipmentID)
|
||||
.where("is_deleted", isEqualTo: false)
|
||||
.getDocuments();
|
||||
return querySnap.documents
|
||||
.map((e) => Carton.fromMap(e.data, e.documentID))
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<Carton> getCarton(String id) async {
|
||||
String path = "/$cartons_collection";
|
||||
var snap = await Firestore.instance.collection(path).document(id).get();
|
||||
return Carton.fromMap(snap.data, snap.documentID);
|
||||
}
|
||||
|
||||
Future<void> createCarton(Carton carton) {
|
||||
return Services.instance.cartonService.createCarton(carton);
|
||||
}
|
||||
@@ -435,4 +205,8 @@ class CartonModel extends BaseModel {
|
||||
Future<void> updateCarton(Carton carton) {
|
||||
return Services.instance.cartonService.updateCarton(carton);
|
||||
}
|
||||
|
||||
Future<void> deleteCarton(Carton carton) {
|
||||
return Services.instance.cartonService.deleteCarton(carton);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user