123 lines
3.5 KiB
Dart
123 lines
3.5 KiB
Dart
class Product {
|
|
final int? id;
|
|
final int? userId;
|
|
final int? categoryId;
|
|
final int? uomId;
|
|
final String? hsnCode;
|
|
|
|
final String name;
|
|
final String? sku;
|
|
final String? barcode;
|
|
final String? description;
|
|
final double? sellingPrice;
|
|
final double? gstRate;
|
|
final String? dimensions;
|
|
final String? color;
|
|
final String? size;
|
|
final String priceCalcRule;
|
|
final bool autoCalculatePrice;
|
|
final double? purityFactor;
|
|
final double? makingCharges;
|
|
final String? makingChargesType;
|
|
final double? wastagePercentage;
|
|
final bool isActive;
|
|
final List<int> imageIds;
|
|
final double? currentStock;
|
|
|
|
Product({
|
|
this.id,
|
|
this.userId,
|
|
this.categoryId,
|
|
this.uomId,
|
|
required this.name,
|
|
this.hsnCode,
|
|
this.sku,
|
|
this.barcode,
|
|
this.description,
|
|
this.sellingPrice,
|
|
this.gstRate,
|
|
this.dimensions,
|
|
this.color,
|
|
this.size,
|
|
this.priceCalcRule = 'MANUAL',
|
|
this.autoCalculatePrice = false,
|
|
this.purityFactor = 1.0,
|
|
this.makingCharges = 0.0,
|
|
this.makingChargesType = 'FLAT',
|
|
this.wastagePercentage = 0.0,
|
|
this.isActive = true,
|
|
this.imageIds = const [],
|
|
this.currentStock = 0.0,
|
|
});
|
|
|
|
factory Product.fromJson(Map<String, dynamic> json) {
|
|
return Product(
|
|
id: json['id'],
|
|
userId: json['userId'] ?? json['user_id'],
|
|
categoryId: json['categoryId'] ?? json['category_id'],
|
|
uomId: json['uomId'] ?? json['uom_id'],
|
|
name: json['name'],
|
|
hsnCode: json['hsnCode'] ?? json['hsn_code'],
|
|
sku: json['sku'],
|
|
barcode: json['barcode'],
|
|
description: json['description'],
|
|
sellingPrice: (json['sellingPrice'] ?? json['selling_price'] as num?)
|
|
?.toDouble(),
|
|
gstRate: (json['gstRate'] ?? json['gst_rate'] as num?)?.toDouble(),
|
|
dimensions: json['dimensions'],
|
|
color: json['color'],
|
|
size: json['size'],
|
|
priceCalcRule:
|
|
json['priceCalcRule'] ?? json['price_calc_rule'] ?? 'MANUAL',
|
|
autoCalculatePrice:
|
|
json['autoCalculatePrice'] ?? json['auto_calculate_price'] ?? false,
|
|
purityFactor:
|
|
(json['purityFactor'] ?? json['purity_factor'] as num?)?.toDouble() ??
|
|
1.0,
|
|
makingCharges:
|
|
(json['makingCharges'] ?? json['making_charges'] as num?)
|
|
?.toDouble() ??
|
|
0.0,
|
|
makingChargesType:
|
|
json['makingChargesType'] ?? json['making_charges_type'] ?? 'FLAT',
|
|
wastagePercentage:
|
|
(json['wastagePercentage'] ?? json['wastage_percentage'] as num?)
|
|
?.toDouble() ??
|
|
0.0,
|
|
isActive: json['isActive'] ?? json['is_active'] ?? true,
|
|
imageIds: json['images'] != null
|
|
? (json['images'] as List).map((i) => i['id'] as int).toList()
|
|
: [],
|
|
currentStock:
|
|
(json['currentStock'] ?? json['current_stock'] as num?)?.toDouble() ??
|
|
0.0,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'userId': userId,
|
|
'categoryId': categoryId,
|
|
'uomId': uomId,
|
|
'name': name,
|
|
'hsnCode': hsnCode,
|
|
'sku': sku,
|
|
'barcode': barcode,
|
|
'description': description,
|
|
'sellingPrice': sellingPrice,
|
|
'gstRate': gstRate,
|
|
'dimensions': dimensions,
|
|
'color': color,
|
|
'size': size,
|
|
'priceCalcRule': priceCalcRule,
|
|
'autoCalculatePrice': autoCalculatePrice,
|
|
'purityFactor': purityFactor,
|
|
'makingCharges': makingCharges,
|
|
'makingChargesType': makingChargesType,
|
|
'wastagePercentage': wastagePercentage,
|
|
'isActive': isActive,
|
|
};
|
|
}
|
|
}
|