import 'package:aman_kassa_flutter/core/locator.dart'; import 'package:aman_kassa_flutter/core/models/money.dart'; import 'package:aman_kassa_flutter/core/models/response.dart'; import 'package:aman_kassa_flutter/core/models/dialog_models.dart'; import 'package:aman_kassa_flutter/core/route_names.dart'; import 'package:aman_kassa_flutter/core/services/ApiService.dart'; import 'package:aman_kassa_flutter/core/services/dialog_service.dart'; import 'package:aman_kassa_flutter/core/services/navigator_service.dart'; import 'package:aman_kassa_flutter/redux/actions/user_actions.dart'; import 'package:aman_kassa_flutter/redux/actions/setting_actions.dart'; import 'package:aman_kassa_flutter/redux/constants/setting_const.dart'; import 'package:aman_kassa_flutter/redux/state/setting_state.dart'; import 'package:aman_kassa_flutter/redux/store.dart'; import 'package:aman_kassa_flutter/shared/app_colors.dart'; import 'package:aman_kassa_flutter/shared/ui_helpers.dart'; import 'package:aman_kassa_flutter/views/check/image_show_container.dart'; import 'package:aman_kassa_flutter/widgets/fields/aman_icon_button.dart'; import 'package:aman_kassa_flutter/widgets/fields/aman_icon_button_horizontal.dart'; import 'package:aman_kassa_flutter/widgets/fields/busy_button.dart'; import 'package:flutter/material.dart'; import 'package:flutter_redux/flutter_redux.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; class AdditionalTab extends StatefulWidget { final int index; AdditionalTab(this.index); @override _AdditionalTabState createState() => _AdditionalTabState(); } class _AdditionalTabState extends State { ApiService _api = locator(); NavigatorService _navigator = locator(); DialogService _dialog = locator(); bool isMoneyCheckBusy; bool closeSmenaBusy; bool openSmenaBusy; bool depositBusy; bool withdrawalBusy; bool xReportBusy; @override void initState() { super.initState(); isMoneyCheckBusy = false; closeSmenaBusy = false; openSmenaBusy = false; depositBusy = false; withdrawalBusy = false; xReportBusy = false; } void _closeSmena() async { setState(() { closeSmenaBusy = true; }); await Redux.store.dispatch(closeSmena); setState(() { closeSmenaBusy = false; }); } void _openSmena() async { setState(() { openSmenaBusy = true; }); await Redux.store.dispatch(openSmena); setState(() { openSmenaBusy = false; }); } void _xReport() async { setState(() { xReportBusy = true; }); Response response = await _api.xReport(Redux.store.state.userState.user.token); if (response.operation) { _navigator.push(ImageShowRoute, arguments: ImageShowModel(response.body['check'], 'X Отчет')); } else { _dialog.showDialog(description: response.body['message']); } setState(() { xReportBusy = false; }); } void _deposit() async { setState(() { depositBusy = true; }); try { DialogResponse response = await _dialog.showConfirmationDialogInput( description: 'Укажите сумму', cancelTitle: 'Отмена', confirmationTitle: 'Взнос', ); if (response.confirmed) { Response result = await _api.deposit( Redux.store.state.userState.user.token, response.responseText); _dialog.showDialog(description: result.body['message']); if(result.operation) { await Redux.store.dispatch(checkMoney); } } } catch (e) { print(e); } finally { setState(() { depositBusy = false; }); } } void _withdrawal() async { setState(() { withdrawalBusy = true; }); try { DialogResponse response = await _dialog.showConfirmationDialogInput( description: 'Укажите сумму', cancelTitle: 'Отмена', confirmationTitle: 'Снятие', ); if (response.confirmed) { Response result = await _api.withdrawal( Redux.store.state.userState.user.token, response.responseText); _dialog.showDialog(description: result.body['message']); if(result.operation) { await Redux.store.dispatch(checkMoney); } } } catch (e) { print(e); } finally { setState(() { withdrawalBusy = false; }); } } void _checkMoney() async { setState(() { isMoneyCheckBusy = true; }); try { Response result = await Redux.store.dispatch(checkMoney); //await _api.money(.state.userState.user.token); setState(() { isMoneyCheckBusy = false; }); if(result != null) { if (result.operation) { _dialog.showDialog( description: 'Денег в кассе: ${result.body['money']}'); } else { _dialog.showDialog(description: '${result.body['message']}'); } } } catch (e) { print(e); setState(() { isMoneyCheckBusy = false; }); } } @override Widget build(BuildContext context) { return Container( padding: const EdgeInsets.symmetric(vertical: 15), child: ListView( children: [ Padding( padding: const EdgeInsets.symmetric(horizontal: 20.0), child: StoreConnector( converter: (store) => store.state.settingState, builder: (context, vm) { return Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Flexible( flex: 1, child: AmanIconButtonHorizontal( icon: MdiIcons.calculator, title: 'Калькулятор', selected: vm.mode == SettingModeCalc, onPressed: () => changeMode(false), )), Center( child: Switch( value: vm.mode == SettingModeKassa, onChanged: changeMode, inactiveThumbColor: primaryColor, activeColor: primaryColor, )), Flexible( flex: 1, child: AmanIconButtonHorizontal( icon: MdiIcons.cashRegister, title: 'Режим кассы', selected: vm.mode == SettingModeKassa, onPressed: () => changeMode(true))), ], ); }), ), Divider(), verticalSpaceMedium, Padding( padding: const EdgeInsets.symmetric(horizontal: 20.0), child: Center( child: Column( children: [ Text( 'Денег в кассе:', style: TextStyle(color: primaryColor, fontSize: 15), ), StoreConnector( converter: (store) => store.state.userState.money, builder: (_, vm) { return Text( vm.total !=null ? '${vm.total} тенге' : 'нет информации', style: TextStyle( color: vm.total !=null ? primaryColor : Colors.grey.withOpacity(0.5), fontSize: 25, fontWeight: FontWeight.bold), ); } ), ], )), ), verticalSpaceMedium, Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ AmanIconButton( title: 'Открыть смену', onPressed: _openSmena, mainColor: greenColor, busy: openSmenaBusy, icon: Icons.lock_open, ), AmanIconButton( title: 'Закрыть смену', onPressed: _closeSmena, mainColor: redColor, busy: closeSmenaBusy, icon: Icons.lock_outline, ), AmanIconButton( title: 'Денег в кассе', onPressed: _checkMoney, busy: isMoneyCheckBusy, icon: Icons.attach_money, mainColor: primaryColor, ), ], ), verticalSpaceTiny, Row( mainAxisAlignment: MainAxisAlignment.center, children: [ AmanIconButton( title: 'Х Отчет', onPressed: _xReport, busy: xReportBusy, mainColor: primaryColor, icon: Icons.description, ), ], ), verticalSpaceMedium, Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ BusyButton( title: 'Взнос наличных', onPressed: _deposit, busy: depositBusy, ), BusyButton( title: 'Снятие наличных', onPressed: _withdrawal, mainColor: redColor, busy: withdrawalBusy, ), ], ), ], ), ); } void changeMode(el) { Redux.store.dispatch(changeModeFromSetting(el)); } }