pd-android-app/lib/models/rd_order_item_model.dart
2024-10-09 14:55:41 +05:30

83 lines
2.3 KiB
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<String> 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,
});
factory RDOrderItem.fromJson(Map<String, dynamic> json) {
return RDOrderItem(
productId: json['productId'] ?? '',
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'] ?? []),
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)';
}
}