add structure

This commit is contained in:
2020-05-29 07:45:27 +06:30
parent 4c851d9971
commit bad27ba5c4
272 changed files with 36065 additions and 174 deletions

38
lib/vo/announcement.dart Normal file
View File

@@ -0,0 +1,38 @@
import 'package:cloud_firestore/cloud_firestore.dart';
class Announcement {
String id;
String name;
String text;
DateTime time;
Announcement({this.id, this.name, this.text, this.time});
bool fromToday() {
var now = DateTime.now();
if (time == null) return false;
return time.day == now.day &&
time.month == now.month &&
time.year == now.year;
}
factory Announcement.fromMap(Map<String, dynamic> map, String id) {
var _time = (map['time'] as Timestamp);
return Announcement(
id: id,
time: _time?.toDate(),
name: map['name'],
text: map['text'],
);
}
Map<String, dynamic> toMap() {
return {'id': id, 'name': name, 'text': text};
}
@override
String toString() {
return 'Announcement{id:$id,name:$name,text:$text}';
}
}

14
lib/vo/attach.dart Normal file
View File

@@ -0,0 +1,14 @@
import 'dart:io';
class AttachFile {
File orderFile;
File storageFile;
String action;
AttachFile({this.orderFile, this.storageFile});
@override
String toString() {
return 'AttachFile{orderFile:$orderFile, storageFile:$storageFile}';
}
}

31
lib/vo/bank_account.dart Normal file
View File

@@ -0,0 +1,31 @@
class BankAccount {
int index;
String bankName;
String bankLogo;
String accountName;
String accountNumber;
BankAccount(
{this.index,
this.bankName,
this.bankLogo,
this.accountName,
this.accountNumber});
BankAccount.fromMap(int index, Map<String, dynamic> json) {
this.index = index;
bankName = json['bank_name'];
bankLogo = json['bank_logo'];
accountName = json['account_name'];
accountNumber = json['account_number'];
}
Map<String, dynamic> toMap() {
return {
"index": index,
'bank_name': bankName,
'bank_logo': bankLogo,
'account_name': accountName,
'account_number': accountNumber,
};
}
}

188
lib/vo/buyer.dart Normal file
View File

@@ -0,0 +1,188 @@
import 'package:cloud_firestore/cloud_firestore.dart';
class Buyer {
String id;
String bizName;
String bizAddress;
String bizType;
int numOfShops;
String shopAddress;
String status;
String userName;
String userID;
String phoneNumber;
DateTime regDate;
List<BuyerProduct> buyerProducts = [];
String comment;
String nricFrontUrl;
String nricBackUrl;
int dailyQuota;
int maxQuota;
int dailyQuotaUsed;
int maxQuotaUsed;
Map<String, int> dailyQuotaUsedProducts;
Map<String, int> maxQuotaUsedProducts;
String get phone => phoneNumber != null && phoneNumber.startsWith("959")
? "0${phoneNumber.substring(2)}"
: phoneNumber;
Buyer(
{this.bizName,
this.bizAddress,
this.numOfShops,
this.status,
this.bizType,
this.regDate,
this.userName,
this.userID,
this.phoneNumber,
this.id,
this.comment,
this.nricBackUrl,
this.nricFrontUrl,
this.shopAddress,
this.dailyQuota,
this.maxQuota,
this.dailyQuotaUsed,
this.maxQuotaUsed,
this.dailyQuotaUsedProducts,
this.maxQuotaUsedProducts});
factory Buyer.fromJson(Map<String, dynamic> json) {
var _regDate = DateTime.parse(json['reg_date']);
return Buyer(
bizName: json['biz_name'],
bizAddress: json['biz_address'],
numOfShops: json['num_of_shops'],
shopAddress: json['shop_address'],
status: json['status'],
bizType: json['biz_type'],
regDate: _regDate,
userName: json['user_name'],
userID: json['user_id'],
phoneNumber: json['phone_number'],
id: json['id'],
comment: json['comment'],
nricBackUrl: json['nric_back_url'],
nricFrontUrl: json['nric_front_url']);
}
factory Buyer.fromMap(Map<String, dynamic> map, String id) {
var _regDate = (map['reg_date'] as Timestamp);
return Buyer(
id: id,
bizName: map['biz_name'],
bizAddress: map['biz_address'],
bizType: map['biz_type'],
numOfShops: map['num_of_shops'],
shopAddress: map['shop_address'],
status: map['status'],
userName: map['user_name'],
userID: map['user_id'],
phoneNumber: map['phone_number'],
nricFrontUrl: map['nric_front_url'],
nricBackUrl: map['nric_back_url'],
dailyQuota: map['daily_quota'],
maxQuota: map['max_quota'],
dailyQuotaUsed: map['daily_quota_used'] ?? 0,
maxQuotaUsed: map['max_quota_used'] ?? 0,
dailyQuotaUsedProducts:
Map.from(map['daily_quota_used_products'] ?? Map<String, int>()),
maxQuotaUsedProducts:
Map.from(map['max_quota_used_products'] ?? Map<String, int>()),
regDate: _regDate?.toDate(),
);
}
Map<String, dynamic> toMap() {
List products = buyerProducts.map((l) => l.toMap()).toList();
return {
'id': id,
'biz_name': bizName,
'biz_address': bizAddress,
'biz_type': bizType,
'num_of_shops': numOfShops,
'shop_address': shopAddress,
'buyer_products': products,
'user_name': userName,
'user_id': userID,
'phone_number': phoneNumber,
'comment': comment,
'nric_front_url': nricFrontUrl,
'nric_back_url': nricBackUrl,
'daily_quota': dailyQuota,
'max_quota': maxQuota,
};
}
bool isApproved() {
return status != null && status == "approved";
}
bool isPending() {
return status != null && status == "pending";
}
@override
String toString() {
return 'Buyer{bizName:$bizName,bizAddress:$bizAddress,numOfShops:$numOfShops,status:$status}';
}
}
class BuyerProduct {
String productID;
String productName;
int dailySaleQty;
int storageCapacityQty;
int dailyQuota;
int maxQuota;
String action;
BuyerProduct(
{this.productID,
this.productName,
this.dailySaleQty,
this.storageCapacityQty,
this.dailyQuota,
this.maxQuota,
this.action});
factory BuyerProduct.fromMap(Map<String, dynamic> map, String id) {
return BuyerProduct(
productID: map['product_id'],
productName: map['product_name'],
dailySaleQty: map['daily_sale_qty'],
storageCapacityQty: map['storage_capacity_qty'],
dailyQuota: map['daily_quota'],
maxQuota: map['max_quota'],
);
}
Map<String, dynamic> toMap() {
return {
'product_id': productID,
'product_name': productName,
'daily_sale_qty': dailySaleQty,
'storage_capacity_qty': storageCapacityQty,
'daily_quota': dailyQuota,
'max_quota': maxQuota,
};
}
@override
bool operator ==(other) {
if (identical(this, other)) {
return true;
}
return (other.productID == this.productID);
}
@override
int get hashCode {
int result = 17;
result = 37 * result + productID.hashCode;
return result;
}
}

24
lib/vo/device.dart Normal file
View File

@@ -0,0 +1,24 @@
class PhoneDevice {
String id;
String name;
bool deviceOn;
bool primaryDevice;
PhoneDevice({this.id, this.name, this.deviceOn, this.primaryDevice});
factory PhoneDevice.fromMap(Map<String, dynamic> map, String id) {
return PhoneDevice(
id: id,
name: map['name'],
deviceOn: map['device_on'],
primaryDevice: map['primary_device']);
}
bool isDeviceOn() {
return this.deviceOn == true;
}
@override
String toString() {
return 'PhoneDevice{id:$id, name:$name,deviceOn:$deviceOn,primaryDevice:$primaryDevice}';
}
}

386
lib/vo/do.dart Normal file
View File

@@ -0,0 +1,386 @@
import 'dart:io';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:intl/intl.dart';
import 'po.dart';
import 'setting.dart';
class DOSubmission {
final dateFormatter = new DateFormat('dd MMM yyyy hh:mm a');
String id;
String poID;
String doNumber;
DateTime deliveryDate;
DateTime doDate;
String driverLicenseNumber;
String driverName;
String carNo;
String status;
String deliveryStatus;
DateTime deliveryInitiatedTime;
String comment;
String userID;
String userName;
String type;
String bizName;
String driverImgUrl;
String doReceiptUrl;
int storageCharge = 0;
String storageReceiptUrl;
String driverLicenceUrl;
int totalQty;
File driverImg;
List<DOLine> doLines = List();
List<POSubmission> pos = List();
List<DOPOLine> dopoLies = List();
get isApproved => status != null && status == "approved";
get isClosed => status != null && status == "closed";
get isPending => status == "pending";
get getDeliveryStatus =>
deliveryStatus == null ? "You can initiate delivery" : deliveryStatus;
get deliveryInitTime => deliveryInitiatedTime == null
? ""
: dateFormatter.format(deliveryInitiatedTime);
bool hasStorageCharge() {
return this.storageCharge != null && this.storageCharge > 0;
}
DOSubmission(
{this.id,
this.doNumber,
this.deliveryDate,
this.doDate,
this.driverLicenseNumber,
this.driverName,
this.carNo,
this.status,
this.comment,
this.type,
this.userName,
this.bizName,
this.deliveryStatus,
this.driverImgUrl,
this.deliveryInitiatedTime,
this.poID,
this.doReceiptUrl,
this.storageCharge,
this.storageReceiptUrl,
this.driverLicenceUrl,
this.totalQty});
void loadPOs() {
this.doLines.clear();
var isSingle = type == "single";
pos.forEach((p) => p.poLines.forEach((l) {
var dl = DOLine(
productID: l.productID,
productName: l.productName,
qty: isSingle ? l.balanceQty : 0,
poBalQty: l.balanceQty);
if (this.doLines.contains(dl)) {
this.doLines[this.doLines.indexOf(dl)].qty += dl.qty;
this.doLines[this.doLines.indexOf(dl)].poBalQty += dl.poBalQty;
} else {
this.doLines.add(dl);
}
}));
dopoLies.clear();
pos.forEach((p) => p.poLines.forEach((l) => dopoLies.add(DOPOLine(
poID: p.id,
productID: l.productID,
productName: l.productName,
poNumber: p.poNumber,
poQty: l.qty,
poBalQty: l.balanceQty,
doQty: isSingle ? l.balanceQty : 0,
poApproveDate: p.poApproveDate,
))));
dopoLies.sort((l1, l2) => l1.poNumber.compareTo(l2.poNumber));
}
void updateDoline(String productID, int qty) {
var _doLine = this.doLines.firstWhere((l) => l.productID == productID);
if (qty < 0) {
throw Exception("invalid number, must be greater than or equal to zero");
}
if (_doLine.poBalQty < qty) {
throw Exception(
"invalid number,must be less than or equal to PO balance qty");
}
if (_doLine != null && _doLine.poBalQty >= qty) {
_doLine.qty = qty;
var _dopoLines = dopoLies.where((l) => l.productID == productID).toList();
// clear
_dopoLines.forEach((l) => l.doQty = 0);
// add
var poBalQty = qty;
_dopoLines.forEach((l) {
if (poBalQty == 0) return;
var _qty = poBalQty > l.poBalQty ? l.poBalQty : poBalQty;
l.doQty = _qty;
poBalQty -= _qty;
});
}
}
void updateStorageCharge(Setting setting) {
if (deliveryDate == null) {
storageCharge = 0;
return;
}
var _deliveryDate =
DateTime(deliveryDate.year, deliveryDate.month, deliveryDate.day);
storageCharge = 0;
dopoLies.forEach((l) {
var _approveDate = DateTime(
l.poApproveDate.year, l.poApproveDate.month, l.poApproveDate.day);
int diff = _deliveryDate.difference(_approveDate).inDays;
if (diff > setting.firstStorageChargeIn) {
storageCharge += l.doQty * setting.firstStorageCharge;
}
if (diff > setting.secondStorageChargeIn) {
storageCharge += l.doQty * setting.secondStorageCharge;
}
});
}
List<String> getPOs() {
return this.dopoLies.map((l) => l.poID).toList();
}
void setDOPOLineBalance(String poID, List<POLine> poLines) {
poLines.forEach((poLine) {
this.dopoLies.forEach((l) {
if (l.poID == poID && l.productID == poLine.productID) {
l.poBalQty = poLine.balanceQty;
}
});
});
}
Map<String, dynamic> toMap() {
List lines = doLines.map((l) => l.toMap()).toList();
List doPOlines = dopoLies.map((l) => l.toMap()).toList();
return {
"id": id,
'delivery_date': deliveryDate?.toUtc()?.toIso8601String(),
'do_number': doNumber,
'po_id': poID,
'car_number': carNo,
'driver_name': driverName,
'driver_license_number': driverLicenseNumber,
'do_lines': lines,
'do_po_lines': doPOlines,
'comment': comment,
'user_id': userID,
'user_name': userName,
'type': type,
'driver_img_url': driverImgUrl,
'driver_sign_url': doReceiptUrl,
'delivery_status': deliveryStatus,
'storage_charge': storageCharge,
'storage_receipt_url': storageReceiptUrl,
'driver_license_url': driverLicenceUrl,
};
}
factory DOSubmission.fromMap(Map<String, dynamic> map, String id) {
var ts = (map['delivery_date'] as Timestamp);
var dt = (map['delivery_initiated_time'] as Timestamp);
var dots = (map['do_date'] as Timestamp);
return DOSubmission(
id: id,
deliveryDate: ts == null ? null : ts.toDate(),
deliveryInitiatedTime: dt == null ? null : dt.toDate(),
doDate: dots == null ? null : dots.toDate(),
doNumber: map['do_number'],
status: map['status'],
comment: map["comment"],
driverName: map["driver_name"],
driverLicenseNumber: map["driver_license_number"],
driverImgUrl: map["driver_img_url"],
doReceiptUrl: map["driver_sign_url"],
carNo: map["car_number"],
type: map["type"],
userName: map['user_name'],
bizName: map['biz_name'],
deliveryStatus: map['delivery_status'],
poID: map['po_id'],
storageCharge: map['storage_charge'],
storageReceiptUrl: map['storage_receipt_url'],
driverLicenceUrl: map['driver_license_url'],
totalQty: map['total_qty']);
}
@override
String toString() {
return 'DOSubmission{id:$id, deliveryDate:$deliveryDate,driverLicenseNumber:$driverLicenseNumber,driverName:$driverName,carNo:$carNo,status:$status,doLines:$doLines}';
}
}
class DOLine {
String id;
String productID;
String productName;
int qty;
int amount;
int price;
String storageID;
String storageName;
String action;
int displayOrder;
int poBalQty; // only for UI
DOLine(
{this.id,
this.productID,
this.productName,
this.qty,
this.amount,
this.price,
this.storageID,
this.storageName,
this.action,
this.poBalQty,
this.displayOrder});
factory DOLine.fromMap(Map<String, dynamic> map) {
return DOLine(
id: map['id'],
productID: map['product_id'],
productName: map['product_name'],
qty: map['quantity'],
amount: map['amount'],
price: map['price'],
storageID: map['storage_id'],
storageName: map['storage_name'],
);
}
Map<String, dynamic> toMap() {
return {
'id': id,
'product_id': productID,
'product_name': productName,
'quantity': qty,
'price': price,
'amount': amount,
'storage_id': storageID,
'storage_name': storageName,
};
}
@override
bool operator ==(other) {
if (identical(this, other)) {
return true;
}
return other.productID == this.productID;
}
@override
int get hashCode {
int result = 17;
result = 37 * result + productID.hashCode;
return result;
}
@override
String toString() {
return 'DOLine{productID:$productID,productName:$productName,qty:$qty,amount:$amount,price:$price,storageID:$storageID,displayOrder:$displayOrder}';
}
}
class DOPOLine {
String id;
String poID;
String poNumber;
DateTime poApproveDate;
String productID;
String productName;
int poQty;
int poBalQty;
int doQty;
int poBalAtCreate;
DateTime poApprovedDate;
int displayOrder;
get getPoBalanceQty => poBalQty - doQty;
get getPoBalanceQtyAtCreate =>
poBalAtCreate == null ? 0 : (poBalAtCreate - doQty);
DOPOLine(
{this.id,
this.poID,
this.poNumber,
this.productID,
this.productName,
this.poQty,
this.poBalQty,
this.doQty,
this.poApproveDate,
this.displayOrder,
this.poBalAtCreate});
factory DOPOLine.fromMap(Map<String, dynamic> map) {
return DOPOLine(
id: map['id'],
poID: map['po_id'],
poNumber: map['po_number'],
productID: map['product_id'],
productName: map['product_name'],
doQty: map['do_quantity'],
poQty: map['po_quantity'],
poBalQty: map['po_bal_quantity'],
poBalAtCreate: map['po_balance_at_create']);
}
Map<String, dynamic> toMap() {
return {
'id': id,
'po_id': poID,
'po_number': poNumber,
'product_id': productID,
'product_name': productName,
'do_quantity': doQty,
'po_quantity': poQty,
'po_bal_quantity': poBalQty,
'po_balance_at_create': poBalQty,
};
}
@override
bool operator ==(other) {
if (identical(this, other)) {
return true;
}
return other.productID == this.productID && other.poID == this.poID;
}
@override
int get hashCode {
int result = 17;
result = 37 * result + poID.hashCode;
result = 37 * result + productID.hashCode;
return result;
}
@override
String toString() {
return 'DOLine{productID:$productID,productName:$productName,doQty:$doQty}';
}
}

79
lib/vo/document_log.dart Normal file
View File

@@ -0,0 +1,79 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'buyer.dart';
import 'do.dart';
import 'po.dart';
import 'role.dart';
import 'user.dart';
class DocLog {
String id;
String docID;
String docType;
String ownerID;
String ownerName;
DateTime date;
String actionerID;
String actionerName;
Map<dynamic, dynamic> docData;
String data;
String getDesc(List<Privilege> privileges) {
if (docType == "po") {
return getPO().status;
} else if (docType == "do") {
return getDO().status;
} else if (docType == "buyer") {
return getBuyer().status;
} else if (docType == "user") {
User user=getUser();
return "${user.status}\nprivileges:${user.getLogDesc(privileges)}";
}
return "-";
}
DocLog(
{this.id,
this.docID,
this.docType,
this.date,
this.ownerID,
this.ownerName,
this.actionerID,
this.actionerName,
this.docData});
factory DocLog.fromMap(Map<String, dynamic> map, String id) {
var date = (map['date'] as Timestamp);
return DocLog(
id: id,
docID: map['doc_id'],
docType: map['doc_type'],
ownerID: map['owner_id'],
ownerName: map['owner_name'],
actionerID: map['actioner_id'],
actionerName: map['actioner_name'],
date: date == null ? null : date.toDate(),
docData: map['doc_data'],
);
}
Buyer getBuyer() {
return Buyer.fromMap(docData.cast<String, dynamic>(), docID);
}
POSubmission getPO() {
return POSubmission.fromMap(docData.cast<String, dynamic>(), docID);
}
DOSubmission getDO() {
return DOSubmission.fromMap(docData.cast<String, dynamic>(), docID);
}
User getUser() {
return User.fromMap(docData.cast<String, dynamic>(), docID);
}
}

View File

@@ -0,0 +1,54 @@
class InventoryLine {
String storageID;
String storageName;
String productID;
String productName;
int quantity;
int oldQty;
String action;
InventoryLine(
{this.storageID,
this.storageName,
this.productID,
this.productName,
this.quantity,
this.oldQty});
@override
bool operator ==(other) {
if (identical(this, other)) {
return true;
}
return (other.storageID == this.storageID &&
other.productID == this.productID);
}
@override
int get hashCode {
int result = 17;
result = 37 * result + storageID.hashCode;
result = 37 * result + productID.hashCode;
return result;
}
Map<String, dynamic> toMap() {
return {
'storage_id': storageID,
'storage_name': storageName,
'product_id': productID,
'product_name': productName,
'quantity': quantity
};
}
factory InventoryLine.fromMap(Map<String, dynamic> map) {
return InventoryLine(
storageID: map['storage_id'],
storageName: map['storage_name'],
productID: map['product_id'],
productName: map['product_name'],
quantity: map['quantity'],
);
}
}

View File

@@ -0,0 +1,44 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'inventory_line.dart';
class InventoryTaking {
String accountID;
String id;
DateTime dateTime;
String userID;
String userName;
List<InventoryLine> inventoryLines = [];
bool linesLoaded = false;
InventoryTaking(
{this.accountID, this.id, this.userID, this.userName, this.dateTime});
factory InventoryTaking.fromMap(Map<String, dynamic> map, String id) {
var _dateTime = (map['date_time'] as Timestamp);
return InventoryTaking(
id: id,
accountID: map['account_id'],
userID: map['user_id'],
userName: map['user_name'],
dateTime: _dateTime?.toDate(),
);
}
Map<String, dynamic> toMap() {
List lines = inventoryLines.map((l) => l.toMap()).toList();
return {
'id': id,
'user_id': userID,
'user_name': userName,
'inventory_lines': lines,
};
}
@override
String toString() {
return 'InventoryTaking{id:$id,name:$userName}';
}
}

24
lib/vo/log.dart Normal file
View File

@@ -0,0 +1,24 @@
import 'package:cloud_firestore/cloud_firestore.dart';
class Log {
DateTime activeTime;
String deviceID;
String deviceName;
Log({this.activeTime, this.deviceID, this.deviceName});
factory Log.fromMap(Map<String, dynamic> map, String docID) {
var activeTime = (map['active_time'] as Timestamp);
return Log(
activeTime: activeTime == null ? null : activeTime.toDate(),
deviceID: map['device_id'],
deviceName: map['device_name'],
);
}
@override
String toString() {
return 'Log{activeTime: $activeTime, deviceID: $deviceID, deviceName: $deviceName}';
}
}

236
lib/vo/manual.dart Normal file
View File

@@ -0,0 +1,236 @@
class ManualItem {
int id;
dynamic title;
dynamic titlemm;
List<SlideData> slides;
bool isBuyer;
ManualItem({this.id, this.title, this.titlemm, this.slides, this.isBuyer});
factory ManualItem.fromJson(Map<String, dynamic> json) {
var list = json['slides'] as List;
List<SlideData> slideList = list.map((i) => SlideData.fromJson(i)).toList();
return ManualItem(
id: json['id'],
title: json['title'],
titlemm: json['titlemm'],
isBuyer: json['isBuyer'],
slides: slideList);
}
factory ManualItem.fromMap(Map<String, dynamic> map) {
var list = map['slides'] as List;
List<SlideData> slideList = list.map((i) => SlideData.fromJson(i)).toList();
return ManualItem(
id: map['id'],
title: map['title'],
titlemm: map['titlemm'],
isBuyer: map['isBuyer'],
slides: slideList);
}
Map<String, dynamic> toJson() => {
'id': id,
'title': "$title",
'titlemm': "$titlemm",
'isBuyer': isBuyer,
'slides': slides.map((slide) {
return slide.toJson();
}).toList(),
};
Map<String, dynamic> toMap() => {
'id': id,
'title': title,
'titlemm': titlemm,
'isBuyer': isBuyer,
'slides': slides.map((slide) {
return slide.toMap();
}).toList(),
};
@override
String toString() {
return 'ManualItem{id:$id,title: $title,titlemm: $titlemm,isBuyer: $isBuyer, slides: $slides}';
}
@override
bool operator ==(other) {
if (identical(this, other)) {
return true;
}
return other.id == this.id;
}
@override
int get hashCode {
int result = 17;
result = 37 * result + id.hashCode;
return result;
}
factory ManualItem.clone(ManualItem m) {
return ManualItem(
id: m.id,
title: m.title,
titlemm: m.titlemm,
isBuyer: m.isBuyer,
slides: m.slides.map((s) => SlideData.clone(s)).toList(),
);
}
}
class SlideData {
int id;
String image;
String imagemm;
List<Instruction> instructions;
List<Instruction> instructionsmm;
SlideData(
{this.id,
this.image,
this.imagemm,
this.instructions,
this.instructionsmm});
factory SlideData.fromJson(Map<String, dynamic> json) {
var list = json['instructions'] as List;
List<Instruction> instructionList =
list.map((i) => Instruction.fromJson(i)).toList();
var listmm = json['instructionsmm'] as List;
List<Instruction> instructionmmList =
listmm.map((i) => Instruction.fromJson(i)).toList();
return SlideData(
id: json['id'],
image: json['image'],
imagemm: json['imagemm'],
instructions: instructionList,
instructionsmm: instructionmmList,
);
}
factory SlideData.fromMap(Map<String, dynamic> map, int id) {
return SlideData(
id: id,
image: map['image'],
imagemm: map['imagemm'],
instructions: map['instructions'],
instructionsmm: map['instructionsmm'],
);
}
Map<String, dynamic> toJson() => {
'id': id,
'image': image,
'imagemm': imagemm,
'instructions': instructions.map((instruction) {
return instruction.toJson();
}).toList(),
'instructionsmm': instructionsmm.map((instruction) {
return instruction.toJson();
}).toList(),
};
Map<String, dynamic> toMap() => {
'id': id,
'image': image,
'imagemm': imagemm,
'instructions': instructions.map((instruction) {
return instruction.toJson();
}).toList(),
'instructionsmm': instructionsmm.map((instruction) {
return instruction.toJson();
}).toList(),
};
@override
String toString() {
return 'SlideData{id:$id,image: $image,imagemm: $imagemm, instructions: $instructions,instructionsmm: $instructionsmm,}';
}
factory SlideData.clone(SlideData s) {
return SlideData(
id: s.id,
image: s.image,
imagemm: s.imagemm,
instructions: s.instructions.map((e) => Instruction.clone(e)).toList(),
instructionsmm:
s.instructionsmm.map((e) => Instruction.clone(e)).toList());
}
@override
bool operator ==(other) {
if (identical(this, other)) {
return true;
}
return other.id == this.id;
}
@override
int get hashCode {
int result = 17;
result = 37 * result + id.hashCode;
return result;
}
}
class Instruction {
int id;
String text;
double top;
double left;
Instruction({this.id, this.text, this.top, this.left});
factory Instruction.fromJson(Map<String, dynamic> json) {
return Instruction(
id: json['id'] == null ? 0 : json['id'],
text: json['text'] == null ? "" : json['text'],
top: double.parse(json['top'].toString()),
left: double.parse(json['left'].toString()),
);
}
factory Instruction.fromMap(Map<String, dynamic> map, int id) {
return Instruction(
id: id,
text: map['text'],
top: map['top'],
left: map['left'],
);
}
Map<String, dynamic> toJson() => {
'id': id,
'text': text,
'top': top,
'left': left,
};
Map<String, dynamic> toMap() => {
'id': id,
'text': text,
'top': top,
'left': left,
};
@override
String toString() {
return 'Instruction{id: $id,text: $text,top: $top, left: $left}';
}
@override
bool operator ==(other) {
if (identical(this, other)) {
return true;
}
return other.id == this.id;
}
@override
int get hashCode {
int result = 17;
result = 37 * result + id.hashCode;
return result;
}
factory Instruction.clone(Instruction i) {
return Instruction(id: i.id, text: i.text, top: i.top, left: i.left);
}
}

49
lib/vo/notification.dart Normal file
View File

@@ -0,0 +1,49 @@
import 'package:cloud_firestore/cloud_firestore.dart';
class Notification {
String id;
String itemID;
String itemNumber;
String itemType;
String desc;
DateTime time;
bool seen;
Notification(
{this.id,
this.itemID,
this.itemNumber,
this.itemType,
this.desc,
this.time,
this.seen});
String get getDesc =>
desc != null && desc.length > 30 ? desc.substring(0, 30) : desc;
bool fromToday() {
var now = DateTime.now();
return time.day == now.day &&
time.month == now.month &&
time.year == now.year;
}
factory Notification.fromMap(Map<String, dynamic> map, String id) {
var _time = (map['time'] as Timestamp);
return Notification(
id: id,
time: _time?.toDate(),
itemID: map['item_id'],
itemNumber: map['item_number'],
itemType: map['item_type'],
desc: map['desc'],
seen: map['seen'],
);
}
@override
String toString() {
return 'Notification{id:$id,itemID:$itemID,itemNumber:$itemNumber,itemType:$itemType,desc:$desc,seen:$seen}';
}
}

90
lib/vo/pd.dart Normal file
View File

@@ -0,0 +1,90 @@
import 'package:cloud_firestore/cloud_firestore.dart';
class PD {
String id;
DateTime date;
String userID;
String userName;
String pdNumber;
List<PDLine> pdLines = [];
PD({this.id, this.date, this.userID, this.userName, this.pdNumber});
factory PD.fromMap(Map<String, dynamic> map, String id) {
var _dateTime = (map['date'] as Timestamp);
return PD(
id: id,
userID: map['user_id'],
userName: map['user_name'],
date: _dateTime?.toDate(),
pdNumber: map['pd_number']);
}
Map<String, dynamic> toMap() {
List lines = pdLines.map((l) => l.toMap()).toList();
return {
'id': id,
'date': date,
'pd_lines': lines,
};
}
@override
String toString() {
return 'PD{id:$id, date:$date,pdLines:$pdLines}';
}
}
class PDLine {
String storageID, storageName, productID, productName;
int quantity;
String action;
PDLine(
{this.storageID,
this.storageName,
this.productID,
this.productName,
this.quantity});
Map<String, dynamic> toMap() {
return {
'storage_id': storageID,
'storage_name': storageName,
'product_id': productID,
'product_name': productName,
'quantity': quantity
};
}
factory PDLine.fromMap(Map<String, dynamic> map) {
return PDLine(
storageID: map['storage_id'],
storageName: map['storage_name'],
productID: map['product_id'],
productName: map['product_name'],
quantity: map['quantity'],
);
}
@override
bool operator ==(other) {
if (identical(this, other)) {
return true;
}
return (other.storageID == this.storageID &&
other.productID == this.productID);
}
@override
int get hashCode {
int result = 17;
result = 37 * result + storageID.hashCode;
result = 37 * result + productID.hashCode;
return result;
}
@override
String toString() {
return 'PDLine{storageName:$storageName,productName:$productName,quantity:$quantity}';
}
}

260
lib/vo/po.dart Normal file
View File

@@ -0,0 +1,260 @@
import 'dart:ui';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:charts_flutter/flutter.dart' as charts;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'do.dart';
class POSubmission {
String id;
DateTime poDate;
String poNumber;
String status;
String poReceiptUrl;
List<String> poReceiptUrls;
String storageReceiptUrl;
int storageCharge;
int amount;
String userID;
String userName;
String comment;
String bizName;
DateTime poApproveDate;
List<POLine> poLines = [];
List<DOSubmission> dos = [];
int get getAmount => poLines.fold(0, (p, e) => p + e.amount);
POSubmission(
{this.id,
this.poDate,
this.poNumber,
this.status,
this.poReceiptUrl,
this.storageReceiptUrl,
this.storageCharge = 0,
this.amount = 0,
this.userID,
this.userName,
this.comment,
this.bizName,
this.poApproveDate,
this.poReceiptUrls});
bool isPending() {
return status == "pending";
}
bool isApproved() {
return status == "approved";
}
bool allowSingleType() {
return dos.length == 0;
}
bool hasStorageCharge() {
return this.storageCharge != null && this.storageCharge > 0;
}
bool hasStorageReceipt() {
return this.storageReceiptUrl != null && this.storageReceiptUrl != "";
}
bool hasPaymentReceipt() {
return (this.poReceiptUrl != null && this.poReceiptUrl != "") ||
(this.poReceiptUrls != null && this.poReceiptUrls.length > 0);
}
factory POSubmission.fromMap(Map<String, dynamic> map, String id) {
var ts = (map['po_date'] as Timestamp);
var poAppovetTS = (map['po_approved_date'] as Timestamp);
var poReceiptUrls = (map['po_receipt_urls'] as List);
if (poReceiptUrls != null) {
poReceiptUrls = List<String>.from(poReceiptUrls);
} else {
poReceiptUrls = new List<String>();
}
String receiptURL = map['po_receipt_url'];
if (receiptURL != null && receiptURL != "") {
poReceiptUrls.add(receiptURL);
}
return POSubmission(
id: id,
poDate: ts == null ? null : ts.toDate(),
poNumber: map['po_number'],
status: map['status'],
poReceiptUrl: map['po_receipt_url'],
storageReceiptUrl: map['storage_receipt_url'],
storageCharge: map["storage_charge"],
userID: map["user_id"],
userName: map["user_name"],
comment: map["comment"],
bizName: map['biz_name'],
poApproveDate: poAppovetTS == null ? null : poAppovetTS.toDate(),
poReceiptUrls: poReceiptUrls == null ? null : poReceiptUrls,
amount: map['amount']);
}
Map<String, dynamic> toMap() {
List lines = poLines.map((l) => l.toMap()).toList();
return {
"id": id,
'po_receipt_url': poReceiptUrl,
'storage_receipt_url': storageReceiptUrl,
'po_receipt_urls': poReceiptUrls,
'po_lines': lines,
'comment': comment,
};
}
@override
bool operator ==(other) {
if (identical(this, other)) {
return true;
}
return other.id == this.id;
}
@override
int get hashCode {
int result = 17;
result = 37 * result + id.hashCode;
return result;
}
@override
String toString() {
return 'POSubmission{id:$id, poDate:$poDate,poNumber:$poNumber,dos:$dos,poLines:$poLines,status:$status}';
}
}
class POLine {
String productID;
String productName;
int qty;
int balanceQty;
int deliveryBalanceQty;
int amount;
int price;
int deliveryBalQty;
String action;
int displayOrder;
POLine(
{this.productID,
this.productName,
this.qty,
this.amount,
this.price,
this.balanceQty,
this.action,
this.displayOrder,
this.deliveryBalQty});
@override
bool operator ==(other) {
if (identical(this, other)) {
return true;
}
return other.productID == this.productID;
}
@override
int get hashCode {
int result = 17;
result = 37 * result + productID.hashCode;
return result;
}
Map<String, dynamic> toMap() {
return {
'product_id': productID,
'product_name': productName,
'quantity': qty,
'price': price,
'amount': amount,
'action': action
};
}
factory POLine.fromMap(Map<String, dynamic> map) {
return POLine(
productID: map['product_id'],
productName: map['product_name'],
qty: map['quantity'],
balanceQty: map['balance_quantity'],
amount: map['amount'],
price: map['price'],
action: map['action'],
deliveryBalQty: map['delivery_balance_quantity']);
}
@override
String toString() {
return 'POLine{productID:$productID,productName:$productName,qty:$qty,amount:$amount,price:$price}';
}
}
class POChartData {
String userName;
String productID;
String productName;
int balanceQty;
int color;
int displayOrder;
get getColor => Color(color);
POChartData(
{@required this.userName,
@required this.productName,
@required this.balanceQty,
@required this.color,
this.productID,
this.displayOrder});
factory POChartData.fromJson(Map<String, dynamic> json, String qty) {
var _qty = 0;
var _color = 0;
try {
_qty = json[qty];
_color = json['color'];
} catch (e) {}
return POChartData(
userName: json['user_name'],
productName: json['product_name'],
productID: json['product_id'],
balanceQty: _qty,
color: _color,
);
}
}
class POBuyerData {
String status;
int amount;
POBuyerData({
@required this.status,
@required this.amount,
});
get getColor => status == "approved"
? Colors.green
: status == "rejected"
? Colors.red
: status == "pending" ? Colors.blue : Colors.grey;
factory POBuyerData.fromJson(Map<String, dynamic> json, String qty) {
return POBuyerData(
status: json['status'],
amount: json[qty],
);
}
}

141
lib/vo/po_do_count.dart Normal file
View File

@@ -0,0 +1,141 @@
import 'package:intl/intl.dart';
class PODOCount {
Map<dynamic, dynamic> mapPOCount = {};
Map<dynamic, dynamic> mapDOCount = {};
PODOCount({
this.mapPOCount,
this.mapDOCount,
});
//for po count
List<CountData> getPODataCounts(String status) {
return getDataCounts(mapPOCount, status);
}
List<TotalCountData> getPOTotalCounts() {
return getTotalCounts(mapPOCount);
}
//for do count
List<CountData> getDODataCounts(String status) {
return getDataCounts(mapDOCount, status);
}
List<TotalCountData> getDOTotalCounts() {
return getTotalCounts(mapDOCount);
}
List<CountData> getDataCounts(counts, String status) {
List<CountData> result = new List();
if (counts != null) {
DateTime today = new DateTime.now();
DateTime thirtyDaysAgo = today.subtract(new Duration(days: 30));
String _formatter = new DateFormat("yyyyMMdd").format(thirtyDaysAgo);
int _lastThirtyDays = int.tryParse(_formatter);
counts.forEach((k, value) {
int mapDay = int.tryParse(k);
if (mapDay < _lastThirtyDays) return;
CountData data = new CountData();
var parsedDate = DateTime.parse(k);
data.date = parsedDate;
if (value != null) {
value.forEach((key, count) {
if (key == status) {
data.status = key;
data.count = count;
}
});
}
result.add(data);
});
result.sort((a, b) {
return a.date.compareTo(b.date);
});
}
return result;
}
List<TotalCountData> getTotalCounts(counts) {
List<TotalCountData> result = new List();
if (counts != null) {
DateTime today = new DateTime.now();
DateTime thirtyDaysAgo = today.subtract(new Duration(days: 30));
String _formatter = new DateFormat("yyyyMMdd").format(thirtyDaysAgo);
int _lastThirtyDays = int.tryParse(_formatter);
counts.forEach((k, value) {
int mapDay = int.tryParse(k);
if (mapDay < _lastThirtyDays) return;
var parsedDate = DateTime.parse(k);
int sum = 0;
List<CountData> countList = new List();
if (value != null) {
value.forEach((key, count) {
sum += count;
countList
.add(CountData(date: parsedDate, status: key, count: count));
});
}
result.add(TotalCountData(
date: parsedDate, totalCount: sum, detailCountsList: countList));
});
result.sort((a, b) {
return a.date.compareTo(b.date);
});
}
return result;
}
List<CountData> getDetailCounts(counts) {
List<CountData> result = new List();
if (counts != null) {
counts.forEach((k, value) {
var parsedDate = DateTime.parse(k);
if (value != null) {
value.forEach((key, count) {
result.add(CountData(date: parsedDate, status: key, count: count));
});
}
});
result.sort((a, b) {
return a.date.compareTo(b.date);
});
}
return result;
}
factory PODOCount.fromMap(Map<String, dynamic> map, String docID) {
return PODOCount(
mapPOCount: map['po_count'],
mapDOCount: map['do_count'],
);
}
@override
String toString() {
return null;
}
}
class CountData {
DateTime date;
String status;
int count;
CountData({this.date, this.count, this.status});
}
class TotalCountData {
DateTime date;
int totalCount;
List<CountData> detailCountsList;
TotalCountData({this.date, this.detailCountsList, this.totalCount});
}

5
lib/vo/popup_menu.dart Normal file
View File

@@ -0,0 +1,5 @@
class PopupMenu {
int index;
String status;
PopupMenu({this.status, this.index});
}

123
lib/vo/product.dart Normal file
View File

@@ -0,0 +1,123 @@
import '../util.dart';
class Product {
String accountID;
String id;
String name;
int price;
int color;
String action;
int quantity;
int displayOrder;
Map<String, int> priceHistory;
bool isDisable;
// used for buyer registration
int dailySale;
int storageCapacity;
int dailyQuota;
int oldPirce;
//used for do item
String storageID;
String storageName;
String get getname => this.name;
int get getprice => this.price;
List<ProductPrice> get getPrices => this
.priceHistory
.entries
.map((k) => ProductPrice(
name: name,
price: k.value,
date: DateUtil.toLocal(DateTime.parse(k.key)),
displayOrder: displayOrder))
.toList();
Product(
{this.accountID,
this.id,
this.name,
this.price,
this.color,
this.action,
this.priceHistory,
this.dailySale,
this.storageCapacity,
this.dailyQuota,
this.quantity,
this.oldPirce,
this.displayOrder,
this.storageID,
this.storageName,
this.isDisable});
factory Product.clone(Product p) {
return Product(
accountID: p.accountID,
id: p.id,
name: p.name,
price: p.price,
color: p.color,
displayOrder: p.displayOrder,
action: p.action,
isDisable: p.isDisable);
}
factory Product.fromJson(Map<String, dynamic> json) {
return Product(
name: json['name'],
price: int.parse(json['price']),
);
}
Map<String, dynamic> toMap() {
return {
'account_id': accountID,
'id': id,
'name': name,
'price': price,
'color': color,
'display_order': displayOrder,
'action': action,
'disable': isDisable
};
}
factory Product.fromMap(Map<String, dynamic> map, String id) {
return Product(
id: id,
name: map['name'] ?? map['product_name'],
price: map['price'],
color: map['color'],
quantity: map['quantity'],
displayOrder: map['display_order'],
priceHistory: map['price_history']?.cast<String, int>(),
storageID: map['storage_id'],
storageName: map['storage_name'],
isDisable: map['disable']);
}
@override
String toString() {
return 'User{name: $name, price: $price,storageID:$storageID,storageName:$storageName,isDisable:$isDisable}';
}
}
class ProductPrice {
DateTime date;
int price;
String name;
int displayOrder;
ProductPrice({this.date, this.price, this.name, this.displayOrder});
int compareTo(ProductPrice other) {
int r = other.date.compareTo(this.date);
if (r == 0) {
return this.displayOrder.compareTo(other.displayOrder);
}
return r;
}
}

49
lib/vo/reg.dart Normal file
View File

@@ -0,0 +1,49 @@
import 'product.dart';
class Reg {
String name = "", address = "", type = "";
int numberOfShops = 0;
final String sellerID;
final String buyerID;
final List<Product> products;
Map<String, dynamic> toMap() {
var _products = [];
products.forEach((p) => _products.add(p.toMap()));
return {
'products': _products,
'seller_id': sellerID,
'buyer_id': buyerID,
};
}
Reg(this.sellerID, this.buyerID, this.products);
void addProduct(Product product) {
var _product = _get(product.id);
if (_product == null) {
_product = product;
products.add(product);
}
_product.dailySale = product.dailySale;
_product.storageCapacity = product.storageCapacity;
}
void deleteProduct(Product product) {
var _product = _get(product.id);
if (_product == null) {
return;
}
products.remove(_product);
}
Product _get(String id) {
try {
return products.firstWhere((p) => p.id == id);
} catch (e) {
return null;
}
}
}

258
lib/vo/report.dart Normal file
View File

@@ -0,0 +1,258 @@
class Report {
String id;
String name;
String display;
String object;
List groupbys = [];
List sorts = [];
List displayFields = [];
List<Field> fields;
List<DisplayFilter> displayFilters;
bool forAllUser;
Report(
{this.id,
this.name,
this.display,
this.displayFields,
this.displayFilters,
this.fields,
this.groupbys,
this.sorts,
this.object,
this.forAllUser});
@override
bool operator ==(other) {
if (identical(this, other)) {
return true;
}
return other.id == this.id;
}
@override
int get hashCode {
int result = 17;
result = 37 * result + id.hashCode;
return result;
}
Map<String, dynamic> toMap() {
List sortList = sorts.map((l) => l.toMap()).toList();
List groupByList = groupbys.map((l) => l.toMap()).toList();
List dFieldList = displayFields.map((l) => l.toMap()).toList();
return {
'id': id,
'name': name,
'display': display,
'sorts': sortList,
'object': object,
'groupbys': groupByList,
'display_fields': dFieldList,
'display_filters': displayFilters.map((filter) {
return filter.toMap();
}).toList(),
'fields': fields.map((field) {
return field.toMap();
}).toList(),
};
}
factory Report.fromMap(Map<String, dynamic> map, String id) {
var list = map['fields'] as List;
List<Field> fields = list.map((i) => Field.fromJson(i)).toList();
var filterlist = map['display_filters'] as List;
List<DisplayFilter> displayFilters =
filterlist.map((i) => DisplayFilter.fromJson(i)).toList();
return Report(
id: id,
name: map['name'],
display: map['display'],
displayFields: map['display_fields'],
groupbys: map['groupbys'] == null ? [] : map['groupbys'],
sorts: map['sorts'] == null ? [] : map['sorts'],
fields: fields,
displayFilters: displayFilters,
object: map['object'],
forAllUser: map['for_all_users']);
}
convertArrayToString(Report report, List filters) {
var aggFun = [];
var fields = [];
var groupbys = [];
report.fields.asMap().forEach((key, value) {
if (value.aggFun == '') {
aggFun.add('');
} else {
aggFun.add(value.aggFun);
}
});
report.fields.asMap().forEach((key, value) {
fields.add(value.name);
});
String strFields;
fields.forEach((element) {
if (strFields == null) {
strFields = element;
} else {
strFields = strFields + ',' + element;
}
});
String strAgg;
aggFun.forEach((element) {
if (strAgg == null) {
strAgg = element;
} else {
strAgg = strAgg + ',' + element;
}
});
String strGroup;
groupbys.forEach((element) {
if (strGroup == null) {
strGroup = element;
} else {
strGroup = strGroup + ',' + element;
}
});
var data = {
"fields": strFields == null ? '' : strFields,
"aggfuns": strAgg == null ? '' : strAgg,
"groupbys": strGroup == null ? '' : strGroup,
"sorts": report.sorts == null ? [] : report.sorts,
"filters": filters == null ? [] : filters
};
return data;
}
@override
String toString() {
return 'Report{id:$id,name:$name,object: $object display: $display, sorts: $sorts, groupbys: $groupbys, fields: $fields, displayFilters: $displayFilters, displayFields: $displayFields}';
}
}
class Field {
String aggFun;
String dataType;
String displayName;
String name;
int toFixed;
Field(
{this.aggFun, this.dataType, this.displayName, this.name, this.toFixed});
factory Field.fromJson(Map<dynamic, dynamic> json) {
return Field(
aggFun: json['agg_fun'] == '' ? '' : json['agg_fun'],
dataType: json['type'],
displayName: json['display_name'],
name: json['name'],
toFixed: json['to_fixed'] == null ? 0 : json['to_fixed']);
}
factory Field.fromMap(Map<String, dynamic> map) {
return Field(
aggFun: map['agg_fun'],
dataType: map['type'],
displayName: map['display_name'],
name: map['name'],
toFixed: map['to_fixed']);
}
Map<String, dynamic> toMap() => {
'aggFun': aggFun,
'dataType': dataType,
'displayName': displayName,
'name': name,
'toFixed': toFixed
};
Map<String, dynamic> toJson() => {
'aggFun': aggFun,
'dataType': dataType,
'displayName': displayName,
'name': name,
'toFixed': toFixed
};
@override
String toString() {
return 'Field{aggFun: $aggFun, dataType: $dataType, displayName: $displayName, name: $name, toFixed: $toFixed}';
}
}
class DisplayFilter {
String compare;
String type;
String displayName;
String name;
DisplayFilter({this.compare, this.type, this.displayName, this.name});
factory DisplayFilter.fromJson(Map<dynamic, dynamic> json) {
return DisplayFilter(
compare: json['compare'],
type: json['data_type'] == '' ? '' : json['data_type'],
displayName: json['display_name'],
name: json['name']);
}
factory DisplayFilter.fromMap(Map<int, dynamic> map) {
return DisplayFilter(
compare: map['compare'],
type: map['type'],
displayName: map['display_name'],
name: map['name']);
}
Map<String, dynamic> toMap() => {
'compare': compare,
'type': type,
'displayName': displayName,
'name': name,
};
@override
String toString() {
return 'DisplayFilter{compare: $compare, type: $type, displayName: $displayName, name: $name}';
}
}
class ReportFieldPositionSelection {
String id;
List<Field> fieldPosition;
List fieldSelection;
ReportFieldPositionSelection(
{this.id, this.fieldPosition, this.fieldSelection});
factory ReportFieldPositionSelection.fromJson(Map<dynamic, dynamic> json) {
var list = json['field_position'] as List;
List<Field> fields = list.map((i) => Field.fromJson(i)).toList();
return ReportFieldPositionSelection(
id: json['id'],
fieldPosition: fields,
fieldSelection: json['field_selection']);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'field_selection': fieldSelection,
'field_position': fieldPosition.map((field) {
return field.toMap();
}).toList(),
};
}
@override
String toString() {
return 'ReportFieldPositionSelection{id: $id, fieldPosition: $fieldPosition, fieldSelection: $fieldSelection}';
}
}

21
lib/vo/report_data.dart Normal file
View File

@@ -0,0 +1,21 @@
class ReportData {
String id;
String productName;
String productId;
int balanceQty;
ReportData({this.id, this.productName, this.productId, this.balanceQty});
factory ReportData.fromJson(Map<String, dynamic> json, String qty) {
var _qty = 0;
try {
_qty = json[qty];
} catch (e) {}
return ReportData(
id: json['id'],
productName: json['product_name'],
productId: json['product_id'],
balanceQty: _qty,
);
}
}

33
lib/vo/report_user.dart Normal file
View File

@@ -0,0 +1,33 @@
class ReportUser {
String id;
String reportID;
String reportName;
String userID;
String userName;
ReportUser({
this.id,
this.reportID,
this.reportName,
this.userID,
this.userName,
});
factory ReportUser.fromMap(Map<String, dynamic> map, String docID) {
return ReportUser(
id: docID,
reportID: map['report_id'],
reportName: map['report_name'],
userID: map['user_id'],
userName: map['user_name'],
);
}
Map<String, dynamic> toMap() {
return {
"id": id,
"report_id": reportID,
"report_name": reportName,
"user_id": userID,
"user_name": userName
};
}
}

279
lib/vo/revenue.dart Normal file
View File

@@ -0,0 +1,279 @@
import 'package:intl/intl.dart';
class Revenue {
Map<dynamic, dynamic> mapData = {};
Map<dynamic, dynamic> mapPOCount = {};
Map<dynamic, dynamic> mapDOCount = {};
Map<dynamic, dynamic> mapDelivery = {};
Map<dynamic, dynamic> mapDoDelivery = {};
List<double> getData1(int index) {
var endRange = 0;
if (index == 0) {
// 7 days
endRange = 6 > mapData.length ? mapData.length : 6;
} else if (index == 1) {
// one months
endRange = 30 > mapData.length ? mapData.length : 30;
} else {
// three months
endRange = 90 > mapData.length ? mapData.length : 90;
}
List<int> result = new List();
if (mapData != null) {
mapData.forEach((k, value) {
result.add(value.toInt());
});
}
return result.getRange(0, endRange).map((v) => v.toDouble()).toList();
}
List<Data> getData() {
List<Data> result = new List();
if (mapData != null) {
DateTime today = new DateTime.now();
DateTime thirtyDaysAgo = today.subtract(new Duration(days: 30));
String _formatter = new DateFormat("yyyyMMdd").format(thirtyDaysAgo);
int _lastThirtyDays = int.tryParse(_formatter);
mapData.forEach((k, value) {
int mapDay = int.tryParse(k);
if (mapDay < _lastThirtyDays) return;
var parsedDate = DateTime.parse(k);
var data = Data(date: parsedDate, amount: value);
result.add(data);
});
result.sort((a, b) {
return a.date.compareTo(b.date);
});
}
return result;
}
List<Data> getPOCounts() {
List<Data> result = new List();
if (mapPOCount != null) {
mapPOCount.forEach((k, value) {
var parsedDate = DateTime.parse(k);
var data = Data(date: parsedDate, count: value);
result.add(data);
});
result.sort((a, b) {
return a.date.compareTo(b.date);
});
}
return result;
}
List<Data> getDOCounts() {
List<Data> result = new List();
if (mapDOCount != null) {
mapDOCount.forEach((k, value) {
var parsedDate = DateTime.parse(k);
var data = Data(date: parsedDate, count: value);
result.add(data);
});
result.sort((a, b) {
return a.date.compareTo(b.date);
});
}
return result;
}
List<Data> getDelivery() {
List<Data> result = new List();
if (mapDelivery != null) {
mapDelivery.forEach((k, value) {
var parsedDate = DateTime.parse(k);
var data = Data(date: parsedDate, amount: value);
result.add(data);
});
result.sort((a, b) {
return a.date.compareTo(b.date);
});
}
return result;
}
List<Data> getDeliverySummary() {
List<Data> _list = new List();
List<Data> result = new List();
if (mapDelivery != null) {
mapDelivery.forEach((k, value) {
var parsedDate = DateTime.parse(k);
var data = Data(date: parsedDate, amount: value);
_list.add(data);
});
_list.sort((a, b) {
return a.date.compareTo(b.date);
});
int _count = 1;
int _index = 0;
int _totalDay = 0;
int _totalAmount = 0;
int lastIndex = _list.length - 1;
_list.asMap().forEach((index, value) {
_totalAmount += value.amount;
if (_count == 10 || index == lastIndex) {
_totalDay = (_index + 1) * 10;
if (index == lastIndex && lastIndex > 0) {
_totalDay = lastIndex + 1;
_totalAmount +=
result.length > 0 ? result[result.length - 1].totalAmount : 0;
}
if (lastIndex == 0) {
_totalDay = 1;
}
if (_index != 0 && index != lastIndex) {
_totalAmount += result[_index - 1].totalAmount;
}
result.insert(
_index, Data(totalDay: _totalDay, totalAmount: _totalAmount));
_totalAmount = 0;
_count = 0;
_index++;
}
_count++;
});
}
return result;
}
List<Data> getDeliveryDo() {
List<Data> result = new List();
if (mapDoDelivery != null) {
mapDoDelivery.forEach((k, value) {
var parsedDate = DateTime.parse(k);
var data = Data(date: parsedDate, count: value);
result.add(data);
});
result.sort((a, b) {
return a.date.compareTo(b.date);
});
}
return result;
}
List<Data> getDeliveryDoSummary() {
List<Data> _list = new List();
List<Data> result = new List();
if (mapDoDelivery != null) {
mapDoDelivery.forEach((k, value) {
var parsedDate = DateTime.parse(k);
var data = Data(date: parsedDate, count: value);
_list.add(data);
});
_list.sort((a, b) {
return a.date.compareTo(b.date);
});
int _count = 1;
int _index = 0;
int _totalDay = 0;
int _totalCount = 0;
int lastIndex = _list.length - 1;
_list.asMap().forEach((index, value) {
_totalCount += value.count;
if (_count == 10 || index == lastIndex) {
_totalDay = (_index + 1) * 10;
if (index == lastIndex && lastIndex > 0) {
_totalDay = lastIndex + 1;
_totalCount +=
result.length > 0 ? result[result.length - 1].totalCount : 0;
}
if (lastIndex == 0) {
_totalDay = 1;
}
if (_index != 0 && index != lastIndex) {
_totalCount += result[_index - 1].totalCount;
}
result.insert(
_index, Data(totalDay: _totalDay, totalCount: _totalCount));
_totalCount = 0;
_count = 0;
_index++;
}
_count++;
});
}
return result;
}
int getTotal(int index) {
var endRange = 0;
if (index == 0) {
// 7 days
endRange = 6 > mapData.length ? mapData.length : 6;
} else if (index == 1) {
// one months
endRange = 30 > mapData.length ? mapData.length : 30;
} else {
// three months
endRange = 90 > mapData.length ? mapData.length : 90;
}
List<int> result = new List();
if (mapData != null) {
DateTime today = new DateTime.now();
DateTime thirtyDaysAgo = today.subtract(new Duration(days: 30));
String _formatter = new DateFormat("yyyyMMdd").format(thirtyDaysAgo);
int _lastThirtyDays = int.tryParse(_formatter);
mapData.forEach((k, value) {
int mapDay = int.tryParse(k);
if (mapDay < _lastThirtyDays) return;
result.add(value.toInt());
});
}
return result.fold(0, (prev, element) => prev + element);
}
Revenue(
{this.mapData,
this.mapPOCount,
this.mapDOCount,
this.mapDelivery,
this.mapDoDelivery});
factory Revenue.fromMap(Map<String, dynamic> map, String docID) {
return Revenue(
mapData: map['data'],
mapPOCount: map['po_count'],
mapDOCount: map['do_count'],
mapDelivery: map['delivery'],
mapDoDelivery: map['do_delivery']);
}
@override
String toString() {
return null;
}
}
class Data {
DateTime date;
int totalDay;
int totalCount;
int totalAmount;
int amount;
int count;
Data(
{this.date,
this.amount,
this.count,
this.totalDay,
this.totalCount,
this.totalAmount});
}

71
lib/vo/role.dart Normal file
View File

@@ -0,0 +1,71 @@
class Role {
String roleID;
String roleName;
String privileges;
Role({this.roleName, this.roleID, this.privileges});
Role.fromJson(Map<String, dynamic> json) {
roleName = json['role_name'];
roleID = json['role_id'];
privileges = json['privileges'];
}
}
class Parser {
String status;
String message;
Role data;
Parser({this.status, this.message, this.data});
Parser.fromJson(Map<String, dynamic> json) {
status = json['status'];
message = json['message'];
if (json['status'] == 'Ok') {
data = Role.fromJson(json['data']);
}
}
}
class StatusParser {
String status;
String message;
StatusParser(this.status, this.message);
StatusParser.fromJson(Map<String, dynamic> json) {
status = json['status'];
message = json['message'];
}
}
class Privilege {
String id;
String name;
String desc;
bool sysAdminOnly = true;
bool isChecked = false;
Privilege({this.id, this.name, this.desc, this.isChecked, this.sysAdminOnly});
factory Privilege.fromMap(Map<String, dynamic> map, String docID) {
return Privilege(
id: docID,
name: map['name'],
desc: map['desc'],
sysAdminOnly: map['sys_admin_only']);
}
}
class UserLevel {
String id;
String name;
int level;
UserLevel({this.id, this.name, this.level});
factory UserLevel.fromMap(Map<String, dynamic> map, String docID) {
return UserLevel(
id: docID,
name: map['name'],
level: map['level']
);
}
}

168
lib/vo/setting.dart Normal file
View File

@@ -0,0 +1,168 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'bank_account.dart';
List<Day> dayLists = [
Day(id: 1, name: 'Sun'),
Day(id: 2, name: 'Mon'),
Day(id: 3, name: 'Tue'),
Day(id: 4, name: 'Wed'),
Day(id: 5, name: 'Thu'),
Day(id: 6, name: 'Fri'),
Day(id: 7, name: 'Sat'),
];
class Setting {
final int supportBuildNum;
final String okEnergyId;
final String about;
final String terms;
int poExpireInHours;
int doExpireInHours;
int poOpenAt;
int poCloseAt;
List<int> poCloseOn;
int latestDeliveryDay;
int firstStorageChargeIn;
int firstStorageCharge;
int secondStorageChargeIn;
int secondStorageCharge;
int deliveryStartWaitMin;
String reportURL;
String helpVersion;
String helpURL;
List<String> phones;
String deliveryPhone;
String address;
String email;
String website;
String facebook;
DateTime priceLastUpdate;
String bankAccountInfo;
List<BankAccount> bankAccounts;
String get getPoOpenAt => poOpenAt > 12
? (poOpenAt - 12).toString() + "PM"
: poOpenAt.toString() + "AM";
String get getPoCloseAt => poCloseAt > 12
? (poCloseAt - 12).toString() + "PM"
: poCloseAt.toString() + "AM";
String get getPoCloseOn => poCloseOn.fold(
"", (p, e) => p + (p == "" ? "" : ", ") + dayLists[e - 1].name);
String get getPoOpenOn => dayLists.fold(
"",
(p, e) =>
p +
(p == "" ? "" : poCloseOn.contains(e.id) ? "" : ", ") +
(poCloseOn.contains(e.id) ? "" : e.name));
bool get isPOClose {
DateTime now = DateTime.now();
// dart starts from monday width starting index one
// server starts from sunday with starting index one
var day = (now.weekday + 1) == 8 ? 1 : now.weekday + 1;
return poCloseOn.contains(day) ||
(now.hour < poOpenAt || now.hour >= poCloseAt);
}
Setting(
{this.supportBuildNum,
this.about,
this.okEnergyId,
this.terms,
this.poExpireInHours,
this.doExpireInHours,
this.poOpenAt,
this.poCloseAt,
this.poCloseOn,
this.latestDeliveryDay,
this.firstStorageCharge,
this.firstStorageChargeIn,
this.secondStorageCharge,
this.secondStorageChargeIn,
this.deliveryStartWaitMin,
this.reportURL,
this.helpVersion,
this.helpURL,
this.phones,
this.email,
this.website,
this.facebook,
this.priceLastUpdate,
this.bankAccountInfo,
this.bankAccounts,
this.deliveryPhone,
this.address});
factory Setting.fromMap(Map<String, dynamic> map) {
var ts = (map['price_last_update'] as Timestamp);
var list = (map['bank_accounts'] as List);
List<BankAccount> bankAccounts = [];
if (list != null) {
list.asMap().forEach((index, item) {
bankAccounts
.add(BankAccount.fromMap(index, item.cast<String, dynamic>()));
});
}
return Setting(
priceLastUpdate: ts?.toDate(),
supportBuildNum: map['support_build_number'],
about: map['about'],
terms: map['terms'],
okEnergyId: map['ok_energy_id'],
poExpireInHours: map['po_expire_hours'],
doExpireInHours: map['do_expire_hours'],
poOpenAt: map['po_open_at'],
poCloseAt: map['po_close_at'],
poCloseOn: List.from(map['po_close_on']),
latestDeliveryDay: map['latest_delivery_days'],
firstStorageChargeIn: map['first_storage_charge_in'],
firstStorageCharge: map['first_storage_charge'],
secondStorageChargeIn: map['second_storage_charge_in'],
secondStorageCharge: map['second_storage_charge'],
deliveryStartWaitMin: map['delivery_start_wait_min'],
reportURL: map['report_url'],
helpVersion: map['help_version'],
helpURL: map['help_url'],
phones: List.from(map['phones']),
email: map['email'],
deliveryPhone: map['delivery_phone'],
address: map['address'],
website: map['website'],
facebook: map['facebook'],
bankAccountInfo: map['bank_account_info'],
bankAccounts: bankAccounts);
}
Map<String, dynamic> toMap() {
return {
'terms': terms,
};
}
String helpFileName() {
return "help-v$helpVersion.zip";
}
@override
String toString() {
return 'Setting{supportBuildNum:$supportBuildNum,about:$about,okEnergyId:$okEnergyId}';
}
}
class Day {
int id;
String name;
bool isChecked = false;
Day({this.id, this.name, this.isChecked});
@override
String toString() {
return 'Day{id:$id,name:$name,isChecked:$isChecked}';
}
}

13
lib/vo/status.dart Normal file
View File

@@ -0,0 +1,13 @@
class Status {
String status;
String message;
String errorCode;
Status(this.status, this.message);
Status.fromJson(Map<String, dynamic> json) {
status = json['status'];
message = json['message'];
errorCode = json['error_code'];
}
}

38
lib/vo/storage.dart Normal file
View File

@@ -0,0 +1,38 @@
import 'product.dart';
class Storage {
String accountID;
String id;
String name;
bool productsLoaded;
List<Product> products = [];
Storage(
{this.accountID,
this.id,
this.name,
this.products,
this.productsLoaded = false});
factory Storage.fromMap(Map<String, dynamic> map, String id) {
return Storage(
id: id,
accountID: map['account_id'],
name: map['name'],
);
}
Map<String, dynamic> toMap() {
return {
'account_id': accountID,
'id': id,
'name': name,
};
}
@override
String toString() {
return 'Storage{id:$id,name:$name}';
}
}

325
lib/vo/user.dart Normal file
View File

@@ -0,0 +1,325 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'role.dart';
class User {
String docID;
final String corpId;
final String name;
String phoneNumber;
String get phone => phoneNumber != null && phoneNumber.startsWith("959")
? "0${phoneNumber.substring(2)}"
: phoneNumber;
List<String> claimPrivileges = [];
final String dateofBirth;
final String gender;
final String status;
final bool disable;
bool registeredBuyer;
List<String> privilegeIds;
String roleName;
String roleID;
bool agreeTerms;
String bizID;
String accountID;
String email;
bool isBlock;
int userLevel;
String userLevelID;
String frontUrl;
String backUrl;
String selfieUrl;
DateTime lastActiveTime;
String device;
String primaryDeviceID;
String primaryDeviceName;
String pin;
String get getcorpId => this.corpId;
String get getname => this.name;
String get getphonenumber => this.phoneNumber;
String get getdateofBirth => this.dateofBirth;
bool get getdisable => this.disable;
String getLogDesc(List<Privilege> privileges) {
String result = "";
if (privilegeIds.isNotEmpty) {
privilegeIds.forEach((pID) {
privileges.forEach((p) {
if (p.id == pID) {
if (result != "") result += ",";
result += p.name;
}
});
});
}
return result;
}
Future<void> setFirebaseUser(FirebaseUser firebaseUser) async {
IdTokenResult idToken = await firebaseUser.getIdToken(refresh: true);
String privileges = idToken.claims["privileges"];
if (privileges == null || privileges == "") return;
this.claimPrivileges = privileges.split(":").toList();
this.accountID = idToken.claims["account_id"];
this.bizID = idToken.claims["biz_id"];
}
User(
{this.docID,
this.name,
this.gender,
this.phoneNumber,
this.dateofBirth,
this.corpId,
this.roleName,
this.roleID,
this.privilegeIds,
this.email,
this.disable,
this.status,
this.frontUrl,
this.backUrl,
this.selfieUrl,
this.registeredBuyer,
this.agreeTerms,
this.lastActiveTime,
this.device,
this.primaryDeviceID,
this.primaryDeviceName,
this.isBlock,
this.userLevel,
this.userLevelID,
this.pin});
factory User.fromJson(Map<String, dynamic> json) {
return User(
docID: json['id'],
name: json['user_name'],
phoneNumber: json['phone_number'],
dateofBirth: json['dob'],
gender: json['gender'],
frontUrl: json['front_url'],
backUrl: json['back_url'],
selfieUrl: json['selfie_url'],
status: json['status'],
agreeTerms: json['agree_terms'],
disable: json['disable'],
registeredBuyer: json['registered_buyer'],
privilegeIds: json['privileges'],
email: json['email'],
isBlock: json['black_list'],
userLevel: json['user_level'],
userLevelID: json['user_level_id'],
pin: json['pin']);
}
factory User.fromUserJson(Map<String, dynamic> json) {
DateTime parsedDate = DateTime.parse(json['last_active_time']);
return User(
docID: json['id'],
name: json['user_name'],
phoneNumber: json['phone_number'],
dateofBirth: json['dob'],
corpId: json['corp_id'],
roleName: json['role_name'],
roleID: json['role_id'],
disable: json['disable'],
gender: json['gender'],
status: json['status'],
// agreeTerms: json['agree_terms'],
// registeredBuyer: json['registered_buyer'],
// privilegeIds: json['privileges']==null?[]:json['privileges'].cast<String>(),
// isBlock: map['black_list'],
lastActiveTime: parsedDate == null ? null : parsedDate,
device: json['last_active_device'],
email: json['email'],
primaryDeviceID: json['primary_device_id'],
primaryDeviceName: json['primary_device_name'],
userLevel: json['user_level'],
userLevelID: json['user_level_id'],
pin: json['pin']);
}
Map<String, dynamic> toJson() => {
'id': docID,
'user_name': name,
'gender': gender,
'phone_number': phoneNumber,
'dob': dateofBirth,
'corpId': corpId,
'roleName': roleName,
'roleId': roleID,
'disable': disable,
'status': status,
'registered_buyer': registeredBuyer,
'agree_terms': agreeTerms,
'front_url': frontUrl,
'back_url': backUrl,
'selfie_url': selfieUrl,
'email': email,
'black_list': isBlock,
'user_level': userLevel,
'user_level_id': userLevelID,
'pin': pin,
'privileges': privilegeIds,
};
Map<String, dynamic> toMap() {
return {
'user_name': name,
'phone_number': phoneNumber,
'dob': dateofBirth,
'corp_id': corpId,
'role_name': roleName,
'role_id': roleID,
'disable': disable,
'gender': gender,
'status': status,
'email': email,
'black_list': isBlock,
'user_level': userLevel,
'user_level_id': userLevelID,
'pin': pin
};
}
factory User.fromMap(Map<String, dynamic> map, String docID) {
var activeTime = (map['last_active_time'] as Timestamp);
return User(
docID: docID,
name: map['user_name'],
phoneNumber: map['phone_number'],
privilegeIds:
map['privileges'] == null ? [] : map['privileges'].cast<String>(),
dateofBirth: map['dob'],
corpId: map['corp_id'],
roleName: map['role_name'],
roleID: map['role_id'],
disable: map['disable'],
gender: map['gender'],
status: map['status'],
registeredBuyer: map['registered_buyer'],
agreeTerms: map['agree_terms'] == null ? false : map['agree_terms'],
lastActiveTime: activeTime == null ? null : activeTime.toDate(),
device: map['last_active_device'],
email: map['email'],
primaryDeviceID: map['primary_device_id'],
primaryDeviceName: map['primary_device_name'],
isBlock: map['black_list'],
userLevel: map['user_level'],
userLevelID: map['user_level_id'],
pin: map['pin']);
}
bool isBlockUser() {
return this.isBlock == true;
}
bool isPrimaryDevice() {
return this.primaryDeviceID != null && this.primaryDeviceID != '';
}
bool isRegisteredBuyer() {
return this.registeredBuyer != null && this.registeredBuyer;
}
bool isSysAdmin() {
return claimPrivileges != null
? claimPrivileges.contains('sys_admin')
: false;
}
bool isSysSupport() {
return claimPrivileges != null
? claimPrivileges.contains('sys_support')
: false;
}
bool isBizAdmin() {
return claimPrivileges != null ? claimPrivileges.contains('ba') : false;
}
bool isBuyer() {
return claimPrivileges == null || claimPrivileges.length == 0;
}
bool isEmail() {
return email != null;
}
bool hasAccount() {
return isOwner() ||
(claimPrivileges != null ? claimPrivileges.contains('a') : false);
}
bool hasDelivery() {
return isOwner() ||
(claimPrivileges != null ? claimPrivileges.contains('d') : false);
}
bool hasBuyer() {
return isOwner() ||
(claimPrivileges != null ? claimPrivileges.contains('b') : false);
}
bool isOwner() {
return claimPrivileges != null ? claimPrivileges.contains('o') : false;
}
bool isOwnerAndAbove() {
return isOwner() || isBizAdmin() || isSysAdmin();
}
bool hasAdmin() {
return isOwner() ||
(claimPrivileges != null ? claimPrivileges.contains('admin') : false);
}
bool hasDO() {
return isOwner() ||
(claimPrivileges != null ? claimPrivileges.contains('do') : false);
}
bool hasPO() {
return isOwner() ||
(claimPrivileges != null ? claimPrivileges.contains('po') : false);
}
bool hasInventory() {
return isOwner() ||
(claimPrivileges != null ? claimPrivileges.contains('inv') : false);
}
@override
String toString() {
return 'User{name: $name, phoneNumber: $phoneNumber,dateofBirth:$dateofBirth,corpId:$corpId,disable:$disable,gender:$gender,roleName:$roleName,roleID:$roleID,privilegeIds:$privilegeIds,status:$status,frontUrl:$frontUrl,backUrl:$backUrl,selfieUrl:$selfieUrl}';
}
}
class JsonUser {
String status;
String message;
User data;
String sessionId;
JsonUser({this.status, this.message, this.sessionId, this.data});
JsonUser.fromJson(Map<String, dynamic> json) {
status = json['status'];
message = json['message'];
sessionId = json['session_id'];
if (json['status'] == 'Ok') {
data = User.fromJson(json['data']);
}
}
}