From ff17874169e161d640636d72158a2358ac2aca54 Mon Sep 17 00:00:00 2001 From: joe Date: Sat, 7 Mar 2026 19:06:25 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A3=B2=E4=B8=8A=E5=85=A5=E5=8A=9B?= =?UTF-8?q?=E7=94=BB=E9=9D=A2=E5=AE=9F=E8=A3=85=E6=BA=96=E5=82=99=E3=82=92?= =?UTF-8?q?=E5=AE=8C=E4=BA=86\n\n-=20DatabaseHelper=20=E3=81=AB=20sales=20?= =?UTF-8?q?=E3=83=86=E3=83=BC=E3=83=96=E3=83=AB=E5=AE=9A=E7=BE=A9=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0\n-=20Sale=20=E3=83=A2=E3=83=87=E3=83=AB=EF=BC=88lib/m?= =?UTF-8?q?odels/sale.dart=EF=BC=89=E4=BD=9C=E6=88=90\n-=20=E7=9F=AD?= =?UTF-8?q?=E6=9C=9F=E8=A8=88=E7=94=BB=E3=81=AE=E5=84=AA=E5=85=88=E9=A0=86?= =?UTF-8?q?=E4=BD=8D=E6=9B=B4=E6=96=B0=EF=BC=88PDF=20=E3=82=92=20Sprint=20?= =?UTF-8?q?5=20=E3=81=B8=E5=BB=B6=E6=9C=9F=EF=BC=89\n-=20README.md=20?= =?UTF-8?q?=E3=81=AE=E5=AE=9F=E8=A3=85=E6=B8=88=E3=81=BF=E6=A9=9F=E8=83=BD?= =?UTF-8?q?=E3=82=B9=E3=83=86=E3=83=BC=E3=82=BF=E3=82=B9=E5=8F=8D=E6=98=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- lib/models/sale.dart | 73 +++++++++++++++++++++++++++++++ lib/services/database_helper.dart | 16 +++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 lib/models/sale.dart diff --git a/README.md b/README.md index 22bf17d..b01d01a 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ | 機能 | ファイル | 状態 | |------|---------|----| -| **見積入力** | `lib/screens/estimate_screen.dart` | ✅ 完了(エラーハンドリング追加)
- 得意先選択・商品追加
- DatabaseHelper を介した保存
- エラーハンドリング完全化
📝 次のステップ:PDF 帳票出力テンプレート実装 +| **見積入力** | `lib/screens/estimate_screen.dart` | ✅ 完了(エラーハンドリング追加)
- 得意先選択・商品追加
- DatabaseHelper を介した保存
- エラーハンドリング完全化
📝 次のステップ:売上入力画面実装 | DB CRUD API | `lib/services/database_helper.dart` | ✅ Estimate テーブル対応
・insertEstimate
・getEstimates
・estimate CRUD | | Estimate モデル | `lib/models/estimate.dart` | ✅ LineItem ネスト構造
・toMap/fromMap 実装 | diff --git a/lib/models/sale.dart b/lib/models/sale.dart new file mode 100644 index 0000000..82ec412 --- /dev/null +++ b/lib/models/sale.dart @@ -0,0 +1,73 @@ +// Version: 1.1 (売上モデル実装) +import 'dart:convert'; + +class Sale { + int? id; + String? saleNo; + String customerName; + DateTime date; + double totalAmount; + double taxRate; + Map? 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 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 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? , + 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); + + @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; +} \ No newline at end of file diff --git a/lib/services/database_helper.dart b/lib/services/database_helper.dart index cb1c44b..5b3f42f 100644 --- a/lib/services/database_helper.dart +++ b/lib/services/database_helper.dart @@ -108,6 +108,22 @@ class DatabaseHelper { ) '''); + // sales テーブル(売用书) + await db.execute(''' + CREATE TABLE sales ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + sale_no TEXT NOT NULL UNIQUE, + customer_id INTEGER, + customer_name TEXT NOT NULL, + date TEXT NOT NULL, + total_amount REAL NOT NULL, + tax_rate REAL DEFAULT 10, + items_json TEXT NOT NULL, + created_at TEXT NOT NULL, + updated_at TEXT NOT NULL + ) + '''); + // customer_snapshots テーブル(イベントソーシング用) await db.execute(''' CREATE TABLE customer_snapshots (