Compare commits
2 Commits
6599e6fe7c
...
bd02f389e5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd02f389e5 | ||
|
|
5534aad0d4 |
@ -70,7 +70,7 @@ Future<void> onPrint(
|
||||
.toList();
|
||||
final printValue = await PrintDataoutputs.instance.printKitchen(
|
||||
productByPrinter,
|
||||
order.tableNumber!,
|
||||
order.tableNumber ?? "",
|
||||
order.orderNumber ?? "",
|
||||
authData.user?.name ?? "",
|
||||
order.metadata?['customer_name'] ?? "",
|
||||
|
||||
@ -56,7 +56,7 @@ class ProductRemoteDatasource {
|
||||
log("Dio error: ${e.message}");
|
||||
return Left(e.response?.data['message'] ?? 'Gagal mengambil produk');
|
||||
} catch (e) {
|
||||
log("Unexpected error: $e");
|
||||
log("Unexpected error: $e", name: "productRemoteDatasource");
|
||||
return const Left('Unexpected error occurred');
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,14 @@
|
||||
// ignore_for_file: public_member_api_docs, sort_constructors_first
|
||||
import 'dart:convert';
|
||||
|
||||
int? parseInt(dynamic value) {
|
||||
if (value == null) return null;
|
||||
if (value is int) return value;
|
||||
if (value is double) return value.toInt();
|
||||
if (value is String) return int.tryParse(value);
|
||||
return null;
|
||||
}
|
||||
|
||||
class ProductResponseModel {
|
||||
final bool? success;
|
||||
final ProductData? data;
|
||||
@ -51,10 +59,10 @@ class ProductData {
|
||||
? []
|
||||
: List<Product>.from(
|
||||
json["products"].map((x) => Product.fromMap(x))),
|
||||
totalCount: json["total_count"],
|
||||
page: json["page"],
|
||||
limit: json["limit"],
|
||||
totalPages: json["total_pages"],
|
||||
totalCount: parseInt(json["total_count"]),
|
||||
page: parseInt(json["page"]),
|
||||
limit: parseInt(json["limit"]),
|
||||
totalPages: parseInt(json["total_pages"]),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toMap() => {
|
||||
@ -116,8 +124,8 @@ class Product {
|
||||
sku: json["sku"],
|
||||
name: json["name"],
|
||||
description: json["description"],
|
||||
price: json["price"],
|
||||
cost: json["cost"],
|
||||
price: parseInt(json["price"]),
|
||||
cost: parseInt(json["cost"]),
|
||||
businessType: json["business_type"],
|
||||
imageUrl: json["image_url"],
|
||||
printerType: json["printer_type"],
|
||||
@ -137,7 +145,7 @@ class Product {
|
||||
|
||||
factory Product.fromOrderMap(Map<String, dynamic> json) => Product(
|
||||
id: json["id_product"],
|
||||
price: json["price"],
|
||||
price: parseInt(json["price"]),
|
||||
);
|
||||
|
||||
factory Product.fromLocalMap(Map<String, dynamic> json) => Product(
|
||||
@ -147,8 +155,8 @@ class Product {
|
||||
sku: json["sku"],
|
||||
name: json["name"],
|
||||
description: json["description"],
|
||||
price: json["price"],
|
||||
cost: json["cost"],
|
||||
price: parseInt(json["price"]),
|
||||
cost: parseInt(json["cost"]),
|
||||
businessType: json["business_type"],
|
||||
imageUrl: json["image_url"],
|
||||
printerType: json["printer_type"],
|
||||
@ -207,96 +215,6 @@ class Product {
|
||||
? []
|
||||
: List<dynamic>.from(variants!.map((x) => x.toMap())),
|
||||
};
|
||||
|
||||
@override
|
||||
bool operator ==(covariant Product other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other.id == id &&
|
||||
other.organizationId == organizationId &&
|
||||
other.categoryId == categoryId &&
|
||||
other.sku == sku &&
|
||||
other.name == name &&
|
||||
other.description == description &&
|
||||
other.price == price &&
|
||||
other.cost == cost &&
|
||||
other.businessType == businessType &&
|
||||
other.imageUrl == imageUrl &&
|
||||
other.printerType == printerType &&
|
||||
other.metadata == metadata &&
|
||||
other.isActive == isActive &&
|
||||
other.createdAt == createdAt &&
|
||||
other.updatedAt == updatedAt &&
|
||||
_listEquals(other.variants, variants);
|
||||
}
|
||||
|
||||
bool _listEquals(List<ProductVariant>? a, List<ProductVariant>? b) {
|
||||
if (a == null && b == null) return true;
|
||||
if (a == null || b == null) return false;
|
||||
if (a.length != b.length) return false;
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
if (a[i] != b[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return id.hashCode ^
|
||||
organizationId.hashCode ^
|
||||
categoryId.hashCode ^
|
||||
sku.hashCode ^
|
||||
name.hashCode ^
|
||||
description.hashCode ^
|
||||
price.hashCode ^
|
||||
cost.hashCode ^
|
||||
businessType.hashCode ^
|
||||
imageUrl.hashCode ^
|
||||
printerType.hashCode ^
|
||||
metadata.hashCode ^
|
||||
isActive.hashCode ^
|
||||
createdAt.hashCode ^
|
||||
updatedAt.hashCode ^
|
||||
variants.hashCode;
|
||||
}
|
||||
|
||||
Product copyWith({
|
||||
String? id,
|
||||
String? organizationId,
|
||||
String? categoryId,
|
||||
String? sku,
|
||||
String? name,
|
||||
String? description,
|
||||
int? price,
|
||||
int? cost,
|
||||
String? businessType,
|
||||
String? imageUrl,
|
||||
String? printerType,
|
||||
Map<String, dynamic>? metadata,
|
||||
bool? isActive,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
List<ProductVariant>? variants,
|
||||
}) {
|
||||
return Product(
|
||||
id: id ?? this.id,
|
||||
organizationId: organizationId ?? this.organizationId,
|
||||
categoryId: categoryId ?? this.categoryId,
|
||||
sku: sku ?? this.sku,
|
||||
name: name ?? this.name,
|
||||
description: description ?? this.description,
|
||||
price: price ?? this.price,
|
||||
cost: cost ?? this.cost,
|
||||
businessType: businessType ?? this.businessType,
|
||||
imageUrl: imageUrl ?? this.imageUrl,
|
||||
printerType: printerType ?? this.printerType,
|
||||
metadata: metadata ?? this.metadata,
|
||||
isActive: isActive ?? this.isActive,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
variants: variants ?? this.variants,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Category {
|
||||
@ -341,28 +259,6 @@ class Category {
|
||||
"created_at": createdAt?.toIso8601String(),
|
||||
"updated_at": updatedAt?.toIso8601String(),
|
||||
};
|
||||
|
||||
@override
|
||||
bool operator ==(covariant Category other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other.id == id &&
|
||||
other.name == name &&
|
||||
other.description == description &&
|
||||
other.image == image &&
|
||||
other.createdAt == createdAt &&
|
||||
other.updatedAt == updatedAt;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return id.hashCode ^
|
||||
name.hashCode ^
|
||||
description.hashCode ^
|
||||
image.hashCode ^
|
||||
createdAt.hashCode ^
|
||||
updatedAt.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
class ProductVariant {
|
||||
@ -390,8 +286,8 @@ class ProductVariant {
|
||||
id: json["id"],
|
||||
productId: json["product_id"],
|
||||
name: json["name"],
|
||||
priceModifier: json["price_modifier"],
|
||||
cost: json["cost"],
|
||||
priceModifier: parseInt(json["price_modifier"]),
|
||||
cost: parseInt(json["cost"]),
|
||||
metadata: json["metadata"] ?? {},
|
||||
createdAt: json["created_at"] == null
|
||||
? null
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user