88 lines
2.4 KiB
Dart
88 lines
2.4 KiB
Dart
|
|
import 'brand_model.dart';
|
|
|
|
class RDOrderItem {
|
|
final String productId;
|
|
final String sku;
|
|
final String name;
|
|
final String categoryName;
|
|
final String brandName;
|
|
final double price; // Ensure price is double
|
|
final int gst; // Ensure GST is int
|
|
final int hsnCode; // Ensure HSN_Code is int
|
|
final String description;
|
|
final List<BrandImage> image;
|
|
int? quantity;
|
|
int? remainingQuantity;
|
|
int? processquantity;
|
|
RDOrderItem({
|
|
required this.productId,
|
|
required this.sku,
|
|
required this.name,
|
|
required this.categoryName,
|
|
required this.brandName,
|
|
required this.price,
|
|
required this.gst,
|
|
required this.hsnCode,
|
|
required this.description,
|
|
required this.image,
|
|
this.quantity,
|
|
this.remainingQuantity,
|
|
this.processquantity = 1,
|
|
});
|
|
|
|
factory RDOrderItem.fromJson(Map<String, dynamic> json) {
|
|
return RDOrderItem(
|
|
productId: json['productId'].toString()?? '',
|
|
sku: json['SKU'] ?? '',
|
|
name: json['name'] ?? '',
|
|
categoryName: json['categoryName'] ?? '',
|
|
brandName: json['brandName'] ?? '',
|
|
price: (json['price'] as num).toDouble(),
|
|
// Ensure price is double
|
|
gst: json['GST'] ?? 0,
|
|
// Handle GST as int
|
|
hsnCode: json['HSN_Code'] ?? 0,
|
|
// Handle HSN_Code as int
|
|
description: json['description'] ?? '',
|
|
//image: List<String>.from(json['image'] ?? []),
|
|
image : (json["image"] as List)
|
|
.map((item) => BrandImage.fromJson(item))
|
|
.toList(),
|
|
quantity: json['quantity'] ?? 0,
|
|
// Handle quantity as int
|
|
processquantity: json['processQuantity']??1,
|
|
remainingQuantity: json['remainingQuantity'] ??
|
|
0, // Handle remainingQuantity as int
|
|
);
|
|
}
|
|
|
|
// Method to convert instance to JSON
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'productId': productId,
|
|
'SKU': sku,
|
|
'name': name,
|
|
'categoryName': categoryName,
|
|
'brandName': brandName,
|
|
'price': price,
|
|
'GST': gst,
|
|
'HSN_Code': hsnCode,
|
|
'description': description,
|
|
'image': image,
|
|
'quantity': quantity,
|
|
'remainingQuantity': remainingQuantity,
|
|
'processquantity':processquantity,
|
|
};
|
|
}
|
|
|
|
// Overriding the toString method
|
|
@override
|
|
String toString() {
|
|
return 'RDOrderItem(productId: $productId, sku: $sku, name: $name, categoryName: $categoryName, '
|
|
'brandName: $brandName, price: $price, gst: $gst, hsnCode: $hsnCode, description: $description, '
|
|
'image: $image, quantity: $quantity, remainingQuantity: $remainingQuantity, processquantity: $processquantity)';
|
|
}
|
|
}
|
|
|