- customer_master_screen.dart: const 使用と SnackBarAction の修正 - employee_master_screen.dart: DropdownButtonFormField のパラメータ追加 - database_helper.dart: jsonEncode メソッドの修正、isDeleted フィールドのチェック - main.dart: ScaffoldMessenger と Navigator のルートジェネレータ実装
85 lines
No EOL
2.2 KiB
Dart
85 lines
No EOL
2.2 KiB
Dart
// Version: 1.0.0
|
||
import '../services/database_helper.dart';
|
||
|
||
class Customer {
|
||
int? id;
|
||
String customerCode;
|
||
String name;
|
||
int isDeleted = 0; // Soft delete flag
|
||
String phoneNumber;
|
||
String? email;
|
||
String address;
|
||
int salesPersonId; // NULL 可(担当未設定)
|
||
int taxRate; // 10%=8, 5%=4 など (小数点切り捨て)
|
||
int discountRate; // パーセント(例:10% なら 10)
|
||
|
||
Customer({
|
||
this.id,
|
||
required this.customerCode,
|
||
required this.name,
|
||
required this.phoneNumber,
|
||
this.email,
|
||
required this.address,
|
||
this.salesPersonId = -1, // -1: 未設定
|
||
this.taxRate = 8, // Default 10%
|
||
this.discountRate = 0,
|
||
});
|
||
|
||
Map<String, dynamic> toMap() {
|
||
return {
|
||
'id': id,
|
||
'customer_code': customerCode,
|
||
'name': name,
|
||
'phone_number': phoneNumber,
|
||
'email': email ?? '',
|
||
'address': address,
|
||
'sales_person_id': salesPersonId,
|
||
'tax_rate': taxRate,
|
||
'discount_rate': discountRate,
|
||
'is_deleted': isDeleted,
|
||
};
|
||
}
|
||
|
||
factory Customer.fromMap(Map<String, dynamic> map) {
|
||
return Customer(
|
||
id: map['id'] as int?,
|
||
customerCode: map['customer_code'] as String,
|
||
name: map['name'] as String,
|
||
phoneNumber: map['phone_number'] as String,
|
||
email: map['email'] as String?,
|
||
address: map['address'] as String,
|
||
salesPersonId: map['sales_person_id'] as int? ?? -1,
|
||
taxRate: map['tax_rate'] as int? ?? 8,
|
||
discountRate: map['discount_rate'] as int? ?? 0,
|
||
);
|
||
}
|
||
|
||
Customer copyWith({
|
||
int? id,
|
||
String? customerCode,
|
||
String? name,
|
||
String? phoneNumber,
|
||
String? email,
|
||
String? address,
|
||
int? salesPersonId,
|
||
int? taxRate,
|
||
int? discountRate,
|
||
}) {
|
||
return Customer(
|
||
id: id ?? this.id,
|
||
customerCode: customerCode ?? this.customerCode,
|
||
name: name ?? this.name,
|
||
phoneNumber: phoneNumber ?? this.phoneNumber,
|
||
email: email ?? this.email,
|
||
address: address ?? this.address,
|
||
salesPersonId: salesPersonId ?? this.salesPersonId,
|
||
taxRate: taxRate ?? this.taxRate,
|
||
discountRate: discountRate ?? this.discountRate,
|
||
);
|
||
}
|
||
|
||
// Snapshot for Event Sourcing(簡易版)
|
||
Map<String, dynamic> toSnapshot() {
|
||
return toMap();
|
||
}
|
||
} |