Initial commit
This commit is contained in:
40
lib/providers/configuracion_provider.dart
Normal file
40
lib/providers/configuracion_provider.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../database/database_helper.dart';
|
||||
import '../models/configuracion.dart';
|
||||
import '../services/notification_service.dart';
|
||||
|
||||
class ConfiguracionProvider extends ChangeNotifier {
|
||||
final DatabaseHelper _db = DatabaseHelper.instance;
|
||||
Configuracion? _config;
|
||||
bool _cargando = false;
|
||||
|
||||
Configuracion? get config => _config;
|
||||
bool get cargando => _cargando;
|
||||
|
||||
Future<void> cargarConfiguracion() async {
|
||||
_cargando = true;
|
||||
notifyListeners();
|
||||
_config = await _db.getConfiguracion();
|
||||
if (_config == null) {
|
||||
_config = Configuracion(diasRecordatorio: '7,3,1,0');
|
||||
await _db.saveConfiguracion(_config!);
|
||||
}
|
||||
_cargando = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> guardarConfiguracion(Configuracion config) async {
|
||||
await _db.saveConfiguracion(config);
|
||||
_config = config;
|
||||
await NotificationService.instance.scheduleRecordatorios();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
List<int> get diasRecordatorioList {
|
||||
if (_config == null) return [7, 3, 1, 0];
|
||||
return _config!.diasRecordatorio
|
||||
.split(',')
|
||||
.map((e) => int.tryParse(e.trim()) ?? 0)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
61
lib/providers/factura_provider.dart
Normal file
61
lib/providers/factura_provider.dart
Normal file
@@ -0,0 +1,61 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../database/database_helper.dart';
|
||||
import '../models/factura.dart';
|
||||
|
||||
class FacturaProvider extends ChangeNotifier {
|
||||
final DatabaseHelper _db = DatabaseHelper.instance;
|
||||
List<Factura> _facturas = [];
|
||||
List<Factura> _facturasVencidas = [];
|
||||
bool _cargando = false;
|
||||
|
||||
List<Factura> get facturas => _facturas;
|
||||
List<Factura> get facturasVencidas => _facturasVencidas;
|
||||
bool get cargando => _cargando;
|
||||
|
||||
Future<void> cargarFacturas({String? estado, int? servicioId}) async {
|
||||
_cargando = true;
|
||||
notifyListeners();
|
||||
_facturas = await _db.getFacturas(estado: estado, servicioId: servicioId);
|
||||
_facturasVencidas = await _db.getFacturasVencidas();
|
||||
_cargando = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> agregarFactura(Factura factura) async {
|
||||
await _db.insertFactura(factura);
|
||||
await cargarFacturas();
|
||||
}
|
||||
|
||||
Future<void> marcarPagada(int id) async {
|
||||
final factura = _facturas.firstWhere((f) => f.id == id);
|
||||
final hoy = DateTime.now().toIso8601String().split('T')[0];
|
||||
final actualizada = factura.copyWith(estado: 'Pagada', fechaPago: hoy);
|
||||
await _db.updateFactura(actualizada);
|
||||
await cargarFacturas();
|
||||
}
|
||||
|
||||
Future<void> eliminarFactura(int id) async {
|
||||
await _db.deleteFactura(id);
|
||||
await cargarFacturas();
|
||||
}
|
||||
|
||||
Future<double> totalGastadoMes(int year, int month) async {
|
||||
return await _db.getTotalGastadoMes(year, month);
|
||||
}
|
||||
|
||||
Future<Map<String, double>> gastosPorServicio(int year, int month) async {
|
||||
return await _db.getGastosPorServicio(year, month);
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> gastoMensual(int year) async {
|
||||
return await _db.getGastoMensual(year);
|
||||
}
|
||||
|
||||
Future<List<Factura>> facturasPorMes(int year, int month) async {
|
||||
return await _db.getFacturasPorMes(year, month);
|
||||
}
|
||||
|
||||
Future<List<Factura>> facturasPorRango(String inicio, String fin) async {
|
||||
return await _db.getFacturasPorRango(inicio, fin);
|
||||
}
|
||||
}
|
||||
35
lib/providers/servicio_provider.dart
Normal file
35
lib/providers/servicio_provider.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../database/database_helper.dart';
|
||||
import '../models/servicio.dart';
|
||||
|
||||
class ServicioProvider extends ChangeNotifier {
|
||||
final DatabaseHelper _db = DatabaseHelper.instance;
|
||||
List<Servicio> _servicios = [];
|
||||
bool _cargando = false;
|
||||
|
||||
List<Servicio> get servicios => _servicios;
|
||||
bool get cargando => _cargando;
|
||||
|
||||
Future<void> cargarServicios() async {
|
||||
_cargando = true;
|
||||
notifyListeners();
|
||||
_servicios = await _db.getServicios();
|
||||
_cargando = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> agregarServicio(Servicio servicio) async {
|
||||
await _db.insertServicio(servicio);
|
||||
await cargarServicios();
|
||||
}
|
||||
|
||||
Future<void> actualizarServicio(Servicio servicio) async {
|
||||
await _db.updateServicio(servicio);
|
||||
await cargarServicios();
|
||||
}
|
||||
|
||||
Future<void> eliminarServicio(int id) async {
|
||||
await _db.deleteServicio(id);
|
||||
await cargarServicios();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user