- lib/models/product.dart: Product クラス作成 - lib/services/database_helper.dart: getProducts/insert/update/delete/Product snapshot API 追加 - lib/screens/estimate_screen.dart: 商品選択・合計計算・得意先連携ロジック実装
75 lines
No EOL
1.7 KiB
Dart
75 lines
No EOL
1.7 KiB
Dart
// Version: 1.0.0
|
|
import '../services/database_helper.dart';
|
|
|
|
class Product {
|
|
int? id;
|
|
String productCode;
|
|
String name;
|
|
int price; // 単価(税込)
|
|
int stock;
|
|
String? category;
|
|
String? unit;
|
|
int isDeleted = 0; // Soft delete flag
|
|
|
|
Product({
|
|
this.id,
|
|
required this.productCode,
|
|
required this.name,
|
|
required this.price,
|
|
this.stock = 0,
|
|
this.category,
|
|
this.unit,
|
|
this.isDeleted = 0,
|
|
});
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
'id': id,
|
|
'product_code': productCode,
|
|
'name': name,
|
|
'price': price,
|
|
'stock': stock,
|
|
'category': category ?? '',
|
|
'unit': unit ?? '',
|
|
'is_deleted': isDeleted,
|
|
};
|
|
}
|
|
|
|
factory Product.fromMap(Map<String, dynamic> map) {
|
|
return Product(
|
|
id: map['id'] as int?,
|
|
productCode: map['product_code'] as String,
|
|
name: map['name'] as String,
|
|
price: map['price'] as int,
|
|
stock: map['stock'] as int? ?? 0,
|
|
category: map['category'] as String?,
|
|
unit: map['unit'] as String?,
|
|
isDeleted: map['is_deleted'] as int? ?? 0,
|
|
);
|
|
}
|
|
|
|
Product copyWith({
|
|
int? id,
|
|
String? productCode,
|
|
String? name,
|
|
int? price,
|
|
int? stock,
|
|
String? category,
|
|
String? unit,
|
|
int? isDeleted,
|
|
}) {
|
|
return Product(
|
|
id: id ?? this.id,
|
|
productCode: productCode ?? this.productCode,
|
|
name: name ?? this.name,
|
|
price: price ?? this.price,
|
|
stock: stock ?? this.stock,
|
|
category: category ?? this.category,
|
|
unit: unit ?? this.unit,
|
|
isDeleted: isDeleted ?? this.isDeleted,
|
|
);
|
|
}
|
|
|
|
// 税込価格(引数にない場合は自身)
|
|
int get taxPrice => price;
|
|
} |