Files
home-control/lib/models/factura.dart
2026-06-14 15:03:29 -04:00

65 lines
1.7 KiB
Dart

class Factura {
final int? id;
final int servicioId;
final double monto;
final String fechaEmision;
final String fechaVencimiento;
final String estado;
final String? nota;
final String? fechaPago;
Factura({
this.id,
required this.servicioId,
required this.monto,
required this.fechaEmision,
required this.fechaVencimiento,
this.estado = 'Pendiente',
this.nota,
this.fechaPago,
});
Factura copyWith({
int? id,
int? servicioId,
double? monto,
String? fechaEmision,
String? fechaVencimiento,
String? estado,
String? nota,
String? fechaPago,
}) =>
Factura(
id: id ?? this.id,
servicioId: servicioId ?? this.servicioId,
monto: monto ?? this.monto,
fechaEmision: fechaEmision ?? this.fechaEmision,
fechaVencimiento: fechaVencimiento ?? this.fechaVencimiento,
estado: estado ?? this.estado,
nota: nota ?? this.nota,
fechaPago: fechaPago ?? this.fechaPago,
);
Map<String, dynamic> toMap() => {
'id': id,
'servicio_id': servicioId,
'monto': monto,
'fecha_emision': fechaEmision,
'fecha_vencimiento': fechaVencimiento,
'estado': estado,
'nota': nota,
'fecha_pago': fechaPago,
};
factory Factura.fromMap(Map<String, dynamic> map) => Factura(
id: map['id'] as int?,
servicioId: map['servicio_id'] as int,
monto: (map['monto'] as num).toDouble(),
fechaEmision: map['fecha_emision'] as String,
fechaVencimiento: map['fecha_vencimiento'] as String,
estado: map['estado'] as String? ?? 'Pendiente',
nota: map['nota'] as String?,
fechaPago: map['fecha_pago'] as String?,
);
}