- url redirect

- auth message
- update catalog
4.4
Serik.Uvaissov 2020-07-02 15:21:36 +06:00
parent 31e9ac2260
commit 8d16949f40
8 changed files with 85 additions and 34 deletions

View File

@ -16,12 +16,17 @@ import 'package:http/http.dart' as http;
/// The service responsible for networking requests /// The service responsible for networking requests
class ApiService extends BaseService { class ApiService extends BaseService {
static const endpoint = 'https://kassa-test.aman.com.kz/ru/api/v2'; static const test_endpoint = 'https://kassa-test.aman.com.kz/ru/api/v2';
static const endpoint = 'https://kassa.aman.com.kz/ru/api/v2';
final NavigatorService _navigatorService = locator<NavigatorService>(); final NavigatorService _navigatorService = locator<NavigatorService>();
final DialogService _dialogService = locator<DialogService>(); final DialogService _dialogService = locator<DialogService>();
var client = new http.Client(); var client = new http.Client();
bool _test = false;
bool get test => this._test;
set test(bool value) => this._test = value;
Future<AuthBody> authenticate(String email, String password, { bool statusCheck = true}) async { Future<AuthBody> authenticate(String email, String password, { bool statusCheck = true}) async {
Map<String, String> requestBody = <String, String>{ Map<String, String> requestBody = <String, String>{
'email': email, 'email': email,
@ -43,7 +48,7 @@ class ApiService extends BaseService {
Future<Response<Message>> isActive(String token) async { Future<Response<Message>> isActive(String token) async {
Map<String, String> requestBody = <String, String>{'api_token': token}; Map<String, String> requestBody = <String, String>{'api_token': token};
var response = await requestFormData('/test_auth', requestBody); var response = await requestFormData('/test_auth', requestBody, statusCheck: false);
return Response.fromJson(json.decode(response), Message.fromJson); return Response.fromJson(json.decode(response), Message.fromJson);
} }
@ -129,8 +134,11 @@ class ApiService extends BaseService {
HttpHeaders.userAgentHeader: iosInfo.utsname.machine, HttpHeaders.userAgentHeader: iosInfo.utsname.machine,
}); });
} }
String url = '$endpoint$point';
var uri = Uri.parse('$endpoint$point'); if(this._test) {
url = '$test_endpoint$point';
}
var uri = Uri.parse(url);
var request = http.MultipartRequest('POST', uri) var request = http.MultipartRequest('POST', uri)
..headers.addAll(headers) ..headers.addAll(headers)
..fields.addAll(requestBody); ..fields.addAll(requestBody);

View File

@ -63,7 +63,6 @@ class DataService extends BaseService {
if ((paymentType ?? 'cash') == 'card') { if ((paymentType ?? 'cash') == 'card') {
checkData.card = summ; checkData.card = summ;
} }
print(checkData);
return checkData; return checkData;
} }
@ -88,7 +87,6 @@ class DataService extends BaseService {
if ((paymentType ?? 'cash') == 'card') { if ((paymentType ?? 'cash') == 'card') {
checkData.card = summ; checkData.card = summ;
} }
print(checkData);
return checkData; return checkData;
} }
@ -167,21 +165,18 @@ class DataService extends BaseService {
await _db.deleteAll(Service_tableName); await _db.deleteAll(Service_tableName);
log.i('All tables cleaned'); log.i('All tables cleaned');
for (var key in goods.body.keys) { for (var key in goods.body.keys) {
print(goods.body[key]);
Good row = Good.fromJson(goods.body[key]); Good row = Good.fromJson(goods.body[key]);
await _db.insert(Goog_tableName, row.toMap()); await _db.insert(Goog_tableName, row.toMap());
} }
log.i('Inserted ${goods.body.length} to table $Goog_tableName'); log.i('Inserted ${goods.body.length} to table $Goog_tableName');
for (var el in categories.body) { for (var el in categories.body) {
print(el);
Category row = Category.fromJson(el); Category row = Category.fromJson(el);
await _db.insert(Category_tableName, row.toMap()); await _db.insert(Category_tableName, row.toMap());
} }
log.i('Inserted ${categories.body.length} to table $Category_tableName'); log.i('Inserted ${categories.body.length} to table $Category_tableName');
for (var key in services.body.keys) { for (var key in services.body.keys) {
print(services.body[key]);
Service row = Service.fromJson(services.body[key]); Service row = Service.fromJson(services.body[key]);
await _db.insert(Service_tableName, row.toMap()); await _db.insert(Service_tableName, row.toMap());
} }

View File

@ -31,11 +31,18 @@ final DialogService _dialogService = locator<DialogService>();
Future<void> checkUserAction(Store<AppState> store) async { Future<void> checkUserAction(Store<AppState> store) async {
store.dispatch(SetUserStateAction(UserState(isLoading: true))); store.dispatch(SetUserStateAction(UserState(isLoading: true)));
try { try {
String token = store.state.userState.user?.token; User user = store.state.userState.user;
String token = user?.token;
bool isAuthenticated = false; bool isAuthenticated = false;
if (token != null) { if (token != null) {
if(user.email!=null && user.email.toLowerCase().trim().startsWith('test')){
_api.test = true;
} else {
_api.test = false;
}
Response<Message> session = await _api.isActive(token); Response<Message> session = await _api.isActive(token);
isAuthenticated = "OK" == session.body.message; isAuthenticated = "OK" == session.body.message;
} else { } else {
await Future.delayed(Duration(milliseconds: 2000)); await Future.delayed(Duration(milliseconds: 2000));
} }
@ -114,7 +121,7 @@ ThunkAction<AppState> authenticateToken(String token) {
))); )));
if (result.user == null && result.message != null) { if (result.user == null && result.message != null) {
_dialogService.showDialog( _dialogService.showDialog(
title: 'Warning', buttonTitle: 'Ok', description: result.message); title: 'Внимание', buttonTitle: 'Ok', description: 'Ошибка авторизации');
} }
if (result.user != null) { if (result.user != null) {
_navigation.replace(HomeViewRoute); _navigation.replace(HomeViewRoute);
@ -146,7 +153,7 @@ ThunkAction<AppState> authenticate(String email, String password) {
))); )));
if (result.user == null && result.message != null) { if (result.user == null && result.message != null) {
_dialogService.showDialog( _dialogService.showDialog(
title: 'Warning', buttonTitle: 'Ok', description: result.message); title: 'Внимание', buttonTitle: 'Ok', description: 'Ошибка авторизации');
} }
if (result.user != null) { if (result.user != null) {
_navigation.replace(HomeViewRoute); _navigation.replace(HomeViewRoute);

View File

@ -3,7 +3,7 @@ import 'package:aman_kassa_flutter/shared/app_colors.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
const List<Choice> choices = const <Choice>[ const List<Choice> choices = const <Choice>[
const Choice(title: 'Обновить номенклатуру', icon: Icons.update, command: 'update'), //const Choice(title: 'Обновить номенклатуру', icon: Icons.update, command: 'update'),
//const Choice(title: 'Помощь', icon: Icons.help, command: 'help'), //const Choice(title: 'Помощь', icon: Icons.help, command: 'help'),
//const Choice(title: 'О Программе', icon: Icons.info_outline, command: 'info'), //const Choice(title: 'О Программе', icon: Icons.info_outline, command: 'info'),
//const Choice(title: 'Язык', icon: Icons.language, command: 'language'), //const Choice(title: 'Язык', icon: Icons.language, command: 'language'),

View File

@ -4,6 +4,7 @@ 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/models/dialog_models.dart';
import 'package:aman_kassa_flutter/core/route_names.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/ApiService.dart';
import 'package:aman_kassa_flutter/core/services/DataService.dart';
import 'package:aman_kassa_flutter/core/services/dialog_service.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/core/services/navigator_service.dart';
import 'package:aman_kassa_flutter/redux/actions/user_actions.dart'; import 'package:aman_kassa_flutter/redux/actions/user_actions.dart';
@ -17,6 +18,7 @@ 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.dart';
import 'package:aman_kassa_flutter/widgets/fields/aman_icon_button_horizontal.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:aman_kassa_flutter/widgets/fields/busy_button.dart';
import 'package:aman_kassa_flutter/widgets/loader/Dialogs.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart'; import 'package:flutter_redux/flutter_redux.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
@ -34,6 +36,8 @@ class _AdditionalTabState extends State<AdditionalTab> {
ApiService _api = locator<ApiService>(); ApiService _api = locator<ApiService>();
NavigatorService _navigator = locator<NavigatorService>(); NavigatorService _navigator = locator<NavigatorService>();
DialogService _dialog = locator<DialogService>(); DialogService _dialog = locator<DialogService>();
DataService _dataService = locator<DataService>();
final GlobalKey<State> _keyLoader = new GlobalKey<State>();
bool isMoneyCheckBusy; bool isMoneyCheckBusy;
bool closeSmenaBusy; bool closeSmenaBusy;
@ -41,6 +45,7 @@ class _AdditionalTabState extends State<AdditionalTab> {
bool depositBusy; bool depositBusy;
bool withdrawalBusy; bool withdrawalBusy;
bool xReportBusy; bool xReportBusy;
bool updateCatalog;
@override @override
void initState() { void initState() {
@ -51,6 +56,7 @@ class _AdditionalTabState extends State<AdditionalTab> {
depositBusy = false; depositBusy = false;
withdrawalBusy = false; withdrawalBusy = false;
xReportBusy = false; xReportBusy = false;
updateCatalog = false;
} }
void _closeSmena() async { void _closeSmena() async {
@ -90,6 +96,20 @@ class _AdditionalTabState extends State<AdditionalTab> {
}); });
} }
void _updateCatalog() async {
setState(() {
updateCatalog = true;
});
Dialogs.showLoadingDialog(context, _keyLoader);
bool result = await _dataService.getDataFromServer(Redux.store.state.userState.user);
Navigator.of(_keyLoader.currentContext, rootNavigator: true).pop();
setState(() {
updateCatalog = false;
});
}
void _deposit() async { void _deposit() async {
setState(() { setState(() {
depositBusy = true; depositBusy = true;
@ -255,6 +275,7 @@ class _AdditionalTabState extends State<AdditionalTab> {
verticalSpaceMedium, verticalSpaceMedium,
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
AmanIconButton( AmanIconButton(
title: 'Открыть смену', title: 'Открыть смену',
@ -282,6 +303,7 @@ class _AdditionalTabState extends State<AdditionalTab> {
verticalSpaceTiny, verticalSpaceTiny,
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
AmanIconButton( AmanIconButton(
title: 'Х Отчет', title: 'Х Отчет',
@ -290,6 +312,13 @@ class _AdditionalTabState extends State<AdditionalTab> {
mainColor: primaryColor, mainColor: primaryColor,
icon: Icons.description, icon: Icons.description,
), ),
AmanIconButton(
title: 'Обновить номенклатуру',
onPressed: _updateCatalog,
busy: updateCatalog,
mainColor: greenColor,
icon: MdiIcons.databaseRefresh,
),
], ],
), ),
verticalSpaceMedium, verticalSpaceMedium,

View File

@ -74,7 +74,7 @@ class _ProductAddBottomSheetState extends State<ProductAddBottomSheet> {
labelText: 'Количество', labelText: 'Количество',
prefixText: ' ', prefixText: ' ',
), ),
keyboardType: TextInputType.number, keyboardType: const TextInputType.numberWithOptions(decimal: false,),
inputFormatters: <TextInputFormatter>[ inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter.digitsOnly WhitelistingTextInputFormatter.digitsOnly
], ],
@ -90,7 +90,7 @@ class _ProductAddBottomSheetState extends State<ProductAddBottomSheet> {
labelText: 'Стоимость', labelText: 'Стоимость',
prefixText: ' ', prefixText: ' ',
), ),
keyboardType: TextInputType.number, keyboardType: const TextInputType.numberWithOptions(decimal: true),
inputFormatters: <TextInputFormatter>[ inputFormatters: <TextInputFormatter>[
WhitelistingTextInputFormatter(RegExp("^[0-9.]*")), WhitelistingTextInputFormatter(RegExp("^[0-9.]*")),
], ],

View File

@ -1,6 +1,7 @@
import 'dart:ui'; import 'dart:ui';
import 'package:aman_kassa_flutter/core/locator.dart'; import 'package:aman_kassa_flutter/core/locator.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/dialog_service.dart';
import 'package:aman_kassa_flutter/redux/actions/user_actions.dart'; import 'package:aman_kassa_flutter/redux/actions/user_actions.dart';
import 'package:aman_kassa_flutter/redux/state/user_state.dart'; import 'package:aman_kassa_flutter/redux/state/user_state.dart';
@ -25,6 +26,7 @@ class LoginView extends StatelessWidget {
final FocusNode passwordNode = new FocusNode(); final FocusNode passwordNode = new FocusNode();
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
final DialogService _dialogService = locator<DialogService>(); final DialogService _dialogService = locator<DialogService>();
final ApiService _apiService = locator<ApiService>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -97,6 +99,11 @@ class LoginView extends StatelessWidget {
} }
_pressBtnEnter() async { _pressBtnEnter() async {
if(emailController.text!=null && emailController.text.toLowerCase().trim().startsWith('test')){
_apiService.test = true;
} else {
_apiService.test = false;
}
Redux.store Redux.store
.dispatch(authenticate(emailController.text, passwordController.text)); .dispatch(authenticate(emailController.text, passwordController.text));
} }
@ -109,13 +116,18 @@ class LoginView extends StatelessWidget {
"flash_off": 'Выкл фонарик', "flash_off": 'Выкл фонарик',
}); });
var result = await BarcodeScanner.scan(options: options); var result = await BarcodeScanner.scan(options: options);
print(result.type); // The result type (barcode, cancelled, failed) // print(result.type); // The result type (barcode, cancelled, failed)
print(result.rawContent); // The barcode content // print(result.rawContent); // The barcode content
print(result.format); // The barcode format (as enum) // print(result.format); // The barcode format (as enum)
print(result // print(result
.formatNote); // If a unknown format was scanned this field contains a note // .formatNote); // If a unknown format was scanned this field contains a note
if (result.type == ResultType.Barcode && if (result.type == ResultType.Barcode &&
result.rawContent?.length == 60) { result.rawContent?.length == 60) {
if(result.rawContent.toLowerCase().trim().startsWith('test')){
_apiService.test = true;
} else {
_apiService.test = false;
}
Redux.store.dispatch(authenticateToken(result.rawContent)); Redux.store.dispatch(authenticateToken(result.rawContent));
} else if (result.type == ResultType.Error ) { } else if (result.type == ResultType.Error ) {
_dialogService.showDialog(description: 'Не верный формат QR кода'); _dialogService.showDialog(description: 'Не верный формат QR кода');

View File

@ -36,7 +36,7 @@ class _AmanIconButtonState extends State<AmanIconButton> {
width: 120, width: 120,
alignment: Alignment.center, alignment: Alignment.center,
padding: EdgeInsets.symmetric( padding: EdgeInsets.symmetric(
horizontal: 25, //horizontal: 25,
vertical: 15), vertical: 15),
decoration: BoxDecoration( decoration: BoxDecoration(
//color: widget.enabled ? ( whiteColor ) : blueColorLigth, //color: widget.enabled ? ( whiteColor ) : blueColorLigth,
@ -44,19 +44,19 @@ class _AmanIconButtonState extends State<AmanIconButton> {
//boxShadow: [buttonShadowBox], //boxShadow: [buttonShadowBox],
), ),
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
(!widget.busy (!widget.busy
? Icon( ? Icon(
widget.icon, widget.icon,
color: widget.mainColor, color: widget.mainColor,
size: 36, size: 36,
) )
: CircularProgressIndicator( : CircularProgressIndicator(
strokeWidth: 3, strokeWidth: 3,
valueColor: AlwaysStoppedAnimation<Color>(widget.mainColor))), valueColor: AlwaysStoppedAnimation<Color>(widget.mainColor))),
Text(widget.title, style: TextStyle(color: widget.mainColor, fontSize: 15, fontWeight: FontWeight.bold, ), textAlign: TextAlign.center,) Text(widget.title, overflow: TextOverflow.fade, maxLines: 2, style: TextStyle(color: widget.mainColor, fontSize: 14, fontWeight: FontWeight.w800, ), textAlign: TextAlign.center,)
], ],
), ),
), ),
), ),
); );