45 lines
1.4 KiB
Dart
45 lines
1.4 KiB
Dart
import 'package:meta/meta.dart';
|
|
import 'package:redux/redux.dart';
|
|
import 'package:redux_thunk/redux_thunk.dart';
|
|
import 'package:satu/core/entity/Category.dart';
|
|
import 'package:satu/core/entity/Goods.dart';
|
|
import 'package:satu/core/models/flow/product_dao.dart';
|
|
import 'package:satu/core/redux/state/sell_state.dart';
|
|
import 'package:satu/core/services/db_service.dart';
|
|
import 'package:satu/core/services/dialog_service.dart';
|
|
import 'package:satu/core/utils/locator.dart';
|
|
|
|
import '../store.dart';
|
|
|
|
@immutable
|
|
class SetSellStateAction {
|
|
final SellState sellState;
|
|
|
|
SetSellStateAction(this.sellState);
|
|
}
|
|
|
|
final DbService _dbService = locator<DbService>();
|
|
|
|
ThunkAction<AppState> addSellItem({Good good, String excise}) {
|
|
return (Store<AppState> store) async {
|
|
ProductDao item = new ProductDao()
|
|
..id = good.id
|
|
..price = good.price
|
|
..article = good.articul
|
|
..count = 1.0
|
|
..eanCode = good.ean
|
|
..productName = good.name
|
|
..excise = excise;
|
|
//category add logic
|
|
if (good.categoryId != null) {
|
|
List<Map<String, dynamic>> set =
|
|
await _dbService.queryRowsWithWhere(CategoryTableName, 'id = ?', [good.categoryId]);
|
|
if (set.isNotEmpty) {
|
|
Category category = Category.fromMap(set.first);
|
|
item.categoryId = category.id;
|
|
}
|
|
}
|
|
store.dispatch(SetSellStateAction(SellState()));
|
|
};
|
|
}
|