feat: Agente Ventas SIGMAC — app de rutas y pedidos de campo
App Flutter 2.11 para vendedores de ruta de Telcotronics. Incluye ruta del día con mapa custom, catálogo, pedidos CRUD, firma digital, scanner QR/barcode, selector de clientes escalable, notificaciones in-app y soporte multiplataforma (Android + Linux desktop). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
class Cliente {
|
||||
final String id;
|
||||
final String nombre;
|
||||
final String razonSocial;
|
||||
final String direccion;
|
||||
final String telefono;
|
||||
final String nit;
|
||||
final double lat;
|
||||
final double lng;
|
||||
final String categoria;
|
||||
|
||||
const Cliente({
|
||||
required this.id,
|
||||
required this.nombre,
|
||||
required this.razonSocial,
|
||||
required this.direccion,
|
||||
required this.telefono,
|
||||
required this.nit,
|
||||
required this.lat,
|
||||
required this.lng,
|
||||
required this.categoria,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toMap() => {
|
||||
'id': id,
|
||||
'nombre': nombre,
|
||||
'razon_social': razonSocial,
|
||||
'direccion': direccion,
|
||||
'telefono': telefono,
|
||||
'nit': nit,
|
||||
'lat': lat,
|
||||
'lng': lng,
|
||||
'categoria': categoria,
|
||||
};
|
||||
|
||||
factory Cliente.fromMap(Map<String, dynamic> m) => Cliente(
|
||||
id: m['id'] as String,
|
||||
nombre: m['nombre'] as String,
|
||||
razonSocial: m['razon_social'] as String? ?? '',
|
||||
direccion: m['direccion'] as String? ?? '',
|
||||
telefono: m['telefono'] as String? ?? '',
|
||||
nit: m['nit'] as String? ?? '',
|
||||
lat: (m['lat'] as num?)?.toDouble() ?? 0.0,
|
||||
lng: (m['lng'] as num?)?.toDouble() ?? 0.0,
|
||||
categoria: m['categoria'] as String? ?? 'Minorista',
|
||||
);
|
||||
|
||||
Cliente copyWith({
|
||||
String? nombre, String? razonSocial, String? direccion,
|
||||
String? telefono, String? nit, String? categoria,
|
||||
}) => Cliente(
|
||||
id: id, lat: lat, lng: lng,
|
||||
nombre: nombre ?? this.nombre,
|
||||
razonSocial: razonSocial ?? this.razonSocial,
|
||||
direccion: direccion ?? this.direccion,
|
||||
telefono: telefono ?? this.telefono,
|
||||
nit: nit ?? this.nit,
|
||||
categoria: categoria ?? this.categoria,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import 'producto.dart';
|
||||
|
||||
class ItemPedido {
|
||||
final int? dbId;
|
||||
final Producto producto;
|
||||
int cantidad;
|
||||
double precioUnitario;
|
||||
|
||||
ItemPedido({
|
||||
this.dbId,
|
||||
required this.producto,
|
||||
required this.cantidad,
|
||||
required this.precioUnitario,
|
||||
});
|
||||
|
||||
double get subtotal => cantidad * precioUnitario;
|
||||
|
||||
Map<String, dynamic> toMap(String pedidoId) => {
|
||||
if (dbId != null) 'id': dbId,
|
||||
'pedido_id': pedidoId,
|
||||
'producto_id': producto.id,
|
||||
'cantidad': cantidad,
|
||||
'precio_unitario': precioUnitario,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
enum TipoNotificacion {
|
||||
pedidoConfirmado,
|
||||
pedidoEntregado,
|
||||
paradaProxima,
|
||||
stockBajo,
|
||||
metaVentas,
|
||||
recordatorio,
|
||||
alerta,
|
||||
}
|
||||
|
||||
extension TipoNotificacionExt on TipoNotificacion {
|
||||
String get label {
|
||||
switch (this) {
|
||||
case TipoNotificacion.pedidoConfirmado: return 'Pedido confirmado';
|
||||
case TipoNotificacion.pedidoEntregado: return 'Pedido entregado';
|
||||
case TipoNotificacion.paradaProxima: return 'Próxima parada';
|
||||
case TipoNotificacion.stockBajo: return 'Stock bajo';
|
||||
case TipoNotificacion.metaVentas: return 'Meta de ventas';
|
||||
case TipoNotificacion.recordatorio: return 'Recordatorio';
|
||||
case TipoNotificacion.alerta: return 'Alerta';
|
||||
}
|
||||
}
|
||||
|
||||
IconData get icono {
|
||||
switch (this) {
|
||||
case TipoNotificacion.pedidoConfirmado: return Icons.receipt_long;
|
||||
case TipoNotificacion.pedidoEntregado: return Icons.local_shipping;
|
||||
case TipoNotificacion.paradaProxima: return Icons.location_on;
|
||||
case TipoNotificacion.stockBajo: return Icons.inventory_2;
|
||||
case TipoNotificacion.metaVentas: return Icons.trending_up;
|
||||
case TipoNotificacion.recordatorio: return Icons.alarm;
|
||||
case TipoNotificacion.alerta: return Icons.warning_amber;
|
||||
}
|
||||
}
|
||||
|
||||
Color get color {
|
||||
switch (this) {
|
||||
case TipoNotificacion.pedidoConfirmado: return const Color(0xFF16A34A);
|
||||
case TipoNotificacion.pedidoEntregado: return const Color(0xFF0891B2);
|
||||
case TipoNotificacion.paradaProxima: return const Color(0xFF2563EB);
|
||||
case TipoNotificacion.stockBajo: return const Color(0xFFD97706);
|
||||
case TipoNotificacion.metaVentas: return const Color(0xFF7C3AED);
|
||||
case TipoNotificacion.recordatorio: return const Color(0xFF0891B2);
|
||||
case TipoNotificacion.alerta: return const Color(0xFFDC2626);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Notificacion {
|
||||
final String id;
|
||||
final TipoNotificacion tipo;
|
||||
final String titulo;
|
||||
final String cuerpo;
|
||||
final DateTime fecha;
|
||||
bool leida;
|
||||
final String? accionId;
|
||||
|
||||
Notificacion({
|
||||
required this.id,
|
||||
required this.tipo,
|
||||
required this.titulo,
|
||||
required this.cuerpo,
|
||||
required this.fecha,
|
||||
this.leida = false,
|
||||
this.accionId,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import 'cliente.dart';
|
||||
|
||||
enum EstadoParada { pendiente, visitado, saltado }
|
||||
|
||||
extension EstadoParadaExt on EstadoParada {
|
||||
String get value {
|
||||
switch (this) {
|
||||
case EstadoParada.visitado: return 'visitado';
|
||||
case EstadoParada.saltado: return 'saltado';
|
||||
default: return 'pendiente';
|
||||
}
|
||||
}
|
||||
|
||||
static EstadoParada fromString(String s) {
|
||||
switch (s) {
|
||||
case 'visitado': return EstadoParada.visitado;
|
||||
case 'saltado': return EstadoParada.saltado;
|
||||
default: return EstadoParada.pendiente;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ParadaRuta {
|
||||
final String id;
|
||||
final Cliente cliente;
|
||||
final int orden;
|
||||
EstadoParada estado;
|
||||
final String horaEstimada;
|
||||
String? horaVisita;
|
||||
String? notasVisita;
|
||||
|
||||
ParadaRuta({
|
||||
required this.id,
|
||||
required this.cliente,
|
||||
required this.orden,
|
||||
required this.estado,
|
||||
required this.horaEstimada,
|
||||
this.horaVisita,
|
||||
this.notasVisita,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toMap(String rutaId) => {
|
||||
'id': id,
|
||||
'ruta_id': rutaId,
|
||||
'cliente_id': cliente.id,
|
||||
'orden': orden,
|
||||
'estado': estado.value,
|
||||
'hora_estimada': horaEstimada,
|
||||
'hora_visita': horaVisita,
|
||||
'notas_visita': notasVisita,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import 'cliente.dart';
|
||||
import 'item_pedido.dart';
|
||||
|
||||
enum EstadoPedido { pendiente, confirmado, entregado, cancelado }
|
||||
|
||||
extension EstadoPedidoExt on EstadoPedido {
|
||||
String get label {
|
||||
switch (this) {
|
||||
case EstadoPedido.pendiente: return 'Pendiente';
|
||||
case EstadoPedido.confirmado: return 'Confirmado';
|
||||
case EstadoPedido.entregado: return 'Entregado';
|
||||
case EstadoPedido.cancelado: return 'Cancelado';
|
||||
}
|
||||
}
|
||||
|
||||
static EstadoPedido fromString(String s) {
|
||||
switch (s) {
|
||||
case 'confirmado': return EstadoPedido.confirmado;
|
||||
case 'entregado': return EstadoPedido.entregado;
|
||||
case 'cancelado': return EstadoPedido.cancelado;
|
||||
default: return EstadoPedido.pendiente;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Pedido {
|
||||
final String id;
|
||||
final Cliente cliente;
|
||||
final List<ItemPedido> items;
|
||||
EstadoPedido estado;
|
||||
final DateTime fecha;
|
||||
String notas;
|
||||
String? firmaBase64;
|
||||
|
||||
Pedido({
|
||||
required this.id,
|
||||
required this.cliente,
|
||||
required this.items,
|
||||
required this.estado,
|
||||
required this.fecha,
|
||||
this.notas = '',
|
||||
this.firmaBase64,
|
||||
});
|
||||
|
||||
double get subtotal => items.fold(0, (s, i) => s + i.subtotal);
|
||||
double get total => subtotal;
|
||||
int get totalItems => items.fold(0, (s, i) => s + i.cantidad);
|
||||
|
||||
Map<String, dynamic> toMap() => {
|
||||
'id': id,
|
||||
'cliente_id': cliente.id,
|
||||
'estado': estado.label.toLowerCase(),
|
||||
'fecha': fecha.toIso8601String(),
|
||||
'notas': notas,
|
||||
'firma_base64': firmaBase64,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
class Producto {
|
||||
final String id;
|
||||
final String nombre;
|
||||
final String descripcion;
|
||||
final String categoria;
|
||||
final double precio;
|
||||
final double precioMayorista;
|
||||
final String unidad;
|
||||
final int stock;
|
||||
final String sku;
|
||||
final String emoji;
|
||||
|
||||
const Producto({
|
||||
required this.id,
|
||||
required this.nombre,
|
||||
required this.descripcion,
|
||||
required this.categoria,
|
||||
required this.precio,
|
||||
required this.precioMayorista,
|
||||
required this.unidad,
|
||||
required this.stock,
|
||||
required this.sku,
|
||||
required this.emoji,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toMap() => {
|
||||
'id': id,
|
||||
'sku': sku,
|
||||
'nombre': nombre,
|
||||
'descripcion': descripcion,
|
||||
'categoria': categoria,
|
||||
'precio': precio,
|
||||
'precio_mayorista': precioMayorista,
|
||||
'unidad': unidad,
|
||||
'stock': stock,
|
||||
'emoji': emoji,
|
||||
};
|
||||
|
||||
factory Producto.fromMap(Map<String, dynamic> m) => Producto(
|
||||
id: m['id'] as String,
|
||||
sku: m['sku'] as String? ?? '',
|
||||
nombre: m['nombre'] as String,
|
||||
descripcion: m['descripcion'] as String? ?? '',
|
||||
categoria: m['categoria'] as String? ?? '',
|
||||
precio: (m['precio'] as num).toDouble(),
|
||||
precioMayorista: (m['precio_mayorista'] as num).toDouble(),
|
||||
unidad: m['unidad'] as String? ?? 'unidad',
|
||||
stock: m['stock'] as int? ?? 0,
|
||||
emoji: m['emoji'] as String? ?? '📦',
|
||||
);
|
||||
|
||||
Producto copyWith({int? stock, double? precio, double? precioMayorista}) => Producto(
|
||||
id: id, sku: sku, nombre: nombre, descripcion: descripcion,
|
||||
categoria: categoria, unidad: unidad, emoji: emoji,
|
||||
precio: precio ?? this.precio,
|
||||
precioMayorista: precioMayorista ?? this.precioMayorista,
|
||||
stock: stock ?? this.stock,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'parada_ruta.dart';
|
||||
|
||||
class Ruta {
|
||||
final String id;
|
||||
final String nombre;
|
||||
final String zona;
|
||||
final List<ParadaRuta> paradas;
|
||||
final DateTime fecha;
|
||||
|
||||
Ruta({
|
||||
required this.id,
|
||||
required this.nombre,
|
||||
required this.zona,
|
||||
required this.paradas,
|
||||
required this.fecha,
|
||||
});
|
||||
|
||||
int get visitadas => paradas.where((p) => p.estado == EstadoParada.visitado).length;
|
||||
int get pendientes => paradas.where((p) => p.estado == EstadoParada.pendiente).length;
|
||||
|
||||
Map<String, dynamic> toMap() => {
|
||||
'id': id,
|
||||
'nombre': nombre,
|
||||
'zona': zona,
|
||||
'fecha': fecha.toIso8601String(),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
class Vendedor {
|
||||
final String id;
|
||||
final String nombre;
|
||||
final String email;
|
||||
final String telefono;
|
||||
final String zona;
|
||||
final String avatarInitials;
|
||||
|
||||
const Vendedor({
|
||||
required this.id,
|
||||
required this.nombre,
|
||||
required this.email,
|
||||
required this.telefono,
|
||||
required this.zona,
|
||||
required this.avatarInitials,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toMap() => {
|
||||
'id': id,
|
||||
'nombre': nombre,
|
||||
'email': email,
|
||||
'telefono': telefono,
|
||||
'zona': zona,
|
||||
'avatar_initials': avatarInitials,
|
||||
};
|
||||
|
||||
factory Vendedor.fromMap(Map<String, dynamic> m) => Vendedor(
|
||||
id: m['id'] as String,
|
||||
nombre: m['nombre'] as String,
|
||||
email: m['email'] as String,
|
||||
telefono: m['telefono'] as String? ?? '',
|
||||
zona: m['zona'] as String? ?? '',
|
||||
avatarInitials: m['avatar_initials'] as String? ?? '',
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user