73 lines
No EOL
2.1 KiB
Dart
73 lines
No EOL
2.1 KiB
Dart
// Version: 1.1 (売上モデル実装)
|
|
import 'dart:convert';
|
|
|
|
class Sale {
|
|
int? id;
|
|
String? saleNo;
|
|
String customerName;
|
|
DateTime date;
|
|
double totalAmount;
|
|
double taxRate;
|
|
Map<String, dynamic>? items; // LineItem ネスト構造
|
|
DateTime createdAt;
|
|
DateTime updatedAt;
|
|
|
|
Sale({
|
|
this.id,
|
|
this.saleNo,
|
|
required this.customerName,
|
|
required this.date,
|
|
required this.totalAmount,
|
|
this.taxRate = 10,
|
|
this.items,
|
|
DateTime? createdAt,
|
|
DateTime? updatedAt,
|
|
}) : createdAt = createdAt ?? DateTime.now(),
|
|
updatedAt = updatedAt ?? DateTime.now();
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
'id': id,
|
|
'sale_no': saleNo,
|
|
'customer_name': customerName,
|
|
'date': date.toIso8601String(),
|
|
'total_amount': totalAmount,
|
|
'tax_rate': taxRate,
|
|
'items': items,
|
|
'created_at': createdAt.toIso8601String(),
|
|
'updated_at': updatedAt.toIso8601String(),
|
|
};
|
|
}
|
|
|
|
factory Sale.fromMap(Map<String, dynamic> map) {
|
|
return Sale(
|
|
id: map['id'] as int?,
|
|
saleNo: map['sale_no'] as String?,
|
|
customerName: map['customer_name'] as String,
|
|
date: DateTime.parse(map['date'] as String),
|
|
totalAmount: (map['total_amount'] as num).toDouble(),
|
|
taxRate: map['tax_rate'] as double? ?? 10,
|
|
items: map['items'] as Map<String, dynamic>? ,
|
|
createdAt: map['created_at'] != null ? DateTime.parse(map['created_at']) : DateTime.now(),
|
|
updatedAt: map['updated_at'] != null ? DateTime.parse(map['updated_at']) : DateTime.now(),
|
|
);
|
|
}
|
|
|
|
String toJson() => json.encode(toMap());
|
|
|
|
factory Sale.fromJson(String source) => Sale.fromMap(json.decode(source) as Map<String, dynamic>);
|
|
|
|
@override
|
|
String toString() {
|
|
return 'Sale(id: $id, saleNo: $saleNo, customerName: $customerName, date: $date, totalAmount: $totalAmount, taxRate: $taxRate, items: $items)';
|
|
}
|
|
|
|
@override
|
|
bool operator ==(covariant Sale other) {
|
|
if (identical(this, other)) return true;
|
|
return other.id == id && other.saleNo == saleNo;
|
|
}
|
|
|
|
@override
|
|
int get hashCode => id ^ saleNo;
|
|
} |