add structure
This commit is contained in:
260
lib/vo/po.dart
Normal file
260
lib/vo/po.dart
Normal 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],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user