123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- // import 'package:computo_lite/main.dart';
- // import 'package:computo_lite/viewmodels/viewmodels.dart';
- // import 'package:computo_lite/viewmodels/package_view_model.dart';
- // import 'package:computo_lite/viewmodels/schedule_view_model.dart';
- // import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';
- // import 'package:diacritic/diacritic.dart';
- // import 'package:flutter/cupertino.dart';
- // import 'package:flutter/material.dart';
- // import 'package:flutter_typeahead/flutter_typeahead.dart';
- // import 'package:intl/intl.dart';
- // import 'package:provider/provider.dart';
- // class PackageStore extends StatefulWidget {
- // final String _entradaSalida;
- // final Map<String, dynamic> _package;
- // final bool _scanner;
- // PackageStore(this._entradaSalida, this._package, this._scanner) : super();
- // @override
- // _PackageStoreState createState() => _PackageStoreState();
- // }
- // const List<int> idsAgendasDisabledStore = [1, 2, 7, 8, 12];
- // const List<String> idsTipoAgenda2 = ["3", "4", "5", "6", "9", "10", "11", "13"];
- // const List<String> months = ["Mayo", "Junio"];
- // const Map<String, String> montsNumber = {"Mayo": "05", "Junio": "06"};
- // class _PackageStoreState extends State<PackageStore> {
- // final _controllerAgenda = TextEditingController();
- // final List<int> _days = List<int>.generate(31, (i) => i + 1);
- // final DateFormat _format = DateFormat("HH:mm");
- // final DateTime _now = DateTime.now();
- // final OutlineInputBorder _border = OutlineInputBorder(
- // borderSide: BorderSide(color: Color(0xFFBDBDBD)),
- // );
- // final DateFormat format = DateFormat("dd-MM-yyyy- HH:mm");
- // final OutlineInputBorder border = OutlineInputBorder(
- // borderSide: BorderSide(color: Color(0xFFBDBDBD)),
- // );
- // final ScheduleViewModel _scheduleViewModel = ScheduleViewModel();
- // final PackageViewModel _packageViewModel = PackageViewModel();
- // final FirebaseFirestore db = FirebaseFirestore.instance;
- // bool _loading = true;
- // bool _saving = false;
- // List<Map<String, dynamic>> _schedules = [];
- // List<Map<String, dynamic>> _motives = [];
- // late Map<String, dynamic> _scheduleReceiveSelected;
- // late Map<String, dynamic> _scheduleSendSelected;
- // late Map<String, dynamic> _motiveSelected;
- // DateTime _timeSelected = DateTime.now();
- // late String _monthSelected;
- // late int _daySelected;
- // @override
- // void initState() {
- // super.initState();
- // Future(() async {
- // try {
- // final Map<String, dynamic> user =
- // Provider.of<LoginViewModel>(context, listen: false).userData;
- // final List<Map<String, dynamic>> schedules = await _scheduleViewModel
- // .getSchedules(idsAgendasDisabledStore, idsTipoAgenda2, 0);
- // final List<Map<String, dynamic>> motives =
- // await _packageViewModel.getMotives();
- // final DocumentSnapshot docIdAgendaEntrega = await db
- // .collection('agendas')
- // .doc(user["idAgenda"].toString())
- // .get();
- // //final Object? idsAgendas = docIdAgendaEntrega.data();
- // final Map<String, dynamic> idsAgendas =
- // docIdAgendaEntrega.data() is Map<String, dynamic>
- // ? docIdAgendaEntrega.data() as Map<String, dynamic>
- // : <String, dynamic>{};
- // schedules
- // .sort((a, b) => a["nombreCompleto"].compareTo(b["nombreCompleto"]));
- // if (mounted) {
- // setState(() {
- // _monthSelected = _now.month == 5 ? "Mayo" : "Junio";
- // _daySelected = _now.day;
- // _motives = motives
- // .where((Map<String, dynamic> motive) =>
- // motive["tipo"] == widget._entradaSalida)
- // .toList();
- // _schedules = schedules;
- // /* if(idsAgendas != null && idsAgendas["idAgendaEntrega"] != null) {
- // _scheduleSendSelected = schedules.firstWhere((Map<String, dynamic> s) => s["idAgenda"] == int.parse(idsAgendas["idAgendaEntrega"]));
- // } */
- // if (idsAgendas != null && idsAgendas["idAgendaRecibe"] != null) {
- // _scheduleReceiveSelected = schedules.firstWhere(
- // (Map<String, dynamic> s) =>
- // s["idAgenda"] == int.parse(idsAgendas["idAgendaRecibe"]));
- // }
- // });
- // }
- // } catch (e) {
- // print(e);
- // } finally {
- // if (mounted) setState(() => _loading = false);
- // }
- // });
- // }
- // Future<void> _toStockOrTakeOut() async {
- // if (_saving || _loading) return;
- // try {
- // if (_monthSelected == null) {
- // await _dialogError("Favor de seleccionar el Mes.");
- // return;
- // }
- // if (_daySelected == null) {
- // await _dialogError("Favor de seleccionar el Día.");
- // return;
- // }
- // if (_timeSelected == null) {
- // await _dialogError("Favor de seleccionar la Hora.");
- // return;
- // }
- // if (_scheduleSendSelected == null) {
- // await _dialogError("Favor de seleccionar el Funcionario Entrega.");
- // return;
- // }
- // if (_scheduleReceiveSelected == null) {
- // await _dialogError("Favor de seleccionar el Funcionario Recibe.");
- // return;
- // }
- // if (_motiveSelected == null) {
- // await _dialogError("Favor de seleccionar el Motivo.");
- // return;
- // }
- // if (mounted) setState(() => _saving = true);
- // final Map<String, dynamic> user =
- // Provider.of<LoginViewModel>(context, listen: false).userData;
- // Map<String, dynamic> data = {
- // "idActa": widget._package["idActa"],
- // "month": montsNumber[_monthSelected],
- // "day": _daySelected,
- // "time": _timeSelected,
- // "idMotivoPaquete": _motiveSelected["idMotivoPaquete"],
- // "idAgendaEntrega": _scheduleSendSelected["idAgenda"],
- // "idAgendaRecibe": _scheduleReceiveSelected["idAgenda"],
- // };
- // bool response = await _packageViewModel.toStockOrTakeOut(data);
- // if (response) {
- // await db.collection('agendas').doc(user["idAgenda"].toString()).set({
- // 'idAgendaEntrega': _scheduleSendSelected["idAgenda"].toString(),
- // 'idAgendaRecibe': _scheduleReceiveSelected["idAgenda"].toString(),
- // });
- // Navigator.pushAndRemoveUntil(
- // context,
- // MaterialPageRoute(
- // builder: (context) =>
- // MainPage(pageSelected: widget._scanner ? 1 : 2)),
- // (e) => false);
- // } else {
- // await _dialogError("Error.");
- // }
- // } catch (e) {
- // print(e);
- // } finally {
- // if (mounted) setState(() => _saving = false);
- // }
- // }
- // Future<void> _dialogError(String message) async {
- // await HelpersViewModel.dialog(
- // 1,
- // Row(
- // children: [
- // Icon(Icons.error),
- // SizedBox(width: 5),
- // Text("Error"),
- // ],
- // ),
- // message,
- // context,
- // "Aceptar",
- // "",
- // () {},
- // () {});
- // }
- // @override
- // Widget build(BuildContext context) {
- // return Scaffold(
- // floatingActionButton: _saving
- // ? CircularProgressIndicator()
- // : SizedBox(
- // width: double.infinity,
- // child: Padding(
- // padding: const EdgeInsets.only(left: 30.0),
- // child: TextButton(
- // onPressed: _toStockOrTakeOut,
- // style: ButtonStyle(
- // backgroundColor: MaterialStateProperty.all<Color>(
- // Color(0xffdb6500))),
- // child: Text(
- // widget._entradaSalida == "E" ? "Almacenar" : "Sacar",
- // style: TextStyle(color: Colors.white),
- // )),
- // ),
- // ),
- // appBar: AppBar(
- // elevation: 0,
- // centerTitle: true,
- // title: Image.asset("lib/assets/logo_iee.png", height: 50),
- // ),
- // body: _loading
- // ? Center(child: CircularProgressIndicator())
- // : Padding(
- // padding: const EdgeInsets.all(20.0),
- // child: SingleChildScrollView(
- // child: Wrap(
- // runSpacing: 20,
- // children: [
- // Center(
- // child: Text(widget._package["nombreCompletoActa"],
- // style: TextStyle(
- // fontSize: 18,
- // color: Color(0xffdb6500),
- // fontWeight: FontWeight.bold))),
- // Row(
- // mainAxisAlignment: MainAxisAlignment.spaceBetween,
- // children: [
- // Expanded(
- // child: DropdownButtonFormField<String>(
- // value: _monthSelected,
- // isExpanded: true,
- // decoration: InputDecoration(
- // labelText: "Mes",
- // focusedBorder: _border,
- // enabledBorder: _border,
- // ),
- // items: months
- // .map<DropdownMenuItem<String>>((String value) {
- // return DropdownMenuItem<String>(
- // value: value,
- // child: Text(value),
- // );
- // }).toList(),
- // onChanged: (String? newValue) {
- // setState(() => _monthSelected = newValue!);
- // },
- // ),
- // ),
- // Expanded(
- // child: DropdownButtonFormField<int>(
- // value: _daySelected,
- // isExpanded: true,
- // decoration: InputDecoration(
- // labelText: "Día",
- // focusedBorder: _border,
- // enabledBorder: _border,
- // ),
- // items: _days.where((element) {
- // if (_monthSelected == "Junio" && element == 31) {
- // return false;
- // } else {
- // return true;
- // }
- // }).map<DropdownMenuItem<int>>((int value) {
- // return DropdownMenuItem<int>(
- // value: value,
- // child: Text(value.toString()),
- // );
- // }).toList(),
- // onChanged: _monthSelected == null
- // ? null
- // : (int? newValue) =>
- // setState(() => _daySelected = newValue!),
- // ),
- // ),
- // ],
- // ),
- // DateTimeField(
- // initialValue: _timeSelected,
- // decoration: InputDecoration(
- // labelText: "Hora",
- // focusedBorder: _border,
- // enabledBorder: _border,
- // ),
- // format: _format,
- // onChanged: (DateTime? newValue) =>
- // setState(() => _timeSelected = newValue!),
- // onShowPicker: (context, currentValue) async {
- // final time = await showTimePicker(
- // context: context,
- // initialTime: TimeOfDay.fromDateTime(
- // currentValue ?? DateTime.now()),
- // );
- // return DateTimeField.convert(time);
- // },
- // ),
- // TypeAheadFormField(
- // textFieldConfiguration: TextFieldConfiguration(
- // autofocus: false,
- // decoration: InputDecoration(
- // border: OutlineInputBorder(),
- // labelText: "Entrega",
- // ),
- // controller: _controllerAgenda),
- // noItemsFoundBuilder: (context) {
- // return Padding(
- // padding: const EdgeInsets.all(8.0),
- // child: Text(
- // 'No encontrado.',
- // textAlign: TextAlign.center,
- // style: TextStyle(
- // color: Theme.of(context).disabledColor,
- // fontSize: 18.0),
- // ),
- // );
- // },
- // suggestionsCallback: (String query) {
- // return _schedules
- // .where((Map<String, dynamic> s) =>
- // _scheduleReceiveSelected == null ||
- // s["idAgenda"] !=
- // _scheduleReceiveSelected["idAgenda"])
- // .where((Map<String, dynamic> agenda) =>
- // agenda["nombreCompleto"] != null &&
- // removeDiacritics(
- // agenda["nombreCompleto"].toString())
- // .toUpperCase()
- // .contains(query.toUpperCase()))
- // .toList();
- // },
- // itemBuilder: (context, Map<String, dynamic> agenda) {
- // return Padding(
- // padding: const EdgeInsets.all(8.0),
- // child: Text(
- // agenda['nombreCompleto'],
- // style: TextStyle(fontSize: 16),
- // ),
- // );
- // },
- // onSuggestionSelected: (Map<String, dynamic> newValue) {
- // _controllerAgenda.text = newValue["nombreCompleto"];
- // setState(() => _scheduleSendSelected = newValue);
- // },
- // ),
- // DropdownButtonFormField<Map<String, dynamic>>(
- // isDense: false,
- // itemHeight: 60,
- // isExpanded: true,
- // value: _scheduleReceiveSelected,
- // decoration: InputDecoration(
- // labelText: "Recibe",
- // focusedBorder: border,
- // enabledBorder: border,
- // ),
- // items: _schedules
- // .where((Map<String, dynamic> s) =>
- // _scheduleSendSelected == null ||
- // _scheduleSendSelected != null &&
- // s["idAgenda"] !=
- // _scheduleSendSelected["idAgenda"])
- // .map<DropdownMenuItem<Map<String, dynamic>>>(
- // (Map<String, dynamic> value) {
- // return DropdownMenuItem<Map<String, dynamic>>(
- // value: value,
- // child: Text(value["nombreCompleto"],
- // overflow: TextOverflow.clip),
- // );
- // }).toList(),
- // onChanged: (Map<String, dynamic>? newValue) =>
- // setState(() => _scheduleReceiveSelected = newValue!),
- // ),
- // DropdownButtonFormField<Map<String, dynamic>>(
- // isExpanded: true,
- // decoration: InputDecoration(
- // labelText: "Motivo",
- // focusedBorder: border,
- // enabledBorder: border,
- // ),
- // items: _motives
- // .map<DropdownMenuItem<Map<String, dynamic>>>(
- // (Map<String, dynamic> value) {
- // return DropdownMenuItem<Map<String, dynamic>>(
- // value: value,
- // child: Text(value["descripcion"],
- // overflow: TextOverflow.ellipsis),
- // );
- // }).toList(),
- // onChanged: (Map<String, dynamic>? newValue) {
- // setState(() => _motiveSelected = newValue!);
- // },
- // ),
- // ],
- // ),
- // ),
- // ),
- // );
- // }
- // }
|