parent
31e9ac2260
commit
8d16949f40
|
|
@ -16,12 +16,17 @@ import 'package:http/http.dart' as http;
|
|||
|
||||
/// The service responsible for networking requests
|
||||
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 DialogService _dialogService = locator<DialogService>();
|
||||
|
||||
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 {
|
||||
Map<String, String> requestBody = <String, String>{
|
||||
'email': email,
|
||||
|
|
@ -43,7 +48,7 @@ class ApiService extends BaseService {
|
|||
|
||||
Future<Response<Message>> isActive(String token) async {
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -129,8 +134,11 @@ class ApiService extends BaseService {
|
|||
HttpHeaders.userAgentHeader: iosInfo.utsname.machine,
|
||||
});
|
||||
}
|
||||
|
||||
var uri = Uri.parse('$endpoint$point');
|
||||
String url = '$endpoint$point';
|
||||
if(this._test) {
|
||||
url = '$test_endpoint$point';
|
||||
}
|
||||
var uri = Uri.parse(url);
|
||||
var request = http.MultipartRequest('POST', uri)
|
||||
..headers.addAll(headers)
|
||||
..fields.addAll(requestBody);
|
||||
|
|
|
|||
|
|
@ -63,7 +63,6 @@ class DataService extends BaseService {
|
|||
if ((paymentType ?? 'cash') == 'card') {
|
||||
checkData.card = summ;
|
||||
}
|
||||
print(checkData);
|
||||
return checkData;
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +87,6 @@ class DataService extends BaseService {
|
|||
if ((paymentType ?? 'cash') == 'card') {
|
||||
checkData.card = summ;
|
||||
}
|
||||
print(checkData);
|
||||
return checkData;
|
||||
}
|
||||
|
||||
|
|
@ -167,21 +165,18 @@ class DataService extends BaseService {
|
|||
await _db.deleteAll(Service_tableName);
|
||||
log.i('All tables cleaned');
|
||||
for (var key in goods.body.keys) {
|
||||
print(goods.body[key]);
|
||||
Good row = Good.fromJson(goods.body[key]);
|
||||
await _db.insert(Goog_tableName, row.toMap());
|
||||
}
|
||||
log.i('Inserted ${goods.body.length} to table $Goog_tableName');
|
||||
|
||||
for (var el in categories.body) {
|
||||
print(el);
|
||||
Category row = Category.fromJson(el);
|
||||
await _db.insert(Category_tableName, row.toMap());
|
||||
}
|
||||
log.i('Inserted ${categories.body.length} to table $Category_tableName');
|
||||
|
||||
for (var key in services.body.keys) {
|
||||
print(services.body[key]);
|
||||
Service row = Service.fromJson(services.body[key]);
|
||||
await _db.insert(Service_tableName, row.toMap());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,11 +31,18 @@ final DialogService _dialogService = locator<DialogService>();
|
|||
Future<void> checkUserAction(Store<AppState> store) async {
|
||||
store.dispatch(SetUserStateAction(UserState(isLoading: true)));
|
||||
try {
|
||||
String token = store.state.userState.user?.token;
|
||||
User user = store.state.userState.user;
|
||||
String token = user?.token;
|
||||
bool isAuthenticated = false;
|
||||
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);
|
||||
isAuthenticated = "OK" == session.body.message;
|
||||
|
||||
} else {
|
||||
await Future.delayed(Duration(milliseconds: 2000));
|
||||
}
|
||||
|
|
@ -114,7 +121,7 @@ ThunkAction<AppState> authenticateToken(String token) {
|
|||
)));
|
||||
if (result.user == null && result.message != null) {
|
||||
_dialogService.showDialog(
|
||||
title: 'Warning', buttonTitle: 'Ok', description: result.message);
|
||||
title: 'Внимание', buttonTitle: 'Ok', description: 'Ошибка авторизации');
|
||||
}
|
||||
if (result.user != null) {
|
||||
_navigation.replace(HomeViewRoute);
|
||||
|
|
@ -146,7 +153,7 @@ ThunkAction<AppState> authenticate(String email, String password) {
|
|||
)));
|
||||
if (result.user == null && result.message != null) {
|
||||
_dialogService.showDialog(
|
||||
title: 'Warning', buttonTitle: 'Ok', description: result.message);
|
||||
title: 'Внимание', buttonTitle: 'Ok', description: 'Ошибка авторизации');
|
||||
}
|
||||
if (result.user != null) {
|
||||
_navigation.replace(HomeViewRoute);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import 'package:aman_kassa_flutter/shared/app_colors.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
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.info_outline, command: 'info'),
|
||||
//const Choice(title: 'Язык', icon: Icons.language, command: 'language'),
|
||||
|
|
|
|||
|
|
@ -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/route_names.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/navigator_service.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_horizontal.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_redux/flutter_redux.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>();
|
||||
NavigatorService _navigator = locator<NavigatorService>();
|
||||
DialogService _dialog = locator<DialogService>();
|
||||
DataService _dataService = locator<DataService>();
|
||||
final GlobalKey<State> _keyLoader = new GlobalKey<State>();
|
||||
|
||||
bool isMoneyCheckBusy;
|
||||
bool closeSmenaBusy;
|
||||
|
|
@ -41,6 +45,7 @@ class _AdditionalTabState extends State<AdditionalTab> {
|
|||
bool depositBusy;
|
||||
bool withdrawalBusy;
|
||||
bool xReportBusy;
|
||||
bool updateCatalog;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
|
@ -51,6 +56,7 @@ class _AdditionalTabState extends State<AdditionalTab> {
|
|||
depositBusy = false;
|
||||
withdrawalBusy = false;
|
||||
xReportBusy = false;
|
||||
updateCatalog = false;
|
||||
}
|
||||
|
||||
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 {
|
||||
setState(() {
|
||||
depositBusy = true;
|
||||
|
|
@ -255,6 +275,7 @@ class _AdditionalTabState extends State<AdditionalTab> {
|
|||
verticalSpaceMedium,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
AmanIconButton(
|
||||
title: 'Открыть смену',
|
||||
|
|
@ -282,6 +303,7 @@ class _AdditionalTabState extends State<AdditionalTab> {
|
|||
verticalSpaceTiny,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
AmanIconButton(
|
||||
title: 'Х Отчет',
|
||||
|
|
@ -290,6 +312,13 @@ class _AdditionalTabState extends State<AdditionalTab> {
|
|||
mainColor: primaryColor,
|
||||
icon: Icons.description,
|
||||
),
|
||||
AmanIconButton(
|
||||
title: 'Обновить номенклатуру',
|
||||
onPressed: _updateCatalog,
|
||||
busy: updateCatalog,
|
||||
mainColor: greenColor,
|
||||
icon: MdiIcons.databaseRefresh,
|
||||
),
|
||||
],
|
||||
),
|
||||
verticalSpaceMedium,
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class _ProductAddBottomSheetState extends State<ProductAddBottomSheet> {
|
|||
labelText: 'Количество',
|
||||
prefixText: ' ',
|
||||
),
|
||||
keyboardType: TextInputType.number,
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: false,),
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
WhitelistingTextInputFormatter.digitsOnly
|
||||
],
|
||||
|
|
@ -90,7 +90,7 @@ class _ProductAddBottomSheetState extends State<ProductAddBottomSheet> {
|
|||
labelText: 'Стоимость',
|
||||
prefixText: ' ',
|
||||
),
|
||||
keyboardType: TextInputType.number,
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
WhitelistingTextInputFormatter(RegExp("^[0-9.]*")),
|
||||
],
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'dart:ui';
|
||||
|
||||
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/redux/actions/user_actions.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 GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
|
||||
final DialogService _dialogService = locator<DialogService>();
|
||||
final ApiService _apiService = locator<ApiService>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
@ -97,6 +99,11 @@ class LoginView extends StatelessWidget {
|
|||
}
|
||||
|
||||
_pressBtnEnter() async {
|
||||
if(emailController.text!=null && emailController.text.toLowerCase().trim().startsWith('test')){
|
||||
_apiService.test = true;
|
||||
} else {
|
||||
_apiService.test = false;
|
||||
}
|
||||
Redux.store
|
||||
.dispatch(authenticate(emailController.text, passwordController.text));
|
||||
}
|
||||
|
|
@ -109,13 +116,18 @@ class LoginView extends StatelessWidget {
|
|||
"flash_off": 'Выкл фонарик',
|
||||
});
|
||||
var result = await BarcodeScanner.scan(options: options);
|
||||
print(result.type); // The result type (barcode, cancelled, failed)
|
||||
print(result.rawContent); // The barcode content
|
||||
print(result.format); // The barcode format (as enum)
|
||||
print(result
|
||||
.formatNote); // If a unknown format was scanned this field contains a note
|
||||
// print(result.type); // The result type (barcode, cancelled, failed)
|
||||
// print(result.rawContent); // The barcode content
|
||||
// print(result.format); // The barcode format (as enum)
|
||||
// print(result
|
||||
// .formatNote); // If a unknown format was scanned this field contains a note
|
||||
if (result.type == ResultType.Barcode &&
|
||||
result.rawContent?.length == 60) {
|
||||
if(result.rawContent.toLowerCase().trim().startsWith('test')){
|
||||
_apiService.test = true;
|
||||
} else {
|
||||
_apiService.test = false;
|
||||
}
|
||||
Redux.store.dispatch(authenticateToken(result.rawContent));
|
||||
} else if (result.type == ResultType.Error ) {
|
||||
_dialogService.showDialog(description: 'Не верный формат QR кода');
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class _AmanIconButtonState extends State<AmanIconButton> {
|
|||
width: 120,
|
||||
alignment: Alignment.center,
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 25,
|
||||
//horizontal: 25,
|
||||
vertical: 15),
|
||||
decoration: BoxDecoration(
|
||||
//color: widget.enabled ? ( whiteColor ) : blueColorLigth,
|
||||
|
|
@ -44,19 +44,19 @@ class _AmanIconButtonState extends State<AmanIconButton> {
|
|||
//boxShadow: [buttonShadowBox],
|
||||
),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
(!widget.busy
|
||||
? Icon(
|
||||
widget.icon,
|
||||
color: widget.mainColor,
|
||||
size: 36,
|
||||
)
|
||||
: CircularProgressIndicator(
|
||||
strokeWidth: 3,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(widget.mainColor))),
|
||||
Text(widget.title, style: TextStyle(color: widget.mainColor, fontSize: 15, fontWeight: FontWeight.bold, ), textAlign: TextAlign.center,)
|
||||
],
|
||||
),
|
||||
children: <Widget>[
|
||||
(!widget.busy
|
||||
? Icon(
|
||||
widget.icon,
|
||||
color: widget.mainColor,
|
||||
size: 36,
|
||||
)
|
||||
: CircularProgressIndicator(
|
||||
strokeWidth: 3,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(widget.mainColor))),
|
||||
Text(widget.title, overflow: TextOverflow.fade, maxLines: 2, style: TextStyle(color: widget.mainColor, fontSize: 14, fontWeight: FontWeight.w800, ), textAlign: TextAlign.center,)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue