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