sell
parent
56aab17cec
commit
d01366fced
|
|
@ -3,6 +3,7 @@ import 'package:satu/core/utils/utils_parse.dart';
|
|||
const String goodTableName = 'goods';
|
||||
const String GoodColumnId = 'id';
|
||||
const String GoodColumnCategoryId = 'category_id';
|
||||
const String GoodColumnCategoryName = 'categoryName';
|
||||
const String GoodColumnName = 'name';
|
||||
const String GoodColumnEan = 'ean';
|
||||
const String GoodColumnArticul = 'articul';
|
||||
|
|
@ -21,6 +22,7 @@ class Good {
|
|||
name = (map[GoodColumnName] ?? '') as String ;
|
||||
price = map[GoodColumnPrice] as num;
|
||||
categoryId = map[GoodColumnCategoryId] as int;
|
||||
categoryName = map[GoodColumnCategoryName] as String?;
|
||||
ean = map[GoodColumnEan] as String;
|
||||
appCompanyId = map[GoodColumnAppCompanyId] as int;
|
||||
optPrice = map[GoodColumnOptPrice] as num;
|
||||
|
|
@ -31,6 +33,7 @@ class Good {
|
|||
|
||||
int? id;
|
||||
int? categoryId;
|
||||
String? categoryName;
|
||||
String name = '';
|
||||
String? ean;
|
||||
int? articul;
|
||||
|
|
@ -49,6 +52,7 @@ class Good {
|
|||
GoodColumnName: name,
|
||||
GoodColumnPrice: price,
|
||||
GoodColumnCategoryId: categoryId,
|
||||
GoodColumnCategoryName: categoryName,
|
||||
GoodColumnEan: ean,
|
||||
GoodColumnAppCompanyId: appCompanyId,
|
||||
GoodColumnOptPrice: optPrice,
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ class GoodResponseEntity {
|
|||
double? price;
|
||||
@JsonKey(name: 'opt_price')
|
||||
double? optPrice;
|
||||
@JsonKey(name: 'app_company_id')
|
||||
int? appCompanyId;
|
||||
@JsonKey(name: 'base_price')
|
||||
double? basePrice;
|
||||
@JsonKey(name: 'auto_base_price')
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ GoodResponseEntity _$GoodResponseEntityFromJson(Map<String, dynamic> json) =>
|
|||
..articul = json['articul'] as int?
|
||||
..price = (json['price'] as num?)?.toDouble()
|
||||
..optPrice = (json['opt_price'] as num?)?.toDouble()
|
||||
..appCompanyId = json['app_company_id'] as int?
|
||||
..basePrice = (json['base_price'] as num?)?.toDouble()
|
||||
..autoBasePrice = (json['auto_base_price'] as num?)?.toDouble()
|
||||
..divisible = json['divisible'] as int?
|
||||
|
|
@ -30,6 +31,7 @@ Map<String, dynamic> _$GoodResponseEntityToJson(GoodResponseEntity instance) =>
|
|||
'articul': instance.articul,
|
||||
'price': instance.price,
|
||||
'opt_price': instance.optPrice,
|
||||
'app_company_id': instance.appCompanyId,
|
||||
'base_price': instance.basePrice,
|
||||
'auto_base_price': instance.autoBasePrice,
|
||||
'divisible': instance.divisible,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ class ProductDao {
|
|||
|
||||
ProductDao.fromMap(dynamic map) {
|
||||
id = map['id'] as int;
|
||||
categoryId = map['categoryId'] as int;
|
||||
categoryId = map['categoryId'] as int? ;
|
||||
count = map['count'] as double;
|
||||
price = map['price'] as double;
|
||||
productName = cast<String>(map['productName']) ?? '';
|
||||
|
|
|
|||
|
|
@ -127,17 +127,10 @@ ThunkAction<AppState> addSellItem({required Good good, String? excise}) {
|
|||
..count = 1.0
|
||||
..eanCode = good.ean
|
||||
..productName = good.name
|
||||
..excise = excise;
|
||||
//category add logic
|
||||
if (good.categoryId != null) {
|
||||
final List<Map<String, dynamic>> set = await _dbService
|
||||
.queryRowsWithWhere(categoryTableName, 'id = ?', [good.categoryId]);
|
||||
if (set.isNotEmpty) {
|
||||
final Category category = Category.fromMap(set.first);
|
||||
item.categoryId = category.id;
|
||||
item.categoryName = category.name;
|
||||
}
|
||||
}
|
||||
..excise = excise
|
||||
..categoryId = good.categoryId
|
||||
..categoryName = good.categoryName;
|
||||
|
||||
final TransactionRec rec = TransactionRec()
|
||||
..data = jsonEncode(item.toMap())
|
||||
..transactionId = transaction.id
|
||||
|
|
|
|||
|
|
@ -44,12 +44,12 @@ class ApiService extends BaseService {
|
|||
headers.addAll(header);
|
||||
}
|
||||
final String url = '$endpoint$point';
|
||||
// if (requestBody != null) {
|
||||
// log.i(host);
|
||||
// log.i(url);
|
||||
// log.i(headers);
|
||||
// log.i(jsonEncode(requestBody));
|
||||
// }
|
||||
if (requestBody != null) {
|
||||
//log.i(host);
|
||||
//log.i(url);
|
||||
//log.i(headers);
|
||||
log.i(jsonEncode(requestBody));
|
||||
}
|
||||
final response = await http.post(Uri.https(host, url),
|
||||
body: jsonEncode(requestBody), headers: headers);
|
||||
|
||||
|
|
|
|||
|
|
@ -50,30 +50,6 @@ class DbService extends BaseService {
|
|||
log.i('create tables');
|
||||
//Goods table
|
||||
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS $goodTableName (
|
||||
$GoodColumnId integer primary key unique,
|
||||
$GoodColumnArticul integer not null,
|
||||
$GoodColumnName text not null,
|
||||
$GoodColumnPrice real not null,
|
||||
$GoodColumnCategoryId integer not null,
|
||||
$GoodColumnEan text,
|
||||
$GoodColumnAppCompanyId integer,
|
||||
$GoodColumnOptPrice real,
|
||||
$GoodColumnBasePrice real,
|
||||
$GoodColumnDivisible integer,
|
||||
$GoodColumnUpdatedAt text not null
|
||||
);
|
||||
''');
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS $categoryTableName (
|
||||
$categoryColumnId integer primary key unique,
|
||||
$categoryColumnName text not null,
|
||||
$categoryColumnParentIn integer,
|
||||
$categoryColumnAppCompanyId integer,
|
||||
$categoryColumnUpdatedAt text not null
|
||||
);
|
||||
''');
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS $transactionTableName (
|
||||
$transactionColumnId integer primary key autoincrement,
|
||||
|
|
|
|||
|
|
@ -15,21 +15,42 @@ class DictionaryService extends BaseService {
|
|||
final ApiService _api = locator<ApiService>();
|
||||
final DbService _db = locator<DbService>();
|
||||
|
||||
Good goodResponseToGood(GoodResponseEntity response) {
|
||||
return Good()
|
||||
..id = response.id
|
||||
..name = response.name
|
||||
..basePrice = response.basePrice
|
||||
..optPrice = response.optPrice
|
||||
..price = response.price
|
||||
..articul = response.articul
|
||||
..categoryId = response.categoryId
|
||||
..categoryName = response.categoryName
|
||||
..divisible = response.divisible
|
||||
..ean = response.ean13
|
||||
..appCompanyId = response.appCompanyId;
|
||||
}
|
||||
|
||||
Category categoryResponseToCategory(CategoryResponse response) {
|
||||
return Category()
|
||||
..id = response.id
|
||||
..parentId = response.parentId
|
||||
..name = response.name;
|
||||
}
|
||||
|
||||
Future<void> refreshFull() async {}
|
||||
|
||||
Future<List<Category>> getCategoryByParentId(int parentId) async {
|
||||
Future<List<Category>> getCategoryByParentId(int? parentId) async {
|
||||
final List<Category> list = [];
|
||||
try {
|
||||
final int? appCompanyId = Redux.store?.state.userState?.auth?.companyId;
|
||||
final List<Map<String, dynamic>> elements = await _db.queryRowsWithWhere(
|
||||
categoryTableName,
|
||||
'$categoryColumnAppCompanyId = ? and $categoryColumnParentIn = ?',
|
||||
[appCompanyId, parentId]);
|
||||
for (final Map<String, dynamic> element in elements) {
|
||||
list.add(Category.fromMap(element));
|
||||
dynamic filter = {'col': 'parent_id', 'action': 'equal', 'val': parentId};
|
||||
List<CategoryResponse> responses =
|
||||
await getCategories(page: 1, perpage: 100, filter: filter);
|
||||
for (final CategoryResponse response in responses) {
|
||||
final Category category = categoryResponseToCategory(response);
|
||||
list.add(category);
|
||||
}
|
||||
} catch (e, stack) {
|
||||
log.e('getCategoryByParentId', e, stack);
|
||||
log.e('getCategories', e, stack);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
|
@ -52,19 +73,22 @@ class DictionaryService extends BaseService {
|
|||
return result;
|
||||
}
|
||||
|
||||
Future<List<Good>> getGoodsByCategoryId(int categoryId) async {
|
||||
Future<List<Good>> getGoodsByCategoryId(int? categoryId) async {
|
||||
final List<Good> list = [];
|
||||
try {
|
||||
final int? appCompanyId = Redux.store?.state.userState?.auth?.companyId;
|
||||
final List<Map<String, dynamic>> elements = await _db.queryRowsWithWhere(
|
||||
goodTableName,
|
||||
'$GoodColumnAppCompanyId = ? and $GoodColumnCategoryId = ?',
|
||||
[appCompanyId, categoryId]);
|
||||
for (final Map<String, dynamic> element in elements) {
|
||||
list.add(Good.fromMap(element));
|
||||
dynamic filter = {
|
||||
'col': 'eacc_good_category_id',
|
||||
'action': 'equal',
|
||||
'val': categoryId
|
||||
};
|
||||
List<GoodResponseEntity> responses =
|
||||
await getGoods(page: 1, perpage: 100, filter: filter);
|
||||
for (final GoodResponseEntity response in responses) {
|
||||
final Good good = goodResponseToGood(response);
|
||||
list.add(good);
|
||||
}
|
||||
} catch (e, stack) {
|
||||
log.e('getGoodsByCategoryId', e, stack);
|
||||
log.e('getGoods', e, stack);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
|
@ -76,7 +100,7 @@ class DictionaryService extends BaseService {
|
|||
String where =
|
||||
'( $GoodColumnAppCompanyId = ? and $GoodColumnName like ? ) ';
|
||||
final List args = [appCompanyId, '%$query%'];
|
||||
if (_isNumericInt(query)) {
|
||||
if (_isNumericInt(query) && query.length >= 8) {
|
||||
where += ' or $GoodColumnEan like ?';
|
||||
args.add('${int.parse(query).toString()}%');
|
||||
}
|
||||
|
|
@ -99,15 +123,13 @@ class DictionaryService extends BaseService {
|
|||
}
|
||||
|
||||
Future<List<CategoryResponse>> getCategories(
|
||||
{required int page, required int perpage, String? query}) async {
|
||||
{required int page, required int perpage, dynamic filter}) async {
|
||||
List<CategoryResponse> list = [];
|
||||
try {
|
||||
final Map<String, dynamic> requestBody = <String, dynamic>{
|
||||
'page': page,
|
||||
'perpage': perpage,
|
||||
'filter': [
|
||||
{'col': 'name', 'action': 'like', 'val': query ?? ''}
|
||||
]
|
||||
'filter': [filter]
|
||||
};
|
||||
|
||||
DictResponseEntity categories = await _api
|
||||
|
|
@ -148,15 +170,13 @@ class DictionaryService extends BaseService {
|
|||
}
|
||||
|
||||
Future<List<GoodResponseEntity>> getGoods(
|
||||
{required int page, required int perpage, String? query}) async {
|
||||
{required int page, required int perpage, dynamic filter}) async {
|
||||
List<GoodResponseEntity> list = [];
|
||||
try {
|
||||
final Map<String, dynamic> requestBody = <String, dynamic>{
|
||||
'page': page,
|
||||
'perpage': perpage,
|
||||
'filter': [
|
||||
{'col': 'name', 'action': 'like', 'val': query ?? ''}
|
||||
]
|
||||
'filter': [filter]
|
||||
};
|
||||
|
||||
DictResponseEntity categories =
|
||||
|
|
@ -177,11 +197,9 @@ class DictionaryService extends BaseService {
|
|||
Future<String?> saveGood(GoodResponseEntity good) async {
|
||||
DictResponseEntity? status;
|
||||
if (good.id != null) {
|
||||
status =
|
||||
await _api.dictionarySave('/goods_goods_edit', good.toJson());
|
||||
status = await _api.dictionarySave('/goods_goods_edit', good.toJson());
|
||||
} else {
|
||||
status =
|
||||
await _api.dictionarySave('/goods_goods_add', good.toJson());
|
||||
status = await _api.dictionarySave('/goods_goods_add', good.toJson());
|
||||
}
|
||||
String? message = getErrorMsg(status);
|
||||
|
||||
|
|
|
|||
|
|
@ -132,8 +132,9 @@ class _CategorySelectViewState extends State<CategorySelectView> {
|
|||
}
|
||||
|
||||
Future<void> _fetchData(int pageKey, int perPage, String? query) async {
|
||||
dynamic filter = {'col': 'name', 'action': 'like', 'val': query ?? ''};
|
||||
final List<CategoryResponse> newItems = await _dictionaryService
|
||||
.getCategories(page: pageKey, query: query, perpage: perPage);
|
||||
.getCategories(page: pageKey, filter: filter, perpage: perPage);
|
||||
|
||||
final isLastPage = newItems.length < _pageSize;
|
||||
if (isLastPage) {
|
||||
|
|
|
|||
|
|
@ -137,8 +137,9 @@ class _CategoryDictionaryViewState extends State<CategoryDictionaryView> {
|
|||
}
|
||||
|
||||
Future<void> _fetchData(int pageKey, int perPage, String? query) async {
|
||||
dynamic filter = {'col': 'name', 'action': 'like', 'val': query ?? ''};
|
||||
final List<CategoryResponse> newItems = await _dictionaryService
|
||||
.getCategories(page: pageKey, query: query, perpage: perPage);
|
||||
.getCategories(page: pageKey, filter: filter, perpage: perPage);
|
||||
|
||||
final isLastPage = newItems.length < _pageSize;
|
||||
if (isLastPage) {
|
||||
|
|
|
|||
|
|
@ -152,7 +152,9 @@ class _GoodsDictionaryViewState extends State<GoodsDictionaryView> {
|
|||
|
||||
Future<void> _fetchData(int pageKey, int perPage, String? query) async {
|
||||
final List<GoodResponseEntity> newItems = await _dictionaryService.getGoods(
|
||||
page: pageKey, query: query, perpage: perPage);
|
||||
page: pageKey,
|
||||
filter: {'col': 'name', 'action': 'like', 'val': query ?? ''},
|
||||
perpage: perPage);
|
||||
|
||||
final isLastPage = newItems.length < _pageSize;
|
||||
if (isLastPage) {
|
||||
|
|
|
|||
|
|
@ -40,11 +40,11 @@ class _AddProductViewState extends State<AddProductView> {
|
|||
reset();
|
||||
}
|
||||
});
|
||||
_history = [Category()..id = 0];
|
||||
_history = [Category()..id = null];
|
||||
_categories = [];
|
||||
_goods = [];
|
||||
super.initState();
|
||||
navigateCategory(0);
|
||||
navigateCategory(null);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -128,7 +128,7 @@ class _AddProductViewState extends State<AddProductView> {
|
|||
_searchTextController.clear();
|
||||
}
|
||||
|
||||
void navigateCategory(int categoryId) async {
|
||||
void navigateCategory(int? categoryId) async {
|
||||
List<Category> categories =
|
||||
await _dictionaryService.getCategoryByParentId(categoryId);
|
||||
List<Good> goods =
|
||||
|
|
|
|||
Loading…
Reference in New Issue