Files
app-grosir/lib/models/product.dart
2026-07-23 22:12:32 +07:00

52 lines
1.3 KiB
Dart

class Product {
final String id;
final String name;
final String barcode;
final double price;
final double priceReseller;
final int stock;
final int minStock;
final double hargaPokok;
Product({
required this.id,
required this.name,
this.barcode = '',
required this.price,
this.priceReseller = 0,
required this.stock,
this.minStock = 5,
this.hargaPokok = 0,
});
factory Product.fromJson(Map<String, dynamic> json) {
return Product(
id: json['id'] as String,
name: json['name'] as String,
barcode: json['barcode'] != null ? json['barcode'] as String : '',
price: (json['price'] as num).toDouble(),
priceReseller: json['price_reseller'] != null
? (json['price_reseller'] as num).toDouble()
: 0,
stock: json['stock'] as int,
minStock: json['min_stock'] != null
? (json['min_stock'] as int)
: 5,
hargaPokok: json['harga_pokok'] != null
? (json['harga_pokok'] as num).toDouble()
: 0,
);
}
Map<String, dynamic> toJson() => {
'id': id,
'name': name,
'barcode': barcode,
'price': price,
'price_reseller': priceReseller,
'stock': stock,
'min_stock': minStock,
'harga_pokok': hargaPokok,
};
}