|
@@ -48,6 +48,8 @@ class _PedidoFormState extends State<PedidoForm> {
|
|
TextEditingController tarjetaController = TextEditingController();
|
|
TextEditingController tarjetaController = TextEditingController();
|
|
TextEditingController transferenciaController = TextEditingController();
|
|
TextEditingController transferenciaController = TextEditingController();
|
|
double cambio = 0.0;
|
|
double cambio = 0.0;
|
|
|
|
+ double faltante = 0.0;
|
|
|
|
+ bool totalCompletado = false;
|
|
|
|
|
|
double calcularTotalPedido() {
|
|
double calcularTotalPedido() {
|
|
double total = 0;
|
|
double total = 0;
|
|
@@ -164,8 +166,11 @@ class _PedidoFormState extends State<PedidoForm> {
|
|
Future<void> _promptForCustomerName() async {
|
|
Future<void> _promptForCustomerName() async {
|
|
TextEditingController nombreController = TextEditingController();
|
|
TextEditingController nombreController = TextEditingController();
|
|
TextEditingController comentarioController = TextEditingController();
|
|
TextEditingController comentarioController = TextEditingController();
|
|
- String errorMessage = '';
|
|
|
|
- double faltante = totalPedido;
|
|
|
|
|
|
+ TextEditingController efectivoController = TextEditingController();
|
|
|
|
+ TextEditingController tarjetaController = TextEditingController();
|
|
|
|
+ TextEditingController transferenciaController = TextEditingController();
|
|
|
|
+
|
|
|
|
+ faltante = totalPedido;
|
|
bool totalCompletado = false;
|
|
bool totalCompletado = false;
|
|
bool efectivoCompleto = false;
|
|
bool efectivoCompleto = false;
|
|
bool tarjetaCompleto = false;
|
|
bool tarjetaCompleto = false;
|
|
@@ -178,586 +183,369 @@ class _PedidoFormState extends State<PedidoForm> {
|
|
|
|
|
|
setState(() {
|
|
setState(() {
|
|
cambio = totalPagado - totalPedido;
|
|
cambio = totalPagado - totalPedido;
|
|
- if (cambio < 0) {
|
|
|
|
- faltante = totalPedido - totalPagado;
|
|
|
|
- cambio = 0;
|
|
|
|
- totalCompletado = false;
|
|
|
|
- } else {
|
|
|
|
- faltante = 0;
|
|
|
|
- totalCompletado = true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Si el total ha sido alcanzado o excedido, desactivar otros métodos de pago
|
|
|
|
- if (totalPagado >= totalPedido) {
|
|
|
|
- if (!efectivoSeleccionado) efectivoSeleccionado = false;
|
|
|
|
- if (!tarjetaSeleccionada) tarjetaSeleccionada = false;
|
|
|
|
- if (!transferenciaSeleccionada) transferenciaSeleccionada = false;
|
|
|
|
- }
|
|
|
|
|
|
+ faltante = cambio < 0 ? totalPedido - totalPagado : 0;
|
|
|
|
+ totalCompletado = cambio >= 0;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- void _validarCantidad(
|
|
|
|
- StateSetter setState, TextEditingController controller) {
|
|
|
|
- double cantidad = double.tryParse(controller.text) ?? 0;
|
|
|
|
- if (cantidad > totalPedido) {
|
|
|
|
- setState(() {
|
|
|
|
- controller.text = totalPedido.toStringAsFixed(2);
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- _calcularCambio(setState);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- bool _isPaymentOptionEnabled(bool isSelected) {
|
|
|
|
- return !totalCompletado || isSelected;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
bool? shouldSave = await showDialog<bool>(
|
|
bool? shouldSave = await showDialog<bool>(
|
|
context: context,
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
builder: (BuildContext context) {
|
|
return StatefulBuilder(
|
|
return StatefulBuilder(
|
|
builder: (context, setState) {
|
|
builder: (context, setState) {
|
|
- return RawKeyboardListener(
|
|
|
|
- focusNode: FocusNode(),
|
|
|
|
- onKey: (RawKeyEvent event) {
|
|
|
|
- if (event.isKeyPressed(LogicalKeyboardKey.enter) &&
|
|
|
|
- totalCompletado) {
|
|
|
|
- Navigator.of(context).pop(true);
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- child: AlertDialog(
|
|
|
|
- actionsPadding: EdgeInsets.fromLTRB(50, 10, 50, 30),
|
|
|
|
- title: const Text(
|
|
|
|
- 'Finalizar Pedido',
|
|
|
|
- style: TextStyle(fontSize: 22, fontWeight: FontWeight.w500),
|
|
|
|
- ),
|
|
|
|
- content: Container(
|
|
|
|
- height: 600,
|
|
|
|
- child: Column(
|
|
|
|
- children: [
|
|
|
|
- Expanded(
|
|
|
|
- child: SingleChildScrollView(
|
|
|
|
- child: Column(
|
|
|
|
- children: [
|
|
|
|
- AppTextField(
|
|
|
|
- controller: nombreController,
|
|
|
|
- etiqueta: 'Nombre',
|
|
|
|
- hintText: "Nombre del Cliente",
|
|
|
|
- ),
|
|
|
|
- const SizedBox(height: 10),
|
|
|
|
- AppTextField(
|
|
|
|
- controller: comentarioController,
|
|
|
|
- etiqueta: 'Comentarios (opcional)',
|
|
|
|
- hintText: 'Comentarios',
|
|
|
|
- maxLines: 2,
|
|
|
|
- ),
|
|
|
|
- const SizedBox(height: 10),
|
|
|
|
- Align(
|
|
|
|
- alignment: Alignment.center,
|
|
|
|
- child: Text(
|
|
|
|
- 'Métodos de pago',
|
|
|
|
- style: TextStyle(
|
|
|
|
- fontWeight: FontWeight.bold,
|
|
|
|
- fontSize: 20),
|
|
|
|
- ),
|
|
|
|
- ),
|
|
|
|
- const SizedBox(height: 10),
|
|
|
|
- // Efectivo
|
|
|
|
- GestureDetector(
|
|
|
|
- onTap: () {
|
|
|
|
- if (_isPaymentOptionEnabled(
|
|
|
|
- efectivoSeleccionado)) {
|
|
|
|
- setState(() {
|
|
|
|
- efectivoSeleccionado =
|
|
|
|
- !efectivoSeleccionado;
|
|
|
|
- if (!efectivoSeleccionado) {
|
|
|
|
- efectivoCompleto = false;
|
|
|
|
- efectivoController.clear();
|
|
|
|
- _calcularCambio(setState);
|
|
|
|
- } else if (efectivoCompleto) {
|
|
|
|
- efectivoController.text =
|
|
|
|
- totalPedido.toStringAsFixed(2);
|
|
|
|
- _calcularCambio(setState);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- child: Row(
|
|
|
|
- mainAxisAlignment:
|
|
|
|
- MainAxisAlignment.spaceBetween,
|
|
|
|
- crossAxisAlignment:
|
|
|
|
- CrossAxisAlignment.center,
|
|
|
|
- children: [
|
|
|
|
- Row(
|
|
|
|
- children: [
|
|
|
|
- Checkbox(
|
|
|
|
- activeColor: AppTheme.primary,
|
|
|
|
- value: efectivoSeleccionado,
|
|
|
|
- onChanged: _isPaymentOptionEnabled(
|
|
|
|
- efectivoSeleccionado)
|
|
|
|
- ? (bool? value) {
|
|
|
|
- setState(() {
|
|
|
|
- efectivoSeleccionado =
|
|
|
|
- value ?? false;
|
|
|
|
- if (!efectivoSeleccionado) {
|
|
|
|
- efectivoCompleto =
|
|
|
|
- false;
|
|
|
|
- efectivoController
|
|
|
|
- .clear();
|
|
|
|
- _calcularCambio(
|
|
|
|
- setState);
|
|
|
|
- } else if (efectivoCompleto) {
|
|
|
|
- efectivoController
|
|
|
|
- .text =
|
|
|
|
- totalPedido
|
|
|
|
- .toStringAsFixed(
|
|
|
|
- 2);
|
|
|
|
- _calcularCambio(
|
|
|
|
- setState);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- : null,
|
|
|
|
- ),
|
|
|
|
- const Text(
|
|
|
|
- "Efectivo",
|
|
|
|
- style: TextStyle(
|
|
|
|
- fontSize: 18,
|
|
|
|
- fontWeight: FontWeight.bold),
|
|
|
|
- ),
|
|
|
|
- ],
|
|
|
|
- ),
|
|
|
|
- if (efectivoSeleccionado)
|
|
|
|
- SizedBox(
|
|
|
|
- width: 180,
|
|
|
|
- child: Row(
|
|
|
|
- crossAxisAlignment:
|
|
|
|
- CrossAxisAlignment.start,
|
|
|
|
- children: [
|
|
|
|
- Column(
|
|
|
|
- children: [
|
|
|
|
- const Text('Exacto',
|
|
|
|
- style: TextStyle(
|
|
|
|
- fontSize: 18,
|
|
|
|
- fontWeight:
|
|
|
|
- FontWeight.bold,
|
|
|
|
- color: Colors.black)),
|
|
|
|
- const SizedBox(
|
|
|
|
- height: 17,
|
|
|
|
- ),
|
|
|
|
- Checkbox(
|
|
|
|
- activeColor:
|
|
|
|
- AppTheme.primary,
|
|
|
|
- value: efectivoCompleto,
|
|
|
|
- onChanged:
|
|
|
|
- efectivoSeleccionado
|
|
|
|
- ? (bool? value) {
|
|
|
|
- setState(() {
|
|
|
|
- efectivoCompleto =
|
|
|
|
- value ??
|
|
|
|
- false;
|
|
|
|
- if (efectivoCompleto) {
|
|
|
|
- efectivoController
|
|
|
|
- .text =
|
|
|
|
- totalPedido
|
|
|
|
- .toStringAsFixed(2);
|
|
|
|
- _calcularCambio(
|
|
|
|
- setState);
|
|
|
|
- } else {
|
|
|
|
- efectivoController
|
|
|
|
- .clear();
|
|
|
|
- _calcularCambio(
|
|
|
|
- setState);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- : null,
|
|
|
|
- ),
|
|
|
|
- ],
|
|
|
|
- ),
|
|
|
|
- const SizedBox(
|
|
|
|
- width: 5,
|
|
|
|
- ),
|
|
|
|
- Expanded(
|
|
|
|
- child: AppTextField(
|
|
|
|
- controller:
|
|
|
|
- efectivoController,
|
|
|
|
- etiqueta: 'Cantidad',
|
|
|
|
- hintText: '0.00',
|
|
|
|
- keyboardType:
|
|
|
|
- TextInputType.number,
|
|
|
|
- onChanged: (value) =>
|
|
|
|
- _calcularCambio(setState),
|
|
|
|
- ),
|
|
|
|
- ),
|
|
|
|
- ],
|
|
|
|
- ),
|
|
|
|
- ),
|
|
|
|
- ],
|
|
|
|
- ),
|
|
|
|
- ),
|
|
|
|
- const SizedBox(height: 10),
|
|
|
|
- // Tarjeta
|
|
|
|
- GestureDetector(
|
|
|
|
- onTap: () {
|
|
|
|
- if (_isPaymentOptionEnabled(
|
|
|
|
- tarjetaSeleccionada)) {
|
|
|
|
- setState(() {
|
|
|
|
- tarjetaSeleccionada =
|
|
|
|
- !tarjetaSeleccionada;
|
|
|
|
- if (!tarjetaSeleccionada) {
|
|
|
|
- tarjetaController.clear();
|
|
|
|
- _calcularCambio(setState);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- child: Row(
|
|
|
|
- mainAxisAlignment:
|
|
|
|
- MainAxisAlignment.spaceBetween,
|
|
|
|
- crossAxisAlignment:
|
|
|
|
- CrossAxisAlignment.center,
|
|
|
|
- children: [
|
|
|
|
- Row(
|
|
|
|
- children: [
|
|
|
|
- Checkbox(
|
|
|
|
- activeColor: AppTheme.primary,
|
|
|
|
- value: tarjetaSeleccionada,
|
|
|
|
- onChanged: _isPaymentOptionEnabled(
|
|
|
|
- tarjetaSeleccionada)
|
|
|
|
- ? (bool? value) {
|
|
|
|
- setState(() {
|
|
|
|
- tarjetaSeleccionada =
|
|
|
|
- value ?? false;
|
|
|
|
- if (!tarjetaSeleccionada) {
|
|
|
|
- tarjetaController
|
|
|
|
- .clear();
|
|
|
|
- _calcularCambio(
|
|
|
|
- setState);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- : null,
|
|
|
|
- ),
|
|
|
|
- const Text(
|
|
|
|
- "Tarjeta",
|
|
|
|
- style: TextStyle(
|
|
|
|
- fontSize: 18,
|
|
|
|
- fontWeight: FontWeight.bold),
|
|
|
|
- ),
|
|
|
|
- ],
|
|
|
|
- ),
|
|
|
|
- if (tarjetaSeleccionada)
|
|
|
|
- SizedBox(
|
|
|
|
- width: 180,
|
|
|
|
- child: Row(
|
|
|
|
- crossAxisAlignment:
|
|
|
|
- CrossAxisAlignment.start,
|
|
|
|
- children: [
|
|
|
|
- Column(
|
|
|
|
- children: [
|
|
|
|
- const Text('Exacto',
|
|
|
|
- style: TextStyle(
|
|
|
|
- fontSize: 18,
|
|
|
|
- fontWeight:
|
|
|
|
- FontWeight.bold,
|
|
|
|
- color: Colors.black)),
|
|
|
|
- const SizedBox(
|
|
|
|
- height: 17,
|
|
|
|
- ),
|
|
|
|
- Checkbox(
|
|
|
|
- activeColor:
|
|
|
|
- AppTheme.primary,
|
|
|
|
- value: tarjetaCompleto,
|
|
|
|
- onChanged:
|
|
|
|
- tarjetaSeleccionada
|
|
|
|
- ? (bool? value) {
|
|
|
|
- setState(() {
|
|
|
|
- tarjetaCompleto =
|
|
|
|
- value ??
|
|
|
|
- false;
|
|
|
|
- if (tarjetaCompleto) {
|
|
|
|
- tarjetaController
|
|
|
|
- .text =
|
|
|
|
- totalPedido
|
|
|
|
- .toStringAsFixed(2);
|
|
|
|
- _calcularCambio(
|
|
|
|
- setState);
|
|
|
|
- } else {
|
|
|
|
- tarjetaController
|
|
|
|
- .clear();
|
|
|
|
- _calcularCambio(
|
|
|
|
- setState);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- : null,
|
|
|
|
- ),
|
|
|
|
- ],
|
|
|
|
- ),
|
|
|
|
- const SizedBox(
|
|
|
|
- width: 5,
|
|
|
|
- ),
|
|
|
|
- Expanded(
|
|
|
|
- child: AppTextField(
|
|
|
|
- controller: tarjetaController,
|
|
|
|
- etiqueta: 'Cantidad',
|
|
|
|
- hintText: '0.00',
|
|
|
|
- keyboardType:
|
|
|
|
- TextInputType.number,
|
|
|
|
- onChanged: (value) {
|
|
|
|
- _validarCantidad(setState,
|
|
|
|
- tarjetaController);
|
|
|
|
- },
|
|
|
|
- ),
|
|
|
|
- ),
|
|
|
|
- ],
|
|
|
|
- ),
|
|
|
|
- ),
|
|
|
|
- ],
|
|
|
|
- ),
|
|
|
|
- ),
|
|
|
|
- const SizedBox(height: 10),
|
|
|
|
- // Transferencia
|
|
|
|
- GestureDetector(
|
|
|
|
- onTap: () {
|
|
|
|
- if (_isPaymentOptionEnabled(
|
|
|
|
- transferenciaSeleccionada)) {
|
|
|
|
- setState(() {
|
|
|
|
- transferenciaSeleccionada =
|
|
|
|
- !transferenciaSeleccionada;
|
|
|
|
- if (!transferenciaSeleccionada) {
|
|
|
|
- transferenciaController.clear();
|
|
|
|
- _calcularCambio(setState);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- child: Row(
|
|
|
|
- mainAxisAlignment:
|
|
|
|
- MainAxisAlignment.spaceBetween,
|
|
|
|
- crossAxisAlignment:
|
|
|
|
- CrossAxisAlignment.center,
|
|
|
|
- children: [
|
|
|
|
- Row(
|
|
|
|
- children: [
|
|
|
|
- Checkbox(
|
|
|
|
- activeColor: AppTheme.primary,
|
|
|
|
- value: transferenciaSeleccionada,
|
|
|
|
- onChanged: _isPaymentOptionEnabled(
|
|
|
|
- transferenciaSeleccionada)
|
|
|
|
- ? (bool? value) {
|
|
|
|
- setState(() {
|
|
|
|
- transferenciaSeleccionada =
|
|
|
|
- value ?? false;
|
|
|
|
- if (!transferenciaSeleccionada) {
|
|
|
|
- transferenciaController
|
|
|
|
- .clear();
|
|
|
|
- _calcularCambio(
|
|
|
|
- setState);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- : null,
|
|
|
|
- ),
|
|
|
|
- const Text(
|
|
|
|
- "Transferencia",
|
|
|
|
- style: TextStyle(
|
|
|
|
- fontSize: 18,
|
|
|
|
- fontWeight: FontWeight.bold),
|
|
|
|
- ),
|
|
|
|
- ],
|
|
|
|
- ),
|
|
|
|
- if (transferenciaSeleccionada)
|
|
|
|
- SizedBox(
|
|
|
|
- width: 180,
|
|
|
|
- child: Row(
|
|
|
|
- crossAxisAlignment:
|
|
|
|
- CrossAxisAlignment.start,
|
|
|
|
- children: [
|
|
|
|
- Column(
|
|
|
|
- children: [
|
|
|
|
- const Text('Exacto',
|
|
|
|
- style: TextStyle(
|
|
|
|
- fontSize: 18,
|
|
|
|
- fontWeight:
|
|
|
|
- FontWeight.bold,
|
|
|
|
- color: Colors.black)),
|
|
|
|
- const SizedBox(
|
|
|
|
- height: 17,
|
|
|
|
- ),
|
|
|
|
- Checkbox(
|
|
|
|
- activeColor:
|
|
|
|
- AppTheme.primary,
|
|
|
|
- value:
|
|
|
|
- transferenciaCompleto,
|
|
|
|
- onChanged:
|
|
|
|
- transferenciaSeleccionada
|
|
|
|
- ? (bool? value) {
|
|
|
|
- setState(() {
|
|
|
|
- transferenciaCompleto =
|
|
|
|
- value ??
|
|
|
|
- false;
|
|
|
|
- if (transferenciaCompleto) {
|
|
|
|
- transferenciaController
|
|
|
|
- .text =
|
|
|
|
- totalPedido
|
|
|
|
- .toStringAsFixed(2);
|
|
|
|
- _calcularCambio(
|
|
|
|
- setState);
|
|
|
|
- } else {
|
|
|
|
- transferenciaController
|
|
|
|
- .clear();
|
|
|
|
- _calcularCambio(
|
|
|
|
- setState);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- : null,
|
|
|
|
- ),
|
|
|
|
- ],
|
|
|
|
- ),
|
|
|
|
- const SizedBox(
|
|
|
|
- width: 5,
|
|
|
|
- ),
|
|
|
|
- Expanded(
|
|
|
|
- child: AppTextField(
|
|
|
|
- controller:
|
|
|
|
- transferenciaController,
|
|
|
|
- etiqueta: 'Cantidad',
|
|
|
|
- hintText: '0.00',
|
|
|
|
- keyboardType:
|
|
|
|
- TextInputType.number,
|
|
|
|
- onChanged: (value) {
|
|
|
|
- _validarCantidad(setState,
|
|
|
|
- transferenciaController);
|
|
|
|
- },
|
|
|
|
- ),
|
|
|
|
- ),
|
|
|
|
- ],
|
|
|
|
- ),
|
|
|
|
- ),
|
|
|
|
- ],
|
|
|
|
- ),
|
|
|
|
- ),
|
|
|
|
- const SizedBox(height: 10),
|
|
|
|
- // Mostrar el total del pedido y la cantidad faltante
|
|
|
|
- Align(
|
|
|
|
- alignment: Alignment.centerRight,
|
|
|
|
- child: Column(
|
|
|
|
- crossAxisAlignment:
|
|
|
|
- CrossAxisAlignment.end,
|
|
|
|
- children: [
|
|
|
|
- Text(
|
|
|
|
- 'Total del pedido: \$${totalPedido.toStringAsFixed(2)}',
|
|
|
|
- style: const TextStyle(
|
|
|
|
- fontWeight: FontWeight.bold,
|
|
|
|
- fontSize: 18),
|
|
|
|
- ),
|
|
|
|
- if (faltante > 0)
|
|
|
|
- Text(
|
|
|
|
- 'Faltante: \$${faltante.toStringAsFixed(2)}',
|
|
|
|
- style: const TextStyle(
|
|
|
|
- color: Colors.red,
|
|
|
|
- fontSize: 18,
|
|
|
|
- fontWeight: FontWeight.bold),
|
|
|
|
- )
|
|
|
|
- else if (cambio > 0)
|
|
|
|
- Text(
|
|
|
|
- 'Cambio: \$${cambio.toStringAsFixed(2)}',
|
|
|
|
- style: const TextStyle(
|
|
|
|
- color: Colors.green,
|
|
|
|
- fontSize: 18,
|
|
|
|
- fontWeight: FontWeight.bold)),
|
|
|
|
- ]),
|
|
|
|
- ),
|
|
|
|
- ],
|
|
|
|
- ),
|
|
|
|
- ),
|
|
|
|
- ),
|
|
|
|
- // Aquí mantenemos los botones fijos
|
|
|
|
- Row(
|
|
|
|
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
|
+ return AlertDialog(
|
|
|
|
+ actionsPadding: EdgeInsets.fromLTRB(50, 10, 50, 30),
|
|
|
|
+ title: const Text(
|
|
|
|
+ 'Finalizar Pedido',
|
|
|
|
+ style: TextStyle(fontSize: 22, fontWeight: FontWeight.w500),
|
|
|
|
+ ),
|
|
|
|
+ content: Container(
|
|
|
|
+ height: 600,
|
|
|
|
+ child: Column(
|
|
|
|
+ children: [
|
|
|
|
+ Expanded(
|
|
|
|
+ child: SingleChildScrollView(
|
|
|
|
+ child: Column(
|
|
children: [
|
|
children: [
|
|
- TextButton(
|
|
|
|
- child: const Text('Cancelar',
|
|
|
|
- style: TextStyle(fontSize: 18)),
|
|
|
|
- onPressed: () {
|
|
|
|
- Navigator.of(context).pop(false);
|
|
|
|
|
|
+ AppTextField(
|
|
|
|
+ controller: nombreController,
|
|
|
|
+ etiqueta: 'Nombre',
|
|
|
|
+ hintText: "Nombre del Cliente",
|
|
|
|
+ ),
|
|
|
|
+ const SizedBox(height: 10),
|
|
|
|
+ AppTextField(
|
|
|
|
+ controller: comentarioController,
|
|
|
|
+ etiqueta: 'Comentarios (opcional)',
|
|
|
|
+ hintText: 'Comentarios',
|
|
|
|
+ maxLines: 2,
|
|
|
|
+ ),
|
|
|
|
+ const SizedBox(height: 10),
|
|
|
|
+ Align(
|
|
|
|
+ alignment: Alignment.center,
|
|
|
|
+ child: Text(
|
|
|
|
+ 'Métodos de pago',
|
|
|
|
+ style: TextStyle(
|
|
|
|
+ fontWeight: FontWeight.bold, fontSize: 20),
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ const SizedBox(height: 10),
|
|
|
|
+ // Efectivo
|
|
|
|
+ _buildPaymentMethodRow(
|
|
|
|
+ setState,
|
|
|
|
+ label: 'Efectivo',
|
|
|
|
+ selected: efectivoSeleccionado,
|
|
|
|
+ exactSelected: efectivoCompleto,
|
|
|
|
+ controller: efectivoController,
|
|
|
|
+ onSelected: (value) {
|
|
|
|
+ setState(() {
|
|
|
|
+ efectivoSeleccionado = value;
|
|
|
|
+ if (!efectivoSeleccionado) {
|
|
|
|
+ efectivoCompleto = false;
|
|
|
|
+ efectivoController.clear();
|
|
|
|
+ }
|
|
|
|
+ _calcularCambio(setState);
|
|
|
|
+ });
|
|
},
|
|
},
|
|
- style: ButtonStyle(
|
|
|
|
- padding: MaterialStatePropertyAll(
|
|
|
|
- EdgeInsets.fromLTRB(30, 20, 30, 20)),
|
|
|
|
- backgroundColor:
|
|
|
|
- MaterialStatePropertyAll(Colors.red),
|
|
|
|
- foregroundColor: MaterialStatePropertyAll(
|
|
|
|
- AppTheme.secondary)),
|
|
|
|
|
|
+ onExactSelected: (value) {
|
|
|
|
+ setState(() {
|
|
|
|
+ efectivoCompleto = value;
|
|
|
|
+ if (efectivoCompleto) {
|
|
|
|
+ efectivoController.text =
|
|
|
|
+ totalPedido.toStringAsFixed(2);
|
|
|
|
+ efectivoSeleccionado = true;
|
|
|
|
+ tarjetaSeleccionada = false;
|
|
|
|
+ transferenciaSeleccionada = false;
|
|
|
|
+ tarjetaController.clear();
|
|
|
|
+ transferenciaController.clear();
|
|
|
|
+ } else {
|
|
|
|
+ efectivoController.clear();
|
|
|
|
+ }
|
|
|
|
+ _calcularCambio(setState);
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ disableOtherMethods:
|
|
|
|
+ tarjetaCompleto || transferenciaCompleto,
|
|
|
|
+ onChangedMonto: () => _calcularCambio(setState),
|
|
),
|
|
),
|
|
- const SizedBox(width: 100),
|
|
|
|
- TextButton(
|
|
|
|
- child: const Text('Guardar',
|
|
|
|
- style: TextStyle(fontSize: 18)),
|
|
|
|
- onPressed: totalCompletado
|
|
|
|
- ? () {
|
|
|
|
- Navigator.of(context).pop(true);
|
|
|
|
- }
|
|
|
|
- : null,
|
|
|
|
- style: ButtonStyle(
|
|
|
|
- padding: MaterialStatePropertyAll(
|
|
|
|
- EdgeInsets.fromLTRB(30, 20, 30, 20)),
|
|
|
|
- backgroundColor: MaterialStatePropertyAll(
|
|
|
|
- totalCompletado
|
|
|
|
- ? AppTheme.tertiary
|
|
|
|
- : Colors.grey),
|
|
|
|
- foregroundColor: MaterialStatePropertyAll(
|
|
|
|
- AppTheme.quaternary)),
|
|
|
|
|
|
+ // Tarjeta
|
|
|
|
+ _buildPaymentMethodRow(
|
|
|
|
+ setState,
|
|
|
|
+ label: 'Tarjeta',
|
|
|
|
+ selected: tarjetaSeleccionada,
|
|
|
|
+ exactSelected: tarjetaCompleto,
|
|
|
|
+ controller: tarjetaController,
|
|
|
|
+ onSelected: (value) {
|
|
|
|
+ setState(() {
|
|
|
|
+ tarjetaSeleccionada = value;
|
|
|
|
+ if (!tarjetaSeleccionada) {
|
|
|
|
+ tarjetaCompleto = false;
|
|
|
|
+ tarjetaController.clear();
|
|
|
|
+ }
|
|
|
|
+ _calcularCambio(setState);
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ onExactSelected: (value) {
|
|
|
|
+ setState(() {
|
|
|
|
+ tarjetaCompleto = value;
|
|
|
|
+ if (tarjetaCompleto) {
|
|
|
|
+ tarjetaController.text =
|
|
|
|
+ totalPedido.toStringAsFixed(2);
|
|
|
|
+ tarjetaSeleccionada = true;
|
|
|
|
+ efectivoSeleccionado = false;
|
|
|
|
+ transferenciaSeleccionada = false;
|
|
|
|
+ efectivoController.clear();
|
|
|
|
+ transferenciaController.clear();
|
|
|
|
+ } else {
|
|
|
|
+ tarjetaController.clear();
|
|
|
|
+ }
|
|
|
|
+ _calcularCambio(setState);
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ disableOtherMethods:
|
|
|
|
+ efectivoCompleto || transferenciaCompleto,
|
|
|
|
+ onChangedMonto: () => _calcularCambio(setState),
|
|
|
|
+ ),
|
|
|
|
+ // Transferencia
|
|
|
|
+ _buildPaymentMethodRow(
|
|
|
|
+ setState,
|
|
|
|
+ label: 'Transferencia',
|
|
|
|
+ selected: transferenciaSeleccionada,
|
|
|
|
+ exactSelected: transferenciaCompleto,
|
|
|
|
+ controller: transferenciaController,
|
|
|
|
+ onSelected: (value) {
|
|
|
|
+ setState(() {
|
|
|
|
+ transferenciaSeleccionada = value;
|
|
|
|
+ if (!transferenciaSeleccionada) {
|
|
|
|
+ transferenciaCompleto = false;
|
|
|
|
+ transferenciaController.clear();
|
|
|
|
+ }
|
|
|
|
+ _calcularCambio(setState);
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ onExactSelected: (value) {
|
|
|
|
+ setState(() {
|
|
|
|
+ transferenciaCompleto = value;
|
|
|
|
+ if (transferenciaCompleto) {
|
|
|
|
+ transferenciaController.text =
|
|
|
|
+ totalPedido.toStringAsFixed(2);
|
|
|
|
+ transferenciaSeleccionada = true;
|
|
|
|
+ efectivoSeleccionado = false;
|
|
|
|
+ tarjetaSeleccionada = false;
|
|
|
|
+ efectivoController.clear();
|
|
|
|
+ tarjetaController.clear();
|
|
|
|
+ } else {
|
|
|
|
+ transferenciaController.clear();
|
|
|
|
+ }
|
|
|
|
+ _calcularCambio(setState);
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ disableOtherMethods:
|
|
|
|
+ efectivoCompleto || tarjetaCompleto,
|
|
|
|
+ onChangedMonto: () => _calcularCambio(setState),
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
- ],
|
|
|
|
|
|
+ ),
|
|
),
|
|
),
|
|
|
|
+ // Total y Faltante
|
|
|
|
+ Align(
|
|
|
|
+ alignment: Alignment.centerRight,
|
|
|
|
+ child: Column(
|
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
+ children: [
|
|
|
|
+ Text(
|
|
|
|
+ 'Total del pedido: \$${totalPedido.toStringAsFixed(2)}',
|
|
|
|
+ style: const TextStyle(
|
|
|
|
+ fontWeight: FontWeight.bold, fontSize: 18),
|
|
|
|
+ ),
|
|
|
|
+ if (faltante > 0)
|
|
|
|
+ Text(
|
|
|
|
+ 'Faltante: \$${faltante.toStringAsFixed(2)}',
|
|
|
|
+ style: const TextStyle(
|
|
|
|
+ color: Colors.red,
|
|
|
|
+ fontSize: 18,
|
|
|
|
+ fontWeight: FontWeight.bold),
|
|
|
|
+ )
|
|
|
|
+ else if (cambio > 0)
|
|
|
|
+ Text(
|
|
|
|
+ 'Cambio: \$${cambio.toStringAsFixed(2)}',
|
|
|
|
+ style: const TextStyle(
|
|
|
|
+ color: Colors.green,
|
|
|
|
+ fontSize: 18,
|
|
|
|
+ fontWeight: FontWeight.bold),
|
|
|
|
+ ),
|
|
|
|
+ ],
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ ],
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ actions: [
|
|
|
|
+ TextButton(
|
|
|
|
+ child: const Text('Cancelar', style: TextStyle(fontSize: 18)),
|
|
|
|
+ onPressed: () => Navigator.of(context).pop(false),
|
|
|
|
+ style: ButtonStyle(
|
|
|
|
+ padding: MaterialStateProperty.all(
|
|
|
|
+ EdgeInsets.fromLTRB(30, 20, 30, 20)),
|
|
|
|
+ backgroundColor: MaterialStateProperty.all(Colors.red),
|
|
|
|
+ foregroundColor:
|
|
|
|
+ MaterialStateProperty.all(AppTheme.secondary),
|
|
),
|
|
),
|
|
- ));
|
|
|
|
|
|
+ ),
|
|
|
|
+ const SizedBox(width: 100),
|
|
|
|
+ TextButton(
|
|
|
|
+ child: const Text('Guardar', style: TextStyle(fontSize: 18)),
|
|
|
|
+ onPressed: totalCompletado
|
|
|
|
+ ? () => Navigator.of(context).pop(true)
|
|
|
|
+ : null,
|
|
|
|
+ style: ButtonStyle(
|
|
|
|
+ padding: MaterialStateProperty.all(
|
|
|
|
+ EdgeInsets.fromLTRB(30, 20, 30, 20)),
|
|
|
|
+ backgroundColor: MaterialStateProperty.all(
|
|
|
|
+ totalCompletado ? AppTheme.tertiary : Colors.grey),
|
|
|
|
+ foregroundColor:
|
|
|
|
+ MaterialStateProperty.all(AppTheme.quaternary),
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ ],
|
|
|
|
+ );
|
|
},
|
|
},
|
|
);
|
|
);
|
|
},
|
|
},
|
|
);
|
|
);
|
|
|
|
|
|
if (shouldSave ?? false) {
|
|
if (shouldSave ?? false) {
|
|
- prepararPedidoActual(nombreController.text, comentarioController.text);
|
|
|
|
|
|
+ prepararPedidoActual(
|
|
|
|
+ nombreController.text,
|
|
|
|
+ comentarioController.text,
|
|
|
|
+ efectivoController,
|
|
|
|
+ tarjetaController,
|
|
|
|
+ transferenciaController,
|
|
|
|
+ );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- void prepararPedidoActual(String nombreCliente, String comentarios) async {
|
|
|
|
|
|
+ Widget _buildPaymentMethodRow(
|
|
|
|
+ StateSetter setState, {
|
|
|
|
+ required String label,
|
|
|
|
+ required bool selected,
|
|
|
|
+ required bool exactSelected,
|
|
|
|
+ required TextEditingController controller,
|
|
|
|
+ required Function(bool) onSelected,
|
|
|
|
+ required Function(bool) onExactSelected,
|
|
|
|
+ required bool disableOtherMethods,
|
|
|
|
+ required Function() onChangedMonto,
|
|
|
|
+ }) {
|
|
|
|
+ return Row(
|
|
|
|
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
+ children: [
|
|
|
|
+ Row(
|
|
|
|
+ children: [
|
|
|
|
+ Checkbox(
|
|
|
|
+ activeColor: AppTheme.primary,
|
|
|
|
+ value: selected,
|
|
|
|
+ onChanged: disableOtherMethods
|
|
|
|
+ ? null
|
|
|
|
+ : (value) {
|
|
|
|
+ onSelected(value ?? false);
|
|
|
|
+ },
|
|
|
|
+ ),
|
|
|
|
+ Text(
|
|
|
|
+ label,
|
|
|
|
+ style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
|
|
|
+ ),
|
|
|
|
+ ],
|
|
|
|
+ ),
|
|
|
|
+ SizedBox(
|
|
|
|
+ width: 180,
|
|
|
|
+ child: Row(
|
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
+ children: [
|
|
|
|
+ Column(
|
|
|
|
+ children: [
|
|
|
|
+ const Text(
|
|
|
|
+ 'Exacto',
|
|
|
|
+ style: TextStyle(
|
|
|
|
+ fontSize: 18,
|
|
|
|
+ fontWeight: FontWeight.bold,
|
|
|
|
+ color: Colors.black),
|
|
|
|
+ ),
|
|
|
|
+ const SizedBox(height: 17),
|
|
|
|
+ Checkbox(
|
|
|
|
+ activeColor: AppTheme.primary,
|
|
|
|
+ value: exactSelected,
|
|
|
|
+ onChanged: !disableOtherMethods
|
|
|
|
+ ? (value) {
|
|
|
|
+ onExactSelected(value ?? false);
|
|
|
|
+ if (value == true) {
|
|
|
|
+ setState(() {
|
|
|
|
+ disableOtherMethods = true;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ : null,
|
|
|
|
+ ),
|
|
|
|
+ ],
|
|
|
|
+ ),
|
|
|
|
+ const SizedBox(width: 5),
|
|
|
|
+ Expanded(
|
|
|
|
+ child: AppTextField(
|
|
|
|
+ controller: controller,
|
|
|
|
+ enabled: selected,
|
|
|
|
+ etiqueta: 'Cantidad',
|
|
|
|
+ hintText: '0.00',
|
|
|
|
+ keyboardType: TextInputType.number,
|
|
|
|
+ onChanged: (_) {
|
|
|
|
+ onChangedMonto();
|
|
|
|
+ },
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ ],
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ ],
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void prepararPedidoActual(
|
|
|
|
+ String nombreCliente,
|
|
|
|
+ String comentarios,
|
|
|
|
+ TextEditingController efectivoController,
|
|
|
|
+ TextEditingController tarjetaController,
|
|
|
|
+ TextEditingController transferenciaController,
|
|
|
|
+ ) async {
|
|
String now = DateTime.now().toUtc().toIso8601String();
|
|
String now = DateTime.now().toUtc().toIso8601String();
|
|
|
|
|
|
|
|
+ double cantEfectivo = efectivoSeleccionado
|
|
|
|
+ ? double.tryParse(efectivoController.text) ?? 0
|
|
|
|
+ : 0;
|
|
|
|
+ double cantTarjeta =
|
|
|
|
+ tarjetaSeleccionada ? double.tryParse(tarjetaController.text) ?? 0 : 0;
|
|
|
|
+ double cantTransferencia = transferenciaSeleccionada
|
|
|
|
+ ? double.tryParse(transferenciaController.text) ?? 0
|
|
|
|
+ : 0;
|
|
|
|
+
|
|
Pedido nuevoPedido = Pedido(
|
|
Pedido nuevoPedido = Pedido(
|
|
peticion: now,
|
|
peticion: now,
|
|
nombreCliente: nombreCliente,
|
|
nombreCliente: nombreCliente,
|
|
comentarios: comentarios,
|
|
comentarios: comentarios,
|
|
- estatus: "NUEVO",
|
|
|
|
|
|
+ estatus: "TERMINADO",
|
|
totalPedido: totalPedido,
|
|
totalPedido: totalPedido,
|
|
descuento: pedidoActual?.descuento,
|
|
descuento: pedidoActual?.descuento,
|
|
tipoPago: _obtenerTipoPago(),
|
|
tipoPago: _obtenerTipoPago(),
|
|
- cantEfectivo:
|
|
|
|
- efectivoSeleccionado ? double.tryParse(efectivoController.text) : 0,
|
|
|
|
- cantTarjeta:
|
|
|
|
- tarjetaSeleccionada ? double.tryParse(tarjetaController.text) : 0,
|
|
|
|
- cantTransferencia: transferenciaSeleccionada
|
|
|
|
- ? double.tryParse(transferenciaController.text)
|
|
|
|
- : 0,
|
|
|
|
|
|
+ cantEfectivo: cantEfectivo,
|
|
|
|
+ cantTarjeta: cantTarjeta,
|
|
|
|
+ cantTransferencia: cantTransferencia,
|
|
);
|
|
);
|
|
|
|
|
|
List<PedidoProducto> listaPedidoProducto = carrito.map((item) {
|
|
List<PedidoProducto> listaPedidoProducto = carrito.map((item) {
|
|
List<PedidoProductoTopping> selectedToppings = [];
|
|
List<PedidoProductoTopping> selectedToppings = [];
|
|
-
|
|
|
|
item.selectedToppings.forEach((categoryId, selectedToppingIds) {
|
|
item.selectedToppings.forEach((categoryId, selectedToppingIds) {
|
|
for (int toppingId in selectedToppingIds) {
|
|
for (int toppingId in selectedToppingIds) {
|
|
- selectedToppings.add(PedidoProductoTopping(
|
|
|
|
- idTopping: toppingId,
|
|
|
|
- ));
|
|
|
|
|
|
+ selectedToppings.add(PedidoProductoTopping(idTopping: toppingId));
|
|
}
|
|
}
|
|
});
|
|
});
|
|
-
|
|
|
|
return PedidoProducto(
|
|
return PedidoProducto(
|
|
idProducto: item.producto.id,
|
|
idProducto: item.producto.id,
|
|
producto: item.producto,
|
|
producto: item.producto,
|
|
@@ -794,7 +582,7 @@ class _PedidoFormState extends State<PedidoForm> {
|
|
if (efectivoSeleccionado) tiposPago.add('Efectivo');
|
|
if (efectivoSeleccionado) tiposPago.add('Efectivo');
|
|
if (tarjetaSeleccionada) tiposPago.add('Tarjeta');
|
|
if (tarjetaSeleccionada) tiposPago.add('Tarjeta');
|
|
if (transferenciaSeleccionada) tiposPago.add('Transferencia');
|
|
if (transferenciaSeleccionada) tiposPago.add('Transferencia');
|
|
- return tiposPago.join(',');
|
|
|
|
|
|
+ return tiposPago.isNotEmpty ? tiposPago.join(',') : 'No Definido';
|
|
}
|
|
}
|
|
|
|
|
|
void _limpiarBusqueda() async {
|
|
void _limpiarBusqueda() async {
|