package_store.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. // import 'package:computo_lite/main.dart';
  2. // import 'package:computo_lite/viewmodels/viewmodels.dart';
  3. // import 'package:computo_lite/viewmodels/package_view_model.dart';
  4. // import 'package:computo_lite/viewmodels/schedule_view_model.dart';
  5. // import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';
  6. // import 'package:diacritic/diacritic.dart';
  7. // import 'package:flutter/cupertino.dart';
  8. // import 'package:flutter/material.dart';
  9. // import 'package:flutter_typeahead/flutter_typeahead.dart';
  10. // import 'package:intl/intl.dart';
  11. // import 'package:provider/provider.dart';
  12. // class PackageStore extends StatefulWidget {
  13. // final String _entradaSalida;
  14. // final Map<String, dynamic> _package;
  15. // final bool _scanner;
  16. // PackageStore(this._entradaSalida, this._package, this._scanner) : super();
  17. // @override
  18. // _PackageStoreState createState() => _PackageStoreState();
  19. // }
  20. // const List<int> idsAgendasDisabledStore = [1, 2, 7, 8, 12];
  21. // const List<String> idsTipoAgenda2 = ["3", "4", "5", "6", "9", "10", "11", "13"];
  22. // const List<String> months = ["Mayo", "Junio"];
  23. // const Map<String, String> montsNumber = {"Mayo": "05", "Junio": "06"};
  24. // class _PackageStoreState extends State<PackageStore> {
  25. // final _controllerAgenda = TextEditingController();
  26. // final List<int> _days = List<int>.generate(31, (i) => i + 1);
  27. // final DateFormat _format = DateFormat("HH:mm");
  28. // final DateTime _now = DateTime.now();
  29. // final OutlineInputBorder _border = OutlineInputBorder(
  30. // borderSide: BorderSide(color: Color(0xFFBDBDBD)),
  31. // );
  32. // final DateFormat format = DateFormat("dd-MM-yyyy- HH:mm");
  33. // final OutlineInputBorder border = OutlineInputBorder(
  34. // borderSide: BorderSide(color: Color(0xFFBDBDBD)),
  35. // );
  36. // final ScheduleViewModel _scheduleViewModel = ScheduleViewModel();
  37. // final PackageViewModel _packageViewModel = PackageViewModel();
  38. // final FirebaseFirestore db = FirebaseFirestore.instance;
  39. // bool _loading = true;
  40. // bool _saving = false;
  41. // List<Map<String, dynamic>> _schedules = [];
  42. // List<Map<String, dynamic>> _motives = [];
  43. // late Map<String, dynamic> _scheduleReceiveSelected;
  44. // late Map<String, dynamic> _scheduleSendSelected;
  45. // late Map<String, dynamic> _motiveSelected;
  46. // DateTime _timeSelected = DateTime.now();
  47. // late String _monthSelected;
  48. // late int _daySelected;
  49. // @override
  50. // void initState() {
  51. // super.initState();
  52. // Future(() async {
  53. // try {
  54. // final Map<String, dynamic> user =
  55. // Provider.of<LoginViewModel>(context, listen: false).userData;
  56. // final List<Map<String, dynamic>> schedules = await _scheduleViewModel
  57. // .getSchedules(idsAgendasDisabledStore, idsTipoAgenda2, 0);
  58. // final List<Map<String, dynamic>> motives =
  59. // await _packageViewModel.getMotives();
  60. // final DocumentSnapshot docIdAgendaEntrega = await db
  61. // .collection('agendas')
  62. // .doc(user["idAgenda"].toString())
  63. // .get();
  64. // //final Object? idsAgendas = docIdAgendaEntrega.data();
  65. // final Map<String, dynamic> idsAgendas =
  66. // docIdAgendaEntrega.data() is Map<String, dynamic>
  67. // ? docIdAgendaEntrega.data() as Map<String, dynamic>
  68. // : <String, dynamic>{};
  69. // schedules
  70. // .sort((a, b) => a["nombreCompleto"].compareTo(b["nombreCompleto"]));
  71. // if (mounted) {
  72. // setState(() {
  73. // _monthSelected = _now.month == 5 ? "Mayo" : "Junio";
  74. // _daySelected = _now.day;
  75. // _motives = motives
  76. // .where((Map<String, dynamic> motive) =>
  77. // motive["tipo"] == widget._entradaSalida)
  78. // .toList();
  79. // _schedules = schedules;
  80. // /* if(idsAgendas != null && idsAgendas["idAgendaEntrega"] != null) {
  81. // _scheduleSendSelected = schedules.firstWhere((Map<String, dynamic> s) => s["idAgenda"] == int.parse(idsAgendas["idAgendaEntrega"]));
  82. // } */
  83. // if (idsAgendas != null && idsAgendas["idAgendaRecibe"] != null) {
  84. // _scheduleReceiveSelected = schedules.firstWhere(
  85. // (Map<String, dynamic> s) =>
  86. // s["idAgenda"] == int.parse(idsAgendas["idAgendaRecibe"]));
  87. // }
  88. // });
  89. // }
  90. // } catch (e) {
  91. // print(e);
  92. // } finally {
  93. // if (mounted) setState(() => _loading = false);
  94. // }
  95. // });
  96. // }
  97. // Future<void> _toStockOrTakeOut() async {
  98. // if (_saving || _loading) return;
  99. // try {
  100. // if (_monthSelected == null) {
  101. // await _dialogError("Favor de seleccionar el Mes.");
  102. // return;
  103. // }
  104. // if (_daySelected == null) {
  105. // await _dialogError("Favor de seleccionar el Día.");
  106. // return;
  107. // }
  108. // if (_timeSelected == null) {
  109. // await _dialogError("Favor de seleccionar la Hora.");
  110. // return;
  111. // }
  112. // if (_scheduleSendSelected == null) {
  113. // await _dialogError("Favor de seleccionar el Funcionario Entrega.");
  114. // return;
  115. // }
  116. // if (_scheduleReceiveSelected == null) {
  117. // await _dialogError("Favor de seleccionar el Funcionario Recibe.");
  118. // return;
  119. // }
  120. // if (_motiveSelected == null) {
  121. // await _dialogError("Favor de seleccionar el Motivo.");
  122. // return;
  123. // }
  124. // if (mounted) setState(() => _saving = true);
  125. // final Map<String, dynamic> user =
  126. // Provider.of<LoginViewModel>(context, listen: false).userData;
  127. // Map<String, dynamic> data = {
  128. // "idActa": widget._package["idActa"],
  129. // "month": montsNumber[_monthSelected],
  130. // "day": _daySelected,
  131. // "time": _timeSelected,
  132. // "idMotivoPaquete": _motiveSelected["idMotivoPaquete"],
  133. // "idAgendaEntrega": _scheduleSendSelected["idAgenda"],
  134. // "idAgendaRecibe": _scheduleReceiveSelected["idAgenda"],
  135. // };
  136. // bool response = await _packageViewModel.toStockOrTakeOut(data);
  137. // if (response) {
  138. // await db.collection('agendas').doc(user["idAgenda"].toString()).set({
  139. // 'idAgendaEntrega': _scheduleSendSelected["idAgenda"].toString(),
  140. // 'idAgendaRecibe': _scheduleReceiveSelected["idAgenda"].toString(),
  141. // });
  142. // Navigator.pushAndRemoveUntil(
  143. // context,
  144. // MaterialPageRoute(
  145. // builder: (context) =>
  146. // MainPage(pageSelected: widget._scanner ? 1 : 2)),
  147. // (e) => false);
  148. // } else {
  149. // await _dialogError("Error.");
  150. // }
  151. // } catch (e) {
  152. // print(e);
  153. // } finally {
  154. // if (mounted) setState(() => _saving = false);
  155. // }
  156. // }
  157. // Future<void> _dialogError(String message) async {
  158. // await HelpersViewModel.dialog(
  159. // 1,
  160. // Row(
  161. // children: [
  162. // Icon(Icons.error),
  163. // SizedBox(width: 5),
  164. // Text("Error"),
  165. // ],
  166. // ),
  167. // message,
  168. // context,
  169. // "Aceptar",
  170. // "",
  171. // () {},
  172. // () {});
  173. // }
  174. // @override
  175. // Widget build(BuildContext context) {
  176. // return Scaffold(
  177. // floatingActionButton: _saving
  178. // ? CircularProgressIndicator()
  179. // : SizedBox(
  180. // width: double.infinity,
  181. // child: Padding(
  182. // padding: const EdgeInsets.only(left: 30.0),
  183. // child: TextButton(
  184. // onPressed: _toStockOrTakeOut,
  185. // style: ButtonStyle(
  186. // backgroundColor: MaterialStateProperty.all<Color>(
  187. // Color(0xffdb6500))),
  188. // child: Text(
  189. // widget._entradaSalida == "E" ? "Almacenar" : "Sacar",
  190. // style: TextStyle(color: Colors.white),
  191. // )),
  192. // ),
  193. // ),
  194. // appBar: AppBar(
  195. // elevation: 0,
  196. // centerTitle: true,
  197. // title: Image.asset("lib/assets/logo_iee.png", height: 50),
  198. // ),
  199. // body: _loading
  200. // ? Center(child: CircularProgressIndicator())
  201. // : Padding(
  202. // padding: const EdgeInsets.all(20.0),
  203. // child: SingleChildScrollView(
  204. // child: Wrap(
  205. // runSpacing: 20,
  206. // children: [
  207. // Center(
  208. // child: Text(widget._package["nombreCompletoActa"],
  209. // style: TextStyle(
  210. // fontSize: 18,
  211. // color: Color(0xffdb6500),
  212. // fontWeight: FontWeight.bold))),
  213. // Row(
  214. // mainAxisAlignment: MainAxisAlignment.spaceBetween,
  215. // children: [
  216. // Expanded(
  217. // child: DropdownButtonFormField<String>(
  218. // value: _monthSelected,
  219. // isExpanded: true,
  220. // decoration: InputDecoration(
  221. // labelText: "Mes",
  222. // focusedBorder: _border,
  223. // enabledBorder: _border,
  224. // ),
  225. // items: months
  226. // .map<DropdownMenuItem<String>>((String value) {
  227. // return DropdownMenuItem<String>(
  228. // value: value,
  229. // child: Text(value),
  230. // );
  231. // }).toList(),
  232. // onChanged: (String? newValue) {
  233. // setState(() => _monthSelected = newValue!);
  234. // },
  235. // ),
  236. // ),
  237. // Expanded(
  238. // child: DropdownButtonFormField<int>(
  239. // value: _daySelected,
  240. // isExpanded: true,
  241. // decoration: InputDecoration(
  242. // labelText: "Día",
  243. // focusedBorder: _border,
  244. // enabledBorder: _border,
  245. // ),
  246. // items: _days.where((element) {
  247. // if (_monthSelected == "Junio" && element == 31) {
  248. // return false;
  249. // } else {
  250. // return true;
  251. // }
  252. // }).map<DropdownMenuItem<int>>((int value) {
  253. // return DropdownMenuItem<int>(
  254. // value: value,
  255. // child: Text(value.toString()),
  256. // );
  257. // }).toList(),
  258. // onChanged: _monthSelected == null
  259. // ? null
  260. // : (int? newValue) =>
  261. // setState(() => _daySelected = newValue!),
  262. // ),
  263. // ),
  264. // ],
  265. // ),
  266. // DateTimeField(
  267. // initialValue: _timeSelected,
  268. // decoration: InputDecoration(
  269. // labelText: "Hora",
  270. // focusedBorder: _border,
  271. // enabledBorder: _border,
  272. // ),
  273. // format: _format,
  274. // onChanged: (DateTime? newValue) =>
  275. // setState(() => _timeSelected = newValue!),
  276. // onShowPicker: (context, currentValue) async {
  277. // final time = await showTimePicker(
  278. // context: context,
  279. // initialTime: TimeOfDay.fromDateTime(
  280. // currentValue ?? DateTime.now()),
  281. // );
  282. // return DateTimeField.convert(time);
  283. // },
  284. // ),
  285. // TypeAheadFormField(
  286. // textFieldConfiguration: TextFieldConfiguration(
  287. // autofocus: false,
  288. // decoration: InputDecoration(
  289. // border: OutlineInputBorder(),
  290. // labelText: "Entrega",
  291. // ),
  292. // controller: _controllerAgenda),
  293. // noItemsFoundBuilder: (context) {
  294. // return Padding(
  295. // padding: const EdgeInsets.all(8.0),
  296. // child: Text(
  297. // 'No encontrado.',
  298. // textAlign: TextAlign.center,
  299. // style: TextStyle(
  300. // color: Theme.of(context).disabledColor,
  301. // fontSize: 18.0),
  302. // ),
  303. // );
  304. // },
  305. // suggestionsCallback: (String query) {
  306. // return _schedules
  307. // .where((Map<String, dynamic> s) =>
  308. // _scheduleReceiveSelected == null ||
  309. // s["idAgenda"] !=
  310. // _scheduleReceiveSelected["idAgenda"])
  311. // .where((Map<String, dynamic> agenda) =>
  312. // agenda["nombreCompleto"] != null &&
  313. // removeDiacritics(
  314. // agenda["nombreCompleto"].toString())
  315. // .toUpperCase()
  316. // .contains(query.toUpperCase()))
  317. // .toList();
  318. // },
  319. // itemBuilder: (context, Map<String, dynamic> agenda) {
  320. // return Padding(
  321. // padding: const EdgeInsets.all(8.0),
  322. // child: Text(
  323. // agenda['nombreCompleto'],
  324. // style: TextStyle(fontSize: 16),
  325. // ),
  326. // );
  327. // },
  328. // onSuggestionSelected: (Map<String, dynamic> newValue) {
  329. // _controllerAgenda.text = newValue["nombreCompleto"];
  330. // setState(() => _scheduleSendSelected = newValue);
  331. // },
  332. // ),
  333. // DropdownButtonFormField<Map<String, dynamic>>(
  334. // isDense: false,
  335. // itemHeight: 60,
  336. // isExpanded: true,
  337. // value: _scheduleReceiveSelected,
  338. // decoration: InputDecoration(
  339. // labelText: "Recibe",
  340. // focusedBorder: border,
  341. // enabledBorder: border,
  342. // ),
  343. // items: _schedules
  344. // .where((Map<String, dynamic> s) =>
  345. // _scheduleSendSelected == null ||
  346. // _scheduleSendSelected != null &&
  347. // s["idAgenda"] !=
  348. // _scheduleSendSelected["idAgenda"])
  349. // .map<DropdownMenuItem<Map<String, dynamic>>>(
  350. // (Map<String, dynamic> value) {
  351. // return DropdownMenuItem<Map<String, dynamic>>(
  352. // value: value,
  353. // child: Text(value["nombreCompleto"],
  354. // overflow: TextOverflow.clip),
  355. // );
  356. // }).toList(),
  357. // onChanged: (Map<String, dynamic>? newValue) =>
  358. // setState(() => _scheduleReceiveSelected = newValue!),
  359. // ),
  360. // DropdownButtonFormField<Map<String, dynamic>>(
  361. // isExpanded: true,
  362. // decoration: InputDecoration(
  363. // labelText: "Motivo",
  364. // focusedBorder: border,
  365. // enabledBorder: border,
  366. // ),
  367. // items: _motives
  368. // .map<DropdownMenuItem<Map<String, dynamic>>>(
  369. // (Map<String, dynamic> value) {
  370. // return DropdownMenuItem<Map<String, dynamic>>(
  371. // value: value,
  372. // child: Text(value["descripcion"],
  373. // overflow: TextOverflow.ellipsis),
  374. // );
  375. // }).toList(),
  376. // onChanged: (Map<String, dynamic>? newValue) {
  377. // setState(() => _motiveSelected = newValue!);
  378. // },
  379. // ),
  380. // ],
  381. // ),
  382. // ),
  383. // ),
  384. // );
  385. // }
  386. // }