Initial commit
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user