feat: BD v2 — tablas clientes y suscripciones con migración
- BD versión 2 con onUpgrade automático desde v1 - Tabla clientes: nombre, teléfono, email, dirección - Tabla suscripciones: cliente_id, servicio, tipo, plan, estado, fechas, monto - Modelo Suscripcion con props calculadas vencida y activa - SuscripcionesDao: getByCliente, getByEstado, getProximasAVencer, cambiarEstado - Seed v2: 3 clientes y 5 suscripciones con estados variados Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
3e2294faf6
commit
4d3d298773
@@ -0,0 +1,40 @@
|
||||
import '../database_helper.dart';
|
||||
import '../../models/cliente.dart';
|
||||
|
||||
class ClientesDao {
|
||||
final _db = DatabaseHelper.instance;
|
||||
|
||||
Future<List<Cliente>> getAll() async {
|
||||
final db = await _db.db;
|
||||
final rows = await db.query('clientes', orderBy: 'nombre ASC');
|
||||
return rows.map(Cliente.fromMap).toList();
|
||||
}
|
||||
|
||||
Future<Cliente?> getById(int id) async {
|
||||
final db = await _db.db;
|
||||
final rows = await db.query('clientes', where: 'id = ?', whereArgs: [id]);
|
||||
return rows.isEmpty ? null : Cliente.fromMap(rows.first);
|
||||
}
|
||||
|
||||
Future<int> insert(Cliente c) async {
|
||||
final db = await _db.db;
|
||||
return db.insert('clientes', c.toMap());
|
||||
}
|
||||
|
||||
Future<int> update(Cliente c) async {
|
||||
final db = await _db.db;
|
||||
return db.update('clientes', c.toMap(),
|
||||
where: 'id = ?', whereArgs: [c.id]);
|
||||
}
|
||||
|
||||
Future<int> delete(int id) async {
|
||||
final db = await _db.db;
|
||||
return db.delete('clientes', where: 'id = ?', whereArgs: [id]);
|
||||
}
|
||||
|
||||
Future<List<Cliente>> getPendientes() async {
|
||||
final db = await _db.db;
|
||||
final rows = await db.query('clientes', where: 'sincronizado = 0');
|
||||
return rows.map(Cliente.fromMap).toList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user