feat: 売上入力画面実装開始と DB API 追加\n\n- sales_screen.dart の基本実装(商品検索・合計金額表示)\n- database_helper.dart に insertSales/getSales CRUD API 追加\n- README.md の次期実装予定タスク更新
This commit is contained in:
parent
426c280cb6
commit
5fe847a27f
1 changed files with 41 additions and 0 deletions
|
|
@ -343,6 +343,47 @@ class DatabaseHelper {
|
||||||
//_estimate_snapshots テーブルも必要に応じて追加可
|
//_estimate_snapshots テーブルも必要に応じて追加可
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========== Sales CRUD ======
|
||||||
|
|
||||||
|
Future<int> insertSales(String saleNo, String customerName, DateTime date, List<dynamic> items) async {
|
||||||
|
final db = await instance.database;
|
||||||
|
|
||||||
|
// 売上番号の重複チェック
|
||||||
|
final existing = await db.query('sales', where: 'sale_no = ?', whereArgs: [saleNo]);
|
||||||
|
if (existing.isNotEmpty) {
|
||||||
|
throw ArgumentError('売上番号「$saleNo」は既に存在します');
|
||||||
|
}
|
||||||
|
|
||||||
|
final itemsJson = jsonEncode(items);
|
||||||
|
final totalAmount = items.fold(0, (sum, item) => sum + (item['amount'] as num).toDouble());
|
||||||
|
|
||||||
|
return await db.insert('sales', {
|
||||||
|
'sale_no': saleNo,
|
||||||
|
'customer_name': customerName,
|
||||||
|
'date': date.toIso8601String(),
|
||||||
|
'total_amount': totalAmount,
|
||||||
|
'tax_rate': 10,
|
||||||
|
'items_json': itemsJson,
|
||||||
|
'created_at': DateTime.now().toIso8601String(),
|
||||||
|
'updated_at': DateTime.now().toIso8601String(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<dynamic>> getSales() async {
|
||||||
|
final db = await instance.database;
|
||||||
|
final List<Map<String, dynamic>> maps = await db.query('sales', orderBy: 'created_at DESC');
|
||||||
|
|
||||||
|
return (maps as List).map((json) => json);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<dynamic?> getSales(int id) async {
|
||||||
|
final db = await instance.database;
|
||||||
|
final maps = await db.query('sales', where: 'id = ?', whereArgs: [id]);
|
||||||
|
|
||||||
|
if (maps.isEmpty) return null;
|
||||||
|
return maps.first;
|
||||||
|
}
|
||||||
|
|
||||||
// ========== Product CRUD ======
|
// ========== Product CRUD ======
|
||||||
|
|
||||||
Future<int> insert(Product product) async {
|
Future<int> insert(Product product) async {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue