This commit is contained in:
Phaung Phaung
2021-09-13 09:55:23 +06:30
8 changed files with 33 additions and 27 deletions

View File

@@ -69,6 +69,7 @@ const privilege_delivery = "deli";
const privilege_invoice = "inv";
const privilege_processing = "pr";
const privilege_receiving = "rc";
const privilege_pickup = "pku";
// Pickup types
const shipment_local_pickup = "Local pickup";

View File

@@ -64,9 +64,8 @@ class Carton {
// String get packageNumber =>
// shipmentNumber + "-" + receiverNumber + " #" + boxNumber;
double get actualWeight => cargoTypes == null
? 0
: cargoTypes.fold(0, (p, e) => e.weight + p);
double get actualWeight =>
cargoTypes == null ? 0 : cargoTypes.fold(0, (p, e) => e.weight + p);
int getShipmentWeight(double volumetricRatio) {
if (length == null ||
@@ -110,13 +109,12 @@ class Carton {
double wd = sw - aw;
wd = wd - rate.diffDiscountWeight;
double wdAmount = wd > 0 ? wd * rate.diffWeightRate : 0;
DiscountByWeight discountByWeight = rate.getDiscountByWeight(aw);
double total = 0;
cargoTypes.forEach((e) {
double r = e.rate -
(discountByWeight != null ? (discountByWeight.discount) : 0);
double r =
e.rate - (discountByWeight != null ? (discountByWeight.discount) : 0);
double amount = e.weight * r;
total += amount;
});
@@ -194,7 +192,8 @@ class Carton {
}
factory Carton.fromMap(Map<String, dynamic> map, String docID) {
var _arrivedDate = (map['arrived_date'] as Timestamp);
var _arrivedDate =
map['arrived_date'] == null ? null : (map['arrived_date'] as Timestamp);
var da = map['delivery_address'];
var _da = da != null ? DeliveryAddress.fromMap(da, da["id"]) : null;
var cargoTypesMaps =

View File

@@ -16,10 +16,12 @@ class Rate {
DiscountByWeight getDiscountByWeight(double weight) {
discountByWeights.sort((d1, d2) => d2.weight.compareTo(d1.weight));
return discountByWeights.firstWhere((e) => e.weight < weight);
return discountByWeights.firstWhere((e) => e.weight < weight,
orElse: () => DiscountByWeight());
}
CargoType get defaultCargoType => cargoTypes.firstWhere((e) => e.name == "General");
CargoType get defaultCargoType =>
cargoTypes.firstWhere((e) => e.name == "General");
Rate(
{this.deliveryFee = 0,

View File

@@ -43,6 +43,8 @@ class Privilege {
iconData = FontAwesome.dropbox;
} else if (this.id == privilege_receiving) {
iconData = MaterialCommunityIcons.inbox_arrow_down;
} else if (this.id == privilege_pickup) {
iconData = FontAwesome.dropbox;
} else {
iconData = MaterialCommunityIcons.account_question;
}

View File

@@ -4,15 +4,15 @@ 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/vo/message.dart';
import 'package:fcs/helpers/paginator.dart';
import 'package:fcs/pages/main/model/base_model.dart';
import 'package:logging/logging.dart';
class DeliveryModel extends BaseModel {
final log = Logger('DeliveryModel');
List<Carton> get cartons =>
_selectedIndex == 1 ? _cartons : List<Carton>.from(_delivered?.values ?? []);
List<Carton> get cartons => _selectedIndex == 1
? _cartons
: List<Carton>.from(_delivered?.values ?? []);
Paginator? _delivered;
int _selectedIndex = 1;
@@ -57,7 +57,8 @@ class DeliveryModel extends BaseModel {
_cartons.clear();
_cartons = snapshot.docs.map((documentSnapshot) {
var s = Carton.fromMap(
documentSnapshot.data as Map<String, dynamic>, documentSnapshot.id);
documentSnapshot.data as Map<String, dynamic>,
documentSnapshot.id);
return s;
}).toList();
notifyListeners();

View File

@@ -39,7 +39,8 @@ class _ProcessingInfoState extends State<ProcessingInfo> {
initPackage(widget.package!);
}
initPackage(Package package) {
initPackage(Package? package) {
if (package == null) return;
setState(() {
_package = package;
multiImgController.setImageUrls = package.photoUrls;
@@ -223,7 +224,7 @@ class _ProcessingInfoState extends State<ProcessingInfo> {
PackageModel packageModel =
Provider.of<PackageModel>(context, listen: false);
Package? p = await packageModel.getPackage(_package!.id!);
initPackage(p!);
initPackage(p);
}
}
}

View File

@@ -40,7 +40,8 @@ class _ReceivingInfoState extends State<ReceivingInfo> {
initPackage(widget.package!);
}
initPackage(Package package) {
initPackage(Package? package) {
if (package == null) return;
multiImgController.setImageUrls = package.photoUrls;
setState(() {
_package = package;
@@ -150,7 +151,7 @@ class _ReceivingInfoState extends State<ReceivingInfo> {
PackageModel packageModel =
Provider.of<PackageModel>(context, listen: false);
var pkg = await packageModel.getPackage(widget.package!.id!);
initPackage(pkg!);
initPackage(pkg);
}
_delete() {

View File

@@ -622,7 +622,6 @@ class MyDataTable extends StatelessWidget {
final List<TableColumnWidth> tableColumns = (columns.length +
(showCheckboxColumn ? 1 : 0)) as List<TableColumnWidth>;
final List<TableRow> tableRows = List<TableRow>.generate(
rows.length + 1, // the +1 is for the header row
(int index) {