forked from hesabix/arc
100 lines
3.4 KiB
Dart
Executable file
100 lines
3.4 KiB
Dart
Executable file
import 'package:hesabix_ui/core/api_client.dart';
|
|
|
|
class OpeningBalanceService {
|
|
final ApiClient _apiClient;
|
|
|
|
OpeningBalanceService(this._apiClient);
|
|
|
|
Future<Map<String, dynamic>?> fetch({required int businessId, int? fiscalYearId}) async {
|
|
final resp = await _apiClient.get(
|
|
'/businesses/$businessId/opening-balance',
|
|
query: {
|
|
if (fiscalYearId != null) 'fiscal_year_id': fiscalYearId,
|
|
},
|
|
);
|
|
if (resp.statusCode == 200) {
|
|
return (resp.data?['data'] as Map<String, dynamic>?) ?? {};
|
|
}
|
|
throw Exception('خطا در دریافت تراز افتتاحیه: ${resp.statusMessage}');
|
|
}
|
|
|
|
Future<Map<String, dynamic>> save({
|
|
required int businessId,
|
|
required Map<String, dynamic> payload,
|
|
}) async {
|
|
final resp = await _apiClient.put(
|
|
'/businesses/$businessId/opening-balance',
|
|
data: payload,
|
|
);
|
|
if (resp.statusCode == 200) {
|
|
return (resp.data?['data'] as Map<String, dynamic>? ?? {});
|
|
}
|
|
throw Exception('خطا در ذخیره تراز افتتاحیه: ${resp.statusMessage}');
|
|
}
|
|
|
|
Future<Map<String, dynamic>> post({required int businessId, int? fiscalYearId}) async {
|
|
final resp = await _apiClient.post(
|
|
'/businesses/$businessId/opening-balance/post',
|
|
query: {
|
|
if (fiscalYearId != null) 'fiscal_year_id': fiscalYearId,
|
|
},
|
|
);
|
|
if (resp.statusCode == 200) {
|
|
return (resp.data?['data'] as Map<String, dynamic>? ?? {});
|
|
}
|
|
throw Exception('خطا در نهاییسازی تراز افتتاحیه: ${resp.statusMessage}');
|
|
}
|
|
|
|
Future<Map<String, dynamic>> unpost({required int businessId, int? fiscalYearId}) async {
|
|
final resp = await _apiClient.post(
|
|
'/businesses/$businessId/opening-balance/unpost',
|
|
query: {
|
|
if (fiscalYearId != null) 'fiscal_year_id': fiscalYearId,
|
|
},
|
|
);
|
|
if (resp.statusCode == 200) {
|
|
return (resp.data?['data'] as Map<String, dynamic>? ?? {});
|
|
}
|
|
throw Exception('خطا در لغو نهاییسازی تراز افتتاحیه: ${resp.statusMessage}');
|
|
}
|
|
|
|
Future<Map<String, dynamic>> fetchPersonLineEligibility({
|
|
required int businessId,
|
|
int? fiscalYearId,
|
|
int? personId,
|
|
}) async {
|
|
final resp = await _apiClient.get(
|
|
'/businesses/$businessId/opening-balance/person-line-eligibility',
|
|
query: {
|
|
if (fiscalYearId != null) 'fiscal_year_id': fiscalYearId,
|
|
if (personId != null) 'person_id': personId,
|
|
},
|
|
);
|
|
if (resp.statusCode == 200) {
|
|
return Map<String, dynamic>.from((resp.data?['data'] as Map?) ?? {});
|
|
}
|
|
throw Exception('خطا در بررسی امکان مانده افتتاحیه: ${resp.statusMessage}');
|
|
}
|
|
|
|
Future<Map<String, dynamic>> fetchProductLineEligibility({
|
|
required int businessId,
|
|
int? fiscalYearId,
|
|
int? productId,
|
|
int? warehouseId,
|
|
}) async {
|
|
final resp = await _apiClient.get(
|
|
'/businesses/$businessId/opening-balance/product-line-eligibility',
|
|
query: {
|
|
if (fiscalYearId != null) 'fiscal_year_id': fiscalYearId,
|
|
if (productId != null) 'product_id': productId,
|
|
if (warehouseId != null) 'warehouse_id': warehouseId,
|
|
},
|
|
);
|
|
if (resp.statusCode == 200) {
|
|
return Map<String, dynamic>.from((resp.data?['data'] as Map?) ?? {});
|
|
}
|
|
throw Exception('خطا در بررسی امکان تعداد اولیه: ${resp.statusMessage}');
|
|
}
|
|
}
|
|
|
|
|