first commit
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:enaklo_pos/data/models/response/product_response_model.dart';
|
||||
|
||||
class DraftOrderItem {
|
||||
final Product product;
|
||||
int quantity;
|
||||
DraftOrderItem({
|
||||
required this.product,
|
||||
required this.quantity,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'product': product.toMap(),
|
||||
'quantity': quantity,
|
||||
};
|
||||
}
|
||||
|
||||
// id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
// id_order INTEGER,
|
||||
// id_product INTEGER,
|
||||
// quantity INTEGER,
|
||||
// price INTEGER
|
||||
|
||||
Map<String, dynamic> toMapForLocal(int orderId) {
|
||||
return {
|
||||
'id_draft_order': orderId,
|
||||
'id_product': product.productId,
|
||||
'quantity': quantity,
|
||||
'price': product.price,
|
||||
};
|
||||
}
|
||||
|
||||
static OrderItemModel fromMapLocal(Map<String, dynamic> map) {
|
||||
return OrderItemModel(
|
||||
productId: map['id_product']?.toInt() ?? 0,
|
||||
quantity: map['quantity']?.toInt() ?? 0,
|
||||
totalPrice: map['price']?.toInt() ?? 0 * (map['quantity']?.toInt() ?? 0),
|
||||
);
|
||||
}
|
||||
|
||||
factory DraftOrderItem.fromMap(Map<String, dynamic> map) {
|
||||
return DraftOrderItem(
|
||||
product: Product.fromMap(map['product']),
|
||||
quantity: map['quantity']?.toInt() ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
factory DraftOrderItem.fromJson(String source) =>
|
||||
DraftOrderItem.fromMap(json.decode(source));
|
||||
}
|
||||
|
||||
class OrderItemModel {
|
||||
final int productId;
|
||||
final int quantity;
|
||||
final int totalPrice;
|
||||
|
||||
OrderItemModel({
|
||||
required this.productId,
|
||||
required this.quantity,
|
||||
required this.totalPrice,
|
||||
});
|
||||
|
||||
factory OrderItemModel.fromJson(String str) =>
|
||||
OrderItemModel.fromMap(json.decode(str));
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
factory OrderItemModel.fromMap(Map<String, dynamic> json) => OrderItemModel(
|
||||
productId: json["product_id"],
|
||||
quantity: json["quantity"],
|
||||
totalPrice: json["total_price"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toMap() => {
|
||||
"product_id": productId,
|
||||
"quantity": quantity,
|
||||
"total_price": totalPrice,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:enaklo_pos/presentation/table/models/draft_order_item.dart';
|
||||
|
||||
import '../../home/models/order_item.dart';
|
||||
|
||||
class DraftOrderModel {
|
||||
final int? id;
|
||||
final List<DraftOrderItem> orders;
|
||||
|
||||
final int totalQuantity;
|
||||
final int subTotal;
|
||||
final int tax;
|
||||
final int discount;
|
||||
final int discountAmount;
|
||||
final int serviceCharge;
|
||||
final int totalPrice;
|
||||
final String transactionTime;
|
||||
final int tableNumber;
|
||||
final String draftName;
|
||||
|
||||
DraftOrderModel({
|
||||
this.id,
|
||||
required this.orders,
|
||||
required this.totalQuantity,
|
||||
required this.subTotal,
|
||||
required this.tax,
|
||||
required this.discount,
|
||||
required this.discountAmount,
|
||||
required this.serviceCharge,
|
||||
required this.totalPrice,
|
||||
required this.tableNumber,
|
||||
required this.draftName,
|
||||
required this.transactionTime,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'orders': orders.map((x) => x.toMap()).toList(),
|
||||
'totalQuantity': totalQuantity,
|
||||
'totalPrice': totalPrice,
|
||||
'tableNumber': tableNumber,
|
||||
'draftName': draftName,
|
||||
};
|
||||
}
|
||||
|
||||
// mominal INTEGER,
|
||||
// payment_method TEXT
|
||||
// total_item INTEGER,
|
||||
// id_kasir INTEGER,
|
||||
// nama_kasir TEXT,
|
||||
// is_sync INTEGER DEFAULT 0
|
||||
|
||||
Map<String, dynamic> toMapForLocal() {
|
||||
return {
|
||||
'total_item': totalQuantity,
|
||||
'subTotal': subTotal,
|
||||
'tax': tax,
|
||||
'discount': discount,
|
||||
'discount_amount': discountAmount,
|
||||
'service_charge': serviceCharge,
|
||||
'total': totalPrice,
|
||||
'table_number': tableNumber,
|
||||
'transaction_time': transactionTime,
|
||||
'draft_name': draftName,
|
||||
};
|
||||
}
|
||||
|
||||
factory DraftOrderModel.fromLocalMap(Map<String, dynamic> map) {
|
||||
return DraftOrderModel(
|
||||
orders: [],
|
||||
totalQuantity: map['total_item']?.toInt() ?? 0,
|
||||
totalPrice: map['nominal']?.toInt() ?? 0,
|
||||
id: map['id']?.toInt() ?? 0,
|
||||
transactionTime: map['transaction_time'] ?? '',
|
||||
tableNumber: map['table_number']?.toInt() ?? 0,
|
||||
draftName: map['draft_name'] ?? '',
|
||||
discount: map['discount']?.toInt() ?? 0,
|
||||
discountAmount: map['discount_amount']?.toInt() ?? 0,
|
||||
serviceCharge: map['service_charge']?.toInt() ?? 0,
|
||||
subTotal: map['subTotal']?.toInt() ?? 0,
|
||||
tax: map['tax']?.toInt() ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
factory DraftOrderModel.newFromLocalMap(
|
||||
Map<String, dynamic> map, List<DraftOrderItem> orders) {
|
||||
log("newFromLocalMap: $map");
|
||||
return DraftOrderModel(
|
||||
orders: orders,
|
||||
totalQuantity: map['total_item']?.toInt() ?? 0,
|
||||
totalPrice: map['nominal']?.toInt() ?? 0,
|
||||
id: map['id']?.toInt() ?? 0,
|
||||
transactionTime: map['transaction_time'] ?? '',
|
||||
tableNumber: map['table_number']?.toInt() ?? 0,
|
||||
draftName: map['draft_name'] ?? '',
|
||||
discount: map['discount']?.toInt() ?? 0,
|
||||
discountAmount: map['discount_amount']?.toInt() ?? 0,
|
||||
serviceCharge: map['service_charge']?.toInt() ?? 0,
|
||||
subTotal: map['subTotal']?.toInt() ?? 0,
|
||||
tax: map['tax']?.toInt() ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
factory DraftOrderModel.fromMap(Map<String, dynamic> map) {
|
||||
return DraftOrderModel(
|
||||
orders: List<DraftOrderItem>.from(
|
||||
map['orders']?.map((x) => OrderItem.fromMap(x))),
|
||||
totalQuantity: map['totalQuantity']?.toInt() ?? 0,
|
||||
totalPrice: map['totalPrice']?.toInt() ?? 0,
|
||||
id: map['id']?.toInt() ?? 0,
|
||||
transactionTime: map['transactionTime'] ?? '',
|
||||
tableNumber: map['tableNumber']?.toInt() ?? 0,
|
||||
draftName: map['draftName'] ?? '',
|
||||
discount: map['discount']?.toInt() ?? 0,
|
||||
discountAmount: map['discountAmount']?.toInt() ?? 0,
|
||||
serviceCharge: map['serviceCharge']?.toInt() ?? 0,
|
||||
subTotal: map['subTotal']?.toInt() ?? 0,
|
||||
tax: map['tax']?.toInt() ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
factory DraftOrderModel.fromJson(String source) =>
|
||||
DraftOrderModel.fromMap(json.decode(source));
|
||||
|
||||
DraftOrderModel copyWith({
|
||||
int? id,
|
||||
List<DraftOrderItem>? orders,
|
||||
int? totalQuantity,
|
||||
int? subTotal,
|
||||
int? tax,
|
||||
int? discount,
|
||||
int? discountAmount,
|
||||
int? serviceCharge,
|
||||
int? totalPrice,
|
||||
String? transactionTime,
|
||||
int? tableNumber,
|
||||
String? draftName,
|
||||
}) {
|
||||
return DraftOrderModel(
|
||||
id: id ?? this.id,
|
||||
orders: orders ?? this.orders,
|
||||
totalQuantity: totalQuantity ?? this.totalQuantity,
|
||||
subTotal: subTotal ?? this.subTotal,
|
||||
tax: tax ?? this.tax,
|
||||
discount: discount ?? this.discount,
|
||||
discountAmount: discountAmount ?? this.discountAmount,
|
||||
serviceCharge: serviceCharge ?? this.serviceCharge,
|
||||
totalPrice: totalPrice ?? this.totalPrice,
|
||||
transactionTime: transactionTime ?? this.transactionTime,
|
||||
tableNumber: tableNumber ?? this.tableNumber,
|
||||
draftName: draftName ?? this.draftName,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user