add payment
This commit is contained in:
@@ -13,6 +13,7 @@ class FcsShipment {
|
||||
String port;
|
||||
String destination;
|
||||
String status;
|
||||
String reportName;
|
||||
FcsShipment({
|
||||
this.id,
|
||||
this.shipmentNumber,
|
||||
@@ -24,6 +25,7 @@ class FcsShipment {
|
||||
this.consignee,
|
||||
this.port,
|
||||
this.destination,
|
||||
this.reportName,
|
||||
});
|
||||
|
||||
factory FcsShipment.fromMap(Map<String, dynamic> map, String docID) {
|
||||
@@ -57,6 +59,7 @@ class FcsShipment {
|
||||
'port': port,
|
||||
'destination': destination,
|
||||
'status': status,
|
||||
'report_name': reportName,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:fcs/domain/entities/carton.dart';
|
||||
import 'package:fcs/domain/entities/custom_duty.dart';
|
||||
import 'package:fcs/domain/entities/discount.dart';
|
||||
import 'package:fcs/domain/entities/discount_by_weight.dart';
|
||||
import 'package:fcs/domain/entities/payment.dart';
|
||||
import 'package:fcs/domain/entities/payment_method.dart';
|
||||
import 'package:fcs/domain/entities/rate.dart';
|
||||
import 'package:fcs/domain/entities/shipment.dart';
|
||||
@@ -28,6 +29,7 @@ class Invoice {
|
||||
List<Carton> cartons;
|
||||
List<CargoType> cargoTypes;
|
||||
List<Shipment> shipments;
|
||||
List<Payment> payments;
|
||||
Discount discount;
|
||||
PaymentMethod paymentMethod;
|
||||
String invoiceURL;
|
||||
@@ -70,6 +72,8 @@ class Invoice {
|
||||
return total;
|
||||
}
|
||||
|
||||
double get balance => (amount ?? 0) - (paidAmount ?? 0);
|
||||
|
||||
double getNetAmount(Rate rate) {
|
||||
List<CargoType> cargoTypes = getCargoTypes(rate);
|
||||
var total = cargoTypes.fold(0.0, (p, c) => c.calAmount + p);
|
||||
@@ -108,6 +112,7 @@ class Invoice {
|
||||
this.userName,
|
||||
this.phoneNumber,
|
||||
this.amount,
|
||||
this.paidAmount,
|
||||
this.discount,
|
||||
this.status,
|
||||
this.customDuties,
|
||||
@@ -118,6 +123,7 @@ class Invoice {
|
||||
this.fcsShipmentID,
|
||||
this.shipments,
|
||||
this.invoiceURL,
|
||||
this.payments,
|
||||
this.paymentMethod});
|
||||
|
||||
factory Invoice.fromMap(Map<String, dynamic> map, String docID) {
|
||||
@@ -142,6 +148,8 @@ class Invoice {
|
||||
: null;
|
||||
var discountMap = map['discount'];
|
||||
var discount = Discount.fromMap(discountMap, discountMap['id']);
|
||||
var paymentMaps = List<Map<String, dynamic>>.from(map['payments'] ?? []);
|
||||
var payments = paymentMaps.map((e) => Payment.fromMap(e, e["id"])).toList();
|
||||
return Invoice(
|
||||
id: docID,
|
||||
invoiceNumber: map['invoice_number'],
|
||||
@@ -150,6 +158,7 @@ class Invoice {
|
||||
fcsID: map['fcs_id'],
|
||||
phoneNumber: map['phone_number'],
|
||||
amount: map['amount'],
|
||||
paidAmount: double.tryParse(map['paid_amount'].toString()) ?? 0,
|
||||
status: map['status'],
|
||||
cartons: cartons,
|
||||
cargoTypes: cargoTypes,
|
||||
@@ -159,6 +168,7 @@ class Invoice {
|
||||
invoiceURL: map['invoice_url'],
|
||||
paymentMethod: paymentMethod,
|
||||
discount: discount,
|
||||
payments: payments,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
50
lib/domain/entities/payment.dart
Normal file
50
lib/domain/entities/payment.dart
Normal file
@@ -0,0 +1,50 @@
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
|
||||
class Payment {
|
||||
String id;
|
||||
String invoiceID;
|
||||
DateTime paymentDate;
|
||||
String paymentReceiptURL;
|
||||
String status;
|
||||
double amount;
|
||||
|
||||
Payment(
|
||||
{this.id,
|
||||
this.invoiceID,
|
||||
this.paymentDate,
|
||||
this.paymentReceiptURL,
|
||||
this.status,
|
||||
this.amount});
|
||||
|
||||
factory Payment.fromMap(Map<String, dynamic> map, String id) {
|
||||
var _paymentDate = (map['payment_date'] as Timestamp);
|
||||
return Payment(
|
||||
id: id,
|
||||
paymentDate: _paymentDate?.toDate(),
|
||||
paymentReceiptURL: map['payment_receipt_url'],
|
||||
status: map['status'],
|
||||
amount: map['amount']?.toDouble() ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
"id": id,
|
||||
"invoice_id": invoiceID,
|
||||
'payment_date': paymentDate?.toUtc()?.toIso8601String(),
|
||||
'payment_receipt_url': paymentReceiptURL,
|
||||
'status': status,
|
||||
'amount': amount,
|
||||
};
|
||||
}
|
||||
|
||||
Payment clone() {
|
||||
return Payment.fromMap(toMap(), this.id);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => other is Payment && other.id == id;
|
||||
|
||||
@override
|
||||
int get hashCode => id.hashCode;
|
||||
}
|
||||
Reference in New Issue
Block a user