194 lines
6.3 KiB
Dart
194 lines
6.3 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 double? itemLength;
|
|
final double? itemWidth;
|
|
final double? itemHeight;
|
|
final String? dimensionUom;
|
|
|
|
final double? packageLength;
|
|
final double? packageWidth;
|
|
final double? packageHeight;
|
|
final String? packageDimensionUom;
|
|
|
|
final String? manufacturerCode;
|
|
final String? material;
|
|
final String? brandName;
|
|
final String? countryOfOrigin;
|
|
|
|
final double? weightInG;
|
|
final double? packageWeightInG;
|
|
final double? volumetricWeightInKg;
|
|
|
|
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.itemLength,
|
|
this.itemWidth,
|
|
this.itemHeight,
|
|
this.dimensionUom = 'cm',
|
|
this.packageLength,
|
|
this.packageWidth,
|
|
this.packageHeight,
|
|
this.packageDimensionUom = 'cm',
|
|
this.manufacturerCode,
|
|
this.material,
|
|
this.brandName,
|
|
this.countryOfOrigin,
|
|
this.weightInG,
|
|
this.packageWeightInG,
|
|
this.volumetricWeightInKg,
|
|
this.priceCalcRule = 'MANUAL',
|
|
this.autoCalculatePrice = false,
|
|
this.purityFactor,
|
|
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'],
|
|
itemLength: (json['itemLength'] ?? json['item_length'] as num?)?.toDouble(),
|
|
itemWidth: (json['itemWidth'] ?? json['item_width'] as num?)?.toDouble(),
|
|
itemHeight: (json['itemHeight'] ?? json['item_height'] as num?)?.toDouble(),
|
|
dimensionUom: json['dimensionUom'] ?? json['dimension_uom'] ?? 'cm',
|
|
packageLength: (json['packageLength'] ?? json['package_length'] as num?)?.toDouble(),
|
|
packageWidth: (json['packageWidth'] ?? json['package_width'] as num?)?.toDouble(),
|
|
packageHeight: (json['packageHeight'] ?? json['package_height'] as num?)?.toDouble(),
|
|
packageDimensionUom: json['packageDimensionUom'] ?? json['package_dimension_uom'] ?? 'cm',
|
|
manufacturerCode: json['manufacturerCode'] ?? json['manufacturer_code'],
|
|
material: json['material'],
|
|
brandName: json['brandName'] ?? json['brand_name'],
|
|
countryOfOrigin: json['countryOfOrigin'] ?? json['country_of_origin'],
|
|
weightInG: (json['weightInG'] ?? json['weight_in_g'] as num?)?.toDouble(),
|
|
packageWeightInG: (json['packageWeightInG'] ?? json['package_weight_in_g'] as num?)?.toDouble(),
|
|
volumetricWeightInKg: (json['volumetricWeightInKg'] ?? json['volumetric_weight_in_kg'] as num?)?.toDouble(),
|
|
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(),
|
|
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) {
|
|
if (i is Map) {
|
|
return (i['id'] as num).toInt();
|
|
} else if (i is num) {
|
|
return i.toInt();
|
|
}
|
|
return 0;
|
|
}).where((id) => id > 0).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,
|
|
'itemLength': itemLength,
|
|
'itemWidth': itemWidth,
|
|
'itemHeight': itemHeight,
|
|
'dimensionUom': dimensionUom,
|
|
'packageLength': packageLength,
|
|
'packageWidth': packageWidth,
|
|
'packageHeight': packageHeight,
|
|
'packageDimensionUom': packageDimensionUom,
|
|
'manufacturerCode': manufacturerCode,
|
|
'material': material,
|
|
'brandName': brandName,
|
|
'countryOfOrigin': countryOfOrigin,
|
|
'weightInG': weightInG,
|
|
'packageWeightInG': packageWeightInG,
|
|
'volumetricWeightInKg': volumetricWeightInKg,
|
|
'priceCalcRule': priceCalcRule,
|
|
'autoCalculatePrice': autoCalculatePrice,
|
|
'purityFactor': purityFactor,
|
|
'makingCharges': makingCharges,
|
|
'makingChargesType': makingChargesType,
|
|
'wastagePercentage': wastagePercentage,
|
|
'isActive': isActive,
|
|
};
|
|
}
|
|
}
|