117 lines
3.7 KiB
Dart
117 lines
3.7 KiB
Dart
import 'package:satu/core/base/base_service.dart';
|
|
import 'package:satu/core/models/inventarization/invetarization_good_list/invetarization_good_list.dart';
|
|
import 'package:satu/core/models/inventarization/response/inventarization_response.dart';
|
|
import 'package:satu/core/utils/locator.dart';
|
|
|
|
import '../models/inventarization/good_item/good_item.dart';
|
|
import '../models/response/response_entity.dart';
|
|
import 'api_service.dart';
|
|
|
|
class InventarizationService extends BaseService {
|
|
final ApiService _api = locator<ApiService>();
|
|
|
|
Future<List<InventarizationResponse>> getList(
|
|
{required int page, required int perpage, dynamic filter}) async {
|
|
List<InventarizationResponse> list = [];
|
|
try {
|
|
final Map<String, dynamic> requestBody = <String, dynamic>{
|
|
'page': page,
|
|
'perpage': perpage
|
|
};
|
|
|
|
ResponseEntity categories = await _api.postRequest('/goods_inventory_get',
|
|
requestBody: requestBody);
|
|
if (categories.original.data != null &&
|
|
categories.original.data!.isNotEmpty) {
|
|
for (final dynamic map in categories.original.data!) {
|
|
final InventarizationResponse item =
|
|
InventarizationResponse.fromJson(map);
|
|
list.add(item);
|
|
}
|
|
}
|
|
} catch (e, stack) {
|
|
log.e('getList', e, stack);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
Future<List<GoodInventarization>> getGoodByInventarizationId(
|
|
{required int page, required int perpage, required int id}) async {
|
|
List<GoodInventarization> list = [];
|
|
try {
|
|
final Map<String, dynamic> requestBody = <String, dynamic>{
|
|
'page': page,
|
|
'perpage': perpage,
|
|
'id': id
|
|
};
|
|
|
|
ResponseEntity categories = await _api.postRequest(
|
|
'/goods_inventory_get_edit_form_data',
|
|
requestBody: requestBody);
|
|
if (categories.original.result != null) {
|
|
InventarizationGoodList listResponse = InventarizationGoodList.fromJson(categories.original.result);
|
|
list.addAll(listResponse.goodsList);
|
|
}
|
|
} catch (e, stack) {
|
|
log.e('getList', e, stack);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
Future<bool> addGoodToList(int inventoryId, int? goodId) async {
|
|
bool result = false;
|
|
try {
|
|
final Map<String, dynamic> requestBody = <String, dynamic>{
|
|
'page': 1,
|
|
'perpage': 1,
|
|
'id': inventoryId,
|
|
'good_id' : goodId
|
|
};
|
|
ResponseEntity response = await _api.postRequest(
|
|
'/goods_inventory_select_item',
|
|
requestBody: requestBody);
|
|
result = response.original.result != null;
|
|
} catch (e, stack) {
|
|
log.e('getList', e, stack);
|
|
}
|
|
return result ;
|
|
}
|
|
|
|
Future<bool> deleteFromList(int inventoryId, int inventory_item_id) async {
|
|
bool result = false;
|
|
try {
|
|
final Map<String, dynamic> requestBody = <String, dynamic>{
|
|
'page': 1,
|
|
'perpage': 1,
|
|
'id': inventoryId,
|
|
'inventory_item_id' : inventory_item_id
|
|
};
|
|
ResponseEntity response = await _api.postRequest(
|
|
'/goods_inventory_delete_item',
|
|
requestBody: requestBody);
|
|
result = response.original.result != null;
|
|
} catch (e, stack) {
|
|
log.e('getList', e, stack);
|
|
}
|
|
return result ;
|
|
}
|
|
|
|
Future<bool> setCountToItem(int inventoryId, int inventoryItemId, double value) async {
|
|
bool result = false;
|
|
try {
|
|
final Map<String, dynamic> requestBody = <String, dynamic>{
|
|
'id': inventoryId,
|
|
'inventory_item_id' : inventoryItemId,
|
|
'cnt_buh': value
|
|
};
|
|
ResponseEntity response = await _api.postRequest(
|
|
'/goods_inventory_set_cnt_item',
|
|
requestBody: requestBody);
|
|
result = response.original.result != null;
|
|
} catch (e, stack) {
|
|
log.e('getList', e, stack);
|
|
}
|
|
return result ;
|
|
}
|
|
}
|