first commit

This commit is contained in:
Aditya Siregar
2025-07-30 22:38:44 +07:00
commit 73320561b0
444 changed files with 64633 additions and 0 deletions
@@ -0,0 +1,31 @@
import 'package:enaklo_pos/data/models/response/product_response_model.dart';
import 'product_model.dart';
class OrderItem {
final Product product;
int quantity;
OrderItem({
required this.product,
required this.quantity,
});
factory OrderItem.fromMap(Map<String, dynamic> map) {
return OrderItem(
product: Product.fromMap(map['product']),
quantity: map['quantity']?.toInt() ?? 0,
);
}
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is OrderItem &&
other.product == product &&
other.quantity == quantity;
}
@override
int get hashCode => product.hashCode ^ quantity.hashCode;
}
@@ -0,0 +1,211 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'dart:convert';
import 'package:enaklo_pos/presentation/home/models/product_quantity.dart';
import 'package:enaklo_pos/presentation/home/models/order_type.dart';
// id INTEGER PRIMARY KEY AUTOINCREMENT,
// sub_total INTEGER,
// tax INTEGER,
// discount INTEGER,
// service_charge INTEGER,
// total INTEGER,
// payment_method TEXT,
// total_item INTEGER,
// id_kasir INTEGER,
// nama_kasir TEXT,
// transaction_time TEXT,
// is_sync INTEGER DEFAULT 0
class OrderModel {
final int? id;
//payment_amount
final int paymentAmount;
final int subTotal;
final int tax;
final int discount;
final int discountAmount;
final int serviceCharge;
final int total;
final String paymentMethod;
final int totalItem;
final int idKasir;
final String namaKasir;
final String transactionTime;
final String customerName;
final int tableNumber;
final String status;
final String paymentStatus;
final int isSync;
final List<ProductQuantity> orderItems;
final OrderType orderType;
OrderModel({
this.id,
required this.paymentAmount,
required this.subTotal,
required this.tax,
required this.discount,
required this.discountAmount,
required this.serviceCharge,
required this.total,
required this.paymentMethod,
required this.totalItem,
required this.idKasir,
required this.namaKasir,
required this.transactionTime,
required this.customerName,
required this.tableNumber,
required this.status,
required this.paymentStatus,
required this.isSync,
required this.orderItems,
this.orderType = OrderType.dineIn,
});
// 'payment_amount' => 'required',
// 'sub_total' => 'required',
// 'tax' => 'required',
// 'discount' => 'required',
// 'service_charge' => 'required',
// 'total' => 'required',
// 'payment_method' => 'required',
// 'total_item' => 'required',
// 'id_kasir' => 'required',
// 'nama_kasir' => 'required',
// 'transaction_time' => 'required',
// 'order_items' => 'required'
Map<String, dynamic> toServerMap() {
return {
'payment_amount': paymentAmount,
'sub_total': subTotal,
'tax': tax,
'discount': discount,
'discount_amount': discountAmount,
'service_charge': serviceCharge,
'total': total,
'payment_method': paymentMethod,
'total_item': totalItem,
'id_kasir': idKasir,
'nama_kasir': namaKasir,
'customer_name': customerName,
'table_number': tableNumber,
'status': status,
'payment_status': paymentStatus,
'transaction_time': transactionTime,
'order_type': orderType.value,
'order_items': orderItems.map((e) => e.toServerMap(id)).toList(),
};
}
Map<String, dynamic> toMap({bool includeOrderType = true}) {
final map = {
// 'id': id,
'payment_amount': paymentAmount,
'sub_total': subTotal,
'tax': tax,
'discount': discount,
'discount_amount': discountAmount,
'service_charge': serviceCharge,
'total': total,
'payment_method': paymentMethod,
'total_item': totalItem,
'id_kasir': 1,
'nama_kasir': 'Kasir',
'transaction_time': transactionTime,
'customer_name': customerName,
'table_number': tableNumber,
'status': status,
'payment_status': paymentStatus,
'is_sync': isSync,
};
if (includeOrderType) {
map['order_type'] = orderType.value;
}
return map;
}
factory OrderModel.fromMap(Map<String, dynamic> map) {
print("Discount AMount${map['discount_amount']}");
return OrderModel(
id: map['id']?.toInt(),
paymentAmount: map['payment_amount']?.toInt() ?? 0,
subTotal: map['sub_total']?.toInt() ?? 0,
tax: map['tax']?.toInt() ?? 0,
discount: map['discount']?.toInt() ?? 0,
discountAmount: map['discount_amount']?.toInt() ?? 0,
serviceCharge: map['service_charge']?.toInt() ?? 0,
total: map['total']?.toInt() ?? 0,
paymentMethod: map['payment_method'] ?? '',
totalItem: map['total_item']?.toInt() ?? 0,
idKasir: map['id_kasir']?.toInt() ?? 0,
namaKasir: map['nama_kasir'] ?? '',
transactionTime: map['transaction_time'] ?? '',
isSync: map['is_sync']?.toInt() ?? 0,
customerName: map['customer_name'] ?? '',
tableNumber: map['table_number']?.toInt() ?? 0,
status: map['status'] ?? '',
paymentStatus: map['payment_status'] ?? '',
orderType: OrderType.fromString(map['order_type'] ?? 'DINE IN'),
orderItems: [],
);
}
String toJson() => json.encode(toServerMap());
factory OrderModel.fromJson(String source) =>
OrderModel.fromMap(json.decode(source));
OrderModel copyWith({
int? id,
int? paymentAmount,
int? subTotal,
int? tax,
int? discount,
int? discountAmount,
int? serviceCharge,
int? total,
String? paymentMethod,
int? totalItem,
int? idKasir,
String? namaKasir,
String? transactionTime,
String? customerName,
int? tableNumber,
String? status,
String? paymentStatus,
int? isSync,
List<ProductQuantity>? orderItems,
OrderType? orderType,
}) {
return OrderModel(
id: id ?? this.id,
paymentAmount: paymentAmount ?? this.paymentAmount,
subTotal: subTotal ?? this.subTotal,
tax: tax ?? this.tax,
discount: discount ?? this.discount,
discountAmount: discountAmount ?? this.discountAmount,
serviceCharge: serviceCharge ?? this.serviceCharge,
total: total ?? this.total,
paymentMethod: paymentMethod ?? this.paymentMethod,
totalItem: totalItem ?? this.totalItem,
idKasir: idKasir ?? this.idKasir,
namaKasir: namaKasir ?? this.namaKasir,
transactionTime: transactionTime ?? this.transactionTime,
customerName: customerName ?? this.customerName,
tableNumber: tableNumber ?? this.tableNumber,
status: status ?? this.status,
paymentStatus: paymentStatus ?? this.paymentStatus,
isSync: isSync ?? this.isSync,
orderItems: orderItems ?? this.orderItems,
orderType: orderType ?? this.orderType,
);
}
@override
String toString() {
return 'OrderModel(id: $id, paymentAmount: $paymentAmount, subTotal: $subTotal, tax: $tax, discount: $discount, discountAmount: $discountAmount, serviceCharge: $serviceCharge, total: $total, paymentMethod: $paymentMethod, totalItem: $totalItem, idKasir: $idKasir, namaKasir: $namaKasir, transactionTime: $transactionTime, customerName: $customerName, tableNumber: $tableNumber, status: $status, paymentStatus: $paymentStatus, isSync: $isSync, orderItems: $orderItems, orderType: $orderType)';
}
}
@@ -0,0 +1,16 @@
enum OrderType {
dineIn('DINE IN'),
takeAway('TAKE AWAY'),
grab('GRAB'),
delivery('DELIVERY');
final String value;
const OrderType(this.value);
static OrderType fromString(String value) {
return OrderType.values.firstWhere(
(type) => type.value == value,
orElse: () => OrderType.dineIn,
);
}
}
@@ -0,0 +1,13 @@
enum ProductCategory {
none('None'),
drink('Minuman'),
food('Makanan'),
snack('Snack');
final String value;
const ProductCategory(this.value);
bool get isFood => this == ProductCategory.food;
bool get isDrink => this == ProductCategory.drink;
bool get isSnack => this == ProductCategory.snack;
}
@@ -0,0 +1,43 @@
import 'package:enaklo_pos/core/extensions/int_ext.dart';
import 'product_category.dart';
class ProductModel {
final String image;
final String name;
final ProductCategory category;
final int price;
final int stock;
ProductModel({
required this.image,
required this.name,
required this.category,
required this.price,
required this.stock,
});
String get priceFormat => price.currencyFormatRp;
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is ProductModel &&
other.image == image &&
other.name == name &&
other.category == category &&
other.price == price &&
other.stock == stock;
}
@override
int get hashCode {
return image.hashCode ^
name.hashCode ^
category.hashCode ^
price.hashCode ^
stock.hashCode;
}
}
@@ -0,0 +1,94 @@
import 'dart:convert';
import 'dart:developer';
import 'package:enaklo_pos/data/models/response/product_response_model.dart';
class ProductQuantity {
final Product product;
int quantity;
String notes;
ProductQuantity({
required this.product,
required this.quantity,
this.notes = '',
});
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is ProductQuantity &&
other.product == product &&
other.quantity == quantity &&
other.notes == notes;
}
@override
int get hashCode => product.hashCode ^ quantity.hashCode ^ notes.hashCode;
Map<String, dynamic> toMap() {
return {
'product': product.toMap(),
'quantity': quantity,
'notes': notes,
};
}
Map<String, dynamic> toLocalMap(int orderId) {
log("OrderProductId: ${product.id}");
return {
'id_order': orderId,
'id_product': product.productId,
'quantity': quantity,
'price': product.price,
'notes': notes,
};
}
Map<String, dynamic> toServerMap(int? orderId) {
log("toServerMap: ${product.productId}");
return {
'id_order': orderId ?? 0,
'id_product': product.productId,
'quantity': quantity,
'price': product.price,
'notes': notes,
};
}
factory ProductQuantity.fromMap(Map<String, dynamic> map) {
return ProductQuantity(
product: Product.fromMap(map['product']),
quantity: map['quantity']?.toInt() ?? 0,
notes: map['notes'] ?? '',
);
}
factory ProductQuantity.fromLocalMap(Map<String, dynamic> map) {
log("ProductQuantity: $map");
return ProductQuantity(
product: Product.fromOrderMap(map),
quantity: map['quantity']?.toInt() ?? 0,
notes: map['notes'] ?? '',
);
}
String toJson() => json.encode(toMap());
factory ProductQuantity.fromJson(String source) =>
ProductQuantity.fromMap(json.decode(source));
ProductQuantity copyWith({
Product? product,
int? quantity,
String? notes,
}) {
return ProductQuantity(
product: product ?? this.product,
quantity: quantity ?? this.quantity,
notes: notes ?? this.notes,
);
}
}